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: list protocols on DefiLlama #10165

Closed
Closed
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
131 changes: 97 additions & 34 deletions projects/clearpool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,107 @@ const CPOOL = "0x66761fa41377003622aee3c7675fc7b5c1c2fac5";

module.exports = {
methodology: "We count liquidity by Stables deposited on the pools contracts",
}
};

const config = {
ethereum: { factory: '0xde204e5a060ba5d3b63c7a4099712959114c2d48', fromBlock: 14443222 }, // Permissionless Pools
polygon_zkevm: { factory: '0xCE3Fec90A05992dF1357651FEF6D143FeeC7Ca16', fromBlock: 302970 }, // Permissionless Pools
polygon: { factory: '0x215CCa938dF02c9814BE2D39A285B941FbdA79bA', fromBlock: 31128013 }, // Permissionless Pools
optimism: { factory: '0x99C10A7aBd93b2db6d1a2271e69F268a2c356b80', fromBlock: 107128813 }, // Permissionless Pools
mantle: { factory: '0xB217D93a8f6A4b7861bB2C865a8C22105FbCdE41', fromBlock: 49691965 }, // Permissionless Pools
}

Object.keys(config).forEach(chain => {
const { fromBlock, factory } = config[chain]

const tvl = async (api) => {
const { pools, tokens } = await _getLogs(api)
return api.sumTokens({ tokensAndOwners2: [tokens, pools] })
}
dynamic: {
ethereum: {
factory: "0xde204e5a060ba5d3b63c7a4099712959114c2d48",
fromBlock: 14443222,
},
polygon_zkevm: {
factory: "0xCE3Fec90A05992dF1357651FEF6D143FeeC7Ca16",
fromBlock: 302970,
},
polygon: {
factory: "0x215CCa938dF02c9814BE2D39A285B941FbdA79bA",
fromBlock: 31128013,
},
optimism: {
factory: "0x99C10A7aBd93b2db6d1a2271e69F268a2c356b80",
fromBlock: 107128813,
},
arbitrum: {
factory: "0x99C10A7aBd93b2db6d1a2271e69F268a2c356b80",
fromBlock: 113112037,
},
},
vaults: {
base: {
factory: "0x199A016FFbe14781365bCaED9Cc52598B205DfAd",
fromBlock: 12634153,
},
avax: {
factory: "0x8E557363AC9E5cbf09A2616A302CA3c8f6ab2b7A",
fromBlock: 42597808,
},
},
treasury: {
flare: {
factory: "0x8E557363AC9E5cbf09A2616A302CA3c8f6ab2b7A",
fromBlock: 23711495,
},
},
};

async function _getLogs(api) {
const logs = await getLogs({
api,
target: factory,
fromBlock,
eventAbi: 'event PoolCreated(address indexed pool, address indexed owner, address indexed token)',
onlyArgs: true
})
const pools = logs.map(log => log.pool)
const tokens = logs.map(log => log.token)
return { pools, tokens }
const getEventAndABI = (protocol) => {
let borrowFn = "";
let abi = "";
switch (protocol) {
case "dynamic":
(abi =
"event PoolCreated(address indexed pool, address indexed owner, address indexed token)"),
(borrowFn = "uint256:borrows");
break;
case "vaults":
(abi =
"event PoolCreated(uint256 depositCap, uint256 repaymentFrequency, uint256 minimumNoticePeriod, uint256 minDeposit, uint256 lendAPR, address indexed asset, address indexed borrower, address pool, address bondNft, bool indexed kycRequired)"),
(borrowFn = "uint256:poolSize");
break;
case "treasury":
(abi =
"event PoolCreated(address asset, address treasuryYieldAddress, address manager, bool kycRequired)"),
(borrowFn = "uint256:cash");
break;
}
return { borrowFn, abi };
};

const borrowed = async (api) => {
const { pools, tokens } = await _getLogs(api)
const bals = await api.multiCall({ abi: abi.borrows, calls: pools })
api.addTokens(tokens, bals)
}

module.exports[chain] = { tvl, borrowed }
})
Object.keys(config).forEach((protocol) => {
const networks = Object.keys(config[protocol]);
networks.forEach((chain) => {
const { fromBlock, factory } = config[protocol][chain];
const {abi, borrowFn} = getEventAndABI(protocol)

const tvl = async (api) => {
const { pools, tokens } = await _getLogs(api);
return api.sumTokens({ tokensAndOwners2: [tokens, pools] });
};

async function _getLogs(api) {
const logs = await getLogs({
api,
target: factory,
fromBlock,
eventAbi: abi,
onlyArgs: true,
});

const pools = logs.map((log) => protocol =='treasury'? log.treasuryYieldAddress : log.pool);
const tokens = logs.map((log) => protocol == 'dynamic' ? log.token : log.asset);
return { pools, tokens };
}

const borrowed = async (api) => {
const { pools, tokens } = await _getLogs(api);
const bals = await api.multiCall({ abi: borrowFn, calls: pools });
api.addTokens(tokens, bals);
};

module.exports[chain] = { tvl, borrowed };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module.exports[chain] = { tvl, borrowed };
module.exports[chain][protocol] = { tvl, borrowed };

});
});


module.exports.ethereum.staking = stakings(singleStakingContracts, CPOOL)
module.exports.ethereum.staking = stakings(singleStakingContracts, CPOOL);
Loading