chore(adapters): Address PR review

keep mock data as empty bytes
This commit is contained in:
PierreMkt
2024-08-05 13:56:28 -04:00
parent 36c7e94e00
commit 07ca52b2ff
7 changed files with 35 additions and 20 deletions

View File

@@ -60,7 +60,7 @@ contract IntegralSwapAdapter is ISwapAdapter {
address buyToken, address buyToken,
OrderSide side, OrderSide side,
uint256 specifiedAmount, uint256 specifiedAmount,
bytes32 data bytes32
) external override returns (Trade memory trade) { ) external override returns (Trade memory trade) {
if (specifiedAmount == 0) { if (specifiedAmount == 0) {
return trade; return trade;

View File

@@ -10,7 +10,7 @@ import "src/libraries/FractionMath.sol";
contract AdapterTest is Test, ISwapAdapterTypes { contract AdapterTest is Test, ISwapAdapterTypes {
using FractionMath for Fraction; using FractionMath for Fraction;
bytes32 mockData = bytes32(abi.encodePacked(false)); bytes32 mockData;
uint256 constant pricePrecision = 10e24; uint256 constant pricePrecision = 10e24;
string[] public stringPctgs = ["0%", "0.1%", "50%", "100%"]; string[] public stringPctgs = ["0%", "0.1%", "50%", "100%"];

View File

@@ -18,7 +18,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
ITransmuter(0x00253582b2a3FE112feEC532221d9708c64cEFAb); ITransmuter(0x00253582b2a3FE112feEC532221d9708c64cEFAb);
uint256 constant TEST_ITERATIONS = 100; uint256 constant TEST_ITERATIONS = 100;
bytes32 mockData = bytes32(abi.encodePacked(false)); bytes32 mockData;
function setUp() public { function setUp() public {
uint256 forkBlock = 18921770; uint256 forkBlock = 18921770;
@@ -179,19 +179,20 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes {
function testGetCapabilitiesAngle(bytes32 pair, address t0, address t1) function testGetCapabilitiesAngle(bytes32 pair, address t0, address t1)
public public
view
{ {
Capability[] memory res = adapter.getCapabilities(pair, t0, t1); Capability[] memory res = adapter.getCapabilities(pair, t0, t1);
assertEq(res.length, 2); assertEq(res.length, 2);
} }
function testGetTokensAngle() public { function testGetTokensAngle() public view {
address[] memory tokens = adapter.getTokens(bytes32(0)); address[] memory tokens = adapter.getTokens(bytes32(0));
assertGe(tokens.length, 2); assertGe(tokens.length, 2);
} }
function testGetLimitsAngle() public { function testGetLimitsAngle() public view {
bytes32 pair = bytes32(0); bytes32 pair = bytes32(0);
uint256[] memory limits = uint256[] memory limits =
adapter.getLimits(pair, address(agEUR), address(EURC)); adapter.getLimits(pair, address(agEUR), address(EURC));

View File

@@ -12,6 +12,7 @@ import {FractionMath} from "src/libraries/FractionMath.sol";
contract BalancerV2SwapAdapterTest is AdapterTest { contract BalancerV2SwapAdapterTest is AdapterTest {
using FractionMath for Fraction; using FractionMath for Fraction;
bytes32 mockBoolData = bytes32(abi.encode(false));
IVault constant balancerV2Vault = IVault constant balancerV2Vault =
IVault(payable(0xBA12222222228d8Ba445958a75a0704d566BF2C8)); IVault(payable(0xBA12222222228d8Ba445958a75a0704d566BF2C8));
BalancerV2SwapAdapter adapter; BalancerV2SwapAdapter adapter;
@@ -111,7 +112,12 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
uint256 weth_balance = IERC20(WETH).balanceOf(address(this)); uint256 weth_balance = IERC20(WETH).balanceOf(address(this));
Trade memory trade = adapter.swap( Trade memory trade = adapter.swap(
B_80BAL_20WETH_POOL_ID, BAL, WETH, side, specifiedAmount, mockData B_80BAL_20WETH_POOL_ID,
BAL,
WETH,
side,
specifiedAmount,
mockBoolData
); );
if (trade.calculatedAmount > 0) { if (trade.calculatedAmount > 0) {
@@ -154,7 +160,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
WETH, WETH,
OrderSide.Sell, OrderSide.Sell,
amounts[i], amounts[i],
mockData mockBoolData
); );
vm.revertTo(beforeSwap); vm.revertTo(beforeSwap);
@@ -190,7 +196,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
WETH, WETH,
OrderSide.Buy, OrderSide.Buy,
amounts[i], amounts[i],
mockData mockBoolData
); );
vm.revertTo(beforeSwap); vm.revertTo(beforeSwap);
@@ -214,6 +220,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
function testGetCapabilitiesFuzz(bytes32 pool, address t0, address t1) function testGetCapabilitiesFuzz(bytes32 pool, address t0, address t1)
public public
view
{ {
Capability[] memory res = adapter.getCapabilities(pool, t0, t1); Capability[] memory res = adapter.getCapabilities(pool, t0, t1);
@@ -224,7 +231,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest {
assertEq(uint256(res[3]), uint256(Capability.HardLimits)); assertEq(uint256(res[3]), uint256(Capability.HardLimits));
} }
function testGetTokens() public { function testGetTokens() public view {
address[] memory tokens = adapter.getTokens(B_80BAL_20WETH_POOL_ID); address[] memory tokens = adapter.getTokens(B_80BAL_20WETH_POOL_ID);
assertEq(tokens[0], BAL); assertEq(tokens[0], BAL);

View File

@@ -15,7 +15,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
IeEth eEth; IeEth eEth;
uint256 constant TEST_ITERATIONS = 100; uint256 constant TEST_ITERATIONS = 100;
bytes32 mockData = bytes32(abi.encodePacked(false)); bytes32 mockData;
function setUp() public { function setUp() public {
uint256 forkBlock = 19218495; uint256 forkBlock = 19218495;
@@ -404,6 +404,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
function testGetCapabilitiesEtherfi(bytes32 pair, address t0, address t1) function testGetCapabilitiesEtherfi(bytes32 pair, address t0, address t1)
public public
view
{ {
Capability[] memory res = Capability[] memory res =
adapter.getCapabilities(pair, address(t0), address(t1)); adapter.getCapabilities(pair, address(t0), address(t1));
@@ -411,14 +412,14 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes {
assertEq(res.length, 3); assertEq(res.length, 3);
} }
function testGetTokensEtherfi() public { function testGetTokensEtherfi() public view {
bytes32 pair = bytes32(0); bytes32 pair = bytes32(0);
address[] memory tokens = adapter.getTokens(pair); address[] memory tokens = adapter.getTokens(pair);
assertEq(tokens.length, 3); assertEq(tokens.length, 3);
} }
function testGetLimitsEtherfi() public { function testGetLimitsEtherfi() public view {
bytes32 pair = bytes32(0); bytes32 pair = bytes32(0);
uint256[] memory limits = uint256[] memory limits =
adapter.getLimits(pair, address(eEth), address(weEth)); adapter.getLimits(pair, address(eEth), address(weEth));

View File

@@ -16,7 +16,7 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes {
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant USDC_WETH_PAIR = 0x2fe16Dd18bba26e457B7dD2080d5674312b026a2; address constant USDC_WETH_PAIR = 0x2fe16Dd18bba26e457B7dD2080d5674312b026a2;
address constant relayerAddress = 0xd17b3c9784510E33cD5B87b490E79253BcD81e2E; address constant relayerAddress = 0xd17b3c9784510E33cD5B87b490E79253BcD81e2E;
bytes32 mockData = bytes32(abi.encodePacked(false)); bytes32 mockData;
uint256 constant TEST_ITERATIONS = 100; uint256 constant TEST_ITERATIONS = 100;
@@ -31,7 +31,10 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes {
vm.label(address(USDC_WETH_PAIR), "USDC_WETH_PAIR"); vm.label(address(USDC_WETH_PAIR), "USDC_WETH_PAIR");
} }
function testPriceFuzzIntegral(uint256 amount0, uint256 amount1) public { function testPriceFuzzIntegral(uint256 amount0, uint256 amount1)
public
view
{
bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR));
uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH);
vm.assume(amount0 < limits[0]); vm.assume(amount0 < limits[0]);
@@ -159,14 +162,14 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes {
assertEq(res.length, 4); assertEq(res.length, 4);
} }
function testGetTokensIntegral() public { function testGetTokensIntegral() public view {
bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR));
address[] memory tokens = adapter.getTokens(pair); address[] memory tokens = adapter.getTokens(pair);
assertEq(tokens.length, 2); assertEq(tokens.length, 2);
} }
function testGetLimitsIntegral() public { function testGetLimitsIntegral() public view {
bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR));
uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH);

View File

@@ -29,7 +29,7 @@ contract UniswapV2PairFunctionTest is AdapterTest {
vm.label(USDC_WETH_PAIR, "USDC_WETH_PAIR"); vm.label(USDC_WETH_PAIR, "USDC_WETH_PAIR");
} }
function testPriceFuzz(uint256 amount0, uint256 amount1) public { function testPriceFuzz(uint256 amount0, uint256 amount1) public view {
bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR));
uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH);
vm.assume(amount0 < limits[0]); vm.assume(amount0 < limits[0]);
@@ -47,7 +47,7 @@ contract UniswapV2PairFunctionTest is AdapterTest {
} }
} }
function testPriceDecreasing() public { function testPriceDecreasing() public view {
bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR));
uint256[] memory amounts = new uint256[](TEST_ITERATIONS); uint256[] memory amounts = new uint256[](TEST_ITERATIONS);
@@ -149,13 +149,16 @@ contract UniswapV2PairFunctionTest is AdapterTest {
executeIncreasingSwaps(OrderSide.Buy); executeIncreasingSwaps(OrderSide.Buy);
} }
function testGetCapabilities(bytes32 pair, address t0, address t1) public { function testGetCapabilities(bytes32 pair, address t0, address t1)
public
view
{
Capability[] memory res = adapter.getCapabilities(pair, t0, t1); Capability[] memory res = adapter.getCapabilities(pair, t0, t1);
assertEq(res.length, 4); assertEq(res.length, 4);
} }
function testGetLimits() public { function testGetLimits() public view {
bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR));
uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH);