Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2800 +/- ##
==========================================
- Coverage 43.61% 41.24% -2.37%
==========================================
Files 104 106 +2
Lines 4464 4485 +21
Branches 1218 1225 +7
==========================================
- Hits 1947 1850 -97
- Misses 2514 2632 +118
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| } else { | ||
| amount0 = amountOut; | ||
| amount1 = 0; | ||
| } |
There was a problem hiding this comment.
TODO: There might be a way to simplify the above code
There was a problem hiding this comment.
Could be expressed as:
(uint256 amount0, uint256 amount1) = (_tokenIn == asset && oTokenPoolIndex == 1) ||
(_tokenIn == oToken && oTokenPoolIndex == 0)
? (uint256(0), amountOut)
: (amountOut, 0);While that is more condensed I think it is less readable
There was a problem hiding this comment.
Pull request overview
This PR refactors the Sonic SwapXAMO strategy into a generalized Algebra-based AMO strategy and introduces a new Supernova AMO strategy for OETH on mainnet. The refactoring enables code reuse across different Algebra-style DEX pools while making the strategy token-order agnostic.
Changes:
- Extracted a generalized
StableSwapAMMStrategybase contract that works with any Algebra-style stable swap pool - Refactored
SonicSwapXAMOStrategyto inherit from the base contract, removing ~850 lines of duplicated code - Added new
OETHSupernovaAMOStrategyfor OETH/WETH pool on mainnet - Created comprehensive behavior-driven tests that can be reused across different Algebra AMO implementations
- Updated deployment scripts and fixtures to support the new strategy architecture
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
contracts/contracts/strategies/algebra/StableSwapAMMStrategy.sol |
New generalized base strategy for Algebra stable pools with token-order-agnostic handling |
contracts/contracts/strategies/sonic/SonicSwapXAMOStrategy.sol |
Refactored to inherit from base, reducing from ~850 to ~5 lines |
contracts/contracts/strategies/algebra/OETHSupernovaAMOStrategy.sol |
New OETH Supernova AMO strategy implementation |
contracts/test/behaviour/algebraAmoStrategy.js |
Comprehensive reusable behavior tests for Algebra AMO strategies |
contracts/test/strategies/sonic/swapx-amo.sonic.fork-test.js |
Refactored to use behavior tests |
contracts/test/strategies/oeth-supernova-amo.mainnet.fork-test.js |
New tests for OETH Supernova strategy |
contracts/deploy/mainnet/178_supernova_AMO.js |
Deployment script for mainnet Supernova AMO |
contracts/deploy/deployActions.js |
Helper functions for pool/gauge creation and strategy deployment |
contracts/test/_fixture.js |
New fixture for OETH Supernova AMO testing |
contracts/test/_fixture-sonic.js |
Enhanced fixture with auto-allocate handling |
contracts/contracts/interfaces/algebra/* |
New interfaces for Algebra pair and gauge contracts |
contracts/utils/addresses.js |
Added Supernova protocol addresses |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| log(`Adding ${config.poolAddOethAmount} WETH to the pool`); | ||
| const wethAmount = parseUnits(cfg.poolAddWethAmount.toString(), 18); | ||
| await weth.connect(josh).transfer(supernovaPool.address, wethAmount); | ||
| } | ||
|
|
||
| // Add OETH to the pool directly. | ||
| if (cfg.poolAddOethAmount > 0) { | ||
| log(`Adding ${config.poolAddOethAmount} OETH to the pool`); |
There was a problem hiding this comment.
The log message says "Adding ${config.poolAddOethAmount} OETH to the pool" but should say "Adding ${cfg.poolAddOethAmount} OETH to the pool". The variable reference is incorrect - it should use cfg instead of config.
| log(`Adding ${config.poolAddOethAmount} WETH to the pool`); | |
| const wethAmount = parseUnits(cfg.poolAddWethAmount.toString(), 18); | |
| await weth.connect(josh).transfer(supernovaPool.address, wethAmount); | |
| } | |
| // Add OETH to the pool directly. | |
| if (cfg.poolAddOethAmount > 0) { | |
| log(`Adding ${config.poolAddOethAmount} OETH to the pool`); | |
| log(`Adding ${cfg.poolAddWethAmount} WETH to the pool`); | |
| const wethAmount = parseUnits(cfg.poolAddWethAmount.toString(), 18); | |
| await weth.connect(josh).transfer(supernovaPool.address, wethAmount); | |
| } | |
| // Add OETH to the pool directly. | |
| if (cfg.poolAddOethAmount > 0) { | |
| log(`Adding ${cfg.poolAddOethAmount} OETH to the pool`); |
contracts/test/_fixture-sonic.js
Outdated
| } | ||
| } | ||
|
|
||
| // Add ETH to the Metapool |
There was a problem hiding this comment.
The comment says "Add ETH to the Metapool" but this is actually adding wS (Wrapped S) to a Sonic SwapX pool, not ETH to a Metapool. The comment should be updated to reflect the actual operation being performed.
There was a problem hiding this comment.
@copilot can you check if this has been fixed? If so, add a comment with the commit
| log(`Adding ${config.poolAddOethAmount} WETH to the pool`); | ||
| const wethAmount = parseUnits(cfg.poolAddWethAmount.toString(), 18); | ||
| await weth.connect(josh).transfer(supernovaPool.address, wethAmount); | ||
| } | ||
|
|
||
| // Add OETH to the pool directly. | ||
| if (cfg.poolAddOethAmount > 0) { | ||
| log(`Adding ${config.poolAddOethAmount} OETH to the pool`); |
There was a problem hiding this comment.
The log message says "Adding ${config.poolAddOethAmount} WETH to the pool" but should say "Adding ${cfg.poolAddWethAmount} WETH to the pool". The variable reference is also incorrect - it should use cfg instead of config, and should reference the poolAddWethAmount field instead of poolAddOethAmount.
| log(`Adding ${config.poolAddOethAmount} WETH to the pool`); | |
| const wethAmount = parseUnits(cfg.poolAddWethAmount.toString(), 18); | |
| await weth.connect(josh).transfer(supernovaPool.address, wethAmount); | |
| } | |
| // Add OETH to the pool directly. | |
| if (cfg.poolAddOethAmount > 0) { | |
| log(`Adding ${config.poolAddOethAmount} OETH to the pool`); | |
| log(`Adding ${cfg.poolAddWethAmount} WETH to the pool`); | |
| const wethAmount = parseUnits(cfg.poolAddWethAmount.toString(), 18); | |
| await weth.connect(josh).transfer(supernovaPool.address, wethAmount); | |
| } | |
| // Add OETH to the pool directly. | |
| if (cfg.poolAddOethAmount > 0) { | |
| log(`Adding ${cfg.poolAddOethAmount} OETH to the pool`); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@naddison36 I've opened a new pull request, #2810, to work on those changes. Once the pull request is ready, I'll request review from you. |
naddison36
left a comment
There was a problem hiding this comment.
I have a separate PR with some changes #2811
| */ | ||
| constructor( | ||
| BaseStrategyConfig memory _baseConfig, | ||
| address _oToken, |
There was a problem hiding this comment.
We could add a call to the Vault's oToken to check the _oToken param. The IVault interface is missing the oToken function so that would need to be added.
It also greats a dependency on the OETH Vault upgrade but I don't think that's a bad thing. The Vault could be upgrade at the same time the Supernova Strategy is deployed
| /** | ||
| * @dev Skim the Algebra pool in case any extra asset or OToken tokens were added | ||
| */ | ||
| modifier skimPool() { |
There was a problem hiding this comment.
On Sonic we skimmed the pool on every transaction with value to avoid complications with donation attacks. Gas was not an issue on Sonic so this was an easy tradeoff.
On Ethereum we need to be more careful with gas. Testing
against a Supernova stable pair, skim only used 52k in gas. With gas costs less than 1 Gwei currently on Ethereum, I think this extra call is fine.
test tx 0x5f17572d31f07af38e3cd774103ae33aced687d0f68fb66bc029b3f6899dcf3d
Supernova AMO
TODO:
deployOETHSupernovaAMOStrategyPoolAndGaugefrom the deploy script once the pool and the gauge are createdWhat was done
SwapXAMOstrategy into a generalized Algebra-based strategy.Test fixes and updates
Why this change
SwapXAMOimplementation was too specialized and was expecting ws / OS tokens in specific order. Also the strategy was named SwapX even though the pool engine underneath was AlgebraWhat isn't done
Code review suggestions
A couple of files have been moved still they should be compared with their old versions:
StableSwapAMMStrategy.solwith theSonicSwapXAMOStrategy.solexample code-diff as of 03e81d9 commit : https://www.diffchecker.com/MdOvAfVf/algebraAmoStrategy.jswith theswapx-amo.sonic.fork-test.jsonline diff tools do a terrible job heresol2uml diff 0x6509f770B83856Ac51613AEe73D1E7bFaD032784 -bn sonic 0xcfE67b6c7B65c8d038e666b3241a161888B7f2b0