Skip to content
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

[SC-1245][SC-1256] Deploy test stand #107

Merged
merged 11 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 474076)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 473718)
EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 195267)
EscrowFactoryTest:test_MultipleFillsInvalidKey() (gas: 474157)
EscrowFactoryTest:test_MultipleFillsInvalidSecretsAmount() (gas: 473799)
EscrowFactoryTest:test_NoDeploymentForNotResolver() (gas: 195258)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMaker() (gas: 128468)
EscrowFactoryTest:test_NoInsufficientBalanceDeploymentForTaker() (gas: 27118)
EscrowFactoryTest:test_NoInsufficientBalanceNativeDeploymentForMaker() (gas: 121693)
Expand All @@ -10,68 +10,68 @@ EscrowTest:test_CancelDst() (gas: 116076)
EscrowTest:test_CancelDstDifferentTarget() (gas: 143334)
EscrowTest:test_CancelDstWithNativeToken() (gas: 93670)
EscrowTest:test_CancelPublicSrc() (gas: 170900)
EscrowTest:test_CancelResolverSrc() (gas: 168624)
EscrowTest:test_CancelResolverSrc() (gas: 168607)
EscrowTest:test_CancelResolverSrcReceiver() (gas: 179361)
EscrowTest:test_NoAnyoneCancelDuringResolverCancelSrc() (gas: 163856)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 286516)
EscrowTest:test_NoCallsWithInvalidImmutables() (gas: 286518)
EscrowTest:test_NoCancelByAnyoneDst() (gas: 121726)
EscrowTest:test_NoCancelDuringWithdrawalDst() (gas: 121486)
EscrowTest:test_NoCancelDuringWithdrawalSrc() (gas: 164001)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 216883)
EscrowTest:test_NoFailedNativeTokenTransferCancelSrc() (gas: 216919)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDst() (gas: 192056)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalDstNative() (gas: 84157)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 349789)
EscrowTest:test_NoFailedNativeTokenTransferWithdrawalSrc() (gas: 349820)
EscrowTest:test_NoPublicCallsByAnyone() (gas: 287575)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 168592)
EscrowTest:test_NoPublicCancelDuringPrivateCancellationSrc() (gas: 168572)
EscrowTest:test_NoPublicWithdrawOutsideOfAllowedPeriodDst() (gas: 137737)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 179922)
EscrowTest:test_NoPublicWithdrawalOutsideOfAllowedPeriodSrc() (gas: 179920)
EscrowTest:test_NoRescueFundsByAnyoneDst() (gas: 176333)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 209064)
EscrowTest:test_NoRescueFundsByAnyoneSrc() (gas: 209079)
EscrowTest:test_NoRescueFundsEarlierDst() (gas: 175721)
EscrowTest:test_NoRescueFundsEarlierSrc() (gas: 208959)
EscrowTest:test_NoWithdrawalByAnyoneSrc() (gas: 160853)
EscrowTest:test_NoWithdrawalByNonResolverDst() (gas: 121439)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodDst() (gas: 126326)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 169636)
EscrowTest:test_NoWithdrawalOutsideOfAllowedPeriodSrc() (gas: 169627)
EscrowTest:test_NoWithdrawalWithWrongSecretDst() (gas: 122798)
EscrowTest:test_NoWithdrawalWithWrongSecretSrc() (gas: 164448)
EscrowTest:test_PublicWithdrawSrc() (gas: 187170)
EscrowTest:test_PublicWithdrawSrc() (gas: 187154)
EscrowTest:test_RescueFundsDst() (gas: 158237)
EscrowTest:test_RescueFundsDstNative() (gas: 186700)
EscrowTest:test_RescueFundsSrc() (gas: 195453)
EscrowTest:test_RescueFundsSrc() (gas: 195445)
EscrowTest:test_RescueFundsSrcNative() (gas: 197742)
EscrowTest:test_WithdrawByAnyoneDst() (gas: 146701)
EscrowTest:test_WithdrawByResolverDst() (gas: 142374)
EscrowTest:test_WithdrawByResolverDstNative() (gas: 97859)
EscrowTest:test_WithdrawByResolverPublicDst() (gas: 141720)
EscrowTest:test_WithdrawSrc() (gas: 186522)
EscrowTest:test_WithdrawSrcTo() (gas: 191352)
IntegrationEscrowFactoryTest:test_DeployCloneForMakerNonWhitelistedResolverInt() (gas: 510174)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 341264)
IntegrationEscrowFactoryTest:test_NoResolverReentrancy() (gas: 2065187)
EscrowTest:test_WithdrawSrcTo() (gas: 191335)
IntegrationEscrowFactoryTest:test_DeployCloneForMakerNonWhitelistedResolverInt() (gas: 510255)
IntegrationEscrowFactoryTest:test_NoInsufficientBalanceDeploymentForMakerInt() (gas: 341345)
IntegrationEscrowFactoryTest:test_NoResolverReentrancy() (gas: 2065268)
IntegrationResolverMockTest:test_MockCancelDst() (gas: 157134)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 353957)
IntegrationResolverMockTest:test_MockCancelSrc() (gas: 354038)
IntegrationResolverMockTest:test_MockDeployDst() (gas: 151470)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 364921)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 397880)
IntegrationResolverMockTest:test_MockDeploySrc() (gas: 364984)
IntegrationResolverMockTest:test_MockPublicCancelSrc() (gas: 397961)
IntegrationResolverMockTest:test_MockPublicWithdrawDst() (gas: 170216)
IntegrationResolverMockTest:test_MockRescueFundsDst() (gas: 161053)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 382583)
IntegrationResolverMockTest:test_MockRescueFundsSrc() (gas: 382664)
IntegrationResolverMockTest:test_MockWithdrawDst() (gas: 182875)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 354839)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 923554)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllFromLast() (gas: 922336)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 922136)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 707614)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 932984)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 707218)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 301456)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoReuseOfSecrets() (gas: 1069228)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 785978)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 444783)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 707615)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 921433)
MerkleStorageInvalidatorTest:test_ShortenedProofIsNotValid() (gas: 230605)
IntegrationResolverMockTest:test_MockWithdrawToSrc() (gas: 354920)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllExtra() (gas: 923635)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllFromLast() (gas: 922417)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillAllTwoFills() (gas: 922239)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirst() (gas: 707710)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillFirstTwoFills() (gas: 933041)
MerkleStorageInvalidatorIntTest:test_MultipleFillsFillLast() (gas: 707378)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoDeploymentWithoutValidation() (gas: 301424)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoReuseOfSecrets() (gas: 1068098)
MerkleStorageInvalidatorIntTest:test_MultipleFillsNoSecondDeploymentWithTheSameIndex() (gas: 786092)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOddDivision() (gas: 444873)
MerkleStorageInvalidatorIntTest:test_MultipleFillsOneFill() (gas: 707726)
MerkleStorageInvalidatorIntTest:test_MultipleFillsTwoFills() (gas: 921505)
MerkleStorageInvalidatorTest:test_ShortenedProofIsNotValid() (gas: 230686)
TimelocksLibTest:test_NoTimelocksOverflow() (gas: 193707)
TimelocksLibTest:test_getStartTimestamps() (gas: 16207)
TimelocksLibTest:test_setDeployedAt() (gas: 5741)
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ build
.coverage_artifacts
.idea
.env
.env.deployment
.DS_Store

