Sub-Adapters 1

Preview and test each sub adapter.

Coinbase cbETH (coinbase-cbeth)

Metadata

ID
coinbase-cbeth
name

"Coinbase cbETH"

icon
tokenAddress

"0xBe9895146f7AF43049ca1c1AE358B0541Ea49704"

tokenSymbol

"cbETH"

website

"https://coinbase.com"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Coinbase cbETH';
2export const version = '0.1.4';
3export const license = 'MIT';
4
5const CBETH_ADDRESS = '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704';
6
7const CURVE_POOL = '0x5FAE7E604FC3e24fd43A72867ceBaC94c65b404A';
8
9const CBETH_ABI = [
10  'function exchangeRate() external view returns (uint256)',
11];
12
13const CURVE_ABI = [
14  'function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256)',
15];
16
17export function setup(sdk: Context) {
18  const getTotalStaked = async () => {
19    const [supply, exchangeRate] = await Promise.all([
20      sdk.ethers.getERC20Contract(CBETH_ADDRESS).totalSupply(),
21      sdk.ethers.getContract(CBETH_ADDRESS, CBETH_ABI).exchangeRate(),
22    ]);
23
24    return supply * exchangeRate / 1e36;
25  };
26
27  const getAPR = async () => {
28    const rethContract = sdk.ethers.getContract(CBETH_ADDRESS, CBETH_ABI);
29
30    const today = sdk.date.formatDate(new Date());
31    const weekAgo = sdk.date.offsetDaysFormatted(today, -7);
32
33    const totalRewardsNow = await rethContract.exchangeRate({ blockTag: today });
34    const totalRewardsWeekAgo = await rethContract.exchangeRate({ blockTag: weekAgo });
35
36    const rewardDiff = totalRewardsNow.toString() - totalRewardsWeekAgo.toString()
37    return rewardDiff / 1e18 * 52;
38  };
39
40  const getMarketPrice = async () => {
41    const curve = sdk.ethers.getContract(CURVE_POOL, CURVE_ABI);
42    const output = await curve.get_dy(1, 0, '1000000000000000000');
43    return output / 1e18;
44  }
45
46  const getUnderlyingMarketPrice = async () => {
47    const marketPrice = await getMarketPrice();
48    const exchangeRate = await getUnderlyingExchangeRate();
49
50    const delta = marketPrice * (exchangeRate - marketPrice);
51    const marketRate = (exchangeRate - delta);
52    return marketRate;
53  };
54
55  const getUnderlyingExchangeRate = async () => {
56    const cbETHContract = sdk.ethers.getContract(CBETH_ADDRESS, CBETH_ABI); 
57  
58    const exchangeRate = parseFloat(await cbETHContract.exchangeRate());
59
60    return exchangeRate / 1e18;
61  }
62
63  sdk.register({
64    id: 'coinbase-cbeth',
65    queries: {
66      totalStakedETH: getTotalStaked,
67      apy: getAPR,
68      marketPrice: getMarketPrice,
69      underlyingAssetMarketRate: getUnderlyingMarketPrice,
70      underlyingExchangeRate: getUnderlyingExchangeRate
71    },
72    metadata: {
73      name: 'Coinbase cbETH',
74      icon: sdk.ipfs.getDataURILoader('QmUfFvmTKZe5iDWp8GnwZeg9LYbeHa8KGu4FtaJakvStft', 'image/png'),
75      tokenAddress: '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704',
76      tokenSymbol: 'cbETH',
77      website: 'https://coinbase.com',
78    },
79  })
80}
81

It's something off?

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

Adapter Info

Version

0.1.4

License

MIT

IPFS CID

QmT5agCHXa1p9xMTqStrXgPJ9QCF7WrMN5C8e8wHk7HdnL

CID (source)

QmdawR8GdYD4ryN7PCM9ESUfAPfAYQgPaTw3gEeR21ADZG

Author

mihal.eth