From c039dc5637d2acb01ca6bd44b8886158fe24115c Mon Sep 17 00:00:00 2001 From: bout3fiddy <11488427+bout3fiddy@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:17:59 +0530 Subject: [PATCH] use immutable boolean for rebasing checks --- contracts/main/CurveStableSwapMetaNG.vy | 8 +++++--- contracts/main/CurveStableSwapNG.vy | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/contracts/main/CurveStableSwapMetaNG.vy b/contracts/main/CurveStableSwapMetaNG.vy index d3b1e47a..795abdbe 100644 --- a/contracts/main/CurveStableSwapMetaNG.vy +++ b/contracts/main/CurveStableSwapMetaNG.vy @@ -215,6 +215,7 @@ math: immutable(Math) factory: immutable(Factory) coins: public(immutable(DynArray[address, MAX_COINS])) asset_type: immutable(uint8) +pool_is_rebasing: immutable(bool) stored_balances: uint256[N_COINS] # Fee specific vars @@ -346,6 +347,7 @@ def __init__( coins = _coins # <---------------- coins[1] is always base pool LP token. asset_type = _asset_types[0] + pool_is_rebasing = asset_type == 2 rate_multiplier = _rate_multipliers[0] for i in range(MAX_COINS): @@ -498,7 +500,7 @@ def _transfer_out( """ assert receiver != empty(address) # dev: do not send tokens to zero_address - if asset_type != 2: + if not pool_is_rebasing: self.stored_balances[_coin_idx] -= _amount assert ERC20(coins[_coin_idx]).transfer( @@ -569,7 +571,7 @@ def _balances() -> uint256[N_COINS]: admin_balances: DynArray[uint256, MAX_COINS] = self.admin_balances for i in range(N_COINS_128): - if asset_type != 2: + if pool_is_rebasing: result[i] = ERC20(coins[i]).balanceOf(self) - admin_balances[i] else: result[i] = self.stored_balances[i] - admin_balances[i] @@ -634,7 +636,7 @@ def exchange_received( @param _receiver Address that receives `j` @return Actual amount of `j` received """ - assert asset_type != 2 # dev: exchange_received not supported if pool contains rebasing tokens + assert not pool_is_rebasing # dev: exchange_received not supported if pool contains rebasing tokens return self._exchange( msg.sender, i, diff --git a/contracts/main/CurveStableSwapNG.vy b/contracts/main/CurveStableSwapNG.vy index f4f32c10..cf0342fe 100644 --- a/contracts/main/CurveStableSwapNG.vy +++ b/contracts/main/CurveStableSwapNG.vy @@ -159,6 +159,7 @@ PRECISION: constant(uint256) = 10 ** 18 factory: immutable(Factory) coins: public(immutable(DynArray[address, MAX_COINS])) asset_types: immutable(DynArray[uint8, MAX_COINS]) +pool_is_rebasing: immutable(bool) stored_balances: DynArray[uint256, MAX_COINS] # Fee specific vars @@ -274,6 +275,7 @@ def __init__( coins = _coins asset_types = _asset_types + pool_is_rebasing = 2 in asset_types __n_coins: uint256 = len(_coins) N_COINS = __n_coins N_COINS_128 = convert(__n_coins, int128) @@ -403,7 +405,7 @@ def _transfer_out(_coin_idx: int128, _amount: uint256, receiver: address): """ assert receiver != empty(address) # dev: do not send tokens to zero_address - if not 2 in asset_types: + if not pool_is_rebasing: self.stored_balances[_coin_idx] -= _amount assert ERC20(coins[_coin_idx]).transfer( @@ -478,7 +480,7 @@ def _balances() -> DynArray[uint256, MAX_COINS]: for i in range(N_COINS_128, bound=MAX_COINS_128): - if 2 in asset_types: + if pool_is_rebasing: balances_i = ERC20(coins[i]).balanceOf(self) - self.admin_balances[i] else: balances_i = self.stored_balances[i] - self.admin_balances[i] @@ -545,7 +547,7 @@ def exchange_received( @param _receiver Address that receives `j` @return Actual amount of `j` received """ - assert not 2 in asset_types # dev: exchange_received not supported if pool contains rebasing tokens + assert not pool_is_rebasing # dev: exchange_received not supported if pool contains rebasing tokens return self._exchange( msg.sender, i,