Merge pull request #178 from propeller-heads/router/dc/test-improvements
chore: move single tests to TychoRouterProtocolIntegration.t.sol
This commit is contained in:
1192
Cargo.lock
generated
1192
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -790,6 +790,9 @@ contract TychoRouter is AccessControl, Dispatcher, Pausable, ReentrancyGuard {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Gets balance of a token for a given address. Supports both native ETH and ERC20 tokens.
|
||||
*/
|
||||
function _balanceOf(address token, address owner)
|
||||
internal
|
||||
view
|
||||
|
||||
@@ -2,8 +2,93 @@
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "./TychoRouterTestSetup.sol";
|
||||
import "./executors/UniswapV4Utils.sol";
|
||||
|
||||
contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
function testSingleSwapUSV4CallbackPermit2() public {
|
||||
vm.startPrank(ALICE);
|
||||
uint256 amountIn = 100 ether;
|
||||
deal(USDE_ADDR, ALICE, amountIn);
|
||||
(
|
||||
IAllowanceTransfer.PermitSingle memory permitSingle,
|
||||
bytes memory signature
|
||||
) = handlePermit2Approval(USDE_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
UniswapV4Executor.UniswapV4Pool[] memory pools =
|
||||
new UniswapV4Executor.UniswapV4Pool[](1);
|
||||
pools[0] = UniswapV4Executor.UniswapV4Pool({
|
||||
intermediaryToken: USDT_ADDR,
|
||||
fee: uint24(100),
|
||||
tickSpacing: int24(1)
|
||||
});
|
||||
|
||||
bytes memory protocolData = UniswapV4Utils.encodeExactInput(
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
true,
|
||||
TokenTransfer.TransferType.TRANSFER_PERMIT2_TO_PROTOCOL,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
encodeSingleSwap(address(usv4Executor), protocolData);
|
||||
|
||||
tychoRouter.singleSwapPermit2(
|
||||
amountIn,
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
99943850,
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
permitSingle,
|
||||
signature,
|
||||
swap
|
||||
);
|
||||
|
||||
assertEq(IERC20(USDT_ADDR).balanceOf(ALICE), 99963618);
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testSplitSwapMultipleUSV4Callback() public {
|
||||
// This test has two uniswap v4 hops that will be executed inside of the V4 pool manager
|
||||
// USDE -> USDT -> WBTC
|
||||
uint256 amountIn = 100 ether;
|
||||
deal(USDE_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
UniswapV4Executor.UniswapV4Pool[] memory pools =
|
||||
new UniswapV4Executor.UniswapV4Pool[](2);
|
||||
pools[0] = UniswapV4Executor.UniswapV4Pool({
|
||||
intermediaryToken: USDT_ADDR,
|
||||
fee: uint24(100),
|
||||
tickSpacing: int24(1)
|
||||
});
|
||||
pools[1] = UniswapV4Executor.UniswapV4Pool({
|
||||
intermediaryToken: WBTC_ADDR,
|
||||
fee: uint24(3000),
|
||||
tickSpacing: int24(60)
|
||||
});
|
||||
|
||||
bytes memory protocolData = UniswapV4Utils.encodeExactInput(
|
||||
USDE_ADDR,
|
||||
WBTC_ADDR,
|
||||
true,
|
||||
TokenTransfer.TransferType.TRANSFER_TO_PROTOCOL,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
encodeSingleSwap(address(usv4Executor), protocolData);
|
||||
|
||||
tychoRouter.singleSwap(
|
||||
amountIn, USDE_ADDR, WBTC_ADDR, 118280, false, false, ALICE, swap
|
||||
);
|
||||
|
||||
assertEq(IERC20(WBTC_ADDR).balanceOf(ALICE), 118281);
|
||||
}
|
||||
|
||||
function testSequentialUSV4Integration() public {
|
||||
// Test created with calldata from our router encoder.
|
||||
|
||||
@@ -141,4 +226,49 @@ contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testSingleSwapUSV3Permit2() public {
|
||||
// Trade 1 WETH for DAI with 1 swap on Uniswap V3 using Permit2
|
||||
// Tests entire USV3 flow including callback
|
||||
// 1 WETH -> DAI
|
||||
// (USV3)
|
||||
vm.startPrank(ALICE);
|
||||
uint256 amountIn = 10 ** 18;
|
||||
deal(WETH_ADDR, ALICE, amountIn);
|
||||
(
|
||||
IAllowanceTransfer.PermitSingle memory permitSingle,
|
||||
bytes memory signature
|
||||
) = handlePermit2Approval(WETH_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
uint256 expAmountOut = 1205_128428842122129186; //Swap 1 WETH for 1205.12 DAI
|
||||
bool zeroForOne = false;
|
||||
bytes memory protocolData = encodeUniswapV3Swap(
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
ALICE,
|
||||
DAI_WETH_USV3,
|
||||
zeroForOne,
|
||||
TokenTransfer.TransferType.TRANSFER_PERMIT2_TO_PROTOCOL
|
||||
);
|
||||
bytes memory swap =
|
||||
encodeSingleSwap(address(usv3Executor), protocolData);
|
||||
|
||||
tychoRouter.singleSwapPermit2(
|
||||
amountIn,
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
expAmountOut - 1,
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
permitSingle,
|
||||
signature,
|
||||
swap
|
||||
);
|
||||
|
||||
uint256 finalBalance = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
assertGe(finalBalance, expAmountOut);
|
||||
|
||||
vm.stopPrank();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,56 +349,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testSplitSwapSingleUSV3Permit2() public {
|
||||
// Trade 1 WETH for DAI with 1 swap on Uniswap V3 using Permit2
|
||||
// Tests entire USV3 flow including callback
|
||||
// 1 WETH -> DAI
|
||||
// (USV3)
|
||||
vm.startPrank(ALICE);
|
||||
uint256 amountIn = 10 ** 18;
|
||||
deal(WETH_ADDR, ALICE, amountIn);
|
||||
(
|
||||
IAllowanceTransfer.PermitSingle memory permitSingle,
|
||||
bytes memory signature
|
||||
) = handlePermit2Approval(WETH_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
uint256 expAmountOut = 1205_128428842122129186; //Swap 1 WETH for 1205.12 DAI
|
||||
bool zeroForOne = false;
|
||||
bytes memory protocolData = encodeUniswapV3Swap(
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
ALICE,
|
||||
DAI_WETH_USV3,
|
||||
zeroForOne,
|
||||
TokenTransfer.TransferType.TRANSFER_PERMIT2_TO_PROTOCOL
|
||||
);
|
||||
bytes memory swap = encodeSplitSwap(
|
||||
uint8(0), uint8(1), uint24(0), address(usv3Executor), protocolData
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](1);
|
||||
swaps[0] = swap;
|
||||
|
||||
tychoRouter.splitSwapPermit2(
|
||||
amountIn,
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
expAmountOut - 1,
|
||||
false,
|
||||
false,
|
||||
2,
|
||||
ALICE,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
|
||||
uint256 finalBalance = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||
assertGe(finalBalance, expAmountOut);
|
||||
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testEmptySwapsRevert() public {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
bytes memory swaps = "";
|
||||
@@ -406,97 +356,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouter.exposedSplitSwap(amountIn, 2, swaps);
|
||||
}
|
||||
|
||||
function testSplitSwapSingleUSV4CallbackPermit2() public {
|
||||
vm.startPrank(ALICE);
|
||||
uint256 amountIn = 100 ether;
|
||||
deal(USDE_ADDR, ALICE, amountIn);
|
||||
(
|
||||
IAllowanceTransfer.PermitSingle memory permitSingle,
|
||||
bytes memory signature
|
||||
) = handlePermit2Approval(USDE_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
UniswapV4Executor.UniswapV4Pool[] memory pools =
|
||||
new UniswapV4Executor.UniswapV4Pool[](1);
|
||||
pools[0] = UniswapV4Executor.UniswapV4Pool({
|
||||
intermediaryToken: USDT_ADDR,
|
||||
fee: uint24(100),
|
||||
tickSpacing: int24(1)
|
||||
});
|
||||
|
||||
bytes memory protocolData = UniswapV4Utils.encodeExactInput(
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
true,
|
||||
TokenTransfer.TransferType.TRANSFER_PERMIT2_TO_PROTOCOL,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
|
||||
bytes memory swap = encodeSplitSwap(
|
||||
uint8(0), uint8(1), uint24(0), address(usv4Executor), protocolData
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](1);
|
||||
swaps[0] = swap;
|
||||
|
||||
tychoRouter.splitSwapPermit2(
|
||||
amountIn,
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
99943850,
|
||||
false,
|
||||
false,
|
||||
2,
|
||||
ALICE,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
|
||||
assertEq(IERC20(USDT_ADDR).balanceOf(ALICE), 99963618);
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testSplitSwapMultipleUSV4Callback() public {
|
||||
// This test has two uniswap v4 hops that will be executed inside of the V4 pool manager
|
||||
// USDE -> USDT -> WBTC
|
||||
uint256 amountIn = 100 ether;
|
||||
deal(USDE_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
UniswapV4Executor.UniswapV4Pool[] memory pools =
|
||||
new UniswapV4Executor.UniswapV4Pool[](2);
|
||||
pools[0] = UniswapV4Executor.UniswapV4Pool({
|
||||
intermediaryToken: USDT_ADDR,
|
||||
fee: uint24(100),
|
||||
tickSpacing: int24(1)
|
||||
});
|
||||
pools[1] = UniswapV4Executor.UniswapV4Pool({
|
||||
intermediaryToken: WBTC_ADDR,
|
||||
fee: uint24(3000),
|
||||
tickSpacing: int24(60)
|
||||
});
|
||||
|
||||
bytes memory protocolData = UniswapV4Utils.encodeExactInput(
|
||||
USDE_ADDR,
|
||||
WBTC_ADDR,
|
||||
true,
|
||||
TokenTransfer.TransferType.TRANSFER_TO_PROTOCOL,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
|
||||
bytes memory swap = encodeSplitSwap(
|
||||
uint8(0), uint8(1), uint24(0), address(usv4Executor), protocolData
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](1);
|
||||
swaps[0] = swap;
|
||||
|
||||
tychoRouter.exposedSplitSwap(amountIn, 2, pleEncode(swaps));
|
||||
|
||||
assertEq(IERC20(WBTC_ADDR).balanceOf(ALICE), 118281);
|
||||
}
|
||||
|
||||
function testSplitInputCyclicSwapInternalMethod() public {
|
||||
// This test has start and end tokens that are the same
|
||||
// The flow is:
|
||||
|
||||
@@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut buffer = String::new();
|
||||
io::stdin()
|
||||
.read_to_string(&mut buffer)
|
||||
.map_err(|e| format!("Failed to read from stdin: {}", e))?;
|
||||
.map_err(|e| format!("Failed to read from stdin: {e}"))?;
|
||||
|
||||
if buffer.trim().is_empty() {
|
||||
return Err("No input provided. Expected JSON input on stdin.".into());
|
||||
@@ -108,8 +108,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Output the encoded result as JSON to stdout
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string(&encoded)
|
||||
.map_err(|e| format!("Failed to serialize output: {}", e))?
|
||||
serde_json::to_string(&encoded).map_err(|e| format!("Failed to serialize output: {e}"))?
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -116,8 +116,7 @@ impl Permit2 {
|
||||
Ok(allowance)
|
||||
}
|
||||
Err(err) => Err(EncodingError::RecoverableError(format!(
|
||||
"Call to permit2 allowance method failed with error: {:?}",
|
||||
err
|
||||
"Call to permit2 allowance method failed with error: {err}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
@@ -158,8 +157,7 @@ impl Permit2 {
|
||||
.sign_hash_sync(&hash)
|
||||
.map_err(|e| {
|
||||
EncodingError::FatalError(format!(
|
||||
"Failed to sign permit2 approval with error: {}",
|
||||
e
|
||||
"Failed to sign permit2 approval with error: {e}"
|
||||
))
|
||||
})?;
|
||||
Ok((permit_single, signature))
|
||||
|
||||
@@ -64,8 +64,7 @@ impl ProtocolApprovalsManager {
|
||||
Ok(allowance.is_zero())
|
||||
}
|
||||
Err(err) => Err(EncodingError::RecoverableError(format!(
|
||||
"Allowance call failed with error: {:?}",
|
||||
err
|
||||
"Allowance call failed with error: {err}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +90,7 @@ impl StrategyEncoder for SingleSwapStrategyEncoder {
|
||||
let number_of_groups = grouped_swaps.len();
|
||||
if number_of_groups != 1 {
|
||||
return Err(EncodingError::InvalidInput(format!(
|
||||
"Executor strategy only supports exactly one swap for non-groupable protocols. Found {}",
|
||||
number_of_groups
|
||||
"Executor strategy only supports exactly one swap for non-groupable protocols. Found {number_of_groups}",
|
||||
)))
|
||||
}
|
||||
|
||||
@@ -119,8 +118,7 @@ impl StrategyEncoder for SingleSwapStrategyEncoder {
|
||||
.get_swap_encoder(&protocol)
|
||||
.ok_or_else(|| {
|
||||
EncodingError::InvalidInput(format!(
|
||||
"Swap encoder not found for protocol: {}",
|
||||
protocol
|
||||
"Swap encoder not found for protocol: {protocol}"
|
||||
))
|
||||
})?;
|
||||
|
||||
@@ -303,8 +301,7 @@ impl StrategyEncoder for SequentialSwapStrategyEncoder {
|
||||
.get_swap_encoder(&protocol)
|
||||
.ok_or_else(|| {
|
||||
EncodingError::InvalidInput(format!(
|
||||
"Swap encoder not found for protocol: {}",
|
||||
protocol
|
||||
"Swap encoder not found for protocol: {protocol}",
|
||||
))
|
||||
})?;
|
||||
|
||||
@@ -547,8 +544,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
||||
.get_swap_encoder(&protocol)
|
||||
.ok_or_else(|| {
|
||||
EncodingError::InvalidInput(format!(
|
||||
"Swap encoder not found for protocol: {}",
|
||||
protocol
|
||||
"Swap encoder not found for protocol: {protocol}",
|
||||
))
|
||||
})?;
|
||||
|
||||
@@ -780,7 +776,7 @@ mod tests {
|
||||
"0000000000000000000000000000", // padding
|
||||
));
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_single_swap_strategy_encoder: {}", hex_calldata);
|
||||
println!("test_single_swap_strategy_encoder: {hex_calldata}");
|
||||
|
||||
assert_eq!(hex_calldata[..456], expected_input);
|
||||
assert_eq!(hex_calldata[1224..], expected_swap);
|
||||
@@ -862,7 +858,7 @@ mod tests {
|
||||
let hex_calldata = encode(&calldata);
|
||||
|
||||
assert_eq!(hex_calldata, expected_input);
|
||||
println!("test_single_swap_strategy_encoder_no_permit2: {}", hex_calldata);
|
||||
println!("test_single_swap_strategy_encoder_no_permit2: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -941,7 +937,7 @@ mod tests {
|
||||
let hex_calldata = encode(&calldata);
|
||||
|
||||
assert_eq!(hex_calldata, expected_input);
|
||||
println!("test_single_swap_strategy_encoder_no_transfer_in: {}", hex_calldata);
|
||||
println!("test_single_swap_strategy_encoder_no_transfer_in: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -994,7 +990,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_single_swap_strategy_encoder_wrap: {}", hex_calldata);
|
||||
println!("test_single_swap_strategy_encoder_wrap: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1047,7 +1043,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_split_swap_strategy_encoder_unwrap: {}", hex_calldata);
|
||||
println!("test_split_swap_strategy_encoder_unwrap: {hex_calldata}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1117,8 +1113,8 @@ mod tests {
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("test_sequential_swap_strategy_encoder: {}", _hex_calldata);
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_sequential_swap_strategy_encoder: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1178,7 +1174,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_sequential_swap_strategy_encoder_no_permit2: {}", hex_calldata);
|
||||
println!("test_sequential_swap_strategy_encoder_no_permit2: {hex_calldata}");
|
||||
|
||||
let expected = String::from(concat!(
|
||||
"e8a980d7", /* function selector */
|
||||
@@ -1338,7 +1334,7 @@ mod tests {
|
||||
|
||||
assert_eq!(hex_calldata[..456], expected_input);
|
||||
assert_eq!(hex_calldata[1224..], expected_swaps);
|
||||
println!("test_cyclic_sequential_swap_split_strategy: {}", hex_calldata);
|
||||
println!("test_cyclic_sequential_swap_split_strategy: {hex_calldata}");
|
||||
}
|
||||
|
||||
mod optimized_transfers {
|
||||
@@ -1415,8 +1411,8 @@ mod tests {
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("test_uniswap_v3_uniswap_v2: {}", _hex_calldata);
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_uniswap_v3_uniswap_v2: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1497,8 +1493,8 @@ mod tests {
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("test_uniswap_v3_uniswap_v3: {}", _hex_calldata);
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_uniswap_v3_uniswap_v3: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1583,8 +1579,8 @@ mod tests {
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("test_uniswap_v3_curve: {}", _hex_calldata);
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_uniswap_v3_curve: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1650,8 +1646,8 @@ mod tests {
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("test_balancer_v2_uniswap_v2: {}", _hex_calldata);
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_balancer_v2_uniswap_v2: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1799,8 +1795,8 @@ mod tests {
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("multi_protocol: {}", _hex_calldata);
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("multi_protocol: {hex_calldata}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1898,8 +1894,8 @@ mod tests {
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
|
||||
let _hex_calldata = encode(&calldata);
|
||||
println!("test_split_swap_strategy_encoder: {}", _hex_calldata);
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_split_swap_strategy_encoder: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2066,7 +2062,7 @@ mod tests {
|
||||
.join("");
|
||||
assert_eq!(hex_calldata[..520], expected_input);
|
||||
assert_eq!(hex_calldata[1288..], expected_swaps);
|
||||
println!("test_split_input_cyclic_swap: {}", hex_calldata);
|
||||
println!("test_split_input_cyclic_swap: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2231,7 +2227,7 @@ mod tests {
|
||||
|
||||
assert_eq!(hex_calldata[..520], expected_input);
|
||||
assert_eq!(hex_calldata[1288..], expected_swaps);
|
||||
println!("test_split_output_cyclic_swap: {}", hex_calldata);
|
||||
println!("test_split_output_cyclic_swap: {hex_calldata}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2301,7 +2297,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_single_encoding_strategy_ekubo: {}", hex_calldata);
|
||||
println!("test_single_encoding_strategy_ekubo: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2366,7 +2362,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let hex_calldata = encode(&calldata);
|
||||
|
||||
println!("test_single_encoding_strategy_usv4_eth_in: {}", hex_calldata);
|
||||
println!("test_single_encoding_strategy_usv4_eth_in: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2435,7 +2431,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_single_encoding_strategy_usv4_eth_out: {}", hex_calldata);
|
||||
println!("test_single_encoding_strategy_usv4_eth_out: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2564,7 +2560,7 @@ mod tests {
|
||||
|
||||
assert_eq!(hex_calldata[..456], expected_input);
|
||||
assert_eq!(hex_calldata[1224..], expected_swaps);
|
||||
println!("test_sequential_encoding_strategy_usv4: {}", hex_calldata);
|
||||
println!("test_sequential_encoding_strategy_usv4: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2627,7 +2623,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_split_encoding_strategy_curve: {}", hex_calldata);
|
||||
println!("test_split_encoding_strategy_curve: {hex_calldata}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2690,7 +2686,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let hex_calldata = encode(&calldata);
|
||||
println!("test_single_encoding_strategy_curve_st_eth: {}", hex_calldata);
|
||||
println!("test_single_encoding_strategy_curve_st_eth: {hex_calldata}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +150,7 @@ impl SplitSwapValidator {
|
||||
if token_swaps.len() == 1 {
|
||||
if token_swaps[0].split != 0.0 {
|
||||
return Err(EncodingError::InvalidInput(format!(
|
||||
"Single swap must have 0% split for token {:?}",
|
||||
token
|
||||
"Single swap must have 0% split for token {token}",
|
||||
)));
|
||||
}
|
||||
continue;
|
||||
@@ -163,16 +162,14 @@ impl SplitSwapValidator {
|
||||
match (swap.split == 0.0, i == token_swaps.len() - 1) {
|
||||
(true, false) => {
|
||||
return Err(EncodingError::InvalidInput(format!(
|
||||
"The 0% split for token {:?} must be the last swap",
|
||||
token
|
||||
"The 0% split for token {token} must be the last swap",
|
||||
)))
|
||||
}
|
||||
(true, true) => found_zero_split = true,
|
||||
(false, _) => {
|
||||
if swap.split < 0.0 {
|
||||
return Err(EncodingError::InvalidInput(format!(
|
||||
"All splits must be >= 0% for token {:?}",
|
||||
token
|
||||
"All splits must be >= 0% for token {token}"
|
||||
)));
|
||||
}
|
||||
total_percentage += swap.split;
|
||||
@@ -182,8 +179,7 @@ impl SplitSwapValidator {
|
||||
|
||||
if !found_zero_split {
|
||||
return Err(EncodingError::InvalidInput(format!(
|
||||
"Token {:?} must have exactly one 0% split for remainder handling",
|
||||
token
|
||||
"Token {token} must have exactly one 0% split for remainder handling"
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ impl SwapEncoderRegistry {
|
||||
let config_str = if let Some(ref path) = executors_file_path {
|
||||
fs::read_to_string(path).map_err(|e| {
|
||||
EncodingError::FatalError(format!(
|
||||
"Error reading executors file from {:?}: {}",
|
||||
executors_file_path, e
|
||||
"Error reading executors file from {executors_file_path:?}: {e}",
|
||||
))
|
||||
})?
|
||||
} else {
|
||||
|
||||
@@ -408,8 +408,7 @@ impl CurveSwapEncoder {
|
||||
// StableSwap factory
|
||||
"0x4F8846Ae9380B90d2E71D5e3D042dff3E7ebb40d" => Ok(U8::from(1)),
|
||||
_ => Err(EncodingError::FatalError(format!(
|
||||
"Unsupported curve factory address: {}",
|
||||
factory_address
|
||||
"Unsupported curve factory address: {factory_address}"
|
||||
))),
|
||||
},
|
||||
}
|
||||
@@ -466,8 +465,7 @@ impl CurveSwapEncoder {
|
||||
if token_in != native_token_curve_address && token_out != native_token_curve_address
|
||||
{
|
||||
Err(EncodingError::RecoverableError(format!(
|
||||
"Curve meta registry call failed with error: {:?}",
|
||||
err
|
||||
"Curve meta registry call failed with error: {err}"
|
||||
)))
|
||||
} else {
|
||||
let wrapped_token = bytes_to_address(&self.wrapped_native_token_address)?;
|
||||
@@ -832,7 +830,7 @@ mod tests {
|
||||
.encode_swap(swap, encoding_context)
|
||||
.unwrap();
|
||||
let hex_swap = encode(&encoded_swap);
|
||||
println!("test_encode_uniswap_v4_simple_swap: {}", hex_swap);
|
||||
println!("test_encode_uniswap_v4_simple_swap: {hex_swap}");
|
||||
|
||||
assert_eq!(
|
||||
hex_swap,
|
||||
@@ -1003,7 +1001,7 @@ mod tests {
|
||||
let combined_hex =
|
||||
format!("{}{}", encode(&initial_encoded_swap), encode(&second_encoded_swap));
|
||||
|
||||
println!("test_encode_uniswap_v4_sequential_swap: {}", combined_hex);
|
||||
println!("test_encode_uniswap_v4_sequential_swap: {combined_hex}");
|
||||
assert_eq!(
|
||||
combined_hex,
|
||||
String::from(concat!(
|
||||
@@ -1032,7 +1030,7 @@ mod tests {
|
||||
"00003c"
|
||||
))
|
||||
);
|
||||
println!("{}", combined_hex)
|
||||
println!("{combined_hex}")
|
||||
}
|
||||
}
|
||||
mod ekubo {
|
||||
@@ -1161,7 +1159,7 @@ mod tests {
|
||||
let combined_hex =
|
||||
format!("{}{}", encode(first_encoded_swap), encode(second_encoded_swap));
|
||||
|
||||
println!("{}", combined_hex);
|
||||
println!("{combined_hex}");
|
||||
assert_eq!(
|
||||
combined_hex,
|
||||
// transfer type
|
||||
|
||||
@@ -235,8 +235,7 @@ impl TychoExecutorEncoder {
|
||||
let number_of_groups = grouped_swaps.len();
|
||||
if number_of_groups > 1 {
|
||||
return Err(EncodingError::InvalidInput(format!(
|
||||
"Tycho executor encoder only supports one swap. Found {}",
|
||||
number_of_groups
|
||||
"Tycho executor encoder only supports one swap. Found {number_of_groups}"
|
||||
)))
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn bytes_to_address(address: &Bytes) -> Result<Address, EncodingError> {
|
||||
if address.len() == 20 {
|
||||
Ok(Address::from_slice(address))
|
||||
} else {
|
||||
Err(EncodingError::InvalidInput(format!("Invalid address: {:?}", address)))
|
||||
Err(EncodingError::InvalidInput(format!("Invalid address: {address}",)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ pub fn get_token_position(tokens: Vec<Bytes>, token: Bytes) -> Result<U8, Encodi
|
||||
.iter()
|
||||
.position(|t| *t == token)
|
||||
.ok_or_else(|| {
|
||||
EncodingError::InvalidInput(format!("Token {:?} not found in tokens array", token))
|
||||
EncodingError::InvalidInput(format!("Token {token} not found in tokens array"))
|
||||
})?,
|
||||
);
|
||||
Ok(position)
|
||||
@@ -121,9 +121,7 @@ pub fn get_static_attribute(swap: &Swap, attribute_name: &str) -> Result<Vec<u8>
|
||||
.component
|
||||
.static_attributes
|
||||
.get(attribute_name)
|
||||
.ok_or_else(|| {
|
||||
EncodingError::FatalError(format!("Attribute {} not found", attribute_name))
|
||||
})?
|
||||
.ok_or_else(|| EncodingError::FatalError(format!("Attribute {attribute_name} not found")))?
|
||||
.to_vec())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user