Skip to content

Commit 7563034

Browse files
committed
more fixes
1 parent 9468ffc commit 7563034

File tree

30 files changed

+112
-437
lines changed

30 files changed

+112
-437
lines changed

projects/agora/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
const sdk = require("@defillama/sdk");
22
const { compoundExports } = require("../helper/compound");
3-
const { transformMetisAddress } = require("../helper/portedTokens");
43
const {calculateUsdUniTvl} = require('../helper/getUsdUniTvl.js')
54

6-
7-
85
const factory = '0x3c4063B964B1b3bF229315fCc4df61a694B0aE84'
96
const metis = '0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000'
107
const agora = '0x0Ed0Ca6872073E02cd3aE005BaF04bA43BE947fA'
@@ -25,15 +22,14 @@ const { tvl: agoraTvl, borrowed: agoraBorrowed } = compoundExports(
2522
"metis",
2623
"0xcFd482DcE13cA1d27834D381AF1b570E9E6C6810",
2724
metis,
28-
transformMetisAddress(),
2925
);
3026

3127
const { tvl: agoraPlusTvl, borrowed: agoraPlusBorrowed } = compoundExports(
3228
"0x92DcecEaF4c0fDA373899FEea00032E8E8Da58Da",
3329
"metis",
3430
"0xE85A1ae1A2A21135c49ADEd398D3FD5Ed032B28e",
3531
metis,
36-
transformMetisAddress(),
32+
undefined,
3733
symbol => symbol.indexOf('appuffNetswap') > -1
3834
);
3935

@@ -42,15 +38,15 @@ const { tvl: agoraStakeTvl, borrowed: agoraStakeBorrowed } = compoundExports(
4238
"metis",
4339
"0xc3034143816398d37Ec9447c9CA17c407e96Dc12",
4440
metis,
45-
transformMetisAddress(),
41+
undefined,
4642
);
4743

4844
const { tvl: agoraFarmTvl, borrowed: agoraFarmBorrowed } = compoundExports(
4945
"0xEC1A06f320E6e295Ab6892BB4e0f9e29c712F11F",
5046
"metis",
5147
"0x13Cb104a1D94A89a260b27DfAAB07C862da622E5",
5248
metis,
53-
transformMetisAddress(),
49+
undefined,
5450
);
5551

5652
const chainTvl = calculateUsdUniTvl(

projects/avalaunch/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const sdk = require('@defillama/sdk')
22
const { unwrapUniswapLPs } = require('../helper/unwrapLPs')
3-
const {fixAvaxBalances} = require('../helper/portedTokens')
43

54
const xavaAddress = "0xd1c3f94DE7e5B45fa4eDBBA472491a9f4B166FC4";
65
const stakingContracts = [
@@ -26,7 +25,6 @@ async function pool2(timestamp, ethBlock, chainBlocks){
2625
token: lp,
2726
balance: lpLocked.output
2827
}], block, 'avax', addr=>`avax:${addr}`);
29-
fixAvaxBalances(balances);
3028
return balances;
3129
};
3230
async function staking(timestamp, ethBlock, chainBlocks){

projects/bodhfinance/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
const { compoundExports } = require('../helper/compound')
2-
const { transformBobaAddress } = require('../helper/portedTokens')
32

43
const WETH = "0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000"
54
const bETH = "0xe970c37243F3d0B2AeB041b855Ef6466CB140BcA"
65
const unitroller = "0x97b491744587d05ca33e84bB18B61Df9B3986DcE"
76

87
const { tvl, borrowed } = compoundExports(
9-
unitroller, "boba", bETH, WETH, transformBobaAddress(),
10-
);
8+
unitroller, "boba", bETH, WETH, );
119

