econia-labs / emojicoin-dot-fun

https://emojicoin-dot-fun.vercel.app
Other
7 stars 14 forks source link

[ECO-2053] Incorporate auditor, testnet campaign feedback #197

Closed alnoki closed 3 months ago

alnoki commented 3 months ago

Source code changes

API updates

  1. Add nonzero min_output_amount argument to swap for slippage control.
  2. Add nonzero min_lp_coins_out argument to provide_liquidity for rounding attack mitigation.
  3. Add nonzero min_quote_out argument to remove_liquidity for rounding attack mitigation.
  4. Add balance_as_fraction_of_circulating_supply_before_q64 and balance_as_fraction_of_circulating_supply_after_q64 fields to Swap event, which require adding type arguments and ensure_coin_types_initialized check to simulate_swap_inner function.

Revised economic dynamics

  1. Enforce winner-take-all donation claim process.
  2. Lower state transition threshold to 1,000 APT of cumulative buy pressure.
  3. Update market registration function to charge a 4 APT deposit.
  4. Update swap to return market registration deposit upon state transition.

Error case handling

  1. Update swap API to calculate FDV/market cap after buy/sell operation to prevent unexpected over/underflow errors.
  2. Update cpamm_simple_swap_output_amount to abort if output amount is 0.
  3. Update simulate_remove_liquidity_inner to abort if base/quote output amount is 0 (no new associated test, due to difficulty of setting up such an edge case).
  4. Add check for insufficient base balance to simulate_swap.

Docs

  1. Update blackpaper source for new economic variables based on lowered threshold.
  2. Rebuild blackpaper render for docs site.
  3. Rebuild Move docs.
  4. Update package README with --override-size-check command now required to publish package.
  5. Update docs site values for lowered state transition threshold, with mention of new grace period and refundable deposit.
  6. Fix typo on docs site that stipulates cumulative sell pressure instead of buy pressure.
  7. Relocate blackpaper render location.

Testing

Test code updates

  1. Lower setup buy amounts for new economic parameters.
  2. Update test logic for new winner-take-all donation claim process.
  3. Refactor existing test for selling base but not having sufficient balance so that it is not triggered by new abort for swap output amount of 0.
  4. Add expected failure test for swap where there is no output amount.
  5. Add expected failure test for swap min output amount specified as 0.
  6. Add expected failure test/minimal happy path for swap min output amount not met.
  7. Add expected failure test for provide liquidity min lp coins out specified as 0.
  8. Add expected failure test/minimal happy path for provide liquidity min lp coins out not met.
  9. Add expected failure test for remove liquidity min quote out specified as 0.
  10. Add expected failure test/minimal happy path for remove liquidity min quote out not met.
  11. Update existing tests to support new 4 APT market registration deposit and subsequent return.
  12. Add expected failure test for registrant unable to afford deposit.
  13. Update expected failure swap test case for new base balance check.
  14. Update existing tests to support new balance before/after Swap fields.
  15. Alphabetize test cases for swap simulation.
  16. Add test to exercise edge cases for balance as fraction of circulating supply before a swap.

Running tests

  1. From in src/move/emojicoin-dot-fun:

    aptos move test --dev
  2. Package publishability verified on devnet per Move package README.

Previously the package was tested to 100% coverage, but the coverage tool breaks for inline functions (https://github.com/aptos-labs/aptos-core/issues/9154) so re-demonstrating a 100% coverage run requires manually taking out inline keywords as per 6d65d23 and c13dbe2.

As per #181 this PR instead manually adds test cases to hit coverage on new functionality.

Checklist

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
emojicoin-dot-fun ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 7:36pm
emojicoin-dot-fun-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 7:36pm