# foundry
cache_forge
out
broadcast

# zkSync
zkout
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ignore:
- "test"
- "contracts/mocks"
- "script"
64 changes: 32 additions & 32 deletions deployments/arbitrum/EscrowFactory.json

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions deployments/avalanche/EscrowFactory.json

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions deployments/base/EscrowFactory.json

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions deployments/bsc/EscrowFactory.json

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions deployments/gnosis/EscrowFactory.json

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions deployments/mainnet/EscrowFactory.json

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions deployments/optimism/EscrowFactory.json

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions deployments/polygon/EscrowFactory.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"lint:fix": "solhint --max-warnings 0 \"contracts/**/*.sol\" \"test/**/*.sol\" --fix",
"test": "FOUNDRY_PROFILE=default forge snapshot --no-match-test \"testFuzz_*\"",
"test:lite": "FOUNDRY_PROFILE=lite forge test -vvv",
"test:zksync": "FOUNDRY_PROFILE=zksync forge test -vvv --zksync"
"test:zksync": "FOUNDRY_PROFILE=zksync forge test -vvv --zksync",
"deploy": "./scripts/deploy.sh"
}
}
51 changes: 51 additions & 0 deletions script/DeployEscrowFactory.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.23;

import { Script } from "forge-std/Script.sol";

import { ICreate3Deployer } from "solidity-utils/contracts/interfaces/ICreate3Deployer.sol";

