Skip to content

Commit

Permalink
rename var for clarity and add some more codecomments
Browse files Browse the repository at this point in the history
  • Loading branch information
bout3fiddy committed Dec 12, 2023
1 parent 7e0f67e commit 8eaf5e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions contracts/main/CurveStableSwapMetaNG.vy
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ math: immutable(Math)
factory: immutable(Factory)
coins: public(immutable(DynArray[address, MAX_COINS]))
asset_type: immutable(uint8)
pool_is_rebasing: immutable(bool)
pool_contains_rebasing_tokens: immutable(bool)
stored_balances: uint256[N_COINS]

# Fee specific vars
Expand Down Expand Up @@ -349,7 +349,7 @@ def __init__(
coins = _coins # <---------------- coins[1] is always base pool LP token.

asset_type = _asset_types[0]
pool_is_rebasing = asset_type == 2
pool_contains_rebasing_tokens = asset_type == 2
rate_multiplier = _rate_multipliers[0]

for i in range(MAX_COINS):
Expand Down Expand Up @@ -502,15 +502,17 @@ def _transfer_out(
"""
assert receiver != empty(address) # dev: do not send tokens to zero_address

if not pool_is_rebasing:
if not pool_contains_rebasing_tokens:

# we need not cache balanceOf pool before swap out
self.stored_balances[_coin_idx] -= _amount
assert ERC20(coins[_coin_idx]).transfer(
receiver, _amount, default_return_value=True
)

else:

# cache balances pre and post to account for fee on transfers etc.
coin_balance: uint256 = ERC20(coins[_coin_idx]).balanceOf(self)
assert ERC20(coins[_coin_idx]).transfer(
receiver, _amount, default_return_value=True
Expand Down Expand Up @@ -573,9 +575,11 @@ def _balances() -> uint256[N_COINS]:
admin_balances: DynArray[uint256, MAX_COINS] = self.admin_balances
for i in range(N_COINS_128):

if pool_is_rebasing:
if pool_contains_rebasing_tokens:
# Read balances by gulping to account for rebases
result[i] = ERC20(coins[i]).balanceOf(self) - admin_balances[i]
else:
# Use cached balances
result[i] = self.stored_balances[i] - admin_balances[i]

return result
Expand Down Expand Up @@ -638,7 +642,7 @@ def exchange_received(
@param _receiver Address that receives `j`
@return Actual amount of `j` received
"""
assert not pool_is_rebasing # dev: exchange_received not supported if pool contains rebasing tokens
assert not pool_contains_rebasing_tokens # dev: exchange_received not supported if pool contains rebasing tokens
return self._exchange(
msg.sender,
i,
Expand Down
14 changes: 9 additions & 5 deletions contracts/main/CurveStableSwapNG.vy
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,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)
pool_contains_rebasing_tokens: immutable(bool)
stored_balances: DynArray[uint256, MAX_COINS]

# Fee specific vars
Expand Down Expand Up @@ -277,7 +277,7 @@ def __init__(

coins = _coins
asset_types = _asset_types
pool_is_rebasing = 2 in asset_types
pool_contains_rebasing_tokens = 2 in asset_types
__n_coins: uint256 = len(_coins)
N_COINS = __n_coins
N_COINS_128 = convert(__n_coins, int128)
Expand Down Expand Up @@ -407,15 +407,17 @@ def _transfer_out(_coin_idx: int128, _amount: uint256, receiver: address):
"""
assert receiver != empty(address) # dev: do not send tokens to zero_address

if not pool_is_rebasing:
if not pool_contains_rebasing_tokens:

# we need not cache balanceOf pool before swap out
self.stored_balances[_coin_idx] -= _amount
assert ERC20(coins[_coin_idx]).transfer(
receiver, _amount, default_return_value=True
)

else:

# cache balances pre and post to account for fee on transfers etc.
coin_balance: uint256 = ERC20(coins[_coin_idx]).balanceOf(self)
assert ERC20(coins[_coin_idx]).transfer(
receiver, _amount, default_return_value=True
Expand Down Expand Up @@ -482,9 +484,11 @@ def _balances() -> DynArray[uint256, MAX_COINS]:

for i in range(N_COINS_128, bound=MAX_COINS_128):

if pool_is_rebasing:
if pool_contains_rebasing_tokens:
# Read balances by gulping to account for rebases
balances_i = ERC20(coins[i]).balanceOf(self) - self.admin_balances[i]
else:
# Use cached balances
balances_i = self.stored_balances[i] - self.admin_balances[i]

result.append(balances_i)
Expand Down Expand Up @@ -549,7 +553,7 @@ def exchange_received(
@param _receiver Address that receives `j`
@return Actual amount of `j` received
"""
assert not pool_is_rebasing # dev: exchange_received not supported if pool contains rebasing tokens
assert not pool_contains_rebasing_tokens # dev: exchange_received not supported if pool contains rebasing tokens
return self._exchange(
msg.sender,
i,
Expand Down

0 comments on commit 8eaf5e2

Please sign in to comment.