Skip to content

Commit 9468ffc

Browse files
committed
code refactor
1 parent d8dac9c commit 9468ffc

File tree

10 files changed

+1451
-2061
lines changed

10 files changed

+1451
-2061
lines changed

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/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({

projects/helper/portedTokens.js

Lines changed: 43 additions & 1962 deletions
Large diffs are not rendered by default.

projects/helper/tokenMapping.js

Lines changed: 1389 additions & 0 deletions
Large diffs are not rendered by default.

projects/klap/index.js

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,9 @@
11
const { aaveChainTvl } = require("../helper/aave");
2-
const { getFixBalances } = require("../helper/portedTokens");
3-
4-
async function transformKlaytnAddress() {
5-
const mapping = {
6-
"0x5388ce775de8f7a69d17fd5caa9f7dbfee65dfce":
7-
"0x4576E6825B462b6916D2a41E187626E9090A92c6", // Donkey
8-
"0x9eaefb09fe4aabfbe6b1ca316a3c36afc83a393f": "ripple", // XRP
9-
"0x02cbe46fb8a1f579254a9b485788f2d86cad51aa":
10-
"0x26fb86579e371c7aedc461b2ddef0a8628c93d3b", // bora
11-
"0x078dB7827a5531359f6CB63f62CFA20183c4F10c":
12-
"0x6b175474e89094c44da98b954eedeac495271d0f", // dai
13-
"0x6270B58BE569a7c0b8f47594F191631Ae5b2C86C":
14-
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
15-
"0x0268dbed3832b87582b1fa508acf5958cbb1cd74":
16-
"bsc:0xf258f061ae2d68d023ea6e7cceef97962785c6c1", // IJM
17-
"0xd6dAb4CfF47dF175349e6e7eE2BF7c40Bb8C05A3":
18-
"0xdac17f958d2ee523a2206206994597c13d831ec7", // USDT
19-
"0x168439b5eebe8c83db9eef44a0d76c6f54767ae4":
20-
"0x6b175474e89094c44da98b954eedeac495271d0f", // pUSD
21-
"0x4fa62f1f404188ce860c8f0041d6ac3765a72e67":
22-
"0x6b175474e89094c44da98b954eedeac495271d0f", // KSD
23-
"0xce40569d65106c32550626822b91565643c07823":
24-
"0x6b175474e89094c44da98b954eedeac495271d0f", // KASH
25-
"0x210bc03f49052169d5588a52c317f71cf2078b85":
26-
"bsc:0xe9e7cea3dedca5984780bafc599bd69add087d56", // kBUSD
27-
"0xDCbacF3f7a069922E677912998c8d57423C37dfA":
28-
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599", // WBTC
29-
"0xCD6f29dC9Ca217d0973d3D21bF58eDd3CA871a86":
30-
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH
31-
"0xe4f05A66Ec68B54A58B17c22107b02e0232cC817": "0xe4f05a66ec68b54a58b17c22107b02e0232cc817" // Klaytn
32-
};
33-
return addr => {
34-
const mappingResult = mapping[addr]
35-
addr = addr.toLowerCase();
36-
return mappingResult || `klaytn:${addr}`;
37-
};
38-
}
2+
const { getFixBalances, getChainTransform } = require("../helper/portedTokens");
393

404
function lending(borrowed) {
415
return async (timestamp, ethBlock, chainBlocks) => {
42-
const transform = await transformKlaytnAddress();
6+
const transform = await getChainTransform('klaytn');
437
const balances = await aaveChainTvl(
448
"klaytn",
459
"0x969E4A05c2F3F3029048e7943274eC2E762497AB",

projects/pegasusdao.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { tombTvl } = require("./helper/tomb");
22
const sdk = require("@defillama/sdk");
3-
const { transformCronosAddress } = require("./helper/portedTokens");
4-
const { unwrapUniswapLPs } = require('./helper/unwrapLPs');
3+
const { getChainTransform } = require("./helper/portedTokens");
4+
const { unwrapUniswapLPs, unwrapLPsAuto } = require('./helper/unwrapLPs');
55

66
const PES = "0x8efbaa6080412d7832025b03b9239d0be1e2aa3b";
77
const SPES = "0xBBd4650EeA85f9DBd83d6Fb2a6E8B3d8f32FE1C5";
@@ -38,7 +38,7 @@ function addToExports(chain, key, fn) {
3838

3939
async function tvl(timestamp, block, chainBlocks) {
4040
const balances = {};
41-
const transform = await transformCronosAddress();
41+
const transform = await getChainTransform('cronos');
4242
const result = await sdk.api.abi.multiCall({
4343
calls: genesisTokens.map((t) => ({
4444
target: t,
@@ -64,7 +64,7 @@ async function tvl(timestamp, block, chainBlocks) {
6464
);
6565

6666
delete balances[`cronos:${PES}`];
67-
67+
await unwrapLPsAuto({ balances, block: chainBlocks.cronos, chain: 'cronos', })
6868
return balances;
6969
};
7070

projects/solv-protocol/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { sumTokens, } = require('../helper/unwrapLPs')
22
const axios = require('axios')
33
const { staking } = require('../helper/staking');
4-
const { transformBscAddress, transformEthereumAddress, transformPolygonAddress, transformArbitrumAddress } = require("../helper/portedTokens");
4+
const { getChainTransform } = require("../helper/portedTokens");
55

66
// token list
77
const tokenListsApiEndpoint = "https://token-list.solv.finance/vouchers-prod.json"
@@ -13,22 +13,22 @@ const solvBscTokenAddress = '0xC073c4eD65622A9423b5e5BDe2BFC8B81EBC471c'
1313
const solvBscPoolAddress = '0xE5742912EDb4599779ACC1CE2acB6a06E01f1089'
1414

1515
const ethereumTVL = async (timestamp, block, chainBlocks) => {
16-
const transform = await transformEthereumAddress();
16+
const transform = await getChainTransform('ethereum');
1717
return tvl(timestamp, block, chainBlocks, "ethereum", 1, transform);
1818
}
1919

2020
const polygonTVL = async (timestamp, block, chainBlocks) => {
21-
const transform = await transformPolygonAddress();
21+
const transform = await getChainTransform('polygon');
2222
return tvl(timestamp, block, chainBlocks, "polygon", 137, transform);
2323
}
2424

2525
const arbitrumTVL = async (timestamp, block, chainBlocks) => {
26-
const transform = await transformArbitrumAddress();
26+
const transform = await getChainTransform('arbitrum');
2727
return tvl(timestamp, block, chainBlocks, "arbitrum", 42161, transform);
2828
};
2929

3030
const bscTVL = async (timestamp, block, chainBlocks) => {
31-
const transform = await transformBscAddress();
31+
const transform = await getChainTransform('bsc');
3232
return tvl(timestamp, block, chainBlocks, "bsc", 56, transform);
3333
};
3434

projects/symbiosis-finance/index.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
const sdk = require('@defillama/sdk');
22
const {
3-
transformBscAddress,
4-
transformAvaxAddress,
5-
transformPolygonAddress,
6-
transformBobaAddress,
7-
transformAuroraAddress,
8-
transformTelosAddress
3+
getChainTransform,
94
} = require('../helper/portedTokens');
105

116
const getTokenAbi = require("./abi/getToken.json");
127
const getTokenBalanceAbi = require("./abi/getTokenBalance.json");
13-
const BigNumber = require("bignumber.js");
148

159
const config = {
1610
chains: [
@@ -84,23 +78,7 @@ const config = {
8478
}
8579

8680
async function getTransform(chainName) {
87-
let transform = (address) => {
88-
return address
89-
}
90-
if (chainName === 'bsc') {
91-
transform = await transformBscAddress();
92-
} else if (chainName === 'avax') {
93-
transform = await transformAvaxAddress();
94-
} else if (chainName === 'polygon') {
95-
transform = await transformPolygonAddress();
96-
} else if (chainName === 'boba') {
97-
transform = await transformBobaAddress();
98-
} else if (chainName === 'aurora') {
99-
transform = await transformAuroraAddress();
100-
} else if (chainName === 'telos') {
101-
transform = await transformTelosAddress();
102-
}
103-
return transform
81+
return getChainTransform(chainName)
10482
}
10583

10684
async function tvl(chainName, timestamp, block, chainBlocks) {

projects/waves-exchange/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { sumSingleBalance } = require('@defillama/sdk/build/generalUtil')
22
const { get } = require('../helper/http')
3-
const { wavesMapping } = require('../helper/portedTokens')
3+
const { fixBalancesTokens: { waves: wavesMapping } } = require('../helper/tokenMapping')
44

55

66
const endpoint = "https://waves.exchange/api/v1/liquidity_pools/stats"

0 commit comments

Comments
 (0)