-
Notifications
You must be signed in to change notification settings - Fork 2
Wasabi propamm adapter #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c1336a
feat: add Wasabi Prop AMM adapter and related interfaces
WEBthe3rd 7187a8a
msg.value validation
WEBthe3rd 0b9f3b6
Pin fork tests to a specific block number
WEBthe3rd a2ef1a5
Remove native ETH handling
WEBthe3rd 96ed1a1
Add comments
dev-wasabi ffc49ef
style: lint
thepluck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| interface IPropPool { | ||
| /// @notice Swap exact input amount of tokenIn for tokenOut | ||
| /// @param tokenIn The token to swap from | ||
| /// @param amountIn The amount of tokenIn to swap | ||
| /// @param minAmountOut The minimum amount of tokenOut to receive | ||
| /// @return amountOut The amount of tokenOut received | ||
| function swapExactInput(address tokenIn, uint256 amountIn, uint256 minAmountOut) | ||
| external | ||
| returns (uint256 amountOut); | ||
|
|
||
| /// @notice Get the base token of the pool | ||
| /// @return The base token | ||
| function getBaseToken() external view returns (address); | ||
|
|
||
| /// @notice Get the quote token of the pool | ||
| /// @return The quote token | ||
| function getQuoteToken() external view returns (address); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import './IPropPool.sol'; | ||
|
|
||
| import '../../libraries/CalldataDecoder.sol'; | ||
| import '../../libraries/TokenHelper.sol'; | ||
|
|
||
| contract WasabiPropAmmAdapter { | ||
| using TokenHelper for address; | ||
| using CalldataDecoder for bytes; | ||
|
|
||
| function executeWasabiPropAmm( | ||
| bytes calldata data, | ||
| uint256 amountIn, | ||
| address tokenIn, | ||
| address, | ||
| address | ||
| ) external payable returns (uint256 amountUnused, uint256 amountOut) { | ||
| address pool = data.decodeAddress(0); | ||
|
|
||
| // Approve pool to pull tokenIn from this adapter | ||
| tokenIn.forceApprove(pool, amountIn); | ||
|
|
||
| // Execute swap -- pool pulls tokenIn, sends tokenOut back to this contract | ||
| amountOut = IPropPool(pool).swapExactInput(tokenIn, amountIn, 1); | ||
|
qcuong98 marked this conversation as resolved.
|
||
|
|
||
| amountUnused = 0; // PropPool exact-input always consumes full amount | ||
|
qcuong98 marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import 'forge-std/Test.sol'; | ||
|
|
||
| import 'src/adapters/wasabi-prop-amm/WasabiPropAmmAdapter.sol'; | ||
|
|
||
| interface ITestPropPoolFactory { | ||
| function getPropPool(address token) external view returns (address); | ||
| function checkRole(uint64 roleId, address account) external view; | ||
| } | ||
|
|
||
| interface ITestPropPool { | ||
| function getBaseToken() external view returns (address); | ||
| function getQuoteToken() external view returns (address); | ||
| function getPriceOracle() external view returns (address); | ||
| } | ||
|
|
||
| interface ITestPriceOracle { | ||
| struct PriceData { | ||
| uint256 price; | ||
| uint8 precision; | ||
| uint16 volatilityPips; | ||
| uint256 lastUpdated; | ||
| } | ||
|
|
||
| function getUSDPrice(address token) external view returns (PriceData memory); | ||
| } | ||
|
|
||
| contract WasabiPropAmmAdapterTest is Test { | ||
| using TokenHelper for address; | ||
| WasabiPropAmmAdapter adapter; | ||
|
|
||
| address constant FACTORY = 0x851fC799C9F1443A2c1e6B966605A80f8A1b1BF2; | ||
| address constant BASE_WETH = 0x4200000000000000000000000000000000000006; | ||
| address constant BASE_USDC = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913; | ||
| uint64 constant AUTHORIZED_SWAPPER_ROLE = 100; | ||
|
|
||
| address pool; | ||
| address recipient = makeAddr('recipient'); | ||
|
|
||
| string RPC_URL = 'https://mainnet.base.org'; | ||
| uint256 BLOCK_NUMBER = 42_026_331; | ||
|
|
||
| function setUp() public { | ||
| vm.createSelectFork(RPC_URL, BLOCK_NUMBER); | ||
|
|
||
| adapter = new WasabiPropAmmAdapter(); | ||
| pool = ITestPropPoolFactory(FACTORY).getPropPool(BASE_WETH); | ||
|
|
||
| // Mock factory's checkRole to allow the adapter to swap | ||
| vm.mockCall( | ||
| FACTORY, | ||
| abi.encodeWithSelector( | ||
| ITestPropPoolFactory.checkRole.selector, AUTHORIZED_SWAPPER_ROLE, address(adapter) | ||
| ), | ||
| bytes('') | ||
| ); | ||
| } | ||
|
|
||
| function _warpToFreshOracle() internal { | ||
| address oracle = ITestPropPool(pool).getPriceOracle(); | ||
| address baseToken = ITestPropPool(pool).getBaseToken(); | ||
| ITestPriceOracle.PriceData memory priceData = ITestPriceOracle(oracle).getUSDPrice(baseToken); | ||
| vm.warp(priceData.lastUpdated + 1); | ||
| } | ||
|
|
||
| function test_executeWasabiPropAmm(uint256 amountIn, bool tokenToUSDC) public { | ||
| vm.assume(pool != address(0)); | ||
| _warpToFreshOracle(); | ||
|
|
||
| address tokenIn; | ||
| address tokenOut; | ||
| if (tokenToUSDC) { | ||
| tokenIn = BASE_WETH; | ||
| tokenOut = BASE_USDC; | ||
| amountIn = bound(amountIn, 1e15, 1e18); | ||
| } else { | ||
| tokenIn = BASE_USDC; | ||
| tokenOut = BASE_WETH; | ||
| amountIn = bound(amountIn, 1e6, 3000e6); | ||
| } | ||
|
|
||
| deal(tokenIn, address(adapter), amountIn); | ||
|
|
||
| bytes memory data = abi.encode(pool); | ||
| (uint256 amountUnused, uint256 amountOut) = | ||
| adapter.executeWasabiPropAmm(data, amountIn, tokenIn, tokenOut, recipient); | ||
|
|
||
| assertEq(amountUnused, 0); | ||
| assertGt(amountOut, 0); | ||
| // ERC20 output stays in adapter | ||
| assertEq(amountOut, tokenOut.balanceOf(address(adapter))); | ||
| // Input token fully consumed | ||
| assertEq(tokenIn.balanceOf(address(adapter)), 0); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.