import { EscrowFactory } from "contracts/EscrowFactory.sol";

// solhint-disable no-console
import { console } from "forge-std/console.sol";

contract DeployEscrowFactory is Script {
uint32 public constant RESCUE_DELAY = 691200; // 8 days
bytes32 public constant CROSSCHAIN_SALT = keccak256("1inch EscrowFactory");

address public constant LOP = 0x111111125421cA6dc452d289314280a0f8842A65; // All chains
address public constant ACCESS_TOKEN = 0xACCe550000159e70908C0499a1119D04e7039C28; // All chains
ICreate3Deployer public constant CREATE3_DEPLOYER = ICreate3Deployer(0x65B3Db8bAeF0215A1F9B14c506D2a3078b2C84AE); // All chains

mapping(uint256 => address) public FEE_TOKEN;

function run() external {
FEE_TOKEN[1] = 0x6B175474E89094C44Da98b954EedeAC495271d0F; // Mainnet (DAI)
FEE_TOKEN[56] = 0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3; // BSC (DAI)
FEE_TOKEN[137] = 0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063; // Polygon (DAI)
FEE_TOKEN[43114] = 0xd586E7F844cEa2F87f50152665BCbc2C279D8d70; // Avalanche (DAI)
FEE_TOKEN[100] = 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d; // Gnosis (wXDAI)
FEE_TOKEN[42161] = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1; // Arbitrum One (DAI)
FEE_TOKEN[10] = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1; // Optimism (DAI)
FEE_TOKEN[8453] = 0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb; // Base (DAI)

address deployer = vm.envAddress("DEPLOYER_ADDRESS");
address feeBankOwner = deployer;
address feeToken = FEE_TOKEN[block.chainid];

vm.startBroadcast();
address escrowFactory = CREATE3_DEPLOYER.deploy(
CROSSCHAIN_SALT,
abi.encodePacked(
type(EscrowFactory).creationCode,
abi.encode(LOP, feeToken, ACCESS_TOKEN, feeBankOwner, RESCUE_DELAY, RESCUE_DELAY)
)
);
vm.stopBroadcast();

console.log("Escrow Factory deployed at: ", escrowFactory);
}
}
// solhint-enable no-console
52 changes: 52 additions & 0 deletions script/txn_example/CancelDst.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.23;

import { Script } from "forge-std/Script.sol";
import { Address } from "solidity-utils/contracts/libraries/AddressLib.sol";

import { IBaseEscrow } from "contracts/interfaces/IBaseEscrow.sol";
import { IResolverExample } from "contracts/interfaces/IResolverExample.sol";
import { Timelocks, TimelocksLib } from "contracts/libraries/TimelocksLib.sol";

contract CancelDst is Script {
function run() external {
address deployer = vm.envAddress("DEPLOYER_ADDRESS");
uint256 deployerPK = vm.envUint("DEPLOYER_PRIVATE_KEY");
IResolverExample resolver = IResolverExample(vm.envAddress("RESOLVER"));
// address srcToken = vm.envAddress("TOKEN_SRC");
address dstToken = address(0); // ETH
bytes32 orderHash = vm.envBytes32("ORDER_HASH");
Timelocks timelocks = Timelocks.wrap(vm.envUint("TIMELOCKS"));
uint256 deployedAt = vm.envUint("DEPLOYED_AT");

timelocks = TimelocksLib.setDeployedAt(timelocks, deployedAt);
bytes32 secret = keccak256(abi.encodePacked("secret"));
bytes32 hashlock = keccak256(abi.encode(secret));
uint256 dstAmount = 1; // 1 USDC
uint256 safetyDeposit = 1;

IBaseEscrow.Immutables memory immutables = IBaseEscrow.Immutables({
orderHash: orderHash,
amount: dstAmount,
maker: Address.wrap(uint160(deployer)),
taker: Address.wrap(uint160(address(resolver))),
token: Address.wrap(uint160(dstToken)),
hashlock: hashlock,
safetyDeposit: safetyDeposit,
timelocks: timelocks
});

address escrow = vm.envAddress("ESCROW_DST");
// address escrow = IEscrowFactory(escrowFactory).addressOfEscrowDst(immutables);

address[] memory targets = new address[](1);
bytes[] memory data = new bytes[](1);
targets[0] = escrow;
data[0] = abi.encodeWithSelector(IBaseEscrow(escrow).cancel.selector, immutables);

vm.startBroadcast(deployerPK);
resolver.arbitraryCalls(targets, data);
vm.stopBroadcast();
}
}
54 changes: 54 additions & 0 deletions script/txn_example/CancelSrc.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.23;

