Sub-Adapters 1

Preview and test each sub adapter.

Lido (lido)

Metadata

ID
lido
name

"Lido"

icon

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Lido';
2export const version = '0.1.1';
3export const license = 'MIT';
4
5const STETH_ADDRESS = '0xae7ab96520de3a18e5e111b5eaab095312d7fe84';
6
7const STETH_ABI = [
8  'function getPooledEthByShares(uint256 shares) external view returns (uint256 pooledEth)',
9  'function getBeaconStat() external view returns (uint256, uint256, uint256)',
10];
11
12const ONE_SHARE = '1000000000000000000';
13
14export function setup(sdk: Context) {
15  const getTotalStaked = async () => {
16    const stethContract = sdk.ethers.getContract(STETH_ADDRESS, STETH_ABI);
17
18    const beaconStats = await stethContract.getBeaconStat();
19    const numValidators = beaconStats[0].toString();
20
21    return numValidators * 32;
22  };
23
24  const getAPR = async () => {
25    const stethContract = sdk.ethers.getContract(STETH_ADDRESS, STETH_ABI);
26
27    const today = sdk.date.formatDate(new Date());
28    const weekAgo = sdk.date.offsetDaysFormatted(today, -7);
29
30    const totalRewardsNow = await stethContract.getPooledEthByShares(ONE_SHARE, { blockTag: today });
31    const totalRewardsWeekAgo = await stethContract.getPooledEthByShares(ONE_SHARE, { blockTag: weekAgo });
32
33    const rewardDiff = totalRewardsNow.toString() - totalRewardsWeekAgo.toString()
34
35    return rewardDiff / 1e18 * 52;
36  };
37
38  sdk.register({
39    id: 'lido',
40    queries: {
41      totalStakedETH: getTotalStaked,
42      apy: getAPR,
43    },
44    metadata: {
45      name: 'Lido',
46      icon: sdk.ipfs.getDataURILoader('QmcsGcopqrVyzTLXETtecJuhqxqxbzUvuFMqBd27yFKCMt', 'image/svg+xml'),
47    },
48  })
49}
50

It's something off?

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

Adapter Info

Version

0.1.1

License

MIT

IPFS CID

QmY1nDWqELLu6dsufnWxu1S8SbBbGVC4cncJtg2zAhRi8c

CID (source)

Qmca2Snkpp2vnAvG2S9cc5CouQiEUpYyveyeg9dLP9pVtr

Author

mihal.eth