Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/adding new chain to adapter #11657

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 62 additions & 23 deletions projects/sweep-n-flip/index.js
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,
})),
});
},
};
});
Loading