Sub-Adapters 1

Preview and test each sub adapter.

Ankr (ankr)

Metadata

ID
ankr
name

"Ankr"

icon
tokenSymbol

"aETHc"

tokenAddress

"0xE95A203B1a91a908F9B9CE46459d101078c2c3cb"

website

"https://ankr.com"

governanceTokenSymbol

"ANKR"

governanceTokenCoingecko

"ankr-network"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Ankr';
2export const version = '0.2.0';
3export const license = 'MIT';
4
5const aETHc_ADDRESS = '0xE95A203B1a91a908F9B9CE46459d101078c2c3cb';
6const aETHb_ADDRESS = '0xD01ef7C0A5d8c432fc2d1a85c66cF2327362E5C6';
7
8const aETHc_ABI = [
9  'function ratio() public view returns (uint256)',
10];
11
12const CURVE_POOL = '0xa96a65c051bf88b4095ee1f2451c2a9d43f53ae2';
13
14const CURVE_ABI = [
15  'function get_dy(int128 i, int128 j, uint256 dx) external view returns (uint256)',
16];
17
18export function setup(sdk: Context) {
19  const getTotalStakedForToken = async (tokenAddress: string) => {
20    const token = sdk.ethers.getERC20Contract(tokenAddress);
21    const supply = await token.totalSupply();
22    return supply.toString() / 1e18;
23  }
24
25  const getTotalStaked = async () => {
26    const [stakedB, stakedC] = await Promise.all([
27      getTotalStakedForToken(aETHb_ADDRESS),
28      getTotalStakedForToken(aETHc_ADDRESS),
29    ])
30    return stakedB + stakedC;
31  }
32
33  const getAPR = async () => {
34    const aETHcContract = sdk.ethers.getContract(aETHc_ADDRESS, aETHc_ABI);
35
36    const today = sdk.date.formatDate(new Date());
37    const weekAgo = sdk.date.offsetDaysFormatted(today, -7);
38
39    const ratioNow = await aETHcContract.ratio({blockTag: today});
40    const ratioWeekAgo = await aETHcContract.ratio({blockTag: weekAgo});
41
42    // get accumulated rewards per eth staked using '1 - ratio' 
43    const rewardsDiff = (1  - ( ratioNow.toString() / 1e18 )) - (1  - ( ratioWeekAgo.toString() / 1e18 ));
44
45    return rewardsDiff * 52;
46  }
47
48  const getMarketPrice = async () => {
49    const curve = sdk.ethers.getContract(CURVE_POOL, CURVE_ABI);
50
51    const output = await curve.get_dy(0, 1, '1000000000000000000');
52    const outputAETHC = output / 1e18;
53    return 1 / outputAETHC;
54  }
55
56  const getDiscount = async () => {
57    const aETHcContract = sdk.ethers.getContract(aETHc_ADDRESS, aETHc_ABI);
58
59    const marketPrice = await getMarketPrice();
60    const ratioNow = await aETHcContract.ratio();
61    const ratioDecimal = ratioNow / 1e18;
62
63    return marketPrice * ratioDecimal;
64  };
65
66  const getExchangeRate = async () => {
67    const aETHcContract = sdk.ethers.getContract(aETHc_ADDRESS, aETHc_ABI);
68    const ratioNow = await aETHcContract.ratio();
69    const ratioDecimal = 1 / (ratioNow / 1e18);
70    return ratioDecimal;
71  }
72
73  sdk.register({
74    id: 'ankr',
75    queries: {
76      totalStakedETH: getTotalStaked,
77      apy: getAPR,
78      marketPrice: getMarketPrice,
79      underlyingAssetMarketRate: getDiscount,
80      underlyingExchangeRate: getExchangeRate,
81    },
82    metadata: {
83      name: 'Ankr',
84      icon: sdk.ipfs.getDataURILoader('QmedFW6x588qnxWgQP9RZiNs27AXF3kREptY1cuaXXPRVS', 'image/svg+xml'),
85      tokenSymbol: 'aETHc',
86      tokenAddress: '0xE95A203B1a91a908F9B9CE46459d101078c2c3cb',
87      website: 'https://ankr.com',
88      governanceTokenSymbol: 'ANKR',
89      governanceTokenCoingecko: 'ankr-network',
90    },
91  });
92}
93
94
95

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.2.0

License

MIT

IPFS CID

QmdcimZx3pv8gbjYrtJd5YaoZjhGkMhLxGDBebWe1CUfsw

CID (source)

QmRd62ubjwW4PVLyrVGnybg2V2pdy3tnRJ22Jrry31z1Bq

Author

mihal.eth