import { Script } from "forge-std/Script.sol";
import { Address } from "solidity-utils/contracts/libraries/AddressLib.sol";

import { IBaseEscrow } from "contracts/interfaces/IBaseEscrow.sol";
import { IEscrowFactory } from "contracts/interfaces/IEscrowFactory.sol";
import { IResolverExample } from "contracts/interfaces/IResolverExample.sol";
import { Timelocks, TimelocksLib } from "contracts/libraries/TimelocksLib.sol";


contract CancelSrc is Script {
function run() external {
address deployer = vm.envAddress("DEPLOYER_ADDRESS");
uint256 deployerPK = vm.envUint("DEPLOYER_PRIVATE_KEY");
IResolverExample resolver = IResolverExample(vm.envAddress("RESOLVER"));
address escrowFactory = vm.envAddress("ESCROW_FACTORY");
address srcToken = vm.envAddress("TOKEN_SRC");
bytes32 orderHash = vm.envBytes32("ORDER_HASH");
Timelocks timelocks = Timelocks.wrap(vm.envUint("TIMELOCKS"));
uint256 deployedAt = vm.envUint("DEPLOYED_AT");

timelocks = TimelocksLib.setDeployedAt(timelocks, deployedAt);
bytes32 secret = keccak256(abi.encodePacked("secret"));
bytes32 hashlock = keccak256(abi.encode(secret));
uint256 srcAmount = 1; // 1 USDC
uint256 safetyDeposit = 1;

IBaseEscrow.Immutables memory immutables = IBaseEscrow.Immutables({
orderHash: orderHash,
amount: srcAmount,
maker: Address.wrap(uint160(deployer)),
taker: Address.wrap(uint160(address(resolver))),
token: Address.wrap(uint160(srcToken)),
hashlock: hashlock,
safetyDeposit: safetyDeposit,
timelocks: timelocks
});

// address escrow = vm.envAddress("ESCROW_SRC");
address escrow = IEscrowFactory(escrowFactory).addressOfEscrowSrc(immutables);

address[] memory targets = new address[](1);
bytes[] memory data = new bytes[](1);
targets[0] = escrow;
data[0] = abi.encodeWithSelector(IBaseEscrow(escrow).cancel.selector, immutables);

vm.startBroadcast(deployerPK);
resolver.arbitraryCalls(targets, data);
vm.stopBroadcast();
}
}
51 changes: 51 additions & 0 deletions script/txn_example/DeployEscrowDst.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.23;

import { Script } from "forge-std/Script.sol";

import { Timelocks } from "contracts/libraries/TimelocksLib.sol";
import { IBaseEscrow } from "contracts/interfaces/IBaseEscrow.sol";
import { IResolverExample } from "contracts/interfaces/IResolverExample.sol";

import { CrossChainTestLib } from "test/utils/libraries/CrossChainTestLib.sol";

contract DeployEscrowDst is Script {
function run() external {
address deployer = vm.envAddress("DEPLOYER_ADDRESS");
uint256 deployerPK = vm.envUint("DEPLOYER_PRIVATE_KEY");
IResolverExample resolver = IResolverExample(vm.envAddress("RESOLVER"));
bytes32 orderHash = vm.envBytes32("ORDER_HASH");
Timelocks timelocks = Timelocks.wrap(vm.envUint("TIMELOCKS"));

// Prepare data to deploy escrow
address maker = deployer;
address dstToken = address(0); // ETH
uint256 dstAmount = 1; // ETH
uint256 safetyDeposit = 1;
bytes32 secret = keccak256(abi.encodePacked("secret"));
bytes32 hashlock = keccak256(abi.encode(secret));

IBaseEscrow.Immutables memory escrowImmutables = CrossChainTestLib.buildDstEscrowImmutables(
orderHash,
hashlock,
dstAmount,
maker,
address(resolver),
dstToken,
safetyDeposit,
timelocks
);

uint256 srcCancellationTimestamp = type(uint32).max;

{
vm.startBroadcast(deployerPK);
resolver.deployDst{ value: dstAmount + safetyDeposit }(
escrowImmutables,
srcCancellationTimestamp
);
vm.stopBroadcast();
}
}
}
Loading
Loading