Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StableswapNGViews does not support get_dy_underlyinng for NG base pools #43

Closed
3 tasks
bout3fiddy opened this issue Mar 13, 2024 · 0 comments · Fixed by #45
Closed
3 tasks

StableswapNGViews does not support get_dy_underlyinng for NG base pools #43

bout3fiddy opened this issue Mar 13, 2024 · 0 comments · Fixed by #45
Assignees
Labels
bug Something isn't working

Comments

@bout3fiddy
Copy link
Collaborator

bout3fiddy commented Mar 13, 2024

Description

To replicate:

boa.env.fork('https://eth.llamarpc.com')
metapool = boa.load_partial('./contracts/CurveStableSwapMetaNG.vy').at('0x9e10f9Fb6F0D32B350CEe2618662243d4f24C64a')
views = boa.load_partial('./contracts/CurveStableSwapNGViews.vy').at('0xe0B15824862f3222fdFeD99FeBD0f7e0EC26E1FA')
metapool.get_dy_underlying(1, 0, 50000000)

This returns the following error:

<Unknown location in unknown contract 383e6b4437b59fff47b619cba855ca29342a8559>

<./contracts/CurveStableSwapNGViews.vy at 0xe0B15824862f3222fdFeD99FeBD0f7e0EC26E1FA, compiled with vyper-0.3.10+9136169>
 <compiler: external call failed>
  contract "./contracts/CurveStableSwapNGViews.vy:464", function "_base_calc_token_amount", line 464:15 
       463         base_inputs[base_i] = dx
  ---> 464         return StableSwap2(base_pool).calc_token_amount(base_inputs, is_deposit)
  ------------------------^
       465
 <locals: dx=50000000, base_i=0, base_n_coins=2, base_pool=0x383E6b4437b59fff47B619CBA855CA29342A8559, is_deposit=True>

<./contracts/CurveStableSwapMetaNG.vy at 0x9e10f9Fb6F0D32B350CEe2618662243d4f24C64a, compiled with vyper-0.3.10+9136169>
<storage: stored_balances=[1400663115190697115437619, 390114779115648288603234], fee=4000000, offpeg_fee_multiplier=20000000000, initial_A=15000, future_A=15000, initial_A_time=0, future_A_time=0, admin_balances=[261077551664406060701, 283516149270762751715], last_prices_packed=347411840088524078890531743433958621136961216596013442290, last_D_packed=727366281545842402854317123229978519420754510210983088557039950, ma_exp_time=866, D_ma_time=62324, ma_last_time=581930941243133543360104174758465010551636275095, balanceOf={}, allowance={}, total_supply=1786431867672163347040320, nonces={}>
 <compiler: external call failed>
  contract "./contracts/CurveStableSwapMetaNG.vy:1719", function "get_dy_underlying", line 1719:11 
       1718     """
  ---> 1719     return StableSwapViews(factory.views_implementation()).get_dy_underlying(i, j, dx, self)
  ---------------------^
       1720
 <locals: i=1, j=0>

How to fix

Error exists in:

@internal
@view
def _base_calc_token_amount(
    dx: uint256,
    base_i: int128,
    base_n_coins: uint256,
    base_pool: address,
    is_deposit: bool
) -> uint256:

    if base_n_coins == 2:

        base_inputs: uint256[2] = empty(uint256[2])
        base_inputs[base_i] = dx
        return StableSwap2(base_pool).calc_token_amount(base_inputs, is_deposit)

    elif base_n_coins == 3:

        base_inputs: uint256[3] = empty(uint256[3])
        base_inputs[base_i] = dx
        return StableSwap3(base_pool).calc_token_amount(base_inputs, is_deposit)

    else:

        base_inputs: DynArray[uint256, MAX_COINS] = empty(DynArray[uint256, MAX_COINS])
        for i in range(base_n_coins, bound=MAX_COINS):
            if i == convert(base_i, uint256):
                base_inputs.append(dx)
            else:
                base_inputs.append(0)
        return StableSwapNG(base_pool).calc_token_amount(base_inputs, is_deposit)

base_n_coins can be equal to 2 but it is still an NG pool. So the branching is off. The correct if-else statement should should be:

base_pool_is_ng: bool = raw_call(_base_pool, method_id("D_ma_time()"), revert_on_failure=False)

if base_n_coins == 2 and not base_pool_is_ng:

    base_inputs: uint256[2] = empty(uint256[2])
    base_inputs[base_i] = dx
    return StableSwap2(base_pool).calc_token_amount(base_inputs, is_deposit)

elif base_n_coins == 3 and not base_pool_is_ng:

    base_inputs: uint256[3] = empty(uint256[3])
    base_inputs[base_i] = dx
    return StableSwap3(base_pool).calc_token_amount(base_inputs, is_deposit)

else:

Task list

Since the fix is only for views contract, and each AMM references the address of the views contract stored in the factory, the fix for all pools is in the factory contract (by design):

  • Fix method and deploy new views implementation across all chains
  • create dao vote for governance to accept new views implementation via: factory.set_views_implementation(new_implementation)
  • Execute vote and let integrators know it has been fixed.
@bout3fiddy bout3fiddy self-assigned this Mar 13, 2024
@bout3fiddy bout3fiddy added the bug Something isn't working label Mar 13, 2024
AlbertoCentonze added a commit that referenced this issue Mar 17, 2024
fixtures changes were messing with the other tests
@AlbertoCentonze AlbertoCentonze linked a pull request Apr 25, 2024 that will close this issue
heswithme pushed a commit to heswithme/stableswap-ng that referenced this issue Sep 25, 2024
fixtures changes were messing with the other tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants