Skip to content

Commit

Permalink
Merge pull request #48 from curvefi/feat/Plain2Price-stored_rates
Browse files Browse the repository at this point in the history
Feat: stored_rates() in Plain2Price
  • Loading branch information
michwill authored Oct 4, 2023
2 parents 900e90b + 575bc19 commit bcbd8cb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build/
reports/
node_modules
.build/
.idea

### Python ###
# Byte-compiled / optimized / DLL files
Expand Down
19 changes: 13 additions & 6 deletions contracts/implementations/plain-2/Plain2Price.vy
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _stored_rates() -> uint256[N_COINS]:
oracle: uint256 = self.oracles[i]
if oracle == 0:
continue

# NOTE: assumed that response is of precision 10**18
response: Bytes[32] = raw_call(
convert(oracle % 2**160, address),
Expand All @@ -344,9 +344,16 @@ def _stored_rates() -> uint256[N_COINS]:
)
assert len(response) != 0
rates[i] = rates[i] * convert(response, uint256) / PRECISION

return rates


@view
@external
def stored_rates() -> uint256[N_COINS]:
return self._stored_rates()


@view
@external
def get_balances() -> uint256[N_COINS]:
Expand Down Expand Up @@ -682,7 +689,7 @@ def add_liquidity(
fees[i] = base_fee * difference / FEE_DENOMINATOR
self.balances[i] = new_balance - (fees[i] * ADMIN_FEE / FEE_DENOMINATOR)
new_balances[i] -= fees[i]

xp: uint256[N_COINS] = self._xp_mem(rates, new_balances)
D2: uint256 = self.get_D_mem(rates, new_balances, amp)
mint_amount = total_supply * (D2 - D0) / D0
Expand All @@ -707,9 +714,9 @@ def add_liquidity(
@view
@internal
def get_y(
i: int128,
j: int128,
x: uint256,
i: int128,
j: int128,
x: uint256,
xp: uint256[N_COINS],
amp: uint256,
D: uint256,
Expand Down
10 changes: 8 additions & 2 deletions contracts/implementations/plain-3/Plain3Price.vy
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _stored_rates() -> uint256[N_COINS]:
oracle: uint256 = self.oracles[i]
if oracle == 0:
continue

response: Bytes[32] = raw_call(
convert(oracle % 2**160, address),
_abi_encode(bitwise_and(oracle, BIT_MASK)),
Expand All @@ -316,10 +316,16 @@ def _stored_rates() -> uint256[N_COINS]:
)
assert len(response) != 0
rates[i] = rates[i] * convert(response, uint256) / PRECISION

return rates


@view
@external
def stored_rates() -> uint256[N_COINS]:
return self._stored_rates()


@view
@external
def get_balances() -> uint256[N_COINS]:
Expand Down
10 changes: 8 additions & 2 deletions contracts/implementations/plain-4/Plain4Price.vy
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _stored_rates() -> uint256[N_COINS]:
oracle: uint256 = self.oracles[i]
if oracle == 0:
continue

response: Bytes[32] = raw_call(
convert(oracle % 2**160, address),
_abi_encode(bitwise_and(oracle, BIT_MASK)),
Expand All @@ -316,10 +316,16 @@ def _stored_rates() -> uint256[N_COINS]:
)
assert len(response) != 0
rates[i] = rates[i] * convert(response, uint256) / PRECISION

return rates


@view
@external
def stored_rates() -> uint256[N_COINS]:
return self._stored_rates()


@view
@external
def get_balances() -> uint256[N_COINS]:
Expand Down

0 comments on commit bcbd8cb

Please sign in to comment.