Skip to content

Commit be0e8e3

Browse files
authored
Merge branch 'DefiLlama:main' into main
2 parents 2d1d14f + 3509689 commit be0e8e3

File tree

226 files changed

+2806
-3756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+2806
-3756
lines changed

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/0xDAO/erc20.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

projects/0xDAO/index.js

Lines changed: 51 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,209 +1,68 @@
1-
const oxLensAbi = require("./oxLens.json");
2-
const solidlyLensAbi = require("./solidlyLens.json");
3-
const veAbi = require("./ve.json");
1+
const oxLensAbi = {
2+
"oxPoolsAddresses": "address[]:oxPoolsAddresses",
3+
"oxPoolsData": "function oxPoolsData(address[] _oxPoolsAddresses) view returns (tuple(address id, address stakingAddress, uint256 stakedTotalSupply, uint256 totalSupply, tuple(address id, string symbol, bool stable, address token0Address, address token1Address, address gaugeAddress, address bribeAddress, address[] bribeTokensAddresses, address fees, uint256 totalSupply) poolData)[])"
4+
}
5+
6+
const veAbi = {
7+
"locked": "function locked(uint256) view returns (int128 amount, uint256 end)"
8+
}
9+
410
const partnerRewardsPoolAddress = "0xDA006E87DB89e1C5213D4bfBa771e53c91D920aC";
511
const oxdV1RewardsPoolAddress = "0xDA000779663501df3C9Bc308E7cEc70cE6F04211";
612
const oxSolidRewardPoolAddress = "0xDA0067ec0925eBD6D583553139587522310Bec60";
7-
const vlOxdAddress = "0xDA00527EDAabCe6F97D89aDb10395f719E5559b9";
8-
const oxdAddress = "0xc5A9848b9d145965d821AaeC8fA32aaEE026492d";
913
const solidAddress = "0x888EF71766ca594DED1F0FA3AE64eD2941740A20";
1014
const veAddress = "0xcBd8fEa77c2452255f59743f55A3Ea9d83b3c72b";
1115
const oxSolidAddress = "0xDA0053F0bEfCbcaC208A3f867BB243716734D809";
12-
const sanitize = require("./sanitizeWeb3Response.js");
13-
14-
const { standardPoolInfoAbi, addFundsInMasterChef } = require('../helper/masterchef')
15-
const sdk = require('@defillama/sdk')
1616

