Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: stored_rates() in Plain2Price #48

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading