Skip to content

Commit 9217468

Browse files
committed
minor fix
1 parent aaaeafd commit 9217468

File tree

3 files changed

+28
-276
lines changed

3 files changed

+28
-276
lines changed

projects/cyclefinance/index.js

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const sdk = require("@defillama/sdk");
21
const abi = require("./abi.json");
32
const { sumTokens2 } = require("../helper/unwrapLPs");
43

@@ -88,51 +87,21 @@ const vaults = [
8887

8988
/*** Staking of native token CYCLE and CYCLE/AVAX LP TVL Portion ***/
9089
const staking = async (api) => {
91-
const staking_lpToken =
92-
await api.call({
93-
abi: abi.stakingToken,
94-
target: coreRewards,
95-
})
96-
return sumTokens2({ api, tokens: [CYCLE, staking_lpToken], owners: [coreRewards, avaxRewards]})
90+
const staking_lpToken = await api.call({ abi: abi.stakingToken, target: coreRewards, })
91+
return sumTokens2({ api, tokens: [CYCLE, staking_lpToken], owners: [coreRewards, avaxRewards] })
9792
};
9893

99-
/*** vaults TVL portion ***/
100-
const avaxTvl = async (timestamp, ethBlock, chainBlocks) => {
101-
const balances = {};
102-
103-
const lpTokens = (
104-
await sdk.api.abi.multiCall({
105-
abi: abi.LPtoken,
106-
calls: vaults.map((vault) => ({
107-
target: vault,
108-
})),
109-
chain: "avax",
110-
block: chainBlocks["avax"],
111-
})
112-
).output.map((lp) => lp.output);
113-
114-
const lpTokens_bal = (
115-
await sdk.api.abi.multiCall({
116-
abi: abi.balanceLPinSystem,
117-
calls: vaults.map((vault) => ({
118-
target: vault,
119-
})),
120-
chain: "avax",
121-
block: chainBlocks["avax"],
122-
})
123-
).output.map((lpb) => lpb.output);
124-
125-
for (let index = 0; index < vaults.length; index++) {
126-
sdk.util.sumSingleBalance(balances,lpTokens[index],lpTokens_bal[index], 'avax')
127-
}
128-
129-
return balances;
94+
const avaxTvl = async (api) => {
95+
const lpTokens = await api.multiCall({ abi: abi.LPtoken, calls: vaults, })
96+
const lpTokens_bal = await api.multiCall({ abi: abi.balanceLPinSystem, calls: vaults, })
97+
api.add(lpTokens, lpTokens_bal)
98+
return sumTokens2({ api, resolveLP: true,})
13099
};
131100

132101
module.exports = {
133102
doublecounted: true,
134103
misrepresentedTokens: true,
135-
avax:{
104+
avax: {
136105
tvl: avaxTvl,
137106
staking
138107
},

projects/deerfi/index.js

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,12 @@
1-
/*** This Protocol seems hacked/rugged. It's a case for study and analyze ***/
2-
3-
const sdk = require("@defillama/sdk");
41
const abi = require("./abi.json");
52

63
const factoryContract = "0xa22F8cf50D9827Daef24dCb5BAC92C147a9D342e";
74

8-
const ethTvl = async (timestamp, block) => {
9-
const balances = {};
10-
11-
const lengthOfPools = (
12-
await sdk.api.abi.call({
13-
abi: abi.allPoolsLength,
14-
target: factoryContract,
15-
block,
16-
})
17-
).output;
18-
19-
for (let i = 0; i < lengthOfPools; i++) {
20-
const pool = (
21-
await sdk.api.abi.call({
22-
abi: abi.allPools,
23-
target: factoryContract,
24-
params: i,
25-
block,
26-
})
27-
).output;
28-
29-
const token = (
30-
await sdk.api.abi.call({
31-
abi: abi.token,
32-
target: pool,
33-
block,
34-
})
35-
).output;
36-
37-
const reserve = (
38-
await sdk.api.abi.call({
39-
abi: abi.reserve,
40-
target: pool,
41-
block,
42-
})
43-
).output;
44-
45-
sdk.util.sumSingleBalance(balances, token, reserve);
46-
}
47-
48-
return balances;
5+
const ethTvl = async (api) => {
6+
const pools = await api.fetchList({ lengthAbi: abi.allPoolsLength, itemAbi: abi.allPools, target: factoryContract})
7+
const tokens = await api.multiCall({ abi: abi.token, calls: pools })
8+
const bals = await api.multiCall({ abi: abi.reserve, calls: pools })
9+
api.add(tokens, bals)
4910
};
5011

5112
module.exports = {

projects/definer/index.js

Lines changed: 15 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
const ADDRESSES = require('../helper/coreAssets.json')
2-
const sdk = require("@defillama/sdk");
3-
41
const abi = require("./abi.json");
5-
const contracts = {
2+
const config = {
63
ethereum: {
74
DEPLOY_BLOCK: 10819469,
85
GLOBAL_CONFIG_ADDRESS: "0xa13B12D2c2EC945bCAB381fb596481735E24D585",
@@ -23,196 +20,21 @@ const contracts = {
2320
},
2421
};
2522

26-
const utility = {
27-
// get the latest TokenRegistry address through the GlobalConfig contract
28-
async getTokenRegistryAddressByGlobalConfig(block, chain) {
29-
return (
30-
await sdk.api.abi.call({
31-
block: block,
32-
chain: chain,
33-
target: contracts[chain].GLOBAL_CONFIG_ADDRESS,
34-
params: [],
35-
abi: abi["global:tokenInfoRegistry"],
36-
})
37-
).output;
38-
},
39-
40-
// Get the latest Bank address through the GlobalConfig contract
41-
async getBankAddressByGlobalConfig(block, chain) {
42-
return (
43-
await sdk.api.abi.call({
44-
block: block,
45-
chain: chain,
46-
target: contracts[chain].GLOBAL_CONFIG_ADDRESS,
47-
params: [],
48-
abi: abi["global:bank"],
49-
})
50-
).output;
51-
},
52-
53-
// Get the TokenRegistry contract
54-
async getTokenRegistryContract(block, ads, chain) {
55-
return (
56-
await sdk.api.abi.call({
57-
block: block,
58-
chain: chain,
59-
target: ads,
60-
params: [],
61-
abi: abi["tokenRegistry:getTokens"],
62-
})
63-
).output;
64-
},
65-
66-
// Get all tokens
67-
async getMarkets(block, chain) {
68-
// Get TokenRegistry Address
69-
let tokenRegistryAddress =
70-
await utility.getTokenRegistryAddressByGlobalConfig(block, chain);
71-
72-
// Get latest markets
73-
let currentMarkets = await utility.getTokenRegistryContract(
74-
block,
75-
tokenRegistryAddress,
76-
chain
77-
);
78-
return currentMarkets;
79-
},
80-
81-
async getBankPoolAmounts(block, markets, chain) {
82-
let bankAddress = await utility.getBankAddressByGlobalConfig(block, chain);
83-
let callsArray = [];
84-
markets.forEach((element) => {
85-
callsArray.push({
86-
target: bankAddress,
87-
params: element,
88-
});
89-
});
90-
return (
91-
await sdk.api.abi.multiCall({
92-
block: block,
93-
chain: chain,
94-
abi: abi["bank:getPoolAmount"],
95-
calls: callsArray,
96-
})
97-
).output;
98-
},
99-
100-
async getBankContractTokenState(block, markets, chain) {
101-
let bankAddress = await utility.getBankAddressByGlobalConfig(block, chain);
102-
let callsArray = [];
103-
markets.forEach((element) => {
104-
callsArray.push({
105-
target: bankAddress,
106-
params: element,
107-
});
108-
});
109-
return (
110-
await sdk.api.abi.multiCall({
111-
block: block,
112-
chain: chain,
113-
abi: abi["bank:getTokenState"],
114-
calls: callsArray,
115-
})
116-
).output;
117-
},
118-
119-
// Get Token Value
120-
async getCtokenValue(block, ctoken, chain) {
121-
let cEthToken = await sdk.api.abi.call({
122-
block: block,
123-
chain: chain,
124-
target: ctoken,
125-
params: contracts[chain].SAVINGS_ADDRESS,
126-
abi: "erc20:balanceOf",
127-
});
128-
return cEthToken.output;
129-
},
130-
131-
// Get cTokens
132-
async getCTokens(block, markets, chain) {
133-
let tokenRegistryAddress =
134-
await utility.getTokenRegistryAddressByGlobalConfig(block, chain);
135-
let callsArray = [];
136-
let allTokenObj = {};
137-
markets.forEach((token_address) => {
138-
allTokenObj[token_address] = "";
139-
callsArray.push({
140-
target: tokenRegistryAddress,
141-
params: token_address,
142-
});
143-
});
144-
let cToken = (
145-
await sdk.api.abi.multiCall({
146-
block: block,
147-
chain: chain,
148-
abi: abi["tokenRegistry:getCToken"],
149-
calls: callsArray,
150-
})
151-
).output;
152-
153-
let zeroCTokenAddress = ADDRESSES.null;
154-
cToken.forEach((item) => {
155-
allTokenObj[item.input.params[0]] =
156-
item.output === zeroCTokenAddress ? "" : item.output;
157-
});
158-
return allTokenObj;
159-
},
160-
//
161-
};
162-
163-
async function ethereumTvl(timestamp, blockETH, chainBlocks) {
164-
const block = blockETH;
165-
const chain = "ethereum";
166-
return await getTvlByChain(timestamp, block, chain);
167-
}
168-
async function okexchainTvl(timestamp, blockETH, chainBlocks) {
169-
const block = chainBlocks["okexchain"];
170-
const chain = "okexchain";
171-
return await getTvlByChain(timestamp, block, chain);
172-
}
173-
async function polygonTvl(timestamp, blockETH, chainBlocks) {
174-
const block = chainBlocks["polygon"];
175-
const chain = "polygon";
176-
return await getTvlByChain(timestamp, block, chain);
177-
}
178-
179-
async function getTvlByChain(timestamp, block, chain) {
180-
let config = contracts[chain];
23+
Object.keys(config).forEach(chain => {
24+
const { GLOBAL_CONFIG_ADDRESS, SAVINGS_ADDRESS, CETH, } = config[chain]
25+
module.exports[chain] = {
26+
tvl: async (api) => {
27+
// Get TokenRegistry Address
28+
let tokenRegistryAddress = await api.call({ target: GLOBAL_CONFIG_ADDRESS, abi: abi["global:tokenInfoRegistry"], })
18129

182-
let balances = {};
183-
let networkAddressSymbol = chain === "ethereum" ? "" : `${chain}:`;
184-
if (!block || block > config.DEPLOY_BLOCK) {
185-
// Get all Tokens in the market
186-
let markets = await utility.getMarkets(block, chain);
30+
// Get latest markets
31+
let markets = await api.call({ target: tokenRegistryAddress, abi: abi["tokenRegistry:getTokens"], });
18732

188-
// Get Bank
189-
let banksPoolAmounts = await utility.getBankPoolAmounts(
190-
block,
191-
markets,
192-
chain
193-
);
194-
banksPoolAmounts.forEach((result) => {
195-
balances[networkAddressSymbol + result.input.params] = result.output;
196-
});
33+
let bankAddress = await api.call({ target: GLOBAL_CONFIG_ADDRESS, abi: abi["global:bank"], })
34+
const amounts = await api.multiCall({ abi: abi["bank:getPoolAmount"], calls: markets, target: bankAddress, })
35+
api.add(markets, amounts)
36+
return api.sumTokens({ owner: SAVINGS_ADDRESS, token: CETH})
19737

198-
// cETH value
199-
balances[networkAddressSymbol + config.CETH] = await utility.getCtokenValue(
200-
block,
201-
config.CETH,
202-
chain
203-
);
38+
}
20439
}
205-
return balances;
206-
}
207-
208-
module.exports = {
209-
ethereum: {
210-
tvl: ethereumTvl,
211-
},
212-
okexchain: {
213-
tvl: okexchainTvl,
214-
},
215-
polygon: {
216-
tvl: polygonTvl,
217-
},
218-
};
40+
})

0 commit comments

Comments
 (0)