From afe7733c9664c8a9f1a46a7ba405fb0357db605e Mon Sep 17 00:00:00 2001 From: byshape Date: Thu, 1 Feb 2024 15:01:02 +0000 Subject: [PATCH 1/4] Bumped libs --- lib/clones-with-immutable-args | 2 +- lib/forge-std | 2 +- lib/limit-order-protocol | 2 +- lib/openzeppelin-contracts | 2 +- lib/solidity-utils | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/clones-with-immutable-args b/lib/clones-with-immutable-args index bf8cb7d..f5ca191 160000 --- a/lib/clones-with-immutable-args +++ b/lib/clones-with-immutable-args @@ -1 +1 @@ -Subproject commit bf8cb7dc50833038c2a27fc61384cb493cb731ab +Subproject commit f5ca191afea933d50a36d101009b5644dc28bc99 diff --git a/lib/forge-std b/lib/forge-std index 155d547..4513bc2 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 155d547c449afa8715f538d69454b83944117811 +Subproject commit 4513bc2063f23c57bee6558799584b518d387a39 diff --git a/lib/limit-order-protocol b/lib/limit-order-protocol index b9f9869..1a32e05 160000 --- a/lib/limit-order-protocol +++ b/lib/limit-order-protocol @@ -1 +1 @@ -Subproject commit b9f986971faf59f1652b6ab2fa949d73ca6e82f8 +Subproject commit 1a32e059f78ddcf1fe6294baed6cafb73a04b685 diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts index 01ef448..7eba10d 160000 --- a/lib/openzeppelin-contracts +++ b/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit 01ef448981be9d20ca85f2faf6ebdf591ce409f3 +Subproject commit 7eba10dd1e4899f5ca93e3ec3a0b3dafff9b1f03 diff --git a/lib/solidity-utils b/lib/solidity-utils index ebf7a89..74f8c2a 160000 --- a/lib/solidity-utils +++ b/lib/solidity-utils @@ -1 +1 @@ -Subproject commit ebf7a8990d65eb9bc00ea8ab4f0cbb2358d78e38 +Subproject commit 74f8c2a3c42403a5c85f94ba5d403f1fef51c1bf From 51b4960fb318c2ebdf2f788c4d8ac7cfaf359dd6 Mon Sep 17 00:00:00 2001 From: byshape Date: Thu, 1 Feb 2024 16:13:55 +0000 Subject: [PATCH 2/4] Added ERC20True token --- .gas-snapshot | 73 +++++++++++++++++++---------------- contracts/mocks/ERC20True.sol | 25 ++++++++++++ scripts/coverage.sh | 2 +- test/utils/BaseSetup.sol | 12 +++--- 4 files changed, 73 insertions(+), 39 deletions(-) create mode 100644 contracts/mocks/ERC20True.sol diff --git a/.gas-snapshot b/.gas-snapshot index 4ff575b..b939931 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,36 +1,43 @@ -EscrowFactoryTest:testFuzz_DeployCloneForMaker(bytes32,uint56,uint56) (runs: 256, μ: 234241, ~: 237956) -EscrowFactoryTest:testFuzz_DeployCloneForTaker(bytes32,uint56) (runs: 256, μ: 180570, ~: 183216) -EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 103525) -EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 185403) +EscrowFactoryTest:testFuzz_DeployCloneForMaker(bytes32,uint56,uint56) (runs: 256, μ: 234430, ~: 238022) +EscrowFactoryTest:testFuzz_DeployCloneForTaker(bytes32,uint56) (runs: 256, μ: 180420, ~: 183244) +EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 103566) +EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 185444) EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForTaker() (gas: 27693) -EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 151053) +EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 151094) EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForTaker() (gas: 32357) EscrowFactoryTest:test_NoUnsafeDeploymentForTaker() (gas: 34955) -EscrowTest:test_CancelDst() (gas: 165089) -EscrowTest:test_CancelPublicSrc() (gas: 229612) -EscrowTest:test_CancelResolverSrc() (gas: 230726) -EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 227976) -EscrowTest:test_NoCancelByAnyoneDst() (gas: 172835) -EscrowTest:test_NoCancelDuringPublicWithdrawalDst() (gas: 170638) -EscrowTest:test_NoCancelDuringResolverWithdrawalDst() (gas: 168342) -EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 225391) -EscrowTest:test_NoFailedNativeTokenTransferCancelDst() (gas: 183492) -EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 245406) -EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 203418) -EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 134412) -EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 259569) -EscrowTest:test_NoWithdrawalByAnyone() (gas: 223124) -EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 168494) -EscrowTest:test_NoWithdrawalDuringFinalityLockDst() (gas: 165554) -EscrowTest:test_NoWithdrawalDuringFinalityLockSrc() (gas: 223953) -EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 169358) -EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 226387) -EscrowTest:test_WithdrawByAnyoneDst() (gas: 187578) -EscrowTest:test_WithdrawByResolverDst() (gas: 186317) -EscrowTest:test_WithdrawByResolverDstNative() (gas: 146388) -EscrowTest:test_WithdrawByResolverPublicDst() (gas: 187946) -EscrowTest:test_WithdrawByResolverPublicDstNative() (gas: 148068) -EscrowTest:test_WithdrawSrc() (gas: 245999) -IntegrationEscrowFactoryTest:testFuzz_DeployCloneForMakerInt(bytes32,uint56,uint56) (runs: 256, μ: 296657, ~: 300125) -IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 281711) -TimelocksLibTest:test_getStartTimestamps() (gas: 15326) \ No newline at end of file +EscrowTest:test_CancelDst() (gas: 165239) +EscrowTest:test_CancelPublicSrc() (gas: 229949) +EscrowTest:test_CancelResolverSrc() (gas: 231041) +EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 228304) +EscrowTest:test_NoCancelByAnyoneDst() (gas: 172973) +EscrowTest:test_NoCancelDuringPublicWithdrawalDst() (gas: 170754) +EscrowTest:test_NoCancelDuringResolverWithdrawalDst() (gas: 168458) +EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 225675) +EscrowTest:test_NoFailedNativeTokenTransferCancelDst() (gas: 183608) +EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 245690) +EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 203498) +EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 134571) +EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 259932) +EscrowTest:test_NoRescueFundsByAnyoneDst() (gas: 222092) +EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 270388) +EscrowTest:test_NoRescueFundsEarlierDst() (gas: 221954) +EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 270682) +EscrowTest:test_NoWithdrawalByAnyone() (gas: 223457) +EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 168588) +EscrowTest:test_NoWithdrawalDuringFinalityLockDst() (gas: 165648) +EscrowTest:test_NoWithdrawalDuringFinalityLockSrc() (gas: 224330) +EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 169493) +EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 226717) +EscrowTest:test_RescueFundsDst() (gas: 200728) +EscrowTest:test_RescueFundsDstNative() (gas: 229187) +EscrowTest:test_RescueFundsSrc() (gas: 253648) +EscrowTest:test_RescueFundsSrcNative() (gas: 255833) +EscrowTest:test_WithdrawByAnyoneDst() (gas: 187714) +EscrowTest:test_WithdrawByResolverDst() (gas: 186497) +EscrowTest:test_WithdrawByResolverDstNative() (gas: 146521) +EscrowTest:test_WithdrawByResolverPublicDst() (gas: 188082) +EscrowTest:test_WithdrawSrc() (gas: 246371) +IntegrationEscrowFactoryTest:testFuzz_DeployCloneForMakerInt(bytes32,uint56,uint56) (runs: 256, μ: 416705, ~: 420173) +IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 401568) +TimelocksLibTest:test_getStartTimestamps() (gas: 15344) \ No newline at end of file diff --git a/contracts/mocks/ERC20True.sol b/contracts/mocks/ERC20True.sol new file mode 100644 index 0000000..449febe --- /dev/null +++ b/contracts/mocks/ERC20True.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.23; + +contract ERC20True { + function transfer(address, uint256) public pure returns (bool) { + return true; + } + + function transferFrom(address, address, uint256) public pure returns (bool) { + return true; + } + + function approve(address, uint256) public pure returns (bool) { + return true; + } + + function balanceOf(address) public pure returns (uint256) { + return 0; + } + + function allowance(address, address) public pure returns (uint256) { + return 0; + } +} diff --git a/scripts/coverage.sh b/scripts/coverage.sh index ddf45bd..6347389 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -10,7 +10,7 @@ lcov \ --rc branch_coverage=1 \ --remove coverage/lcov.info \ --output-file coverage/filtered-lcov.info \ - "*test*" + "*test*" "contracts/mocks/*" # Generate summary lcov \ diff --git a/test/utils/BaseSetup.sol b/test/utils/BaseSetup.sol index fa35ed2..0d2b351 100644 --- a/test/utils/BaseSetup.sol +++ b/test/utils/BaseSetup.sol @@ -15,9 +15,10 @@ import { TokenMock } from "solidity-utils/mocks/TokenMock.sol"; import { Escrow } from "contracts/Escrow.sol"; import { EscrowFactory, IEscrowFactory } from "contracts/EscrowFactory.sol"; +import { ERC20True } from "contracts/mocks/ERC20True.sol"; +import { IEscrow } from "contracts/interfaces/IEscrow.sol"; import { PackedAddresses, PackedAddressesMemLib } from "./libraries/PackedAddressesMemLib.sol"; import { Timelocks, TimelocksSettersLib } from "./libraries/TimelocksSettersLib.sol"; -import { IEscrow } from "contracts/interfaces/IEscrow.sol"; import { Utils, VmSafe } from "./Utils.sol"; @@ -153,7 +154,6 @@ contract BaseSetup is Test { vm.startPrank(bob.addr); dai.approve(address(escrowFactory), 1000 ether); - dai.approve(address(limitOrderProtocol), 1000 ether); inch.approve(address(feeBank), 1000 ether); feeBank.deposit(10 ether); vm.stopPrank(); @@ -225,7 +225,7 @@ contract BaseSetup is Test { uint256 srcAmount, uint256 dstAmount, bool fakeOrder - ) internal view returns( + ) internal returns( IOrderMixin.Order memory order, bytes32 orderHash, bytes memory extraData, @@ -271,11 +271,13 @@ contract BaseSetup is Test { whitelist ); + ERC20True erc20True = new ERC20True(); + (order, extension) = _buildOrder( alice.addr, - bob.addr, + address(0), address(usdc), - address(dai), + address(erc20True), srcAmount, dstAmount, MakerTraits.wrap(0), From e1981f35e1ce8d98e9b7fce5b55266cc5e341c5a Mon Sep 17 00:00:00 2001 From: byshape Date: Thu, 1 Feb 2024 16:28:05 +0000 Subject: [PATCH 3/4] Removed mocks from codecov coverage --- codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/codecov.yml b/codecov.yml index b52d0c4..d0011cc 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +1,3 @@ ignore: - "test" + - "contracts/mocks" From 1e4811e701b52340ee07a41f1efe4c05b7a94f60 Mon Sep 17 00:00:00 2001 From: byshape Date: Thu, 1 Feb 2024 18:05:10 +0000 Subject: [PATCH 4/4] Applied suggestion from the review --- .gas-snapshot | 4 ++-- test/utils/BaseSetup.sol | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index b939931..a47495b 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -38,6 +38,6 @@ EscrowTest:test_WithdrawByResolverDst() (gas: 186497) EscrowTest:test_WithdrawByResolverDstNative() (gas: 146521) EscrowTest:test_WithdrawByResolverPublicDst() (gas: 188082) EscrowTest:test_WithdrawSrc() (gas: 246371) -IntegrationEscrowFactoryTest:testFuzz_DeployCloneForMakerInt(bytes32,uint56,uint56) (runs: 256, μ: 416705, ~: 420173) -IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 401568) +IntegrationEscrowFactoryTest:testFuzz_DeployCloneForMakerInt(bytes32,uint56,uint56) (runs: 256, μ: 416624, ~: 419968) +IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 401360) TimelocksLibTest:test_getStartTimestamps() (gas: 15344) \ No newline at end of file diff --git a/test/utils/BaseSetup.sol b/test/utils/BaseSetup.sol index 0d2b351..4f2041c 100644 --- a/test/utils/BaseSetup.sol +++ b/test/utils/BaseSetup.sol @@ -271,13 +271,11 @@ contract BaseSetup is Test { whitelist ); - ERC20True erc20True = new ERC20True(); - (order, extension) = _buildOrder( alice.addr, address(0), address(usdc), - address(erc20True), + address(new ERC20True()), srcAmount, dstAmount, MakerTraits.wrap(0),