Skip to content

Commit

Permalink
bye bye exchange_extended. you were good, but nobody used you
Browse files Browse the repository at this point in the history
  • Loading branch information
bout3fiddy committed Aug 2, 2023
1 parent 5652a3d commit 0c19f16
Showing 1 changed file with 6 additions and 71 deletions.
77 changes: 6 additions & 71 deletions contracts/main/CurveTricryptoOptimizedWETH.vy
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ last_gulp_timestamp: uint256 # <------ Records the block timestamp when admin

ADMIN_ACTIONS_DELAY: constant(uint256) = 3 * 86400
MIN_RAMP_TIME: constant(uint256) = 86400
MIN_GULP_INTERVAL: constant(uint256) = 3600
MIN_GULP_INTERVAL: constant(uint256) = 86400

MIN_A: constant(uint256) = N_COINS**N_COINS * A_MULTIPLIER / 100
MAX_A: constant(uint256) = 1000 * A_MULTIPLIER * N_COINS**N_COINS
Expand Down Expand Up @@ -304,11 +304,7 @@ def __init__(
def _transfer_in(
_coin: address,
dx: uint256,
dy: uint256,
callbacker: address,
callback_sig: bytes32,
sender: address,
receiver: address,
expect_optimistic_transfer: bool,
):
"""
Expand Down Expand Up @@ -336,7 +332,7 @@ def _transfer_in(

received_amounts = coin_balance - self.stored_balances[_coin]

elif callback_sig == empty(bytes32):
else:

assert ERC20(_coin).transferFrom(
sender,
Expand All @@ -346,22 +342,6 @@ def _transfer_in(
)
received_amounts = ERC20(_coin).balanceOf(self) - coin_balance

else:

# --------- This part of the _transfer_in logic is only accessible
# by _exchange.

# First call callback logic and then check if pool
# gets dx amounts of _coins[i], revert otherwise.
raw_call(
callbacker,
concat(
slice(callback_sig, 0, 4),
_abi_encode(sender, receiver, _coin, dx, dy)
)
)
received_amounts = ERC20(_coin).balanceOf(self) - coin_balance

assert received_amounts == dx # dev: user didn't give us coins
self.stored_balances[_coin] += dx

Expand Down Expand Up @@ -414,46 +394,6 @@ def exchange(
)


@external
@nonreentrant('lock')
def exchange_extended(
i: uint256,
j: uint256,
dx: uint256,
min_dy: uint256,
sender: address,
receiver: address,
cb: bytes32
) -> uint256:
"""
@notice Exchange with callback method.
@dev Does not allow flashloans
@dev One use-case is to reduce the number of redundant ERC20 token
transfers in zaps.
@param i Index value for the input coin
@param j Index value for the output coin
@param dx Amount of input coin being swapped in
@param min_dy Minimum amount of output coin to receive
@param sender Address to transfer input coin from
@param receiver Address to send the output coin to
@param cb Callback signature
@return uint256 Amount of tokens at index j received by the `receiver`
"""

assert cb != empty(bytes32) # dev: No callback specified
return self._exchange(
sender,
i,
j,
dx,
min_dy,
receiver,
msg.sender,
cb,
False
)


@external
@nonreentrant('lock')
def exchange_received(
Expand Down Expand Up @@ -553,11 +493,7 @@ def add_liquidity(
self._transfer_in(
coins[i],
amounts[i],
0,
empty(address),
empty(bytes32),
msg.sender,
empty(address),
False, # <--------------------- Disable optimistic transfers.
)

Expand Down Expand Up @@ -894,9 +830,8 @@ def _exchange(
########################## TRANSFER IN <-------
self._transfer_in(
coins[i],
dx, dy,
callbacker, callback_sig, # <-------- Callback method is called here.
sender, receiver,
dx,
sender,
expect_optimistic_transfer # <---- If True, pool expects dx tokens to
) # be transferred in.

Expand Down Expand Up @@ -1165,10 +1100,10 @@ def _claim_admin_fees():

gulped_balances: uint256[N_COINS] = empty(uint256[N_COINS])
for i in range(N_COINS):

# Note: do not add gulping of tokens in external methods that involve
# optimistic token transfers.
gulped_balances[i] = ERC20(coins[i]).balanceOf(self)
# TODO: Add safety checks to ensure balances are not wildly manipulated.
gulped_balances[i] = self.stored_balances[coins[i]] # <-------------------- consider this.

# If the pool has made no profits, `xcp_profit == xcp_profit_a`
# and the pool gulps nothing in the previous step.
Expand Down

0 comments on commit 0c19f16

Please sign in to comment.