Sub-Adapters 1

Preview and test each sub adapter.

Coinbase cbETH (coinbase-cbeth)

Metadata

ID
coinbase-cbeth
name

"Coinbase cbETH"

icon
tokenAddress

"0xBe9895146f7AF43049ca1c1AE358B0541Ea49704"

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.3';
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
41  const getMarketPrice = async () => {
42    const cbETHContract = sdk.ethers.getContract(CBETH_ADDRESS, CBETH_ABI);
43    const curve = sdk.ethers.getContract(CURVE_POOL, CURVE_ABI);
44    
45    //Market Rate
46    const output = await curve.get_dy(1, 0, '1000000000000000000');
47    const exchangeRate = await cbETHContract.exchangeRate();
48    const delta = output * ((exchangeRate - output) / 1e18)
49    const marketRate = (exchangeRate - delta) / 1e18
50    return marketRate;
51  };
52
53  const getUnderlyingExchangeRate = async () => {
54    const cbETHContract = sdk.ethers.getContract(CBETH_ADDRESS, CBETH_ABI); 
55  
56    const exchangeRate = Number(await cbETHContract.exchangeRate());
57
58    return exchangeRate / 1e18;
59  }
60
61  sdk.register({
62    id: 'coinbase-cbeth',
63    queries: {
64      totalStakedETH: getTotalStaked,
65      apy: getAPR,
66      underlyingAssetMarketRate: getMarketPrice,
67      underlyingExchangeRate: getUnderlyingExchangeRate
68    },
69    metadata: {
70      name: 'Coinbase cbETH',
71      icon: sdk.ipfs.getDataURILoader('QmUfFvmTKZe5iDWp8GnwZeg9LYbeHa8KGu4FtaJakvStft', 'image/png'),
72      tokenAddress: '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704',
73      website: 'https://coinbase.com',
74    },
75  })
76}

It's something off?

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

Adapter Info

Version

0.1.3

License

MIT

IPFS CID

QmYvniP1JLs2cCpSwV98JanDWppY1QfvyDcBKximAYPdr8

CID (source)

QmcxotTu9FkFAVDASHSbfTXaAgn9k4VNUSP48t9nPpcrGf

Author

0x70c0EE6bd4a42e9Dc5487e30a765370b65e670A5