Skip to content

Commit 012340a

Browse files
committed
fix ankr
1 parent b0dee74 commit 012340a

File tree

1 file changed

+44
-57
lines changed

1 file changed

+44
-57
lines changed

projects/ankr/index.js

Lines changed: 44 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
const { get } = require("../helper/http")
22
const abi = require("./abi.json");
3+
const ADDRESSES = require('../helper/coreAssets.json')
34

45
let _response
56

7+
const config = {
8+
ethereum: '0xE95A203B1a91a908F9B9CE46459d101078c2c3cb',
9+
avax: '0xc3344870d52688874b06d844E0C36cc39FC727F6',
10+
bsc: '0x52F24a5e03aee338Da5fd9Df68D2b6FAe1178827',
11+
fantom: '0xcfc785741dc0e98ad4c9f6394bb9d43cd1ef5179',
12+
flow: '0x1b97100eA1D7126C4d60027e231EA4CB25314bdb',
13+
}
14+
615
async function getTvls(serviceName, key) {
716
if (!_response) _response = get('https://api.staking.ankr.com/v1alpha/metrics')
817
const response = await _response
918
const data = response.services.find(i => i.serviceName === serviceName)
1019
return data ? +data[key] : 0;
1120
}
1221

13-
async function getETHTvl() {
14-
return {
15-
ethereum: await getTvls("eth", "totalStaked"),
16-
'matic-network': await getTvls("polygon", "totalStaked"),
17-
}
18-
}
19-
20-
async function getBscTvl() {
21-
return {
22-
binancecoin: await getTvls("bnb", "totalStaked"),
23-
}
24-
}
25-
26-
async function getAvaxTvl() {
27-
return {
28-
'avalanche-2': await getTvls("avax", "totalStaked"),
29-
}
30-
}
31-
32-
async function getFlowTvl() {
33-
return {
34-
'flow': await getTvls("flowevm", "totalStaked"),
22+
async function getonChainTvl(api) {
23+
const token = config[api.chain]
24+
const ethSupply = await api.call({ abi: 'erc20:totalSupply', target: token })
25+
const ratio = await api.call({ abi: 'uint256:ratio', target: token })
26+
const ethTvl = ethSupply / (ratio / 1e18)
27+
28+
if (api.chain === 'flow')
29+
api.add(ADDRESSES.flow.WFLOW, ethTvl)
30+
else
31+
api.addGasToken(ethTvl)
32+
33+
if (api.chain === 'ethereum') {
34+
const aMatic = '0x26dcfbfa8bc267b250432c01c982eaf81cc5480c'
35+
const maticSupply = await api.call({ abi: 'erc20:totalSupply', target: aMatic })
36+
const ratio = await api.call({ abi: 'uint256:ratio', target: aMatic })
37+
api.add(ADDRESSES.ethereum.MATIC, maticSupply / (ratio / 1e18))
3538
}
3639
}
3740

@@ -47,59 +50,39 @@ async function ksm() {
4750
}
4851
}
4952

50-
async function getFantomTvl() {
51-
return {
52-
fantom: await getTvls("ftm", "totalStaked"),
53-
}
54-
}
5553

5654
async function getGnosisTvl(api) {
57-
55+
5856
//Current Ankr Provider Address, there is a hard cap on how much mGNO each address can stake, other addresses might appear*/
5957
const ankrProviderAddress = "0x4069D8A3dE3A72EcA86CA5e0a4B94619085E7362"
60-
58+
6159
//Staking Pool Proxy Contract
6260
const proxyStakingPool = "0xfd0f61255913825da1c194b985f04982966c34d6"
63-
61+
6462
//Staking Pool Logic Contract = "0xb6fcfcc497271d837c050ec912004bca0d70db0f"
6563
//Provider Registry Proxy Contract = "0x8a2f83347f0e59faefe2320b7422f8aa432ce27a"
6664
//Provider Registry Logic Contract = "0x6c6f910a79639dcc94b4feef59ff507c2e843929"
6765

6866

69-
var providerBalance = (await api.call({
70-
abi: abi.getProviderBalance,
71-
target: proxyStakingPool,
72-
params: [ankrProviderAddress],
73-
}))
67+
var providerBalance = (await api.call({
68+
abi: abi.getProviderBalance,
69+
target: proxyStakingPool,
70+
params: [ankrProviderAddress],
71+
}))
7472

75-
//providerBalance = [balance, totalCap]
76-
var staked = providerBalance[0] / 1e18
73+
//providerBalance = [balance, totalCap]
74+
var staked = providerBalance[0] / 1e18
7775

78-
//Staked amount is in mGNO, 32 mGNO = 1 GNO
79-
var trueStaked = staked / 32
76+
//Staked amount is in mGNO, 32 mGNO = 1 GNO
77+
var trueStaked = staked / 32
8078

81-
return {
82-
gnosis: trueStaked
83-
}
79+
return {
80+
gnosis: trueStaked
81+
}
8482
}
8583

8684
module.exports = {
8785
timetravel: false,
88-
ethereum: {
89-
tvl: getETHTvl,
90-
},
91-
bsc: {
92-
tvl: getBscTvl,
93-
},
94-
avax:{
95-
tvl: getAvaxTvl,
96-
},
97-
fantom: {
98-
tvl: getFantomTvl,
99-
},
100-
flow: {
101-
tvl: getFlowTvl,
102-
},
10386
polkadot: {
10487
tvl: polkadot,
10588
},
@@ -111,3 +94,7 @@ module.exports = {
11194
},
11295
methodology: `We get the total staked amount and total staked USD from Ankr's official API. Gnosis: Gets staked amount from the staking pool.`,
11396
};
97+
98+
Object.keys(config).forEach(chain => {
99+
module.exports[chain] = { tvl: getonChainTvl }
100+
})

0 commit comments

Comments
 (0)