Skip to content

Commit

Permalink
use immutable boolean for rebasing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bout3fiddy committed Dec 12, 2023
1 parent 1fb6428 commit c039dc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions contracts/main/CurveStableSwapMetaNG.vy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions contracts/main/CurveStableSwapNG.vy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c039dc5

Please sign in to comment.