Skip to content

Commit

Permalink
Pirex rate provider
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkorin committed Jan 25, 2024
1 parent 625fef4 commit 41e900b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions contracts/providers/PirexRateProvider.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# @version 0.3.7

from vyper.interfaces import ERC4626

ASSET: constant(address) = 0x9Ba021B0a9b958B5E75cE9f6dff97C7eE52cb3E6 # apxETH
UNIT: constant(uint256) = 1_000_000_000_000_000_000

@external
@view
def rate(_asset: address) -> uint256:
assert _asset == ASSET
return ERC4626(ASSET).convertToAssets(UNIT)
4 changes: 3 additions & 1 deletion scripts/rate_provider_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def main():
# project.TranchessRateProvider,
project.MetaPoolRateProvider,
project.RocketPoolRateProvider,
project.MevProtocolRateProvider
project.MevProtocolRateProvider,
project.PirexRateProvider,
]

assets = [
Expand All @@ -29,6 +30,7 @@ def main():
'0x48AFbBd342F64EF8a9Ab1C143719b63C2AD81710', # mpETH
'0xae78736Cd615f374D3085123A210448E74Fc6393', # rETH
'0x24Ae2dA0f361AA4BE46b48EB19C91e02c5e4f27E', # mevETH
'0x9Ba021B0a9b958B5E75cE9f6dff97C7eE52cb3E6' # apxETH
]

measure = project.RateProviderMeasure.deploy(sender=deployer)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_pirex_rate_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ape import Contract
import pytest

ASSET = '0x9Ba021B0a9b958B5E75cE9f6dff97C7eE52cb3E6'
UNDERLYING = '0x04C154b66CB340F3Ae24111CC767e0184Ed00Cc6'
UNIT = 1_000_000_000_000_000_000

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

def test_rate_provider(provider, accounts):
asset = Contract(ASSET)
account = accounts['0x3A8EAF3fE0082e478293917F2E81F4fEED97ace2']
underlying = Contract(UNDERLYING)
asset.redeem(UNIT, accounts[0], account, sender=account)

rate = provider.rate(ASSET)
assert rate > UNIT and rate < UNIT * 12 // 10
assert underlying.balanceOf(accounts[0]) == rate

0 comments on commit 41e900b

Please sign in to comment.