Skip to content

Update Centrifuge #15700

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

Merged
merged 2 commits into from
Jul 29, 2025
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
72 changes: 60 additions & 12 deletions projects/centrifuge/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
const ADDRESSES = require('../helper/coreAssets.json')

const nullAddress = ADDRESSES.null

const CONFIG = {
ethereum: {
factory: { START_BLOCK: 20432393, TOKEN_FACTORY: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' },
assets: { USDC: ADDRESSES.ethereum.USDC },
factories : [
{ START_BLOCK: 20432393, TOKEN_FACTORY_V2: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' }, // v2
{ START_BLOCK: 22924277, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
],
assets: { USDC: ADDRESSES.ethereum.USDC }
},
base: {
factory: { START_BLOCK: 17854404, TOKEN_FACTORY: '0x7f192F34499DdB2bE06c4754CFf2a21c4B056994' },
factories : [
{ START_BLOCK: 17854404, TOKEN_FACTORY_V2: '0x7f192F34499DdB2bE06c4754CFf2a21c4B056994' }, // v2
{ START_BLOCK: 32901390, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
],
assets: { USDC: ADDRESSES.base.USDC }
},
arbitrum: {
factory: { START_BLOCK: 238245701, TOKEN_FACTORY: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' },
factories : [
{ START_BLOCK: 238245701, TOKEN_FACTORY_V2: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' }, // v2
{ START_BLOCK: 357984300, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
],
assets: { USDC: ADDRESSES.arbitrum.USDC_CIRCLE }
},
avax: {
factories : [
{ START_BLOCK: 65493376, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
],
assets: { USDC: ADDRESSES.avax.USDC }
},
bsc: {
factories : [
{ START_BLOCK: 54801665, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
],
assets: { USDC: ADDRESSES.bsc.USDC }
},
plume_mainnet: {
factories : [
{ START_BLOCK: 15715268, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
],
assets: { USDC: ADDRESSES.plume_mainnet.USDC_e }
},
}

const abis = {
Expand All @@ -21,20 +50,39 @@ const abis = {
};

const eventAbis = {
deployTranches: 'event DeployTranche(uint64 indexed poolId, bytes16 indexed trancheId, address indexed tranche)'
deployTranches: 'event DeployTranche(uint64 indexed poolId, bytes16 indexed trancheId, address indexed tranche)',
addShareClass: 'event AddShareClass(uint64 indexed poolId, bytes16 indexed scId, address token)'
}

const getTokens = async (api, block, START_BLOCK, TOKEN_FACTORY) => {
const tranches = await api.getLogs({ target: TOKEN_FACTORY, fromBlock: START_BLOCK, toBlock: block, eventAbi: eventAbis.deployTranches, onlyArgs: true })
return tranches.map(({ tranche }) => tranche)
}
const getTokens = async (api, block, factories) => {
const logs = await Promise.all(
factories.map(async (factory) => {
let allTranches = []

if (factory.TOKEN_FACTORY_V2) {
const tranches = await api.getLogs({ target: factory.TOKEN_FACTORY_V2, fromBlock: factory.START_BLOCK, toBlock: block, eventAbi: eventAbis.deployTranches, onlyArgs: true })
allTranches.push(...tranches.map(({ tranche }) => tranche))
}

if (factory.TOKEN_FACTORY_V3) {
const shareClasses = await api.getLogs({ target: factory.TOKEN_FACTORY_V3, fromBlock: factory.START_BLOCK, toBlock: block, eventAbi: eventAbis.addShareClass, onlyArgs: true })
allTranches.push(...shareClasses.map(({ token }) => token))
}

return allTranches
})
)

return [...new Set(logs.flat())]
}

const tvl = async (api) => {
const chain = api.chain
const block = await api.getBlock() - 100
const { factory: { START_BLOCK, TOKEN_FACTORY }, assets: { USDC } } = CONFIG[chain]
const tokens = await getTokens(api, block, START_BLOCK, TOKEN_FACTORY)
const vaults = await api.multiCall({ calls: tokens.map((t) => ({ target: t, params: [USDC] })), abi: abis.getVault })
const { factories, assets: { USDC } } = CONFIG[chain]
const tokens = await getTokens(api, block, factories)
if (!tokens) return;
const vaults = (await api.multiCall({ calls: tokens.map((t) => ({ target: t, params: [USDC] })), abi: abis.getVault })).filter(addr => addr.toLowerCase() !== nullAddress)
await api.erc4626Sum({ calls: vaults, tokenAbi: 'address:asset', balanceAbi: 'uint256:totalAssets' })
}

Expand Down
Loading