|
| 1 | +"""Test ERC-4626 vault price reading and estimation.""" |
| 2 | +from decimal import Decimal |
| 3 | + |
| 4 | +import pytest |
| 5 | +from tradeexecutor.ethereum.vault.vault_live_pricing import VaultPricing |
| 6 | +from tradeexecutor.strategy.generic.generic_pricing_model import GenericPricing |
| 7 | +from tradeexecutor.state.identifier import TradingPairIdentifier |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture() |
| 11 | +def vault_pricing( |
| 12 | + pricing_model: GenericPricing, |
| 13 | + ipor_usdc: TradingPairIdentifier |
| 14 | +) -> VaultPricing: |
| 15 | + """Create a vault pricing model fixture.""" |
| 16 | + |
| 17 | + vault_pricing = pricing_model.pair_configurator.get_pricing(ipor_usdc) |
| 18 | + assert isinstance(vault_pricing, VaultPricing) |
| 19 | + return vault_pricing |
| 20 | + |
| 21 | + |
| 22 | +def test_vault_estimate_buy( |
| 23 | + vault_pricing, |
| 24 | + ipor_usdc: TradingPairIdentifier |
| 25 | +): |
| 26 | + """Estimate buy price / deosit estimate for a vault.""" |
| 27 | + |
| 28 | + estimate = vault_pricing.get_buy_price( |
| 29 | + ts=None, |
| 30 | + pair=ipor_usdc, |
| 31 | + reserve=Decimal("100.00") |
| 32 | + ) |
| 33 | + assert estimate.block_number > 0 |
| 34 | + # Price of one share |
| 35 | + assert estimate.mid_price == pytest.approx(1.0335669634763602) # We use forked by block mainnet |
| 36 | + |
| 37 | + |
| 38 | +def test_vault_estimate_sell( |
| 39 | + vault_pricing, |
| 40 | + ipor_usdc: TradingPairIdentifier |
| 41 | +): |
| 42 | + """Estimate sell price / redeem estimate for a vault.""" |
| 43 | + |
| 44 | + estimate = vault_pricing.get_sell_price( |
| 45 | + ts=None, |
| 46 | + pair=ipor_usdc, |
| 47 | + quantity=Decimal("100.00") |
| 48 | + ) |
| 49 | + assert estimate.block_number > 0 |
| 50 | + # Price of one share |
| 51 | + assert estimate.mid_price == pytest.approx(1.0335669634763602) # We use forked by block mainnet |
| 52 | + |
| 53 | + |
| 54 | +def test_vault_tvl( |
| 55 | + vault_pricing, |
| 56 | + ipor_usdc: TradingPairIdentifier |
| 57 | +): |
| 58 | + """Get the real-time TVL of ERC-4626 vault.""" |
| 59 | + tvl = vault_pricing.get_usd_tvl( |
| 60 | + timestamp=None, |
| 61 | + pair=ipor_usdc, |
| 62 | + ) |
| 63 | + assert tvl == pytest.approx(1437072.77357) # We use forked by block mainnet |
0 commit comments