Skip to content

Commit dffc59d

Browse files
authored
Fix: notional-v3 (#17034)
1 parent 56ad412 commit dffc59d

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

projects/notional-v3/index.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
const { sumTokens2 } = require('../helper/unwrapLPs');
2-
const abi = require('../notional/abi');
32
const { cachedGraphQuery } = require('../helper/cache')
43

5-
const SUBGRAPHS = {
6-
arbitrum: 'DnghsCNvJ4xmp4czX8Qn7UpkJ8HyHjy7cFN4wcH91Nrx',
7-
ethereum: '4oVxkMtN4cFepbiYrSKz1u6HWnJym435k5DQRAFt2vHW'
8-
};
9-
const vaultsQuery = `{ vaultConfigurations { id } }`
4+
const CONFIG = {
5+
ethereum: { endpoint: '4oVxkMtN4cFepbiYrSKz1u6HWnJym435k5DQRAFt2vHW', contract: '0x6e7058c91F85E0F6db4fc9da2CA41241f5e4263f'},
6+
arbitrum: { endpoint: 'DnghsCNvJ4xmp4czX8Qn7UpkJ8HyHjy7cFN4wcH91Nrx', contract: '0x1344A36A1B56144C3Bc62E7757377D288fDE0369'},
7+
}
8+
9+
const payload = `{ vaultConfigurations { id } }`
1010

11-
const CONTRACTS = {
12-
arbitrum: "0x1344A36A1B56144C3Bc62E7757377D288fDE0369",
13-
ethereum: "0x6e7058c91F85E0F6db4fc9da2CA41241f5e4263f"
11+
const abi = {
12+
getMaxCurrencyId: "function getMaxCurrencyId() view returns (uint16)",
13+
getCurrency: "function getCurrency(uint16) view returns ((address,bool,int256,uint8,uint256),(address,bool,int256,uint8,uint256))",
14+
getPrimeCashHoldingsOracle: "function getPrimeCashHoldingsOracle(uint16) view returns (address)",
15+
currencyIdToAddress: "function currencyIdToAddress(uint16) view returns (address)"
1416
}
1517

16-
async function addVaultTvl(api) {
17-
let { vaultConfigurations } = await cachedGraphQuery(`notional-v3/${api.chain}`, SUBGRAPHS[api.chain], vaultsQuery)
18+
async function addVaultTvl(api, endpoint) {
19+
const { vaultConfigurations } = await cachedGraphQuery(`notional-v3/${api.chain}`, endpoint, payload)
1820
const vaults = vaultConfigurations.map(i => i.id)
1921
const abi = "function getStrategyVaultInfo() view returns ((address pool, uint8 singleSidedTokenIndex, uint256 totalLPTokens, uint256 totalVaultShares, uint256 maxPoolShare, uint256 oraclePriceDeviationLimitPercent))"
2022
const data = await api.multiCall({ abi, calls: vaults, permitFailure: true })
2123
data.forEach(i => i && api.add(i.pool, i.totalLPTokens))
2224
}
2325

24-
async function tvl(api) {
25-
let oracles = await api.fetchList({ lengthAbi: abi.getMaxCurrencyId, itemAbi: abi.getPrimeCashHoldingsOracle, target: CONTRACTS[api.chain], startFromOne: true, })
26-
let underlying = await api.multiCall({ abi: 'address:underlying', calls: oracles.map((o) => ({ target: o })) })
27-
let holdings = await api.multiCall({ abi: 'address[]:holdings', calls: oracles.map((o) => ({ target: o })) })
28-
let tokens = underlying.concat(holdings.flatMap((_) => _))
29-
await addVaultTvl(api)
30-
return sumTokens2({ tokens, owner: CONTRACTS[api.chain], api })
26+
const getArbTvl = async (api, contract) => {
27+
const tokens = await api.fetchList({ itemCount: 15, itemAbi: abi.currencyIdToAddress, target: contract, startFromOne: true })
28+
return sumTokens2({ tokens, owner: contract, api })
29+
}
30+
31+
const tvl = async (api) => {
32+
const chain = api.chain
33+
const { contract, endpoint } = CONFIG[chain]
34+
if (chain === 'arbitrum') return getArbTvl(api, contract)
35+
const oracles = await api.fetchList({ lengthAbi: abi.getMaxCurrencyId, itemAbi: abi.getPrimeCashHoldingsOracle, target: contract, startFromOne: true, })
36+
const underlying = await api.multiCall({ abi: 'address:underlying', calls: oracles.map((o) => ({ target: o })), permitFailure: true })
37+
const holdings = await api.multiCall({ abi: 'address[]:holdings', calls: oracles.map((o) => ({ target: o })), permitFailure: true })
38+
const tokens = underlying.concat(holdings.flatMap((_) => _))
39+
await addVaultTvl(api, endpoint)
40+
return sumTokens2({ tokens, owner: contract, api })
3141
}
3242

33-
module.exports = {
34-
arbitrum: { tvl },
35-
ethereum: { tvl }
36-
};
43+
Object.keys(CONFIG).forEach((chain) => {
44+
module.exports[chain] = { tvl }
45+
})

0 commit comments

Comments
 (0)