forked from balancer/metastable-rate-providers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
import "./interfaces/IcbETH.sol"; | ||
import "./interfaces/IRateProvider.sol"; | ||
|
||
|
||
/** | ||
* @title Coinbase wrapped staked Eth Rate Provider | ||
* @notice Returns value of cbEth in terms of Eth | ||
*/ | ||
contract CbEthRateProvider is IRateProvider { | ||
IcbETH public immutable cbETH; | ||
address public origin; | ||
|
||
constructor(IcbETH _cbETH) { | ||
cbETH = _cbETH; | ||
|
||
} | ||
|
||
/** | ||
* @return value of cbETH in terms of Eth scaled by 10**18 | ||
*/ | ||
function getRate() public view override returns (uint256) { | ||
return cbETH.exchangeRate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.4; | ||
|
||
|
||
|
||
/** | ||
* @title Coinbase Staked ETH interface to return exchangeRate | ||
* @dev | ||
* | ||
*/ | ||
interface IcbETH { | ||
/** | ||
* @notice get exchange rate | ||
* @return Returns the current exchange rate scaled by by 10**18 | ||
*/ | ||
function exchangeRate() external view returns (uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//SPDX-License-Identifier: MIT | ||
|
||
pragma solidity^0.8.4; | ||
|
||
contract MockCBEth { | ||
uint256 private _exchangeRate = 1; | ||
|
||
function exchangeRate() external view returns(uint256){ | ||
return _exchangeRate*1e18; | ||
} | ||
|
||
// anyone can set the rate in this mock example | ||
function setExchangeRate(uint256 newRate) external { | ||
_exchangeRate = newRate; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ethers } from 'hardhat'; | ||
import { expect } from 'chai'; | ||
import { Contract } from 'ethers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address'; | ||
|
||
|
||
describe('Coinbase Eth rate provider', function() { | ||
let mockCBEth: Contract; | ||
let cBEthRateProvider: Contract; | ||
let signer: SignerWithAddress; | ||
let tempAddress; | ||
|
||
before('setup eoas', async () => { | ||
[signer, ] = await ethers.getSigners(); | ||
}) | ||
|
||
beforeEach('deploy mock & rate provider', async () =>{ | ||
const MockCBEth = await ethers.getContractFactory('MockCBEth'); | ||
mockCBEth = await MockCBEth.deploy(); | ||
tempAddress = mockCBEth.address; | ||
const CBEthRateProvider = await ethers.getContractFactory('CbEthRateProvider'); | ||
cBEthRateProvider = await CBEthRateProvider.deploy(tempAddress); | ||
|
||
}) | ||
|
||
it('returns rate scaled correctly', async () => { | ||
expect(await mockCBEth.exchangeRate()).to.equal(ethers.utils.parseUnits('1', 18)); | ||
}) | ||
it('can set rate', async () => { | ||
await mockCBEth.setExchangeRate(2) | ||
expect(await mockCBEth.exchangeRate()).to.equal(ethers.utils.parseUnits('2', 18)); | ||
}) | ||
it('gets rate from rateProvider',async () => { | ||
expect(await cBEthRateProvider.getRate()).to.equal(ethers.utils.parseUnits('1', 18)); | ||
}) | ||
it('gets correct rate from rateProvider after underlying rate update',async () => { | ||
await mockCBEth.setExchangeRate(2); | ||
expect(await cBEthRateProvider.getRate()).to.equal(ethers.utils.parseUnits('2', 18)); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ethers } from 'hardhat'; | ||
import { expect, assert } from 'chai'; | ||
import { BigNumber, Contract } from 'ethers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address'; | ||
|
||
|
||
|
||
describe('Coinbase Eth rate provider', function() { | ||
let cBEthRateProvider: Contract; | ||
let signer: SignerWithAddress; | ||
let cbEthAddres = '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704'; //mainnet | ||
|
||
before('setup eoas', async () => { | ||
[signer, ] = await ethers.getSigners(); | ||
}) | ||
|
||
beforeEach('deploy rate provider', async () =>{ | ||
const CBEthRateProvider = await ethers.getContractFactory('CbEthRateProvider'); | ||
cBEthRateProvider = await CBEthRateProvider.deploy(cbEthAddres); | ||
}) | ||
it('checks if proxy = asset in rate provider',async () => { | ||
expect(await cBEthRateProvider.cbETH()).to.equal(cbEthAddres) | ||
}) | ||
it('greater than 18 decimals scale - scaled',async () => { | ||
let currentRate = await cBEthRateProvider.getRate(); | ||
expect(currentRate.gt(BigNumber.from(10).pow(18))).to.be.true; | ||
}) | ||
it('is lower than 19 decimals - scaled',async () => { | ||
let currentRate = await cBEthRateProvider.getRate(); | ||
expect(currentRate.lt(BigNumber.from(10).pow(19))).to.be.true; | ||
}) | ||
}) |
359cb88
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cbEth whitepaper: https://www.coinbase.com/cbeth/whitepaper
cbEth audit: https://blog.openzeppelin.com/coinbase-liquid-staking-token-audit/
proxy: https://etherscan.io/address/0xBe9895146f7AF43049ca1c1AE358B0541Ea49704#readProxyContract
implementation: https://etherscan.io/address/0x31724ca0c982a31fbb5c57f4217ab585271fc9a5#readContract