-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/adding new chain to adapter (#11657)
- Loading branch information
1 parent
7183fb7
commit d150361
Showing
1 changed file
with
62 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,76 @@ | ||
const { getLogs } = require('../helper/cache/getLogs'); | ||
const { transformDexBalances } = require('../helper/portedTokens'); | ||
|
||
const { getLogs } = require('../helper/cache/getLogs') | ||
const { transformDexBalances } = require('../helper/portedTokens') | ||
|
||
const factory = '0x16eD649675e6Ed9F1480091123409B4b8D228dC1' | ||
module.exports = { | ||
misrepresentedTokens: true, | ||
methodology: 'TVL counts the liquidity of the pools on each chain.', | ||
} | ||
}; | ||
|
||
const config = { | ||
ethereum: { fromBlock: 12965000, }, | ||
polygon: { fromBlock: 12965000, }, | ||
arbitrum: { fromBlock: 101851523, }, | ||
} | ||
ethereum: { | ||
fromBlock: 12965000, | ||
factory: '0x16eD649675e6Ed9F1480091123409B4b8D228dC1', | ||
}, | ||
polygon: { | ||
fromBlock: 12965000, | ||
factory: '0x16eD649675e6Ed9F1480091123409B4b8D228dC1', | ||
}, | ||
arbitrum: { | ||
fromBlock: 101851523, | ||
factory: '0x16eD649675e6Ed9F1480091123409B4b8D228dC1', | ||
}, | ||
mode: { | ||
fromBlock: 6989680, | ||
factory: '0x7962223D940E1b099AbAe8F54caBFB8a3a0887AB', | ||
}, | ||
}; | ||
|
||
Object.keys(config).forEach(chain => { | ||
const { fromBlock } = config[chain] | ||
Object.keys(config).forEach((chain) => { | ||
const { fromBlock, factory } = config[chain]; | ||
module.exports[chain] = { | ||
tvl: async (api) => { | ||
let logs = await getLogs({ | ||
api, | ||
target: factory, | ||
eventAbi: "event PairCreated(address indexed token0, address indexed token1, address pair, uint256)", | ||
eventAbi: | ||
'event PairCreated(address indexed token0, address indexed token1, address pair, uint256)', | ||
onlyArgs: true, | ||
fromBlock, | ||
}) | ||
let pairs = logs.map(log => log.pair) | ||
const names = await api.multiCall({ abi: 'string:name', calls: pairs }) | ||
logs = logs.filter((pair, i) => names[i] === 'SweepnFlip LPs') | ||
pairs = logs.map(log => log.pair) | ||
const bals0 = await api.multiCall({ abi: 'erc20:balanceOf', calls: pairs.map((pair, i) => ({ target: logs[i].token0, params: pair })) }) | ||
const bals1 = await api.multiCall({ abi: 'erc20:balanceOf', calls: pairs.map((pair, i) => ({ target: logs[i].token1, params: pair })) }) | ||
return transformDexBalances({ chain, data: logs.map((l, i) => ({ token0Bal: bals0[i], token1Bal: bals1[i], token0: l.token0, token1: l.token1 })) }) | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
let pairs = logs.map((log) => log.pair); | ||
|
||
const names = await api.multiCall({ abi: 'string:name', calls: pairs }); | ||
|
||
logs = logs.filter((pair, i) => names[i] === 'SweepnFlip LPs'); | ||
|
||
pairs = logs.map((log) => log.pair); | ||
|
||
const bals0 = await api.multiCall({ | ||
abi: 'erc20:balanceOf', | ||
calls: pairs.map((pair, i) => ({ | ||
target: logs[i].token0, | ||
params: pair, | ||
})), | ||
}); | ||
|
||
const bals1 = await api.multiCall({ | ||
abi: 'erc20:balanceOf', | ||
calls: pairs.map((pair, i) => ({ | ||
target: logs[i].token1, | ||
params: pair, | ||
})), | ||
}); | ||
|
||
return transformDexBalances({ | ||
chain, | ||
data: logs.map((l, i) => ({ | ||
token0Bal: bals0[i], | ||
token1Bal: bals1[i], | ||
token0: l.token0, | ||
token1: l.token1, | ||
})), | ||
}); | ||
}, | ||
}; | ||
}); |