refactor(bridge): trustless swap stack and fork test cleanups
Tighten EnhancedSwapRouter, InboxETH, SwapRouter, MerkleProofVerifier; align DEXIntegration and ForkTests with updated behavior. Made-with: Cursor
This commit is contained in:
@@ -577,10 +577,10 @@ contract EnhancedSwapRouter is AccessControl, ReentrancyGuard {
|
||||
* @notice Execute Curve swap
|
||||
*/
|
||||
function _executeCurveSwap(
|
||||
address stablecoinToken,
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMin
|
||||
) internal returns (uint256) {
|
||||
address,
|
||||
uint256,
|
||||
uint256
|
||||
) internal pure returns (uint256) {
|
||||
// Curve 3pool doesn't support WETH directly
|
||||
// Would need intermediate swap or different pool
|
||||
revert("EnhancedSwapRouter: Curve direct swap not supported");
|
||||
@@ -590,9 +590,9 @@ contract EnhancedSwapRouter is AccessControl, ReentrancyGuard {
|
||||
* @notice Execute 1inch swap
|
||||
*/
|
||||
function _execute1inchSwap(
|
||||
address stablecoinToken,
|
||||
address,
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMin
|
||||
uint256
|
||||
) internal returns (uint256) {
|
||||
if (oneInchRouter == address(0)) revert ProviderDisabled();
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ contract InboxETH is ReentrancyGuard {
|
||||
* @param asset Asset address (address(0) for native ETH)
|
||||
* @param amount Deposit amount
|
||||
* @param recipient Recipient address on Ethereum
|
||||
* @param proof Optional proof data (not used in optimistic model, but reserved for future light client)
|
||||
* @return bondAmount Amount of bond posted
|
||||
*/
|
||||
function submitClaim(
|
||||
@@ -104,7 +103,7 @@ contract InboxETH is ReentrancyGuard {
|
||||
address asset,
|
||||
uint256 amount,
|
||||
address recipient,
|
||||
bytes calldata proof
|
||||
bytes calldata
|
||||
) external payable nonReentrant returns (uint256 bondAmount) {
|
||||
if (depositId == 0) revert ZeroDepositId();
|
||||
if (asset == address(0) && amount == 0) revert ZeroAmount();
|
||||
@@ -423,4 +422,4 @@ contract InboxETH is ReentrancyGuard {
|
||||
function getRelayerFee(uint256 depositId) external view returns (RelayerFee memory) {
|
||||
return relayerFees[depositId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ contract SwapRouter is ReentrancyGuard {
|
||||
* @param stablecoinToken Target stablecoin address (USDT, USDC, or DAI)
|
||||
* @param amountIn Input amount
|
||||
* @param amountOutMin Minimum output amount (slippage protection)
|
||||
* @param routeData Optional route data for specific provider
|
||||
* @return amountOut Output amount
|
||||
*/
|
||||
function swapToStablecoin(
|
||||
@@ -104,7 +103,7 @@ contract SwapRouter is ReentrancyGuard {
|
||||
address stablecoinToken,
|
||||
uint256 amountIn,
|
||||
uint256 amountOutMin,
|
||||
bytes calldata routeData
|
||||
bytes calldata
|
||||
) external payable nonReentrant returns (uint256 amountOut) {
|
||||
if (amountIn == 0) revert ZeroAmount();
|
||||
if (stablecoinToken == address(0)) revert ZeroAddress();
|
||||
|
||||
@@ -106,13 +106,12 @@ library MerkleProofVerifier {
|
||||
/**
|
||||
* @notice Verify state root against block header
|
||||
* @param blockHeader Block header bytes
|
||||
* @param stateRoot State root to verify
|
||||
* @return True if state root matches block header
|
||||
* @dev This is a placeholder - in production, implement full block header parsing
|
||||
*/
|
||||
function verifyStateRoot(
|
||||
bytes memory blockHeader,
|
||||
bytes32 stateRoot
|
||||
bytes32
|
||||
) internal pure returns (bool) {
|
||||
// Placeholder: In production, parse RLP-encoded block header and extract state root
|
||||
// For now, require non-empty block header
|
||||
@@ -127,4 +126,3 @@ library MerkleProofVerifier {
|
||||
return true; // Placeholder - always return true for now
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ contract DEXIntegrationTest is Test {
|
||||
);
|
||||
}
|
||||
|
||||
function test_SwapRouter_Addresses() public {
|
||||
function test_SwapRouter_Addresses() public view {
|
||||
// Test contract addresses are set correctly
|
||||
assertEq(swapRouter.uniswapV3Router(), UNISWAP_V3_ROUTER, "Uniswap router should match");
|
||||
assertEq(swapRouter.weth(), WETH, "WETH address should match");
|
||||
@@ -43,7 +43,7 @@ contract DEXIntegrationTest is Test {
|
||||
assertEq(swapRouter.dai(), DAI, "DAI address should match");
|
||||
}
|
||||
|
||||
function test_SwapRouter_FeeTiers() public {
|
||||
function test_SwapRouter_FeeTiers() public view {
|
||||
// Test fee tier constants
|
||||
assertEq(swapRouter.FEE_TIER_LOW(), 500, "Low fee tier should be 0.05%");
|
||||
assertEq(swapRouter.FEE_TIER_MEDIUM(), 3000, "Medium fee tier should be 0.3%");
|
||||
|
||||
@@ -93,10 +93,6 @@ contract ForkTests is Test {
|
||||
// Get initial USDT balance
|
||||
uint256 balanceBefore = IERC20Token(USDT).balanceOf(user);
|
||||
|
||||
// Calculate minimum output (5% slippage tolerance)
|
||||
// We'll use a reasonable estimate - in production, you'd get a quote first
|
||||
uint256 amountOutMin = 0; // For fork test, we'll accept any output
|
||||
|
||||
// Note: This test requires the swapRouter to have the actual swap logic implemented
|
||||
// Since we simplified SwapRouter, this test serves as a template for full implementation
|
||||
|
||||
@@ -109,7 +105,7 @@ contract ForkTests is Test {
|
||||
// LiquidityPoolETH.AssetType.WETH,
|
||||
// USDT,
|
||||
// amountIn,
|
||||
// amountOutMin,
|
||||
// 0,
|
||||
// ""
|
||||
// );
|
||||
|
||||
@@ -119,7 +115,7 @@ contract ForkTests is Test {
|
||||
assertEq(address(swapRouter.usdt()), USDT);
|
||||
}
|
||||
|
||||
function testVerifyUniswapV3RouterExists() public skipIfNoFork {
|
||||
function testVerifyUniswapV3RouterExists() public view skipIfNoFork {
|
||||
// Verify Uniswap V3 Router has code
|
||||
uint256 codeSize;
|
||||
assembly {
|
||||
@@ -128,7 +124,7 @@ contract ForkTests is Test {
|
||||
assertGt(codeSize, 0);
|
||||
}
|
||||
|
||||
function testVerifyTokenAddresses() public skipIfNoFork {
|
||||
function testVerifyTokenAddresses() public view skipIfNoFork {
|
||||
// Verify WETH has code
|
||||
uint256 wethCodeSize;
|
||||
assembly {
|
||||
@@ -151,7 +147,7 @@ contract ForkTests is Test {
|
||||
assertGt(usdcCodeSize, 0);
|
||||
}
|
||||
|
||||
function testVerifyCurve3PoolExists() public skipIfNoFork {
|
||||
function testVerifyCurve3PoolExists() public view skipIfNoFork {
|
||||
// Verify Curve 3pool exists on mainnet
|
||||
uint256 codeSize;
|
||||
assembly {
|
||||
@@ -160,7 +156,7 @@ contract ForkTests is Test {
|
||||
assertGt(codeSize, 0, "Curve 3pool should exist");
|
||||
}
|
||||
|
||||
function testVerifyBalancerVaultExists() public skipIfNoFork {
|
||||
function testVerifyBalancerVaultExists() public view skipIfNoFork {
|
||||
// Verify Balancer V2 Vault exists on mainnet
|
||||
address balancerVault = address(0xBA12222222228d8Ba445958a75a0704d566BF2C8);
|
||||
uint256 codeSize;
|
||||
@@ -170,7 +166,7 @@ contract ForkTests is Test {
|
||||
assertGt(codeSize, 0, "Balancer Vault should exist");
|
||||
}
|
||||
|
||||
function testVerifyDodoexRouterExists() public skipIfNoFork {
|
||||
function testVerifyDodoexRouterExists() public view skipIfNoFork {
|
||||
// Verify Dodoex Router exists on mainnet (if deployed)
|
||||
address dodoexRouter = address(0xa356867fDCEa8e71AEaF87805808803806231FdC); // Dodo V2 Proxy
|
||||
uint256 codeSize;
|
||||
@@ -186,7 +182,7 @@ contract ForkTests is Test {
|
||||
}
|
||||
}
|
||||
|
||||
function testVerify1inchRouterExists() public skipIfNoFork {
|
||||
function testVerify1inchRouterExists() public view skipIfNoFork {
|
||||
// Verify 1inch Router exists on mainnet
|
||||
uint256 codeSize;
|
||||
assembly {
|
||||
@@ -195,7 +191,7 @@ contract ForkTests is Test {
|
||||
assertGt(codeSize, 0, "1inch Router should exist");
|
||||
}
|
||||
|
||||
function testVerifyDAIExists() public skipIfNoFork {
|
||||
function testVerifyDAIExists() public view skipIfNoFork {
|
||||
// Verify DAI exists on mainnet
|
||||
uint256 codeSize;
|
||||
assembly {
|
||||
|
||||
Reference in New Issue
Block a user