Skip to content

Commit

Permalink
EtherFi rate provider
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkorin committed Dec 26, 2023
1 parent ef8f1ce commit 91f58f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions contracts/providers/EtherFiRateProvider.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @version 0.3.7

interface EtherFiLiquidityPool:
def amountForShare(_shares: uint256) -> uint256: view

ASSET: constant(address) = 0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee # weETH
LIQUIDITY_POOL: constant(address) = 0x308861A430be4cce5502d0A12724771Fc6DaF216
UNIT: constant(uint256) = 1_000_000_000_000_000_000

@external
@view
def rate(_asset: address) -> uint256:
assert _asset == ASSET
return EtherFiLiquidityPool(LIQUIDITY_POOL).amountForShare(UNIT)
19 changes: 19 additions & 0 deletions tests/test_etherfi_rate_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from ape import Contract
import pytest

ASSET = '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee'
UNDERLYING = '0x35fA164735182de50811E8e2E824cFb9B6118ac2'
UNIT = 1_000_000_000_000_000_000

@pytest.fixture
def provider(project, deployer):
return project.EtherFiRateProvider.deploy(sender=deployer)

def test_rate_provider(provider, accounts):
asset = Contract(ASSET)
account = accounts['0x2b0024ecee0626E9cFB5F0195F69DCaC5b759Dc9']
underlying = Contract(UNDERLYING)
rate = provider.rate(ASSET)
asset.unwrap(UNIT, sender=account)
assert rate > UNIT and rate < UNIT * 12 // 10
assert abs(underlying.balanceOf(account) - rate) <= 1 # rounding difference due to rebase mechanism

0 comments on commit 91f58f1

Please sign in to comment.