1210
module.exports = {
1311
timetravel: true,

projects/demeter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const retry = require('./helper/retry')
22
const axios = require("axios");
33
const sdk = require('@defillama/sdk');
4-
const { transformHecoAddress } = require('./helper/portedTokens');
4+
const { getChainTransform } = require('./helper/portedTokens');
55
const { unwrapUniswapLPs } = require("./helper/unwrapLPs");
66
const { getBlock } = require('./helper/getBlock')
77

88
async function tvl(timestamp, block, chainBlocks) {
99
let balances = {};
10-
const transform = await transformHecoAddress();
10+
const transform = await getChainTransform('heco');
1111

1212
let liquidity = (await retry(async bail =>
1313
await axios.get('https://demeter.xyz/app/api/market_global_data', {
@@ -27,7 +27,7 @@ async function tvl(timestamp, block, chainBlocks) {
2727

2828
async function staking(timestamp, block, chainBlocks) {
2929
let balances = {};
30-
const transform = await transformHecoAddress();
30+
const transform = await getChainTransform('heco');
3131
block = await getBlock(timestamp, 'heco', chainBlocks);
3232

3333
let liquidity = (await retry(async bail =>

projects/domfi/index.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const sdk = require("@defillama/sdk");
2-
const { sumTokens, unwrapUniswapLPs } = require("../helper/unwrapLPs");
3-
const { transformPolygonAddress, transformBobaAddress } = require("../helper/portedTokens");
2+
const { sumTokens, } = require("../helper/unwrapLPs");
3+
const { getChainTransform } = require("../helper/portedTokens");
44
const { getBlock } = require("../helper/getBlock");
55
const abi = require("./abi");
66
const { Chain, lsps, uniswapFactory, ZERO_ADDRESS, usdc } = require("./registry");
77

88
const makeUniswapReserves = (chain, makeAddressTransform) => {
99
return async (timestamp, block, chainBlocks) => {
1010
const balances = {};
11-
const transform = await makeAddressTransform?.();
11+
const transform = await getChainTransform(chain);
1212
block = await getBlock(timestamp, chain, chainBlocks);
1313

1414
const getLongToken = abi["LongShortPair.longToken"];
@@ -78,7 +78,7 @@ const makeUniswapReserves = (chain, makeAddressTransform) => {
7878
const makeLspTvl = (chain, makeAddressTransform) => {
7979
return async (timestamp, block, chainBlocks) => {
8080
const balances = {};
81-
const transform = await makeAddressTransform?.();
81+
const transform = await getChainTransform(chain);
8282
block = await getBlock(timestamp, chain, chainBlocks);
8383

8484
const getCollateralToken = abi["LongShortPair.collateralToken"];
@@ -104,15 +104,8 @@ const makeLspTvl = (chain, makeAddressTransform) => {
104104
}
105105
}
106106

107-
const transformers = {
108-
[Chain.ETHEREUM]: undefined,
109-
[Chain.POLYGON]: transformPolygonAddress,
110-
[Chain.BOBA]: transformBobaAddress,
111-
}
112-
113107
const run = (chain, f) => {
114-
const transform = transformers[chain];
115-
return f(chain, transform);
108+
return f(chain);
116109
}
117110

118111
const runAll = (chain, fs) => {

projects/drachma/index.js

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const sdk = require("@defillama/sdk");
2-
const { transformMetisAddress } = require("../helper/portedTokens");
32
const contracts = require('./contracts.json');
3+
const { sumTokens2 } = require('../helper/unwrapLPs')
44

55
const { compoundExports } = require("../helper/compound");
66
const comptroller = "0xB6ef08Ffbbb0691a3D9E6c41db4b1d2F97D8D49a";
@@ -14,37 +14,10 @@ const { tvl: drachmaTvl, borrowed: drachmaBorrowed } = compoundExports(
1414
//tvl for drachma app
1515
function tvl(chain) {
1616
return async (timestamp, block, chainBlocks) => {
17-
const transform = await transformMetisAddress()
18-
const balances = {};
19-
20-
const [tokenBalances, usdcBalances] = await Promise.all([
21-
sdk.api.abi.multiCall({
22-
calls: contracts[chain].map((c) => ({
23-
target: c.token,
24-
params: [c.address],
25-
})),
26-
abi: "erc20:balanceOf",
27-
block: chainBlocks[chain],
28-
chain,
29-
}),
30-
31-
sdk.api.abi.multiCall({
32-
calls: contracts[chain].map((c) => ({
33-
target: contracts.usdc[chain],
34-
params: [c.address],
35-
})),
36-
abi: "erc20:balanceOf",
37-
block: chainBlocks[chain],
38-
chain,
39-
}),
40-
]);
41-
42-
await Promise.all([
43-
sdk.util.sumMultiBalanceOf(balances, tokenBalances, true, transform),
44-
sdk.util.sumMultiBalanceOf(balances, usdcBalances, true, transform),
45-
]);
46-
47-
return balances;
17+
const toa = []
18+
toa.push(...contracts[chain].map(c => ([c.token, c.address])))
19+
toa.push(...contracts[chain].map(c => ([contracts.usdc[chain], c.address])))
20+
return sumTokens2({ chain, tokensAndOwners: toa, block: chainBlocks[chain], resolveLP: true, })
4821
};
4922
};
5023

projects/farmhero/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const { stakings } = require("../helper/staking");
44
const { pool2s } = require("../helper/pool2");
55
const { unwrapUniswapLPs } = require("../helper/unwrapLPs");
66
const {
7-
transformBscAddress,
8-
transformPolygonAddress,
9-
transformOkexAddress,
7+
getChainTransform,
108
} = require("../helper/portedTokens");
119

1210
// --- BSC Addresses ---
@@ -204,7 +202,7 @@ const calcTvl = async (
204202
const bscTvl = async (chainBlocks) => {
205203
const balances = {};
206204

207-
const transformAddress = await transformBscAddress();
205+
const transformAddress = await getChainTransform('bsc');
208206

209207
await calcTvl(
210208
balances,
@@ -221,7 +219,7 @@ const bscTvl = async (chainBlocks) => {
221219
const polygonTvl = async (chainBlocks) => {
222220
const balances = {};
223221

224-
const transformAddress = await transformPolygonAddress();
222+
const transformAddress = await getChainTransform('polygon');
225223

226224
await calcTvl(
227225
balances,
@@ -238,7 +236,7 @@ const polygonTvl = async (chainBlocks) => {
238236
const okexTvl = async (chainBlocks) => {
239237
const balances = {};
240238

241-
const transformAddress = await transformOkexAddress();
239+
const transformAddress = await getChainTransform('okexchain');
242240

243241
await calcTvl(
244242
balances,

projects/fountain.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
const { compoundExports } = require("./helper/compound");
2-
const { transformOasisAddressBase } = require('./helper/portedTokens')
32

43
module.exports = {
54
timetravel: true,
6-
aurora: {
5+
oasis: {
76
...compoundExports(
87
'0xA7684aE7e07Dac91113900342b3ef25B9Fd1D841',
98
'oasis',
109
'0xD7d588bAbFb99E82Cd6dd0cA7677A5599AA678B5',
1110
'0x21C718C22D52d0F3a789b752D4c2fD5908a8A733',
12-
transformOasisAddressBase,
1311
)
1412
},
1513
}; // node test.js projects/fountain.js

projects/helper/compound.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const abi = require('./abis/compound.json');
44
const { getBlock } = require('./getBlock');
55
const { unwrapUniswapLPs } = require('./unwrapLPs');
66
const { requery } = require("./requery");
7-
const { getUniqueAddresses } = require("./utils");
8-
const { transformMetisAddress, getChainTransform, getFixBalances, } = require('./portedTokens');
7+
const { getChainTransform, getFixBalances, } = require('./portedTokens');
98
const { usdtAddress } = require('./balances');
109
const agoraAbi = require("./../agora/abi.json");
1110
// ask comptroller for all markets array
@@ -97,8 +96,7 @@ async function unwrapPuffTokens(balances, lpPositions, block) {
9796
balances,
9897
newLpPositions,
9998
block,
100-
'metis',
101-
transformMetisAddress()
99+
'metis'
102100
);
103101
};
104102

@@ -270,11 +268,11 @@ function compoundExports(comptroller, chain, cether, cetheEquivalent, transformA
270268
function compoundExportsWithAsyncTransform(comptroller, chain, cether, cetheEquivalent, transformAdressConstructor) {
271269
return {
272270
tvl: async (...args) => {
273-
const transformAddress = await transformAdressConstructor()
271+
const transformAddress = await getChainTransform(chain)
274272
return getCompoundV2Tvl(comptroller, chain, transformAddress, cether, cetheEquivalent)(...args)
275273
},
276274
borrowed: async (...args) => {
277-
const transformAddress = await transformAdressConstructor()
275+
const transformAddress = await getChainTransform(chain)
278276
return getCompoundV2Tvl(comptroller, chain, transformAddress, cether, cetheEquivalent, true)(...args)
279277
},
280278
}

projects/helper/hodltree/calculateBalances.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {
55
polygonContracts,
66
dexTypes
77
} = require('../../config/hodltree');
8-
const { transformPolygonAddress, transformEthereumAddress } = require('../portedTokens');
8+
const { getChainTransform } = require('../portedTokens');
99
const { calculateEM } = require('./calculateEM');
1010
const { calculateFlashloan } = require('./calculateFlashloan');
1111
const { calculateLendBorrow } = require('./calculateLendBorrow');
@@ -38,12 +38,12 @@ async function calculateHodltreeBalances(dexes, chain, chainBlocks, transform) {
3838
}
3939

4040
async function calculateHodltreeBalancesEth(timestamp, block, chainBlocks) {
41-
const transform = await transformEthereumAddress();
41+
const transform = await getChainTransform('ethereum');
4242
return calculateHodltreeBalances(ethContracts, 'ethereum', chainBlocks, transform);
4343
}
4444

4545
async function calculateHodltreeBalancesPolygon(timestamp, block, chainBlocks) {
46-
const transform = await transformPolygonAddress()
46+
const transform = await getChainTransform('polygon')
4747
return calculateHodltreeBalances(polygonContracts, 'polygon', chainBlocks, transform);
4848

4949
}

0 commit comments

Comments
 (0)