Skip to content

Commit e0457bd

Browse files
committed
minor refactor
1 parent 97675e9 commit e0457bd

File tree

3 files changed

+26
-54
lines changed

3 files changed

+26
-54
lines changed

projects/cronos-zk/index.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,7 @@
1-
const { sumTokens2 } = require("../helper/unwrapLPs");
2-
3-
const target = "0xD7f9f54194C633F36CCD5F3da84ad4a1c38cB2cB"
4-
const gasQuery = '0x0000000000000000000000000000000000000001'
5-
const gasAddress = '0x0000000000000000000000000000000000000000'
6-
const chainId = 388
1+
const getTvl = require("../txBridge/util")
72

83
module.exports = {
94
ethereum: {
10-
tvl: async (api) => {
11-
const totalBalances = await sumTokens2({
12-
api,
13-
owner: target,
14-
fetchCoValentTokens: true,
15-
})
16-
const balances = await api.multiCall({
17-
calls: [gasQuery, ...Object.keys(totalBalances)].map(token => ({
18-
target, params: [chainId, token.substring(token.indexOf(':') + 1)]
19-
})),
20-
abi: { "inputs": [{ "internalType": "uint256", "name": "chainId", "type": "uint256" }, { "internalType": "address", "name": "l1Token", "type": "address" }], "name": "chainBalance", "outputs": [{ "internalType": "uint256", "name": "balance", "type": "uint256" }], "stateMutability": "view", "type": "function" },
21-
permitFailure: true,
22-
withMetadata: true
23-
})
24-
api._balances._balances = {}
25-
balances.map(call => {
26-
const token = call.input.params[1]
27-
api.add(token == gasQuery ? gasAddress : token, call.output)
28-
})
29-
}
5+
tvl: async (api) => getTvl(api, { chainId: 388, }),
306
},
31-
};
7+
}

projects/txBridge/index.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,7 @@
1-
const { sumTokens2 } = require("../helper/unwrapLPs");
2-
3-
const target = "0xD7f9f54194C633F36CCD5F3da84ad4a1c38cB2cB"
4-
const gasQuery = '0x0000000000000000000000000000000000000001'
5-
const gasAddress = '0x0000000000000000000000000000000000000000'
6-
const chainId = 324
1+
const getTvl = require("./util")
72

83
module.exports = {
94
ethereum: {
10-
tvl: async (api) => {
11-
const totalBalances = await sumTokens2({
12-
api,
13-
owner: target,
14-
fetchCoValentTokens: true,
15-
})
16-
const balances = await api.multiCall({
17-
calls: [gasQuery, ...Object.keys(totalBalances)].map(token => ({
18-
target, params: [chainId, token.substring(token.indexOf(':') + 1)]
19-
})),
20-
abi: { "inputs": [{ "internalType": "uint256", "name": "chainId", "type": "uint256" }, { "internalType": "address", "name": "l1Token", "type": "address" }], "name": "chainBalance", "outputs": [{ "internalType": "uint256", "name": "balance", "type": "uint256" }], "stateMutability": "view", "type": "function" },
21-
permitFailure: true,
22-
withMetadata: true
23-
})
24-
api._balances._balances = {}
25-
balances.map(call => {
26-
const token = call.input.params[1]
27-
api.add(token == gasQuery ? gasAddress : token, call.output)
28-
})
29-
}
5+
tvl: async (api) => getTvl(api, { chainId: 324, }),
306
},
31-
};
7+
}

projects/txBridge/util.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { sumTokens2 } = require("../helper/unwrapLPs");
2+
3+
const _target = "0xD7f9f54194C633F36CCD5F3da84ad4a1c38cB2cB"
4+
const gasQuery = '0x0000000000000000000000000000000000000001'
5+
const gasAddress = '0x0000000000000000000000000000000000000000'
6+
7+
module.exports = async (api, { chainId, target = _target } = {}) => {
8+
const totalBalances = await sumTokens2({ api, owner: target, fetchCoValentTokens: true, balances: {} })
9+
const tokens = Object.keys(totalBalances).map(token => token.split(':')[1]).filter(token => token !== gasAddress)
10+
tokens.unshift(gasQuery)
11+
const balances = (await api.multiCall({
12+
target,
13+
calls: tokens.map(token => ({ params: [chainId, token] })),
14+
abi: "function chainBalance(uint256 chainId, address l1Token) view returns (uint256 balance)",
15+
permitFailure: true,
16+
})).map(i => i ?? 0)
17+
tokens[0] = gasAddress
18+
api.add(tokens, balances)
19+
return api.getBalances()
20+
}

0 commit comments

Comments
 (0)