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.1.4';
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
27 let totalStaked = await getTotalStakedForToken(aETHb_ADDRESS) + await getTotalStakedForToken(aETHc_ADDRESS);
28 return totalStaked ;
29 }
30
31 const getAPR = async () => {
32 const aETHcContract = sdk.ethers.getContract(aETHc_ADDRESS, aETHc_ABI);
33
34 const today = sdk.date.formatDate(new Date());
35 const weekAgo = sdk.date.offsetDaysFormatted(today, -7);
36
37 const ratioNow = await aETHcContract.ratio({blockTag: today});
38 const ratioWeekAgo = await aETHcContract.ratio({blockTag: weekAgo});
39
40 // get accumulated rewards per eth staked using '1 - ratio'
41 const rewardsDiff = (1 - ( ratioNow.toString() / 1e18 )) - (1 - ( ratioWeekAgo.toString() / 1e18 ));
42
43 return rewardsDiff * 52;
44 }
45
46 const getDiscount = async () => {
47 const aETHcContract = sdk.ethers.getContract(aETHc_ADDRESS, aETHc_ABI);
48 const curve = sdk.ethers.getContract(CURVE_POOL, CURVE_ABI);
49
50 const output = await curve.get_dy(0, 1, '1000000000000000000');
51 const outputAETHC = output / 1e18;
52 const ratioNow = await aETHcContract.ratio();
53 const ratioDecimal = ratioNow / 1e18;
54
55 return outputAETHC * ratioDecimal;
56 };
57
58
59 sdk.register({
60 id: 'ankr',
61 queries: {
62 totalStakedETH: getTotalStaked,
63 apy: getAPR,
64 underlyingAssetMarketRate: getDiscount,
65 },
66 metadata: {
67 name: 'Ankr',
68 icon: sdk.ipfs.getDataURILoader('QmedFW6x588qnxWgQP9RZiNs27AXF3kREptY1cuaXXPRVS', 'image/svg+xml'),
69 tokenSymbol: 'aETHc',
70 tokenAddress: '0xE95A203B1a91a908F9B9CE46459d101078c2c3cb',
71 website: 'https://ankr.com',
72 governanceTokenSymbol: 'ANKR',
73 governanceTokenCoingecko: 'ankr-network',
74 },
75 });
76}
77
78
79
It's something off?
Report it to the discussion board on Discord, we will take care of it.