17-
const shareValue = "uint256:getShareValue"
18-
const xSCREAM = "0xe3D17C7e840ec140a7A51ACA351a482231760824"
19-
const xCREDIT = "0xd9e28749e80D867d5d14217416BFf0e668C10645"
20-
const shareTarot = "function shareValuedAsUnderlying(uint256 _share) returns (uint256 underlyingAmount_)"
21-
const xTAROT = "0x74D1D2A851e339B8cB953716445Be7E8aBdf92F4"
22-
23-
const fBEET = "0xfcef8a994209d6916EB2C86cDD2AFD60Aa6F54b1"
24-
25-
async function tvl(_, __, chainBlocks) {
26-
// 0xDAO Master Chef
27-
const balances = {}
28-
const chain = 'fantom'
29-
const block = chainBlocks[chain]
30-
const calldata = {
31-
chain, block
17+
const { standardPoolInfoAbi } = require('../helper/masterchef')
18+
const { sumTokens2 } = require("../helper/unwrapLPs.js");
19+
20+
async function tvl(api) {
21+
const masterchef = "0xa7821c3e9fc1bf961e280510c471031120716c3d"
22+
const oxd = "0xc165d941481e68696f43ee6e99bfb2b23e0e3114"
23+
const tokens = (await api.fetchList({ lengthAbi: 'poolLength', itemAbi: standardPoolInfoAbi, target: masterchef })).map(i => i.lpToken)
24+
await api.sumTokens({ owner: masterchef, tokens, blacklistedTokens: [oxd] })
25+
26+
// 0xDAO Core
27+
const oxLensAddress = "0xDA00137c79B30bfE06d04733349d98Cf06320e69";
28+
29+
// Fetch pools addresses
30+
const oxPoolsAddresses = await api.call({ target: oxLensAddress, abi: oxLensAbi.oxPoolsAddresses })
31+
const pageSize = 200;
32+
let currentPage = 0;
33+
34+
let addresses = []
35+
while (addresses) {
36+
const start = currentPage * pageSize;
37+
const end = start + pageSize;
38+
addresses = oxPoolsAddresses.slice(start, end);
39+
if (addresses.length === 0) {
40+
break;
3241
}
33-
const transform = addr => `fantom:${addr}`
34-
await addFundsInMasterChef(balances, "0xa7821c3e9fc1bf961e280510c471031120716c3d", block, chain,
35-
transform, standardPoolInfoAbi, [], true, true, "0xc165d941481e68696f43ee6e99bfb2b23e0e3114")
36-
37-
const screamShare = await sdk.api.abi.call({
38-
...calldata,
39-
target: xSCREAM,
40-
abi: shareValue
41-
})
42-
sdk.util.sumSingleBalance(balances, transform("0xe0654C8e6fd4D733349ac7E09f6f23DA256bF475"),
43-
screamShare.output *balances[transform(xSCREAM)] /1e18)
44-
delete balances[transform(xSCREAM)]
45-
46-
const creditShare = await sdk.api.abi.call({
47-
...calldata,
48-
target: xCREDIT,
49-
abi: shareValue
50-
})
51-
sdk.util.sumSingleBalance(balances, transform("0x77128dfdd0ac859b33f44050c6fa272f34872b5e"),
52-
creditShare.output * balances[transform(xCREDIT)] / 1e18)
53-
delete balances[transform(xCREDIT)]
54-
55-
const tarotShare = await sdk.api.abi.call({
56-
...calldata,
57-
target: xTAROT,
58-
abi: shareTarot,
59-
params: sdk.util.convertToBigInt(balances[transform(xTAROT)])
60-
})
61-
sdk.util.sumSingleBalance(balances, transform("0xc5e2b037d30a390e62180970b3aa4e91868764cd"),
62-
tarotShare.output)
63-
delete balances[transform(xTAROT)]
42+
currentPage += 1;
6443

65-
sdk.util.sumSingleBalance(balances, transform("0xf24bcf4d1e507740041c9cfd2dddb29585adce1e"),
66-
balances[transform(fBEET)])
67-
delete balances[transform(fBEET)]
44+
const poolsData = await api.call({ params: [addresses], target: oxLensAddress, abi: oxLensAbi.oxPoolsData })
45+
poolsData.forEach(pool => api.add(pool.poolData.id, pool.totalSupply))
46+
}
6847

69-
// 0xDAO Core
70-
const oxLensAddress = "0xDA00137c79B30bfE06d04733349d98Cf06320e69";
71-
const solidlyLensAddress = "0xDA0024F99A9889E8F48930614c27Ba41DD447c45";
72-
// const oxd = new web3.eth.Contract(erc20Abi, oxdAddress);
48+
// Add locked SOLID
49+
const { amount: lockedSolidAmount } = await api.call({ target: veAddress, params: 2, abi: veAbi.locked })
50+
api.add(solidAddress, lockedSolidAmount);
7351

74-
// Fetch pools addresses
75-
const { output: oxPoolsAddresses } = await sdk.api.abi.call({
76-
block,
77-
chain: 'fantom',
78-
target: oxLensAddress,
79-
abi: oxLensAbi.oxPoolsAddresses
80-
})
81-
const pageSize = 200;
82-
const poolsMap = {};
83-
let currentPage = 0;
52+
// Add staking pools TVL
53+
const oxdV1RewardsPoolBalance = await api.call({ target: oxdV1RewardsPoolAddress, abi: 'erc20:totalSupply' })
54+
const oxSolidRewardsPoolBalance = await api.call({ target: oxSolidRewardPoolAddress, abi: 'erc20:totalSupply' })
55+
const partnerRewardsPoolBalance = await api.call({ target: partnerRewardsPoolAddress, abi: 'erc20:totalSupply' })
8456

85-
// Add pools
86-
const addPools = (pools, reservesData) => {
87-
pools.forEach((pool) => {
88-
const solidlyPoolAddress = pool.poolData.id;
89-
const reserveData = reservesData.find(
90-
(data) => data.id === solidlyPoolAddress
91-
);
92-
const newPool = pool;
93-
newPool.poolData = {
94-
...pool.poolData,
95-
...reserveData,
96-
};
97-
const shareOfTotalSupply = newPool.totalSupply / newPool.poolData.totalSupply
98-
newPool.shareOfTotalSupply = shareOfTotalSupply;
99-
let token0Reserve = newPool.poolData.token0Reserve * shareOfTotalSupply
100-
let token1Reserve = newPool.poolData.token1Reserve * shareOfTotalSupply
101-
if (isNaN(token0Reserve)) {
102-
token0Reserve = "0"
103-
}
104-
if (isNaN(token1Reserve)) {
105-
token1Reserve = "0"
106-
}
107-
newPool.token0Reserve = token0Reserve;
108-
newPool.token1Reserve = token1Reserve;
109-
poolsMap[pool.id] = newPool;
110-
});
111-
};
112-
let addresses = []
113-
while (addresses) {
114-
const start = currentPage * pageSize;
115-
const end = start + pageSize;
116-
addresses = oxPoolsAddresses.slice(start, end);
117-
if (addresses.length === 0) {
118-
break;
119-
}
120-
currentPage += 1;
57+
api.add(oxSolidAddress, oxdV1RewardsPoolBalance);
58+
api.add(oxSolidAddress, partnerRewardsPoolBalance);
59+
api.add(oxSolidAddress, oxSolidRewardsPoolBalance);
12160

122-
const { output: poolsData } = await sdk.api.abi.call({
123-
block,
124-
chain: 'fantom',
125-
params: [addresses],
126-
target: oxLensAddress,
127-
abi: oxLensAbi.oxPoolsData
128-
})
129-
const solidlyPoolsAddresses = poolsData.map((pool) => pool.poolData.id);
130-
const { output: reservesData } = await sdk.api.abi.call({
131-
block,
132-
chain: 'fantom',
133-
target: solidlyLensAddress,
134-
params: [solidlyPoolsAddresses],
135-
abi: solidlyLensAbi.poolsReservesInfo
136-
})
137-
addPools(
138-
sanitize(poolsData),
139-
sanitize(reservesData)
140-
);
141-
}
142-
const pools = Object.values(poolsMap);
143-
144-
// Add TVL from pools to balances
145-
const addBalance = (tokenAddress, amount) => {
146-
const fantomTokenAddress = `fantom:${tokenAddress}`
147-
sdk.util.sumSingleBalance(balances, fantomTokenAddress, amount)
148-
}
149-
pools.forEach(pool => {
150-
const token0 = pool.poolData.token0Address;
151-
const token1 = pool.poolData.token1Address;
152-
const amount0 = pool.token0Reserve;
153-
const amount1 = pool.token1Reserve;
154-
addBalance(token0, amount0);
155-
addBalance(token1, amount1);
156-
});
157-
158-
// Add locked SOLID
159-
const { output: { amount: lockedSolidAmount } } = await sdk.api.abi.call({
160-
block,
161-
chain: 'fantom',
162-
target: veAddress,
163-
params: 2,
164-
abi: veAbi.locked
165-
})
166-
addBalance(solidAddress, lockedSolidAmount);
167-
168-
// Add staking pools TVL
169-
const { output: oxdV1RewardsPoolBalance } = await sdk.api.abi.call({
170-
block,
171-
chain: 'fantom',
172-
target: oxdV1RewardsPoolAddress,
173-
abi: 'erc20:totalSupply'
174-
})
175-
const { output: oxSolidRewardsPoolBalance } = await sdk.api.abi.call({
176-
block,
177-
chain: 'fantom',
178-
target: oxSolidRewardPoolAddress,
179-
abi: 'erc20:totalSupply'
180-
})
181-
const { output: partnerRewardsPoolBalance } = await sdk.api.abi.call({
182-
block,
183-
chain: 'fantom',
184-
target: partnerRewardsPoolAddress,
185-
abi: 'erc20:totalSupply'
186-
})
187-
188-
addBalance(oxSolidAddress, oxdV1RewardsPoolBalance);
189-
addBalance(oxSolidAddress, partnerRewardsPoolBalance);
190-
addBalance(oxSolidAddress, oxSolidRewardsPoolBalance);
191-
192-
// Add vote locked OXD
193-
const { output: voteLockedOxdBalance } = await sdk.api.abi.call({
194-
block,
195-
chain: 'fantom',
196-
target: oxdAddress,
197-
params: vlOxdAddress,
198-
abi: 'erc20:balanceOf'
199-
})
200-
addBalance(oxdAddress, voteLockedOxdBalance);
201-
202-
return balances
61+
return sumTokens2({ api, resolveLP: true, })
20362
}
20463

20564
module.exports = {
206-
fantom: {
207-
tvl
208-
}
65+
fantom: {
66+
tvl
67+
}
20968
}

projects/0xDAO/oxLens.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

projects/0xDAO/sanitizeWeb3Response.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

projects/0xDAO/solidlyLens.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

projects/0xDAO/ve.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

projects/2pi/index.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ const fetchChainAddresses = async chain => {
1515
return getUniqueAddresses(archimedes)
1616
}
1717

18-
const fetchTvl = chain => {
19-
return async (api) => {
20-
const addresses = await fetchChainAddresses(chains[chain])
21-
let pools = await Promise.all(addresses.map(i => api.fetchList({ withMetadata: true, target: i, lengthAbi: archimedesAbi['poolLength'], itemAbi: archimedesAbi['poolInfo'] })))
22-
pools = pools.flat()
23-
const wantTokens = pools.map(i => i.output.want)
24-
const calls = pools.map(i => i.input)
25-
const bal = await api.multiCall({ abi: archimedesAbi.balance, calls, })
26-
api.add(wantTokens, bal)
18+
const tvl = async (api) => {
19+
const addresses = await fetchChainAddresses(chains[api.chain])
20+
const res = await api.fetchList({ lengthAbi: 'poolLength', itemAbi: archimedesAbi['poolInfo'], calls: addresses, groupedByInput: true })
21+
const calls = []
22+
const tokens = []
23+
for (let i = 0; i < res.length; i++) {
24+
const pool = addresses[i]
25+
for (let j = 0; j < res[i].length; j++) {
26+
calls.push({ target: pool, params: j })
27+
tokens.push(res[i][j].want)
28+
}
2729
}
30+
console.log(res, api.chain)
31+
const bals = await api.multiCall({ abi: archimedesAbi.balance, calls})
32+
api.add(tokens, bals)
2833
}
2934

30-
module.exports = {
31-
timetravel: false,
32-
...Object.fromEntries(
33-
Object.keys(chains).map(chain => [
34-
chain, { tvl: fetchTvl(chain) }
35-
])
36-
)
37-
}
35+
36+
Object.keys(chains).forEach(chain => {
37+
module.exports[chain] = { tvl }
38+
})

0 commit comments

Comments
 (0)