From 10678cec99e7d96ccabbbe754a7ba44ecc29342b Mon Sep 17 00:00:00 2001 From: macket Date: Mon, 2 Oct 2023 15:38:53 +0400 Subject: [PATCH 1/3] chore: gitignore .idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eba381d..3830ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build/ reports/ node_modules .build/ +.idea ### Python ### # Byte-compiled / optimized / DLL files From 0c9b2cfd0e3cd2ef818091f78fba459550926fe0 Mon Sep 17 00:00:00 2001 From: macket Date: Mon, 2 Oct 2023 15:46:48 +0400 Subject: [PATCH 2/3] feat: external stored_rates() in Plain2Price --- .../implementations/plain-2/Plain2Price.vy | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/contracts/implementations/plain-2/Plain2Price.vy b/contracts/implementations/plain-2/Plain2Price.vy index b291a37..5aaa8f0 100644 --- a/contracts/implementations/plain-2/Plain2Price.vy +++ b/contracts/implementations/plain-2/Plain2Price.vy @@ -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), @@ -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]: @@ -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 @@ -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, From 575bc1922a55465e4ef70959bf114b5532487507 Mon Sep 17 00:00:00 2001 From: macket Date: Mon, 2 Oct 2023 16:01:37 +0400 Subject: [PATCH 3/3] feat: external stored_rates() in Plain3Price and Plain4Price --- contracts/implementations/plain-3/Plain3Price.vy | 10 ++++++++-- contracts/implementations/plain-4/Plain4Price.vy | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/contracts/implementations/plain-3/Plain3Price.vy b/contracts/implementations/plain-3/Plain3Price.vy index e704efb..8cf41a0 100644 --- a/contracts/implementations/plain-3/Plain3Price.vy +++ b/contracts/implementations/plain-3/Plain3Price.vy @@ -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)), @@ -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]: diff --git a/contracts/implementations/plain-4/Plain4Price.vy b/contracts/implementations/plain-4/Plain4Price.vy index b8c2f78..407817e 100644 --- a/contracts/implementations/plain-4/Plain4Price.vy +++ b/contracts/implementations/plain-4/Plain4Price.vy @@ -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)), @@ -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]: