Skip to content

Commit 0e255e1

Browse files
authored
Merge pull request DefiLlama#3648 from DefiLlama/move-transformCode
code refactor
2 parents b38bfbc + 32f59e4 commit 0e255e1

File tree

41 files changed

+1888
-2857
lines changed

Some content is hidden

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

41 files changed

+1888
-2857
lines changed

projects/KibbleSwap/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
factory: '0xF4bc79D32A7dEfd87c8A9C100FD83206bbF19Af5',
1414
blacklist: [
1515
'0xe52CE89E16c4C596D30D111f3b5c137da412dEb8',
16+
'0xbe14fbbccd4587b276549e734cc80294fc4b0f83',
1617
]
1718
}),
1819
staking: staking({

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/blueshift/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const sdk = require('@defillama/sdk');
22
const { default: BigNumber } = require('bignumber.js');
3-
const { transformMilkomedaAddress } = require('../helper/portedTokens');
3+
const { getChainTransform } = require('../helper/portedTokens');
44

55
const abi = require('./abi.json');
66

@@ -13,7 +13,7 @@ const BLUESHIFT_INDEX_PORTFOLIO = '0xB2A76Ce2D5eD32aD7F8B93a1098C1Fee473e27bA';
1313

1414
async function staking(timestamp, block, chainBlocks) {
1515
const balances = {};
16-
const transform = await transformMilkomedaAddress();
16+
const transform = await getChainTransform('milkomeda');
1717

1818
const value = (await sdk.api.abi.call({
1919
abi: abi.BlueshiftEarning.getAccDeposit,
@@ -62,7 +62,7 @@ async function staking(timestamp, block, chainBlocks) {
6262

6363
async function tvl(timestamp, block, chainBlocks) {
6464
const balances = {};
65-
const transform = await transformMilkomedaAddress();
65+
const transform = await getChainTransform('milkomeda');
6666

6767
const portfolios = (await sdk.api.abi.call({
6868
abi: abi.BlueshiftRegistry.getPortfolios,

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/earnifty/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const sdk = require('@defillama/sdk');
22
const vaultContractABI = require("./abis/vault.json");
3-
const { transformVelasAddress } = require('../helper/portedTokens');
3+
const { getChainTransform } = require('../helper/portedTokens');
44
const { unwrapUniswapLPs } = require('../helper/unwrapLPs');
55
const vaults_info = require('./vaults_info.json');
66

77

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

1212
for (const info of vaults_info) {
1313
const balance = ((await sdk.api.abi.call({

projects/elephantdex/index.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
1-
const { getBlock } = require("../helper/getBlock");
2-
const { transformHarmonyAddress } = require("../helper/portedTokens");
3-
const { calculateUniTvl } = require("../helper/calculateUniTvl");
41
const { getUniTVL } = require("../helper/unknownTokens");
52

6-
const wONE = "bsc:0xdE976f3344cd9F06E451aF3A94a324afC3E154F4";
7-
async function tvl(timestamp, block, chainBlocks) {
8-
block = await getBlock(timestamp, "harmony", chainBlocks);
9-
const transform = await transformHarmonyAddress();
10-
11-
let balances = await calculateUniTvl(
12-
transform,
13-
block,
14-
"harmony",
15-
"0x0Dea90EC11032615E027664D2708BC292Bbd976B",
16-
18105518,
17-
true
18-
);
19-
20-
balances["harmony"] = balances[wONE] / 10 ** 18;
21-
delete balances[wONE];
22-
return balances;
23-
}
24-
253
module.exports = {
264
harmony: {
275
tvl: getUniTVL({

0 commit comments

Comments
 (0)