Sub-Adapters 1
Preview and test each sub adapter.
Ankr (ankr)
Metadata
- ID
- ankr
- name
"Ankr"
- icon
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Ankr';
2export const version = '0.0.1';
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
12
13export function setup(sdk: Context) {
14
15 const getTotalStakedForToken = async (tokenAddress: string) => {
16 const token = sdk.ethers.getERC20Contract(tokenAddress);
17 const supply = await token.totalSupply();
18 return supply.toString() / 1e18;
19 }
20
21 const getTotalStaked = async () => {
22
23 let totalStaked = await getTotalStakedForToken(aETHb_ADDRESS) + await getTotalStakedForToken(aETHc_ADDRESS);
24 return totalStaked ;
25 }
26
27
28 const getAPR = async () => {
29 const aETHcContract = sdk.ethers.getContract(aETHc_ADDRESS, aETHc_ABI);
30
31 const today = sdk.date.formatDate(new Date());
32 const weekAgo = sdk.date.offsetDaysFormatted(today, -7);
33
34 const ratioNow = await aETHcContract.ratio({blockTag: today});
35 const ratioWeekAgo = await aETHcContract.ratio({blockTag: weekAgo});
36
37 // get accumulated rewards per eth staked using '1 - ratio'
38 const rewardsDiff = (1 - ( ratioNow.toString() / 1e18 )) - (1 - ( ratioWeekAgo.toString() / 1e18 ));
39
40 return rewardsDiff * 52;
41 }
42
43 sdk.register({
44 id: 'ankr',
45 queries: {
46 totalStakedEth: getTotalStaked,
47 apr: getAPR,
48 },
49 metadata: {
50 name: 'Ankr',
51 icon: sdk.ipfs.getDataURILoader('QmedFW6x588qnxWgQP9RZiNs27AXF3kREptY1cuaXXPRVS', 'image/svg+xml'),
52 }
53});
54
55
56}
57
58
59
It's something off?
Report it to the discussion board on Discord, we will take care of it.