-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathCryptoFromPoolVault.vy
76 lines (61 loc) · 1.81 KB
/
CryptoFromPoolVault.vy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# @version 0.3.10
"""
@title CryptoFromPoolVault
@notice Price oracle for pools which contain cryptos and crvUSD. This is NOT suitable for minted crvUSD - only for lent out
In addition to "normal" logic, multiplies by vault token's pricePerShare()
@author Curve.Fi
@license MIT
"""
interface Pool:
def price_oracle(i: uint256 = 0) -> uint256: view # Universal method!
def coins(i: uint256) -> address: view
interface Vault:
def pricePerShare() -> uint256: view
def borrowed_token() -> address: view
def collateral_token() -> address: view
POOL: public(immutable(Pool))
BORROWED_IX: public(immutable(uint256))
COLLATERAL_IX: public(immutable(uint256))
N_COINS: public(immutable(uint256))
VAULT: public(immutable(Vault))
@external
def __init__(
pool: Pool,
N: uint256,
borrowed_ix: uint256,
collateral_ix: uint256,
vault: Vault
):
assert borrowed_ix != collateral_ix
assert borrowed_ix < N
assert collateral_ix < N
assert pool.coins(collateral_ix) == vault.borrowed_token()
POOL = pool
N_COINS = N
BORROWED_IX = borrowed_ix
COLLATERAL_IX = collateral_ix
VAULT = vault
@internal
@view
def _raw_price() -> uint256:
p_borrowed: uint256 = 10**18
p_collateral: uint256 = 10**18
if N_COINS == 2:
p: uint256 = POOL.price_oracle()
if COLLATERAL_IX > 0:
p_collateral = p
else:
p_borrowed = p
else:
if BORROWED_IX > 0:
p_borrowed = POOL.price_oracle(BORROWED_IX - 1)
if COLLATERAL_IX > 0:
p_collateral = POOL.price_oracle(COLLATERAL_IX - 1)
return p_collateral * VAULT.pricePerShare() / p_borrowed
@external
@view
def price() -> uint256:
return self._raw_price()
@external
def price_w() -> uint256:
return self._raw_price()