From a2e9fb96afea9bd1975486ba8d0b6b1ee077d4c2 Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Sun, 7 Jan 2024 11:22:38 +0100 Subject: [PATCH] feat: provide support for Bridgehub --- .gitignore | 2 + abi/IBridgehub.json | 631 +++++ abi/IContractDeployer.json | 114 +- abi/IL1Bridge.json | 291 ++- abi/IL1ERC20Bridge.json | 377 +++ abi/IL1SharedBridge.json | 692 ++++++ abi/ITestnetERC20Token.json | 39 + ...kSync.json => IZkSyncStateTransition.json} | 859 ++++++- package.json | 7 +- scripts/entrypoint.sh | 12 +- src/adapters.ts | 1390 ++++++++--- src/provider.ts | 218 +- src/signer.ts | 300 ++- src/typechain/IBridgehub.d.ts | 1737 ++++++++++++++ src/typechain/IBridgehubFactory.ts | 649 +++++ src/typechain/IContractDeployer.d.ts | 348 ++- src/typechain/IContractDeployerFactory.ts | 114 +- src/typechain/ITestnetErc20Token.d.ts | 143 ++ src/typechain/ITestnetErc20TokenFactory.ts | 57 + ...kSync.d.ts => IZkSyncStateTransition.d.ts} | 2129 +++++++++++++++-- ...ry.ts => IZkSyncStateTransitionFactory.ts} | 871 ++++++- src/typechain/Il1Bridge.d.ts | 641 ++++- src/typechain/Il1BridgeFactory.ts | 291 ++- src/typechain/Il1Erc20Bridge.d.ts | 784 ++++++ src/typechain/Il1Erc20BridgeFactory.ts | 395 +++ src/typechain/Il1SharedBridge.d.ts | 1469 ++++++++++++ src/typechain/Il1SharedBridgeFactory.ts | 710 ++++++ src/utils.ts | 90 +- src/wallet.ts | 343 ++- tests/custom-matchers.ts | 50 + tests/files/tokens.json | 192 +- tests/integration/account-abstraction.test.ts | 26 +- tests/integration/contract.test.ts | 9 +- tests/integration/paymaster.test.ts | 120 - tests/integration/provider.test.ts | 229 +- tests/integration/signer.test.ts | 880 +++++-- tests/integration/smart-account.test.ts | 201 +- tests/integration/utils.test.ts | 23 +- tests/integration/wallet.test.ts | 1330 ++++++---- tests/setup.ts | 180 +- tests/unit/signer.test.ts | 20 +- tests/unit/smart-account.test.ts | 59 +- tests/unit/util.test.ts | 35 +- tests/utils.ts | 13 + 44 files changed, 16858 insertions(+), 2212 deletions(-) create mode 100644 abi/IBridgehub.json create mode 100644 abi/IL1ERC20Bridge.json create mode 100644 abi/IL1SharedBridge.json create mode 100644 abi/ITestnetERC20Token.json rename abi/{IZkSync.json => IZkSyncStateTransition.json} (63%) create mode 100644 src/typechain/IBridgehub.d.ts create mode 100644 src/typechain/IBridgehubFactory.ts create mode 100644 src/typechain/ITestnetErc20Token.d.ts create mode 100644 src/typechain/ITestnetErc20TokenFactory.ts rename src/typechain/{IZkSync.d.ts => IZkSyncStateTransition.d.ts} (63%) rename src/typechain/{IZkSyncFactory.ts => IZkSyncStateTransitionFactory.ts} (63%) create mode 100644 src/typechain/Il1Erc20Bridge.d.ts create mode 100644 src/typechain/Il1Erc20BridgeFactory.ts create mode 100644 src/typechain/Il1SharedBridge.d.ts create mode 100644 src/typechain/Il1SharedBridgeFactory.ts delete mode 100644 tests/integration/paymaster.test.ts create mode 100644 tests/utils.ts diff --git a/.gitignore b/.gitignore index 6b29c977..8f194be8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ node_modules tests/build coverage docs +typechain +!src/typechain .idea .vscode diff --git a/abi/IBridgehub.json b/abi/IBridgehub.json new file mode 100644 index 00000000..22db2fd4 --- /dev/null +++ b/abi/IBridgehub.json @@ -0,0 +1,631 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "oldAdmin", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "NewAdmin", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "stateTransitionManager", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "chainGovernance", + "type": "address" + } + ], + "name": "NewChain", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "oldPendingAdmin", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newPendingAdmin", + "type": "address" + } + ], + "name": "NewPendingAdmin", + "type": "event" + }, + { + "inputs": [], + "name": "acceptAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_stateTransitionManager", + "type": "address" + } + ], + "name": "addStateTransitionManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + } + ], + "name": "addToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + } + ], + "name": "baseToken", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_stateTransitionManager", + "type": "address" + }, + { + "internalType": "address", + "name": "_baseToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_salt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_admin", + "type": "address" + }, + { + "internalType": "bytes", + "name": "_initData", + "type": "bytes" + } + ], + "name": "createNewChain", + "outputs": [ + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + } + ], + "name": "getStateTransition", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_gasPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2GasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2GasPerPubdataByteLimit", + "type": "uint256" + } + ], + "name": "l2TransactionBaseCost", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "_l2TxHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "_l2TxNumberInBatch", + "type": "uint16" + }, + { + "internalType": "bytes32[]", + "name": "_merkleProof", + "type": "bytes32[]" + }, + { + "internalType": "enum TxStatus", + "name": "_status", + "type": "uint8" + } + ], + "name": "proveL1ToL2TransactionStatus", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_batchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_index", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint8", + "name": "l2ShardId", + "type": "uint8" + }, + { + "internalType": "bool", + "name": "isService", + "type": "bool" + }, + { + "internalType": "uint16", + "name": "txNumberInBatch", + "type": "uint16" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "key", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "value", + "type": "bytes32" + } + ], + "internalType": "struct L2Log", + "name": "_log", + "type": "tuple" + }, + { + "internalType": "bytes32[]", + "name": "_proof", + "type": "bytes32[]" + } + ], + "name": "proveL2LogInclusion", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_batchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_index", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint16", + "name": "txNumberInBatch", + "type": "uint16" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "internalType": "struct L2Message", + "name": "_message", + "type": "tuple" + }, + { + "internalType": "bytes32[]", + "name": "_proof", + "type": "bytes32[]" + } + ], + "name": "proveL2MessageInclusion", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_stateTransitionManager", + "type": "address" + } + ], + "name": "removeStateTransitionManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "mintValue", + "type": "uint256" + }, + { + "internalType": "address", + "name": "l2Contract", + "type": "address" + }, + { + "internalType": "uint256", + "name": "l2Value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "l2Calldata", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "l2GasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "l2GasPerPubdataByteLimit", + "type": "uint256" + }, + { + "internalType": "bytes[]", + "name": "factoryDeps", + "type": "bytes[]" + }, + { + "internalType": "address", + "name": "refundRecipient", + "type": "address" + } + ], + "internalType": "struct L2TransactionRequestDirect", + "name": "_request", + "type": "tuple" + } + ], + "name": "requestL2TransactionDirect", + "outputs": [ + { + "internalType": "bytes32", + "name": "canonicalTxHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "mintValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "l2Value", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "l2GasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "l2GasPerPubdataByteLimit", + "type": "uint256" + }, + { + "internalType": "address", + "name": "refundRecipient", + "type": "address" + }, + { + "internalType": "address", + "name": "secondBridgeAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "secondBridgeValue", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "secondBridgeCalldata", + "type": "bytes" + } + ], + "internalType": "struct L2TransactionRequestTwoBridgesOuter", + "name": "_request", + "type": "tuple" + } + ], + "name": "requestL2TransactionTwoBridges", + "outputs": [ + { + "internalType": "bytes32", + "name": "canonicalTxHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_newPendingAdmin", + "type": "address" + } + ], + "name": "setPendingAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_sharedBridge", + "type": "address" + } + ], + "name": "setSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "sharedBridge", + "outputs": [ + { + "internalType": "contract IL1SharedBridge", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + } + ], + "name": "stateTransitionManager", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_stateTransitionManager", + "type": "address" + } + ], + "name": "stateTransitionManagerIsRegistered", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_baseToken", + "type": "address" + } + ], + "name": "tokenIsRegistered", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/abi/IContractDeployer.json b/abi/IContractDeployer.json index 8f54565c..2525a786 100644 --- a/abi/IContractDeployer.json +++ b/abi/IContractDeployer.json @@ -84,7 +84,7 @@ "outputs": [ { "internalType": "address", - "name": "newAddress", + "name": "", "type": "address" } ], @@ -113,7 +113,7 @@ "outputs": [ { "internalType": "address", - "name": "newAddress", + "name": "", "type": "address" } ], @@ -147,7 +147,7 @@ "outputs": [ { "internalType": "address", - "name": "newAddress", + "name": "", "type": "address" } ], @@ -158,7 +158,7 @@ "inputs": [ { "internalType": "bytes32", - "name": "_salt", + "name": "", "type": "bytes32" }, { @@ -181,10 +181,114 @@ "outputs": [ { "internalType": "address", - "name": "newAddress", + "name": "", + "type": "address" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "extendedAccountVersion", + "outputs": [ + { + "internalType": "enum IContractDeployer.AccountAbstractionVersion", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "bytecodeHash", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "newAddress", + "type": "address" + }, + { + "internalType": "bool", + "name": "callConstructor", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "input", + "type": "bytes" + } + ], + "internalType": "struct ContractDeployer.ForceDeployment", + "name": "_deployment", + "type": "tuple" + }, + { + "internalType": "address", + "name": "_sender", "type": "address" } ], + "name": "forceDeployOnAddress", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "bytecodeHash", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "newAddress", + "type": "address" + }, + { + "internalType": "bool", + "name": "callConstructor", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "input", + "type": "bytes" + } + ], + "internalType": "struct ContractDeployer.ForceDeployment[]", + "name": "_deployments", + "type": "tuple[]" + } + ], + "name": "forceDeployOnAddresses", + "outputs": [], "stateMutability": "payable", "type": "function" }, diff --git a/abi/IL1Bridge.json b/abi/IL1Bridge.json index 36bc6b52..7069b2de 100644 --- a/abi/IL1Bridge.json +++ b/abi/IL1Bridge.json @@ -2,6 +2,80 @@ { "anonymous": false, "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "txDataHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "l2DepositTxHash", + "type": "bytes32" + } + ], + "name": "BridgehubDepositFinalized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "txDataHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "BridgehubDepositInitiatedSharedBridge", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, { "indexed": true, "internalType": "address", @@ -21,12 +95,18 @@ "type": "uint256" } ], - "name": "ClaimedFailedDeposit", + "name": "ClaimedFailedDepositSharedBridge", "type": "event" }, { "anonymous": false, "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, { "indexed": true, "internalType": "bytes32", @@ -40,7 +120,7 @@ "type": "address" }, { - "indexed": true, + "indexed": false, "internalType": "address", "name": "to", "type": "address" @@ -58,12 +138,18 @@ "type": "uint256" } ], - "name": "DepositInitiated", + "name": "DepositInitiatedSharedBridge", "type": "event" }, { "anonymous": false, "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, { "indexed": true, "internalType": "address", @@ -83,11 +169,136 @@ "type": "uint256" } ], - "name": "WithdrawalFinalized", + "name": "WithdrawalFinalizedSharedBridge", "type": "event" }, + { + "inputs": [], + "name": "bridgehub", + "outputs": [ + { + "internalType": "contract IBridgehub", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "_txDataHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "_txHash", + "type": "bytes32" + } + ], + "name": "bridgehubConfirmL2Transaction", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_prevMsgSender", + "type": "address" + }, + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "bridgehubDeposit", + "outputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "magicValue", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "l2Contract", + "type": "address" + }, + { + "internalType": "bytes", + "name": "l2Calldata", + "type": "bytes" + }, + { + "internalType": "bytes[]", + "name": "factoryDeps", + "type": "bytes[]" + }, + { + "internalType": "bytes32", + "name": "txDataHash", + "type": "bytes32" + } + ], + "internalType": "struct L2TransactionRequestTwoBridgesInner", + "name": "request", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, { "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_prevMsgSender", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "bridgehubDepositBaseToken", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, { "internalType": "address", "name": "_depositSender", @@ -98,6 +309,11 @@ "name": "_l1Token", "type": "address" }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, { "internalType": "bytes32", "name": "_l2TxHash", @@ -131,6 +347,11 @@ }, { "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, { "internalType": "address", "name": "_l2Receiver", @@ -141,6 +362,11 @@ "name": "_l1Token", "type": "address" }, + { + "internalType": "uint256", + "name": "_mintValue", + "type": "uint256" + }, { "internalType": "uint256", "name": "_amount", @@ -175,6 +401,35 @@ }, { "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "_l2TxHash", + "type": "bytes32" + } + ], + "name": "depositHappened", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, { "internalType": "uint256", "name": "_l2BatchNumber", @@ -208,6 +463,11 @@ }, { "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, { "internalType": "uint256", "name": "_l2BatchNumber", @@ -219,7 +479,7 @@ "type": "uint256" } ], - "name": "isWithdrawalFinalized", + "name": "isWithdrawalFinalizedShared", "outputs": [ { "internalType": "bool", @@ -230,28 +490,15 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "l2Bridge", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { - "internalType": "address", - "name": "_l1Token", - "type": "address" + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" } ], - "name": "l2TokenAddress", + "name": "l2BridgeAddress", "outputs": [ { "internalType": "address", diff --git a/abi/IL1ERC20Bridge.json b/abi/IL1ERC20Bridge.json new file mode 100644 index 00000000..bdade3c8 --- /dev/null +++ b/abi/IL1ERC20Bridge.json @@ -0,0 +1,377 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "ClaimedFailedDeposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "l2DepositTxHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "DepositInitiated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "WithdrawalFinalized", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_depositSender", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_l2TxHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "_l2TxNumberInBatch", + "type": "uint16" + }, + { + "internalType": "bytes32[]", + "name": "_merkleProof", + "type": "bytes32[]" + } + ], + "name": "claimFailedDeposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_l2Receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasPerPubdataByte", + "type": "uint256" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "bytes32", + "name": "txHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_l2Receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasPerPubdataByte", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_refundRecipient", + "type": "address" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "bytes32", + "name": "txHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_account", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_depositL2TxHash", + "type": "bytes32" + } + ], + "name": "depositAmount", + "outputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "_l2TxNumberInBatch", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_message", + "type": "bytes" + }, + { + "internalType": "bytes32[]", + "name": "_merkleProof", + "type": "bytes32[]" + } + ], + "name": "finalizeWithdrawal", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + } + ], + "name": "isWithdrawalFinalized", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "l2Bridge", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + } + ], + "name": "l2TokenAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "l2TokenBeacon", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "sharedBridge", + "outputs": [ + { + "internalType": "contract IL1SharedBridge", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "transferTokenToSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/abi/IL1SharedBridge.json b/abi/IL1SharedBridge.json new file mode 100644 index 00000000..a56f86eb --- /dev/null +++ b/abi/IL1SharedBridge.json @@ -0,0 +1,692 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "BridgehubDepositBaseTokenInitiated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "txDataHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "l2DepositTxHash", + "type": "bytes32" + } + ], + "name": "BridgehubDepositFinalized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "txDataHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "BridgehubDepositInitiated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "ClaimedFailedDepositSharedBridge", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "l2DepositTxHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "LegacyDepositInitiated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "WithdrawalFinalizedSharedBridge", + "type": "event" + }, + { + "inputs": [], + "name": "bridgehub", + "outputs": [ + { + "internalType": "contract IBridgehub", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "_txDataHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "_txHash", + "type": "bytes32" + } + ], + "name": "bridgehubConfirmL2Transaction", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_prevMsgSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_l2Value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "bridgehubDeposit", + "outputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "magicValue", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "l2Contract", + "type": "address" + }, + { + "internalType": "bytes", + "name": "l2Calldata", + "type": "bytes" + }, + { + "internalType": "bytes[]", + "name": "factoryDeps", + "type": "bytes[]" + }, + { + "internalType": "bytes32", + "name": "txDataHash", + "type": "bytes32" + } + ], + "internalType": "struct L2TransactionRequestTwoBridgesInner", + "name": "request", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_prevMsgSender", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "bridgehubDepositBaseToken", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_depositSender", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "_l2TxHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "_l2TxNumberInBatch", + "type": "uint16" + }, + { + "internalType": "bytes32[]", + "name": "_merkleProof", + "type": "bytes32[]" + } + ], + "name": "claimFailedDeposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_depositSender", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "_l2TxHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "_l2TxNumberInBatch", + "type": "uint16" + }, + { + "internalType": "bytes32[]", + "name": "_merkleProof", + "type": "bytes32[]" + } + ], + "name": "claimFailedDepositLegacyErc20Bridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "_l2TxHash", + "type": "bytes32" + } + ], + "name": "depositHappened", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_msgSender", + "type": "address" + }, + { + "internalType": "address", + "name": "_l2Receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "_l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2TxGasPerPubdataByte", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_refundRecipient", + "type": "address" + } + ], + "name": "depositLegacyErc20Bridge", + "outputs": [ + { + "internalType": "bytes32", + "name": "txHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "_l2TxNumberInBatch", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_message", + "type": "bytes" + }, + { + "internalType": "bytes32[]", + "name": "_merkleProof", + "type": "bytes32[]" + } + ], + "name": "finalizeWithdrawal", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + }, + { + "internalType": "uint16", + "name": "_l2TxNumberInBatch", + "type": "uint16" + }, + { + "internalType": "bytes", + "name": "_message", + "type": "bytes" + }, + { + "internalType": "bytes32[]", + "name": "_merkleProof", + "type": "bytes32[]" + } + ], + "name": "finalizeWithdrawalLegacyErc20Bridge", + "outputs": [ + { + "internalType": "address", + "name": "l1Receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "l1Token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2BatchNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_l2MessageIndex", + "type": "uint256" + } + ], + "name": "isWithdrawalFinalized", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "l1WethAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + } + ], + "name": "l2BridgeAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "legacyBridge", + "outputs": [ + { + "internalType": "contract IL1ERC20Bridge", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + } + ], + "name": "receiveEth", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_eraFirstPostUpgradeBatch", + "type": "uint256" + } + ], + "name": "setEraFirstPostUpgradeBatch", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/abi/ITestnetERC20Token.json b/abi/ITestnetERC20Token.json new file mode 100644 index 00000000..3c4bbc4e --- /dev/null +++ b/abi/ITestnetERC20Token.json @@ -0,0 +1,39 @@ +[ + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/abi/IZkSync.json b/abi/IZkSyncStateTransition.json similarity index 63% rename from abi/IZkSync.json rename to abi/IZkSyncStateTransition.json index f6480098..d7f8622d 100644 --- a/abi/IZkSync.json +++ b/abi/IZkSyncStateTransition.json @@ -206,38 +206,114 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "oldGovernor", - "type": "address" + "indexed": false, + "internalType": "uint128", + "name": "oldNominator", + "type": "uint128" }, { - "indexed": true, - "internalType": "address", - "name": "newGovernor", - "type": "address" + "indexed": false, + "internalType": "uint128", + "name": "oldDenominator", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "newNominator", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "newDenominator", + "type": "uint128" } ], - "name": "NewGovernor", + "name": "NewBaseTokenMultiplier", "type": "event" }, { "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "oldPendingAdmin", - "type": "address" + "components": [ + { + "internalType": "enum PubdataPricingMode", + "name": "pubdataPricingMode", + "type": "uint8" + }, + { + "internalType": "uint32", + "name": "batchOverheadL1Gas", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "maxPubdataPerBatch", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "maxL2GasPerBatch", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "priorityTxMaxPubdata", + "type": "uint32" + }, + { + "internalType": "uint64", + "name": "minimalL2GasPrice", + "type": "uint64" + } + ], + "indexed": false, + "internalType": "struct FeeParams", + "name": "oldFeeParams", + "type": "tuple" }, { - "indexed": true, - "internalType": "address", - "name": "newPendingAdmin", - "type": "address" + "components": [ + { + "internalType": "enum PubdataPricingMode", + "name": "pubdataPricingMode", + "type": "uint8" + }, + { + "internalType": "uint32", + "name": "batchOverheadL1Gas", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "maxPubdataPerBatch", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "maxL2GasPerBatch", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "priorityTxMaxPubdata", + "type": "uint32" + }, + { + "internalType": "uint64", + "name": "minimalL2GasPrice", + "type": "uint64" + } + ], + "indexed": false, + "internalType": "struct FeeParams", + "name": "newFeeParams", + "type": "tuple" } ], - "name": "NewPendingAdmin", + "name": "NewFeeParams", "type": "event" }, { @@ -246,17 +322,17 @@ { "indexed": true, "internalType": "address", - "name": "oldPendingGovernor", + "name": "oldPendingAdmin", "type": "address" }, { "indexed": true, "internalType": "address", - "name": "newPendingGovernor", + "name": "newPendingAdmin", "type": "address" } ], - "name": "NewPendingGovernor", + "name": "NewPendingAdmin", "type": "event" }, { @@ -364,7 +440,7 @@ } ], "indexed": false, - "internalType": "struct IMailbox.L2CanonicalTransaction", + "internalType": "struct L2CanonicalTransaction", "name": "transaction", "type": "tuple" }, @@ -397,6 +473,89 @@ "name": "NewPriorityTxMaxGasLimit", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "oldTransactionFilterer", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newTransactionFilterer", + "type": "address" + } + ], + "name": "NewTransactionFilterer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "components": [ + { + "internalType": "address", + "name": "facet", + "type": "address" + }, + { + "internalType": "enum Diamond.Action", + "name": "action", + "type": "uint8" + }, + { + "internalType": "bool", + "name": "isFreezable", + "type": "bool" + }, + { + "internalType": "bytes4[]", + "name": "selectors", + "type": "bytes4[]" + } + ], + "internalType": "struct Diamond.FacetCut[]", + "name": "facetCuts", + "type": "tuple[]" + }, + { + "internalType": "address", + "name": "initAddress", + "type": "address" + }, + { + "internalType": "bytes", + "name": "initCalldata", + "type": "bytes" + } + ], + "indexed": false, + "internalType": "struct Diamond.DiamondCutData", + "name": "diamondCut", + "type": "tuple" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "proposalId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "proposalSalt", + "type": "bytes32" + } + ], + "name": "ProposeTransparentUpgrade", + "type": "event" + }, { "anonymous": false, "inputs": [], @@ -422,6 +581,19 @@ "name": "ValidatorStatusUpdate", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "enum PubdataPricingMode", + "name": "validiumMode", + "type": "uint8" + } + ], + "name": "ValidiumModeStatusUpdate", + "type": "event" + }, { "inputs": [], "name": "acceptAdmin", @@ -431,7 +603,137 @@ }, { "inputs": [], - "name": "acceptGovernor", + "name": "baseTokenGasPriceMultiplierDenominator", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseTokenGasPriceMultiplierNominator", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "contractL2", + "type": "address" + }, + { + "internalType": "uint256", + "name": "mintValue", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "l2Value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "l2Calldata", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "l2GasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "l2GasPerPubdataByteLimit", + "type": "uint256" + }, + { + "internalType": "bytes[]", + "name": "factoryDeps", + "type": "bytes[]" + }, + { + "internalType": "address", + "name": "refundRecipient", + "type": "address" + } + ], + "internalType": "struct BridgehubL2TransactionRequest", + "name": "_request", + "type": "tuple" + } + ], + "name": "bridgehubRequestL2Transaction", + "outputs": [ + { + "internalType": "bytes32", + "name": "canonicalTxHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum PubdataPricingMode", + "name": "pubdataPricingMode", + "type": "uint8" + }, + { + "internalType": "uint32", + "name": "batchOverheadL1Gas", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "maxPubdataPerBatch", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "maxL2GasPerBatch", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "priorityTxMaxPubdata", + "type": "uint32" + }, + { + "internalType": "uint64", + "name": "minimalL2GasPrice", + "type": "uint64" + } + ], + "internalType": "struct FeeParams", + "name": "_newFeeParams", + "type": "tuple" + } + ], + "name": "changeFeeParams", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -534,7 +836,7 @@ }, { "internalType": "bytes", - "name": "totalL2ToL1Pubdata", + "name": "pubdataCommitments", "type": "bytes" } ], @@ -548,6 +850,123 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo", + "name": "_lastCommittedBatchData", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "timestamp", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "newStateRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "bootloaderHeapInitialContentsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "eventsQueueStateHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "systemLogs", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "pubdataCommitments", + "type": "bytes" + } + ], + "internalType": "struct IExecutor.CommitBatchInfo[]", + "name": "_newBatchesData", + "type": "tuple[]" + } + ], + "name": "commitBatchesSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -603,6 +1022,66 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo[]", + "name": "_batchesData", + "type": "tuple[]" + } + ], + "name": "executeBatchesSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -773,12 +1252,12 @@ }, { "inputs": [], - "name": "getFirstUnprocessedPriorityTx", + "name": "getAdmin", "outputs": [ { - "internalType": "uint256", + "internalType": "address", "name": "", - "type": "uint256" + "type": "address" } ], "stateMutability": "view", @@ -786,12 +1265,51 @@ }, { "inputs": [], - "name": "getGovernor", + "name": "getBaseToken", "outputs": [ { "internalType": "address", "name": "", - "type": "address" + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getBaseTokenBridge", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getBridgehub", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getFirstUnprocessedPriorityTx", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" } ], "stateMutability": "view", @@ -864,7 +1382,7 @@ }, { "inputs": [], - "name": "getPendingGovernor", + "name": "getPendingAdmin", "outputs": [ { "internalType": "address", @@ -914,6 +1432,32 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "getPubdataPricingMode", + "outputs": [ + { + "internalType": "enum PubdataPricingMode", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getStateTransitionManager", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "getTotalBatchesCommitted", @@ -1115,7 +1659,7 @@ "outputs": [ { "internalType": "bytes32", - "name": "hash", + "name": "merkleRoot", "type": "bytes32" } ], @@ -1300,6 +1844,130 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo", + "name": "_prevBatch", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo[]", + "name": "_committedBatches", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "recursiveAggregationInput", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "serializedProof", + "type": "uint256[]" + } + ], + "internalType": "struct IExecutor.ProofInput", + "name": "_proof", + "type": "tuple" + } + ], + "name": "proveBatchesSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -1348,7 +2016,7 @@ "inputs": [ { "internalType": "uint256", - "name": "_l2BatchNumber", + "name": "_batchNumber", "type": "uint256" }, { @@ -1414,7 +2082,7 @@ "inputs": [ { "internalType": "uint256", - "name": "_l2BatchNumber", + "name": "_batchNumber", "type": "uint256" }, { @@ -1526,12 +2194,17 @@ { "inputs": [ { - "internalType": "address", - "name": "_newPendingAdmin", - "type": "address" + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_newLastBatch", + "type": "uint256" } ], - "name": "setPendingAdmin", + "name": "revertBatchesSharedBridge", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1540,11 +2213,11 @@ "inputs": [ { "internalType": "address", - "name": "_newPendingGovernor", + "name": "_newPendingAdmin", "type": "address" } ], - "name": "setPendingGovernor", + "name": "setPendingAdmin", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1575,6 +2248,37 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "_nominator", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "_denominator", + "type": "uint128" + } + ], + "name": "setTokenMultiplier", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_transactionFilterer", + "type": "address" + } + ], + "name": "setTransactionFilterer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -1593,6 +2297,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "enum PubdataPricingMode", + "name": "_validiumMode", + "type": "uint8" + } + ], + "name": "setValidiumMode", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -1612,11 +2329,75 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "transferEthToSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "unfreezeDiamond", "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_protocolVersion", + "type": "uint256" + }, + { + "components": [ + { + "components": [ + { + "internalType": "address", + "name": "facet", + "type": "address" + }, + { + "internalType": "enum Diamond.Action", + "name": "action", + "type": "uint8" + }, + { + "internalType": "bool", + "name": "isFreezable", + "type": "bool" + }, + { + "internalType": "bytes4[]", + "name": "selectors", + "type": "bytes4[]" + } + ], + "internalType": "struct Diamond.FacetCut[]", + "name": "facetCuts", + "type": "tuple[]" + }, + { + "internalType": "address", + "name": "initAddress", + "type": "address" + }, + { + "internalType": "bytes", + "name": "initCalldata", + "type": "bytes" + } + ], + "internalType": "struct Diamond.DiamondCutData", + "name": "_cutData", + "type": "tuple" + } + ], + "name": "upgradeChainFromVersion", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" } ] diff --git a/package.json b/package.json index ad69dbd7..c1cc7120 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zksync-ethers", - "version": "5.7.0", + "version": "5.8.0-beta.1", "description": "A Web3 library for interacting with the ZkSync Layer 2 scaling solution.", "author": { "name": "Matter Labs", @@ -30,7 +30,8 @@ "files": [ "build/", "abi/", - "src/" + "src/", + "typechain" ], "dependencies": { "ethers": "~5.7.0" @@ -68,7 +69,7 @@ "lint:fix": "gts fix", "watch": "tsc --watch", "types:fetch": "cd scripts && ./update-abi.sh && cd ../", - "types": "rm typechain/*.ts && find ./abi -name \"*.json\" -print0 | xargs -0 -I {} npx typechain --target ethers-v5 --outDir src/typechain {}", + "types": "rm -rf src/typechain/ typechain && find ./abi -name \"*.json\" -print0 | xargs -0 -I {} typechain --target ethers-v5 --outDir src/typechain {} && ncp src/typechain typechain", "clean": "gts clean", "docs": "typedoc --out docs --hideInPageTOC true --useCodeBlocks true --includeVersion true src/index.ts && cd scripts && ./post-process-doc.sh && cd ../" }, diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index ede263b0..bfa96e0c 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -16,11 +16,15 @@ yarn install echo "Generate ABIs" solc --base-path l1-contracts/ \ - --include-path ./node_modules/ \ + --include-path l1-contracts/node_modules/ \ -o l1-abi \ --abi \ - l1-contracts/contracts/zksync/interfaces/IZkSync.sol \ - l1-contracts/contracts/bridge/interfaces/IL1Bridge.sol \ + l1-contracts/contracts/bridgehub/IBridgehub.sol \ + l1-contracts/contracts/state-transition/chain-interfaces/IZkSyncStateTransition.sol \ + l1-contracts/contracts/dev-contracts/interfaces/ITestnetERC20Token.sol \ + l1-contracts/contracts/bridge/interfaces/IL1ERC20Bridge.sol \ + l1-contracts/contracts/bridge/interfaces/IL1WethBridge.sol \ + l1-contracts/contracts/bridge/interfaces/IL1Erc20Bridge.sol \ l1-contracts/contracts/bridge/interfaces/IL2Bridge.sol solc --base-path system-contracts \ @@ -35,7 +39,7 @@ solc --base-path system-contracts \ mkdir abi /abi mv l1-abi/* system-contracts-abi/* abi -contracts="IZkSync.abi IL1Bridge.abi IL2Bridge.abi IContractDeployer.abi IEthToken.abi IL1Messenger.abi INonceHolder.abi IPaymasterFlow.abi" +contracts="IBridgehub.abi IZkSyncStateTransition.abi IL1ERC20Bridge.abi IL1WethBridge.abi IL1Erc20Bridge.abi IL2Bridge.abi IContractDeployer.abi IEthToken.abi IL1Messenger.abi INonceHolder.abi IPaymasterFlow.abi ITestnetERC20Token.abi" for filename in $contracts; do jq '.' "abi/$filename" > "/abi/${filename%.abi}.json" diff --git a/src/adapters.ts b/src/adapters.ts index a4d336f0..096629fb 100644 --- a/src/adapters.ts +++ b/src/adapters.ts @@ -1,12 +1,16 @@ import {BigNumber, BigNumberish, BytesLike, ethers} from 'ethers'; import {Ierc20Factory as IERC20Factory} from './typechain/Ierc20Factory'; -import {Il1BridgeFactory as IL1BridgeFactory} from './typechain/Il1BridgeFactory'; +import {Il1Erc20BridgeFactory as IL1ERC20BridgeFactory} from './typechain/Il1Erc20BridgeFactory'; +import {Il1Erc20Bridge as IL1ERC20Bridge} from './typechain/Il1Erc20Bridge'; import {Il2BridgeFactory as IL2BridgeFactory} from './typechain/Il2BridgeFactory'; -import {IZkSyncFactory} from './typechain/IZkSyncFactory'; +import {Il2Bridge as IL2Bridge} from './typechain/Il2Bridge'; +import {IBridgehubFactory} from './typechain/IBridgehubFactory'; +import {IBridgehub} from './typechain/IBridgehub'; +import {Il1SharedBridge as IL1SharedBridge} from './typechain/Il1SharedBridge'; +import {Il1SharedBridgeFactory as IL1SharedBridgeFactory} from './typechain/Il1SharedBridgeFactory'; import {INonceHolderFactory} from './typechain/INonceHolderFactory'; -import {Il2Bridge} from './typechain/Il2Bridge'; -import {IZkSync} from './typechain/IZkSync'; -import {Il1Bridge} from './typechain/Il1Bridge'; +import {IZkSyncStateTransitionFactory} from './typechain/IZkSyncStateTransitionFactory'; +import {IZkSyncStateTransition} from './typechain/IZkSyncStateTransition'; import {Provider} from './provider'; import { Address, @@ -25,17 +29,18 @@ import { DEFAULT_GAS_PER_PUBDATA_LIMIT, estimateCustomBridgeDepositL2Gas, estimateDefaultBridgeDepositL2Gas, - ETH_ADDRESS, + LEGACY_ETH_ADDRESS, + ETH_ADDRESS_IN_CONTRACTS, getERC20DefaultBridgeData, isETH, L1_MESSENGER_ADDRESS, L1_RECOMMENDED_MIN_ERC20_DEPOSIT_GAS_LIMIT, L1_RECOMMENDED_MIN_ETH_DEPOSIT_GAS_LIMIT, layer1TxDefaults, + NONCE_HOLDER_ADDRESS, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT, scaleGasLimit, undoL1ToL2Alias, - NONCE_HOLDER_ADDRESS, } from './utils'; type Constructor = new (...args: any[]) => T; @@ -73,24 +78,57 @@ export function AdapterL1>(Base: TBase) { /** * Returns `Contract` wrapper of the zkSync Era smart contract. */ - async getMainContract(): Promise { + async getMainContract(): Promise { const address = await this._providerL2().getMainContractAddress(); - return IZkSyncFactory.connect(address, this._signerL1()); + return IZkSyncStateTransitionFactory.connect(address, this._signerL1()); + } + + /** + * Returns `Contract` wrapper of the Bridgehub smart contract. + */ + async getBridgehubContract(): Promise { + const address = await this._providerL2().getBridgehubContractAddress(); + return IBridgehubFactory.connect(address, this._signerL1()); } /** * Returns L1 bridge contracts. * - * @remarks There is no separate Ether bridge contract, {@link getMainContract Main contract} is used instead. + * @remarks There is no separate Ether bridge contract, {@link getBridgehubContract Bridgehub} is used instead. */ - async getL1BridgeContracts(): Promise<{erc20: Il1Bridge; weth: Il1Bridge}> { + async getL1BridgeContracts(): Promise<{ + erc20: IL1ERC20Bridge; + shared: IL1SharedBridge; + }> { const addresses = await this._providerL2().getDefaultBridgeAddresses(); return { - erc20: IL1BridgeFactory.connect(addresses.erc20L1!, this._signerL1()), - weth: IL1BridgeFactory.connect(addresses.wethL1!, this._signerL1()), + erc20: IL1ERC20BridgeFactory.connect( + addresses.erc20L1, + this._signerL1() + ), + shared: IL1SharedBridgeFactory.connect( + addresses.sharedL1, + this._signerL1() + ), }; } + /** + * Returns the address of the base token on L1. + */ + async getBaseToken(): Promise { + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + return await bridgehub.baseToken(chainId); + } + + /** + * Returns whether the chain is ETH-based. + */ + async isETHBasedChain(): Promise { + return this._providerL2().isEthBasedChain(); + } + /** * Returns the amount of the token held by the account on the L1 network. * @@ -102,7 +140,7 @@ export function AdapterL1>(Base: TBase) { token?: Address, blockTag?: ethers.providers.BlockTag ): Promise { - token ??= ETH_ADDRESS; + token ??= LEGACY_ETH_ADDRESS; if (isETH(token)) { return await this._providerL1().getBalance( await this.getAddress(), @@ -119,7 +157,7 @@ export function AdapterL1>(Base: TBase) { * * @param token The Ethereum address of the token. * @param [bridgeAddress] The address of the bridge contract to be used. - * Defaults to the default zkSync Era bridge, either `L1EthBridge` or `L1Erc20Bridge`. + * Defaults to the default zkSync Era bridge, either `L1EthBridge` or `L1ERC20Bridge`. * @param [blockTag] The block in which an allowance should be checked. * Defaults to 'committed', i.e., the latest processed block. */ @@ -130,18 +168,7 @@ export function AdapterL1>(Base: TBase) { ): Promise { if (!bridgeAddress) { const bridgeContracts = await this.getL1BridgeContracts(); - let l2WethToken = ethers.constants.AddressZero; - try { - l2WethToken = await bridgeContracts.weth.l2TokenAddress(token); - } catch (e) { - // skip - } - - // If the token is Wrapped Ether, return allowance to its own bridge, otherwise to the default ERC20 bridge. - bridgeAddress = - l2WethToken !== ethers.constants.AddressZero - ? bridgeContracts.weth.address - : bridgeContracts.erc20.address; + bridgeAddress = bridgeContracts.shared.address; } const erc20contract = IERC20Factory.connect(token, this._providerL1()); @@ -163,21 +190,7 @@ export function AdapterL1>(Base: TBase) { * @param token The address of the token on L1. */ async l2TokenAddress(token: Address): Promise { - if (token === ETH_ADDRESS) { - return ETH_ADDRESS; - } - - const bridgeContracts = await this.getL1BridgeContracts(); - try { - const l2WethToken = await bridgeContracts.weth.l2TokenAddress(token); - // If the token is Wrapped Ether, return its L2 token address. - if (l2WethToken !== ethers.constants.AddressZero) { - return l2WethToken; - } - } catch (e) { - // skip - } - return await bridgeContracts.erc20.l2TokenAddress(token); + return this._providerL2().l2TokenAddress(token); } /** @@ -200,28 +213,25 @@ export function AdapterL1>(Base: TBase) { ); } - let bridgeAddress = overrides?.bridgeAddress; + overrides ??= {}; + let bridgeAddress = overrides.bridgeAddress; const erc20contract = IERC20Factory.connect(token, this._signerL1()); + const baseToken = await this.getBaseToken(); + const isEthBasedChain = await this.isETHBasedChain(); if (!bridgeAddress) { - const bridgeContracts = await this.getL1BridgeContracts(); - let l2WethToken = ethers.constants.AddressZero; - try { - l2WethToken = await bridgeContracts.weth.l2TokenAddress(token); - } catch (e) { - // skip + if (!isEthBasedChain && token === baseToken) { + bridgeAddress = await ( + await this.getBridgehubContract() + ).sharedBridge(); + } else { + const bridgeContracts = await this.getL1BridgeContracts(); + bridgeAddress = bridgeContracts.shared.address; } - // If the token is Wrapped Ether, return corresponding bridge, otherwise return default ERC20 bridge - bridgeAddress = - l2WethToken !== ethers.constants.AddressZero - ? bridgeContracts.weth.address - : bridgeContracts.erc20.address; } else { - delete overrides!.bridgeAddress; + delete overrides.bridgeAddress; } - overrides ??= {}; - return await erc20contract.approve(bridgeAddress, amount, overrides); } @@ -238,13 +248,14 @@ export function AdapterL1>(Base: TBase) { gasPerPubdataByte?: BigNumberish; gasPrice?: BigNumberish; }): Promise { - const zksyncContract = await this.getMainContract(); + const bridgehub = await this.getBridgehubContract(); const parameters = {...layer1TxDefaults(), ...params}; parameters.gasPrice ??= await this._providerL1().getGasPrice(); parameters.gasPerPubdataByte ??= REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT; return BigNumber.from( - await zksyncContract.l2TransactionBaseCost( + await bridgehub.l2TransactionBaseCost( + (await this._providerL2().getNetwork()).chainId, parameters.gasPrice, parameters.gasLimit, parameters.gasPerPubdataByte @@ -252,13 +263,79 @@ export function AdapterL1>(Base: TBase) { ); } + /** + * Returns the parameters for the approval token transaction based on the deposit token and amount. + * Some deposit transactions require multiple approvals. Existing allowance for the bridge is not checked; + * allowance is calculated solely based on the specified amount. + * + * @param token The address of the token to deposit. + * @param amount The amount of the token to deposit. + */ + async getDepositAllowanceParams( + token: Address, + amount: BigNumberish + ): Promise<{token: Address; allowance: BigNumberish}[]> { + if (token === LEGACY_ETH_ADDRESS) { + token = ETH_ADDRESS_IN_CONTRACTS; + } + const baseTokenAddress = await this.getBaseToken(); + const isEthBasedChain = await this.isETHBasedChain(); + + if (isEthBasedChain && token === LEGACY_ETH_ADDRESS) { + throw new Error( + "ETH token can't be approved! The address of the token does not exist on L1." + ); + } else if (baseTokenAddress === ETH_ADDRESS_IN_CONTRACTS) { + return [{token, allowance: amount}]; + } else if (token === LEGACY_ETH_ADDRESS) { + return [ + { + token: baseTokenAddress, + allowance: ( + await this._getDepositETHOnNonETHBasedChainTx({token, amount}) + ).mintValue, + }, + ]; + } else if (token === baseTokenAddress) { + return [ + { + token: baseTokenAddress, + allowance: ( + await this._getDepositBaseTokenOnNonETHBasedChainTx({ + token, + amount, + }) + ).mintValue, + }, + ]; + } else { + // A deposit of a non-base token to a non-ETH-based chain requires two approvals. + return [ + { + token: baseTokenAddress, + allowance: ( + await this._getDepositNonBaseTokenToNonETHBasedChainTx({ + token, + amount, + }) + ).mintValue, + }, + { + token: token, + allowance: amount, + }, + ]; + } + } + /** * Transfers the specified token from the associated account on the L1 network to the target account on the L2 network. * The token can be either ETH or any ERC20 token. For ERC20 tokens, enough approved tokens must be associated with * the specified L1 bridge (default one or the one defined in `transaction.bridgeAddress`). - * In this case, `transaction.approveERC20` can be enabled to perform token approval. If there are already enough - * approved tokens for the L1 bridge, token approval will be skipped. - * To check the amount of approved tokens for a specific bridge, use the {@link getAllowanceL1} method. + * In this case, depending on is the chain ETH-based or not `transaction.approveERC20` or `transaction.approveBaseERC20` + * can be enabled to perform token approval. If there are already enough approved tokens for the L1 bridge, + * token approval will be skipped. To check the amount of approved tokens for a specific bridge, + * use the {@link getAllowanceL1} method. * * @param transaction The transaction object containing deposit details. * @param transaction.token The address of the token to deposit. ETH by default. @@ -270,13 +347,19 @@ export function AdapterL1>(Base: TBase) { * @param [transaction.bridgeAddress] The address of the bridge contract to be used. * Defaults to the default zkSync Era bridge (either `L1EthBridge` or `L1Erc20Bridge`). * @param [transaction.approveERC20] Whether or not token approval should be performed under the hood. - * Set this flag to true if you bridge an ERC20 token and didn't call the {@link approveERC20} function beforehand. + * Set this flag to true if you bridge an ERC20 token and didn't call the {@link approveERC20} function beforehand. + * @param [transaction.approveBaseERC20] Whether or not base token approval should be performed under the hood. + * Set this flag to true if you bridge a base token and didn't call the {@link approveERC20} function beforehand. * @param [transaction.l2GasLimit] Maximum amount of L2 gas that the transaction can consume during execution on L2. * @param [transaction.gasPerPubdataByte] The L2 gas price for each published L1 calldata byte. * @param [transaction.refundRecipient] The address on L2 that will receive the refund for the transaction. * If the transaction fails, it will also be the address to receive `l2Value`. - * @param [transaction.overrides] Transaction's overrides which may be used to pass L1 `gasLimit`, `gasPrice`, `value`, etc. - * @param [transaction.approveOverrides] Transaction's overrides which may be used to pass L1 `gasLimit`, `gasPrice`, `value`, etc. + * @param [transaction.overrides] Transaction's overrides for deposit which may be used to pass + * L1 `gasLimit`, `gasPrice`, `value`, etc. + * @param [transaction.approveOverrides] Transaction's overrides for approval of an ERC20 token which may be used + * to pass L1 `gasLimit`, `gasPrice`, `value`, etc. + * @param [transaction.approveBaseOverrides] Transaction's overrides for approval of a base token which may be used + * to pass L1 `gasLimit`, `gasPrice`, `value`, etc. * @param [transaction.customBridgeData] Additional data that can be sent to a bridge. */ async deposit(transaction: { @@ -286,76 +369,307 @@ export function AdapterL1>(Base: TBase) { operatorTip?: BigNumberish; bridgeAddress?: Address; approveERC20?: boolean; + approveBaseERC20?: boolean; l2GasLimit?: BigNumberish; gasPerPubdataByte?: BigNumberish; refundRecipient?: Address; overrides?: ethers.PayableOverrides; approveOverrides?: ethers.Overrides; + approveBaseOverrides?: ethers.Overrides; customBridgeData?: BytesLike; }): Promise { - const depositTx = await this.getDepositTx(transaction); + if (transaction.token === LEGACY_ETH_ADDRESS) { + transaction.token = ETH_ADDRESS_IN_CONTRACTS; + } + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const baseTokenAddress = await bridgehub.baseToken(chainId); + const isEthBasedChain = baseTokenAddress === ETH_ADDRESS_IN_CONTRACTS; + + if (isEthBasedChain && transaction.token === ETH_ADDRESS_IN_CONTRACTS) { + return await this._depositETHToETHBasedChain(transaction); + } else if (baseTokenAddress === ETH_ADDRESS_IN_CONTRACTS) { + return await this._depositTokenToETHBasedChain(transaction); + } else if (transaction.token === ETH_ADDRESS_IN_CONTRACTS) { + return await this._depositETHToNonETHBasedChain(transaction); + } else if (transaction.token === baseTokenAddress) { + return await this._depositBaseTokenToNonETHBasedChain(transaction); + } else { + return await this._depositNonBaseTokenToNonETHBasedChain(transaction); + } + } - if (transaction.token === ETH_ADDRESS) { - const baseGasLimit = await this.estimateGasRequestExecute(depositTx); - const gasLimit = scaleGasLimit(baseGasLimit); + async _depositNonBaseTokenToNonETHBasedChain(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + approveERC20?: boolean; + approveBaseERC20?: boolean; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + approveOverrides?: ethers.Overrides; + approveBaseOverrides?: ethers.Overrides; + customBridgeData?: BytesLike; + }): Promise { + // Deposit a non-ETH and non-base token to a non-ETH-based chain. + // Go through the BridgeHub and obtain approval for both tokens. + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const baseTokenAddress = await bridgehub.baseToken(chainId); + const bridgeContracts = await this.getL1BridgeContracts(); + const {tx, mintValue} = + await this._getDepositNonBaseTokenToNonETHBasedChainTx(transaction); + + if (transaction.approveBaseERC20) { + // Only request the allowance if the current one is not enough. + const allowance = await this.getAllowanceL1( + baseTokenAddress, + bridgeContracts.shared.address + ); + if (allowance.lt(mintValue)) { + const approveTx = await this.approveERC20( + baseTokenAddress, + mintValue, + { + bridgeAddress: bridgeContracts.shared.address, + ...transaction.approveBaseOverrides, + } + ); + await approveTx.wait(); + } + } - depositTx.overrides ??= {}; - depositTx.overrides.gasLimit ??= gasLimit; + if (transaction.approveERC20) { + const bridgeAddress = transaction.bridgeAddress + ? transaction.bridgeAddress + : bridgeContracts.shared.address; - return this.requestExecute(depositTx); - } else { - const bridgeContracts = await this.getL1BridgeContracts(); - if (transaction.approveERC20) { - let l2WethToken = ethers.constants.AddressZero; - try { - l2WethToken = await bridgeContracts.weth.l2TokenAddress( - transaction.token - ); - } catch (e) { - // skip - } - // If the token is Wrapped Ether, use its bridge. - const proposedBridge = - l2WethToken !== ethers.constants.AddressZero - ? bridgeContracts.weth.address - : bridgeContracts.erc20.address; - const bridgeAddress = transaction.bridgeAddress - ? transaction.bridgeAddress - : proposedBridge; - - // We only request the allowance if the current one is not enough. - const allowance = await this.getAllowanceL1( + // Only request the allowance if the current one is not enough. + const allowance = await this.getAllowanceL1( + transaction.token, + bridgeAddress + ); + if (allowance.lt(transaction.amount)) { + const approveTx = await this.approveERC20( transaction.token, - bridgeAddress + transaction.amount, + { + bridgeAddress, + ...transaction.approveOverrides, + } ); - if (allowance.lt(transaction.amount)) { - const approveTx = await this.approveERC20( - transaction.token, - transaction.amount, - { - bridgeAddress, - ...transaction.approveOverrides, - } - ); - await approveTx.wait(); - } + await approveTx.wait(); + } + } + + const baseGasLimit = await this._providerL1().estimateGas(tx); + const gasLimit = scaleGasLimit(baseGasLimit); + + tx.gasLimit ??= gasLimit; + + return await this._providerL2().getPriorityOpResponse( + await this._signerL1().sendTransaction(tx) + ); + } + + async _depositBaseTokenToNonETHBasedChain(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + approveERC20?: boolean; + approveBaseERC20?: boolean; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + approveOverrides?: ethers.Overrides; + approveBaseOverrides?: ethers.Overrides; + customBridgeData?: BytesLike; + }): Promise { + // Bridging the base token to a non-ETH-based chain. + // Go through the BridgeHub, and give approval. + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const baseTokenAddress = await bridgehub.baseToken(chainId); + const sharedBridge = await bridgehub.sharedBridge(); + const {tx, mintValue} = + await this._getDepositBaseTokenOnNonETHBasedChainTx(transaction); + + if (transaction.approveERC20 || transaction.approveBaseERC20) { + // Only request the allowance if the current one is not enough. + const allowance = await this.getAllowanceL1( + baseTokenAddress, + sharedBridge + ); + if (allowance.lt(mintValue)) { + const approveTx = await this.approveERC20( + baseTokenAddress, + mintValue, + { + bridgeAddress: sharedBridge, + ...transaction.approveBaseOverrides, + } + ); + await approveTx.wait(); } + } + const baseGasLimit = await this.estimateGasRequestExecute(tx); + const gasLimit = scaleGasLimit(baseGasLimit); - const baseGasLimit = await this._providerL1().estimateGas(depositTx); - const gasLimit = scaleGasLimit(baseGasLimit); + tx.overrides ??= {}; + tx.overrides.gasLimit ??= gasLimit; - depositTx.gasLimit ??= gasLimit; + return this.requestExecute(tx); + } - return await this._providerL2().getPriorityOpResponse( - await this._signerL1().sendTransaction(depositTx) + async _depositETHToNonETHBasedChain(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + approveERC20?: boolean; + approveBaseERC20?: boolean; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + approveOverrides?: ethers.Overrides; + approveBaseOverrides?: ethers.Overrides; + customBridgeData?: BytesLike; + }): Promise { + // Depositing ETH into a non-ETH-based chain. + // Use requestL2TransactionTwoBridges, secondBridge is the wETH bridge. + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const baseTokenAddress = await bridgehub.baseToken(chainId); + const sharedBridge = await bridgehub.sharedBridge(); + const {tx, mintValue} = + await this._getDepositETHOnNonETHBasedChainTx(transaction); + + if (transaction.approveBaseERC20) { + // Only request the allowance if the current one is not enough. + const allowance = await this.getAllowanceL1( + baseTokenAddress, + sharedBridge + ); + if (allowance.lt(mintValue)) { + const approveTx = await this.approveERC20( + baseTokenAddress, + mintValue, + { + bridgeAddress: sharedBridge, + ...transaction.approveBaseOverrides, + } + ); + await approveTx.wait(); + } + } + + const baseGasLimit = await this._providerL1().estimateGas(tx); + const gasLimit = scaleGasLimit(baseGasLimit); + + tx.gasLimit ??= gasLimit; + + return await this._providerL2().getPriorityOpResponse( + await this._signerL1().sendTransaction(tx) + ); + } + + async _depositTokenToETHBasedChain(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + approveERC20?: boolean; + approveBaseERC20?: boolean; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + approveOverrides?: ethers.Overrides; + approveBaseOverrides?: ethers.Overrides; + customBridgeData?: BytesLike; + }): Promise { + const bridgeContracts = await this.getL1BridgeContracts(); + const tx = await this._getDepositTokenOnETHBasedChainTx(transaction); + + if (transaction.approveERC20) { + const proposedBridge = bridgeContracts.shared.address; + const bridgeAddress = transaction.bridgeAddress + ? transaction.bridgeAddress + : proposedBridge; + + // Only request the allowance if the current one is not enough. + const allowance = await this.getAllowanceL1( + transaction.token, + bridgeAddress ); + if (allowance.lt(transaction.amount)) { + const approveTx = await this.approveERC20( + transaction.token, + transaction.amount, + { + bridgeAddress, + ...transaction.approveOverrides, + } + ); + await approveTx.wait(); + } } + + const baseGasLimit = await this._providerL1().estimateGas(tx); + const gasLimit = scaleGasLimit(baseGasLimit); + + tx.gasLimit ??= gasLimit; + + return await this._providerL2().getPriorityOpResponse( + await this._signerL1().sendTransaction(tx) + ); + } + + async _depositETHToETHBasedChain(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + approveERC20?: boolean; + approveBaseERC20?: boolean; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + approveOverrides?: ethers.Overrides; + approveBaseOverrides?: ethers.Overrides; + customBridgeData?: BytesLike; + }): Promise { + const tx = await this._getDepositETHOnETHBasedChainTx(transaction); + + const baseGasLimit = await this.estimateGasRequestExecute(tx); + const gasLimit = scaleGasLimit(baseGasLimit); + + tx.overrides ??= {}; + tx.overrides.gasLimit ??= gasLimit; + + return this.requestExecute(tx); } /** * Estimates the amount of gas required for a deposit transaction on the L1 network. * Gas for approving ERC20 tokens is not included in the estimation. * + * In order for estimation to work, enough token allowance is required in the following cases: + * - Depositing ERC20 tokens on an ETH-based chain. + * - Depositing any token (including ETH) on a non-ETH-based chain. + * * @param transaction The transaction details. * @param transaction.token The address of the token to deposit. ETH by default. * @param transaction.amount The amount of the token to deposit. @@ -384,13 +698,16 @@ export function AdapterL1>(Base: TBase) { refundRecipient?: Address; overrides?: ethers.PayableOverrides; }): Promise { - const depositTx = await this.getDepositTx(transaction); + if (transaction.token === LEGACY_ETH_ADDRESS) { + transaction.token = ETH_ADDRESS_IN_CONTRACTS; + } + const tx = await this.getDepositTx(transaction); let baseGasLimit: BigNumber; - if (transaction.token === ETH_ADDRESS) { - baseGasLimit = await this.estimateGasRequestExecute(depositTx); + if (tx.token === (await this.getBaseToken())) { + baseGasLimit = await this.estimateGasRequestExecute(tx); } else { - baseGasLimit = await this._providerL1().estimateGas(depositTx); + baseGasLimit = await this._providerL1().estimateGas(tx); } return scaleGasLimit(baseGasLimit); @@ -427,112 +744,437 @@ export function AdapterL1>(Base: TBase) { refundRecipient?: Address; overrides?: ethers.PayableOverrides; }): Promise { - const bridgeContracts = await this.getL1BridgeContracts(); - if (transaction.bridgeAddress) { - bridgeContracts.erc20 = bridgeContracts.erc20.attach( - transaction.bridgeAddress - ); + if (transaction.token === LEGACY_ETH_ADDRESS) { + transaction.token = ETH_ADDRESS_IN_CONTRACTS; } - - const {...tx} = transaction; - tx.to ??= await this.getAddress(); - tx.operatorTip ??= BigNumber.from(0); - tx.overrides ??= {}; - tx.gasPerPubdataByte ??= REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT; - if (tx.bridgeAddress) { - const customBridgeData = - tx.customBridgeData ?? - bridgeContracts.weth.address === tx.bridgeAddress - ? '0x' - : await getERC20DefaultBridgeData(tx.token, this._providerL1()); - const bridge = IL1BridgeFactory.connect( - tx.bridgeAddress, - this._signerL1() - ); - const l2Address = await bridge.l2Bridge(); - tx.l2GasLimit ??= await estimateCustomBridgeDepositL2Gas( - this._providerL2(), - tx.bridgeAddress, - l2Address, - tx.token, - tx.amount, - tx.to, - customBridgeData, - await this.getAddress(), - tx.gasPerPubdataByte - ); + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const baseTokenAddress = await bridgehub.baseToken(chainId); + const isEthBasedChain = baseTokenAddress === ETH_ADDRESS_IN_CONTRACTS; + + if (isEthBasedChain && transaction.token === ETH_ADDRESS_IN_CONTRACTS) { + return await this._getDepositETHOnETHBasedChainTx(transaction); + } else if (isEthBasedChain) { + return await this._getDepositTokenOnETHBasedChainTx(transaction); + } else if (transaction.token === ETH_ADDRESS_IN_CONTRACTS) { + return (await this._getDepositETHOnNonETHBasedChainTx(transaction)).tx; + } else if (transaction.token === baseTokenAddress) { + return ( + await this._getDepositBaseTokenOnNonETHBasedChainTx(transaction) + ).tx; } else { - tx.l2GasLimit ??= await estimateDefaultBridgeDepositL2Gas( - this._providerL1(), - this._providerL2(), - tx.token, - tx.amount, - tx.to, - await this.getAddress(), - tx.gasPerPubdataByte - ); + return ( + await this._getDepositNonBaseTokenToNonETHBasedChainTx(transaction) + ).tx; } + } - const {to, token, amount, operatorTip, overrides} = tx; + async _getDepositNonBaseTokenToNonETHBasedChainTx(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }) { + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const bridgeContracts = await this.getL1BridgeContracts(); + + const tx = await this._getDepositTxWithDefaults(transaction); + const { + token, + operatorTip, + amount, + overrides, + l2GasLimit, + to, + refundRecipient, + gasPerPubdataByte, + } = tx; - await insertGasPrice(this._providerL1(), overrides); const gasPriceForEstimation = - overrides.maxFeePerGas || overrides.gasPrice; + (await overrides.maxFeePerGas) || (await overrides.gasPrice); + const baseCost = await bridgehub.l2TransactionBaseCost( + chainId, + gasPriceForEstimation!, + l2GasLimit, + gasPerPubdataByte + ); - const zksyncContract = await this.getMainContract(); + const mintValue = baseCost.add(operatorTip); + await checkBaseCost(baseCost, mintValue); + overrides.value ??= 0; - const baseCost = await zksyncContract.l2TransactionBaseCost( - await gasPriceForEstimation!, - tx.l2GasLimit, - tx.gasPerPubdataByte - ); + return { + tx: await bridgehub.populateTransaction.requestL2TransactionTwoBridges( + { + chainId: chainId, + mintValue, + l2Value: 0, + l2GasLimit: l2GasLimit, + l2GasPerPubdataByteLimit: gasPerPubdataByte, + refundRecipient: refundRecipient ?? ethers.constants.AddressZero, + secondBridgeAddress: bridgeContracts.shared.address, + secondBridgeValue: 0, + secondBridgeCalldata: ethers.utils.defaultAbiCoder.encode( + ['address', 'uint256', 'address'], + [token, amount, to] + ), + }, + overrides + ), + mintValue: mintValue, + }; + } + + async _getDepositBaseTokenOnNonETHBasedChainTx(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }) { + // Depositing the base token to a non-ETH-based chain. + // Goes through the BridgeHub. + // Have to give approvals for the sharedBridge. + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + + const tx = await this._getDepositTxWithDefaults(transaction); + const { + operatorTip, + amount, + to, + overrides, + l2GasLimit, + gasPerPubdataByte, + } = tx; - if (token === ETH_ADDRESS) { - overrides.value ??= baseCost.add(operatorTip).add(amount); + const gasPriceForEstimation = + (await overrides.maxFeePerGas) || (await overrides.gasPrice); + const baseCost = await bridgehub.l2TransactionBaseCost( + chainId, + gasPriceForEstimation!, + l2GasLimit, + gasPerPubdataByte + ); - return { + tx.overrides.value = 0; + return { + tx: { contractAddress: to, calldata: '0x', + mintValue: baseCost.add(operatorTip).add(amount), l2Value: amount, ...tx, - }; + }, + mintValue: baseCost.add(operatorTip).add(amount), + }; + } + + async _getDepositETHOnNonETHBasedChainTx(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }) { + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const sharedBridge = (await this.getL1BridgeContracts()).shared; + + const tx = await this._getDepositTxWithDefaults(transaction); + const { + operatorTip, + amount, + overrides, + l2GasLimit, + to, + refundRecipient, + gasPerPubdataByte, + } = tx; + + const gasPriceForEstimation = + (await overrides.maxFeePerGas) || (await overrides.gasPrice); + const baseCost = await bridgehub.l2TransactionBaseCost( + chainId, + gasPriceForEstimation!, + l2GasLimit, + gasPerPubdataByte + ); + + overrides.value ??= amount; + const mintValue = baseCost.add(operatorTip); + await checkBaseCost(baseCost, mintValue); + + return { + tx: await bridgehub.populateTransaction.requestL2TransactionTwoBridges( + { + chainId, + mintValue, + l2Value: 0, + l2GasLimit: l2GasLimit, + l2GasPerPubdataByteLimit: gasPerPubdataByte, + refundRecipient: refundRecipient ?? ethers.constants.AddressZero, + secondBridgeAddress: sharedBridge.address, + secondBridgeValue: amount, + secondBridgeCalldata: ethers.utils.defaultAbiCoder.encode( + ['address', 'uint256', 'address'], + [ETH_ADDRESS_IN_CONTRACTS, 0, to] + ), + }, + overrides + ), + mintValue: mintValue, + }; + } + + async _getDepositTokenOnETHBasedChainTx(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }): Promise { + // Depositing token to an ETH-based chain. Use the ERC20 bridge as done before. + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + + const tx = await this._getDepositTxWithDefaults(transaction); + const { + token, + operatorTip, + amount, + overrides, + l2GasLimit, + to, + refundRecipient, + gasPerPubdataByte, + } = tx; + + const gasPriceForEstimation = + (await overrides.maxFeePerGas) || (await overrides.gasPrice); + const baseCost = await bridgehub.l2TransactionBaseCost( + chainId, + gasPriceForEstimation!, + tx.l2GasLimit, + tx.gasPerPubdataByte + ); + + const mintValue = baseCost.add(operatorTip); + overrides.value ??= mintValue; + await checkBaseCost(baseCost, mintValue); + + let secondBridgeAddress: string; + let secondBridgeCalldata: BytesLike; + if (tx.bridgeAddress) { + secondBridgeAddress = tx.bridgeAddress; + secondBridgeCalldata = await getERC20DefaultBridgeData( + transaction.token, + this._providerL1() + ); } else { - const refundRecipient = - tx.refundRecipient ?? ethers.constants.AddressZero; - const args: [ - Address, - Address, - BigNumberish, - BigNumberish, - BigNumberish, - Address, - ] = [ - to, - token, - amount, - tx.l2GasLimit, - tx.gasPerPubdataByte, - refundRecipient, - ]; + secondBridgeAddress = (await this.getL1BridgeContracts()).shared + .address; + secondBridgeCalldata = ethers.utils.defaultAbiCoder.encode( + ['address', 'uint256', 'address'], + [token, amount, to] + ); + } - overrides.value ??= baseCost.add(operatorTip); - await checkBaseCost(baseCost, overrides.value); + return await bridgehub.populateTransaction.requestL2TransactionTwoBridges( + { + chainId, + mintValue, + l2Value: 0, + l2GasLimit, + l2GasPerPubdataByteLimit: gasPerPubdataByte, + refundRecipient: refundRecipient ?? ethers.constants.AddressZero, + secondBridgeAddress, + secondBridgeValue: 0, + secondBridgeCalldata, + }, + overrides + ); + } - let l2WethToken = ethers.constants.AddressZero; - try { - l2WethToken = await bridgeContracts.weth.l2TokenAddress(tx.token); - } catch (e) { - // skip - } + async _getDepositETHOnETHBasedChainTx(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }) { + // Call the BridgeHub directly, like it's done with the DiamondProxy. + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; - const bridge = - l2WethToken !== ethers.constants.AddressZero - ? bridgeContracts.weth - : bridgeContracts.erc20; - return await bridge.populateTransaction.deposit(...args, overrides); + const tx = await this._getDepositTxWithDefaults(transaction); + const { + operatorTip, + amount, + overrides, + l2GasLimit, + gasPerPubdataByte, + to, + } = tx; + + const gasPriceForEstimation = + (await overrides.maxFeePerGas) || (await overrides.gasPrice); + const baseCost = await bridgehub.l2TransactionBaseCost( + chainId, + gasPriceForEstimation!, + l2GasLimit, + gasPerPubdataByte + ); + + overrides.value ??= baseCost.add(operatorTip).add(amount); + + return { + contractAddress: to, + calldata: '0x', + mintValue: await overrides.value, + l2Value: amount, + ...tx, + }; + } + + // Creates a shallow copy of a transaction and populates missing fields with defaults. + async _getDepositTxWithDefaults(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }): Promise<{ + token: Address; + amount: BigNumberish; + to: Address; + operatorTip: BigNumberish; + bridgeAddress?: Address; + l2GasLimit: BigNumberish; + gasPerPubdataByte: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides: ethers.PayableOverrides; + }> { + const {...tx} = transaction; + tx.to ??= await this.getAddress(); + tx.operatorTip ??= BigNumber.from(0); + tx.overrides ??= {}; + tx.gasPerPubdataByte ??= REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT; + tx.l2GasLimit ??= await this._getL2GasLimit(tx); + await insertGasPrice(this._providerL1(), tx.overrides); + + return tx as { + token: Address; + amount: BigNumberish; + to: Address; + operatorTip: BigNumberish; + bridgeAddress?: Address; + l2GasLimit: BigNumberish; + gasPerPubdataByte: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides: ethers.PayableOverrides; + }; + } + + // Default behaviour for calculating l2GasLimit of deposit transaction. + async _getL2GasLimit(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }): Promise { + if (transaction.bridgeAddress) { + return await this._getL2GasLimitFromCustomBridge(transaction); + } else { + return await estimateDefaultBridgeDepositL2Gas( + this._providerL1(), + this._providerL2(), + transaction.token, + transaction.amount, + transaction.to!, + await this.getAddress(), + transaction.gasPerPubdataByte + ); } } + // Calculates the l2GasLimit of deposit transaction using custom bridge. + async _getL2GasLimitFromCustomBridge(transaction: { + token: Address; + amount: BigNumberish; + to?: Address; + operatorTip?: BigNumberish; + bridgeAddress?: Address; + l2GasLimit?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + customBridgeData?: BytesLike; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }): Promise { + const customBridgeData = + transaction.customBridgeData ?? + (await getERC20DefaultBridgeData( + transaction.token, + this._providerL1() + )); + const bridge = IL1SharedBridgeFactory.connect( + transaction.bridgeAddress!, + this._signerL1() + ); + const l2Address = await bridge.l2Bridge(); + return await estimateCustomBridgeDepositL2Gas( + this._providerL2(), + transaction.bridgeAddress!, + l2Address, + transaction.token, + transaction.amount, + transaction.to!, + customBridgeData, + await this.getAddress(), + transaction.gasPerPubdataByte + ); + } + /** * Retrieves the full needed ETH fee for the deposit. Returns the L1 fee and the L2 fee {@link FullDepositFee}. * @@ -556,92 +1198,74 @@ export function AdapterL1>(Base: TBase) { gasPerPubdataByte?: BigNumberish; overrides?: ethers.PayableOverrides; }): Promise { + if (transaction.token === LEGACY_ETH_ADDRESS) { + transaction.token = ETH_ADDRESS_IN_CONTRACTS; + } // It is assumed that the L2 fee for the transaction does not depend on its value. - const dummyAmount = '1'; + const dummyAmount = BigNumber.from(1); + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const baseTokenAddress = await bridgehub.baseToken(chainId); + const isEthBasedChain = baseTokenAddress === ETH_ADDRESS_IN_CONTRACTS; - const {...tx} = transaction; - const zksyncContract = await this.getMainContract(); + const tx = await this._getDepositTxWithDefaults({ + ...transaction, + amount: dummyAmount, + }); - tx.overrides ??= {}; - await insertGasPrice(this._providerL1(), tx.overrides); - const gasPriceForMessages = + const gasPriceForEstimation = (await tx.overrides.maxFeePerGas) || (await tx.overrides.gasPrice); - - tx.to ??= await this.getAddress(); - tx.gasPerPubdataByte ??= REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT; - - let l2GasLimit = null; - if (tx.bridgeAddress) { - const bridgeContracts = await this.getL1BridgeContracts(); - const customBridgeData = - tx.customBridgeData ?? - bridgeContracts.weth.address === tx.bridgeAddress - ? '0x' - : await getERC20DefaultBridgeData(tx.token, this._providerL1()); - const bridge = IL1BridgeFactory.connect( - tx.bridgeAddress, - this._signerL1() - ); - const l2Address = await bridge.l2Bridge(); - l2GasLimit ??= await estimateCustomBridgeDepositL2Gas( - this._providerL2(), - tx.bridgeAddress, - l2Address, - tx.token, - dummyAmount, - tx.to, - customBridgeData, - await this.getAddress(), - tx.gasPerPubdataByte - ); - } else { - l2GasLimit ??= await estimateDefaultBridgeDepositL2Gas( - this._providerL1(), - this._providerL2(), - tx.token, - dummyAmount, - tx.to, - await this.getAddress(), - tx.gasPerPubdataByte - ); - } - - const baseCost = await zksyncContract.l2TransactionBaseCost( - gasPriceForMessages!, - l2GasLimit, + const baseCost = await bridgehub.l2TransactionBaseCost( + chainId, + gasPriceForEstimation!, + tx.l2GasLimit, tx.gasPerPubdataByte ); - const selfBalanceETH = await this.getBalanceL1(); - - // We could use 0, because the final fee will anyway be bigger than - if (baseCost.gte(selfBalanceETH.add(dummyAmount))) { - const recommendedETHBalance = BigNumber.from( - tx.token === ETH_ADDRESS - ? L1_RECOMMENDED_MIN_ETH_DEPOSIT_GAS_LIMIT - : L1_RECOMMENDED_MIN_ERC20_DEPOSIT_GAS_LIMIT - ) - .mul(gasPriceForMessages!) - .add(baseCost); - const formattedRecommendedBalance = ethers.utils.formatEther( - recommendedETHBalance - ); - throw new Error( - `Not enough balance for deposit! Under the provided gas price, the recommended balance to perform a deposit is ${formattedRecommendedBalance} ETH.` - ); - } - - // For ETH token the value that the user passes to the estimation is the one which has the - // value for the L2 commission subtracted. - let amountForEstimate: BigNumber; - if (isETH(tx.token)) { - amountForEstimate = BigNumber.from(dummyAmount); - } else { - amountForEstimate = BigNumber.from(dummyAmount); - - if ((await this.getAllowanceL1(tx.token)) < amountForEstimate) { + if (isEthBasedChain) { + // To ensure that L1 gas estimation succeeds when using estimateGasDeposit, + // the account needs to have a sufficient ETH balance. + const selfBalanceETH = await this.getBalanceL1(); + if (baseCost.gte(selfBalanceETH.add(dummyAmount))) { + const recommendedL1GasLimit = + tx.token === ETH_ADDRESS_IN_CONTRACTS + ? L1_RECOMMENDED_MIN_ETH_DEPOSIT_GAS_LIMIT + : L1_RECOMMENDED_MIN_ERC20_DEPOSIT_GAS_LIMIT; + const recommendedETHBalance = BigNumber.from(recommendedL1GasLimit) + .mul(gasPriceForEstimation!) + .add(baseCost); + const formattedRecommendedBalance = ethers.utils.formatEther( + recommendedETHBalance + ); + throw new Error( + `Not enough balance for deposit! Under the provided gas price, the recommended balance to perform a deposit is ${formattedRecommendedBalance} ETH` + ); + } + // In case of token deposit, a sufficient token allowance is also required. + if ( + tx.token !== ETH_ADDRESS_IN_CONTRACTS && + (await this.getAllowanceL1(tx.token)) < dummyAmount + ) { throw new Error('Not enough allowance to cover the deposit!'); } + } else { + const mintValue = baseCost.add(tx.operatorTip); + if ((await this.getAllowanceL1(baseTokenAddress)) < mintValue) { + throw new Error( + 'Not enough base token allowance to cover the deposit!' + ); + } + if ( + tx.token === ETH_ADDRESS_IN_CONTRACTS || + tx.token === baseTokenAddress + ) { + tx.overrides.value ??= tx.amount; + } else { + tx.overrides.value ??= 0; + if ((await this.getAllowanceL1(tx.token)) < dummyAmount) { + throw new Error('Not enough token allowance to cover the deposit!'); + } + } } // Deleting the explicit gas limits in the fee estimation @@ -654,15 +1278,15 @@ export function AdapterL1>(Base: TBase) { const l1GasLimit = await this.estimateGasDeposit({ ...tx, - amount: amountForEstimate, + amount: dummyAmount, overrides: estimationOverrides, - l2GasLimit, + l2GasLimit: tx.l2GasLimit, }); const fullCost: FullDepositFee = { baseCost, l1GasLimit, - l2GasLimit, + l2GasLimit: BigNumber.from(tx.l2GasLimit), }; if (tx.overrides.gasPrice) { @@ -677,6 +1301,18 @@ export function AdapterL1>(Base: TBase) { return fullCost; } + /** + * Returns the transaction confirmation data that is part of `L2->L1` message. + * + * @param txHash The hash of the L2 transaction where the message was initiated. + * @param [index=0] In case there were multiple transactions in one message, you may pass an index of the + * transaction which confirmation data should be fetched. + * @throws {Error} If log proof can not be found. + */ + async getPriorityOpConfirmation(txHash: string, index = 0) { + return this._providerL2().getPriorityOpConfirmation(txHash, index); + } + async _getWithdrawalLog(withdrawalHash: BytesLike, index = 0) { const hash = ethers.utils.hexlify(withdrawalHash); const receipt = await this._providerL2().getTransactionReceipt(hash); @@ -765,54 +1401,17 @@ export function AdapterL1>(Base: TBase) { index = 0, overrides?: ethers.Overrides ): Promise { - const { - l1BatchNumber, - l2MessageIndex, - l2TxNumberInBlock, - message, - sender, - proof, - } = await this.finalizeWithdrawalParams(withdrawalHash, index); - - if (isETH(sender)) { - const withdrawTo = ethers.utils.hexDataSlice(message, 4, 24); - const l1Bridges = await this.getL1BridgeContracts(); - // If the destination address matches the address of the L1 WETH contract, - // the withdrawal request is processed through the WETH bridge. - if (withdrawTo.toLowerCase() === l1Bridges.weth.address.toLowerCase()) { - return await l1Bridges.weth.finalizeWithdrawal( - l1BatchNumber!, - l2MessageIndex, - l2TxNumberInBlock!, - message, - proof, - overrides ?? {} - ); - } - - const contractAddress = - await this._providerL2().getMainContractAddress(); - const zksync = IZkSyncFactory.connect( - contractAddress, - this._signerL1() - ); + const {l1BatchNumber, l2MessageIndex, l2TxNumberInBlock, message, proof} = + await this.finalizeWithdrawalParams(withdrawalHash, index); - return await zksync.finalizeEthWithdrawal( - l1BatchNumber!, - l2MessageIndex, - l2TxNumberInBlock!, - message, - proof, - overrides ?? {} - ); - } - - const l2Bridge = IL2BridgeFactory.connect(sender, this._providerL2()); - const l1Bridge = IL1BridgeFactory.connect( - await l2Bridge.l1Bridge(), + const bridgehub = await this.getBridgehubContract(); + const l1SharedBridge = IL1SharedBridgeFactory.connect( + await bridgehub.sharedBridge(), this._signerL1() ); - return await l1Bridge.finalizeWithdrawal( + + return await l1SharedBridge.finalizeWithdrawal( + (await this._providerL2().getNetwork()).chainId, l1BatchNumber!, l2MessageIndex, l2TxNumberInBlock!, @@ -851,27 +1450,25 @@ export function AdapterL1>(Base: TBase) { throw new Error('Log proof not found!'); } - if (isETH(sender)) { - const contractAddress = - await this._providerL2().getMainContractAddress(); - const zksync = IZkSyncFactory.connect( - contractAddress, - this._signerL1() - ); + const chainId = (await this._providerL2().getNetwork()).chainId; - return await zksync.isEthWithdrawalFinalized( - log.l1BatchNumber, - proof.id + let l1Bridge: IL1SharedBridge; + + if (await this._providerL2().isBaseToken(sender)) { + l1Bridge = (await this.getL1BridgeContracts()).shared; + } else { + const l2Bridge = IL2BridgeFactory.connect(sender, this._providerL2()); + l1Bridge = IL1SharedBridgeFactory.connect( + await l2Bridge.l1Bridge(), + this._providerL1() ); } - const l2Bridge = IL2BridgeFactory.connect(sender, this._providerL2()); - const l1Bridge = IL1BridgeFactory.connect( - await l2Bridge.l1Bridge(), - this._providerL1() + return await l1Bridge.isWithdrawalFinalized( + chainId, + log.l1BatchNumber, + proof.id ); - - return await l1Bridge.isWithdrawalFinalized(log.l1BatchNumber, proof.id); } /** @@ -898,7 +1495,7 @@ export function AdapterL1>(Base: TBase) { ); const successL2ToL1Log = receipt.l2ToL1Logs[successL2ToL1LogIndex]; if (successL2ToL1Log.value !== ethers.constants.HashZero) { - throw new Error('Cannot claim successful deposit!'); + throw new Error('Cannot claim successful deposit'); } const tx = await this._providerL2().getTransaction( @@ -909,7 +1506,7 @@ export function AdapterL1>(Base: TBase) { const l1BridgeAddress = undoL1ToL2Alias(receipt.from); const l2BridgeAddress = receipt.to; - const l1Bridge = IL1BridgeFactory.connect( + const l1Bridge = IL1SharedBridgeFactory.connect( l1BridgeAddress, this._signerL1() ); @@ -932,8 +1529,10 @@ export function AdapterL1>(Base: TBase) { } return await l1Bridge.claimFailedDeposit( + (await this._providerL2().getNetwork()).chainId, calldata['_l1Sender'], calldata['_l1Token'], + calldata['_amount'], depositHash, receipt.l1BatchNumber, proof.id, @@ -950,6 +1549,7 @@ export function AdapterL1>(Base: TBase) { * @param transaction.contractAddress The L2 contract to be called. * @param transaction.calldata The input of the L2 transaction. * @param [transaction.l2GasLimit] Maximum amount of L2 gas that transaction can consume during execution on L2. + * @param [transaction.mintValue] The amount of base token that needs to be minted on non-ETH-based L2. * @param [transaction.l2Value] `msg.value` of L2 transaction. * @param [transaction.factoryDeps] An array of L2 bytecodes that will be marked as known on L2. * @param [transaction.operatorTip] (currently not used) If the ETH value passed with the transaction is not @@ -965,6 +1565,7 @@ export function AdapterL1>(Base: TBase) { contractAddress: Address; calldata: BytesLike; l2GasLimit?: BigNumberish; + mintValue?: BigNumberish; l2Value?: BigNumberish; factoryDeps?: ethers.BytesLike[]; operatorTip?: BigNumberish; @@ -985,6 +1586,7 @@ export function AdapterL1>(Base: TBase) { * @param transaction.contractAddress The L2 contract to be called. * @param transaction.calldata The input of the L2 transaction. * @param [transaction.l2GasLimit] Maximum amount of L2 gas that transaction can consume during execution on L2. + * @param [transaction.mintValue] The amount of base token that needs to be minted on non-ETH-based L2. * @param [transaction.l2Value] `msg.value` of L2 transaction. * @param [transaction.factoryDeps] An array of L2 bytecodes that will be marked as known on L2. * @param [transaction.operatorTip] (currently not used) If the ETH value passed with the transaction is not @@ -999,6 +1601,7 @@ export function AdapterL1>(Base: TBase) { contractAddress: Address; calldata: BytesLike; l2GasLimit?: BigNumberish; + mintValue?: BigNumberish; l2Value?: BigNumberish; factoryDeps?: ethers.BytesLike[]; operatorTip?: BigNumberish; @@ -1015,6 +1618,61 @@ export function AdapterL1>(Base: TBase) { return this._providerL1().estimateGas(requestExecuteTx); } + /** + * Returns the parameters for the approval token transaction based on the request execute transaction. + * Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified transaction. + * + * @param transaction The request execute transaction on which approval parameters are calculated. + */ + async getRequestExecuteAllowanceParams(transaction: { + contractAddress: Address; + calldata: BytesLike; + l2GasLimit?: BigNumberish; + l2Value?: BigNumberish; + factoryDeps?: ethers.BytesLike[]; + operatorTip?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }): Promise<{token: Address; allowance: BigNumberish}> { + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const isETHBaseToken = + (await bridgehub.baseToken(chainId)) === ETH_ADDRESS_IN_CONTRACTS; + + if (isETHBaseToken) { + throw new Error('Could not estimate mint value on ETH-based chain!'); + } + + const {...tx} = transaction; + tx.l2Value ??= BigNumber.from(0); + tx.operatorTip ??= BigNumber.from(0); + tx.factoryDeps ??= []; + tx.overrides ??= {}; + tx.gasPerPubdataByte ??= REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT; + tx.refundRecipient ??= await this.getAddress(); + tx.l2GasLimit ??= + await this._providerL2().estimateL1ToL2Execute(transaction); + + const {l2Value, l2GasLimit, operatorTip, overrides, gasPerPubdataByte} = + tx; + + await insertGasPrice(this._providerL1(), overrides); + const gasPriceForEstimation = + (await overrides.maxFeePerGas) || (await overrides.gasPrice); + + const baseCost = await this.getBaseCost({ + gasPrice: gasPriceForEstimation, + gasPerPubdataByte, + gasLimit: l2GasLimit, + }); + + return { + token: await this.getBaseToken(), + allowance: baseCost.add(operatorTip).add(l2Value), + }; + } + /** * Returns a populated request execute transaction. * @@ -1022,6 +1680,7 @@ export function AdapterL1>(Base: TBase) { * @param transaction.contractAddress The L2 contract to be called. * @param transaction.calldata The input of the L2 transaction. * @param [transaction.l2GasLimit] Maximum amount of L2 gas that transaction can consume during execution on L2. + * @param [transaction.mintValue] The amount of base token that needs to be minted on non-ETH-based L2. * @param [transaction.l2Value] `msg.value` of L2 transaction. * @param [transaction.factoryDeps] An array of L2 bytecodes that will be marked as known on L2. * @param [transaction.operatorTip] (currently not used) If the ETH value passed with the transaction is not @@ -1036,6 +1695,7 @@ export function AdapterL1>(Base: TBase) { contractAddress: Address; calldata: BytesLike; l2GasLimit?: BigNumberish; + mintValue?: BigNumberish; l2Value?: BigNumberish; factoryDeps?: ethers.BytesLike[]; operatorTip?: BigNumberish; @@ -1043,7 +1703,10 @@ export function AdapterL1>(Base: TBase) { refundRecipient?: Address; overrides?: ethers.PayableOverrides; }): Promise { - const zksyncContract = await this.getMainContract(); + const bridgehub = await this.getBridgehubContract(); + const chainId = (await this._providerL2().getNetwork()).chainId; + const isETHBaseToken = + (await bridgehub.baseToken(chainId)) === ETH_ADDRESS_IN_CONTRACTS; const {...tx} = transaction; tx.l2Value ??= BigNumber.from(0); @@ -1058,6 +1721,7 @@ export function AdapterL1>(Base: TBase) { const { contractAddress, l2Value, + mintValue, calldata, l2GasLimit, factoryDeps, @@ -1069,26 +1733,35 @@ export function AdapterL1>(Base: TBase) { await insertGasPrice(this._providerL1(), overrides); const gasPriceForEstimation = - overrides.maxFeePerGas || overrides.gasPrice; + (await overrides.maxFeePerGas) || (await overrides.gasPrice); const baseCost = await this.getBaseCost({ - gasPrice: await gasPriceForEstimation, + gasPrice: gasPriceForEstimation, gasPerPubdataByte, gasLimit: l2GasLimit, }); - overrides.value ??= baseCost.add(operatorTip).add(l2Value); + const l2Costs = baseCost.add(operatorTip).add(l2Value); + let providedValue = isETHBaseToken ? overrides.value : mintValue; + if (providedValue === undefined || providedValue === null) { + providedValue = l2Costs; + if (isETHBaseToken) overrides.value = providedValue; + } - await checkBaseCost(baseCost, overrides.value); + await checkBaseCost(baseCost, providedValue); - return await zksyncContract.populateTransaction.requestL2Transaction( - contractAddress, - l2Value, - calldata, - l2GasLimit, - REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT, - factoryDeps, - refundRecipient, + return await bridgehub.populateTransaction.requestL2TransactionDirect( + { + chainId, + mintValue: await providedValue, + l2Contract: contractAddress, + l2Value: l2Value, + l2Calldata: calldata, + l2GasLimit: l2GasLimit, + l2GasPerPubdataByteLimit: REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT, + factoryDeps: factoryDeps, + refundRecipient: refundRecipient, + }, overrides ); } @@ -1150,11 +1823,10 @@ export function AdapterL2>(Base: TBase) { /** * Returns L2 bridge contracts. */ - async getL2BridgeContracts(): Promise<{erc20: Il2Bridge; weth: Il2Bridge}> { + async getL2BridgeContracts(): Promise<{shared: IL2Bridge}> { const addresses = await this._providerL2().getDefaultBridgeAddresses(); return { - erc20: IL2BridgeFactory.connect(addresses.erc20L2!, this._signerL2()), - weth: IL2BridgeFactory.connect(addresses.wethL2!, this._signerL2()), + shared: IL2BridgeFactory.connect(addresses.sharedL2, this._signerL2()), }; } diff --git a/src/provider.ts b/src/provider.ts index 83756526..448438a6 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -10,7 +10,7 @@ import { import {ExternalProvider} from '@ethersproject/providers'; import {ConnectionInfo, poll} from '@ethersproject/web'; import {Ierc20Factory as IERC20Factory} from './typechain/Ierc20Factory'; -import {IEthTokenFactory as IEthTokenFactory} from './typechain/IEthTokenFactory'; +import {IEthTokenFactory} from './typechain/IEthTokenFactory'; import {Il2BridgeFactory as IL2BridgeFactory} from './typechain/Il2BridgeFactory'; import { Address, @@ -38,16 +38,18 @@ import { Eip712Meta, } from './types'; import { + BOOTLOADER_FORMAL_ADDRESS, CONTRACT_DEPLOYER, CONTRACT_DEPLOYER_ADDRESS, EIP712_TX_TYPE, - ETH_ADDRESS, + LEGACY_ETH_ADDRESS, + ETH_ADDRESS_IN_CONTRACTS, getL2HashFromPriorityOp, - isETH, - L2_ETH_TOKEN_ADDRESS, + L2_BASE_TOKEN_ADDRESS, parseTransaction, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT, sleep, + isETH, } from './utils'; import {Signer} from './signer'; import Formatter = providers.Formatter; @@ -61,11 +63,12 @@ let defaultFormatter: Formatter | null = null; export class Provider extends ethers.providers.JsonRpcProvider { private static _nextPollId = 1; protected contractAddresses: { + bridgehubContract?: Address; mainContract?: Address; erc20BridgeL1?: Address; - erc20BridgeL2?: Address; - wethBridgeL1?: Address; - wethBridgeL2?: Address; + sharedBridgeL1?: Address; + sharedBridgeL2?: Address; + baseToken?: Address; }; // NOTE: this is almost a complete copy-paste of the parent poll method @@ -493,8 +496,8 @@ export class Provider extends ethers.providers.JsonRpcProvider { tokenAddress?: Address ): Promise { const tag = this.formatter.blockTag(blockTag); - if (!tokenAddress || isETH(tokenAddress)) { - // requesting ETH balance + if (!tokenAddress || (await this.isBaseToken(tokenAddress))) { + // requesting base token balance return await super.getBalance(address, tag); } else { try { @@ -522,29 +525,21 @@ export class Provider extends ethers.providers.JsonRpcProvider { * console.log(`L2 token address: ${await provider.l2TokenAddress("0x5C221E77624690fff6dd741493D735a17716c26B")}`); */ async l2TokenAddress(token: Address): Promise { - if (token === ETH_ADDRESS) { - return ETH_ADDRESS; + if (token === LEGACY_ETH_ADDRESS) { + token = ETH_ADDRESS_IN_CONTRACTS; } - const bridgeAddresses = await this.getDefaultBridgeAddresses(); - const l2WethBridge = IL2BridgeFactory.connect( - bridgeAddresses.wethL2!, - this - ); - try { - const l2WethToken = await l2WethBridge.l2TokenAddress(token); - // If the token is Wrapped Ether, return its L2 token address - if (l2WethToken !== ethers.constants.AddressZero) { - return l2WethToken; - } - } catch (e) { - // skip + const baseToken = await this.getBaseTokenContractAddress(); + if (token.toLowerCase() === baseToken.toLowerCase()) { + return L2_BASE_TOKEN_ADDRESS; } - const l2Erc20Bridge = IL2BridgeFactory.connect( - bridgeAddresses.erc20L2!, + + const bridgeAddresses = await this.getDefaultBridgeAddresses(); + const l2SharedBridge = IL2BridgeFactory.connect( + bridgeAddresses.sharedL2, this ); - return await l2Erc20Bridge.l2TokenAddress(token); + return await l2SharedBridge.l2TokenAddress(token); } /** @@ -562,30 +557,18 @@ export class Provider extends ethers.providers.JsonRpcProvider { * const provider = Provider.getDefaultProvider(types.Network.Sepolia); * console.log(`L1 token address: ${await provider.l1TokenAddress("0x3e7676937A7E96CFB7616f255b9AD9FF47363D4b")}`); */ - async l1TokenAddress(token: Address): Promise { - if (token === ETH_ADDRESS) { - return ETH_ADDRESS; + async l1TokenAddress(token: Address) { + if (token === LEGACY_ETH_ADDRESS) { + return LEGACY_ETH_ADDRESS; } const bridgeAddresses = await this.getDefaultBridgeAddresses(); - const l2WethBridge = IL2BridgeFactory.connect( - bridgeAddresses.wethL2!, - this - ); - try { - const l1WethToken = await l2WethBridge.l1TokenAddress(token); - // If the token is Wrapped Ether, return its L1 token address - if (l1WethToken !== ethers.constants.AddressZero) { - return l1WethToken; - } - } catch (e) { - // skip - } - const erc20Bridge = IL2BridgeFactory.connect( - bridgeAddresses.erc20L2!, + + const sharedBridge = IL2BridgeFactory.connect( + bridgeAddresses.sharedL2, this ); - return await erc20Bridge.l1TokenAddress(token); + return await sharedBridge.l1TokenAddress(token); } /** @@ -823,6 +806,21 @@ export class Provider extends ethers.providers.JsonRpcProvider { return [parseInt(range[0], 16), parseInt(range[1], 16)]; } + /** + * Returns the Bridgehub smart contract address. + * + * Calls the {@link https://docs.zksync.io/build/api.html#zks-getbridgehubcontract zks_getBridgehubContract} JSON-RPC method. + */ + async getBridgehubContractAddress(): Promise
{ + if (!this.contractAddresses.bridgehubContract) { + this.contractAddresses.bridgehubContract = await this.send( + 'zks_getBridgehubContract', + [] + ); + } + return this.contractAddresses.bridgehubContract!; + } + /** * Returns the main zkSync Era smart contract address. * @@ -844,6 +842,38 @@ export class Provider extends ethers.providers.JsonRpcProvider { return this.contractAddresses.mainContract!; } + /** + * Returns the L1 base token address. + */ + async getBaseTokenContractAddress(): Promise
{ + if (!this.contractAddresses.baseToken) { + this.contractAddresses.baseToken = await this.send( + 'zks_getBaseTokenL1Address', + [] + ); + } + return ethers.utils.getAddress(this.contractAddresses.baseToken!); + } + + /** + * Returns whether the chain is ETH-based. + */ + async isEthBasedChain(): Promise { + return ( + (await this.getBaseTokenContractAddress()) === ETH_ADDRESS_IN_CONTRACTS + ); + } + + /** + * Returns whether the `token` is the base token. + */ + async isBaseToken(token: Address): Promise { + return ( + token === (await this.getBaseTokenContractAddress()) || + token === L2_BASE_TOKEN_ADDRESS + ); + } + /** * Returns the testnet {@link https://docs.zksync.io/build/developer-reference/account-abstraction.html#paymasters paymaster address} * if available, or `null`. @@ -876,28 +906,24 @@ export class Provider extends ethers.providers.JsonRpcProvider { * console.log(`Default bridges: ${utils.toJSON(await provider.getDefaultBridgeAddresses())}`); */ async getDefaultBridgeAddresses(): Promise<{ - erc20L1: string | undefined; - erc20L2: string | undefined; - wethL1: string | undefined; - wethL2: string | undefined; + erc20L1: string; + sharedL1: string; + sharedL2: string; }> { if (!this.contractAddresses.erc20BridgeL1) { const addresses: { l1Erc20DefaultBridge: string; - l2Erc20DefaultBridge: string; - l1WethBridge: string; - l2WethBridge: string; + l1SharedDefaultBridge: string; + l2SharedDefaultBridge: string; } = await this.send('zks_getBridgeContracts', []); this.contractAddresses.erc20BridgeL1 = addresses.l1Erc20DefaultBridge; - this.contractAddresses.erc20BridgeL2 = addresses.l2Erc20DefaultBridge; - this.contractAddresses.wethBridgeL1 = addresses.l1WethBridge; - this.contractAddresses.wethBridgeL2 = addresses.l2WethBridge; + this.contractAddresses.sharedBridgeL1 = addresses.l1SharedDefaultBridge; + this.contractAddresses.sharedBridgeL2 = addresses.l2SharedDefaultBridge; } return { erc20L1: this.contractAddresses.erc20BridgeL1, - erc20L2: this.contractAddresses.erc20BridgeL2, - wethL1: this.contractAddresses.wethBridgeL1, - wethL2: this.contractAddresses.wethBridgeL2, + sharedL1: this.contractAddresses.sharedBridgeL1!, + sharedL2: this.contractAddresses.sharedBridgeL2!, }; } @@ -1163,6 +1189,9 @@ export class Provider extends ethers.providers.JsonRpcProvider { overrides?: ethers.CallOverrides; }): Promise { const {...tx} = transaction; + if (tx.token === LEGACY_ETH_ADDRESS) { + tx.token = ETH_ADDRESS_IN_CONTRACTS; + } if (!tx.to && !tx.from) { throw new Error('Withdrawal target address is undefined!'); @@ -1185,7 +1214,7 @@ export class Provider extends ethers.providers.JsonRpcProvider { throw new Error('The tx.value is not equal to the value withdrawn!'); } - const ethL2Token = IEthTokenFactory.connect(L2_ETH_TOKEN_ADDRESS, this); + const ethL2Token = IEthTokenFactory.connect(L2_BASE_TOKEN_ADDRESS, this); const populatedTx = await ethL2Token.populateTransaction.withdraw( tx.to!, tx.overrides @@ -1203,20 +1232,7 @@ export class Provider extends ethers.providers.JsonRpcProvider { if (!tx.bridgeAddress) { const bridgeAddresses = await this.getDefaultBridgeAddresses(); - const l2WethBridge = IL2BridgeFactory.connect( - bridgeAddresses.wethL2!, - this - ); - let l1WethToken = ethers.constants.AddressZero; - try { - l1WethToken = await l2WethBridge.l1TokenAddress(tx.token); - } catch (e) { - // skip - } - tx.bridgeAddress = - l1WethToken !== ethers.constants.AddressZero - ? bridgeAddresses.wethL2 - : bridgeAddresses.erc20L2; + tx.bridgeAddress = bridgeAddresses.sharedL2; } const bridge = IL2BridgeFactory.connect(tx.bridgeAddress!, this); @@ -1333,7 +1349,11 @@ export class Provider extends ethers.providers.JsonRpcProvider { tx.overrides ??= {}; tx.overrides.from ??= tx.from; - if (!tx.token || tx.token === ETH_ADDRESS) { + if ( + !tx.token || + tx.token === LEGACY_ETH_ADDRESS || + (await this.isBaseToken(tx.token)) + ) { if (tx.paymasterParams) { return { ...(await ethers.utils.resolveProperties(tx.overrides)), @@ -1710,6 +1730,54 @@ export class Provider extends ethers.providers.JsonRpcProvider { return l2Response; } + async _getPriorityOpConfirmationL2ToL1Log(txHash: string, index = 0) { + const hash = ethers.utils.hexlify(txHash); + const receipt = await this.getTransactionReceipt(hash); + const messages = Array.from(receipt.l2ToL1Logs.entries()).filter( + ([, log]) => log.sender === BOOTLOADER_FORMAL_ADDRESS + ); + const [l2ToL1LogIndex, l2ToL1Log] = messages[index]; + + return { + l2ToL1LogIndex, + l2ToL1Log, + l1BatchTxId: receipt.l1BatchTxIndex, + }; + } + + /** + * Returns the transaction confirmation data that is part of `L2->L1` message. + * + * @param txHash The hash of the L2 transaction where the message was initiated. + * @param [index=0] In case there were multiple transactions in one message, you may pass an index of the + * transaction which confirmation data should be fetched. + * @throws {Error} If log proof can not be found. + * + * @example + * + * import { Provider, types, utils } from "zksync-ethers"; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * // Any L2 -> L1 transaction can be used. + * // In this case, withdrawal transaction is used. + * const tx = "0x2a1c6c74b184965c0cb015aae9ea134fd96215d2e4f4979cfec12563295f610e"; + * console.log(`Confirmation data: ${utils.toJSON(await provider.getPriorityOpConfirmation(tx, 0))}`); + */ + async getPriorityOpConfirmation(txHash: string, index = 0) { + const {l2ToL1LogIndex, l2ToL1Log, l1BatchTxId} = + await this._getPriorityOpConfirmationL2ToL1Log(txHash, index); + const proof = await this.getLogProof(txHash, l2ToL1LogIndex); + if (!proof) { + throw new Error('Log proof not found!'); + } + return { + l1BatchNumber: l2ToL1Log.l1BatchNumber, + l2MessageIndex: proof.id, + l2TxNumberInBlock: l1BatchTxId, + proof: proof.proof, + }; + } + /** * Returns the version of the supported account abstraction and nonce ordering from a given contract address. * diff --git a/src/signer.ts b/src/signer.ts index 0095de3a..7543cb87 100644 --- a/src/signer.ts +++ b/src/signer.ts @@ -21,9 +21,11 @@ import { import {TypedDataDomain, TypedDataSigner} from '@ethersproject/abstract-signer'; import {_TypedDataEncoder as TypedDataEncoder} from '@ethersproject/hash'; import {AdapterL1, AdapterL2} from './adapters'; -import {Il2Bridge} from './typechain/Il2Bridge'; -import {IZkSync} from './typechain/IZkSync'; -import {Il1Bridge} from './typechain/Il1Bridge'; +import {Il2Bridge as IL2Bridge} from './typechain/Il2Bridge'; +import {Il1Erc20Bridge as IL1ERC20Bridge} from './typechain/Il1Erc20Bridge'; +import {Il1SharedBridge as IL1SharedBridge} from './typechain/Il1SharedBridge'; +import {IZkSyncStateTransition} from './typechain/IZkSyncStateTransition'; +import {IBridgehub} from './typechain/IBridgehub'; /** * All typed data conforming to the EIP712 standard within zkSync Era. @@ -267,8 +269,7 @@ export class Signer extends AdapterL2(ethers.providers.JsonRpcSigner) { * const l2BridgeContracts = await signer.getL2BridgeContracts(); */ override async getL2BridgeContracts(): Promise<{ - erc20: Il2Bridge; - weth: Il2Bridge; + shared: IL2Bridge; }> { return super.getL2BridgeContracts(); } @@ -276,7 +277,7 @@ export class Signer extends AdapterL2(ethers.providers.JsonRpcSigner) { /** * @inheritDoc * - * @example Withdraw ETH. + * @example Withdraw token. * * import { Web3Provider, Provider, types } from "zksync-ethers"; * @@ -292,7 +293,7 @@ export class Signer extends AdapterL2(ethers.providers.JsonRpcSigner) { * amount: 10_000_000, * }); * - * @example Withdraw ETH using paymaster to facilitate fee payment with an ERC20 token. + * @example Withdraw token using paymaster to facilitate fee payment with an ERC20 token. * * import { Web3Provider, Provider, types } from "zksync-ethers"; * @@ -306,7 +307,7 @@ export class Signer extends AdapterL2(ethers.providers.JsonRpcSigner) { * ); * * const tokenL2 = "0x6a4Fb925583F7D4dF82de62d98107468aE846FD1"; - * await wallet.withdraw({ + * await signer.withdraw({ * token: tokenL2, * amount: 10_000_000, * paymasterParams: utils.getPaymasterParams(paymaster, { @@ -525,12 +526,31 @@ export class L1Signer extends AdapterL1(ethers.providers.JsonRpcSigner) { * ); * * const mainContract = await signer.getMainContract(); - * console.log(mainContract.address); */ - override async getMainContract(): Promise { + override async getMainContract(): Promise { return super.getMainContract(); } + /** + * @inheritDoc + * + * @example + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * const bridgehub = await signer.getBridgehubContract(); + */ + override async getBridgehubContract(): Promise { + return super.getBridgehubContract(); + } + /** * @inheritDoc * @@ -548,8 +568,8 @@ export class L1Signer extends AdapterL1(ethers.providers.JsonRpcSigner) { * const l1BridgeContracts = await signer.getL1BridgeContracts(); */ override async getL1BridgeContracts(): Promise<{ - erc20: Il1Bridge; - weth: Il1Bridge; + erc20: IL1ERC20Bridge; + shared: IL1SharedBridge; }> { return super.getL1BridgeContracts(); } @@ -692,7 +712,133 @@ export class L1Signer extends AdapterL1(ethers.providers.JsonRpcSigner) { /** * @inheritDoc * - * @example Deposit ETH. + * @example + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * console.log(`Base token: ${await signer.getBaseToken()}`); + */ + override async getBaseToken(): Promise { + return super.getBaseToken(); + } + + /** + * @inheritDoc + * + * @example + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * console.log(`Is ETH-based chain: ${await signer.isETHBasedChain()}`); + */ + override async isETHBasedChain(): Promise { + return super.isETHBasedChain(); + } + + /** + * @inheritDoc + * + * @example Get allowance parameters for depositing ETH on non-ETH-based chain. + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * const token = utils.LEGACY_ETH_ADDRESS; + * const amount = 5; + * const approveParams = await signer.getDepositAllowanceParams(token, amount); + * await ( + * await signer.approveERC20( + * approveParams[0].token, + * approveParams[0].allowance + * ) + * ).wait(); + * + * @example Get allowance parameters for depositing base token on non-ETH-based chain. + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * const token = await signer.getBaseToken(); + * const amount = 5; + * const approveParams = await signer.getDepositAllowanceParams(token, amount); + * await ( + * await signer.approveERC20( + * approveParams[0].token, + * approveParams[0].allowance + * ) + * ).wait(); + * + * @example Get allowance parameters for depositing non-base token on non-ETH-based chain. + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * const token = ""; + * const amount = 5; + * const approveParams = await signer.getDepositAllowanceParams(token, amount); + * + * await ( + * await signer.approveERC20( + * approveParams[0].token, + * approveParams[0].allowance + * ) + * ).wait(); + * + * await ( + * await signer.approveERC20( + * approveParams[1].token, + * approveParams[1].allowance + * ) + * ).wait(); + */ + override async getDepositAllowanceParams( + token: Address, + amount: BigNumberish + ): Promise< + { + token: Address; + allowance: BigNumberish; + }[] + > { + return super.getDepositAllowanceParams(token, amount); + } + + /** + * @inheritDoc + * + * @example Deposit ETH on ETH-based chain. * * import { Provider, L1Signer, types } from "zksync-ethers"; * import { ethers } from "ethers"; @@ -708,7 +854,59 @@ export class L1Signer extends AdapterL1(ethers.providers.JsonRpcSigner) { * amount: 10_000_000, * }); * - * @example Deposit token. + * @example Deposit token on ETH-based chain. + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * const tokenL1 = "0x56E69Fa1BB0d1402c89E3A4E3417882DeA6B14Be"; + * await signer.deposit({ + * token: tokenL1, + * amount: 10_000_000, + * approveERC20: true, + * }); + * + * @example Deposit ETH on non-ETH-chain. + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * await signer.deposit({ + * token: utils.ETH_ADDRESS, + * amount: 10_000_000, + * approveBaseERC20: true, + * }); + * + * @example Deposit base token on non-ETH-based chain. + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * await signer.deposit({ + * token: await signer.getBaseToken(), + * amount: 10_000_000, + * approveERC20: true, // or approveBaseERC20: true + * }); + * + * @example Deposit non-base token on non-ETH-based chain. * * import { Provider, L1Signer, types } from "zksync-ethers"; * import { ethers } from "ethers"; @@ -724,6 +922,7 @@ export class L1Signer extends AdapterL1(ethers.providers.JsonRpcSigner) { * token: tokenL1, * amount: 10_000_000, * approveERC20: true, + * approveBaseERC20: true, * }); */ override async deposit(transaction: { @@ -943,6 +1142,48 @@ export class L1Signer extends AdapterL1(ethers.providers.JsonRpcSigner) { return super.claimFailedDeposit(depositHash, overrides); } + /** + * @inheritDoc + * + * @example + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * const tx = { + * contractAddress: await signer.getAddress(), + * calldata: '0x', + * l2Value: 7_000_000_000, + * }; + * + * const approveParams = await signer.getRequestExecuteAllowanceParams(tx); + * await ( + * await signer.approveERC20( + * approveParams.token, + * approveParams.allowance + * ) + * ).wait(); + */ + override async getRequestExecuteAllowanceParams(transaction: { + contractAddress: Address; + calldata: BytesLike; + l2GasLimit?: BigNumberish; + l2Value?: BigNumberish; + factoryDeps?: BytesLike[]; + operatorTip?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }): Promise<{token: Address; allowance: BigNumberish}> { + return super.getRequestExecuteAllowanceParams(transaction); + } + /** * @inheritDoc * @@ -1047,6 +1288,37 @@ export class L1Signer extends AdapterL1(ethers.providers.JsonRpcSigner) { return super.getRequestExecuteTx(transaction); } + /** + * @inheritDoc + * + * @example + * + * import { Provider, L1Signer, types } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const browserProvider = new ethers.providers.Web3Provider(window.ethereum); + * const signer = L1Signer.from( + * browserProvider.getSigner(), + * Provider.getDefaultProvider(types.Network.Sepolia) + * ); + * + * // Any L2 -> L1 transaction can be used. + * // In this case, withdrawal transaction is used. + * const tx = "0x2a1c6c74b184965c0cb015aae9ea134fd96215d2e4f4979cfec12563295f610e"; + * console.log(`Confirmation data: ${utils.toJSON(await signer.getPriorityOpConfirmation(tx, 0))}`); + */ + override async getPriorityOpConfirmation( + txHash: string, + index = 0 + ): Promise<{ + l1BatchNumber: number; + l2MessageIndex: number; + l2TxNumberInBlock: number; + proof: string[]; + }> { + return super.getPriorityOpConfirmation(txHash, index); + } + /** * Creates a new L1Singer with provided `signer` and `zksyncProvider`. * diff --git a/src/typechain/IBridgehub.d.ts b/src/typechain/IBridgehub.d.ts new file mode 100644 index 00000000..282a145c --- /dev/null +++ b/src/typechain/IBridgehub.d.ts @@ -0,0 +1,1737 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, +} from "ethers"; +import { + Contract, + ContractTransaction, + Overrides, + PayableOverrides, + CallOverrides, +} from "@ethersproject/contracts"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; + +interface IBridgehubInterface extends ethers.utils.Interface { + functions: { + "acceptAdmin()": FunctionFragment; + "addStateTransitionManager(address)": FunctionFragment; + "addToken(address)": FunctionFragment; + "baseToken(uint256)": FunctionFragment; + "createNewChain(uint256,address,address,uint256,address,bytes)": FunctionFragment; + "getStateTransition(uint256)": FunctionFragment; + "l2TransactionBaseCost(uint256,uint256,uint256,uint256)": FunctionFragment; + "proveL1ToL2TransactionStatus(uint256,bytes32,uint256,uint256,uint16,bytes32[],uint8)": FunctionFragment; + "proveL2LogInclusion(uint256,uint256,uint256,tuple,bytes32[])": FunctionFragment; + "proveL2MessageInclusion(uint256,uint256,uint256,tuple,bytes32[])": FunctionFragment; + "removeStateTransitionManager(address)": FunctionFragment; + "requestL2TransactionDirect(tuple)": FunctionFragment; + "requestL2TransactionTwoBridges(tuple)": FunctionFragment; + "setPendingAdmin(address)": FunctionFragment; + "setSharedBridge(address)": FunctionFragment; + "sharedBridge()": FunctionFragment; + "stateTransitionManager(uint256)": FunctionFragment; + "stateTransitionManagerIsRegistered(address)": FunctionFragment; + "tokenIsRegistered(address)": FunctionFragment; + }; + + encodeFunctionData( + functionFragment: "acceptAdmin", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "addStateTransitionManager", + values: [string] + ): string; + encodeFunctionData(functionFragment: "addToken", values: [string]): string; + encodeFunctionData( + functionFragment: "baseToken", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "createNewChain", + values: [BigNumberish, string, string, BigNumberish, string, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "getStateTransition", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "l2TransactionBaseCost", + values: [BigNumberish, BigNumberish, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "proveL1ToL2TransactionStatus", + values: [ + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike[], + BigNumberish + ] + ): string; + encodeFunctionData( + functionFragment: "proveL2LogInclusion", + values: [ + BigNumberish, + BigNumberish, + BigNumberish, + { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + BytesLike[] + ] + ): string; + encodeFunctionData( + functionFragment: "proveL2MessageInclusion", + values: [ + BigNumberish, + BigNumberish, + BigNumberish, + { txNumberInBatch: BigNumberish; sender: string; data: BytesLike }, + BytesLike[] + ] + ): string; + encodeFunctionData( + functionFragment: "removeStateTransitionManager", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "requestL2TransactionDirect", + values: [ + { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + } + ] + ): string; + encodeFunctionData( + functionFragment: "requestL2TransactionTwoBridges", + values: [ + { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + } + ] + ): string; + encodeFunctionData( + functionFragment: "setPendingAdmin", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "setSharedBridge", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "sharedBridge", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "stateTransitionManager", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "stateTransitionManagerIsRegistered", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "tokenIsRegistered", + values: [string] + ): string; + + decodeFunctionResult( + functionFragment: "acceptAdmin", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "addStateTransitionManager", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "addToken", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "baseToken", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "createNewChain", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getStateTransition", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "l2TransactionBaseCost", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "proveL1ToL2TransactionStatus", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "proveL2LogInclusion", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "proveL2MessageInclusion", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "removeStateTransitionManager", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "requestL2TransactionDirect", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "requestL2TransactionTwoBridges", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setPendingAdmin", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setSharedBridge", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "sharedBridge", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "stateTransitionManager", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "stateTransitionManagerIsRegistered", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "tokenIsRegistered", + data: BytesLike + ): Result; + + events: { + "NewAdmin(address,address)": EventFragment; + "NewChain(uint256,address,address)": EventFragment; + "NewPendingAdmin(address,address)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "NewAdmin"): EventFragment; + getEvent(nameOrSignatureOrTopic: "NewChain"): EventFragment; + getEvent(nameOrSignatureOrTopic: "NewPendingAdmin"): EventFragment; +} + +export class IBridgehub extends Contract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + on(event: EventFilter | string, listener: Listener): this; + once(event: EventFilter | string, listener: Listener): this; + addListener(eventName: EventFilter | string, listener: Listener): this; + removeAllListeners(eventName: EventFilter | string): this; + removeListener(eventName: any, listener: Listener): this; + + interface: IBridgehubInterface; + + functions: { + acceptAdmin(overrides?: Overrides): Promise; + + "acceptAdmin()"(overrides?: Overrides): Promise; + + addStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "addStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + addToken( + _token: string, + overrides?: Overrides + ): Promise; + + "addToken(address)"( + _token: string, + overrides?: Overrides + ): Promise; + + baseToken( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + "baseToken(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + createNewChain( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + "createNewChain(uint256,address,address,uint256,address,bytes)"( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + getStateTransition( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + "getStateTransition(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + l2TransactionBaseCost( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: BigNumber; + }>; + + "l2TransactionBaseCost(uint256,uint256,uint256,uint256)"( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: BigNumber; + }>; + + proveL1ToL2TransactionStatus( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + "proveL1ToL2TransactionStatus(uint256,bytes32,uint256,uint256,uint16,bytes32[],uint8)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + proveL2LogInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + "proveL2LogInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + proveL2MessageInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + "proveL2MessageInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + removeStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "removeStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + requestL2TransactionDirect( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionDirect(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + requestL2TransactionTwoBridges( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionTwoBridges(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + setPendingAdmin( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + "setPendingAdmin(address)"( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + setSharedBridge( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + "setSharedBridge(address)"( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + sharedBridge(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "sharedBridge()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + stateTransitionManager( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + "stateTransitionManager(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + stateTransitionManagerIsRegistered( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + "stateTransitionManagerIsRegistered(address)"( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + tokenIsRegistered( + _baseToken: string, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + "tokenIsRegistered(address)"( + _baseToken: string, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + }; + + acceptAdmin(overrides?: Overrides): Promise; + + "acceptAdmin()"(overrides?: Overrides): Promise; + + addStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "addStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + addToken(_token: string, overrides?: Overrides): Promise; + + "addToken(address)"( + _token: string, + overrides?: Overrides + ): Promise; + + baseToken(_chainId: BigNumberish, overrides?: CallOverrides): Promise; + + "baseToken(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + createNewChain( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + "createNewChain(uint256,address,address,uint256,address,bytes)"( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + getStateTransition( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "getStateTransition(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2TransactionBaseCost( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2TransactionBaseCost(uint256,uint256,uint256,uint256)"( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL1ToL2TransactionStatus( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "proveL1ToL2TransactionStatus(uint256,bytes32,uint256,uint256,uint16,bytes32[],uint8)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL2LogInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2LogInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + proveL2MessageInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2MessageInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + removeStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "removeStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + requestL2TransactionDirect( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionDirect(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + requestL2TransactionTwoBridges( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionTwoBridges(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + setPendingAdmin( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + "setPendingAdmin(address)"( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + setSharedBridge( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + "setSharedBridge(address)"( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + stateTransitionManager( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManager(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + stateTransitionManagerIsRegistered( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManagerIsRegistered(address)"( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + tokenIsRegistered( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + + "tokenIsRegistered(address)"( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + + callStatic: { + acceptAdmin(overrides?: CallOverrides): Promise; + + "acceptAdmin()"(overrides?: CallOverrides): Promise; + + addStateTransitionManager( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + "addStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + addToken(_token: string, overrides?: CallOverrides): Promise; + + "addToken(address)"( + _token: string, + overrides?: CallOverrides + ): Promise; + + baseToken( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "baseToken(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + createNewChain( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: CallOverrides + ): Promise; + + "createNewChain(uint256,address,address,uint256,address,bytes)"( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: CallOverrides + ): Promise; + + getStateTransition( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "getStateTransition(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2TransactionBaseCost( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2TransactionBaseCost(uint256,uint256,uint256,uint256)"( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL1ToL2TransactionStatus( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "proveL1ToL2TransactionStatus(uint256,bytes32,uint256,uint256,uint16,bytes32[],uint8)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL2LogInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2LogInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + proveL2MessageInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2MessageInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + removeStateTransitionManager( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + "removeStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + requestL2TransactionDirect( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: CallOverrides + ): Promise; + + "requestL2TransactionDirect(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: CallOverrides + ): Promise; + + requestL2TransactionTwoBridges( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: CallOverrides + ): Promise; + + "requestL2TransactionTwoBridges(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: CallOverrides + ): Promise; + + setPendingAdmin( + _newPendingAdmin: string, + overrides?: CallOverrides + ): Promise; + + "setPendingAdmin(address)"( + _newPendingAdmin: string, + overrides?: CallOverrides + ): Promise; + + setSharedBridge( + _sharedBridge: string, + overrides?: CallOverrides + ): Promise; + + "setSharedBridge(address)"( + _sharedBridge: string, + overrides?: CallOverrides + ): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + stateTransitionManager( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManager(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + stateTransitionManagerIsRegistered( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManagerIsRegistered(address)"( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + tokenIsRegistered( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + + "tokenIsRegistered(address)"( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + NewAdmin(oldAdmin: string | null, newAdmin: string | null): EventFilter; + + NewChain( + chainId: BigNumberish | null, + stateTransitionManager: null, + chainGovernance: string | null + ): EventFilter; + + NewPendingAdmin( + oldPendingAdmin: string | null, + newPendingAdmin: string | null + ): EventFilter; + }; + + estimateGas: { + acceptAdmin(overrides?: Overrides): Promise; + + "acceptAdmin()"(overrides?: Overrides): Promise; + + addStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "addStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + addToken(_token: string, overrides?: Overrides): Promise; + + "addToken(address)"( + _token: string, + overrides?: Overrides + ): Promise; + + baseToken( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "baseToken(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + createNewChain( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + "createNewChain(uint256,address,address,uint256,address,bytes)"( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + getStateTransition( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "getStateTransition(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2TransactionBaseCost( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2TransactionBaseCost(uint256,uint256,uint256,uint256)"( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL1ToL2TransactionStatus( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "proveL1ToL2TransactionStatus(uint256,bytes32,uint256,uint256,uint16,bytes32[],uint8)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL2LogInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2LogInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + proveL2MessageInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2MessageInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + removeStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "removeStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + requestL2TransactionDirect( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionDirect(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + requestL2TransactionTwoBridges( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionTwoBridges(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + setPendingAdmin( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + "setPendingAdmin(address)"( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + setSharedBridge( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + "setSharedBridge(address)"( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + stateTransitionManager( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManager(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + stateTransitionManagerIsRegistered( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManagerIsRegistered(address)"( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + tokenIsRegistered( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + + "tokenIsRegistered(address)"( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + }; + + populateTransaction: { + acceptAdmin(overrides?: Overrides): Promise; + + "acceptAdmin()"(overrides?: Overrides): Promise; + + addStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "addStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + addToken( + _token: string, + overrides?: Overrides + ): Promise; + + "addToken(address)"( + _token: string, + overrides?: Overrides + ): Promise; + + baseToken( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "baseToken(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + createNewChain( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + "createNewChain(uint256,address,address,uint256,address,bytes)"( + _chainId: BigNumberish, + _stateTransitionManager: string, + _baseToken: string, + _salt: BigNumberish, + _admin: string, + _initData: BytesLike, + overrides?: Overrides + ): Promise; + + getStateTransition( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "getStateTransition(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2TransactionBaseCost( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2TransactionBaseCost(uint256,uint256,uint256,uint256)"( + _chainId: BigNumberish, + _gasPrice: BigNumberish, + _l2GasLimit: BigNumberish, + _l2GasPerPubdataByteLimit: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL1ToL2TransactionStatus( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "proveL1ToL2TransactionStatus(uint256,bytes32,uint256,uint256,uint16,bytes32[],uint8)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + _status: BigNumberish, + overrides?: CallOverrides + ): Promise; + + proveL2LogInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2LogInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _log: { + l2ShardId: BigNumberish; + isService: boolean; + txNumberInBatch: BigNumberish; + sender: string; + key: BytesLike; + value: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + proveL2MessageInclusion( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "proveL2MessageInclusion(uint256,uint256,uint256,tuple,bytes32[])"( + _chainId: BigNumberish, + _batchNumber: BigNumberish, + _index: BigNumberish, + _message: { + txNumberInBatch: BigNumberish; + sender: string; + data: BytesLike; + }, + _proof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + removeStateTransitionManager( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + "removeStateTransitionManager(address)"( + _stateTransitionManager: string, + overrides?: Overrides + ): Promise; + + requestL2TransactionDirect( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionDirect(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Contract: string; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + requestL2TransactionTwoBridges( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + "requestL2TransactionTwoBridges(tuple)"( + _request: { + chainId: BigNumberish; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + refundRecipient: string; + secondBridgeAddress: string; + secondBridgeValue: BigNumberish; + secondBridgeCalldata: BytesLike; + }, + overrides?: PayableOverrides + ): Promise; + + setPendingAdmin( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + "setPendingAdmin(address)"( + _newPendingAdmin: string, + overrides?: Overrides + ): Promise; + + setSharedBridge( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + "setSharedBridge(address)"( + _sharedBridge: string, + overrides?: Overrides + ): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + stateTransitionManager( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManager(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + stateTransitionManagerIsRegistered( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + "stateTransitionManagerIsRegistered(address)"( + _stateTransitionManager: string, + overrides?: CallOverrides + ): Promise; + + tokenIsRegistered( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + + "tokenIsRegistered(address)"( + _baseToken: string, + overrides?: CallOverrides + ): Promise; + }; +} diff --git a/src/typechain/IBridgehubFactory.ts b/src/typechain/IBridgehubFactory.ts new file mode 100644 index 00000000..97fa46d8 --- /dev/null +++ b/src/typechain/IBridgehubFactory.ts @@ -0,0 +1,649 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer } from "ethers"; +import { Provider } from "@ethersproject/providers"; + +import type { IBridgehub } from "./IBridgehub"; + +export class IBridgehubFactory { + static connect( + address: string, + signerOrProvider: Signer | Provider + ): IBridgehub { + return new Contract(address, _abi, signerOrProvider) as IBridgehub; + } +} + +const _abi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "oldAdmin", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newAdmin", + type: "address", + }, + ], + name: "NewAdmin", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "stateTransitionManager", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "chainGovernance", + type: "address", + }, + ], + name: "NewChain", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "oldPendingAdmin", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newPendingAdmin", + type: "address", + }, + ], + name: "NewPendingAdmin", + type: "event", + }, + { + inputs: [], + name: "acceptAdmin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_stateTransitionManager", + type: "address", + }, + ], + name: "addStateTransitionManager", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_token", + type: "address", + }, + ], + name: "addToken", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + ], + name: "baseToken", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "address", + name: "_stateTransitionManager", + type: "address", + }, + { + internalType: "address", + name: "_baseToken", + type: "address", + }, + { + internalType: "uint256", + name: "_salt", + type: "uint256", + }, + { + internalType: "address", + name: "_admin", + type: "address", + }, + { + internalType: "bytes", + name: "_initData", + type: "bytes", + }, + ], + name: "createNewChain", + outputs: [ + { + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + ], + name: "getStateTransition", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "_gasPrice", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2GasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2GasPerPubdataByteLimit", + type: "uint256", + }, + ], + name: "l2TransactionBaseCost", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "bytes32", + name: "_l2TxHash", + type: "bytes32", + }, + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + { + internalType: "uint16", + name: "_l2TxNumberInBatch", + type: "uint16", + }, + { + internalType: "bytes32[]", + name: "_merkleProof", + type: "bytes32[]", + }, + { + internalType: "enum TxStatus", + name: "_status", + type: "uint8", + }, + ], + name: "proveL1ToL2TransactionStatus", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "_batchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_index", + type: "uint256", + }, + { + components: [ + { + internalType: "uint8", + name: "l2ShardId", + type: "uint8", + }, + { + internalType: "bool", + name: "isService", + type: "bool", + }, + { + internalType: "uint16", + name: "txNumberInBatch", + type: "uint16", + }, + { + internalType: "address", + name: "sender", + type: "address", + }, + { + internalType: "bytes32", + name: "key", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "value", + type: "bytes32", + }, + ], + internalType: "struct L2Log", + name: "_log", + type: "tuple", + }, + { + internalType: "bytes32[]", + name: "_proof", + type: "bytes32[]", + }, + ], + name: "proveL2LogInclusion", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "_batchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_index", + type: "uint256", + }, + { + components: [ + { + internalType: "uint16", + name: "txNumberInBatch", + type: "uint16", + }, + { + internalType: "address", + name: "sender", + type: "address", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + internalType: "struct L2Message", + name: "_message", + type: "tuple", + }, + { + internalType: "bytes32[]", + name: "_proof", + type: "bytes32[]", + }, + ], + name: "proveL2MessageInclusion", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_stateTransitionManager", + type: "address", + }, + ], + name: "removeStateTransitionManager", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "mintValue", + type: "uint256", + }, + { + internalType: "address", + name: "l2Contract", + type: "address", + }, + { + internalType: "uint256", + name: "l2Value", + type: "uint256", + }, + { + internalType: "bytes", + name: "l2Calldata", + type: "bytes", + }, + { + internalType: "uint256", + name: "l2GasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "l2GasPerPubdataByteLimit", + type: "uint256", + }, + { + internalType: "bytes[]", + name: "factoryDeps", + type: "bytes[]", + }, + { + internalType: "address", + name: "refundRecipient", + type: "address", + }, + ], + internalType: "struct L2TransactionRequestDirect", + name: "_request", + type: "tuple", + }, + ], + name: "requestL2TransactionDirect", + outputs: [ + { + internalType: "bytes32", + name: "canonicalTxHash", + type: "bytes32", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "mintValue", + type: "uint256", + }, + { + internalType: "uint256", + name: "l2Value", + type: "uint256", + }, + { + internalType: "uint256", + name: "l2GasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "l2GasPerPubdataByteLimit", + type: "uint256", + }, + { + internalType: "address", + name: "refundRecipient", + type: "address", + }, + { + internalType: "address", + name: "secondBridgeAddress", + type: "address", + }, + { + internalType: "uint256", + name: "secondBridgeValue", + type: "uint256", + }, + { + internalType: "bytes", + name: "secondBridgeCalldata", + type: "bytes", + }, + ], + internalType: "struct L2TransactionRequestTwoBridgesOuter", + name: "_request", + type: "tuple", + }, + ], + name: "requestL2TransactionTwoBridges", + outputs: [ + { + internalType: "bytes32", + name: "canonicalTxHash", + type: "bytes32", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_newPendingAdmin", + type: "address", + }, + ], + name: "setPendingAdmin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_sharedBridge", + type: "address", + }, + ], + name: "setSharedBridge", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "sharedBridge", + outputs: [ + { + internalType: "contract IL1SharedBridge", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + ], + name: "stateTransitionManager", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_stateTransitionManager", + type: "address", + }, + ], + name: "stateTransitionManagerIsRegistered", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_baseToken", + type: "address", + }, + ], + name: "tokenIsRegistered", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, +]; diff --git a/src/typechain/IContractDeployer.d.ts b/src/typechain/IContractDeployer.d.ts index 7cd88871..c36845b7 100644 --- a/src/typechain/IContractDeployer.d.ts +++ b/src/typechain/IContractDeployer.d.ts @@ -27,6 +27,9 @@ interface IContractDeployerInterface extends ethers.utils.Interface { "create2(bytes32,bytes32,bytes)": FunctionFragment; "create2Account(bytes32,bytes32,bytes,uint8)": FunctionFragment; "createAccount(bytes32,bytes32,bytes,uint8)": FunctionFragment; + "extendedAccountVersion(address)": FunctionFragment; + "forceDeployOnAddress(tuple,address)": FunctionFragment; + "forceDeployOnAddresses(tuple[])": FunctionFragment; "getAccountInfo(address)": FunctionFragment; "getNewAddressCreate(address,uint256)": FunctionFragment; "getNewAddressCreate2(address,bytes32,bytes32,bytes)": FunctionFragment; @@ -50,6 +53,35 @@ interface IContractDeployerInterface extends ethers.utils.Interface { functionFragment: "createAccount", values: [BytesLike, BytesLike, BytesLike, BigNumberish] ): string; + encodeFunctionData( + functionFragment: "extendedAccountVersion", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "forceDeployOnAddress", + values: [ + { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + string + ] + ): string; + encodeFunctionData( + functionFragment: "forceDeployOnAddresses", + values: [ + { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[] + ] + ): string; encodeFunctionData( functionFragment: "getAccountInfo", values: [string] @@ -81,6 +113,18 @@ interface IContractDeployerInterface extends ethers.utils.Interface { functionFragment: "createAccount", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "extendedAccountVersion", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "forceDeployOnAddress", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "forceDeployOnAddresses", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "getAccountInfo", data: BytesLike @@ -174,7 +218,7 @@ export class IContractDeployer extends Contract { ): Promise; createAccount( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, @@ -182,13 +226,73 @@ export class IContractDeployer extends Contract { ): Promise; "createAccount(bytes32,bytes32,bytes,uint8)"( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, overrides?: PayableOverrides ): Promise; + extendedAccountVersion( + _address: string, + overrides?: CallOverrides + ): Promise<{ + 0: number; + }>; + + "extendedAccountVersion(address)"( + _address: string, + overrides?: CallOverrides + ): Promise<{ + 0: number; + }>; + + forceDeployOnAddress( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddress(tuple,address)"( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + forceDeployOnAddresses( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddresses(tuple[])"( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + getAccountInfo( _address: string, overrides?: CallOverrides @@ -331,7 +435,7 @@ export class IContractDeployer extends Contract { ): Promise; createAccount( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, @@ -339,13 +443,69 @@ export class IContractDeployer extends Contract { ): Promise; "createAccount(bytes32,bytes32,bytes,uint8)"( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, overrides?: PayableOverrides ): Promise; + extendedAccountVersion( + _address: string, + overrides?: CallOverrides + ): Promise; + + "extendedAccountVersion(address)"( + _address: string, + overrides?: CallOverrides + ): Promise; + + forceDeployOnAddress( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddress(tuple,address)"( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + forceDeployOnAddresses( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddresses(tuple[])"( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + getAccountInfo( _address: string, overrides?: CallOverrides @@ -460,7 +620,7 @@ export class IContractDeployer extends Contract { ): Promise; createAccount( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, @@ -468,13 +628,69 @@ export class IContractDeployer extends Contract { ): Promise; "createAccount(bytes32,bytes32,bytes,uint8)"( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, overrides?: CallOverrides ): Promise; + extendedAccountVersion( + _address: string, + overrides?: CallOverrides + ): Promise; + + "extendedAccountVersion(address)"( + _address: string, + overrides?: CallOverrides + ): Promise; + + forceDeployOnAddress( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: CallOverrides + ): Promise; + + "forceDeployOnAddress(tuple,address)"( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: CallOverrides + ): Promise; + + forceDeployOnAddresses( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: CallOverrides + ): Promise; + + "forceDeployOnAddresses(tuple[])"( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: CallOverrides + ): Promise; + getAccountInfo( _address: string, overrides?: CallOverrides @@ -608,7 +824,7 @@ export class IContractDeployer extends Contract { ): Promise; createAccount( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, @@ -616,13 +832,69 @@ export class IContractDeployer extends Contract { ): Promise; "createAccount(bytes32,bytes32,bytes,uint8)"( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, overrides?: PayableOverrides ): Promise; + extendedAccountVersion( + _address: string, + overrides?: CallOverrides + ): Promise; + + "extendedAccountVersion(address)"( + _address: string, + overrides?: CallOverrides + ): Promise; + + forceDeployOnAddress( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddress(tuple,address)"( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + forceDeployOnAddresses( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddresses(tuple[])"( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + getAccountInfo( _address: string, overrides?: CallOverrides @@ -728,7 +1000,7 @@ export class IContractDeployer extends Contract { ): Promise; createAccount( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, @@ -736,13 +1008,69 @@ export class IContractDeployer extends Contract { ): Promise; "createAccount(bytes32,bytes32,bytes,uint8)"( - _salt: BytesLike, + arg0: BytesLike, _bytecodeHash: BytesLike, _input: BytesLike, _aaVersion: BigNumberish, overrides?: PayableOverrides ): Promise; + extendedAccountVersion( + _address: string, + overrides?: CallOverrides + ): Promise; + + "extendedAccountVersion(address)"( + _address: string, + overrides?: CallOverrides + ): Promise; + + forceDeployOnAddress( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddress(tuple,address)"( + _deployment: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }, + _sender: string, + overrides?: PayableOverrides + ): Promise; + + forceDeployOnAddresses( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + + "forceDeployOnAddresses(tuple[])"( + _deployments: { + bytecodeHash: BytesLike; + newAddress: string; + callConstructor: boolean; + value: BigNumberish; + input: BytesLike; + }[], + overrides?: PayableOverrides + ): Promise; + getAccountInfo( _address: string, overrides?: CallOverrides diff --git a/src/typechain/IContractDeployerFactory.ts b/src/typechain/IContractDeployerFactory.ts index 3905e602..8b52f966 100644 --- a/src/typechain/IContractDeployerFactory.ts +++ b/src/typechain/IContractDeployerFactory.ts @@ -102,7 +102,7 @@ const _abi = [ outputs: [ { internalType: "address", - name: "newAddress", + name: "", type: "address", }, ], @@ -131,7 +131,7 @@ const _abi = [ outputs: [ { internalType: "address", - name: "newAddress", + name: "", type: "address", }, ], @@ -165,7 +165,7 @@ const _abi = [ outputs: [ { internalType: "address", - name: "newAddress", + name: "", type: "address", }, ], @@ -176,7 +176,7 @@ const _abi = [ inputs: [ { internalType: "bytes32", - name: "_salt", + name: "", type: "bytes32", }, { @@ -199,10 +199,114 @@ const _abi = [ outputs: [ { internalType: "address", - name: "newAddress", + name: "", + type: "address", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_address", + type: "address", + }, + ], + name: "extendedAccountVersion", + outputs: [ + { + internalType: "enum IContractDeployer.AccountAbstractionVersion", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "bytes32", + name: "bytecodeHash", + type: "bytes32", + }, + { + internalType: "address", + name: "newAddress", + type: "address", + }, + { + internalType: "bool", + name: "callConstructor", + type: "bool", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + { + internalType: "bytes", + name: "input", + type: "bytes", + }, + ], + internalType: "struct ContractDeployer.ForceDeployment", + name: "_deployment", + type: "tuple", + }, + { + internalType: "address", + name: "_sender", type: "address", }, ], + name: "forceDeployOnAddress", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "bytes32", + name: "bytecodeHash", + type: "bytes32", + }, + { + internalType: "address", + name: "newAddress", + type: "address", + }, + { + internalType: "bool", + name: "callConstructor", + type: "bool", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + { + internalType: "bytes", + name: "input", + type: "bytes", + }, + ], + internalType: "struct ContractDeployer.ForceDeployment[]", + name: "_deployments", + type: "tuple[]", + }, + ], + name: "forceDeployOnAddresses", + outputs: [], stateMutability: "payable", type: "function", }, diff --git a/src/typechain/ITestnetErc20Token.d.ts b/src/typechain/ITestnetErc20Token.d.ts new file mode 100644 index 00000000..dd70f4d1 --- /dev/null +++ b/src/typechain/ITestnetErc20Token.d.ts @@ -0,0 +1,143 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, +} from "ethers"; +import { + Contract, + ContractTransaction, + Overrides, + CallOverrides, +} from "@ethersproject/contracts"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; + +interface ITestnetErc20TokenInterface extends ethers.utils.Interface { + functions: { + "decimals()": FunctionFragment; + "mint(address,uint256)": FunctionFragment; + }; + + encodeFunctionData(functionFragment: "decimals", values?: undefined): string; + encodeFunctionData( + functionFragment: "mint", + values: [string, BigNumberish] + ): string; + + decodeFunctionResult(functionFragment: "decimals", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "mint", data: BytesLike): Result; + + events: {}; +} + +export class ITestnetErc20Token extends Contract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + on(event: EventFilter | string, listener: Listener): this; + once(event: EventFilter | string, listener: Listener): this; + addListener(eventName: EventFilter | string, listener: Listener): this; + removeAllListeners(eventName: EventFilter | string): this; + removeListener(eventName: any, listener: Listener): this; + + interface: ITestnetErc20TokenInterface; + + functions: { + decimals(overrides?: Overrides): Promise; + + "decimals()"(overrides?: Overrides): Promise; + + mint( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "mint(address,uint256)"( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + }; + + decimals(overrides?: Overrides): Promise; + + "decimals()"(overrides?: Overrides): Promise; + + mint( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "mint(address,uint256)"( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + callStatic: { + decimals(overrides?: CallOverrides): Promise; + + "decimals()"(overrides?: CallOverrides): Promise; + + mint( + _to: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "mint(address,uint256)"( + _to: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + }; + + filters: {}; + + estimateGas: { + decimals(overrides?: Overrides): Promise; + + "decimals()"(overrides?: Overrides): Promise; + + mint( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "mint(address,uint256)"( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + }; + + populateTransaction: { + decimals(overrides?: Overrides): Promise; + + "decimals()"(overrides?: Overrides): Promise; + + mint( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "mint(address,uint256)"( + _to: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + }; +} diff --git a/src/typechain/ITestnetErc20TokenFactory.ts b/src/typechain/ITestnetErc20TokenFactory.ts new file mode 100644 index 00000000..b4c3d7c6 --- /dev/null +++ b/src/typechain/ITestnetErc20TokenFactory.ts @@ -0,0 +1,57 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer } from "ethers"; +import { Provider } from "@ethersproject/providers"; + +import type { ITestnetErc20Token } from "./ITestnetErc20Token"; + +export class ITestnetErc20TokenFactory { + static connect( + address: string, + signerOrProvider: Signer | Provider + ): ITestnetErc20Token { + return new Contract(address, _abi, signerOrProvider) as ITestnetErc20Token; + } +} + +const _abi = [ + { + inputs: [], + name: "decimals", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_to", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + ], + name: "mint", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, +]; diff --git a/src/typechain/IZkSync.d.ts b/src/typechain/IZkSyncStateTransition.d.ts similarity index 63% rename from src/typechain/IZkSync.d.ts rename to src/typechain/IZkSyncStateTransition.d.ts index 1a37f3ba..d0a709cb 100644 --- a/src/typechain/IZkSync.d.ts +++ b/src/typechain/IZkSyncStateTransition.d.ts @@ -21,12 +21,17 @@ import { BytesLike } from "@ethersproject/bytes"; import { Listener, Provider } from "@ethersproject/providers"; import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; -interface IZkSyncInterface extends ethers.utils.Interface { +interface IZkSyncStateTransitionInterface extends ethers.utils.Interface { functions: { "acceptAdmin()": FunctionFragment; - "acceptGovernor()": FunctionFragment; + "baseTokenGasPriceMultiplierDenominator()": FunctionFragment; + "baseTokenGasPriceMultiplierNominator()": FunctionFragment; + "bridgehubRequestL2Transaction(tuple)": FunctionFragment; + "changeFeeParams(tuple)": FunctionFragment; "commitBatches(tuple,tuple[])": FunctionFragment; + "commitBatchesSharedBridge(uint256,tuple,tuple[])": FunctionFragment; "executeBatches(tuple[])": FunctionFragment; + "executeBatchesSharedBridge(uint256,tuple[])": FunctionFragment; "executeUpgrade(tuple)": FunctionFragment; "facetAddress(bytes4)": FunctionFragment; "facetAddresses()": FunctionFragment; @@ -34,17 +39,22 @@ interface IZkSyncInterface extends ethers.utils.Interface { "facets()": FunctionFragment; "finalizeEthWithdrawal(uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment; "freezeDiamond()": FunctionFragment; + "getAdmin()": FunctionFragment; + "getBaseToken()": FunctionFragment; + "getBaseTokenBridge()": FunctionFragment; + "getBridgehub()": FunctionFragment; "getFirstUnprocessedPriorityTx()": FunctionFragment; - "getGovernor()": FunctionFragment; "getL2BootloaderBytecodeHash()": FunctionFragment; "getL2DefaultAccountBytecodeHash()": FunctionFragment; "getL2SystemContractsUpgradeBatchNumber()": FunctionFragment; "getL2SystemContractsUpgradeTxHash()": FunctionFragment; "getName()": FunctionFragment; - "getPendingGovernor()": FunctionFragment; + "getPendingAdmin()": FunctionFragment; "getPriorityQueueSize()": FunctionFragment; "getPriorityTxMaxGasLimit()": FunctionFragment; "getProtocolVersion()": FunctionFragment; + "getPubdataPricingMode()": FunctionFragment; + "getStateTransitionManager()": FunctionFragment; "getTotalBatchesCommitted()": FunctionFragment; "getTotalBatchesExecuted()": FunctionFragment; "getTotalBatchesVerified()": FunctionFragment; @@ -60,18 +70,24 @@ interface IZkSyncInterface extends ethers.utils.Interface { "l2TransactionBaseCost(uint256,uint256,uint256)": FunctionFragment; "priorityQueueFrontOperation()": FunctionFragment; "proveBatches(tuple,tuple[],tuple)": FunctionFragment; + "proveBatchesSharedBridge(uint256,tuple,tuple[],tuple)": FunctionFragment; "proveL1ToL2TransactionStatus(bytes32,uint256,uint256,uint16,bytes32[],uint8)": FunctionFragment; "proveL2LogInclusion(uint256,uint256,tuple,bytes32[])": FunctionFragment; "proveL2MessageInclusion(uint256,uint256,tuple,bytes32[])": FunctionFragment; "requestL2Transaction(address,uint256,bytes,uint256,uint256,bytes[],address)": FunctionFragment; "revertBatches(uint256)": FunctionFragment; + "revertBatchesSharedBridge(uint256,uint256)": FunctionFragment; "setPendingAdmin(address)": FunctionFragment; - "setPendingGovernor(address)": FunctionFragment; "setPorterAvailability(bool)": FunctionFragment; "setPriorityTxMaxGasLimit(uint256)": FunctionFragment; + "setTokenMultiplier(uint128,uint128)": FunctionFragment; + "setTransactionFilterer(address)": FunctionFragment; "setValidator(address,bool)": FunctionFragment; + "setValidiumMode(uint8)": FunctionFragment; "storedBatchHash(uint256)": FunctionFragment; + "transferEthToSharedBridge()": FunctionFragment; "unfreezeDiamond()": FunctionFragment; + "upgradeChainFromVersion(uint256,tuple)": FunctionFragment; }; encodeFunctionData( @@ -79,9 +95,42 @@ interface IZkSyncInterface extends ethers.utils.Interface { values?: undefined ): string; encodeFunctionData( - functionFragment: "acceptGovernor", + functionFragment: "baseTokenGasPriceMultiplierDenominator", values?: undefined ): string; + encodeFunctionData( + functionFragment: "baseTokenGasPriceMultiplierNominator", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "bridgehubRequestL2Transaction", + values: [ + { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + } + ] + ): string; + encodeFunctionData( + functionFragment: "changeFeeParams", + values: [ + { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + } + ] + ): string; encodeFunctionData( functionFragment: "commitBatches", values: [ @@ -105,7 +154,35 @@ interface IZkSyncInterface extends ethers.utils.Interface { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; + }[] + ] + ): string; + encodeFunctionData( + functionFragment: "commitBatchesSharedBridge", + values: [ + BigNumberish, + { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; }[] ] ): string; @@ -124,6 +201,22 @@ interface IZkSyncInterface extends ethers.utils.Interface { }[] ] ): string; + encodeFunctionData( + functionFragment: "executeBatchesSharedBridge", + values: [ + BigNumberish, + { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[] + ] + ): string; encodeFunctionData( functionFragment: "executeUpgrade", values: [ @@ -160,12 +253,21 @@ interface IZkSyncInterface extends ethers.utils.Interface { functionFragment: "freezeDiamond", values?: undefined ): string; + encodeFunctionData(functionFragment: "getAdmin", values?: undefined): string; encodeFunctionData( - functionFragment: "getFirstUnprocessedPriorityTx", + functionFragment: "getBaseToken", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getBaseTokenBridge", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getBridgehub", values?: undefined ): string; encodeFunctionData( - functionFragment: "getGovernor", + functionFragment: "getFirstUnprocessedPriorityTx", values?: undefined ): string; encodeFunctionData( @@ -186,7 +288,7 @@ interface IZkSyncInterface extends ethers.utils.Interface { ): string; encodeFunctionData(functionFragment: "getName", values?: undefined): string; encodeFunctionData( - functionFragment: "getPendingGovernor", + functionFragment: "getPendingAdmin", values?: undefined ): string; encodeFunctionData( @@ -201,6 +303,14 @@ interface IZkSyncInterface extends ethers.utils.Interface { functionFragment: "getProtocolVersion", values?: undefined ): string; + encodeFunctionData( + functionFragment: "getPubdataPricingMode", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getStateTransitionManager", + values?: undefined + ): string; encodeFunctionData( functionFragment: "getTotalBatchesCommitted", values?: undefined @@ -283,6 +393,36 @@ interface IZkSyncInterface extends ethers.utils.Interface { } ] ): string; + encodeFunctionData( + functionFragment: "proveBatchesSharedBridge", + values: [ + BigNumberish, + { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + } + ] + ): string; encodeFunctionData( functionFragment: "proveL1ToL2TransactionStatus", values: [ @@ -336,11 +476,11 @@ interface IZkSyncInterface extends ethers.utils.Interface { values: [BigNumberish] ): string; encodeFunctionData( - functionFragment: "setPendingAdmin", - values: [string] + functionFragment: "revertBatchesSharedBridge", + values: [BigNumberish, BigNumberish] ): string; encodeFunctionData( - functionFragment: "setPendingGovernor", + functionFragment: "setPendingAdmin", values: [string] ): string; encodeFunctionData( @@ -351,35 +491,87 @@ interface IZkSyncInterface extends ethers.utils.Interface { functionFragment: "setPriorityTxMaxGasLimit", values: [BigNumberish] ): string; + encodeFunctionData( + functionFragment: "setTokenMultiplier", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setTransactionFilterer", + values: [string] + ): string; encodeFunctionData( functionFragment: "setValidator", values: [string, boolean] ): string; + encodeFunctionData( + functionFragment: "setValidiumMode", + values: [BigNumberish] + ): string; encodeFunctionData( functionFragment: "storedBatchHash", values: [BigNumberish] ): string; + encodeFunctionData( + functionFragment: "transferEthToSharedBridge", + values?: undefined + ): string; encodeFunctionData( functionFragment: "unfreezeDiamond", values?: undefined ): string; + encodeFunctionData( + functionFragment: "upgradeChainFromVersion", + values: [ + BigNumberish, + { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + } + ] + ): string; decodeFunctionResult( functionFragment: "acceptAdmin", data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "acceptGovernor", + functionFragment: "baseTokenGasPriceMultiplierDenominator", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "baseTokenGasPriceMultiplierNominator", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "bridgehubRequestL2Transaction", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "changeFeeParams", data: BytesLike ): Result; decodeFunctionResult( functionFragment: "commitBatches", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "commitBatchesSharedBridge", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "executeBatches", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "executeBatchesSharedBridge", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "executeUpgrade", data: BytesLike @@ -405,12 +597,21 @@ interface IZkSyncInterface extends ethers.utils.Interface { functionFragment: "freezeDiamond", data: BytesLike ): Result; + decodeFunctionResult(functionFragment: "getAdmin", data: BytesLike): Result; decodeFunctionResult( - functionFragment: "getFirstUnprocessedPriorityTx", + functionFragment: "getBaseToken", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getBaseTokenBridge", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getBridgehub", data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "getGovernor", + functionFragment: "getFirstUnprocessedPriorityTx", data: BytesLike ): Result; decodeFunctionResult( @@ -431,7 +632,7 @@ interface IZkSyncInterface extends ethers.utils.Interface { ): Result; decodeFunctionResult(functionFragment: "getName", data: BytesLike): Result; decodeFunctionResult( - functionFragment: "getPendingGovernor", + functionFragment: "getPendingAdmin", data: BytesLike ): Result; decodeFunctionResult( @@ -446,6 +647,14 @@ interface IZkSyncInterface extends ethers.utils.Interface { functionFragment: "getProtocolVersion", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "getPubdataPricingMode", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getStateTransitionManager", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "getTotalBatchesCommitted", data: BytesLike @@ -506,6 +715,10 @@ interface IZkSyncInterface extends ethers.utils.Interface { functionFragment: "proveBatches", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "proveBatchesSharedBridge", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "proveL1ToL2TransactionStatus", data: BytesLike @@ -527,11 +740,11 @@ interface IZkSyncInterface extends ethers.utils.Interface { data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "setPendingAdmin", + functionFragment: "revertBatchesSharedBridge", data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "setPendingGovernor", + functionFragment: "setPendingAdmin", data: BytesLike ): Result; decodeFunctionResult( @@ -542,18 +755,38 @@ interface IZkSyncInterface extends ethers.utils.Interface { functionFragment: "setPriorityTxMaxGasLimit", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "setTokenMultiplier", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setTransactionFilterer", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "setValidator", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "setValidiumMode", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "storedBatchHash", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "transferEthToSharedBridge", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "unfreezeDiamond", data: BytesLike ): Result; + decodeFunctionResult( + functionFragment: "upgradeChainFromVersion", + data: BytesLike + ): Result; events: { "BlockCommit(uint256,bytes32,bytes32)": EventFragment; @@ -565,13 +798,16 @@ interface IZkSyncInterface extends ethers.utils.Interface { "Freeze()": EventFragment; "IsPorterAvailableStatusUpdate(bool)": EventFragment; "NewAdmin(address,address)": EventFragment; - "NewGovernor(address,address)": EventFragment; + "NewBaseTokenMultiplier(uint128,uint128,uint128,uint128)": EventFragment; + "NewFeeParams(tuple,tuple)": EventFragment; "NewPendingAdmin(address,address)": EventFragment; - "NewPendingGovernor(address,address)": EventFragment; "NewPriorityRequest(uint256,bytes32,uint64,tuple,bytes[])": EventFragment; "NewPriorityTxMaxGasLimit(uint256,uint256)": EventFragment; + "NewTransactionFilterer(address,address)": EventFragment; + "ProposeTransparentUpgrade(tuple,uint256,bytes32)": EventFragment; "Unfreeze()": EventFragment; "ValidatorStatusUpdate(address,bool)": EventFragment; + "ValidiumModeStatusUpdate(uint8)": EventFragment; }; getEvent(nameOrSignatureOrTopic: "BlockCommit"): EventFragment; @@ -585,16 +821,19 @@ interface IZkSyncInterface extends ethers.utils.Interface { nameOrSignatureOrTopic: "IsPorterAvailableStatusUpdate" ): EventFragment; getEvent(nameOrSignatureOrTopic: "NewAdmin"): EventFragment; - getEvent(nameOrSignatureOrTopic: "NewGovernor"): EventFragment; + getEvent(nameOrSignatureOrTopic: "NewBaseTokenMultiplier"): EventFragment; + getEvent(nameOrSignatureOrTopic: "NewFeeParams"): EventFragment; getEvent(nameOrSignatureOrTopic: "NewPendingAdmin"): EventFragment; - getEvent(nameOrSignatureOrTopic: "NewPendingGovernor"): EventFragment; getEvent(nameOrSignatureOrTopic: "NewPriorityRequest"): EventFragment; getEvent(nameOrSignatureOrTopic: "NewPriorityTxMaxGasLimit"): EventFragment; + getEvent(nameOrSignatureOrTopic: "NewTransactionFilterer"): EventFragment; + getEvent(nameOrSignatureOrTopic: "ProposeTransparentUpgrade"): EventFragment; getEvent(nameOrSignatureOrTopic: "Unfreeze"): EventFragment; getEvent(nameOrSignatureOrTopic: "ValidatorStatusUpdate"): EventFragment; + getEvent(nameOrSignatureOrTopic: "ValidiumModeStatusUpdate"): EventFragment; } -export class IZkSync extends Contract { +export class IZkSyncStateTransition extends Contract { connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; @@ -605,16 +844,86 @@ export class IZkSync extends Contract { removeAllListeners(eventName: EventFilter | string): this; removeListener(eventName: any, listener: Listener): this; - interface: IZkSyncInterface; + interface: IZkSyncStateTransitionInterface; functions: { acceptAdmin(overrides?: Overrides): Promise; "acceptAdmin()"(overrides?: Overrides): Promise; - acceptGovernor(overrides?: Overrides): Promise; + baseTokenGasPriceMultiplierDenominator(overrides?: CallOverrides): Promise<{ + 0: BigNumber; + }>; + + "baseTokenGasPriceMultiplierDenominator()"( + overrides?: CallOverrides + ): Promise<{ + 0: BigNumber; + }>; + + baseTokenGasPriceMultiplierNominator(overrides?: CallOverrides): Promise<{ + 0: BigNumber; + }>; + + "baseTokenGasPriceMultiplierNominator()"( + overrides?: CallOverrides + ): Promise<{ + 0: BigNumber; + }>; + + bridgehubRequestL2Transaction( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + "bridgehubRequestL2Transaction(tuple)"( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + changeFeeParams( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; - "acceptGovernor()"(overrides?: Overrides): Promise; + "changeFeeParams(tuple)"( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; commitBatches( _lastCommittedBatchData: { @@ -637,7 +946,7 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; @@ -663,13 +972,41 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; - executeBatches( - _batchesData: { + commitBatchesSharedBridge( + _chainId: BigNumberish, + _lastCommittedBatchData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "commitBatchesSharedBridge(uint256,tuple,tuple[])"( + _chainId: BigNumberish, + _lastCommittedBatchData: { batchNumber: BigNumberish; batchHash: BytesLike; indexRepeatedStorageChanges: BigNumberish; @@ -678,11 +1015,23 @@ export class IZkSync extends Contract { l2LogsTreeRoot: BytesLike; timestamp: BigNumberish; commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; - "executeBatches(tuple[])"( + executeBatches( _batchesData: { batchNumber: BigNumberish; batchHash: BytesLike; @@ -696,10 +1045,54 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; - executeUpgrade( - _diamondCut: { - facetCuts: { - facet: string; + "executeBatches(tuple[])"( + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + executeBatchesSharedBridge( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "executeBatchesSharedBridge(uint256,tuple[])"( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + executeUpgrade( + _diamondCut: { + facetCuts: { + facet: string; action: BigNumberish; isFreezable: boolean; selectors: BytesLike[]; @@ -794,22 +1187,46 @@ export class IZkSync extends Contract { "freezeDiamond()"(overrides?: Overrides): Promise; - getFirstUnprocessedPriorityTx(overrides?: CallOverrides): Promise<{ - 0: BigNumber; + getAdmin(overrides?: CallOverrides): Promise<{ + 0: string; }>; - "getFirstUnprocessedPriorityTx()"(overrides?: CallOverrides): Promise<{ - 0: BigNumber; + "getAdmin()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + getBaseToken(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "getBaseToken()"(overrides?: CallOverrides): Promise<{ + 0: string; }>; - getGovernor(overrides?: CallOverrides): Promise<{ + getBaseTokenBridge(overrides?: CallOverrides): Promise<{ 0: string; }>; - "getGovernor()"(overrides?: CallOverrides): Promise<{ + "getBaseTokenBridge()"(overrides?: CallOverrides): Promise<{ 0: string; }>; + getBridgehub(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "getBridgehub()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + getFirstUnprocessedPriorityTx(overrides?: CallOverrides): Promise<{ + 0: BigNumber; + }>; + + "getFirstUnprocessedPriorityTx()"(overrides?: CallOverrides): Promise<{ + 0: BigNumber; + }>; + getL2BootloaderBytecodeHash(overrides?: CallOverrides): Promise<{ 0: string; }>; @@ -852,11 +1269,11 @@ export class IZkSync extends Contract { 0: string; }>; - getPendingGovernor(overrides?: CallOverrides): Promise<{ + getPendingAdmin(overrides?: CallOverrides): Promise<{ 0: string; }>; - "getPendingGovernor()"(overrides?: CallOverrides): Promise<{ + "getPendingAdmin()"(overrides?: CallOverrides): Promise<{ 0: string; }>; @@ -884,6 +1301,22 @@ export class IZkSync extends Contract { 0: BigNumber; }>; + getPubdataPricingMode(overrides?: CallOverrides): Promise<{ + 0: number; + }>; + + "getPubdataPricingMode()"(overrides?: CallOverrides): Promise<{ + 0: number; + }>; + + getStateTransitionManager(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "getStateTransitionManager()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + getTotalBatchesCommitted(overrides?: CallOverrides): Promise<{ 0: BigNumber; }>; @@ -1018,7 +1451,7 @@ export class IZkSync extends Contract { _batchNumber: BigNumberish, overrides?: CallOverrides ): Promise<{ - hash: string; + merkleRoot: string; 0: string; }>; @@ -1026,7 +1459,7 @@ export class IZkSync extends Contract { _batchNumber: BigNumberish, overrides?: CallOverrides ): Promise<{ - hash: string; + merkleRoot: string; 0: string; }>; @@ -1126,6 +1559,64 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + proveBatchesSharedBridge( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + + "proveBatchesSharedBridge(uint256,tuple,tuple[],tuple)"( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + proveL1ToL2TransactionStatus( _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, @@ -1151,7 +1642,7 @@ export class IZkSync extends Contract { }>; proveL2LogInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -1168,7 +1659,7 @@ export class IZkSync extends Contract { }>; "proveL2LogInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -1185,7 +1676,7 @@ export class IZkSync extends Contract { }>; proveL2MessageInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -1199,7 +1690,7 @@ export class IZkSync extends Contract { }>; "proveL2MessageInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -1244,23 +1735,25 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; - setPendingAdmin( - _newPendingAdmin: string, + revertBatchesSharedBridge( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - "setPendingAdmin(address)"( - _newPendingAdmin: string, + "revertBatchesSharedBridge(uint256,uint256)"( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - setPendingGovernor( - _newPendingGovernor: string, + setPendingAdmin( + _newPendingAdmin: string, overrides?: Overrides ): Promise; - "setPendingGovernor(address)"( - _newPendingGovernor: string, + "setPendingAdmin(address)"( + _newPendingAdmin: string, overrides?: Overrides ): Promise; @@ -1284,6 +1777,28 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + setTokenMultiplier( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + "setTokenMultiplier(uint128,uint128)"( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + setTransactionFilterer( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + + "setTransactionFilterer(address)"( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + setValidator( _validator: string, _active: boolean, @@ -1296,6 +1811,16 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + setValidiumMode( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + + "setValidiumMode(uint8)"( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + storedBatchHash( _batchNumber: BigNumberish, overrides?: CallOverrides @@ -1310,18 +1835,122 @@ export class IZkSync extends Contract { 0: string; }>; + transferEthToSharedBridge( + overrides?: Overrides + ): Promise; + + "transferEthToSharedBridge()"( + overrides?: Overrides + ): Promise; + unfreezeDiamond(overrides?: Overrides): Promise; "unfreezeDiamond()"(overrides?: Overrides): Promise; + + upgradeChainFromVersion( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; + + "upgradeChainFromVersion(uint256,tuple)"( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; }; acceptAdmin(overrides?: Overrides): Promise; "acceptAdmin()"(overrides?: Overrides): Promise; - acceptGovernor(overrides?: Overrides): Promise; + baseTokenGasPriceMultiplierDenominator( + overrides?: CallOverrides + ): Promise; + + "baseTokenGasPriceMultiplierDenominator()"( + overrides?: CallOverrides + ): Promise; + + baseTokenGasPriceMultiplierNominator( + overrides?: CallOverrides + ): Promise; + + "baseTokenGasPriceMultiplierNominator()"( + overrides?: CallOverrides + ): Promise; + + bridgehubRequestL2Transaction( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + "bridgehubRequestL2Transaction(tuple)"( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + changeFeeParams( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; - "acceptGovernor()"(overrides?: Overrides): Promise; + "changeFeeParams(tuple)"( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; commitBatches( _lastCommittedBatchData: { @@ -1344,7 +1973,7 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; @@ -1370,13 +1999,14 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; - executeBatches( - _batchesData: { + commitBatchesSharedBridge( + _chainId: BigNumberish, + _lastCommittedBatchData: { batchNumber: BigNumberish; batchHash: BytesLike; indexRepeatedStorageChanges: BigNumberish; @@ -1385,12 +2015,95 @@ export class IZkSync extends Contract { l2LogsTreeRoot: BytesLike; timestamp: BigNumberish; commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; - "executeBatches(tuple[])"( - _batchesData: { + "commitBatchesSharedBridge(uint256,tuple,tuple[])"( + _chainId: BigNumberish, + _lastCommittedBatchData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + executeBatches( + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "executeBatches(tuple[])"( + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + executeBatchesSharedBridge( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "executeBatchesSharedBridge(uint256,tuple[])"( + _chainId: BigNumberish, + _batchesData: { batchNumber: BigNumberish; batchHash: BytesLike; indexRepeatedStorageChanges: BigNumberish; @@ -1485,16 +2198,28 @@ export class IZkSync extends Contract { "freezeDiamond()"(overrides?: Overrides): Promise; + getAdmin(overrides?: CallOverrides): Promise; + + "getAdmin()"(overrides?: CallOverrides): Promise; + + getBaseToken(overrides?: CallOverrides): Promise; + + "getBaseToken()"(overrides?: CallOverrides): Promise; + + getBaseTokenBridge(overrides?: CallOverrides): Promise; + + "getBaseTokenBridge()"(overrides?: CallOverrides): Promise; + + getBridgehub(overrides?: CallOverrides): Promise; + + "getBridgehub()"(overrides?: CallOverrides): Promise; + getFirstUnprocessedPriorityTx(overrides?: CallOverrides): Promise; "getFirstUnprocessedPriorityTx()"( overrides?: CallOverrides ): Promise; - getGovernor(overrides?: CallOverrides): Promise; - - "getGovernor()"(overrides?: CallOverrides): Promise; - getL2BootloaderBytecodeHash(overrides?: CallOverrides): Promise; "getL2BootloaderBytecodeHash()"(overrides?: CallOverrides): Promise; @@ -1523,9 +2248,9 @@ export class IZkSync extends Contract { "getName()"(overrides?: CallOverrides): Promise; - getPendingGovernor(overrides?: CallOverrides): Promise; + getPendingAdmin(overrides?: CallOverrides): Promise; - "getPendingGovernor()"(overrides?: CallOverrides): Promise; + "getPendingAdmin()"(overrides?: CallOverrides): Promise; getPriorityQueueSize(overrides?: CallOverrides): Promise; @@ -1539,6 +2264,14 @@ export class IZkSync extends Contract { "getProtocolVersion()"(overrides?: CallOverrides): Promise; + getPubdataPricingMode(overrides?: CallOverrides): Promise; + + "getPubdataPricingMode()"(overrides?: CallOverrides): Promise; + + getStateTransitionManager(overrides?: CallOverrides): Promise; + + "getStateTransitionManager()"(overrides?: CallOverrides): Promise; + getTotalBatchesCommitted(overrides?: CallOverrides): Promise; "getTotalBatchesCommitted()"(overrides?: CallOverrides): Promise; @@ -1723,6 +2456,64 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + proveBatchesSharedBridge( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + + "proveBatchesSharedBridge(uint256,tuple,tuple[],tuple)"( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + proveL1ToL2TransactionStatus( _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, @@ -1744,7 +2535,7 @@ export class IZkSync extends Contract { ): Promise; proveL2LogInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -1759,7 +2550,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2LogInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -1774,7 +2565,7 @@ export class IZkSync extends Contract { ): Promise; proveL2MessageInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -1786,7 +2577,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2MessageInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -1829,23 +2620,25 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; - setPendingAdmin( - _newPendingAdmin: string, + revertBatchesSharedBridge( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - "setPendingAdmin(address)"( - _newPendingAdmin: string, + "revertBatchesSharedBridge(uint256,uint256)"( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - setPendingGovernor( - _newPendingGovernor: string, + setPendingAdmin( + _newPendingAdmin: string, overrides?: Overrides ): Promise; - "setPendingGovernor(address)"( - _newPendingGovernor: string, + "setPendingAdmin(address)"( + _newPendingAdmin: string, overrides?: Overrides ): Promise; @@ -1869,6 +2662,28 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + setTokenMultiplier( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + "setTokenMultiplier(uint128,uint128)"( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + setTransactionFilterer( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + + "setTransactionFilterer(address)"( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + setValidator( _validator: string, _active: boolean, @@ -1881,6 +2696,16 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + setValidiumMode( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + + "setValidiumMode(uint8)"( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + storedBatchHash( _batchNumber: BigNumberish, overrides?: CallOverrides @@ -1891,18 +2716,122 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; + transferEthToSharedBridge( + overrides?: Overrides + ): Promise; + + "transferEthToSharedBridge()"( + overrides?: Overrides + ): Promise; + unfreezeDiamond(overrides?: Overrides): Promise; "unfreezeDiamond()"(overrides?: Overrides): Promise; + upgradeChainFromVersion( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; + + "upgradeChainFromVersion(uint256,tuple)"( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; + callStatic: { acceptAdmin(overrides?: CallOverrides): Promise; "acceptAdmin()"(overrides?: CallOverrides): Promise; - acceptGovernor(overrides?: CallOverrides): Promise; + baseTokenGasPriceMultiplierDenominator( + overrides?: CallOverrides + ): Promise; + + "baseTokenGasPriceMultiplierDenominator()"( + overrides?: CallOverrides + ): Promise; + + baseTokenGasPriceMultiplierNominator( + overrides?: CallOverrides + ): Promise; + + "baseTokenGasPriceMultiplierNominator()"( + overrides?: CallOverrides + ): Promise; + + bridgehubRequestL2Transaction( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: CallOverrides + ): Promise; + + "bridgehubRequestL2Transaction(tuple)"( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: CallOverrides + ): Promise; + + changeFeeParams( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: CallOverrides + ): Promise; - "acceptGovernor()"(overrides?: CallOverrides): Promise; + "changeFeeParams(tuple)"( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: CallOverrides + ): Promise; commitBatches( _lastCommittedBatchData: { @@ -1925,7 +2854,7 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: CallOverrides ): Promise; @@ -1951,13 +2880,41 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: CallOverrides ): Promise; - executeBatches( - _batchesData: { + commitBatchesSharedBridge( + _chainId: BigNumberish, + _lastCommittedBatchData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; + }[], + overrides?: CallOverrides + ): Promise; + + "commitBatchesSharedBridge(uint256,tuple,tuple[])"( + _chainId: BigNumberish, + _lastCommittedBatchData: { batchNumber: BigNumberish; batchHash: BytesLike; indexRepeatedStorageChanges: BigNumberish; @@ -1966,11 +2923,67 @@ export class IZkSync extends Contract { l2LogsTreeRoot: BytesLike; timestamp: BigNumberish; commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: CallOverrides ): Promise; - "executeBatches(tuple[])"( + executeBatches( + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: CallOverrides + ): Promise; + + "executeBatches(tuple[])"( + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: CallOverrides + ): Promise; + + executeBatchesSharedBridge( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: CallOverrides + ): Promise; + + "executeBatchesSharedBridge(uint256,tuple[])"( + _chainId: BigNumberish, _batchesData: { batchNumber: BigNumberish; batchHash: BytesLike; @@ -2066,6 +3079,22 @@ export class IZkSync extends Contract { "freezeDiamond()"(overrides?: CallOverrides): Promise; + getAdmin(overrides?: CallOverrides): Promise; + + "getAdmin()"(overrides?: CallOverrides): Promise; + + getBaseToken(overrides?: CallOverrides): Promise; + + "getBaseToken()"(overrides?: CallOverrides): Promise; + + getBaseTokenBridge(overrides?: CallOverrides): Promise; + + "getBaseTokenBridge()"(overrides?: CallOverrides): Promise; + + getBridgehub(overrides?: CallOverrides): Promise; + + "getBridgehub()"(overrides?: CallOverrides): Promise; + getFirstUnprocessedPriorityTx( overrides?: CallOverrides ): Promise; @@ -2074,10 +3103,6 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; - getGovernor(overrides?: CallOverrides): Promise; - - "getGovernor()"(overrides?: CallOverrides): Promise; - getL2BootloaderBytecodeHash(overrides?: CallOverrides): Promise; "getL2BootloaderBytecodeHash()"(overrides?: CallOverrides): Promise; @@ -2108,9 +3133,9 @@ export class IZkSync extends Contract { "getName()"(overrides?: CallOverrides): Promise; - getPendingGovernor(overrides?: CallOverrides): Promise; + getPendingAdmin(overrides?: CallOverrides): Promise; - "getPendingGovernor()"(overrides?: CallOverrides): Promise; + "getPendingAdmin()"(overrides?: CallOverrides): Promise; getPriorityQueueSize(overrides?: CallOverrides): Promise; @@ -2124,6 +3149,14 @@ export class IZkSync extends Contract { "getProtocolVersion()"(overrides?: CallOverrides): Promise; + getPubdataPricingMode(overrides?: CallOverrides): Promise; + + "getPubdataPricingMode()"(overrides?: CallOverrides): Promise; + + getStateTransitionManager(overrides?: CallOverrides): Promise; + + "getStateTransitionManager()"(overrides?: CallOverrides): Promise; + getTotalBatchesCommitted(overrides?: CallOverrides): Promise; "getTotalBatchesCommitted()"(overrides?: CallOverrides): Promise; @@ -2311,6 +3344,64 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; + proveBatchesSharedBridge( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: CallOverrides + ): Promise; + + "proveBatchesSharedBridge(uint256,tuple,tuple[],tuple)"( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: CallOverrides + ): Promise; + proveL1ToL2TransactionStatus( _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, @@ -2332,7 +3423,7 @@ export class IZkSync extends Contract { ): Promise; proveL2LogInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -2347,7 +3438,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2LogInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -2362,7 +3453,7 @@ export class IZkSync extends Contract { ): Promise; proveL2MessageInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -2374,7 +3465,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2MessageInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -2417,23 +3508,25 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; - setPendingAdmin( - _newPendingAdmin: string, + revertBatchesSharedBridge( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: CallOverrides ): Promise; - "setPendingAdmin(address)"( - _newPendingAdmin: string, + "revertBatchesSharedBridge(uint256,uint256)"( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: CallOverrides ): Promise; - setPendingGovernor( - _newPendingGovernor: string, + setPendingAdmin( + _newPendingAdmin: string, overrides?: CallOverrides ): Promise; - "setPendingGovernor(address)"( - _newPendingGovernor: string, + "setPendingAdmin(address)"( + _newPendingAdmin: string, overrides?: CallOverrides ): Promise; @@ -2457,6 +3550,28 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; + setTokenMultiplier( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "setTokenMultiplier(uint128,uint128)"( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: CallOverrides + ): Promise; + + setTransactionFilterer( + _transactionFilterer: string, + overrides?: CallOverrides + ): Promise; + + "setTransactionFilterer(address)"( + _transactionFilterer: string, + overrides?: CallOverrides + ): Promise; + setValidator( _validator: string, _active: boolean, @@ -2469,6 +3584,16 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; + setValidiumMode( + _validiumMode: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "setValidiumMode(uint8)"( + _validiumMode: BigNumberish, + overrides?: CallOverrides + ): Promise; + storedBatchHash( _batchNumber: BigNumberish, overrides?: CallOverrides @@ -2479,9 +3604,43 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; + transferEthToSharedBridge(overrides?: CallOverrides): Promise; + + "transferEthToSharedBridge()"(overrides?: CallOverrides): Promise; + unfreezeDiamond(overrides?: CallOverrides): Promise; "unfreezeDiamond()"(overrides?: CallOverrides): Promise; + + upgradeChainFromVersion( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: CallOverrides + ): Promise; + + "upgradeChainFromVersion(uint256,tuple)"( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: CallOverrides + ): Promise; }; filters: { @@ -2518,21 +3677,20 @@ export class IZkSync extends Contract { NewAdmin(oldAdmin: string | null, newAdmin: string | null): EventFilter; - NewGovernor( - oldGovernor: string | null, - newGovernor: string | null + NewBaseTokenMultiplier( + oldNominator: null, + oldDenominator: null, + newNominator: null, + newDenominator: null ): EventFilter; + NewFeeParams(oldFeeParams: null, newFeeParams: null): EventFilter; + NewPendingAdmin( oldPendingAdmin: string | null, newPendingAdmin: string | null ): EventFilter; - NewPendingGovernor( - oldPendingGovernor: string | null, - newPendingGovernor: string | null - ): EventFilter; - NewPriorityRequest( txId: null, txHash: null, @@ -2546,12 +3704,25 @@ export class IZkSync extends Contract { newPriorityTxMaxGasLimit: null ): EventFilter; + NewTransactionFilterer( + oldTransactionFilterer: null, + newTransactionFilterer: null + ): EventFilter; + + ProposeTransparentUpgrade( + diamondCut: null, + proposalId: BigNumberish | null, + proposalSalt: null + ): EventFilter; + Unfreeze(): EventFilter; ValidatorStatusUpdate( validatorAddress: string | null, isActive: null ): EventFilter; + + ValidiumModeStatusUpdate(validiumMode: null): EventFilter; }; estimateGas: { @@ -2559,9 +3730,75 @@ export class IZkSync extends Contract { "acceptAdmin()"(overrides?: Overrides): Promise; - acceptGovernor(overrides?: Overrides): Promise; + baseTokenGasPriceMultiplierDenominator( + overrides?: CallOverrides + ): Promise; - "acceptGovernor()"(overrides?: Overrides): Promise; + "baseTokenGasPriceMultiplierDenominator()"( + overrides?: CallOverrides + ): Promise; + + baseTokenGasPriceMultiplierNominator( + overrides?: CallOverrides + ): Promise; + + "baseTokenGasPriceMultiplierNominator()"( + overrides?: CallOverrides + ): Promise; + + bridgehubRequestL2Transaction( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + "bridgehubRequestL2Transaction(tuple)"( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; + + changeFeeParams( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; + + "changeFeeParams(tuple)"( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; commitBatches( _lastCommittedBatchData: { @@ -2584,7 +3821,7 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; @@ -2610,7 +3847,61 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + commitBatchesSharedBridge( + _chainId: BigNumberish, + _lastCommittedBatchData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "commitBatchesSharedBridge(uint256,tuple,tuple[])"( + _chainId: BigNumberish, + _lastCommittedBatchData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; @@ -2643,6 +3934,36 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + executeBatchesSharedBridge( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "executeBatchesSharedBridge(uint256,tuple[])"( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + executeUpgrade( _diamondCut: { facetCuts: { @@ -2721,6 +4042,22 @@ export class IZkSync extends Contract { "freezeDiamond()"(overrides?: Overrides): Promise; + getAdmin(overrides?: CallOverrides): Promise; + + "getAdmin()"(overrides?: CallOverrides): Promise; + + getBaseToken(overrides?: CallOverrides): Promise; + + "getBaseToken()"(overrides?: CallOverrides): Promise; + + getBaseTokenBridge(overrides?: CallOverrides): Promise; + + "getBaseTokenBridge()"(overrides?: CallOverrides): Promise; + + getBridgehub(overrides?: CallOverrides): Promise; + + "getBridgehub()"(overrides?: CallOverrides): Promise; + getFirstUnprocessedPriorityTx( overrides?: CallOverrides ): Promise; @@ -2729,10 +4066,6 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; - getGovernor(overrides?: CallOverrides): Promise; - - "getGovernor()"(overrides?: CallOverrides): Promise; - getL2BootloaderBytecodeHash(overrides?: CallOverrides): Promise; "getL2BootloaderBytecodeHash()"( @@ -2767,9 +4100,9 @@ export class IZkSync extends Contract { "getName()"(overrides?: CallOverrides): Promise; - getPendingGovernor(overrides?: CallOverrides): Promise; + getPendingAdmin(overrides?: CallOverrides): Promise; - "getPendingGovernor()"(overrides?: CallOverrides): Promise; + "getPendingAdmin()"(overrides?: CallOverrides): Promise; getPriorityQueueSize(overrides?: CallOverrides): Promise; @@ -2783,6 +4116,16 @@ export class IZkSync extends Contract { "getProtocolVersion()"(overrides?: CallOverrides): Promise; + getPubdataPricingMode(overrides?: CallOverrides): Promise; + + "getPubdataPricingMode()"(overrides?: CallOverrides): Promise; + + getStateTransitionManager(overrides?: CallOverrides): Promise; + + "getStateTransitionManager()"( + overrides?: CallOverrides + ): Promise; + getTotalBatchesCommitted(overrides?: CallOverrides): Promise; "getTotalBatchesCommitted()"(overrides?: CallOverrides): Promise; @@ -2939,6 +4282,64 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + proveBatchesSharedBridge( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + + "proveBatchesSharedBridge(uint256,tuple,tuple[],tuple)"( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + proveL1ToL2TransactionStatus( _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, @@ -2960,7 +4361,7 @@ export class IZkSync extends Contract { ): Promise; proveL2LogInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -2975,7 +4376,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2LogInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -2990,7 +4391,7 @@ export class IZkSync extends Contract { ): Promise; proveL2MessageInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -3002,7 +4403,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2MessageInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -3045,23 +4446,25 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; - setPendingAdmin( - _newPendingAdmin: string, + revertBatchesSharedBridge( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - "setPendingAdmin(address)"( - _newPendingAdmin: string, + "revertBatchesSharedBridge(uint256,uint256)"( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - setPendingGovernor( - _newPendingGovernor: string, + setPendingAdmin( + _newPendingAdmin: string, overrides?: Overrides ): Promise; - "setPendingGovernor(address)"( - _newPendingGovernor: string, + "setPendingAdmin(address)"( + _newPendingAdmin: string, overrides?: Overrides ): Promise; @@ -3085,6 +4488,28 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + setTokenMultiplier( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + "setTokenMultiplier(uint128,uint128)"( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + setTransactionFilterer( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + + "setTransactionFilterer(address)"( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + setValidator( _validator: string, _active: boolean, @@ -3097,29 +4522,139 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; - storedBatchHash( - _batchNumber: BigNumberish, + setValidiumMode( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + + "setValidiumMode(uint8)"( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + + storedBatchHash( + _batchNumber: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "storedBatchHash(uint256)"( + _batchNumber: BigNumberish, + overrides?: CallOverrides + ): Promise; + + transferEthToSharedBridge(overrides?: Overrides): Promise; + + "transferEthToSharedBridge()"(overrides?: Overrides): Promise; + + unfreezeDiamond(overrides?: Overrides): Promise; + + "unfreezeDiamond()"(overrides?: Overrides): Promise; + + upgradeChainFromVersion( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; + + "upgradeChainFromVersion(uint256,tuple)"( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; + }; + + populateTransaction: { + acceptAdmin(overrides?: Overrides): Promise; + + "acceptAdmin()"(overrides?: Overrides): Promise; + + baseTokenGasPriceMultiplierDenominator( overrides?: CallOverrides - ): Promise; + ): Promise; - "storedBatchHash(uint256)"( - _batchNumber: BigNumberish, + "baseTokenGasPriceMultiplierDenominator()"( overrides?: CallOverrides - ): Promise; + ): Promise; - unfreezeDiamond(overrides?: Overrides): Promise; + baseTokenGasPriceMultiplierNominator( + overrides?: CallOverrides + ): Promise; - "unfreezeDiamond()"(overrides?: Overrides): Promise; - }; + "baseTokenGasPriceMultiplierNominator()"( + overrides?: CallOverrides + ): Promise; - populateTransaction: { - acceptAdmin(overrides?: Overrides): Promise; + bridgehubRequestL2Transaction( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; - "acceptAdmin()"(overrides?: Overrides): Promise; + "bridgehubRequestL2Transaction(tuple)"( + _request: { + sender: string; + contractL2: string; + mintValue: BigNumberish; + l2Value: BigNumberish; + l2Calldata: BytesLike; + l2GasLimit: BigNumberish; + l2GasPerPubdataByteLimit: BigNumberish; + factoryDeps: BytesLike[]; + refundRecipient: string; + }, + overrides?: PayableOverrides + ): Promise; - acceptGovernor(overrides?: Overrides): Promise; + changeFeeParams( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; - "acceptGovernor()"(overrides?: Overrides): Promise; + "changeFeeParams(tuple)"( + _newFeeParams: { + pubdataPricingMode: BigNumberish; + batchOverheadL1Gas: BigNumberish; + maxPubdataPerBatch: BigNumberish; + maxL2GasPerBatch: BigNumberish; + priorityTxMaxPubdata: BigNumberish; + minimalL2GasPrice: BigNumberish; + }, + overrides?: Overrides + ): Promise; commitBatches( _lastCommittedBatchData: { @@ -3142,7 +4677,7 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; @@ -3168,7 +4703,61 @@ export class IZkSync extends Contract { bootloaderHeapInitialContentsHash: BytesLike; eventsQueueStateHash: BytesLike; systemLogs: BytesLike; - totalL2ToL1Pubdata: BytesLike; + pubdataCommitments: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + commitBatchesSharedBridge( + _chainId: BigNumberish, + _lastCommittedBatchData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "commitBatchesSharedBridge(uint256,tuple,tuple[])"( + _chainId: BigNumberish, + _lastCommittedBatchData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _newBatchesData: { + batchNumber: BigNumberish; + timestamp: BigNumberish; + indexRepeatedStorageChanges: BigNumberish; + newStateRoot: BytesLike; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + bootloaderHeapInitialContentsHash: BytesLike; + eventsQueueStateHash: BytesLike; + systemLogs: BytesLike; + pubdataCommitments: BytesLike; }[], overrides?: Overrides ): Promise; @@ -3201,6 +4790,36 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + executeBatchesSharedBridge( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + + "executeBatchesSharedBridge(uint256,tuple[])"( + _chainId: BigNumberish, + _batchesData: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + overrides?: Overrides + ): Promise; + executeUpgrade( _diamondCut: { facetCuts: { @@ -3281,17 +4900,33 @@ export class IZkSync extends Contract { "freezeDiamond()"(overrides?: Overrides): Promise; - getFirstUnprocessedPriorityTx( + getAdmin(overrides?: CallOverrides): Promise; + + "getAdmin()"(overrides?: CallOverrides): Promise; + + getBaseToken(overrides?: CallOverrides): Promise; + + "getBaseToken()"(overrides?: CallOverrides): Promise; + + getBaseTokenBridge( overrides?: CallOverrides ): Promise; - "getFirstUnprocessedPriorityTx()"( + "getBaseTokenBridge()"( overrides?: CallOverrides ): Promise; - getGovernor(overrides?: CallOverrides): Promise; + getBridgehub(overrides?: CallOverrides): Promise; + + "getBridgehub()"(overrides?: CallOverrides): Promise; + + getFirstUnprocessedPriorityTx( + overrides?: CallOverrides + ): Promise; - "getGovernor()"(overrides?: CallOverrides): Promise; + "getFirstUnprocessedPriorityTx()"( + overrides?: CallOverrides + ): Promise; getL2BootloaderBytecodeHash( overrides?: CallOverrides @@ -3329,11 +4964,9 @@ export class IZkSync extends Contract { "getName()"(overrides?: CallOverrides): Promise; - getPendingGovernor( - overrides?: CallOverrides - ): Promise; + getPendingAdmin(overrides?: CallOverrides): Promise; - "getPendingGovernor()"( + "getPendingAdmin()"( overrides?: CallOverrides ): Promise; @@ -3361,6 +4994,22 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; + getPubdataPricingMode( + overrides?: CallOverrides + ): Promise; + + "getPubdataPricingMode()"( + overrides?: CallOverrides + ): Promise; + + getStateTransitionManager( + overrides?: CallOverrides + ): Promise; + + "getStateTransitionManager()"( + overrides?: CallOverrides + ): Promise; + getTotalBatchesCommitted( overrides?: CallOverrides ): Promise; @@ -3541,6 +5190,64 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + proveBatchesSharedBridge( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + + "proveBatchesSharedBridge(uint256,tuple,tuple[],tuple)"( + _chainId: BigNumberish, + _prevBatch: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }, + _committedBatches: { + batchNumber: BigNumberish; + batchHash: BytesLike; + indexRepeatedStorageChanges: BigNumberish; + numberOfLayer1Txs: BigNumberish; + priorityOperationsHash: BytesLike; + l2LogsTreeRoot: BytesLike; + timestamp: BigNumberish; + commitment: BytesLike; + }[], + _proof: { + recursiveAggregationInput: BigNumberish[]; + serializedProof: BigNumberish[]; + }, + overrides?: Overrides + ): Promise; + proveL1ToL2TransactionStatus( _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, @@ -3562,7 +5269,7 @@ export class IZkSync extends Contract { ): Promise; proveL2LogInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -3577,7 +5284,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2LogInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _log: { l2ShardId: BigNumberish; @@ -3592,7 +5299,7 @@ export class IZkSync extends Contract { ): Promise; proveL2MessageInclusion( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -3604,7 +5311,7 @@ export class IZkSync extends Contract { ): Promise; "proveL2MessageInclusion(uint256,uint256,tuple,bytes32[])"( - _l2BatchNumber: BigNumberish, + _batchNumber: BigNumberish, _index: BigNumberish, _message: { txNumberInBatch: BigNumberish; @@ -3647,23 +5354,25 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; - setPendingAdmin( - _newPendingAdmin: string, + revertBatchesSharedBridge( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - "setPendingAdmin(address)"( - _newPendingAdmin: string, + "revertBatchesSharedBridge(uint256,uint256)"( + _chainId: BigNumberish, + _newLastBatch: BigNumberish, overrides?: Overrides ): Promise; - setPendingGovernor( - _newPendingGovernor: string, + setPendingAdmin( + _newPendingAdmin: string, overrides?: Overrides ): Promise; - "setPendingGovernor(address)"( - _newPendingGovernor: string, + "setPendingAdmin(address)"( + _newPendingAdmin: string, overrides?: Overrides ): Promise; @@ -3687,6 +5396,28 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + setTokenMultiplier( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + "setTokenMultiplier(uint128,uint128)"( + _nominator: BigNumberish, + _denominator: BigNumberish, + overrides?: Overrides + ): Promise; + + setTransactionFilterer( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + + "setTransactionFilterer(address)"( + _transactionFilterer: string, + overrides?: Overrides + ): Promise; + setValidator( _validator: string, _active: boolean, @@ -3699,6 +5430,16 @@ export class IZkSync extends Contract { overrides?: Overrides ): Promise; + setValidiumMode( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + + "setValidiumMode(uint8)"( + _validiumMode: BigNumberish, + overrides?: Overrides + ): Promise; + storedBatchHash( _batchNumber: BigNumberish, overrides?: CallOverrides @@ -3709,8 +5450,46 @@ export class IZkSync extends Contract { overrides?: CallOverrides ): Promise; + transferEthToSharedBridge( + overrides?: Overrides + ): Promise; + + "transferEthToSharedBridge()"( + overrides?: Overrides + ): Promise; + unfreezeDiamond(overrides?: Overrides): Promise; "unfreezeDiamond()"(overrides?: Overrides): Promise; + + upgradeChainFromVersion( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; + + "upgradeChainFromVersion(uint256,tuple)"( + _protocolVersion: BigNumberish, + _cutData: { + facetCuts: { + facet: string; + action: BigNumberish; + isFreezable: boolean; + selectors: BytesLike[]; + }[]; + initAddress: string; + initCalldata: BytesLike; + }, + overrides?: Overrides + ): Promise; }; } diff --git a/src/typechain/IZkSyncFactory.ts b/src/typechain/IZkSyncStateTransitionFactory.ts similarity index 63% rename from src/typechain/IZkSyncFactory.ts rename to src/typechain/IZkSyncStateTransitionFactory.ts index 06214459..aa175388 100644 --- a/src/typechain/IZkSyncFactory.ts +++ b/src/typechain/IZkSyncStateTransitionFactory.ts @@ -5,14 +5,18 @@ import { Contract, Signer } from "ethers"; import { Provider } from "@ethersproject/providers"; -import type { IZkSync } from "./IZkSync"; +import type { IZkSyncStateTransition } from "./IZkSyncStateTransition"; -export class IZkSyncFactory { +export class IZkSyncStateTransitionFactory { static connect( address: string, signerOrProvider: Signer | Provider - ): IZkSync { - return new Contract(address, _abi, signerOrProvider) as IZkSync; + ): IZkSyncStateTransition { + return new Contract( + address, + _abi, + signerOrProvider + ) as IZkSyncStateTransition; } } @@ -224,38 +228,114 @@ const _abi = [ anonymous: false, inputs: [ { - indexed: true, - internalType: "address", - name: "oldGovernor", - type: "address", + indexed: false, + internalType: "uint128", + name: "oldNominator", + type: "uint128", }, { - indexed: true, - internalType: "address", - name: "newGovernor", - type: "address", + indexed: false, + internalType: "uint128", + name: "oldDenominator", + type: "uint128", + }, + { + indexed: false, + internalType: "uint128", + name: "newNominator", + type: "uint128", + }, + { + indexed: false, + internalType: "uint128", + name: "newDenominator", + type: "uint128", }, ], - name: "NewGovernor", + name: "NewBaseTokenMultiplier", type: "event", }, { anonymous: false, inputs: [ { - indexed: true, - internalType: "address", - name: "oldPendingAdmin", - type: "address", + components: [ + { + internalType: "enum PubdataPricingMode", + name: "pubdataPricingMode", + type: "uint8", + }, + { + internalType: "uint32", + name: "batchOverheadL1Gas", + type: "uint32", + }, + { + internalType: "uint32", + name: "maxPubdataPerBatch", + type: "uint32", + }, + { + internalType: "uint32", + name: "maxL2GasPerBatch", + type: "uint32", + }, + { + internalType: "uint32", + name: "priorityTxMaxPubdata", + type: "uint32", + }, + { + internalType: "uint64", + name: "minimalL2GasPrice", + type: "uint64", + }, + ], + indexed: false, + internalType: "struct FeeParams", + name: "oldFeeParams", + type: "tuple", }, { - indexed: true, - internalType: "address", - name: "newPendingAdmin", - type: "address", + components: [ + { + internalType: "enum PubdataPricingMode", + name: "pubdataPricingMode", + type: "uint8", + }, + { + internalType: "uint32", + name: "batchOverheadL1Gas", + type: "uint32", + }, + { + internalType: "uint32", + name: "maxPubdataPerBatch", + type: "uint32", + }, + { + internalType: "uint32", + name: "maxL2GasPerBatch", + type: "uint32", + }, + { + internalType: "uint32", + name: "priorityTxMaxPubdata", + type: "uint32", + }, + { + internalType: "uint64", + name: "minimalL2GasPrice", + type: "uint64", + }, + ], + indexed: false, + internalType: "struct FeeParams", + name: "newFeeParams", + type: "tuple", }, ], - name: "NewPendingAdmin", + name: "NewFeeParams", type: "event", }, { @@ -264,17 +344,17 @@ const _abi = [ { indexed: true, internalType: "address", - name: "oldPendingGovernor", + name: "oldPendingAdmin", type: "address", }, { indexed: true, internalType: "address", - name: "newPendingGovernor", + name: "newPendingAdmin", type: "address", }, ], - name: "NewPendingGovernor", + name: "NewPendingAdmin", type: "event", }, { @@ -382,7 +462,7 @@ const _abi = [ }, ], indexed: false, - internalType: "struct IMailbox.L2CanonicalTransaction", + internalType: "struct L2CanonicalTransaction", name: "transaction", type: "tuple", }, @@ -415,6 +495,89 @@ const _abi = [ name: "NewPriorityTxMaxGasLimit", type: "event", }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "oldTransactionFilterer", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "newTransactionFilterer", + type: "address", + }, + ], + name: "NewTransactionFilterer", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + components: [ + { + components: [ + { + internalType: "address", + name: "facet", + type: "address", + }, + { + internalType: "enum Diamond.Action", + name: "action", + type: "uint8", + }, + { + internalType: "bool", + name: "isFreezable", + type: "bool", + }, + { + internalType: "bytes4[]", + name: "selectors", + type: "bytes4[]", + }, + ], + internalType: "struct Diamond.FacetCut[]", + name: "facetCuts", + type: "tuple[]", + }, + { + internalType: "address", + name: "initAddress", + type: "address", + }, + { + internalType: "bytes", + name: "initCalldata", + type: "bytes", + }, + ], + indexed: false, + internalType: "struct Diamond.DiamondCutData", + name: "diamondCut", + type: "tuple", + }, + { + indexed: true, + internalType: "uint256", + name: "proposalId", + type: "uint256", + }, + { + indexed: false, + internalType: "bytes32", + name: "proposalSalt", + type: "bytes32", + }, + ], + name: "ProposeTransparentUpgrade", + type: "event", + }, { anonymous: false, inputs: [], @@ -440,6 +603,19 @@ const _abi = [ name: "ValidatorStatusUpdate", type: "event", }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "enum PubdataPricingMode", + name: "validiumMode", + type: "uint8", + }, + ], + name: "ValidiumModeStatusUpdate", + type: "event", + }, { inputs: [], name: "acceptAdmin", @@ -449,7 +625,137 @@ const _abi = [ }, { inputs: [], - name: "acceptGovernor", + name: "baseTokenGasPriceMultiplierDenominator", + outputs: [ + { + internalType: "uint128", + name: "", + type: "uint128", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "baseTokenGasPriceMultiplierNominator", + outputs: [ + { + internalType: "uint128", + name: "", + type: "uint128", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "address", + name: "sender", + type: "address", + }, + { + internalType: "address", + name: "contractL2", + type: "address", + }, + { + internalType: "uint256", + name: "mintValue", + type: "uint256", + }, + { + internalType: "uint256", + name: "l2Value", + type: "uint256", + }, + { + internalType: "bytes", + name: "l2Calldata", + type: "bytes", + }, + { + internalType: "uint256", + name: "l2GasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "l2GasPerPubdataByteLimit", + type: "uint256", + }, + { + internalType: "bytes[]", + name: "factoryDeps", + type: "bytes[]", + }, + { + internalType: "address", + name: "refundRecipient", + type: "address", + }, + ], + internalType: "struct BridgehubL2TransactionRequest", + name: "_request", + type: "tuple", + }, + ], + name: "bridgehubRequestL2Transaction", + outputs: [ + { + internalType: "bytes32", + name: "canonicalTxHash", + type: "bytes32", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { + internalType: "enum PubdataPricingMode", + name: "pubdataPricingMode", + type: "uint8", + }, + { + internalType: "uint32", + name: "batchOverheadL1Gas", + type: "uint32", + }, + { + internalType: "uint32", + name: "maxPubdataPerBatch", + type: "uint32", + }, + { + internalType: "uint32", + name: "maxL2GasPerBatch", + type: "uint32", + }, + { + internalType: "uint32", + name: "priorityTxMaxPubdata", + type: "uint32", + }, + { + internalType: "uint64", + name: "minimalL2GasPrice", + type: "uint64", + }, + ], + internalType: "struct FeeParams", + name: "_newFeeParams", + type: "tuple", + }, + ], + name: "changeFeeParams", outputs: [], stateMutability: "nonpayable", type: "function", @@ -552,7 +858,7 @@ const _abi = [ }, { internalType: "bytes", - name: "totalL2ToL1Pubdata", + name: "pubdataCommitments", type: "bytes", }, ], @@ -566,6 +872,123 @@ const _abi = [ stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + components: [ + { + internalType: "uint64", + name: "batchNumber", + type: "uint64", + }, + { + internalType: "bytes32", + name: "batchHash", + type: "bytes32", + }, + { + internalType: "uint64", + name: "indexRepeatedStorageChanges", + type: "uint64", + }, + { + internalType: "uint256", + name: "numberOfLayer1Txs", + type: "uint256", + }, + { + internalType: "bytes32", + name: "priorityOperationsHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "l2LogsTreeRoot", + type: "bytes32", + }, + { + internalType: "uint256", + name: "timestamp", + type: "uint256", + }, + { + internalType: "bytes32", + name: "commitment", + type: "bytes32", + }, + ], + internalType: "struct IExecutor.StoredBatchInfo", + name: "_lastCommittedBatchData", + type: "tuple", + }, + { + components: [ + { + internalType: "uint64", + name: "batchNumber", + type: "uint64", + }, + { + internalType: "uint64", + name: "timestamp", + type: "uint64", + }, + { + internalType: "uint64", + name: "indexRepeatedStorageChanges", + type: "uint64", + }, + { + internalType: "bytes32", + name: "newStateRoot", + type: "bytes32", + }, + { + internalType: "uint256", + name: "numberOfLayer1Txs", + type: "uint256", + }, + { + internalType: "bytes32", + name: "priorityOperationsHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "bootloaderHeapInitialContentsHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "eventsQueueStateHash", + type: "bytes32", + }, + { + internalType: "bytes", + name: "systemLogs", + type: "bytes", + }, + { + internalType: "bytes", + name: "pubdataCommitments", + type: "bytes", + }, + ], + internalType: "struct IExecutor.CommitBatchInfo[]", + name: "_newBatchesData", + type: "tuple[]", + }, + ], + name: "commitBatchesSharedBridge", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ { @@ -621,6 +1044,66 @@ const _abi = [ stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + components: [ + { + internalType: "uint64", + name: "batchNumber", + type: "uint64", + }, + { + internalType: "bytes32", + name: "batchHash", + type: "bytes32", + }, + { + internalType: "uint64", + name: "indexRepeatedStorageChanges", + type: "uint64", + }, + { + internalType: "uint256", + name: "numberOfLayer1Txs", + type: "uint256", + }, + { + internalType: "bytes32", + name: "priorityOperationsHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "l2LogsTreeRoot", + type: "bytes32", + }, + { + internalType: "uint256", + name: "timestamp", + type: "uint256", + }, + { + internalType: "bytes32", + name: "commitment", + type: "bytes32", + }, + ], + internalType: "struct IExecutor.StoredBatchInfo[]", + name: "_batchesData", + type: "tuple[]", + }, + ], + name: "executeBatchesSharedBridge", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ { @@ -791,12 +1274,12 @@ const _abi = [ }, { inputs: [], - name: "getFirstUnprocessedPriorityTx", + name: "getAdmin", outputs: [ { - internalType: "uint256", + internalType: "address", name: "", - type: "uint256", + type: "address", }, ], stateMutability: "view", @@ -804,12 +1287,51 @@ const _abi = [ }, { inputs: [], - name: "getGovernor", + name: "getBaseToken", outputs: [ { internalType: "address", name: "", - type: "address", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getBaseTokenBridge", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getBridgehub", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getFirstUnprocessedPriorityTx", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", }, ], stateMutability: "view", @@ -882,7 +1404,7 @@ const _abi = [ }, { inputs: [], - name: "getPendingGovernor", + name: "getPendingAdmin", outputs: [ { internalType: "address", @@ -932,6 +1454,32 @@ const _abi = [ stateMutability: "view", type: "function", }, + { + inputs: [], + name: "getPubdataPricingMode", + outputs: [ + { + internalType: "enum PubdataPricingMode", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getStateTransitionManager", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, { inputs: [], name: "getTotalBatchesCommitted", @@ -1133,7 +1681,7 @@ const _abi = [ outputs: [ { internalType: "bytes32", - name: "hash", + name: "merkleRoot", type: "bytes32", }, ], @@ -1318,6 +1866,130 @@ const _abi = [ stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + components: [ + { + internalType: "uint64", + name: "batchNumber", + type: "uint64", + }, + { + internalType: "bytes32", + name: "batchHash", + type: "bytes32", + }, + { + internalType: "uint64", + name: "indexRepeatedStorageChanges", + type: "uint64", + }, + { + internalType: "uint256", + name: "numberOfLayer1Txs", + type: "uint256", + }, + { + internalType: "bytes32", + name: "priorityOperationsHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "l2LogsTreeRoot", + type: "bytes32", + }, + { + internalType: "uint256", + name: "timestamp", + type: "uint256", + }, + { + internalType: "bytes32", + name: "commitment", + type: "bytes32", + }, + ], + internalType: "struct IExecutor.StoredBatchInfo", + name: "_prevBatch", + type: "tuple", + }, + { + components: [ + { + internalType: "uint64", + name: "batchNumber", + type: "uint64", + }, + { + internalType: "bytes32", + name: "batchHash", + type: "bytes32", + }, + { + internalType: "uint64", + name: "indexRepeatedStorageChanges", + type: "uint64", + }, + { + internalType: "uint256", + name: "numberOfLayer1Txs", + type: "uint256", + }, + { + internalType: "bytes32", + name: "priorityOperationsHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "l2LogsTreeRoot", + type: "bytes32", + }, + { + internalType: "uint256", + name: "timestamp", + type: "uint256", + }, + { + internalType: "bytes32", + name: "commitment", + type: "bytes32", + }, + ], + internalType: "struct IExecutor.StoredBatchInfo[]", + name: "_committedBatches", + type: "tuple[]", + }, + { + components: [ + { + internalType: "uint256[]", + name: "recursiveAggregationInput", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "serializedProof", + type: "uint256[]", + }, + ], + internalType: "struct IExecutor.ProofInput", + name: "_proof", + type: "tuple", + }, + ], + name: "proveBatchesSharedBridge", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ { @@ -1366,7 +2038,7 @@ const _abi = [ inputs: [ { internalType: "uint256", - name: "_l2BatchNumber", + name: "_batchNumber", type: "uint256", }, { @@ -1432,7 +2104,7 @@ const _abi = [ inputs: [ { internalType: "uint256", - name: "_l2BatchNumber", + name: "_batchNumber", type: "uint256", }, { @@ -1544,12 +2216,17 @@ const _abi = [ { inputs: [ { - internalType: "address", - name: "_newPendingAdmin", - type: "address", + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "_newLastBatch", + type: "uint256", }, ], - name: "setPendingAdmin", + name: "revertBatchesSharedBridge", outputs: [], stateMutability: "nonpayable", type: "function", @@ -1558,11 +2235,11 @@ const _abi = [ inputs: [ { internalType: "address", - name: "_newPendingGovernor", + name: "_newPendingAdmin", type: "address", }, ], - name: "setPendingGovernor", + name: "setPendingAdmin", outputs: [], stateMutability: "nonpayable", type: "function", @@ -1593,6 +2270,37 @@ const _abi = [ stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "uint128", + name: "_nominator", + type: "uint128", + }, + { + internalType: "uint128", + name: "_denominator", + type: "uint128", + }, + ], + name: "setTokenMultiplier", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_transactionFilterer", + type: "address", + }, + ], + name: "setTransactionFilterer", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ { @@ -1611,6 +2319,19 @@ const _abi = [ stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "enum PubdataPricingMode", + name: "_validiumMode", + type: "uint8", + }, + ], + name: "setValidiumMode", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ { @@ -1630,6 +2351,13 @@ const _abi = [ stateMutability: "view", type: "function", }, + { + inputs: [], + name: "transferEthToSharedBridge", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [], name: "unfreezeDiamond", @@ -1637,4 +2365,61 @@ const _abi = [ stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "uint256", + name: "_protocolVersion", + type: "uint256", + }, + { + components: [ + { + components: [ + { + internalType: "address", + name: "facet", + type: "address", + }, + { + internalType: "enum Diamond.Action", + name: "action", + type: "uint8", + }, + { + internalType: "bool", + name: "isFreezable", + type: "bool", + }, + { + internalType: "bytes4[]", + name: "selectors", + type: "bytes4[]", + }, + ], + internalType: "struct Diamond.FacetCut[]", + name: "facetCuts", + type: "tuple[]", + }, + { + internalType: "address", + name: "initAddress", + type: "address", + }, + { + internalType: "bytes", + name: "initCalldata", + type: "bytes", + }, + ], + internalType: "struct Diamond.DiamondCutData", + name: "_cutData", + type: "tuple", + }, + ], + name: "upgradeChainFromVersion", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, ]; diff --git a/src/typechain/Il1Bridge.d.ts b/src/typechain/Il1Bridge.d.ts index 5ac8c671..6834942b 100644 --- a/src/typechain/Il1Bridge.d.ts +++ b/src/typechain/Il1Bridge.d.ts @@ -23,19 +23,38 @@ import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; interface Il1BridgeInterface extends ethers.utils.Interface { functions: { - "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment; - "deposit(address,address,uint256,uint256,uint256,address)": FunctionFragment; - "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment; - "isWithdrawalFinalized(uint256,uint256)": FunctionFragment; - "l2Bridge()": FunctionFragment; - "l2TokenAddress(address)": FunctionFragment; + "bridgehub()": FunctionFragment; + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)": FunctionFragment; + "bridgehubDeposit(uint256,address,bytes)": FunctionFragment; + "bridgehubDepositBaseToken(uint256,address,address,uint256)": FunctionFragment; + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment; + "deposit(uint256,address,address,uint256,uint256,uint256,uint256,address)": FunctionFragment; + "depositHappened(uint256,bytes32)": FunctionFragment; + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment; + "isWithdrawalFinalizedShared(uint256,uint256,uint256)": FunctionFragment; + "l2BridgeAddress(uint256)": FunctionFragment; }; + encodeFunctionData(functionFragment: "bridgehub", values?: undefined): string; + encodeFunctionData( + functionFragment: "bridgehubConfirmL2Transaction", + values: [BigNumberish, BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "bridgehubDeposit", + values: [BigNumberish, string, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "bridgehubDepositBaseToken", + values: [BigNumberish, string, string, BigNumberish] + ): string; encodeFunctionData( functionFragment: "claimFailedDeposit", values: [ + BigNumberish, string, string, + BigNumberish, BytesLike, BigNumberish, BigNumberish, @@ -45,50 +64,97 @@ interface Il1BridgeInterface extends ethers.utils.Interface { ): string; encodeFunctionData( functionFragment: "deposit", - values: [string, string, BigNumberish, BigNumberish, BigNumberish, string] + values: [ + BigNumberish, + string, + string, + BigNumberish, + BigNumberish, + BigNumberish, + BigNumberish, + string + ] + ): string; + encodeFunctionData( + functionFragment: "depositHappened", + values: [BigNumberish, BytesLike] ): string; encodeFunctionData( functionFragment: "finalizeWithdrawal", - values: [BigNumberish, BigNumberish, BigNumberish, BytesLike, BytesLike[]] + values: [ + BigNumberish, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike, + BytesLike[] + ] ): string; encodeFunctionData( - functionFragment: "isWithdrawalFinalized", - values: [BigNumberish, BigNumberish] + functionFragment: "isWithdrawalFinalizedShared", + values: [BigNumberish, BigNumberish, BigNumberish] ): string; - encodeFunctionData(functionFragment: "l2Bridge", values?: undefined): string; encodeFunctionData( - functionFragment: "l2TokenAddress", - values: [string] + functionFragment: "l2BridgeAddress", + values: [BigNumberish] ): string; + decodeFunctionResult(functionFragment: "bridgehub", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "bridgehubConfirmL2Transaction", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "bridgehubDeposit", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "bridgehubDepositBaseToken", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "claimFailedDeposit", data: BytesLike ): Result; decodeFunctionResult(functionFragment: "deposit", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "depositHappened", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "finalizeWithdrawal", data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "isWithdrawalFinalized", + functionFragment: "isWithdrawalFinalizedShared", data: BytesLike ): Result; - decodeFunctionResult(functionFragment: "l2Bridge", data: BytesLike): Result; decodeFunctionResult( - functionFragment: "l2TokenAddress", + functionFragment: "l2BridgeAddress", data: BytesLike ): Result; events: { - "ClaimedFailedDeposit(address,address,uint256)": EventFragment; - "DepositInitiated(bytes32,address,address,address,uint256)": EventFragment; - "WithdrawalFinalized(address,address,uint256)": EventFragment; + "BridgehubDepositFinalized(uint256,bytes32,bytes32)": EventFragment; + "BridgehubDepositInitiatedSharedBridge(uint256,bytes32,address,address,address,uint256)": EventFragment; + "ClaimedFailedDepositSharedBridge(uint256,address,address,uint256)": EventFragment; + "DepositInitiatedSharedBridge(uint256,bytes32,address,address,address,uint256)": EventFragment; + "WithdrawalFinalizedSharedBridge(uint256,address,address,uint256)": EventFragment; }; - getEvent(nameOrSignatureOrTopic: "ClaimedFailedDeposit"): EventFragment; - getEvent(nameOrSignatureOrTopic: "DepositInitiated"): EventFragment; - getEvent(nameOrSignatureOrTopic: "WithdrawalFinalized"): EventFragment; + getEvent(nameOrSignatureOrTopic: "BridgehubDepositFinalized"): EventFragment; + getEvent( + nameOrSignatureOrTopic: "BridgehubDepositInitiatedSharedBridge" + ): EventFragment; + getEvent( + nameOrSignatureOrTopic: "ClaimedFailedDepositSharedBridge" + ): EventFragment; + getEvent( + nameOrSignatureOrTopic: "DepositInitiatedSharedBridge" + ): EventFragment; + getEvent( + nameOrSignatureOrTopic: "WithdrawalFinalizedSharedBridge" + ): EventFragment; } export class Il1Bridge extends Contract { @@ -105,9 +171,63 @@ export class Il1Bridge extends Contract { interface: Il1BridgeInterface; functions: { + bridgehub(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "bridgehub()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + claimFailedDeposit( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -116,9 +236,11 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -128,8 +250,10 @@ export class Il1Bridge extends Contract { ): Promise; deposit( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -137,9 +261,11 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256,address)"( + "deposit(uint256,address,address,uint256,uint256,uint256,uint256,address)"( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -147,7 +273,24 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + finalizeWithdrawal( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -156,7 +299,8 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -165,7 +309,8 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - isWithdrawalFinalized( + isWithdrawalFinalizedShared( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides @@ -173,7 +318,8 @@ export class Il1Bridge extends Contract { 0: boolean; }>; - "isWithdrawalFinalized(uint256,uint256)"( + "isWithdrawalFinalizedShared(uint256,uint256,uint256)"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides @@ -181,32 +327,74 @@ export class Il1Bridge extends Contract { 0: boolean; }>; - l2Bridge(overrides?: CallOverrides): Promise<{ - 0: string; - }>; - - "l2Bridge()"(overrides?: CallOverrides): Promise<{ - 0: string; - }>; - - l2TokenAddress( - _l1Token: string, + l2BridgeAddress( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise<{ 0: string; }>; - "l2TokenAddress(address)"( - _l1Token: string, + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise<{ 0: string; }>; }; + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + claimFailedDeposit( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -215,9 +403,11 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -227,8 +417,10 @@ export class Il1Bridge extends Contract { ): Promise; deposit( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -236,9 +428,11 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256,address)"( + "deposit(uint256,address,address,uint256,uint256,uint256,uint256,address)"( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -246,7 +440,20 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + finalizeWithdrawal( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -255,7 +462,8 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -264,33 +472,106 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - isWithdrawalFinalized( + isWithdrawalFinalizedShared( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - "isWithdrawalFinalized(uint256,uint256)"( + "isWithdrawalFinalizedShared(uint256,uint256,uint256)"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - l2Bridge(overrides?: CallOverrides): Promise; - - "l2Bridge()"(overrides?: CallOverrides): Promise; - - l2TokenAddress(_l1Token: string, overrides?: CallOverrides): Promise; + l2BridgeAddress( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; - "l2TokenAddress(address)"( - _l1Token: string, + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise; callStatic: { + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: CallOverrides + ): Promise<{ + magicValue: string; + l2Contract: string; + l2Calldata: string; + factoryDeps: string[]; + txDataHash: string; + 0: string; + 1: string; + 2: string; + 3: string[]; + 4: string; + }>; + + "bridgehubDeposit(uint256,address,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: CallOverrides + ): Promise<{ + magicValue: string; + l2Contract: string; + l2Calldata: string; + factoryDeps: string[]; + txDataHash: string; + 0: string; + 1: string; + 2: string; + 3: string[]; + 4: string; + }>; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + claimFailedDeposit( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -299,9 +580,11 @@ export class Il1Bridge extends Contract { overrides?: CallOverrides ): Promise; - "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -311,8 +594,10 @@ export class Il1Bridge extends Contract { ): Promise; deposit( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -320,9 +605,11 @@ export class Il1Bridge extends Contract { overrides?: CallOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256,address)"( + "deposit(uint256,address,address,uint256,uint256,uint256,uint256,address)"( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -330,7 +617,20 @@ export class Il1Bridge extends Contract { overrides?: CallOverrides ): Promise; + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + finalizeWithdrawal( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -339,7 +639,8 @@ export class Il1Bridge extends Contract { overrides?: CallOverrides ): Promise; - "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -348,49 +649,65 @@ export class Il1Bridge extends Contract { overrides?: CallOverrides ): Promise; - isWithdrawalFinalized( + isWithdrawalFinalizedShared( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - "isWithdrawalFinalized(uint256,uint256)"( + "isWithdrawalFinalizedShared(uint256,uint256,uint256)"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - l2Bridge(overrides?: CallOverrides): Promise; - - "l2Bridge()"(overrides?: CallOverrides): Promise; - - l2TokenAddress( - _l1Token: string, + l2BridgeAddress( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise; - "l2TokenAddress(address)"( - _l1Token: string, + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise; }; filters: { - ClaimedFailedDeposit( + BridgehubDepositFinalized( + chainId: BigNumberish | null, + txDataHash: BytesLike | null, + l2DepositTxHash: BytesLike | null + ): EventFilter; + + BridgehubDepositInitiatedSharedBridge( + chainId: BigNumberish | null, + txDataHash: BytesLike | null, + from: string | null, + to: null, + l1Token: null, + amount: null + ): EventFilter; + + ClaimedFailedDepositSharedBridge( + chainId: BigNumberish | null, to: string | null, l1Token: string | null, amount: null ): EventFilter; - DepositInitiated( + DepositInitiatedSharedBridge( + chainId: BigNumberish | null, l2DepositTxHash: BytesLike | null, from: string | null, - to: string | null, + to: null, l1Token: null, amount: null ): EventFilter; - WithdrawalFinalized( + WithdrawalFinalizedSharedBridge( + chainId: BigNumberish | null, to: string | null, l1Token: string | null, amount: null @@ -398,9 +715,59 @@ export class Il1Bridge extends Contract { }; estimateGas: { + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + claimFailedDeposit( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -409,9 +776,11 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -421,8 +790,10 @@ export class Il1Bridge extends Contract { ): Promise; deposit( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -430,9 +801,11 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256,address)"( + "deposit(uint256,address,address,uint256,uint256,uint256,uint256,address)"( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -440,7 +813,20 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + finalizeWithdrawal( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -449,7 +835,8 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -458,37 +845,85 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - isWithdrawalFinalized( + isWithdrawalFinalizedShared( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - "isWithdrawalFinalized(uint256,uint256)"( + "isWithdrawalFinalizedShared(uint256,uint256,uint256)"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - l2Bridge(overrides?: CallOverrides): Promise; - - "l2Bridge()"(overrides?: CallOverrides): Promise; - - l2TokenAddress( - _l1Token: string, + l2BridgeAddress( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise; - "l2TokenAddress(address)"( - _l1Token: string, + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise; }; populateTransaction: { + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + claimFailedDeposit( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -497,9 +932,11 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, _depositSender: string, _l1Token: string, + _amount: BigNumberish, _l2TxHash: BytesLike, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, @@ -509,8 +946,10 @@ export class Il1Bridge extends Contract { ): Promise; deposit( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -518,9 +957,11 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; - "deposit(address,address,uint256,uint256,uint256,address)"( + "deposit(uint256,address,address,uint256,uint256,uint256,uint256,address)"( + _chainId: BigNumberish, _l2Receiver: string, _l1Token: string, + _mintValue: BigNumberish, _amount: BigNumberish, _l2TxGasLimit: BigNumberish, _l2TxGasPerPubdataByte: BigNumberish, @@ -528,7 +969,20 @@ export class Il1Bridge extends Contract { overrides?: PayableOverrides ): Promise; + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + finalizeWithdrawal( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -537,7 +991,8 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, _l2TxNumberInBatch: BigNumberish, @@ -546,29 +1001,27 @@ export class Il1Bridge extends Contract { overrides?: Overrides ): Promise; - isWithdrawalFinalized( + isWithdrawalFinalizedShared( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - "isWithdrawalFinalized(uint256,uint256)"( + "isWithdrawalFinalizedShared(uint256,uint256,uint256)"( + _chainId: BigNumberish, _l2BatchNumber: BigNumberish, _l2MessageIndex: BigNumberish, overrides?: CallOverrides ): Promise; - l2Bridge(overrides?: CallOverrides): Promise; - - "l2Bridge()"(overrides?: CallOverrides): Promise; - - l2TokenAddress( - _l1Token: string, + l2BridgeAddress( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise; - "l2TokenAddress(address)"( - _l1Token: string, + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, overrides?: CallOverrides ): Promise; }; diff --git a/src/typechain/Il1BridgeFactory.ts b/src/typechain/Il1BridgeFactory.ts index c6afb2d2..e0f2b9fc 100644 --- a/src/typechain/Il1BridgeFactory.ts +++ b/src/typechain/Il1BridgeFactory.ts @@ -20,6 +20,80 @@ const _abi = [ { anonymous: false, inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "bytes32", + name: "txDataHash", + type: "bytes32", + }, + { + indexed: true, + internalType: "bytes32", + name: "l2DepositTxHash", + type: "bytes32", + }, + ], + name: "BridgehubDepositFinalized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "bytes32", + name: "txDataHash", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "BridgehubDepositInitiatedSharedBridge", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, { indexed: true, internalType: "address", @@ -39,12 +113,18 @@ const _abi = [ type: "uint256", }, ], - name: "ClaimedFailedDeposit", + name: "ClaimedFailedDepositSharedBridge", type: "event", }, { anonymous: false, inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, { indexed: true, internalType: "bytes32", @@ -58,7 +138,7 @@ const _abi = [ type: "address", }, { - indexed: true, + indexed: false, internalType: "address", name: "to", type: "address", @@ -76,12 +156,18 @@ const _abi = [ type: "uint256", }, ], - name: "DepositInitiated", + name: "DepositInitiatedSharedBridge", type: "event", }, { anonymous: false, inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, { indexed: true, internalType: "address", @@ -101,11 +187,136 @@ const _abi = [ type: "uint256", }, ], - name: "WithdrawalFinalized", + name: "WithdrawalFinalizedSharedBridge", type: "event", }, + { + inputs: [], + name: "bridgehub", + outputs: [ + { + internalType: "contract IBridgehub", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "bytes32", + name: "_txDataHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "_txHash", + type: "bytes32", + }, + ], + name: "bridgehubConfirmL2Transaction", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "address", + name: "_prevMsgSender", + type: "address", + }, + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + ], + name: "bridgehubDeposit", + outputs: [ + { + components: [ + { + internalType: "bytes32", + name: "magicValue", + type: "bytes32", + }, + { + internalType: "address", + name: "l2Contract", + type: "address", + }, + { + internalType: "bytes", + name: "l2Calldata", + type: "bytes", + }, + { + internalType: "bytes[]", + name: "factoryDeps", + type: "bytes[]", + }, + { + internalType: "bytes32", + name: "txDataHash", + type: "bytes32", + }, + ], + internalType: "struct L2TransactionRequestTwoBridgesInner", + name: "request", + type: "tuple", + }, + ], + stateMutability: "payable", + type: "function", + }, { inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "address", + name: "_prevMsgSender", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + ], + name: "bridgehubDepositBaseToken", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, { internalType: "address", name: "_depositSender", @@ -116,6 +327,11 @@ const _abi = [ name: "_l1Token", type: "address", }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, { internalType: "bytes32", name: "_l2TxHash", @@ -149,6 +365,11 @@ const _abi = [ }, { inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, { internalType: "address", name: "_l2Receiver", @@ -159,6 +380,11 @@ const _abi = [ name: "_l1Token", type: "address", }, + { + internalType: "uint256", + name: "_mintValue", + type: "uint256", + }, { internalType: "uint256", name: "_amount", @@ -193,6 +419,35 @@ const _abi = [ }, { inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "bytes32", + name: "_l2TxHash", + type: "bytes32", + }, + ], + name: "depositHappened", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, { internalType: "uint256", name: "_l2BatchNumber", @@ -226,6 +481,11 @@ const _abi = [ }, { inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, { internalType: "uint256", name: "_l2BatchNumber", @@ -237,7 +497,7 @@ const _abi = [ type: "uint256", }, ], - name: "isWithdrawalFinalized", + name: "isWithdrawalFinalizedShared", outputs: [ { internalType: "bool", @@ -248,28 +508,15 @@ const _abi = [ stateMutability: "view", type: "function", }, - { - inputs: [], - name: "l2Bridge", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, { inputs: [ { - internalType: "address", - name: "_l1Token", - type: "address", + internalType: "uint256", + name: "_chainId", + type: "uint256", }, ], - name: "l2TokenAddress", + name: "l2BridgeAddress", outputs: [ { internalType: "address", diff --git a/src/typechain/Il1Erc20Bridge.d.ts b/src/typechain/Il1Erc20Bridge.d.ts new file mode 100644 index 00000000..4d8b8f16 --- /dev/null +++ b/src/typechain/Il1Erc20Bridge.d.ts @@ -0,0 +1,784 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, +} from "ethers"; +import { + Contract, + ContractTransaction, + Overrides, + PayableOverrides, + CallOverrides, +} from "@ethersproject/contracts"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; + +interface Il1Erc20BridgeInterface extends ethers.utils.Interface { + functions: { + "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment; + "deposit(address,address,uint256,uint256,uint256)": FunctionFragment; + "depositAmount(address,address,bytes32)": FunctionFragment; + "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment; + "isWithdrawalFinalized(uint256,uint256)": FunctionFragment; + "l2Bridge()": FunctionFragment; + "l2TokenAddress(address)": FunctionFragment; + "l2TokenBeacon()": FunctionFragment; + "sharedBridge()": FunctionFragment; + "transferTokenToSharedBridge(address,uint256)": FunctionFragment; + }; + + encodeFunctionData( + functionFragment: "claimFailedDeposit", + values: [ + string, + string, + BytesLike, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike[] + ] + ): string; + encodeFunctionData( + functionFragment: "deposit", + values: [string, string, BigNumberish, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "depositAmount", + values: [string, string, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "finalizeWithdrawal", + values: [BigNumberish, BigNumberish, BigNumberish, BytesLike, BytesLike[]] + ): string; + encodeFunctionData( + functionFragment: "isWithdrawalFinalized", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData(functionFragment: "l2Bridge", values?: undefined): string; + encodeFunctionData( + functionFragment: "l2TokenAddress", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "l2TokenBeacon", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "sharedBridge", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "transferTokenToSharedBridge", + values: [string, BigNumberish] + ): string; + + decodeFunctionResult( + functionFragment: "claimFailedDeposit", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "deposit", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "depositAmount", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "finalizeWithdrawal", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "isWithdrawalFinalized", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "l2Bridge", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "l2TokenAddress", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "l2TokenBeacon", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "sharedBridge", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "transferTokenToSharedBridge", + data: BytesLike + ): Result; + + events: { + "ClaimedFailedDeposit(address,address,uint256)": EventFragment; + "DepositInitiated(bytes32,address,address,address,uint256)": EventFragment; + "WithdrawalFinalized(address,address,uint256)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "ClaimedFailedDeposit"): EventFragment; + getEvent(nameOrSignatureOrTopic: "DepositInitiated"): EventFragment; + getEvent(nameOrSignatureOrTopic: "WithdrawalFinalized"): EventFragment; +} + +export class Il1Erc20Bridge extends Contract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + on(event: EventFilter | string, listener: Listener): this; + once(event: EventFilter | string, listener: Listener): this; + addListener(eventName: EventFilter | string, listener: Listener): this; + removeAllListeners(eventName: EventFilter | string): this; + removeListener(eventName: any, listener: Listener): this; + + interface: Il1Erc20BridgeInterface; + + functions: { + claimFailedDeposit( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + depositAmount( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + "depositAmount(address,address,bytes32)"( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + finalizeWithdrawal( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + "isWithdrawalFinalized(uint256,uint256)"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + l2Bridge(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "l2Bridge()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + l2TokenAddress( + _l1Token: string, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + "l2TokenAddress(address)"( + _l1Token: string, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + l2TokenBeacon(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "l2TokenBeacon()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + sharedBridge(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "sharedBridge()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + transferTokenToSharedBridge( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "transferTokenToSharedBridge(address,uint256)"( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + }; + + claimFailedDeposit( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + depositAmount( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + "depositAmount(address,address,bytes32)"( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + finalizeWithdrawal( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256)"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + + l2TokenAddress(_l1Token: string, overrides?: CallOverrides): Promise; + + "l2TokenAddress(address)"( + _l1Token: string, + overrides?: CallOverrides + ): Promise; + + l2TokenBeacon(overrides?: CallOverrides): Promise; + + "l2TokenBeacon()"(overrides?: CallOverrides): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + transferTokenToSharedBridge( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "transferTokenToSharedBridge(address,uint256)"( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + callStatic: { + claimFailedDeposit( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: CallOverrides + ): Promise; + + depositAmount( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositAmount(address,address,bytes32)"( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + finalizeWithdrawal( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + isWithdrawalFinalized( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256)"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + + l2TokenAddress( + _l1Token: string, + overrides?: CallOverrides + ): Promise; + + "l2TokenAddress(address)"( + _l1Token: string, + overrides?: CallOverrides + ): Promise; + + l2TokenBeacon(overrides?: CallOverrides): Promise; + + "l2TokenBeacon()"(overrides?: CallOverrides): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + transferTokenToSharedBridge( + _token: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "transferTokenToSharedBridge(address,uint256)"( + _token: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + ClaimedFailedDeposit( + to: string | null, + l1Token: string | null, + amount: null + ): EventFilter; + + DepositInitiated( + l2DepositTxHash: BytesLike | null, + from: string | null, + to: string | null, + l1Token: null, + amount: null + ): EventFilter; + + WithdrawalFinalized( + to: string | null, + l1Token: string | null, + amount: null + ): EventFilter; + }; + + estimateGas: { + claimFailedDeposit( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + depositAmount( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + "depositAmount(address,address,bytes32)"( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + finalizeWithdrawal( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256)"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + + l2TokenAddress( + _l1Token: string, + overrides?: CallOverrides + ): Promise; + + "l2TokenAddress(address)"( + _l1Token: string, + overrides?: CallOverrides + ): Promise; + + l2TokenBeacon(overrides?: CallOverrides): Promise; + + "l2TokenBeacon()"(overrides?: CallOverrides): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + transferTokenToSharedBridge( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "transferTokenToSharedBridge(address,uint256)"( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + }; + + populateTransaction: { + claimFailedDeposit( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "deposit(address,address,uint256,uint256,uint256,address)"( + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + depositAmount( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + "depositAmount(address,address,bytes32)"( + _account: string, + _l1Token: string, + _depositL2TxHash: BytesLike, + overrides?: Overrides + ): Promise; + + finalizeWithdrawal( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256)"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l2Bridge(overrides?: CallOverrides): Promise; + + "l2Bridge()"(overrides?: CallOverrides): Promise; + + l2TokenAddress( + _l1Token: string, + overrides?: CallOverrides + ): Promise; + + "l2TokenAddress(address)"( + _l1Token: string, + overrides?: CallOverrides + ): Promise; + + l2TokenBeacon(overrides?: CallOverrides): Promise; + + "l2TokenBeacon()"(overrides?: CallOverrides): Promise; + + sharedBridge(overrides?: CallOverrides): Promise; + + "sharedBridge()"(overrides?: CallOverrides): Promise; + + transferTokenToSharedBridge( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + + "transferTokenToSharedBridge(address,uint256)"( + _token: string, + _amount: BigNumberish, + overrides?: Overrides + ): Promise; + }; +} diff --git a/src/typechain/Il1Erc20BridgeFactory.ts b/src/typechain/Il1Erc20BridgeFactory.ts new file mode 100644 index 00000000..d8597ceb --- /dev/null +++ b/src/typechain/Il1Erc20BridgeFactory.ts @@ -0,0 +1,395 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer } from "ethers"; +import { Provider } from "@ethersproject/providers"; + +import type { Il1Erc20Bridge } from "./Il1Erc20Bridge"; + +export class Il1Erc20BridgeFactory { + static connect( + address: string, + signerOrProvider: Signer | Provider + ): Il1Erc20Bridge { + return new Contract(address, _abi, signerOrProvider) as Il1Erc20Bridge; + } +} + +const _abi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "ClaimedFailedDeposit", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "l2DepositTxHash", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "DepositInitiated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "WithdrawalFinalized", + type: "event", + }, + { + inputs: [ + { + internalType: "address", + name: "_depositSender", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "bytes32", + name: "_l2TxHash", + type: "bytes32", + }, + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + { + internalType: "uint16", + name: "_l2TxNumberInBatch", + type: "uint16", + }, + { + internalType: "bytes32[]", + name: "_merkleProof", + type: "bytes32[]", + }, + ], + name: "claimFailedDeposit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_l2Receiver", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasPerPubdataByte", + type: "uint256", + }, + ], + name: "deposit", + outputs: [ + { + internalType: "bytes32", + name: "txHash", + type: "bytes32", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_l2Receiver", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasPerPubdataByte", + type: "uint256", + }, + { + internalType: "address", + name: "_refundRecipient", + type: "address", + }, + ], + name: "deposit", + outputs: [ + { + internalType: "bytes32", + name: "txHash", + type: "bytes32", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_account", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "bytes32", + name: "_depositL2TxHash", + type: "bytes32", + }, + ], + name: "depositAmount", + outputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + { + internalType: "uint16", + name: "_l2TxNumberInBatch", + type: "uint16", + }, + { + internalType: "bytes", + name: "_message", + type: "bytes", + }, + { + internalType: "bytes32[]", + name: "_merkleProof", + type: "bytes32[]", + }, + ], + name: "finalizeWithdrawal", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + ], + name: "isWithdrawalFinalized", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "l2Bridge", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + ], + name: "l2TokenAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "l2TokenBeacon", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "sharedBridge", + outputs: [ + { + internalType: "contract IL1SharedBridge", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + ], + name: "transferTokenToSharedBridge", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +]; diff --git a/src/typechain/Il1SharedBridge.d.ts b/src/typechain/Il1SharedBridge.d.ts new file mode 100644 index 00000000..6ff4242d --- /dev/null +++ b/src/typechain/Il1SharedBridge.d.ts @@ -0,0 +1,1469 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { + ethers, + EventFilter, + Signer, + BigNumber, + BigNumberish, + PopulatedTransaction, +} from "ethers"; +import { + Contract, + ContractTransaction, + Overrides, + PayableOverrides, + CallOverrides, +} from "@ethersproject/contracts"; +import { BytesLike } from "@ethersproject/bytes"; +import { Listener, Provider } from "@ethersproject/providers"; +import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; + +interface Il1SharedBridgeInterface extends ethers.utils.Interface { + functions: { + "bridgehub()": FunctionFragment; + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)": FunctionFragment; + "bridgehubDeposit(uint256,address,uint256,bytes)": FunctionFragment; + "bridgehubDepositBaseToken(uint256,address,address,uint256)": FunctionFragment; + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment; + "claimFailedDepositLegacyErc20Bridge(address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment; + "depositHappened(uint256,bytes32)": FunctionFragment; + "depositLegacyErc20Bridge(address,address,address,uint256,uint256,uint256,address)": FunctionFragment; + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment; + "finalizeWithdrawalLegacyErc20Bridge(uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment; + "isWithdrawalFinalized(uint256,uint256,uint256)": FunctionFragment; + "l1WethAddress()": FunctionFragment; + "l2BridgeAddress(uint256)": FunctionFragment; + "legacyBridge()": FunctionFragment; + "receiveEth(uint256)": FunctionFragment; + "setEraFirstPostUpgradeBatch(uint256)": FunctionFragment; + }; + + encodeFunctionData(functionFragment: "bridgehub", values?: undefined): string; + encodeFunctionData( + functionFragment: "bridgehubConfirmL2Transaction", + values: [BigNumberish, BytesLike, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "bridgehubDeposit", + values: [BigNumberish, string, BigNumberish, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "bridgehubDepositBaseToken", + values: [BigNumberish, string, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "claimFailedDeposit", + values: [ + BigNumberish, + string, + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike[] + ] + ): string; + encodeFunctionData( + functionFragment: "claimFailedDepositLegacyErc20Bridge", + values: [ + string, + string, + BigNumberish, + BytesLike, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike[] + ] + ): string; + encodeFunctionData( + functionFragment: "depositHappened", + values: [BigNumberish, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "depositLegacyErc20Bridge", + values: [ + string, + string, + string, + BigNumberish, + BigNumberish, + BigNumberish, + string + ] + ): string; + encodeFunctionData( + functionFragment: "finalizeWithdrawal", + values: [ + BigNumberish, + BigNumberish, + BigNumberish, + BigNumberish, + BytesLike, + BytesLike[] + ] + ): string; + encodeFunctionData( + functionFragment: "finalizeWithdrawalLegacyErc20Bridge", + values: [BigNumberish, BigNumberish, BigNumberish, BytesLike, BytesLike[]] + ): string; + encodeFunctionData( + functionFragment: "isWithdrawalFinalized", + values: [BigNumberish, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "l1WethAddress", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "l2BridgeAddress", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "legacyBridge", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "receiveEth", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setEraFirstPostUpgradeBatch", + values: [BigNumberish] + ): string; + + decodeFunctionResult(functionFragment: "bridgehub", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "bridgehubConfirmL2Transaction", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "bridgehubDeposit", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "bridgehubDepositBaseToken", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "claimFailedDeposit", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "claimFailedDepositLegacyErc20Bridge", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "depositHappened", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "depositLegacyErc20Bridge", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "finalizeWithdrawal", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "finalizeWithdrawalLegacyErc20Bridge", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "isWithdrawalFinalized", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "l1WethAddress", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "l2BridgeAddress", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "legacyBridge", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "receiveEth", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "setEraFirstPostUpgradeBatch", + data: BytesLike + ): Result; + + events: { + "BridgehubDepositBaseTokenInitiated(uint256,address,address,uint256)": EventFragment; + "BridgehubDepositFinalized(uint256,bytes32,bytes32)": EventFragment; + "BridgehubDepositInitiated(uint256,bytes32,address,address,address,uint256)": EventFragment; + "ClaimedFailedDepositSharedBridge(uint256,address,address,uint256)": EventFragment; + "LegacyDepositInitiated(uint256,bytes32,address,address,address,uint256)": EventFragment; + "WithdrawalFinalizedSharedBridge(uint256,address,address,uint256)": EventFragment; + }; + + getEvent( + nameOrSignatureOrTopic: "BridgehubDepositBaseTokenInitiated" + ): EventFragment; + getEvent(nameOrSignatureOrTopic: "BridgehubDepositFinalized"): EventFragment; + getEvent(nameOrSignatureOrTopic: "BridgehubDepositInitiated"): EventFragment; + getEvent( + nameOrSignatureOrTopic: "ClaimedFailedDepositSharedBridge" + ): EventFragment; + getEvent(nameOrSignatureOrTopic: "LegacyDepositInitiated"): EventFragment; + getEvent( + nameOrSignatureOrTopic: "WithdrawalFinalizedSharedBridge" + ): EventFragment; +} + +export class Il1SharedBridge extends Contract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + on(event: EventFilter | string, listener: Listener): this; + once(event: EventFilter | string, listener: Listener): this; + addListener(eventName: EventFilter | string, listener: Listener): this; + removeAllListeners(eventName: EventFilter | string): this; + removeListener(eventName: any, listener: Listener): this; + + interface: Il1SharedBridgeInterface; + + functions: { + bridgehub(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "bridgehub()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,uint256,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + claimFailedDeposit( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + claimFailedDepositLegacyErc20Bridge( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDepositLegacyErc20Bridge(address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + depositLegacyErc20Bridge( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "depositLegacyErc20Bridge(address,address,address,uint256,uint256,uint256,address)"( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + finalizeWithdrawal( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + finalizeWithdrawalLegacyErc20Bridge( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawalLegacyErc20Bridge(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + "isWithdrawalFinalized(uint256,uint256,uint256)"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: boolean; + }>; + + l1WethAddress(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "l1WethAddress()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + l2BridgeAddress( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise<{ + 0: string; + }>; + + legacyBridge(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + "legacyBridge()"(overrides?: CallOverrides): Promise<{ + 0: string; + }>; + + receiveEth( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "receiveEth(uint256)"( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + setEraFirstPostUpgradeBatch( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + + "setEraFirstPostUpgradeBatch(uint256)"( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + }; + + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,uint256,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + claimFailedDeposit( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + claimFailedDepositLegacyErc20Bridge( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDepositLegacyErc20Bridge(address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + depositLegacyErc20Bridge( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "depositLegacyErc20Bridge(address,address,address,uint256,uint256,uint256,address)"( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + finalizeWithdrawal( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + finalizeWithdrawalLegacyErc20Bridge( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawalLegacyErc20Bridge(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256,uint256)"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l1WethAddress(overrides?: CallOverrides): Promise; + + "l1WethAddress()"(overrides?: CallOverrides): Promise; + + l2BridgeAddress( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + legacyBridge(overrides?: CallOverrides): Promise; + + "legacyBridge()"(overrides?: CallOverrides): Promise; + + receiveEth( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "receiveEth(uint256)"( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + setEraFirstPostUpgradeBatch( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + + "setEraFirstPostUpgradeBatch(uint256)"( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + + callStatic: { + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: CallOverrides + ): Promise<{ + magicValue: string; + l2Contract: string; + l2Calldata: string; + factoryDeps: string[]; + txDataHash: string; + 0: string; + 1: string; + 2: string; + 3: string[]; + 4: string; + }>; + + "bridgehubDeposit(uint256,address,uint256,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: CallOverrides + ): Promise<{ + magicValue: string; + l2Contract: string; + l2Calldata: string; + factoryDeps: string[]; + txDataHash: string; + 0: string; + 1: string; + 2: string; + 3: string[]; + 4: string; + }>; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + claimFailedDeposit( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + claimFailedDepositLegacyErc20Bridge( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "claimFailedDepositLegacyErc20Bridge(address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + depositLegacyErc20Bridge( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: CallOverrides + ): Promise; + + "depositLegacyErc20Bridge(address,address,address,uint256,uint256,uint256,address)"( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: CallOverrides + ): Promise; + + finalizeWithdrawal( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise; + + finalizeWithdrawalLegacyErc20Bridge( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise<{ + l1Receiver: string; + l1Token: string; + amount: BigNumber; + 0: string; + 1: string; + 2: BigNumber; + }>; + + "finalizeWithdrawalLegacyErc20Bridge(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: CallOverrides + ): Promise<{ + l1Receiver: string; + l1Token: string; + amount: BigNumber; + 0: string; + 1: string; + 2: BigNumber; + }>; + + isWithdrawalFinalized( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256,uint256)"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l1WethAddress(overrides?: CallOverrides): Promise; + + "l1WethAddress()"(overrides?: CallOverrides): Promise; + + l2BridgeAddress( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + legacyBridge(overrides?: CallOverrides): Promise; + + "legacyBridge()"(overrides?: CallOverrides): Promise; + + receiveEth( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "receiveEth(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + setEraFirstPostUpgradeBatch( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "setEraFirstPostUpgradeBatch(uint256)"( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + BridgehubDepositBaseTokenInitiated( + chainId: BigNumberish | null, + from: string | null, + l1Token: null, + amount: null + ): EventFilter; + + BridgehubDepositFinalized( + chainId: BigNumberish | null, + txDataHash: BytesLike | null, + l2DepositTxHash: BytesLike | null + ): EventFilter; + + BridgehubDepositInitiated( + chainId: BigNumberish | null, + txDataHash: BytesLike | null, + from: string | null, + to: null, + l1Token: null, + amount: null + ): EventFilter; + + ClaimedFailedDepositSharedBridge( + chainId: BigNumberish | null, + to: string | null, + l1Token: string | null, + amount: null + ): EventFilter; + + LegacyDepositInitiated( + chainId: BigNumberish | null, + l2DepositTxHash: BytesLike | null, + from: string | null, + to: null, + l1Token: null, + amount: null + ): EventFilter; + + WithdrawalFinalizedSharedBridge( + chainId: BigNumberish | null, + to: string | null, + l1Token: string | null, + amount: null + ): EventFilter; + }; + + estimateGas: { + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,uint256,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + claimFailedDeposit( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + claimFailedDepositLegacyErc20Bridge( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDepositLegacyErc20Bridge(address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + depositLegacyErc20Bridge( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "depositLegacyErc20Bridge(address,address,address,uint256,uint256,uint256,address)"( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + finalizeWithdrawal( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + finalizeWithdrawalLegacyErc20Bridge( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawalLegacyErc20Bridge(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256,uint256)"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l1WethAddress(overrides?: CallOverrides): Promise; + + "l1WethAddress()"(overrides?: CallOverrides): Promise; + + l2BridgeAddress( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + legacyBridge(overrides?: CallOverrides): Promise; + + "legacyBridge()"(overrides?: CallOverrides): Promise; + + receiveEth( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "receiveEth(uint256)"( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + setEraFirstPostUpgradeBatch( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + + "setEraFirstPostUpgradeBatch(uint256)"( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + }; + + populateTransaction: { + bridgehub(overrides?: CallOverrides): Promise; + + "bridgehub()"(overrides?: CallOverrides): Promise; + + bridgehubConfirmL2Transaction( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + "bridgehubConfirmL2Transaction(uint256,bytes32,bytes32)"( + _chainId: BigNumberish, + _txDataHash: BytesLike, + _txHash: BytesLike, + overrides?: Overrides + ): Promise; + + bridgehubDeposit( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDeposit(uint256,address,uint256,bytes)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l2Value: BigNumberish, + _data: BytesLike, + overrides?: PayableOverrides + ): Promise; + + bridgehubDepositBaseToken( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "bridgehubDepositBaseToken(uint256,address,address,uint256)"( + _chainId: BigNumberish, + _prevMsgSender: string, + _l1Token: string, + _amount: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + claimFailedDeposit( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDeposit(uint256,address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _chainId: BigNumberish, + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + claimFailedDepositLegacyErc20Bridge( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "claimFailedDepositLegacyErc20Bridge(address,address,uint256,bytes32,uint256,uint256,uint16,bytes32[])"( + _depositSender: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxHash: BytesLike, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + depositHappened( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + "depositHappened(uint256,bytes32)"( + _chainId: BigNumberish, + _l2TxHash: BytesLike, + overrides?: CallOverrides + ): Promise; + + depositLegacyErc20Bridge( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + "depositLegacyErc20Bridge(address,address,address,uint256,uint256,uint256,address)"( + _msgSender: string, + _l2Receiver: string, + _l1Token: string, + _amount: BigNumberish, + _l2TxGasLimit: BigNumberish, + _l2TxGasPerPubdataByte: BigNumberish, + _refundRecipient: string, + overrides?: PayableOverrides + ): Promise; + + finalizeWithdrawal( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawal(uint256,uint256,uint256,uint16,bytes,bytes32[])"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + finalizeWithdrawalLegacyErc20Bridge( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + "finalizeWithdrawalLegacyErc20Bridge(uint256,uint256,uint16,bytes,bytes32[])"( + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + _l2TxNumberInBatch: BigNumberish, + _message: BytesLike, + _merkleProof: BytesLike[], + overrides?: Overrides + ): Promise; + + isWithdrawalFinalized( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "isWithdrawalFinalized(uint256,uint256,uint256)"( + _chainId: BigNumberish, + _l2BatchNumber: BigNumberish, + _l2MessageIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + l1WethAddress(overrides?: CallOverrides): Promise; + + "l1WethAddress()"(overrides?: CallOverrides): Promise; + + l2BridgeAddress( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + "l2BridgeAddress(uint256)"( + _chainId: BigNumberish, + overrides?: CallOverrides + ): Promise; + + legacyBridge(overrides?: CallOverrides): Promise; + + "legacyBridge()"(overrides?: CallOverrides): Promise; + + receiveEth( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + "receiveEth(uint256)"( + _chainId: BigNumberish, + overrides?: PayableOverrides + ): Promise; + + setEraFirstPostUpgradeBatch( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + + "setEraFirstPostUpgradeBatch(uint256)"( + _eraFirstPostUpgradeBatch: BigNumberish, + overrides?: Overrides + ): Promise; + }; +} diff --git a/src/typechain/Il1SharedBridgeFactory.ts b/src/typechain/Il1SharedBridgeFactory.ts new file mode 100644 index 00000000..1a02566b --- /dev/null +++ b/src/typechain/Il1SharedBridgeFactory.ts @@ -0,0 +1,710 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer } from "ethers"; +import { Provider } from "@ethersproject/providers"; + +import type { Il1SharedBridge } from "./Il1SharedBridge"; + +export class Il1SharedBridgeFactory { + static connect( + address: string, + signerOrProvider: Signer | Provider + ): Il1SharedBridge { + return new Contract(address, _abi, signerOrProvider) as Il1SharedBridge; + } +} + +const _abi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "BridgehubDepositBaseTokenInitiated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "bytes32", + name: "txDataHash", + type: "bytes32", + }, + { + indexed: true, + internalType: "bytes32", + name: "l2DepositTxHash", + type: "bytes32", + }, + ], + name: "BridgehubDepositFinalized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "bytes32", + name: "txDataHash", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "BridgehubDepositInitiated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "ClaimedFailedDepositSharedBridge", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "bytes32", + name: "l2DepositTxHash", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "LegacyDepositInitiated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "l1Token", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "WithdrawalFinalizedSharedBridge", + type: "event", + }, + { + inputs: [], + name: "bridgehub", + outputs: [ + { + internalType: "contract IBridgehub", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "bytes32", + name: "_txDataHash", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "_txHash", + type: "bytes32", + }, + ], + name: "bridgehubConfirmL2Transaction", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "address", + name: "_prevMsgSender", + type: "address", + }, + { + internalType: "uint256", + name: "_l2Value", + type: "uint256", + }, + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + ], + name: "bridgehubDeposit", + outputs: [ + { + components: [ + { + internalType: "bytes32", + name: "magicValue", + type: "bytes32", + }, + { + internalType: "address", + name: "l2Contract", + type: "address", + }, + { + internalType: "bytes", + name: "l2Calldata", + type: "bytes", + }, + { + internalType: "bytes[]", + name: "factoryDeps", + type: "bytes[]", + }, + { + internalType: "bytes32", + name: "txDataHash", + type: "bytes32", + }, + ], + internalType: "struct L2TransactionRequestTwoBridgesInner", + name: "request", + type: "tuple", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "address", + name: "_prevMsgSender", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + ], + name: "bridgehubDepositBaseToken", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "address", + name: "_depositSender", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + { + internalType: "bytes32", + name: "_l2TxHash", + type: "bytes32", + }, + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + { + internalType: "uint16", + name: "_l2TxNumberInBatch", + type: "uint16", + }, + { + internalType: "bytes32[]", + name: "_merkleProof", + type: "bytes32[]", + }, + ], + name: "claimFailedDeposit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_depositSender", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + { + internalType: "bytes32", + name: "_l2TxHash", + type: "bytes32", + }, + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + { + internalType: "uint16", + name: "_l2TxNumberInBatch", + type: "uint16", + }, + { + internalType: "bytes32[]", + name: "_merkleProof", + type: "bytes32[]", + }, + ], + name: "claimFailedDepositLegacyErc20Bridge", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "bytes32", + name: "_l2TxHash", + type: "bytes32", + }, + ], + name: "depositHappened", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_msgSender", + type: "address", + }, + { + internalType: "address", + name: "_l2Receiver", + type: "address", + }, + { + internalType: "address", + name: "_l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasLimit", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2TxGasPerPubdataByte", + type: "uint256", + }, + { + internalType: "address", + name: "_refundRecipient", + type: "address", + }, + ], + name: "depositLegacyErc20Bridge", + outputs: [ + { + internalType: "bytes32", + name: "txHash", + type: "bytes32", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + { + internalType: "uint16", + name: "_l2TxNumberInBatch", + type: "uint16", + }, + { + internalType: "bytes", + name: "_message", + type: "bytes", + }, + { + internalType: "bytes32[]", + name: "_merkleProof", + type: "bytes32[]", + }, + ], + name: "finalizeWithdrawal", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + { + internalType: "uint16", + name: "_l2TxNumberInBatch", + type: "uint16", + }, + { + internalType: "bytes", + name: "_message", + type: "bytes", + }, + { + internalType: "bytes32[]", + name: "_merkleProof", + type: "bytes32[]", + }, + ], + name: "finalizeWithdrawalLegacyErc20Bridge", + outputs: [ + { + internalType: "address", + name: "l1Receiver", + type: "address", + }, + { + internalType: "address", + name: "l1Token", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2BatchNumber", + type: "uint256", + }, + { + internalType: "uint256", + name: "_l2MessageIndex", + type: "uint256", + }, + ], + name: "isWithdrawalFinalized", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "l1WethAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + ], + name: "l2BridgeAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "legacyBridge", + outputs: [ + { + internalType: "contract IL1ERC20Bridge", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_chainId", + type: "uint256", + }, + ], + name: "receiveEth", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_eraFirstPostUpgradeBatch", + type: "uint256", + }, + ], + name: "setEraFirstPostUpgradeBatch", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +]; diff --git a/src/utils.ts b/src/utils.ts index 80641f84..2ec14719 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,19 +13,19 @@ import {TypedDataDomain, TypedDataField} from '@ethersproject/abstract-signer'; import {Provider} from './provider'; import {EIP712Signer} from './signer'; import {Ierc20Factory as IERC20Factory} from './typechain/Ierc20Factory'; -import {Il1BridgeFactory as IL1BridgeFactory} from './typechain/Il1BridgeFactory'; import {AbiCoder} from 'ethers/lib/utils'; export * from './paymaster-utils'; export * from './smart-account-utils'; export {EIP712_TYPES} from './signer'; -import IZkSyncABI from '../abi/IZkSync.json'; +import IZkSyncABI from '../abi/IZkSyncStateTransition.json'; +import IBridgehubABI from '../abi/IBridgehub.json'; import IContractDeployerABI from '../abi/IContractDeployer.json'; import IL1MessengerABI from '../abi/IL1Messenger.json'; import IERC20ABI from '../abi/IERC20.json'; import IERC1271ABI from '../abi/IERC1271.json'; -import IL1BridgeABI from '../abi/IL1Bridge.json'; +import IL1BridgeABI from '../abi/IL1ERC20Bridge.json'; import IL2BridgeABI from '../abi/IL2Bridge.json'; import INonceHolderABI from '../abi/INonceHolder.json'; @@ -35,6 +35,12 @@ import INonceHolderABI from '../abi/INonceHolder.json'; */ export const ZKSYNC_MAIN_ABI = new utils.Interface(IZkSyncABI); +/** + * The ABI of the `Bridgehub` interface. + * @constant + */ +export const BRIDGEHUB_ABI = new utils.Interface(IBridgehubABI); + /** * The ABI for the `IContractDeployer` interface, which is utilized for deploying smart contracts. * @constant @@ -83,6 +89,19 @@ export const NONCE_HOLDER_ABI = new utils.Interface(INonceHolderABI); */ export const ETH_ADDRESS = '0x0000000000000000000000000000000000000000'; +/** + * The address of the L1 `ETH` token. + * @constant + */ +export const LEGACY_ETH_ADDRESS = '0x0000000000000000000000000000000000000000'; + +/** + * In the contracts the zero address can not be used, use one instead. + * @constant + */ +export const ETH_ADDRESS_IN_CONTRACTS = + '0x0000000000000000000000000000000000000001'; + /** * The formal address for the `Bootloader`. * @constant @@ -107,10 +126,18 @@ export const L1_MESSENGER_ADDRESS = /** * The address of the L2 `ETH` token. * @constant + * @deprecated In favor of {@link L2_BASE_TOKEN_ADDRESS}. */ export const L2_ETH_TOKEN_ADDRESS = '0x000000000000000000000000000000000000800a'; +/** + * The address of the base token. + * @constant + */ +export const L2_BASE_TOKEN_ADDRESS = + '0x000000000000000000000000000000000000800a'; + /** * The address of the Nonce holder. * @constant @@ -222,12 +249,13 @@ export const REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT = 800; * @example * * const isL1ETH = utils.isETH(utils.ETH_ADDRESS); // true - * const isL2ETH = utils.isETH(utils.L2_ETH_TOKEN_ADDRESS); // true + * const isL2ETH = utils.isETH(utils.ETH_ADDRESS_IN_CONTRACTS); // true */ -export function isETH(token: Address): boolean { +export function isETH(token: Address) { return ( - token.toLowerCase() === ETH_ADDRESS || - token.toLowerCase() === L2_ETH_TOKEN_ADDRESS + token.toLowerCase() === LEGACY_ETH_ADDRESS || + token.toLowerCase() === L2_BASE_TOKEN_ADDRESS || + token.toLowerCase() === ETH_ADDRESS_IN_CONTRACTS ); } @@ -873,9 +901,12 @@ export async function getERC20DefaultBridgeData( ): Promise { const token = IERC20Factory.connect(l1TokenAddress, provider); - const name = await token.name(); - const symbol = await token.symbol(); - const decimals = await token.decimals(); + const name = + l1TokenAddress === ETH_ADDRESS_IN_CONTRACTS ? 'Ether' : await token.name(); + const symbol = + l1TokenAddress === ETH_ADDRESS_IN_CONTRACTS ? 'ETH' : await token.symbol(); + const decimals = + l1TokenAddress === ETH_ADDRESS_IN_CONTRACTS ? 18 : await token.decimals(); const coder = new AbiCoder(); @@ -1006,10 +1037,8 @@ async function isSignatureCorrect( msgHash: string, signature: SignatureLike ): Promise { - let isContractAccount = false; - const code = await provider.getCode(address); - isContractAccount = ethers.utils.arrayify(code).length !== 0; + const isContractAccount = ethers.utils.arrayify(code).length !== 0; if (!isContractAccount) { return isECDSASignatureCorrect(address, msgHash, signature); @@ -1137,8 +1166,7 @@ export async function estimateDefaultBridgeDepositL2Gas( // due to storage slot aggregation, the gas estimation will depend on the address // and so estimation for the zero address may be smaller than for the sender. from ??= ethers.Wallet.createRandom().address; - - if (token === ETH_ADDRESS) { + if (await providerL2.isBaseToken(token)) { return await providerL2.estimateL1ToL2Execute({ contractAddress: to, gasPerPubdataByte: gasPerPubdataByte, @@ -1147,35 +1175,17 @@ export async function estimateDefaultBridgeDepositL2Gas( l2Value: amount, }); } else { - let value, l1BridgeAddress, l2BridgeAddress, bridgeData; const bridgeAddresses = await providerL2.getDefaultBridgeAddresses(); - const l1WethBridge = IL1BridgeFactory.connect( - bridgeAddresses.wethL1!, - providerL1 - ); - let l2WethToken = ethers.constants.AddressZero; - try { - l2WethToken = await l1WethBridge.l2TokenAddress(token); - } catch (e) { - // skip - } - if (l2WethToken !== ethers.constants.AddressZero) { - value = amount; - l1BridgeAddress = bridgeAddresses.wethL1; - l2BridgeAddress = bridgeAddresses.wethL2; - bridgeData = '0x'; - } else { - value = 0; - l1BridgeAddress = bridgeAddresses.erc20L1; - l2BridgeAddress = bridgeAddresses.erc20L2; - bridgeData = await getERC20DefaultBridgeData(token, providerL1); - } + const value = 0; + const l1BridgeAddress = bridgeAddresses.sharedL1; + const l2BridgeAddress = bridgeAddresses.sharedL2; + const bridgeData = await getERC20DefaultBridgeData(token, providerL1); return await estimateCustomBridgeDepositL2Gas( providerL2, - l1BridgeAddress!, - l2BridgeAddress!, + l1BridgeAddress, + l2BridgeAddress, token, amount, to, @@ -1263,7 +1273,7 @@ export async function estimateCustomBridgeDepositL2Gas( export function toJSON(object: any): string { return JSON.stringify( object, - (key, value) => { + (_, value) => { if (typeof value === 'bigint') { return value.toString(); // Convert BigInt to string } diff --git a/src/wallet.ts b/src/wallet.ts index fcd7e3a9..622a9f6a 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -23,9 +23,11 @@ import { } from './types'; import {ProgressCallback} from '@ethersproject/json-wallets'; import {AdapterL1, AdapterL2} from './adapters'; -import {IZkSync} from './typechain/IZkSync'; -import {Il1Bridge} from './typechain/Il1Bridge'; -import {Il2Bridge} from './typechain/Il2Bridge'; +import {IZkSyncStateTransition} from './typechain/IZkSyncStateTransition'; +import {Il1Erc20Bridge as IL1ERC20Bridge} from './typechain/Il1Erc20Bridge'; +import {Il1SharedBridge as IL1SharedBridge} from './typechain/Il1SharedBridge'; +import {Il2Bridge as IL2Bridge} from './typechain/Il2Bridge'; +import {IBridgehub} from './typechain/IBridgehub'; /** * A `Wallet` is an extension of {@link ethers.Wallet} with additional features for interacting with zkSync Era. @@ -39,7 +41,9 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { override _providerL1(): ethers.providers.Provider { if (!this.providerL1) { - throw new Error('L1 provider missing: use `connectToL1` to specify!'); + throw new Error( + 'L1 provider is missing! Use `Wallet.connectToL1()` to connect to L1!' + ); } return this.providerL1; } @@ -70,12 +74,32 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { * const ethProvider = ethers.getDefaultProvider("sepolia"); * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); * - * console.log(`Main contract: ${await wallet.getMainContract()}`); + * const mainContract = await wallet.getMainContract(); */ - override async getMainContract(): Promise { + override async getMainContract(): Promise { return super.getMainContract(); } + /** + * @inheritDoc + * + * @example + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const bridgehub = await wallet.getBridgehubContract(); + */ + override async getBridgehubContract(): Promise { + return super.getBridgehubContract(); + } + /** * @inheritDoc * @@ -93,8 +117,8 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { * const l1BridgeContracts = await wallet.getL1BridgeContracts(); */ override async getL1BridgeContracts(): Promise<{ - erc20: Il1Bridge; - weth: Il1Bridge; + erc20: IL1ERC20Bridge; + shared: IL1SharedBridge; }> { return super.getL1BridgeContracts(); } @@ -238,25 +262,229 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { * const ethProvider = ethers.getDefaultProvider("sepolia"); * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); * + * console.log(`Base token: ${await wallet.getBaseToken()}`); + */ + override async getBaseToken(): Promise { + return super.getBaseToken(); + } + + /** + * @inheritDoc + * + * @example + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * console.log(`Is ETH-based chain: ${await wallet.isETHBasedChain()}`); + */ + override async isETHBasedChain(): Promise { + return super.isETHBasedChain(); + } + + /** + * @inheritDoc + * + * @example Get allowance parameters for depositing ETH on non-ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const token = utils.LEGACY_ETH_ADDRESS; + * const amount = 5; + * const approveParams = await wallet.getDepositAllowanceParams(token, amount); + * + * await ( + * await wallet.approveERC20( + * approveParams[0].token, + * approveParams[0].allowance + * ) + * ).wait(); + * + * @example Get allowance parameters for depositing base token on non-ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const token = await wallet.getBaseToken(); + * const amount = 5; + * const approveParams = await wallet.getDepositAllowanceParams(token, amount); + * + * await ( + * await wallet.approveERC20( + * approveParams[0].token, + * approveParams[0].allowance + * ) + * ).wait(); + * + * @example Get allowance parameters for depositing non-base token on non-ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const token = ""; + * const amount = 5; + * const approveParams = await wallet.getDepositAllowanceParams(token, amount); + * + * await ( + * await wallet.approveERC20( + * approveParams[0].token, + * approveParams[0].allowance + * ) + * ).wait(); + * + * await ( + * await wallet.approveERC20( + * approveParams[1].token, + * approveParams[1].allowance + * ) + * ).wait(); + */ + override async getDepositAllowanceParams( + token: Address, + amount: BigNumberish + ): Promise< + { + token: Address; + allowance: BigNumberish; + }[] + > { + return super.getDepositAllowanceParams(token, amount); + } + + /** + * @inheritDoc + * + * @example Deposit ETH on ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const tx = await wallet.deposit({ + * token: utils.ETH_ADDRESS, + * amount: 10_000_000, + * }); + * // Note that we wait not only for the L1 transaction to complete but also for it to be + * // processed by zkSync. If we want to wait only for the transaction to be processed on L1, + * // we can use `await tx.waitL1Commit()` + * await tx.wait(); + * + * @example Deposit token on ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * * const tokenL1 = "0x56E69Fa1BB0d1402c89E3A4E3417882DeA6B14Be"; - * const tokenDepositHandle = await wallet.deposit({ + * const tx = await wallet.deposit({ * token: tokenL1, - * amount: "10000000", + * amount: 10_000_000, * approveERC20: true, * }); * // Note that we wait not only for the L1 transaction to complete but also for it to be * // processed by zkSync. If we want to wait only for the transaction to be processed on L1, - * // we can use `await tokenDepositHandle.waitL1Commit()` - * await tokenDepositHandle.wait(); + * // we can use `await tx.waitL1Commit()` + * await tx.wait(); + * + * @example Deposit ETH on non-ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); * - * const ethDepositHandle = await wallet.deposit({ + * const tx = await wallet.deposit({ * token: utils.ETH_ADDRESS, - * amount: "10000000", + * amount: 10_000_000, + * approveBaseERC20: true, * }); * // Note that we wait not only for the L1 transaction to complete but also for it to be * // processed by zkSync. If we want to wait only for the transaction to be processed on L1, - * // we can use `await ethDepositHandle.waitL1Commit()` - * await ethDepositHandle.wait(); + * // we can use `await tx.waitL1Commit()` + * await tx.wait(); + * + * @example Deposit base token on non-ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const tx = await wallet.deposit({ + * token: await wallet.getBaseToken(), + * amount: 10_000_000, + * approveERC20: true, // or approveBaseERC20: true + * }); + * // Note that we wait not only for the L1 transaction to complete but also for it to be + * // processed by zkSync. If we want to wait only for the transaction to be processed on L1, + * // we can use `await tx.waitL1Commit()` + * await tx.wait(); + * + * @example Deposit non-base token on non-ETH-based chain. + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const tokenL1 = "0x56E69Fa1BB0d1402c89E3A4E3417882DeA6B14Be"; + * const tx = await wallet.deposit({ + * token: tokenL1, + * amount: 10_000_000, + * approveERC20: true, + * approveBaseERC20: true, + * }); + * // Note that we wait not only for the L1 transaction to complete but also for it to be + * // processed by zkSync. If we want to wait only for the transaction to be processed on L1, + * // we can use `await tx.waitL1Commit()` + * await tx.wait(); */ override async deposit(transaction: { token: Address; @@ -265,11 +493,13 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { operatorTip?: BigNumberish; bridgeAddress?: Address; approveERC20?: boolean; + approveBaseERC20?: boolean; l2GasLimit?: BigNumberish; gasPerPubdataByte?: BigNumberish; refundRecipient?: Address; - overrides?: Overrides; - approveOverrides?: Overrides; + overrides?: ethers.PayableOverrides; + approveOverrides?: ethers.Overrides; + approveBaseOverrides?: ethers.Overrides; customBridgeData?: BytesLike; }): Promise { return super.deposit(transaction); @@ -475,6 +705,48 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { return super.claimFailedDeposit(depositHash, overrides); } + /** + * @inheritDoc + * + * @example + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const ethProvider = ethers.getDefaultProvider("sepolia"); + * const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + * + * const tx = { + * contractAddress: await wallet.getAddress(), + * calldata: '0x', + * l2Value: 7_000_000_000, + * }; + * + * const approveParams = await wallet.getRequestExecuteAllowanceParams(tx); + * await ( + * await wallet.approveERC20( + * approveParams.token, + * approveParams.allowance + * ) + * ).wait(); + */ + override async getRequestExecuteAllowanceParams(transaction: { + contractAddress: Address; + calldata: BytesLike; + l2GasLimit?: BigNumberish; + l2Value?: BigNumberish; + factoryDeps?: BytesLike[]; + operatorTip?: BigNumberish; + gasPerPubdataByte?: BigNumberish; + refundRecipient?: Address; + overrides?: ethers.PayableOverrides; + }): Promise<{token: Address; allowance: BigNumberish}> { + return super.getRequestExecuteAllowanceParams(transaction); + } + /** * @inheritDoc * @@ -768,8 +1040,7 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { * const l2BridgeContracts = await wallet.getL2BridgeContracts(); */ override async getL2BridgeContracts(): Promise<{ - erc20: Il2Bridge; - weth: Il2Bridge; + shared: IL2Bridge; }> { return super.getL2BridgeContracts(); } @@ -884,6 +1155,36 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { return super.transfer(transaction); } + /** + * @inheritDoc + * + * @example + * + * import { Wallet, Provider, utils } from "zksync-ethers"; + * import { ethers } from "ethers"; + * + * const PRIVATE_KEY = ""; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * const wallet = new Wallet(PRIVATE_KEY, provider); + * + * // Any L2 -> L1 transaction can be used. + * // In this case, withdrawal transaction is used. + * const tx = "0x2a1c6c74b184965c0cb015aae9ea134fd96215d2e4f4979cfec12563295f610e"; + * console.log(`Confirmation data: ${utils.toJSON(await wallet.getPriorityOpConfirmation(tx, 0))}`); + */ + override async getPriorityOpConfirmation( + txHash: string, + index = 0 + ): Promise<{ + l1BatchNumber: number; + l2MessageIndex: number; + l2TxNumberInBlock: number; + proof: string[]; + }> { + return super.getPriorityOpConfirmation(txHash, index); + } + /** * Returns `ethers.Wallet` object with the same private key. * @@ -1047,7 +1348,7 @@ export class Wallet extends AdapterL2(AdapterL1(ethers.Wallet)) { } /** - * Static methods to create Wallet instances. + * Creates random `Wallet`. * @param options Additional options. * * @example diff --git a/tests/custom-matchers.ts b/tests/custom-matchers.ts index c3c5fb15..492f07a9 100644 --- a/tests/custom-matchers.ts +++ b/tests/custom-matchers.ts @@ -1,4 +1,8 @@ import * as chai from 'chai'; +import {BigNumber} from 'ethers'; +import {types} from '../src'; + +const {expect} = chai; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace @@ -24,3 +28,49 @@ chai.Assertion.addMethod( } } ); + +// Custom assertion function for BigNumber values with a percentage tolerance +export function expectBigNumberCloseTo( + actual: BigNumber, + expected: BigNumber, + tolerancePercentage: number +) { + const actualPercentageDiff = actual + .sub(expected) + .mul(100) + .div(expected) + .abs(); + expect(actualPercentageDiff.lte(tolerancePercentage)).to.be.true; +} + +export function expectFeeDataCloseToExpected( + result: types.FullDepositFee, + expected: types.FullDepositFee, + tolerancePercentage: number +) { + expectBigNumberCloseTo( + result.baseCost, + expected.baseCost, + tolerancePercentage + ); + expectBigNumberCloseTo( + result.l1GasLimit, + expected.l1GasLimit, + tolerancePercentage + ); + expectBigNumberCloseTo( + result.l2GasLimit, + expected.l2GasLimit, + tolerancePercentage + ); + expectBigNumberCloseTo( + result.maxFeePerGas!, + expected.maxFeePerGas!, + tolerancePercentage + ); + expectBigNumberCloseTo( + result.maxPriorityFeePerGas!, + expected.maxPriorityFeePerGas!, + tolerancePercentage + ); +} diff --git a/tests/files/tokens.json b/tests/files/tokens.json index 1b9fdb79..da31cd61 100644 --- a/tests/files/tokens.json +++ b/tests/files/tokens.json @@ -1,98 +1,98 @@ [ - { - "name": "DAI", - "symbol": "DAI", - "decimals": 18, - "address": "0x70a0F165d6f8054d0d0CF8dFd4DD2005f0AF6B55" - }, - { - "name": "wBTC", - "symbol": "wBTC", - "decimals": 8, - "address": "0x1C552d7B40b38Fb1235697Bed7b8e1e47B46e5BA" - }, - { - "name": "BAT", - "symbol": "BAT", - "decimals": 18, - "address": "0xdF2Ff03eAAfae59fA7fd30D4f91ab045B3d5D95D" - }, - { - "name": "GNT", - "symbol": "GNT", - "decimals": 18, - "address": "0xeF81A0BB8819F94EEf15992F31555a282d7009d1" - }, - { - "name": "MLTT", - "symbol": "MLTT", - "decimals": 18, - "address": "0x9ad574a765F65Ec554780c2b5D97979Ed1957d30" - }, - { - "name": "DAIK", - "symbol": "DAIK", - "decimals": 18, - "address": "0x266B465D9D37cF6001d38b8e3f839fAE0e10D619" - }, - { - "name": "wBTCK", - "symbol": "wBTCK", - "decimals": 8, - "address": "0x05789138d7838a4707FFB45EA5B2c498B1e8Be3c" - }, - { - "name": "BATK", - "symbol": "BATS", - "decimals": 18, - "address": "0xfeC8FE20C644fab5d37B86E821A29F1abfEdFc55" - }, - { - "name": "GNTK", - "symbol": "GNTS", - "decimals": 18, - "address": "0xde617bf595d8090c63350CA3916b13FBD79f0E0a" - }, - { - "name": "MLTTK", - "symbol": "MLTTS", - "decimals": 18, - "address": "0x0B827231D3ECE7906361723170701941f5813191" - }, - { - "name": "DAIL", - "symbol": "DAIL", - "decimals": 18, - "address": "0x4EDe5c04d0eF5aDDD222cc7D3C4cbE23Ac7fD4F4" - }, - { - "name": "wBTCL", - "symbol": "wBTCP", - "decimals": 8, - "address": "0x2E694B999D7746Dcf3864E9C2F47a4daEBD65721" - }, - { - "name": "BATL", - "symbol": "BATW", - "decimals": 18, - "address": "0x0a1D1D084645a46E9E019da345684308701855b6" - }, - { - "name": "GNTL", - "symbol": "GNTW", - "decimals": 18, - "address": "0x1630bcE01eb41A9Fd5d49a14e5c6D52b1B127d17" - }, - { - "name": "MLTTL", - "symbol": "MLTTW", - "decimals": 18, - "address": "0xa60bc9ae6a6967CAC6D8b08e12a2EF087348Cd32" - }, - { - "name": "Wrapped Ether", - "symbol": "WETH", - "decimals": 18, - "address": "0x4A470422bFf67C34a3A565106118023059fa4E34" - } + { + "name": "DAI", + "symbol": "DAI", + "decimals": 18, + "address": "0x70a0F165d6f8054d0d0CF8dFd4DD2005f0AF6B55" + }, + { + "name": "wBTC", + "symbol": "wBTC", + "decimals": 8, + "address": "0xAfb5167116e6B833889018916594aC8040DbC05F" + }, + { + "name": "BAT", + "symbol": "BAT", + "decimals": 18, + "address": "0x8E9C82509488eD471A83824d20Dd474b8F534a0b" + }, + { + "name": "GNT", + "symbol": "GNT", + "decimals": 18, + "address": "0x54FCb2405EE4f574C4F09333d25c401E68aD3408" + }, + { + "name": "MLTT", + "symbol": "MLTT", + "decimals": 18, + "address": "0xBac0B12C39a7Bd98172aC283E71fD951D998E4ac" + }, + { + "name": "DAIK", + "symbol": "DAIK", + "decimals": 18, + "address": "0x414C663bFf0358623a1392C6B4C416DeD6fED244" + }, + { + "name": "wBTCK", + "symbol": "wBTCK", + "decimals": 8, + "address": "0xa45cfbb064d940615F3db0D61e3C316d5264B2be" + }, + { + "name": "BATK", + "symbol": "BATS", + "decimals": 18, + "address": "0x565439D05A8F7Fd26AA60A46b3026e9D74172292" + }, + { + "name": "GNTK", + "symbol": "GNTS", + "decimals": 18, + "address": "0xc118ac58c87F65318a70532f4F033B1786CCFF78" + }, + { + "name": "MLTTK", + "symbol": "MLTTS", + "decimals": 18, + "address": "0x3fad2B2E21eA1c96618Cc76a42Fb5a77c3f71c6F" + }, + { + "name": "DAIL", + "symbol": "DAIL", + "decimals": 18, + "address": "0x2B0f9ED4F5D95C6C0f0B093f9F210603EdbF4232" + }, + { + "name": "wBTCL", + "symbol": "wBTCP", + "decimals": 8, + "address": "0xa2Ed35BcE8c6cF76f2d830a48D234586DcCf2204" + }, + { + "name": "BATL", + "symbol": "BATW", + "decimals": 18, + "address": "0x1C552d7B40b38Fb1235697Bed7b8e1e47B46e5BA" + }, + { + "name": "GNTL", + "symbol": "GNTW", + "decimals": 18, + "address": "0x1f13B4147Fd8251Fd7b637f50423cB7BFee83B09" + }, + { + "name": "MLTTL", + "symbol": "MLTTW", + "decimals": 18, + "address": "0x09786e9dbC9DaAa02e490f8b010b9B027C6Fb44A" + }, + { + "name": "Wrapped Ether", + "symbol": "WETH", + "decimals": 18, + "address": "0x3c0E6C514fC91CcD894CadaBd0cB848332053c9c" + } ] diff --git a/tests/integration/account-abstraction.test.ts b/tests/integration/account-abstraction.test.ts index 1a7d2058..a5ac3871 100644 --- a/tests/integration/account-abstraction.test.ts +++ b/tests/integration/account-abstraction.test.ts @@ -3,6 +3,7 @@ import '../custom-matchers'; import {Provider, types, utils, Wallet, ContractFactory} from '../../src'; import {BigNumber, Contract, ethers} from 'ethers'; import {ECDSASmartAccount, MultisigECDSASmartAccount} from '../../src'; +import {PRIVATE_KEY1, ADDRESS1, APPROVAL_TOKEN, PAYMASTER} from '../utils'; const {expect} = chai; @@ -12,15 +13,8 @@ import Storage from '../files/Storage.json'; import MultisigAccount from '../files/TwoUserMultisig.json'; describe('Account Abstraction', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const provider = Provider.getDefaultProvider(types.Network.Localhost); - const wallet = new Wallet(PRIVATE_KEY, provider); - - const TOKEN = '0x841c43Fa5d8fFfdB9efE3358906f7578d8700Dd4'; - const PAYMASTER = '0xa222f0c183AFA73a8Bc1AFb48D34C88c9Bf7A174'; + const wallet = new Wallet(PRIVATE_KEY1, provider); it('use the ERC20 token for paying transaction fee', async () => { const InitMintAmount = BigNumber.from(10); @@ -114,7 +108,7 @@ describe('Account Abstraction', () => { it('use multisig account', async () => { const storageValue = BigNumber.from(500); - const account = ECDSASmartAccount.create(ADDRESS, PRIVATE_KEY, provider); + const account = ECDSASmartAccount.create(ADDRESS1, PRIVATE_KEY1, provider); const multisigAccountAbi = MultisigAccount.abi; const multisigAccountBytecode: string = MultisigAccount.bytecode; @@ -143,11 +137,11 @@ describe('Account Abstraction', () => { // send paymaster approval token to multisig account const sendApprovalTokenTx = await new Wallet( - PRIVATE_KEY, + PRIVATE_KEY1, provider ).transfer({ to: multisigAddress, - token: TOKEN, + token: APPROVAL_TOKEN, amount: 5, }); await sendApprovalTokenTx.wait(); @@ -191,7 +185,7 @@ describe('Account Abstraction', () => { const minimalAllowance = BigNumber.from(1); const storageValue = BigNumber.from(700); - const account = ECDSASmartAccount.create(ADDRESS, PRIVATE_KEY, provider); + const account = ECDSASmartAccount.create(ADDRESS1, PRIVATE_KEY1, provider); const storageAbi = Storage.contracts['Storage.sol:Storage'].abi; const storageBytecode: string = @@ -204,13 +198,14 @@ describe('Account Abstraction', () => { const storage = (await storageFactory.deploy()) as Contract; const accountBalanceBeforeTx = await account.getBalance(); - const accountApprovalTokenBalanceBeforeTx = await account.getBalance(TOKEN); + const accountApprovalTokenBalanceBeforeTx = + await account.getBalance(APPROVAL_TOKEN); const paymasterSetTx = await storage.set(storageValue, { customData: { paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -219,7 +214,8 @@ describe('Account Abstraction', () => { await paymasterSetTx.wait(); const accountBalanceAfterTx = await account.getBalance(); - const accountApprovalTokenBalanceAfterTx = await account.getBalance(TOKEN); + const accountApprovalTokenBalanceAfterTx = + await account.getBalance(APPROVAL_TOKEN); expect(accountBalanceBeforeTx.eq(accountBalanceAfterTx)).to.be.true; expect( diff --git a/tests/integration/contract.test.ts b/tests/integration/contract.test.ts index 75c7ddcf..9de736ac 100644 --- a/tests/integration/contract.test.ts +++ b/tests/integration/contract.test.ts @@ -2,23 +2,18 @@ import * as chai from 'chai'; import '../custom-matchers'; import {ContractFactory, Provider, types, Wallet, Contract} from '../../src'; import {ethers} from 'ethers'; +import {PRIVATE_KEY1, DAI_L1} from '../utils'; const {expect} = chai; -import TokensL1 from '../files/tokens.json'; import Token from '../files/Token.json'; import Paymaster from '../files/Paymaster.json'; import Storage from '../files/Storage.json'; import Demo from '../files/Demo.json'; describe('ContractFactory', () => { - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const provider = Provider.getDefaultProvider(types.Network.Localhost); - const wallet = new Wallet(PRIVATE_KEY, provider); - - const DAI_L1 = TokensL1[0].address; + const wallet = new Wallet(PRIVATE_KEY1, provider); describe('#constructor()', () => { it('`ContractFactory(abi, bytecode, runner)` should return a `ContractFactory` with `create` deployment', async () => { diff --git a/tests/integration/paymaster.test.ts b/tests/integration/paymaster.test.ts deleted file mode 100644 index f4d19684..00000000 --- a/tests/integration/paymaster.test.ts +++ /dev/null @@ -1,120 +0,0 @@ -import * as chai from 'chai'; -import '../custom-matchers'; -import {Provider, types, utils, Wallet, ContractFactory} from '../../src'; -import {Contract, ethers, BigNumber} from 'ethers'; - -const {expect} = chai; - -import Token from '../files/Token.json'; -import Paymaster from '../files/Paymaster.json'; - -describe('Paymaster', () => { - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - - const provider = Provider.getDefaultProvider(types.Network.Localhost); - const wallet = new Wallet(PRIVATE_KEY, provider); - - describe('#ApprovalBased', () => { - it('use ERC20 token to pay transaction fee', async () => { - const INIT_MINT_AMOUNT = 10; - const MINT_AMOUNT = 3; - const MINIMAL_ALLOWANCE = 1; - - const abi = Token.abi; - const bytecode: string = Token.bytecode; - const factory = new ContractFactory(abi, bytecode, wallet); - const tokenContract = (await factory.deploy( - 'Ducat', - 'Ducat', - 18 - )) as Contract; - const tokenAddress = tokenContract.address; - - // mint tokens to wallet, so it could pay fee with tokens - await tokenContract.mint(await wallet.getAddress(), INIT_MINT_AMOUNT); - - const paymasterAbi = Paymaster.abi; - const paymasterBytecode = Paymaster.bytecode; - const accountFactory = new ContractFactory( - paymasterAbi, - paymasterBytecode, - wallet, - 'createAccount' - ); - const paymasterContract = await accountFactory.deploy(tokenAddress); - const paymasterAddress = paymasterContract.address; - - // transfer ETH to paymaster so it could pay fee - const faucetTx = await wallet.transfer({ - token: utils.ETH_ADDRESS, - to: paymasterAddress, - amount: ethers.utils.parseEther('0.01'), - }); - await faucetTx.wait(); - - const paymasterBalanceBeforeTx = - await provider.getBalance(paymasterAddress); - const paymasterTokenBalanceBeforeTx = await provider.getBalance( - paymasterAddress, - 'latest', - tokenAddress - ); - const walletBalanceBeforeTx = await wallet.getBalance(); - const walletTokenBalanceBeforeTx = await wallet.getBalance(tokenAddress); - - // perform tx using paymaster - const tokenAbi = new ethers.utils.Interface(Token.abi); - const tx = await wallet.sendTransaction({ - to: tokenAddress, - data: tokenAbi.encodeFunctionData('mint', [ - await wallet.getAddress(), - MINT_AMOUNT, - ]), - customData: { - gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, - paymasterParams: utils.getPaymasterParams(paymasterAddress, { - type: 'ApprovalBased', - token: tokenAddress, - minimalAllowance: BigNumber.from(MINIMAL_ALLOWANCE), - innerInput: new Uint8Array(), - }), - }, - }); - await tx.wait(); - - const paymasterBalanceAfterTx = - await provider.getBalance(paymasterAddress); - const paymasterTokenBalanceAfterTx = await provider.getBalance( - paymasterAddress, - 'latest', - tokenAddress - ); - const walletBalanceAfterTx = await wallet.getBalance(); - const walletTokenBalanceAfterTx = await wallet.getBalance(tokenAddress); - - expect(paymasterTokenBalanceBeforeTx.isZero()).to.be.true; - expect(walletTokenBalanceBeforeTx.eq(BigNumber.from(INIT_MINT_AMOUNT))).to - .be.true; - - expect( - paymasterBalanceBeforeTx - .sub(paymasterBalanceAfterTx) - .gte(BigNumber.from(0)) - ).to.be.true; - expect(paymasterTokenBalanceAfterTx.eq(BigNumber.from(MINIMAL_ALLOWANCE))) - .to.be.true; - - expect( - walletBalanceBeforeTx.sub(walletBalanceAfterTx).gte(BigNumber.from(0)) - ).to.be.true; - expect( - walletTokenBalanceAfterTx.eq( - walletTokenBalanceBeforeTx - .sub(BigNumber.from(MINIMAL_ALLOWANCE)) - .add(BigNumber.from(MINT_AMOUNT)) - ) - ).to.be.true; - }).timeout(30_000); - }); -}); diff --git a/tests/integration/provider.test.ts b/tests/integration/provider.test.ts index d3e50bb0..da04d9e8 100644 --- a/tests/integration/provider.test.ts +++ b/tests/integration/provider.test.ts @@ -2,30 +2,29 @@ import {expect} from 'chai'; import '../custom-matchers'; import {Provider, types, utils, Wallet} from '../../src'; import {BigNumber, ethers} from 'ethers'; - -import TokensL1 from '../files/tokens.json'; +import { + IS_ETH_BASED, + PRIVATE_KEY1, + ADDRESS1, + ADDRESS2, + DAI_L1, + APPROVAL_TOKEN, + PAYMASTER, +} from '../utils'; describe('Provider', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const provider = Provider.getDefaultProvider(); - const wallet = new Wallet(PRIVATE_KEY, provider); - - const DAI_L1 = TokensL1[0].address; - - const TOKEN = '0x841c43Fa5d8fFfdB9efE3358906f7578d8700Dd4'; - const PAYMASTER = '0xa222f0c183AFA73a8Bc1AFb48D34C88c9Bf7A174'; + const wallet = new Wallet(PRIVATE_KEY1, provider); let receipt: types.TransactionReceipt; + let baseToken: string; before('setup', async function () { this.timeout(25_000); + baseToken = await provider.getBaseTokenContractAddress(); const tx = await wallet.transfer({ - token: utils.ETH_ADDRESS, - to: RECEIVER, + token: utils.LEGACY_ETH_ADDRESS, + to: ADDRESS2, amount: 1_000_000, }); receipt = await tx.wait(); @@ -72,11 +71,17 @@ describe('Provider', () => { }); }); + describe('#getBridgehubContractAddress()', () => { + it('should return the address of main contract', async () => { + const result = await provider.getBridgehubContractAddress(); + expect(result).not.to.be.null; + }); + }); + describe('#getTestnetPaymasterAddress()', () => { it('should return the address of testnet paymaster', async () => { - const TESTNET_PAYMASTER = '0x59067204f2789ffcb6eadb6be6c7cbb7be9fdc7c'; const result = await provider.getTestnetPaymasterAddress(); - expect(result).to.be.equal(TESTNET_PAYMASTER); + expect(result).not.to.be.null; }); }); @@ -104,13 +109,13 @@ describe('Provider', () => { describe('#getBalance()', () => { it('should return balance of the account at `address`', async () => { - const result = await provider.getBalance(ADDRESS); + const result = await provider.getBalance(ADDRESS1); expect(result.gte(BigNumber.from(0))).to.be.true; }); it('should return a DAI balance of the account at `address`', async () => { const result = await provider.getBalance( - ADDRESS, + ADDRESS1, 'latest', await provider.l2TokenAddress(DAI_L1) ); @@ -120,8 +125,9 @@ describe('Provider', () => { describe('#getAllAccountBalances()', () => { it('should return all balances of the account at `address`', async () => { - const result = await provider.getAllAccountBalances(ADDRESS); - expect(Object.keys(result)).to.have.lengthOf(2); // ETH and DAI + const result = await provider.getAllAccountBalances(ADDRESS1); + const expected = IS_ETH_BASED ? 2 : 3; + expect(Object.keys(result)).to.have.lengthOf(expected); }); }); @@ -141,13 +147,14 @@ describe('Provider', () => { }); }); - describe('#getBytecodeByHash()', () => { + describe('#getBytecodeByHash(txHash)', () => { it('should return bytecode of a contract', async () => { - const testnetPaymasterBytecode = - '0x000200000000000200090000000000020001000000010355000000800b0000390000004000b0043f00000000030100190000006003300270000000b2033001970000000102200190000000430000c13d000000040230008c0000004b0000413d000000000201043b000000e002200270000000b40420009c0000004f0000613d000000b50220009c000000630000c13d000000040230008a000000c00420008c000000630000413d0000000404100370000000000404043b000000b60540009c000000630000213d0000002305400039000000b706000041000000000735004b00000000070000190000000007068019000000b705500197000000000805004b0000000006008019000000b70550009c000000000607c019000000000506004b000000630000c13d0000000405400039000000000551034f000000000505043b000000b60650009c000000630000213d00000000045400190000002404400039000000000334004b000000630000213d0000002403100370000000000303043b000000b60430009c000000630000213d0000000002320049000000b703000041000002600420008c00000000040000190000000004034019000000b702200197000000000502004b000000000300a019000000b70220009c000000000304c019000000000203004b000000630000c13d0000008401100370000000000101043b000000010110008c000000630000213d0000004d0000013d0000000001000416000000000101004b000000630000c13d000000200100003900000100001004430000012000000443000000b301000041000002c50001042e000000000103004b000000630000c13d0000000001000019000002c50001042e000000040230008a000000600220008c000000630000413d0000004402100370000000000202043b000000b60420009c000000630000213d00000004042000390000000005430049000000b706000041000002600750008c00000000070000190000000007064019000000b708500197000000000908004b000000000600a019000000b70880009c000000000607c019000000000606004b000000650000613d0000000001000019000002c6000104300000000006000411000080010660008c000000990000c13d0000022406200039000000000661034f000000000606043b0000001f0550008a000000b707000041000000000856004b00000000080000190000000008078019000000b705500197000000b709600197000000000a59004b0000000007008019000000000559013f000000b70550009c000000000708c019000000000507004b000000630000c13d0000000004460019000000000541034f000000000505043b000000b60650009c000000630000213d00000000065300490000002003400039000000b707000041000000000863004b00000000080000190000000008072019000000b706600197000000b709300197000000000a69004b0000000007008019000000000669013f000000b70660009c000000000708c019000000000607004b000000630000c13d000000030650008c000000a50000213d000000b801000041000000800010043f0000002001000039000000840010043f0000003a01000039000000a40010043f000000d201000041000000c40010043f000000d301000041000000a20000013d000000b801000041000000800010043f0000002001000039000000840010043f0000002601000039000000a40010043f000000b901000041000000c40010043f000000ba01000041000000e40010043f000000bb01000041000002c600010430000000000631034f000000000606043b000000bc06600197000000bd0660009c000000dd0000c13d000000040550008a000000600650008c000000630000413d0000000403300039000000000631034f000000000606043b000900000006001d000000c00660009c000000630000213d0000004006300039000000000661034f0000002003300039000000000331034f000000000303043b000800000003001d000000000306043b000000b60630009c000000630000213d0000002406400039000000000465001900000000056300190000001f03500039000000b706000041000000000743004b00000000070000190000000007068019000000b703300197000000b708400197000000000983004b0000000006008019000000000383013f000000b70330009c000000000607c019000000000306004b000000630000c13d00070000000b001d000000000351034f000000000303043b000000c10630009c000000d70000813d000000bf063000390006002000000092000000060660017f000000b60760009c000000e70000a13d000000c40100004100000000001004350000004101000039000000040010043f000000c501000041000002c600010430000000b801000041000000800010043f0000002001000039000000840010043f0000001a01000039000000a40010043f000000be01000041000000c40010043f000000bf01000041000002c600010430000000400060043f000000800030043f00000020055000390000000006530019000000000446004b000000630000213d000000000451034f0000001f0530018f0000000506300272000000fa0000613d00000000070000190000000508700210000000000984034f000000000909043b000000a00880003900000000009804350000000107700039000000000867004b000000f20000413d000000000705004b000001090000613d0000000506600210000000000464034f0000000305500210000000a006600039000000000706043300000000075701cf000000000757022f000000000404043b0000010005500089000000000454022f00000000045401cf000000000474019f0000000000460435000000a0033000390000000000030435000300240020003d0000000301100360000000000101043b000000400400043d000000c20200004100000000002404350000000002000410000000c0032001970000002402400039000100000003001d0000000000320435000000c002100197000500000004001d0000000401400039000200000002001d000000000021043500000000010004140000000902000029000000040220008c000001240000c13d0000000003000031000000200130008c00000000040300190000002004008039000001550000013d000000b202000041000000b20310009c00000000010280190000000504000029000000b20340009c00000000020440190000004002200210000000c001100210000000000121019f000000c3011001c7000000090200002902c402bf0000040f000000050a00002900000000030100190000006003300270000000b203300197000000200430008c000000000403001900000020040080390000001f0540018f0000000506400272000001430000613d0000000007000019000000050870021000000000098a0019000000000881034f000000000808043b00000000008904350000000107700039000000000867004b0000013b0000413d000000000705004b000001520000613d0000000506600210000000000761034f00000005066000290000000305500210000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f0000000000560435000000000003001f00000001022001900000017d0000613d0000001f01400039000000600110018f0000000504100029000000000214004b00000000020000190000000102004039000400000004001d000000b60440009c000000d70000213d0000000102200190000000d70000c13d0000000402000029000000400020043f000000200230008c000000630000413d00000005020000290000000002020433000000080220006c000001a00000813d00000004030000290000006401300039000000d00200004100000000002104350000004401300039000000d1020000410000000000210435000000240130003900000029020000390000000000210435000000b8010000410000000000130435000000040130003900000020020000390000000000210435000000b201000041000000b20230009c00000000030180190000004001300210000000cc011001c7000002c600010430000000400200043d0000001f0430018f00000005053002720000018a0000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000001820000413d000000000604004b000001990000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000000b201000041000000b20420009c000000000201801900000040012002100000006002300210000000000121019f000002c60001043000000003060000290000004002600039000000010520036700000080026000390000000102200367000000000202043b000000000405043b00050000502400ad000000000504004b000001ad0000613d00000005544000f9000000000224004b0000020b0000c13d0000000404000029000000240240003900000001050000290000000000520435000000c6020000410000000000240435000000040240003900000002050000290000000000520435000000440240003900000008040000290000000000420435000000c705000041000000050240006c0000000005004019000800000005001d00000000020004140000000904000029000000040440008c000001f40000613d000000b201000041000000b20320009c00000000020180190000000404000029000000b20340009c00000000010440190000004001100210000000c002200210000000000112019f000000c8011001c7000000090200002902c402ba0000040f000000040a00002900000000030100190000006003300270000000b203300197000000200430008c000000000403001900000020040080390000001f0540018f0000000506400272000001e00000613d0000000007000019000000050870021000000000098a0019000000000881034f000000000808043b00000000008904350000000107700039000000000867004b000001d80000413d000000000705004b000001ef0000613d0000000506600210000000000761034f00000004066000290000000305500210000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f0000000000560435000000000003001f00000001022001900000020f0000613d0000001f01400039000000600110018f0000000401100029000000b60210009c000000d70000213d000000400010043f000000200130008c000000630000413d00000004010000290000000001010433000000000201004b0000000002000019000000010200c039000000000121004b000000630000c13d000000b2010000410000000002000414000000b20320009c0000000002018019000000c001200210000000050200006b000002500000c13d000080010200003902c402ba0000040f000002560000013d000000c40100004100000000001004350000001101000039000000da0000013d0000006002000039000000000403004b0000021f0000c13d0000000001020433000000050210008c000002490000413d000000b202000041000000b20310009c00000000010280190000000704000029000000b20340009c000000000402801900000040024002100000006001100210000000000121019f000002c6000104300000003f02300039000000c904200197000000400200043d0000000004420019000000000524004b00000000050000190000000105004039000000b60640009c000000d70000213d0000000105500190000000d70000c13d000000400040043f0000001f0430018f00000000083204360000000503300272000002380000613d000000000500001900000005065002100000000007680019000000000661034f000000000606043b00000000006704350000000105500039000000000635004b000002300000413d000700000008001d000000000504004b000002120000613d0000000503300210000000000131034f00000007033000290000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000130435000002120000013d000000400100043d0000006402100039000000ca0300004100000000003204350000004402100039000000cb03000041000002ab0000013d000000cd011001c7000080090200003900008001040000390000000503000029000000000500001902c402ba0000040f00000000030100190000006003300270000000b20030019d000000b205300198000002830000613d0000003f03500039000000c903300197000000400400043d0000000003340019000000000643004b00000000060000190000000106004039000000b60730009c000000d70000213d0000000106600190000000d70000c13d000000400030043f0000001f0350018f00000000045404360000000505500272000002740000613d000000000600001900000005076002100000000008740019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b0000026c0000413d000000000603004b000002830000613d0000000505500210000000000151034f00000000045400190000000303300210000000000504043300000000053501cf000000000535022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000151019f0000000000140435000000400100043d0000000102200190000002a60000613d000000200210003900000040030000390000000000320435000000080200002900000000002104350000004003100039000000600200043d00000000002304350000006003100039000000000402004b000002990000613d000000000400001900000000053400190000008006400039000000000606043300000000006504350000002004400039000000000524004b000002920000413d000000000332001900000000000304350000007f02200039000000060220017f000000b203000041000000b20420009c0000000002038019000000b20410009c000000000103801900000040011002100000006002200210000000000112019f000002c50001042e0000006402100039000000ce0300004100000000003204350000004402100039000000cf03000041000000000032043500000024021000390000002a030000390000000000320435000000b8020000410000000000210435000000040210003900000020030000390000000000320435000000b202000041000000b20310009c00000000010280190000004001100210000000cc011001c7000002c600010430000002bd002104210000000102000039000000000001042d0000000002000019000000000001042d000002c2002104230000000102000039000000000001042d0000000002000019000000000001042d000002c400000432000002c50001042e000002c600010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffff000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000038a24bc00000000000000000000000000000000000000000000000000000000817b17f0000000000000000000000000000000000000000000000000ffffffffffffffff800000000000000000000000000000000000000000000000000000000000000008c379a0000000000000000000000000000000000000000000000000000000004f6e6c7920626f6f746c6f616465722063616e2063616c6c207468697320636f6e747261637400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084000000800000000000000000ffffffff00000000000000000000000000000000000000000000000000000000949431dc00000000000000000000000000000000000000000000000000000000556e737570706f72746564207061796d617374657220666c6f770000000000000000000000000000000000000000000000000064000000800000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000010000000000000000dd62ed3e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000440000000000000000000000004e487b7100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002400000000000000000000000023b872dd00000000000000000000000000000000000000000000000000000000038a24bc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000000000000000000001ffffffe07327206163636f756e74000000000000000000000000000000000000000000004661696c656420746f207472616e7366657246726f6d2066726f6d207573657200000000000000000000000000000000000000840000000000000000000000000200000000000000000000000000000000000000000000000000000000000000626f6f746c6f61646572000000000000000000000000000000000000000000004661696c656420746f207472616e736665722066756e647320746f2074686520616c6c6f77616e63650000000000000000000000000000000000000000000000546865207573657220646964206e6f742070726f7669646520656e6f75676820546865207374616e64617264207061796d617374657220696e707574206d757374206265206174206c656173742034206279746573206c6f6e670000000000003e3fedd1037ff662aaf95f9c82a9391df33ea5e806aeb952e06b321484d378cb'; + const testnetPaymasterBytecode = await provider.getCode( + (await provider.getTestnetPaymasterAddress()) as string + ); const tokenFactoryDepsHash = ethers.utils.hexlify( utils.hashBytecode(testnetPaymasterBytecode) - ); // "0x0100012539970918b0ab79e00660723a76fed0d6dac333c9298fdbb8628407f2"; + ); const result = await provider.getBytecodeByHash(tokenFactoryDepsHash); expect(result).to.be.deep.equal( Array.from(ethers.utils.arrayify(testnetPaymasterBytecode)) @@ -251,7 +258,7 @@ describe('Provider', () => { const result = await provider.newFilter({ fromBlock: 0, toBlock: 5, - address: utils.L2_ETH_TOKEN_ADDRESS, + address: utils.L2_BASE_TOKEN_ADDRESS, }); expect(result).not.to.be.null; }); @@ -266,9 +273,16 @@ describe('Provider', () => { }); describe('#l2TokenAddress()', () => { - it('should return L2 token address', async () => { - const result = await provider.l2TokenAddress(utils.ETH_ADDRESS); - expect(result).to.be.equal(utils.ETH_ADDRESS); + it('should return the L2 base address', async () => { + const result = await provider.l2TokenAddress(baseToken); + expect(result).to.be.equal(utils.L2_BASE_TOKEN_ADDRESS); + }); + + it('should return the L2 ETH address', async () => { + if (!IS_ETH_BASED) { + const result = await provider.l2TokenAddress(utils.LEGACY_ETH_ADDRESS); + expect(result).not.to.be.null; + } }); it('should return the L2 DAI address', async () => { @@ -279,8 +293,8 @@ describe('Provider', () => { describe('#l1TokenAddress()', () => { it('should return L1 token address', async () => { - const result = await provider.l1TokenAddress(utils.ETH_ADDRESS); - expect(result).to.be.equal(utils.ETH_ADDRESS); + const result = await provider.l1TokenAddress(utils.LEGACY_ETH_ADDRESS); + expect(result).to.be.equal(utils.LEGACY_ETH_ADDRESS); }); it('should return the L1 DAI address', async () => { @@ -375,7 +389,7 @@ describe('Provider', () => { const result = await provider.getLogs({ fromBlock: 0, toBlock: 5, - address: utils.L2_ETH_TOKEN_ADDRESS, + address: utils.L2_BASE_TOKEN_ADDRESS, }); expect(result).not.to.be.null; }); @@ -384,29 +398,25 @@ describe('Provider', () => { describe('#getWithdrawTx()', () => { it('should return withdraw transaction', async () => { const tx = { - from: ADDRESS, + from: ADDRESS1, value: BigNumber.from(7_000_000_000), - to: ethers.utils.getAddress( - '0x000000000000000000000000000000000000800a' - ), + to: ethers.utils.getAddress(utils.L2_BASE_TOKEN_ADDRESS), data: '0x51cff8d900000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc049', }; const result = await provider.getWithdrawTx({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - to: ADDRESS, - from: ADDRESS, + to: ADDRESS1, + from: ADDRESS1, }); expect(result).to.be.deep.equal(tx); }); - it('should return an ETH withdraw transaction with paymaster parameters', async () => { + it('should return a withdraw transaction of the base token with paymaster parameters', async () => { const tx = { - from: ADDRESS, + from: ADDRESS1, value: BigNumber.from(7_000_000_000), - to: ethers.utils.getAddress( - '0x000000000000000000000000000000000000800a' - ), + to: ethers.utils.getAddress(utils.L2_BASE_TOKEN_ADDRESS), data: '0x51cff8d900000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc049', customData: { paymasterParams: { @@ -417,13 +427,13 @@ describe('Provider', () => { }, }; const result = await provider.getWithdrawTx({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - to: ADDRESS, - from: ADDRESS, + to: ADDRESS1, + from: ADDRESS1, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -433,26 +443,26 @@ describe('Provider', () => { it('should return a DAI withdraw transaction', async () => { const tx = { - from: ADDRESS, + from: ADDRESS1, to: ethers.utils.getAddress( - (await provider.getDefaultBridgeAddresses()).erc20L2 as string + (await provider.getDefaultBridgeAddresses()).sharedL2 as string ), data: '0xd9caed1200000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc04900000000000000000000000082b5ea13260346f4251c0940067a9117a6cf13840000000000000000000000000000000000000000000000000000000000000005', }; const result = await provider.getWithdrawTx({ token: await provider.l2TokenAddress(DAI_L1), amount: 5, - to: ADDRESS, - from: ADDRESS, + to: ADDRESS1, + from: ADDRESS1, }); expect(result).to.be.deepEqualExcluding(tx, ['data']); }); it('should return a DAI withdraw transaction with paymaster parameters', async () => { const tx = { - from: ADDRESS, + from: ADDRESS1, to: ethers.utils.getAddress( - (await provider.getDefaultBridgeAddresses()).erc20L2 as string + (await provider.getDefaultBridgeAddresses()).sharedL2 as string ), data: '0xd9caed1200000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc04900000000000000000000000082b5ea13260346f4251c0940067a9117a6cf13840000000000000000000000000000000000000000000000000000000000000005', customData: { @@ -466,11 +476,11 @@ describe('Provider', () => { const result = await provider.getWithdrawTx({ token: await provider.l2TokenAddress(DAI_L1), amount: 5, - to: ADDRESS, - from: ADDRESS, + to: ADDRESS1, + from: ADDRESS1, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -480,15 +490,15 @@ describe('Provider', () => { it('should return a withdraw transaction with `tx.from==tx.to` when `tx.to` is not provided', async () => { const tx = { - from: ADDRESS, + from: ADDRESS1, value: BigNumber.from(7_000_000_000), - to: '0x000000000000000000000000000000000000800A', + to: ethers.utils.getAddress(utils.L2_BASE_TOKEN_ADDRESS), data: '0x51cff8d900000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc049', }; const result = await provider.getWithdrawTx({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - from: ADDRESS, + from: ADDRESS1, }); expect(result).to.be.deep.equal(tx); }); @@ -496,7 +506,7 @@ describe('Provider', () => { it('should throw an error when `tx.to` and `tx.from` are not provided', async () => { try { await provider.getWithdrawTx({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 5, }); } catch (e) { @@ -509,10 +519,10 @@ describe('Provider', () => { it('should throw an error when `tx.amount!=tx.overrides.value', async () => { try { await provider.getWithdrawTx({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 5, - to: ADDRESS, - from: ADDRESS, + to: ADDRESS1, + from: ADDRESS1, overrides: {value: 7}, }); } catch (e) { @@ -526,15 +536,15 @@ describe('Provider', () => { describe('#getTransferTx()', () => { it('should return transfer transaction', async () => { const tx = { - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, value: 7_000_000_000, }; const result = await provider.getTransferTx({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - to: RECEIVER, - from: ADDRESS, + to: ADDRESS2, + from: ADDRESS1, }); expect(result).to.be.deep.equal(tx); }); @@ -542,8 +552,8 @@ describe('Provider', () => { it('should return an ETH transfer transaction with paymaster parameters', async () => { const tx = { type: utils.EIP712_TX_TYPE, - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, value: 7_000_000_000, customData: { paymasterParams: { @@ -554,13 +564,13 @@ describe('Provider', () => { }, }; const result = await provider.getTransferTx({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - to: RECEIVER, - from: ADDRESS, + to: ADDRESS2, + from: ADDRESS1, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -570,22 +580,22 @@ describe('Provider', () => { it('should return a DAI transfer transaction', async () => { const tx = { - from: ADDRESS, + from: ADDRESS1, to: await provider.l2TokenAddress(DAI_L1), data: '0xa9059cbb000000000000000000000000a61464658afeaf65cccaafd3a512b69a83b776180000000000000000000000000000000000000000000000000000000000000005', }; const result = await provider.getTransferTx({ token: await provider.l2TokenAddress(DAI_L1), amount: 5, - to: RECEIVER, - from: ADDRESS, + to: ADDRESS2, + from: ADDRESS1, }); expect(result).to.be.deep.equal(tx); }); it('should return a DAI transfer transaction with paymaster parameters', async () => { const tx = { - from: ADDRESS, + from: ADDRESS1, to: await provider.l2TokenAddress(DAI_L1), data: '0xa9059cbb000000000000000000000000a61464658afeaf65cccaafd3a512b69a83b776180000000000000000000000000000000000000000000000000000000000000005', customData: { @@ -599,11 +609,11 @@ describe('Provider', () => { const result = await provider.getTransferTx({ token: await provider.l2TokenAddress(DAI_L1), amount: 5, - to: RECEIVER, - from: ADDRESS, + to: ADDRESS2, + from: ADDRESS1, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -615,23 +625,26 @@ describe('Provider', () => { describe('#estimateGasWithdraw()', () => { it('should return gas estimation of withdraw transaction', async () => { const result = await provider.estimateGasWithdraw({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - to: ADDRESS, - from: ADDRESS, + to: ADDRESS1, + from: ADDRESS1, }); expect(result.gte(BigNumber.from(0))).to.be.true; }); it('should return a gas estimation of the withdraw transaction with paymaster', async () => { + const token = IS_ETH_BASED + ? utils.ETH_ADDRESS_IN_CONTRACTS + : await wallet.l2TokenAddress(utils.ETH_ADDRESS_IN_CONTRACTS); const result = await provider.estimateGasWithdraw({ - token: utils.ETH_ADDRESS, + token: token, amount: 7_000_000_000, - to: ADDRESS, - from: ADDRESS, + to: ADDRESS1, + from: ADDRESS1, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -643,23 +656,23 @@ describe('Provider', () => { describe('#estimateGasTransfer()', () => { it('should return gas estimation of transfer transaction', async () => { const result = await provider.estimateGasTransfer({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - to: RECEIVER, - from: ADDRESS, + to: ADDRESS2, + from: ADDRESS1, }); expect(result.gte(BigNumber.from(0))).to.be.true; }); it('should return a gas estimation of the transfer transaction with paymaster', async () => { const result = await provider.estimateGasTransfer({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, amount: 7_000_000_000, - to: RECEIVER, - from: ADDRESS, + to: ADDRESS2, + from: ADDRESS1, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -671,8 +684,8 @@ describe('Provider', () => { describe('#estimateGasL1()', () => { it('should return gas estimation of L1 transaction', async () => { const result = await provider.estimateGasL1({ - from: ADDRESS, - to: await provider.getMainContractAddress(), + from: ADDRESS1, + to: await provider.getBridgehubContractAddress(), value: 7_000_000_000, customData: { gasPerPubdata: 800, @@ -685,9 +698,9 @@ describe('Provider', () => { describe('#estimateL1ToL2Execute()', () => { it('should return gas estimation of L1 to L2 transaction', async () => { const result = await provider.estimateL1ToL2Execute({ - contractAddress: await provider.getMainContractAddress(), + contractAddress: await provider.getBridgehubContractAddress(), calldata: '0x', - caller: ADDRESS, + caller: ADDRESS1, l2Value: 7_000_000_000, }); expect(result.gte(BigNumber.from(0))).to.be.true; @@ -697,8 +710,8 @@ describe('Provider', () => { describe('#estimateFee()', () => { it('should return gas estimation of transaction', async () => { const result = await provider.estimateFee({ - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, value: BigNumber.from(7_000_000_000).toHexString(), }); expect(result).not.to.be.null; @@ -708,18 +721,18 @@ describe('Provider', () => { describe('#estimateGas()', () => { it('should return gas estimation of transaction', async () => { const result = await provider.estimateGas({ - from: ADDRESS, + from: ADDRESS1, to: await provider.l2TokenAddress(DAI_L1), - data: utils.IERC20.encodeFunctionData('approve', [RECEIVER, 1]), + data: utils.IERC20.encodeFunctionData('approve', [ADDRESS2, 1]), }); expect(result.gt(BigNumber.from(0))).to.be.true; }); it('should return a gas estimation of the EIP712 transaction', async () => { const result = await provider.estimateGas({ - from: ADDRESS, + from: ADDRESS1, to: await provider.l2TokenAddress(DAI_L1), - data: utils.IERC20.encodeFunctionData('approve', [RECEIVER, 1]), + data: utils.IERC20.encodeFunctionData('approve', [ADDRESS2, 1]), customData: { gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, }, @@ -731,7 +744,7 @@ describe('Provider', () => { describe('#getFilterChanges()', () => { it('should return filtered logs', async () => { const filter = await provider.newFilter({ - address: utils.L2_ETH_TOKEN_ADDRESS, + address: utils.L2_BASE_TOKEN_ADDRESS, topics: [ethers.utils.id('Transfer(address,address,uint256)')], }); const result = await provider.getFilterChanges(filter); diff --git a/tests/integration/signer.test.ts b/tests/integration/signer.test.ts index 4a197b11..fdc97d68 100644 --- a/tests/integration/signer.test.ts +++ b/tests/integration/signer.test.ts @@ -2,30 +2,38 @@ import * as chai from 'chai'; import '../custom-matchers'; import {Provider, utils, Wallet, L2VoidSigner, L1VoidSigner} from '../../src'; import {ethers, BigNumber} from 'ethers'; +import {ITestnetErc20TokenFactory} from '../../typechain/ITestnetErc20TokenFactory'; +import {IS_ETH_BASED, ADDRESS1, PRIVATE_KEY1, DAI_L1, ADDRESS2} from '../utils'; -import TokensL1 from '../files/tokens.json'; - +import { + expectBigNumberCloseTo, + expectFeeDataCloseToExpected, +} from '../custom-matchers'; const {expect} = chai; describe('L2VoidSigner', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const provider = Provider.getDefaultProvider(); - const signer = new L2VoidSigner(ADDRESS, provider); + const signer = new L2VoidSigner(ADDRESS1, provider); + + let baseToken: string; + + before('setup', async function () { + baseToken = await provider.getBaseTokenContractAddress(); + this.timeout(25_000); + }); describe('#constructor()', () => { it('`L2VoidSigner(address, provider)` should return a `L2VoidSigner` with L2 provider', async () => { - const signer = new L2VoidSigner(ADDRESS, provider); + const signer = new L2VoidSigner(ADDRESS1, provider); - expect(signer.address).to.be.equal(ADDRESS); + expect(signer.address).to.be.equal(ADDRESS1); expect(signer.provider).to.be.equal(provider); }); it('`L2VoidSigner(address)` should return a `L2VoidSigner` without L2 provider', async () => { - const signer = new L2VoidSigner(ADDRESS); + const signer = new L2VoidSigner(ADDRESS1); - expect(signer.address).to.be.equal(ADDRESS); + expect(signer.address).to.be.equal(ADDRESS1); expect(signer.provider).to.be.null; }); }); @@ -40,7 +48,8 @@ describe('L2VoidSigner', () => { describe('#getAllBalances()', () => { it('should return all balances', async () => { const result = await signer.getAllBalances(); - expect(Object.keys(result)).to.have.lengthOf(2); + const expected = IS_ETH_BASED ? 2 : 3; + expect(Object.keys(result)).to.have.lengthOf(expected); }); }); @@ -54,16 +63,16 @@ describe('L2VoidSigner', () => { describe('#getAddress()', () => { it('should return a `L2VoidSigner` address', async () => { const result = await signer.getAddress(); - expect(result).to.be.equal(ADDRESS); + expect(result).to.be.equal(ADDRESS1); }); }); describe('#connect()', () => { it('should return a `L2VoidSigner` with provided `provider` as L2 provider', async () => { - let signer = new L2VoidSigner(ADDRESS); + let signer = new L2VoidSigner(ADDRESS1); signer = signer.connect(provider); - expect(signer.address).to.be.equal(ADDRESS); + expect(signer.address).to.be.equal(ADDRESS1); expect(signer.provider).to.be.equal(provider); }); }); @@ -78,17 +87,17 @@ describe('L2VoidSigner', () => { describe('#populateTransaction()', () => { it('should return populated transaction with default values if are omitted', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 270, - maxFeePerGas: BigNumber.from(2_000_000_000), + maxFeePerGas: BigNumber.from(1_700_000_000), maxPriorityFeePerGas: BigNumber.from(1_500_000_000), }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); @@ -96,10 +105,10 @@ describe('L2VoidSigner', () => { it('should return populated transaction when `maxFeePerGas` and `maxPriorityFeePerGas` and `customData` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 113, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), data: '0x', chainId: 270, @@ -111,7 +120,7 @@ describe('L2VoidSigner', () => { }, }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -125,10 +134,10 @@ describe('L2VoidSigner', () => { it('should return populated transaction when `maxPriorityFeePerGas` and `customData` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 113, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), data: '0x', chainId: 270, @@ -139,7 +148,7 @@ describe('L2VoidSigner', () => { }, }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxPriorityFeePerGas: BigNumber.from(2_000_000_000), customData: { @@ -151,10 +160,10 @@ describe('L2VoidSigner', () => { it('should return populated transaction when `maxFeePerGas` and `customData` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 113, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), data: '0x', chainId: 270, @@ -165,7 +174,7 @@ describe('L2VoidSigner', () => { }, }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), customData: { @@ -177,17 +186,17 @@ describe('L2VoidSigner', () => { it('should return populated EIP1559 transaction when `maxFeePerGas` and `maxPriorityFeePerGas` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 270, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -197,17 +206,17 @@ describe('L2VoidSigner', () => { it('should return populated EIP1559 transaction with `maxFeePerGas` and `maxPriorityFeePerGas` same as provided `gasPrice`', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 270, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(3_500_000_000), }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, gasPrice: BigNumber.from(3_500_000_000), }); @@ -216,17 +225,17 @@ describe('L2VoidSigner', () => { it('should return populated legacy transaction when `type = 0`', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 0, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 270, - gasPrice: BigNumber.from(250_000_000), + gasPrice: BigNumber.from(100_000_000), }; const result = await signer.populateTransaction({ type: 0, - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); @@ -237,7 +246,7 @@ describe('L2VoidSigner', () => { it('should throw an error when trying to send transaction', async () => { try { await signer.sendTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -254,7 +263,7 @@ describe('L2VoidSigner', () => { it('should throw an error when tyring to withdraw assets', async () => { try { await signer.withdraw({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, to: await signer.getAddress(), amount: 7_000_000_000, }); @@ -270,8 +279,8 @@ describe('L2VoidSigner', () => { it('should throw an error when tyring to transfer assets', async () => { try { await signer.transfer({ - token: utils.ETH_ADDRESS, - to: RECEIVER, + token: baseToken, + to: ADDRESS2, amount: 7_000_000_000, }); } catch (e) { @@ -287,7 +296,7 @@ describe('L2VoidSigner', () => { try { await signer.signTransaction({ type: 2, - to: RECEIVER, + to: ADDRESS2, value: BigNumber.from(7_000_000_000), }); } catch (e) { @@ -300,36 +309,40 @@ describe('L2VoidSigner', () => { }); describe('L1VoidSigner', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const provider = Provider.getDefaultProvider(); const ethProvider = ethers.getDefaultProvider('http://localhost:8545'); - const signer = new L1VoidSigner(ADDRESS, ethProvider, provider); + const signer = new L1VoidSigner(ADDRESS1, ethProvider, provider); + + const tolerancePercentage = 10; // 10% tolerance - const DAI_L1 = TokensL1[0].address; + let baseToken: string; + + before('setup', async function () { + this.timeout(25_000); + baseToken = await provider.getBaseTokenContractAddress(); + }); describe('#constructor()', () => { it('`L1VoidSigner(privateKey, providerL1, providerL2)` should return a `L1VoidSigner` with L1 and L2 provider', async () => { - const signer = new L1VoidSigner(ADDRESS, ethProvider, provider); + const signer = new L1VoidSigner(ADDRESS1, ethProvider, provider); - expect(signer.address).to.be.equal(ADDRESS); + expect(signer.address).to.be.equal(ADDRESS1); expect(signer.provider).to.be.equal(ethProvider); expect(signer.providerL2).to.be.equal(provider); }); it('`L1VoidSigner(privateKey, providerL1)` should return a `L1VoidSigner` with L1 provider', async () => { - const signer = new L1VoidSigner(ADDRESS, ethProvider); + const signer = new L1VoidSigner(ADDRESS1, ethProvider); - expect(signer.address).to.be.equal(ADDRESS); + expect(signer.address).to.be.equal(ADDRESS1); expect(signer.provider).to.be.equal(ethProvider); expect(signer.providerL2).to.be.undefined; }); it('`L1VoidSigner(privateKey)` should return a `L1VoidSigner` without providers', async () => { - const signer = new L1VoidSigner(ADDRESS); + const signer = new L1VoidSigner(ADDRESS1); - expect(signer.address).to.be.equal(ADDRESS); + expect(signer.address).to.be.equal(ADDRESS1); expect(signer.provider).to.be.null; expect(signer.providerL2).to.be.undefined; }); @@ -365,20 +378,27 @@ describe('L1VoidSigner', () => { describe('#l2TokenAddress()', () => { it('should return the L2 ETH address', async () => { - const result = await signer.l2TokenAddress(utils.ETH_ADDRESS); - expect(result).to.be.equal(utils.ETH_ADDRESS); + const result = await signer.l2TokenAddress(baseToken); + expect(result).to.be.equal(utils.L2_BASE_TOKEN_ADDRESS); }); it('should return the L2 DAI address', async () => { const result = await signer.l2TokenAddress(DAI_L1); expect(result).not.to.be.null; }); + + if (!IS_ETH_BASED) { + it('should return the L2 ETH address', async () => { + const result = await signer.l2TokenAddress(utils.LEGACY_ETH_ADDRESS); + expect(result).not.to.be.null; + }); + } }); describe('#approveERC20()', () => { it('should throw an error when approving token', async () => { try { - await signer.approveERC20(utils.ETH_ADDRESS, 5); + await signer.approveERC20(utils.LEGACY_ETH_ADDRESS, 5); } catch (e) { expect((e as Error).message).to.be.equal( "ETH token can't be approved! The address of the token does not exist on L1." @@ -404,24 +424,24 @@ describe('L1VoidSigner', () => { describe('#getAddress()', () => { it('should return a `L1VoidSigner` address', async () => { const result = await signer.getAddress(); - expect(result).to.be.equal(ADDRESS); + expect(result).to.be.equal(ADDRESS1); }); }); describe('#connect()', () => { it('should return a `L1VoidSigner` with provided `provider` as L1 provider', async () => { - let singer = new L1VoidSigner(ADDRESS); + let singer = new L1VoidSigner(ADDRESS1); singer = singer.connect(ethProvider); - expect(singer.address).to.be.equal(ADDRESS); + expect(singer.address).to.be.equal(ADDRESS1); expect(singer.provider).to.be.equal(ethProvider); }); }); describe('#connectL2()', () => { it('should return a `L1VoidSigner` with provided `provider` as L2 provider', async () => { - let singer = new L1VoidSigner(ADDRESS); + let singer = new L1VoidSigner(ADDRESS1); singer = singer.connectToL2(provider); - expect(singer.address).to.be.equal(ADDRESS); + expect(singer.address).to.be.equal(ADDRESS1); expect(singer.providerL2).to.be.equal(provider); }); }); @@ -429,17 +449,17 @@ describe('L1VoidSigner', () => { describe('#populateTransaction()', () => { it('should return populated transaction with default values if are omitted', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 9, - maxFeePerGas: BigNumber.from(1_500_000_014), + maxFeePerGas: BigNumber.from(1_500_000_002), maxPriorityFeePerGas: BigNumber.from(1_500_000_000), }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); @@ -447,17 +467,17 @@ describe('L1VoidSigner', () => { it('should return populated EIP1559 transaction when `maxFeePerGas` and `maxPriorityFeePerGas` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 9, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -467,17 +487,17 @@ describe('L1VoidSigner', () => { it('should return populated EIP1559 transaction with `maxFeePerGas` and `maxPriorityFeePerGas` same as provided `gasPrice`', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 9, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(3_500_000_000), }; const result = await signer.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, gasPrice: BigNumber.from(3_500_000_000), }); @@ -486,17 +506,17 @@ describe('L1VoidSigner', () => { it('should return populated legacy transaction when `type = 0`', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 0, - from: ADDRESS, + from: ADDRESS1, nonce: await signer.getNonce('pending'), chainId: 9, - gasPrice: BigNumber.from(1_500_000_007), + gasPrice: BigNumber.from(1000000001), }; const result = await signer.populateTransaction({ type: 0, - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); @@ -507,7 +527,7 @@ describe('L1VoidSigner', () => { it('should throw an error when trying to send transaction', async () => { try { await signer.sendTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -521,113 +541,280 @@ describe('L1VoidSigner', () => { }); describe('#getDepositTx()', () => { - it('should return ETH deposit transaction', async () => { - const tx = { - contractAddress: ADDRESS, - calldata: '0x', - l2Value: 7_000_000, - l2GasLimit: BigNumber.from('0x08cbaa'), - token: '0x0000000000000000000000000000000000000000', - to: ADDRESS, - amount: 7_000_000, - refundRecipient: ADDRESS, - operatorTip: BigNumber.from(0), - overrides: { - maxFeePerGas: BigNumber.from(1_500_000_010), + if (IS_ETH_BASED) { + it('should return ETH deposit transaction', async () => { + const tx = { + contractAddress: ADDRESS1, + calldata: '0x', + l2Value: 7_000_000, + l2GasLimit: BigNumber.from(355_704), + mintValue: BigNumber.from(95_595_457_000_000), + token: utils.ETH_ADDRESS_IN_CONTRACTS, + to: ADDRESS1, + amount: 7_000_000, + refundRecipient: ADDRESS1, + operatorTip: BigNumber.from(0), + overrides: { + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + value: BigNumber.from(95_595_457_000_000), + }, + gasPerPubdataByte: 800, + }; + const result = await signer.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + to: await signer.getAddress(), + amount: 7_000_000, + refundRecipient: await signer.getAddress(), + }); + expect(result).to.be.deep.equal(tx); + }); + + it('should return a deposit transaction with `tx.to == L1VoidSigner.getAddress()` when `tx.to` is not specified', async () => { + const tx = { + contractAddress: ADDRESS1, + calldata: '0x', + l2Value: 7_000_000, + l2GasLimit: BigNumber.from(355_704), + mintValue: BigNumber.from(95_595_457_000_000), + token: utils.ETH_ADDRESS_IN_CONTRACTS, + to: ADDRESS1, + amount: 7_000_000, + refundRecipient: ADDRESS1, + operatorTip: BigNumber.from(0), + overrides: { + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + value: BigNumber.from(95_595_457_000_000), + }, + gasPerPubdataByte: 800, + }; + const result = await signer.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + amount: 7_000_000, + refundRecipient: await signer.getAddress(), + }); + expect(result).to.be.deep.equal(tx); + }); + + it('should return DAI deposit transaction', async () => { + const tx = { + maxFeePerGas: BigNumber.from(1_500_000_001), maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - value: BigNumber.from(288_213_007_000_000), - }, - gasPerPubdataByte: 800, - }; - const result = await signer.getDepositTx({ - token: utils.ETH_ADDRESS, - to: await signer.getAddress(), - amount: 7_000_000, - refundRecipient: await signer.getAddress(), + value: BigNumber.from(107_602_662_500_000), + from: ADDRESS1, + to: (await provider.getBridgehubContractAddress()).toLowerCase(), + }; + const result = await signer.getDepositTx({ + token: DAI_L1, + to: await signer.getAddress(), + amount: 5, + refundRecipient: await signer.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(result).to.be.deepEqualExcluding(tx, ['data']); + }); + } else { + it('should return ETH deposit transaction', async () => { + const tx = { + from: ADDRESS1, + to: (await provider.getBridgehubContractAddress()).toLowerCase(), + value: BigNumber.from(7_000_000), + data: '0x24fd57fb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000010e0000000000000000000000000000000000000000000000000000bf1aaa17ee7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062e3d000000000000000000000000000000000000000000000000000000000000032000000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc049000000000000000000000000842deab39809094bf5e4b77a7f97ae308adc5e5500000000000000000000000000000000000000000000000000000000006acfc0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc049', + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const result = await signer.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + to: await signer.getAddress(), + amount: 7_000_000, + refundRecipient: await signer.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(result).to.be.deepEqualExcluding(tx, ['data']); }); - expect(result).to.be.deep.equal(tx); - }); - it('should return a deposit transaction with `tx.to == L1VoidSigner.getAddress()` when `tx.to` is not specified', async () => { - const tx = { - contractAddress: ADDRESS, - calldata: '0x', - l2Value: 7_000_000, - l2GasLimit: BigNumber.from('0x8cbaa'), - token: '0x0000000000000000000000000000000000000000', - to: ADDRESS, - amount: 7_000_000, - refundRecipient: ADDRESS, - operatorTip: BigNumber.from(0), - overrides: { - maxFeePerGas: BigNumber.from(1_500_000_010), + it('should return a deposit transaction with `tx.to == Wallet.getAddress()` when `tx.to` is not specified', async () => { + const tx = { + from: ADDRESS1, + to: (await provider.getBridgehubContractAddress()).toLowerCase(), + value: BigNumber.from(7_000_000), + maxFeePerGas: BigNumber.from(1_500_000_001), maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - value: BigNumber.from(288_213_007_000_000), - }, - gasPerPubdataByte: 800, - }; - const result = await signer.getDepositTx({ - token: utils.ETH_ADDRESS, - amount: 7_000_000, - refundRecipient: await signer.getAddress(), + }; + const result = await signer.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + amount: 7_000_000, + refundRecipient: await signer.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(result).to.be.deepEqualExcluding(tx, ['data']); }); - expect(result).to.be.deep.equal(tx); - }); - it('should return DAI deposit transaction', async () => { - const tx = { - maxFeePerGas: BigNumber.from(1_500_000_010), - maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - value: BigNumber.from(288_992_000_000_000), - from: ADDRESS, - to: (await signer.getL1BridgeContracts()).erc20.address, - }; - const result = await signer.getDepositTx({ - token: DAI_L1, - to: await signer.getAddress(), - amount: 5, - refundRecipient: await signer.getAddress(), + it('should return DAI deposit transaction', async () => { + const tx = { + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + value: BigNumber.from(210_121_243_750_000), + from: ADDRESS1, + to: ethers.utils.getAddress( + await provider.getBridgehubContractAddress() + ), + }; + + const result = await signer.getDepositTx({ + token: DAI_L1, + to: await signer.getAddress(), + amount: 5, + refundRecipient: await signer.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(result).to.be.deepEqualExcluding(tx, ['data']); }); - result.to = result.to.toLowerCase(); - expect(result).to.be.deepEqualExcluding(tx, ['data']); - }); + } }); describe('#estimateGasDeposit()', () => { - it('should return gas estimation for ETH deposit transaction', async () => { - const result = await signer.estimateGasDeposit({ - token: utils.ETH_ADDRESS, - to: await signer.getAddress(), - amount: 5, - refundRecipient: await signer.getAddress(), - }); - expect(result.eq(BigNumber.from(132_711))).to.be.true; - }); - - it('should return gas estimation for DAI deposit transaction', async () => { - const wallet = new Wallet( - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110', - provider, - ethProvider - ); - const tx = await wallet.approveERC20(DAI_L1, 5); - await tx.wait(); - - const result = await signer.estimateGasDeposit({ - token: DAI_L1, - to: await signer.getAddress(), - amount: 5, - refundRecipient: await signer.getAddress(), + if (IS_ETH_BASED) { + it('should return gas estimation for ETH deposit transaction', async () => { + const result = await signer.estimateGasDeposit({ + token: utils.LEGACY_ETH_ADDRESS, + to: await signer.getAddress(), + amount: 5, + refundRecipient: await signer.getAddress(), + }); + expectBigNumberCloseTo( + result, + BigNumber.from(225_078), + tolerancePercentage + ); }); - expect(result.eq(BigNumber.from(253_418))).to.be.true; - }).timeout(10_000); + + it('should return gas estimation for DAI deposit transaction', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + await (await wallet.approveERC20(DAI_L1, 5)).wait(); + + const result = await signer.estimateGasDeposit({ + token: DAI_L1, + to: await signer.getAddress(), + amount: 5, + refundRecipient: await signer.getAddress(), + }); + expectBigNumberCloseTo( + result, + BigNumber.from(338_196), + tolerancePercentage + ); + }).timeout(10_000); + } else { + it('should throw an error for insufficient allowance when estimating gas for ETH deposit transaction', async () => { + try { + await signer.estimateGasDeposit({ + token: utils.LEGACY_ETH_ADDRESS, + to: await signer.getAddress(), + amount: 5, + refundRecipient: await signer.getAddress(), + }); + } catch (e) { + expect((e as any).reason).to.include('ERC20: insufficient allowance'); + } + }).timeout(10_000); + + it('should return gas estimation for ETH deposit transaction', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const token = utils.LEGACY_ETH_ADDRESS; + const amount = 5; + const approveParams = await signer.getDepositAllowanceParams( + token, + amount + ); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + + const result = await signer.estimateGasDeposit({ + token: token, + to: await signer.getAddress(), + amount: amount, + refundRecipient: await signer.getAddress(), + }); + expect(result.isZero()).to.be.false; + }).timeout(10_000); + + it('should return gas estimation for base token deposit transaction', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const token = await signer.getBaseToken(); + const amount = 5; + const approveParams = await signer.getDepositAllowanceParams( + token, + amount + ); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + + const result = await signer.estimateGasDeposit({ + token: token, + to: await signer.getAddress(), + amount: amount, + refundRecipient: await signer.getAddress(), + }); + expect(result.isZero()).to.be.false; + }).timeout(10_000); + + it('should return gas estimation for DAI deposit transaction', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const token = DAI_L1; + const amount = 5; + const approveParams = await signer.getDepositAllowanceParams( + token, + amount + ); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + await ( + await wallet.approveERC20( + approveParams[1].token, + approveParams[1].allowance + ) + ).wait(); + + const result = await signer.estimateGasDeposit({ + token: token, + to: await signer.getAddress(), + amount: amount, + refundRecipient: await signer.getAddress(), + }); + expectBigNumberCloseTo( + result, + BigNumber.from(361_501), + tolerancePercentage + ); + }).timeout(10_000); + } }); describe('#deposit()', () => { it('should throw an error when trying to deposit assets', async () => { try { await signer.deposit({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, to: await signer.getAddress(), amount: 7_000_000_000, refundRecipient: await signer.getAddress(), @@ -644,7 +831,7 @@ describe('L1VoidSigner', () => { it('should throw an error when trying to claim successful deposit', async () => { try { const response = await signer.deposit({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, to: await signer.getAddress(), amount: 7_000_000_000, refundRecipient: await signer.getAddress(), @@ -661,85 +848,258 @@ describe('L1VoidSigner', () => { }); describe('#getFullRequiredDepositFee()', () => { - it('should return fee for ETH token deposit', async () => { - const feeData = { - baseCost: BigNumber.from(285_096_500_000_000), - l1GasLimit: BigNumber.from(132_711), - l2GasLimit: BigNumber.from('0x08b351'), - maxFeePerGas: BigNumber.from(1_500_000_010), - maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - }; - const result = await signer.getFullRequiredDepositFee({ - token: utils.ETH_ADDRESS, - to: await signer.getAddress(), + if (IS_ETH_BASED) { + it('should return fee for ETH token deposit', async () => { + const fee = { + baseCost: BigNumber.from(95_595_450_000_000), + l1GasLimit: BigNumber.from(225_079), + l2GasLimit: BigNumber.from(355_704), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const result = await signer.getFullRequiredDepositFee({ + token: utils.LEGACY_ETH_ADDRESS, + to: await signer.getAddress(), + }); + + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); }); - expect(result).to.be.deep.equal(feeData); - }); - it('should throw an error when there is not enough allowance to cover the deposit', async () => { - try { - await signer.getFullRequiredDepositFee({ + it('should throw an error when there is not enough allowance to cover the deposit', async () => { + try { + await signer.getFullRequiredDepositFee({ + token: DAI_L1, + to: await signer.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Not enough allowance to cover the deposit!' + ); + } + }).timeout(10_000); + + it('should return fee for DAI token deposit', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const fee = { + baseCost: BigNumber.from(107_602_662_500_000), + l1GasLimit: BigNumber.from(337_820), + l2GasLimit: BigNumber.from(400_382), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + + const tx = await wallet.approveERC20(DAI_L1, 5); + await tx.wait(); + + const result = await signer.getFullRequiredDepositFee({ token: DAI_L1, to: await signer.getAddress(), }); - } catch (e) { - expect((e as Error).message).to.be.equal( - 'Not enough allowance to cover the deposit!' - ); - } - }).timeout(10_000); + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); + }).timeout(10_000); + + it('should throw an error when there is not enough balance for the deposit', async () => { + try { + await new L1VoidSigner( + ethers.Wallet.createRandom().address, + ethProvider, + provider + ).getFullRequiredDepositFee({ + token: DAI_L1, + to: await signer.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.include( + 'Not enough balance for deposit!' + ); + } + }).timeout(10_000); + } else { + it('should throw an error when there is not enough base token allowance to cover the deposit', async () => { + try { + await new L1VoidSigner( + ethers.Wallet.createRandom().address, + ethProvider, + provider + ).getFullRequiredDepositFee({ + token: utils.LEGACY_ETH_ADDRESS, + to: await signer.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Not enough base token allowance to cover the deposit!' + ); + } + }).timeout(10_000); + + it('should return fee for ETH token deposit', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const fee = { + baseCost: BigNumber.from(111_540_656_250_000), + l1GasLimit: BigNumber.from(321_051), + l2GasLimit: BigNumber.from(415_035), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const token = utils.LEGACY_ETH_ADDRESS; + const approveParams = await signer.getDepositAllowanceParams(token, 1); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + + const result = await signer.getFullRequiredDepositFee({ + token: token, + to: await signer.getAddress(), + }); - it('should return fee for DAI token deposit', async () => { - const feeData = { - baseCost: BigNumber.from(288_992_000_000_000), - l1GasLimit: BigNumber.from(253_177), - l2GasLimit: BigNumber.from('0x08d1c0'), - maxFeePerGas: BigNumber.from(1_500_000_010), - maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - }; + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); + }).timeout(10_000); - const result = await signer.getFullRequiredDepositFee({ - token: DAI_L1, - to: await signer.getAddress(), - }); - expect(result).to.be.deep.equal(feeData); - }).timeout(10_000); + it('should return fee for base token deposit', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + const token = await signer.getBaseToken(); + const approveParams = await signer.getDepositAllowanceParams(token, 1); - it('should throw an error when there is not enough balance for the deposit', async () => { - try { - const randomSigner = new L1VoidSigner( - ethers.Wallet.createRandom().address, - ethProvider, - provider - ); + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); - await randomSigner.getFullRequiredDepositFee({ - token: DAI_L1, - to: await randomSigner.getAddress(), + const result = await signer.getFullRequiredDepositFee({ + token: token, + to: await signer.getAddress(), }); - } catch (e) { - expect((e as Error).message).to.include( - 'Not enough balance for deposit!' + expect(result).not.to.be.null; + }).timeout(10_000); + + it('should return fee for DAI token deposit', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const fee = { + baseCost: BigNumber.from(107_602_662_500_000), + l1GasLimit: BigNumber.from(361_124), + l2GasLimit: BigNumber.from(400_382), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const token = DAI_L1; + const approveParams = await signer.getDepositAllowanceParams(token, 1); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + await ( + await wallet.approveERC20( + approveParams[1].token, + approveParams[1].allowance + ) + ).wait(); + + const result = await signer.getFullRequiredDepositFee({ + token: token, + to: await signer.getAddress(), + }); + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); + }).timeout(10_000); + + it('should throw an error when there is not enough token allowance to cover the deposit', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const token = DAI_L1; + const randomWallet = Wallet.createRandom() + .connectToL1(ethProvider) + .connect(provider); + + // mint base token to random wallet + const baseToken = ITestnetErc20TokenFactory.connect( + await wallet.getBaseToken(), + wallet._signerL1() ); - } - }).timeout(10_000); + const baseTokenMintTx = await baseToken.mint( + await randomWallet.getAddress(), + ethers.utils.parseEther('0.5') + ); + await baseTokenMintTx.wait(); + + // transfer ETH to random wallet so that base token approval tx can be performed + const transferTx = await new ethers.Wallet( + PRIVATE_KEY1, + ethProvider + ).sendTransaction({ + to: await randomWallet.getAddress(), + value: ethers.utils.parseEther('0.1'), + }); + await transferTx.wait(); + + const approveParams = await randomWallet.getDepositAllowanceParams( + token, + 1 + ); + // only approve base token + await ( + await randomWallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + + try { + await new L1VoidSigner( + randomWallet.address, + ethProvider, + provider + ).getFullRequiredDepositFee({ + token: token, + to: await wallet.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Not enough token allowance to cover the deposit!' + ); + } + }).timeout(20_000); + } }); describe('#getRequestExecuteTx()', () => { - it('should return request execute transaction', async () => { - const result = await signer.getRequestExecuteTx({ - contractAddress: await provider.getMainContractAddress(), - calldata: '0x', - l2Value: 7_000_000_000, + const amount = 7_000_000_000; + if (IS_ETH_BASED) { + it('should return request execute transaction', async () => { + const result = await signer.getRequestExecuteTx({ + contractAddress: await provider.getBridgehubContractAddress(), + calldata: '0x', + l2Value: amount, + }); + expect(result).not.to.be.null; }); - expect(result).not.to.be.null; - }); + } else { + it('should return request execute transaction', async () => { + const result = await signer.getRequestExecuteTx({ + contractAddress: await signer.getAddress(), + calldata: '0x', + l2Value: amount, + overrides: {nonce: 0}, + }); + expect(result).not.to.be.null; + }); + } }); describe('#estimateGasRequestExecute()', () => { it('should return gas estimation for request execute transaction', async () => { const result = await signer.estimateGasRequestExecute({ - contractAddress: await provider.getMainContractAddress(), + contractAddress: await provider.getBridgehubContractAddress(), calldata: '0x', l2Value: 7_000_000_000, }); @@ -748,27 +1108,67 @@ describe('L1VoidSigner', () => { }); describe('#requestExecute()', () => { - it('should request transaction execution on L2 network', async () => { - try { - await signer.requestExecute({ - contractAddress: await provider.getMainContractAddress(), + if (IS_ETH_BASED) { + it('should request transaction execution on L2 network', async () => { + try { + await signer.requestExecute({ + contractAddress: await provider.getBridgehubContractAddress(), + calldata: '0x', + l2Value: 7_000_000_000, + l2GasLimit: 900_000, + }); + } catch (e) { + expect((e as Error).message).to.contain( + 'VoidSigner cannot sign transactions' + ); + } + }).timeout(10_000); + } else { + it('should request transaction execution on L2 network', async () => { + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); + + const amount = 7_000_000_000; + const request = { + contractAddress: await signer.getAddress(), calldata: '0x', - l2Value: 7_000_000_000, - l2GasLimit: 900_000, - }); - } catch (e) { - expect((e as Error).message).to.contain( - 'VoidSigner cannot sign transactions' - ); - } - }).timeout(10_000); + l2Value: amount, + l2GasLimit: BigNumber.from(1_319_957), + operatorTip: 0, + gasPerPubdataByte: 800, + refundRecipient: await signer.getAddress(), + overrides: { + maxFeePerGas: BigNumber.from(1_500_000_010), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + gasLimit: BigNumber.from(238_654), + value: 0, + }, + }; + + const approveParams = + await signer.getRequestExecuteAllowanceParams(request); + await ( + await wallet.approveERC20( + approveParams.token, + approveParams.allowance + ) + ).wait(); + + try { + await signer.requestExecute(request); + } catch (e) { + expect((e as Error).message).to.contain( + 'VoidSigner cannot sign transactions' + ); + } + }).timeout(10_000); + } }); describe('#signTransaction()', () => { it('should throw an error when trying to send transaction', async () => { try { await signer.sendTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), diff --git a/tests/integration/smart-account.test.ts b/tests/integration/smart-account.test.ts index 5907315d..33a7e9a8 100644 --- a/tests/integration/smart-account.test.ts +++ b/tests/integration/smart-account.test.ts @@ -10,46 +10,47 @@ import { } from '../../src'; import {BigNumber, ethers} from 'ethers'; import {ECDSASmartAccount, MultisigECDSASmartAccount} from '../../src'; - +import { + IS_ETH_BASED, + ADDRESS1, + PRIVATE_KEY1, + ADDRESS2, + PRIVATE_KEY2, + APPROVAL_TOKEN, + PAYMASTER, + DAI_L1, +} from '../utils'; + +import {expectBigNumberCloseTo} from '../custom-matchers'; const {expect} = chai; -import TokensL1 from '../files/tokens.json'; import MultisigAccount from '../files/TwoUserMultisig.json'; describe('SmartAccount', async () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const provider = Provider.getDefaultProvider(types.Network.Localhost); const ethProvider = ethers.getDefaultProvider('http://localhost:8545'); - const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); const account = new SmartAccount( - {address: ADDRESS, secret: PRIVATE_KEY}, + {address: ADDRESS1, secret: PRIVATE_KEY1}, provider ); - - const DAI_L1 = TokensL1[0].address; - - const TOKEN = '0x841c43Fa5d8fFfdB9efE3358906f7578d8700Dd4'; - const PAYMASTER = '0xa222f0c183AFA73a8Bc1AFb48D34C88c9Bf7A174'; + const tolerancePercentage = 10; // 10% tolerance describe('#constructor()', () => { it('`SmartAccount(address, {address, secret}, provider)` should return a `SmartAccount` with signer and provider', () => { const account = new SmartAccount( - {address: ADDRESS, secret: PRIVATE_KEY}, + {address: ADDRESS1, secret: PRIVATE_KEY1}, provider ); - expect(account.address).to.be.equal(ADDRESS); - expect(account.secret).to.be.equal(PRIVATE_KEY); + expect(account.address).to.be.equal(ADDRESS1); + expect(account.secret).to.be.equal(PRIVATE_KEY1); expect(account.provider).to.be.equal(provider); }); it('`SmartWallet(address, {address, secret, payloadSigner, transactionBuilder}, provider)` should return a `SmartAccount` with custom payload signing method', async () => { const account = new SmartAccount( { - address: ADDRESS, - secret: PRIVATE_KEY, + address: ADDRESS1, + secret: PRIVATE_KEY1, payloadSigner: async () => { return '0x'; }, @@ -60,8 +61,8 @@ describe('SmartAccount', async () => { provider ); - expect(account.address).to.be.equal(ADDRESS); - expect(account.secret).to.be.equal(PRIVATE_KEY); + expect(account.address).to.be.equal(ADDRESS1); + expect(account.secret).to.be.equal(PRIVATE_KEY1); expect(account.provider).to.be.equal(provider); }); }); @@ -70,12 +71,12 @@ describe('SmartAccount', async () => { it('should return a `SmartAccount` with provided `provider` as a provider', async () => { const newProvider = Provider.getDefaultProvider(types.Network.Localhost); let account = new SmartAccount( - {address: ADDRESS, secret: PRIVATE_KEY}, + {address: ADDRESS1, secret: PRIVATE_KEY1}, provider ); account = account.connect(newProvider); - expect(account.address).to.be.equal(ADDRESS); - expect(account.secret).to.be.equal(PRIVATE_KEY); + expect(account.address).to.be.equal(ADDRESS1); + expect(account.secret).to.be.equal(PRIVATE_KEY1); expect(account.provider).to.be.equal(newProvider); }); }); @@ -83,11 +84,11 @@ describe('SmartAccount', async () => { describe('#getAddress()', () => { it('should return the `SmartAccount` address', async () => { const account = new SmartAccount( - {address: ADDRESS, secret: PRIVATE_KEY}, + {address: ADDRESS1, secret: PRIVATE_KEY1}, provider ); const result = await account.getAddress(); - expect(result).to.be.equal(ADDRESS); + expect(result).to.be.equal(ADDRESS1); }); }); @@ -101,7 +102,8 @@ describe('SmartAccount', async () => { describe('#getAllBalances()', () => { it('should return all balances', async () => { const result = await account.getAllBalances(); - expect(Object.keys(result)).to.have.lengthOf(2); + const expected = IS_ETH_BASED ? 2 : 3; + expect(Object.keys(result)).to.have.lengthOf(expected); }); }); @@ -115,40 +117,45 @@ describe('SmartAccount', async () => { describe('#populateTransaction()', () => { it('should return a populated transaction', async () => { const tx = { - to: '0xa61464658AfeAf65CccaaFD3a512b69A83B77618', + to: ADDRESS2, value: BigNumber.from(7_000_000_000), type: utils.EIP712_TX_TYPE, - from: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049', + from: ADDRESS1, nonce: await account.getNonce('pending'), - gasLimit: BigNumber.from(154_379), + gasLimit: BigNumber.from(156_726), chainId: 270, data: '0x', customData: {gasPerPubdata: 50_000, factoryDeps: []}, - gasPrice: BigNumber.from(250_000_000), + gasPrice: BigNumber.from(100_000_000), }; const result = await account.populateTransaction({ type: utils.EIP712_TX_TYPE, - to: RECEIVER, + to: ADDRESS2, value: 7_000_000_000, }); - expect(result).to.be.deep.equal(tx); + expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); + expectBigNumberCloseTo( + BigNumber.from(result.gasLimit), + tx.gasLimit, + tolerancePercentage + ); }).timeout(25_000); it('should return a populated transaction with default values if are omitted', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: BigNumber.from(7_000_000), type: utils.EIP712_TX_TYPE, - from: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049', + from: ADDRESS1, nonce: await account.getNonce('pending'), chainId: 270, - gasPrice: BigNumber.from(250_000_000), + gasPrice: BigNumber.from(100_000_000), data: '0x', customData: {gasPerPubdata: 50_000, factoryDeps: []}, }; const result = await account.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); @@ -158,7 +165,7 @@ describe('SmartAccount', async () => { describe('#signTransaction()', () => { it('should return a signed EIP712 transaction', async () => { const result = await account.signTransaction({ - to: RECEIVER, + to: ADDRESS2, value: ethers.utils.parseEther('1'), }); expect(result).not.to.be.null; @@ -195,14 +202,14 @@ describe('SmartAccount', async () => { describe('#transfer()', () => { it('should transfer ETH', async () => { const amount = 7_000_000_000; - const balanceBeforeTransfer = await provider.getBalance(RECEIVER); + const balanceBeforeTransfer = await provider.getBalance(ADDRESS2); const tx = await account.transfer({ token: utils.ETH_ADDRESS, - to: RECEIVER, + to: ADDRESS2, amount: amount, }); const result = await tx.wait(); - const balanceAfterTransfer = await provider.getBalance(RECEIVER); + const balanceAfterTransfer = await provider.getBalance(ADDRESS2); expect(result).not.to.be.null; expect(balanceAfterTransfer.sub(balanceBeforeTransfer).eq(amount)).to.be .true; @@ -217,20 +224,20 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceBeforeTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceBeforeTransfer = await account.getBalance(); const senderApprovalTokenBalanceBeforeTransfer = - await account.getBalance(TOKEN); - const receiverBalanceBeforeTransfer = await provider.getBalance(RECEIVER); + await account.getBalance(APPROVAL_TOKEN); + const receiverBalanceBeforeTransfer = await provider.getBalance(ADDRESS2); const tx = await account.transfer({ token: utils.ETH_ADDRESS, - to: RECEIVER, + to: ADDRESS2, amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -242,12 +249,12 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceAfterTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceAfterTransfer = await account.getBalance(); const senderApprovalTokenBalanceAfterTransfer = - await account.getBalance(TOKEN); - const receiverBalanceAfterTransfer = await provider.getBalance(RECEIVER); + await account.getBalance(APPROVAL_TOKEN); + const receiverBalanceAfterTransfer = await provider.getBalance(ADDRESS2); expect( paymasterBalanceBeforeTransfer.sub(paymasterBalanceAfterTransfer).gte(0) @@ -279,18 +286,18 @@ describe('SmartAccount', async () => { const amount = 5; const l2DAI = await provider.l2TokenAddress(DAI_L1); const balanceBeforeTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); const tx = await account.transfer({ token: l2DAI, - to: RECEIVER, + to: ADDRESS2, amount: amount, }); const result = await tx.wait(); const balanceAfterTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); @@ -309,24 +316,24 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceBeforeTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceBeforeTransfer = await account.getBalance(l2DAI); const senderApprovalTokenBalanceBeforeTransfer = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const receiverBalanceBeforeTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); const tx = await account.transfer({ token: l2DAI, - to: RECEIVER, + to: ADDRESS2, amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -338,13 +345,13 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceAfterTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceAfterTransfer = await account.getBalance(l2DAI); const senderApprovalTokenBalanceAfterTransfer = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const receiverBalanceAfterTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); @@ -408,11 +415,11 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceBeforeWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceBeforeWithdrawal = await account.getBalance(); const l2ApprovalTokenBalanceBeforeWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const withdrawTx = await account.withdraw({ token: utils.ETH_ADDRESS, @@ -420,7 +427,7 @@ describe('SmartAccount', async () => { amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -438,11 +445,11 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceAfterWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceAfterWithdrawal = await account.getBalance(); const l2ApprovalTokenBalanceAfterWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); expect( paymasterBalanceBeforeWithdrawal @@ -504,12 +511,12 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceBeforeWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceBeforeWithdrawal = await account.getBalance(l2DAI); const l1BalanceBeforeWithdrawal = await wallet.getBalanceL1(DAI_L1); const l2ApprovalTokenBalanceBeforeWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const withdrawTx = await account.withdraw({ token: l2DAI, @@ -517,7 +524,7 @@ describe('SmartAccount', async () => { amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -535,12 +542,12 @@ describe('SmartAccount', async () => { const paymasterTokenBalanceAfterWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceAfterWithdrawal = await account.getBalance(l2DAI); const l1BalanceAfterWithdrawal = await wallet.getBalanceL1(DAI_L1); const l2ApprovalTokenBalanceAfterWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); expect( paymasterBalanceBeforeWithdrawal @@ -569,23 +576,11 @@ describe('SmartAccount', async () => { }); describe('MultisigECDSASmartAccount', async () => { - const ADDRESS1 = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY1 = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const ADDRESS2 = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const PRIVATE_KEY2 = - '0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3'; - const provider = Provider.getDefaultProvider(types.Network.Localhost); const ethProvider = ethers.getDefaultProvider('http://localhost:8545'); const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); let account: SmartAccount; - const DAI_L1 = TokensL1[0].address; - - const TOKEN = '0x841c43Fa5d8fFfdB9efE3358906f7578d8700Dd4'; - const PAYMASTER = '0xa222f0c183AFA73a8Bc1AFb48D34C88c9Bf7A174'; - before('setup', async function () { this.timeout(25_000); @@ -618,7 +613,7 @@ describe('MultisigECDSASmartAccount', async () => { // send paymaster approval token to multisig account const sendApprovalTokenTx = await deployer.transfer({ to: multisigAddress, - token: TOKEN, + token: APPROVAL_TOKEN, amount: 5, }); await sendApprovalTokenTx.wait(); @@ -663,11 +658,11 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceBeforeTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceBeforeTransfer = await account.getBalance(); const senderApprovalTokenBalanceBeforeTransfer = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const receiverBalanceBeforeTransfer = await provider.getBalance(ADDRESS2); const tx = await account.transfer({ @@ -676,7 +671,7 @@ describe('MultisigECDSASmartAccount', async () => { amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -688,11 +683,11 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceAfterTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceAfterTransfer = await account.getBalance(); const senderApprovalTokenBalanceAfterTransfer = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const receiverBalanceAfterTransfer = await provider.getBalance(ADDRESS2); expect( @@ -755,11 +750,11 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceBeforeTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceBeforeTransfer = await account.getBalance(l2DAI); const senderApprovalTokenBalanceBeforeTransfer = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const receiverBalanceBeforeTransfer = await provider.getBalance( ADDRESS2, 'latest', @@ -772,7 +767,7 @@ describe('MultisigECDSASmartAccount', async () => { amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -784,11 +779,11 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceAfterTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceAfterTransfer = await account.getBalance(l2DAI); const senderApprovalTokenBalanceAfterTransfer = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const receiverBalanceAfterTransfer = await provider.getBalance( ADDRESS2, 'latest', @@ -854,11 +849,11 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceBeforeWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceBeforeWithdrawal = await account.getBalance(); const l2ApprovalTokenBalanceBeforeWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const withdrawTx = await account.withdraw({ token: utils.ETH_ADDRESS, @@ -866,7 +861,7 @@ describe('MultisigECDSASmartAccount', async () => { amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -884,11 +879,11 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceAfterWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceAfterWithdrawal = await account.getBalance(); const l2ApprovalTokenBalanceAfterWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); expect( paymasterBalanceBeforeWithdrawal @@ -951,12 +946,12 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceBeforeWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceBeforeWithdrawal = await account.getBalance(l2DAI); const l1BalanceBeforeWithdrawal = await wallet.getBalanceL1(DAI_L1); const l2ApprovalTokenBalanceBeforeWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); const withdrawTx = await account.withdraw({ token: l2DAI, @@ -964,7 +959,7 @@ describe('MultisigECDSASmartAccount', async () => { amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: minimalAllowance, innerInput: new Uint8Array(), }), @@ -982,12 +977,12 @@ describe('MultisigECDSASmartAccount', async () => { const paymasterTokenBalanceAfterWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceAfterWithdrawal = await account.getBalance(l2DAI); const l1BalanceAfterWithdrawal = await wallet.getBalanceL1(DAI_L1); const l2ApprovalTokenBalanceAfterWithdrawal = - await account.getBalance(TOKEN); + await account.getBalance(APPROVAL_TOKEN); expect( paymasterBalanceBeforeWithdrawal diff --git a/tests/integration/utils.test.ts b/tests/integration/utils.test.ts index 7566ce1f..1a9e4c84 100644 --- a/tests/integration/utils.test.ts +++ b/tests/integration/utils.test.ts @@ -2,26 +2,23 @@ import * as chai from 'chai'; import '../custom-matchers'; import {Provider, types, utils, EIP712Signer} from '../../src'; import {BigNumber, ethers} from 'ethers'; +import {PRIVATE_KEY1, ADDRESS1} from '../utils'; const {expect} = chai; describe('utils', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const provider = Provider.getDefaultProvider(types.Network.Localhost); describe('#isMessageSignatureCorrect()', () => { it('should return true for a valid message signature', async () => { const message = 'Hello, world!'; - const signature = await new ethers.Wallet(PRIVATE_KEY).signMessage( + const signature = await new ethers.Wallet(PRIVATE_KEY1).signMessage( message ); const result = await utils.isMessageSignatureCorrect( provider, - ADDRESS, + ADDRESS1, message, signature ); @@ -35,7 +32,7 @@ describe('utils', () => { const result = await utils.isMessageSignatureCorrect( provider, - ADDRESS, + ADDRESS1, message, invalidSignature ); @@ -48,13 +45,13 @@ describe('utils', () => { const tx: types.TransactionRequest = { type: 113, chainId: 270, - from: ADDRESS, + from: ADDRESS1, to: '0xa61464658AfeAf65CccaaFD3a512b69A83B77618', value: BigNumber.from(7_000_000), }; const eip712Signer = new EIP712Signer( - new ethers.Wallet(PRIVATE_KEY), + new ethers.Wallet(PRIVATE_KEY1), Number((await provider.getNetwork()).chainId) ); @@ -62,7 +59,7 @@ describe('utils', () => { const result = await utils.isTypedDataSignatureCorrect( provider, - ADDRESS, + ADDRESS1, await eip712Signer.getDomain(), utils.EIP712_TYPES, EIP712Signer.getSignInput(tx), @@ -79,19 +76,19 @@ describe('utils', () => { const tx: types.TransactionRequest = { type: 113, chainId: 270, - from: ADDRESS, + from: ADDRESS1, to: '0xa61464658AfeAf65CccaaFD3a512b69A83B77618', value: BigNumber.from(1_000_000), }; const eip712Signer = new EIP712Signer( - new ethers.Wallet(PRIVATE_KEY), + new ethers.Wallet(PRIVATE_KEY1), Number((await provider.getNetwork()).chainId) ); const result = await utils.isTypedDataSignatureCorrect( provider, - ADDRESS, + ADDRESS1, await eip712Signer.getDomain(), utils.EIP712_TYPES, EIP712Signer.getSignInput(tx), diff --git a/tests/integration/wallet.test.ts b/tests/integration/wallet.test.ts index 5e339b66..54151d43 100644 --- a/tests/integration/wallet.test.ts +++ b/tests/integration/wallet.test.ts @@ -1,43 +1,45 @@ import * as chai from 'chai'; import '../custom-matchers'; -import {Provider, utils, Wallet} from '../../src'; +import {Provider, Wallet, utils} from '../../src'; import {ethers, BigNumber} from 'ethers'; import * as fs from 'fs'; - -import TokensL1 from '../files/tokens.json'; -import CustomBridge from '../files/customBridge.json'; - +import {ITestnetErc20TokenFactory} from '../../typechain/ITestnetErc20TokenFactory'; +import { + MNEMONIC1, + PRIVATE_KEY1, + ADDRESS1, + ADDRESS2, + DAI_L1, + IS_ETH_BASED, + APPROVAL_TOKEN, + PAYMASTER, +} from '../utils'; + +import { + expectFeeDataCloseToExpected, + expectBigNumberCloseTo, +} from '../custom-matchers'; const {expect} = chai; describe('Wallet', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const MNEMONIC = - 'stuff slice staff easily soup parent arm payment cotton trade scatter struggle'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const provider = Provider.getDefaultProvider(); const ethProvider = ethers.getDefaultProvider('http://localhost:8545'); - const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); - - const DAI_L1 = TokensL1[0].address; + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); - const TOKEN = '0x841c43Fa5d8fFfdB9efE3358906f7578d8700Dd4'; - const PAYMASTER = '0xa222f0c183AFA73a8Bc1AFb48D34C88c9Bf7A174'; + const tolerancePercentage = 10; // 10% tolerance describe('#constructor()', () => { it('`Wallet(privateKey, provider)` should return a `Wallet` with L2 provider', async () => { - const wallet = new Wallet(PRIVATE_KEY, provider); + const wallet = new Wallet(PRIVATE_KEY1, provider); - expect(wallet.privateKey).to.be.equal(PRIVATE_KEY); + expect(wallet.privateKey).to.be.equal(PRIVATE_KEY1); expect(wallet.provider).to.be.equal(provider); }); it('`Wallet(privateKey, provider, ethProvider)` should return a `Wallet` with L1 and L2 provider', async () => { - const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); - expect(wallet.privateKey).to.be.equal(PRIVATE_KEY); + expect(wallet.privateKey).to.be.equal(PRIVATE_KEY1); expect(wallet.provider).to.be.equal(provider); expect(wallet.providerL1).to.be.equal(ethProvider); }); @@ -45,7 +47,7 @@ describe('Wallet', () => { describe('#getMainContract()', () => { it('should return the main contract', async () => { - const result = await wallet.getMainContract(); + const result = await wallet.getBridgehubContract(); expect(result).not.to.be.null; }); }); @@ -57,6 +59,22 @@ describe('Wallet', () => { }); }); + describe('#isEthBasedChain()', () => { + it('should return whether the chain is ETH-based or not', async () => { + const result = await wallet.isETHBasedChain(); + expect(result).to.be.equal(IS_ETH_BASED); + }); + }); + + describe('#getBaseToken()', () => { + it('should return base token', async () => { + const result = await wallet.getBaseToken(); + IS_ETH_BASED + ? expect(result).to.be.equal(utils.ETH_ADDRESS_IN_CONTRACTS) + : expect(result).not.to.be.null; + }); + }); + describe('#getBalanceL1()', () => { it('should return a L1 balance', async () => { const result = await wallet.getBalanceL1(); @@ -72,9 +90,17 @@ describe('Wallet', () => { }); describe('#l2TokenAddress()', () => { + it('should return the L2 base address', async () => { + const baseToken = await provider.getBaseTokenContractAddress(); + const result = await wallet.l2TokenAddress(baseToken); + expect(result).to.be.equal(utils.L2_BASE_TOKEN_ADDRESS); + }); + it('should return the L2 ETH address', async () => { - const result = await wallet.l2TokenAddress(utils.ETH_ADDRESS); - expect(result).to.be.equal(utils.ETH_ADDRESS); + if (!IS_ETH_BASED) { + const result = await wallet.l2TokenAddress(utils.LEGACY_ETH_ADDRESS); + expect(result).not.to.be.null; + } }); it('should return the L2 DAI address', async () => { @@ -92,7 +118,7 @@ describe('Wallet', () => { it('should throw an error when approving ETH token', async () => { try { - await wallet.approveERC20(utils.ETH_ADDRESS, 5); + await wallet.approveERC20(utils.LEGACY_ETH_ADDRESS, 5); } catch (e) { expect((e as Error).message).to.be.equal( "ETH token can't be approved! The address of the token does not exist on L1." @@ -118,7 +144,8 @@ describe('Wallet', () => { describe('#getAllBalances()', () => { it('should return all balances', async () => { const result = await wallet.getAllBalances(); - expect(Object.keys(result)).to.have.lengthOf(2); + const expected = IS_ETH_BASED ? 2 : 3; + expect(Object.keys(result)).to.have.lengthOf(expected); }); }); @@ -132,25 +159,25 @@ describe('Wallet', () => { describe('#getAddress()', () => { it('should return a `Wallet` address', async () => { const result = await wallet.getAddress(); - expect(result).to.be.equal(ADDRESS); + expect(result).to.be.equal(ADDRESS1); }); }); describe('#ethWallet()', () => { it('should return a L1 `Wallet`', async () => { - const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); + const wallet = new Wallet(PRIVATE_KEY1, provider, ethProvider); const ethWallet = wallet.ethWallet(); - expect(ethWallet.privateKey).to.be.equal(PRIVATE_KEY); + expect(ethWallet.privateKey).to.be.equal(PRIVATE_KEY1); expect(ethWallet.provider).to.be.equal(ethProvider); }); it('should throw an error when L1 `Provider` is not specified in constructor', async () => { - const wallet = new Wallet(PRIVATE_KEY, provider); + const wallet = new Wallet(PRIVATE_KEY1, provider); try { wallet.ethWallet(); } catch (e) { expect((e as Error).message).to.be.equal( - 'L1 provider missing: use `connectToL1` to specify!' + 'L1 provider is missing! Use `Wallet.connectToL1()` to connect to L1!' ); } }); @@ -158,18 +185,18 @@ describe('Wallet', () => { describe('#connect()', () => { it('should return a `Wallet` with provided `provider` as L2 provider', async () => { - let wallet = new Wallet(PRIVATE_KEY); + let wallet = new Wallet(PRIVATE_KEY1); wallet = wallet.connect(provider); - expect(wallet.privateKey).to.be.equal(PRIVATE_KEY); + expect(wallet.privateKey).to.be.equal(PRIVATE_KEY1); expect(wallet.provider).to.be.equal(provider); }); }); describe('#connectL1()', () => { it('should return a `Wallet` with provided `provider` as L1 provider', async () => { - let wallet = new Wallet(PRIVATE_KEY); + let wallet = new Wallet(PRIVATE_KEY1); wallet = wallet.connectToL1(ethProvider); - expect(wallet.privateKey).to.be.equal(PRIVATE_KEY); + expect(wallet.privateKey).to.be.equal(PRIVATE_KEY1); expect(wallet.providerL1).to.be.equal(ethProvider); }); }); @@ -184,17 +211,17 @@ describe('Wallet', () => { describe('#populateTransaction()', () => { it('should return populated transaction with default values if are omitted', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await wallet.getNonce('pending'), chainId: 270, - maxFeePerGas: BigNumber.from(2_000_000_000), + maxFeePerGas: BigNumber.from(1_700_000_000), maxPriorityFeePerGas: BigNumber.from(1_500_000_000), }; const result = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); @@ -202,10 +229,10 @@ describe('Wallet', () => { it('should return populated transaction when `maxFeePerGas` and `maxPriorityFeePerGas` and `customData` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 113, - from: ADDRESS, + from: ADDRESS1, nonce: await wallet.getNonce('pending'), data: '0x', chainId: 270, @@ -217,7 +244,7 @@ describe('Wallet', () => { }, }; const result = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -231,10 +258,10 @@ describe('Wallet', () => { it('should return populated transaction when `maxPriorityFeePerGas` and `customData` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 113, - from: ADDRESS, + from: ADDRESS1, nonce: await wallet.getNonce('pending'), data: '0x', chainId: 270, @@ -245,7 +272,7 @@ describe('Wallet', () => { }, }; const result = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxPriorityFeePerGas: BigNumber.from(2_000_000_000), customData: { @@ -257,10 +284,10 @@ describe('Wallet', () => { it('should return populated transaction when `maxFeePerGas` and `customData` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 113, - from: ADDRESS, + from: ADDRESS1, nonce: await wallet.getNonce('pending'), data: '0x', chainId: 270, @@ -271,7 +298,7 @@ describe('Wallet', () => { }, }; const result = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), customData: { @@ -283,17 +310,17 @@ describe('Wallet', () => { it('should return populated EIP1559 transaction when `maxFeePerGas` and `maxPriorityFeePerGas` are provided', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await wallet.getNonce('pending'), chainId: 270, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), }; const result = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -303,17 +330,17 @@ describe('Wallet', () => { it('should return populated EIP1559 transaction with `maxFeePerGas` and `maxPriorityFeePerGas` same as provided `gasPrice`', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 2, - from: ADDRESS, + from: ADDRESS1, nonce: await wallet.getNonce('pending'), chainId: 270, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(3_500_000_000), }; const result = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, gasPrice: BigNumber.from(3_500_000_000), }); @@ -322,27 +349,26 @@ describe('Wallet', () => { it('should return populated legacy transaction when `type = 0`', async () => { const tx = { - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, type: 0, - from: ADDRESS, + from: ADDRESS1, nonce: await wallet.getNonce('pending'), - chainId: 270, - gasPrice: BigNumber.from(250_000_000), + gasPrice: BigNumber.from(100_000_000), }; const result = await wallet.populateTransaction({ type: 0, - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); - expect(result).to.be.deepEqualExcluding(tx, ['gasLimit']); + expect(result).to.be.deepEqualExcluding(tx, ['gasLimit', 'chainId']); }); }); describe('#sendTransaction()', () => { it('should send already populated transaction with provided `maxFeePerGas` and `maxPriorityFeePerGas` and `customData` fields', async () => { const populatedTx = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -357,7 +383,7 @@ describe('Wallet', () => { it('should send EIP1559 transaction when `maxFeePerGas` and `maxPriorityFeePerGas` are provided', async () => { const tx = await wallet.sendTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -369,7 +395,7 @@ describe('Wallet', () => { it('should return already populated EIP1559 transaction with `maxFeePerGas` and `maxPriorityFeePerGas`', async () => { const populatedTx = await wallet.populateTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, maxFeePerGas: BigNumber.from(3_500_000_000), maxPriorityFeePerGas: BigNumber.from(2_000_000_000), @@ -383,7 +409,7 @@ describe('Wallet', () => { it('should send EIP1559 transaction with `maxFeePerGas` and `maxPriorityFeePerGas` same as provided `gasPrice`', async () => { const tx = await wallet.sendTransaction({ - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, gasPrice: BigNumber.from(3_500_000_000), }); @@ -395,7 +421,7 @@ describe('Wallet', () => { it('should send legacy transaction when `type = 0`', async () => { const tx = await wallet.sendTransaction({ type: 0, - to: RECEIVER, + to: ADDRESS2, value: 7_000_000, }); const result = await tx.wait(); @@ -406,8 +432,8 @@ describe('Wallet', () => { describe('#fromMnemonic()', () => { it('should return a `Wallet` with the `provider` as L1 provider and a private key that is built from the `mnemonic` passphrase', async () => { - const wallet = Wallet.fromMnemonic(MNEMONIC); - expect(wallet.privateKey).to.be.equal(PRIVATE_KEY); + const wallet = Wallet.fromMnemonic(MNEMONIC1); + expect(wallet.privateKey).to.be.equal(PRIVATE_KEY1); }); }); @@ -417,7 +443,7 @@ describe('Wallet', () => { fs.readFileSync('tests/files/wallet.json', 'utf8'), 'password' ); - expect(wallet.privateKey).to.be.equal(PRIVATE_KEY); + expect(wallet.privateKey).to.be.equal(PRIVATE_KEY1); }).timeout(10_000); }); @@ -427,7 +453,7 @@ describe('Wallet', () => { fs.readFileSync('tests/files/wallet.json', 'utf8'), 'password' ); - expect(wallet.privateKey).to.be.equal(PRIVATE_KEY); + expect(wallet.privateKey).to.be.equal(PRIVATE_KEY1); }).timeout(10_000); }); @@ -439,299 +465,689 @@ describe('Wallet', () => { }); describe('#getDepositTx()', () => { - it('should return ETH deposit transaction', async () => { - const tx = { - contractAddress: ADDRESS, - calldata: '0x', - l2Value: 7_000_000, - l2GasLimit: BigNumber.from('0x08cbaa'), - token: '0x0000000000000000000000000000000000000000', - to: ADDRESS, - amount: 7_000_000, - refundRecipient: ADDRESS, - operatorTip: BigNumber.from(0), - overrides: { - maxFeePerGas: BigNumber.from(1_500_000_010), + if (IS_ETH_BASED) { + it('should return ETH deposit transaction', async () => { + const tx = { + contractAddress: ADDRESS1, + calldata: '0x', + l2Value: 7_000_000, + l2GasLimit: BigNumber.from(415_035), + mintValue: BigNumber.from(111_540_663_250_000), + token: utils.ETH_ADDRESS_IN_CONTRACTS, + to: ADDRESS1, + amount: 7_000_000, + refundRecipient: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049', + operatorTip: BigNumber.from(0), + overrides: { + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + value: BigNumber.from(111_540_663_250_000), + }, + gasPerPubdataByte: 800, + }; + const result = await wallet.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + amount: 7_000_000, + refundRecipient: await wallet.getAddress(), + }); + expect(result).to.be.deepEqualExcluding(tx, [ + 'l2GasLimit', + 'mintValue', + 'overrides', + ]); + expect(result.overrides).to.be.deepEqualExcluding(tx.overrides, [ + 'value', + ]); + }); + + it('should return a deposit transaction with `tx.to == Wallet.getAddress()` when `tx.to` is not specified', async () => { + const tx = { + contractAddress: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049', + calldata: '0x', + l2Value: 7_000_000, + l2GasLimit: BigNumber.from(415_035), + mintValue: BigNumber.from(111_540_663_250_000), + token: '0x0000000000000000000000000000000000000001', + to: ADDRESS1, + amount: 7_000_000, + refundRecipient: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049', + operatorTip: BigNumber.from(0), + overrides: { + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + value: BigNumber.from(111_540_663_250_000), + }, + gasPerPubdataByte: 800, + }; + const result = await wallet.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + amount: 7_000_000, + refundRecipient: await wallet.getAddress(), + }); + expect(result).to.be.deepEqualExcluding(tx, [ + 'l2GasLimit', + 'mintValue', + 'overrides', + ]); + expect(result.overrides).to.be.deepEqualExcluding(tx.overrides, [ + 'value', + ]); + }); + + it('should return DAI deposit transaction', async () => { + const tx = { + maxFeePerGas: BigNumber.from(1_500_000_001), maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - value: BigNumber.from(288_213_007_000_000), - }, - gasPerPubdataByte: 800, - }; - const result = await wallet.getDepositTx({ - token: utils.ETH_ADDRESS, - to: await wallet.getAddress(), - amount: 7_000_000, - refundRecipient: await wallet.getAddress(), + value: BigNumber.from(123_164_093_750_000), + from: ADDRESS1, + to: await provider.getBridgehubContractAddress(), + }; + const result = await wallet.getDepositTx({ + token: DAI_L1, + to: await wallet.getAddress(), + amount: 5, + refundRecipient: await wallet.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(tx).to.be.deepEqualExcluding(tx, ['data']); + }); + } else { + it('should return ETH deposit transaction', async () => { + const tx = { + from: ADDRESS1, + to: (await provider.getBridgehubContractAddress()).toLowerCase(), + value: BigNumber.from(7_000_000), + data: '0x24fd57fb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000010e0000000000000000000000000000000000000000000000000000bf1aaa17ee7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062e3d000000000000000000000000000000000000000000000000000000000000032000000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc049000000000000000000000000842deab39809094bf5e4b77a7f97ae308adc5e5500000000000000000000000000000000000000000000000000000000006acfc0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036615cf349d7f6344891b1e7ca7c72883f5dc049', + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const result = await wallet.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + amount: 7_000_000, + refundRecipient: await wallet.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(result).to.be.deepEqualExcluding(tx, ['data']); }); - expect(result).to.be.deep.equal(tx); - }); - it('should return a deposit transaction with `tx.to == Wallet.getAddress()` when `tx.to` is not specified', async () => { - const tx = { - contractAddress: ADDRESS, - calldata: '0x', - l2Value: 7_000_000, - l2GasLimit: BigNumber.from('0x8cbaa'), - token: '0x0000000000000000000000000000000000000000', - to: ADDRESS, - amount: 7_000_000, - refundRecipient: ADDRESS, - operatorTip: BigNumber.from(0), - overrides: { - maxFeePerGas: BigNumber.from(1_500_000_010), + it('should return a deposit transaction with `tx.to == Wallet.getAddress()` when `tx.to` is not specified', async () => { + const tx = { + from: ADDRESS1, + to: (await provider.getBridgehubContractAddress()).toLowerCase(), + value: BigNumber.from(7_000_000), + maxFeePerGas: BigNumber.from(1_500_000_001), maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - value: BigNumber.from(288_213_007_000_000), - }, - gasPerPubdataByte: 800, - }; - const result = await wallet.getDepositTx({ - token: utils.ETH_ADDRESS, - amount: 7_000_000, - refundRecipient: await wallet.getAddress(), + }; + const result = await wallet.getDepositTx({ + token: utils.LEGACY_ETH_ADDRESS, + amount: 7_000_000, + refundRecipient: await wallet.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(result).to.be.deepEqualExcluding(tx, ['data']); }); - expect(result).to.be.deep.equal(tx); - }); - it('should return DAI deposit transaction', async () => { - const tx = { - maxFeePerGas: BigNumber.from(1_500_000_010), - maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - value: BigNumber.from(288_992_000_000_000), - from: ADDRESS, - to: (await wallet.getL1BridgeContracts()).erc20.address, - }; - const result = await wallet.getDepositTx({ - token: DAI_L1, - to: await wallet.getAddress(), - amount: 5, - refundRecipient: await wallet.getAddress(), + it('should return DAI deposit transaction', async () => { + const tx = { + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + value: BigNumber.from(210_121_243_750_000), + from: ADDRESS1, + to: (await provider.getBridgehubContractAddress()).toLowerCase(), + }; + const result = await wallet.getDepositTx({ + token: DAI_L1, + to: await wallet.getAddress(), + amount: 5, + refundRecipient: await wallet.getAddress(), + }); + result.to = result.to.toLowerCase(); + expect(result).to.be.deepEqualExcluding(tx, ['data']); }); - result.to = result.to.toLowerCase(); - expect(result).to.be.deepEqualExcluding(tx, ['data']); - }); + } }); describe('#estimateGasDeposit()', () => { - it('should return gas estimation for ETH deposit transaction', async () => { - const result = await wallet.estimateGasDeposit({ - token: utils.ETH_ADDRESS, - to: await wallet.getAddress(), - amount: 5, - refundRecipient: await wallet.getAddress(), + if (IS_ETH_BASED) { + it('should return gas estimation for ETH deposit transaction', async () => { + const result = await wallet.estimateGasDeposit({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + amount: 5, + refundRecipient: await wallet.getAddress(), + }); + expectBigNumberCloseTo( + result, + BigNumber.from(225_078), + tolerancePercentage + ); }); - expect(result.eq(BigNumber.from(132_711))).to.be.true; - }); - it('should return gas estimation for DAI deposit transaction', async () => { - const result = await wallet.estimateGasDeposit({ - token: DAI_L1, - to: await wallet.getAddress(), - amount: 5, - refundRecipient: await wallet.getAddress(), + it('should return gas estimation for DAI deposit transaction', async () => { + const result = await wallet.estimateGasDeposit({ + token: DAI_L1, + to: await wallet.getAddress(), + amount: 5, + refundRecipient: await wallet.getAddress(), + }); + expectBigNumberCloseTo( + result, + BigNumber.from(338_196), + tolerancePercentage + ); }); - expect(result.eq(BigNumber.from(253_418))).to.be.true; - }); - }); + } else { + it('should throw an error for insufficient allowance when estimating gas for ETH deposit transaction', async () => { + try { + await wallet.estimateGasDeposit({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + amount: 5, + refundRecipient: await wallet.getAddress(), + }); + } catch (e) { + expect((e as any).reason).to.include('ERC20: insufficient allowance'); + } + }).timeout(10_000); + + it('should return gas estimation for ETH deposit transaction', async () => { + const token = utils.LEGACY_ETH_ADDRESS; + const amount = 5; + const approveParams = await wallet.getDepositAllowanceParams( + token, + amount + ); - describe('#deposit()', () => { - it('should deposit ETH to L2 network', async () => { - const amount = 7_000_000_000; - const l2BalanceBeforeDeposit = await wallet.getBalance(); - const l1BalanceBeforeDeposit = await wallet.getBalanceL1(); - const tx = await wallet.deposit({ - token: utils.ETH_ADDRESS, - to: await wallet.getAddress(), - amount: amount, - refundRecipient: await wallet.getAddress(), - }); - const result = await tx.wait(); - const l2BalanceAfterDeposit = await wallet.getBalance(); - const l1BalanceAfterDeposit = await wallet.getBalanceL1(); - expect(result).not.to.be.null; - expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).gte(amount)).to - .be.true; - expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).gte(amount)).to - .be.true; - }).timeout(10_000); + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); - it('should deposit DAI to L2 network', async () => { - const amount = 5; - const l2DAI = await provider.l2TokenAddress(DAI_L1); - const l2BalanceBeforeDeposit = await wallet.getBalance(l2DAI); - const l1BalanceBeforeDeposit = await wallet.getBalanceL1(DAI_L1); - const tx = await wallet.deposit({ - token: DAI_L1, - to: await wallet.getAddress(), - amount: amount, - approveERC20: true, - refundRecipient: await wallet.getAddress(), - }); - const result = await tx.wait(); - const l2BalanceAfterDeposit = await wallet.getBalance(l2DAI); - const l1BalanceAfterDeposit = await wallet.getBalanceL1(DAI_L1); - expect(result).not.to.be.null; - expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).eq(amount)).to.be - .true; - expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).eq(amount)).to.be - .true; - }).timeout(10_000); + const result = await wallet.estimateGasDeposit({ + token: token, + to: await wallet.getAddress(), + amount: amount, + refundRecipient: await wallet.getAddress(), + }); + expect(result.isZero()).to.be.false; + }).timeout(10_000); + + it('should return gas estimation for base token deposit transaction', async () => { + const token = await wallet.getBaseToken(); + const amount = 5; + const approveParams = await wallet.getDepositAllowanceParams( + token, + amount + ); - it('should deposit DAI to the L2 network with approve transaction for allowance', async () => { - const amount = 7; - const l2DAI = await provider.l2TokenAddress(DAI_L1); - const l2BalanceBeforeDeposit = await wallet.getBalance(l2DAI); - const l1BalanceBeforeDeposit = await wallet.getBalanceL1(DAI_L1); - const tx = await wallet.deposit({ - token: DAI_L1, - to: await wallet.getAddress(), - amount: amount, - approveERC20: true, - refundRecipient: await wallet.getAddress(), - }); - const result = await tx.wait(); - await tx.waitFinalize(); - const l2BalanceAfterDeposit = await wallet.getBalance(l2DAI); - const l1BalanceAfterDeposit = await wallet.getBalanceL1(DAI_L1); - expect(result).not.to.be.null; - expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).eq(amount)).to.be - .true; - expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).eq(amount)).to.be - .true; - }).timeout(30_000); - - it('should deposit USDC using custom bridge', async () => { - const amount = BigNumber.from(7); - const l2USDC = CustomBridge.l2Token; - const l1USDC = CustomBridge.l1Token; - const l2BalanceBeforeDeposit = await wallet.getBalance(l2USDC); - const l1BalanceBeforeDeposit = await wallet.getBalanceL1(l1USDC); - const tx = await wallet.deposit({ - token: l1USDC, - bridgeAddress: CustomBridge.l1Bridge, - to: await wallet.getAddress(), - amount: amount, - approveERC20: true, - refundRecipient: await wallet.getAddress(), - }); - const result = await tx.wait(); - await tx.waitFinalize(); - const l2BalanceAfterDeposit = await wallet.getBalance(l2USDC); - const l1BalanceAfterDeposit = await wallet.getBalanceL1(l1USDC); - expect(result).not.to.be.null; - expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).eq(amount)).to.be - .true; - expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).eq(amount)).to.be - .true; - }).timeout(30_000); + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + + const result = await wallet.estimateGasDeposit({ + token: token, + to: await wallet.getAddress(), + amount: amount, + refundRecipient: await wallet.getAddress(), + }); + expect(result.isZero()).to.be.false; + }).timeout(10_000); + + it('should return gas estimation for DAI deposit transaction', async () => { + const token = DAI_L1; + const amount = 5; + const approveParams = await wallet.getDepositAllowanceParams( + token, + amount + ); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + await ( + await wallet.approveERC20( + approveParams[1].token, + approveParams[1].allowance + ) + ).wait(); + + const result = await wallet.estimateGasDeposit({ + token: token, + to: await wallet.getAddress(), + amount: amount, + refundRecipient: await wallet.getAddress(), + }); + expectBigNumberCloseTo(result, BigNumber.from(361_501), 10); + }).timeout(10_000); + } }); - describe('#claimFailedDeposit()', () => { - // it("should claim failed deposit", async () => { - // const response = await wallet.deposit({ - // token: utils.ETH_ADDRESS, - // to: await wallet.getAddress(), - // amount: 7_000_000_000, - // refundRecipient: await wallet.getAddress(), - // gasPerPubdataByte: 500 // make it fail because of low gas - // }); - // - // const tx = await response.waitFinalize(); // fails, sames goes with response.wait() - // const result = await wallet.claimFailedDeposit(tx.hash); - // - // }).timeout(30_000); - - it('should throw an error when trying to claim successful deposit', async () => { - const response = await wallet.deposit({ - token: utils.ETH_ADDRESS, - to: await wallet.getAddress(), - amount: 7_000_000_000, - refundRecipient: await wallet.getAddress(), - }); + describe('#deposit()', () => { + if (IS_ETH_BASED) { + it('should deposit ETH to L2 network', async () => { + const amount = 7_000_000_000; + const l2BalanceBeforeDeposit = await wallet.getBalance(); + const l1BalanceBeforeDeposit = await wallet.getBalanceL1(); + const tx = await wallet.deposit({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + amount: amount, + refundRecipient: await wallet.getAddress(), + }); + const result = await tx.wait(); + const l2BalanceAfterDeposit = await wallet.getBalance(); + const l1BalanceAfterDeposit = await wallet.getBalanceL1(); + expect(result).not.to.be.null; + expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).gte(amount)).to + .be.true; + expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).gte(amount)).to + .be.true; + }).timeout(10_000); + + it('should deposit DAI to L2 network', async () => { + const amount = 5; + const l2DAI = await provider.l2TokenAddress(DAI_L1); + const l2BalanceBeforeDeposit = await wallet.getBalance(l2DAI); + const l1BalanceBeforeDeposit = await wallet.getBalanceL1(DAI_L1); + const tx = await wallet.deposit({ + token: DAI_L1, + to: await wallet.getAddress(), + amount: amount, + approveERC20: true, + refundRecipient: await wallet.getAddress(), + }); + const result = await tx.wait(); + const l2BalanceAfterDeposit = await wallet.getBalance(l2DAI); + const l1BalanceAfterDeposit = await wallet.getBalanceL1(DAI_L1); + expect(result).not.to.be.null; + expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).eq(amount)).to + .be.true; + expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).eq(amount)).to + .be.true; + }).timeout(10_000); + + it('should deposit DAI to the L2 network with approve transaction for allowance', async () => { + const amount = 7; + const l2DAI = await provider.l2TokenAddress(DAI_L1); + const l2BalanceBeforeDeposit = await wallet.getBalance(l2DAI); + const l1BalanceBeforeDeposit = await wallet.getBalanceL1(DAI_L1); + const tx = await wallet.deposit({ + token: DAI_L1, + to: await wallet.getAddress(), + amount: amount, + approveERC20: true, + refundRecipient: await wallet.getAddress(), + }); + const result = await tx.wait(); + await tx.waitFinalize(); + const l2BalanceAfterDeposit = await wallet.getBalance(l2DAI); + const l1BalanceAfterDeposit = await wallet.getBalanceL1(DAI_L1); + expect(result).not.to.be.null; + expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).eq(amount)).to + .be.true; + expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).eq(amount)).to + .be.true; + }).timeout(30_000); + } else { + it('should deposit ETH to L2 network', async () => { + const amount = 7_000_000_000; + const l2BalanceBeforeDeposit = await wallet.getBalance(); + const l1BalanceBeforeDeposit = await wallet.getBalanceL1(); + const tx = await wallet.deposit({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + amount: amount, + approveBaseERC20: true, + refundRecipient: await wallet.getAddress(), + }); + const result = await tx.wait(); + const l2BalanceAfterDeposit = await wallet.getBalance(); + const l1BalanceAfterDeposit = await wallet.getBalanceL1(); + expect(result).not.to.be.null; + expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).gte(amount)).to + .be.true; + expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).gte(amount)).to + .be.true; + }).timeout(20_000); + + it('should deposit base token to L2 network', async () => { + const amount = 5; + const baseTokenL1 = await wallet.getBaseToken(); + const l2BalanceBeforeDeposit = await wallet.getBalance(); + const l1BalanceBeforeDeposit = await wallet.getBalanceL1(baseTokenL1); + const tx = await wallet.deposit({ + token: baseTokenL1, + to: await wallet.getAddress(), + amount: amount, + approveERC20: true, + refundRecipient: await wallet.getAddress(), + }); + const result = await tx.wait(); + const l2BalanceAfterDeposit = await wallet.getBalance(); + const l1BalanceAfterDeposit = await wallet.getBalanceL1(baseTokenL1); + expect(result).not.to.be.null; + expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).gt(0)).to.be + .true; + expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).gt(0)).to.be + .true; + }).timeout(20_000); + + it('should deposit DAI to L2 network', async () => { + const amount = 5; + const l2DAI = await provider.l2TokenAddress(DAI_L1); + const l2BalanceBeforeDeposit = await wallet.getBalance(l2DAI); + const l1BalanceBeforeDeposit = await wallet.getBalanceL1(DAI_L1); + const tx = await wallet.deposit({ + token: DAI_L1, + to: await wallet.getAddress(), + amount: amount, + approveERC20: true, + approveBaseERC20: true, + refundRecipient: await wallet.getAddress(), + }); + const result = await tx.wait(); + const l2BalanceAfterDeposit = await wallet.getBalance(l2DAI); + const l1BalanceAfterDeposit = await wallet.getBalanceL1(DAI_L1); + expect(result).not.to.be.null; + expect(l2BalanceAfterDeposit.sub(l2BalanceBeforeDeposit).eq(amount)).to + .be.true; + expect(l1BalanceBeforeDeposit.sub(l1BalanceAfterDeposit).eq(amount)).to + .be.true; + }).timeout(20_000); + } + }); - const tx = await response.waitFinalize(); - try { - await wallet.claimFailedDeposit(tx.transactionHash); - } catch (e) { - expect((e as Error).message).to.be.equal( - 'Cannot claim successful deposit!' - ); - } - }).timeout(30_000); + describe('#claimFailedDeposit()', () => { + if (IS_ETH_BASED) { + it('should claim failed deposit', async () => { + const response = await wallet.deposit({ + token: DAI_L1, + to: await wallet.getAddress(), + amount: 5, + approveERC20: true, + refundRecipient: await wallet.getAddress(), + l2GasLimit: 300_000, // make it fail because of low gas + }); + try { + await response.waitFinalize(); + } catch (error) { + await utils.sleep(10_000); + const tx = await wallet.claimFailedDeposit( + (error as any).transactionHash + ); + const result = await tx.wait(); + expect(result.blockHash).to.be.not.null; + } + }).timeout(40_000); + + it('should throw an error when trying to claim successful deposit', async () => { + const response = await wallet.deposit({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + amount: 7_000_000_000, + refundRecipient: await wallet.getAddress(), + }); + const tx = await response.waitFinalize(); + try { + await wallet.claimFailedDeposit(tx.transactionHash); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Cannot claim successful deposit' + ); + } + }).timeout(30_000); + } else { + it('should throw an error when trying to claim successful deposit', async () => { + const response = await wallet.deposit({ + token: await wallet.getBaseToken(), + to: await wallet.getAddress(), + amount: 5, + approveERC20: true, + refundRecipient: await wallet.getAddress(), + }); + const tx = await response.waitFinalize(); + try { + await wallet.claimFailedDeposit(tx.transactionHash); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Cannot claim successful deposit' + ); + } + }).timeout(30_000); + } }); describe('#getFullRequiredDepositFee()', () => { - it('should return fee for ETH token deposit', async () => { - const FEE_DATA = { - baseCost: BigNumber.from(285_096_500_000_000), - l1GasLimit: BigNumber.from(132_711), - l2GasLimit: BigNumber.from('0x08b351'), - maxFeePerGas: BigNumber.from(1_500_000_010), - maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - }; - const result = await wallet.getFullRequiredDepositFee({ - token: utils.ETH_ADDRESS, - to: await wallet.getAddress(), + if (IS_ETH_BASED) { + it('should return fee for ETH token deposit', async () => { + const fee = { + baseCost: BigNumber.from(95_595_450_000_000), + l1GasLimit: BigNumber.from(225_079), + l2GasLimit: BigNumber.from(355_704), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const result = await wallet.getFullRequiredDepositFee({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + }); + + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); }); - expect(result).to.be.deep.equal(FEE_DATA); - }); - it('should throw an error when there is not enough allowance to cover the deposit', async () => { - try { - await wallet.getFullRequiredDepositFee({ + it('should throw an error when there is not enough allowance to cover the deposit', async () => { + try { + await wallet.getFullRequiredDepositFee({ + token: DAI_L1, + to: await wallet.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Not enough allowance to cover the deposit!' + ); + } + }).timeout(10_000); + + it('should return fee for DAI token deposit', async () => { + const fee = { + baseCost: BigNumber.from(107_602_662_500_000), + l1GasLimit: BigNumber.from(337_820), + l2GasLimit: BigNumber.from(400_382), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + + const tx = await wallet.approveERC20(DAI_L1, 5); + await tx.wait(); + + const result = await wallet.getFullRequiredDepositFee({ token: DAI_L1, to: await wallet.getAddress(), }); - } catch (e) { - expect((e as Error).message).to.be.equal( - 'Not enough allowance to cover the deposit!' - ); - } - }).timeout(10_000); + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); + }).timeout(10_000); + + it('should throw an error when there is not enough balance for the deposit', async () => { + try { + const randomWallet = new Wallet( + ethers.Wallet.createRandom().privateKey, + provider, + ethProvider + ); + await randomWallet.getFullRequiredDepositFee({ + token: DAI_L1, + to: await wallet.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.include( + 'Not enough balance for deposit!' + ); + } + }).timeout(10_000); + } else { + it('should throw an error when there is not enough base token allowance to cover the deposit', async () => { + try { + await Wallet.createRandom() + .connectToL1(ethProvider) + .connect(provider) + .getFullRequiredDepositFee({ + token: utils.LEGACY_ETH_ADDRESS, + to: await wallet.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Not enough base token allowance to cover the deposit!' + ); + } + }).timeout(10_000); + + it('should return fee for ETH token deposit', async () => { + const fee = { + baseCost: BigNumber.from(111_540_656_250_000), + l1GasLimit: BigNumber.from(321_051), + l2GasLimit: BigNumber.from(415_035), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const token = utils.LEGACY_ETH_ADDRESS; + const approveParams = await wallet.getDepositAllowanceParams(token, 1); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + + const result = await wallet.getFullRequiredDepositFee({ + token: token, + to: await wallet.getAddress(), + }); - it('should return fee for DAI token deposit', async () => { - const FEE_DATA = { - baseCost: BigNumber.from(288_992_000_000_000), - l1GasLimit: BigNumber.from(253_177), - l2GasLimit: BigNumber.from('0x08d1c0'), - maxFeePerGas: BigNumber.from(1_500_000_010), - maxPriorityFeePerGas: BigNumber.from(1_500_000_000), - }; + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); + }).timeout(10_000); - const tx = await wallet.approveERC20(DAI_L1, 5); - await tx.wait(); + it('should return fee for base token deposit', async () => { + const token = await wallet.getBaseToken(); + const approveParams = await wallet.getDepositAllowanceParams(token, 1); - const result = await wallet.getFullRequiredDepositFee({ - token: DAI_L1, - to: await wallet.getAddress(), - }); - expect(result).to.be.deep.equal(FEE_DATA); - }).timeout(10_000); + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); - it('should throw an error when there is not enough balance for the deposit', async () => { - try { - const randomWallet = new Wallet( - ethers.Wallet.createRandom().privateKey, - provider, - ethProvider - ); - await randomWallet.getFullRequiredDepositFee({ - token: DAI_L1, + const result = await wallet.getFullRequiredDepositFee({ + token: token, to: await wallet.getAddress(), }); - } catch (e) { - expect((e as Error).message).to.include( - 'Not enough balance for deposit!' + expect(result).not.to.be.null; + }).timeout(10_000); + + it('should return fee for DAI token deposit', async () => { + const fee = { + baseCost: BigNumber.from(107_602_662_500_000), + l1GasLimit: BigNumber.from(361_124), + l2GasLimit: BigNumber.from(400_382), + maxFeePerGas: BigNumber.from(1_500_000_001), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + }; + const token = DAI_L1; + const approveParams = await wallet.getDepositAllowanceParams(token, 1); + + await ( + await wallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + await ( + await wallet.approveERC20( + approveParams[1].token, + approveParams[1].allowance + ) + ).wait(); + + const result = await wallet.getFullRequiredDepositFee({ + token: token, + to: await wallet.getAddress(), + }); + expectFeeDataCloseToExpected(result, fee, tolerancePercentage); + }).timeout(10_000); + + it('should throw an error when there is not enough token allowance to cover the deposit', async () => { + const token = DAI_L1; + const randomWallet = Wallet.createRandom() + .connectToL1(ethProvider) + .connect(provider); + + // mint base token to random wallet + const baseToken = ITestnetErc20TokenFactory.connect( + await wallet.getBaseToken(), + wallet._signerL1() ); - } - }).timeout(10_000); + const baseTokenMintTx = await baseToken.mint( + await randomWallet.getAddress(), + ethers.utils.parseEther('0.5') + ); + await baseTokenMintTx.wait(); + + // transfer ETH to random wallet so that base token approval tx can be performed + const transferTx = await new ethers.Wallet( + PRIVATE_KEY1, + ethProvider + ).sendTransaction({ + to: await randomWallet.getAddress(), + value: ethers.utils.parseEther('0.1'), + }); + await transferTx.wait(); + + const approveParams = await randomWallet.getDepositAllowanceParams( + token, + 1 + ); + // only approve base token + await ( + await randomWallet.approveERC20( + approveParams[0].token, + approveParams[0].allowance + ) + ).wait(); + + try { + await randomWallet.getFullRequiredDepositFee({ + token: token, + to: await wallet.getAddress(), + }); + } catch (e) { + expect((e as Error).message).to.be.equal( + 'Not enough token allowance to cover the deposit!' + ); + } + }).timeout(20_000); + } }); describe('#withdraw()', () => { it('should withdraw ETH to L1 network', async () => { const amount = 7_000_000_000; const l2BalanceBeforeWithdrawal = await wallet.getBalance(); + const token = IS_ETH_BASED + ? utils.ETH_ADDRESS_IN_CONTRACTS + : await wallet.l2TokenAddress(utils.ETH_ADDRESS_IN_CONTRACTS); const withdrawTx = await wallet.withdraw({ - token: utils.ETH_ADDRESS, + token: token, to: await wallet.getAddress(), amount: amount, }); @@ -758,19 +1174,19 @@ describe('Wallet', () => { const paymasterTokenBalanceBeforeWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceBeforeWithdrawal = await wallet.getBalance(); const l2ApprovalTokenBalanceBeforeWithdrawal = - await wallet.getBalance(TOKEN); + await wallet.getBalance(APPROVAL_TOKEN); const withdrawTx = await wallet.withdraw({ - token: utils.ETH_ADDRESS, + token: utils.LEGACY_ETH_ADDRESS, to: await wallet.getAddress(), amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -788,11 +1204,11 @@ describe('Wallet', () => { const paymasterTokenBalanceAfterWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceAfterWithdrawal = await wallet.getBalance(); const l2ApprovalTokenBalanceAfterWithdrawal = - await wallet.getBalance(TOKEN); + await wallet.getBalance(APPROVAL_TOKEN); expect( paymasterBalanceBeforeWithdrawal @@ -852,12 +1268,12 @@ describe('Wallet', () => { const paymasterTokenBalanceBeforeWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceBeforeWithdrawal = await wallet.getBalance(l2DAI); const l1BalanceBeforeWithdrawal = await wallet.getBalanceL1(DAI_L1); const l2ApprovalTokenBalanceBeforeWithdrawal = - await wallet.getBalance(TOKEN); + await wallet.getBalance(APPROVAL_TOKEN); const withdrawTx = await wallet.withdraw({ token: l2DAI, @@ -865,7 +1281,7 @@ describe('Wallet', () => { amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -883,12 +1299,12 @@ describe('Wallet', () => { const paymasterTokenBalanceAfterWithdrawal = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const l2BalanceAfterWithdrawal = await wallet.getBalance(l2DAI); const l1BalanceAfterWithdrawal = await wallet.getBalanceL1(DAI_L1); const l2ApprovalTokenBalanceAfterWithdrawal = - await wallet.getBalance(TOKEN); + await wallet.getBalance(APPROVAL_TOKEN); expect( paymasterBalanceBeforeWithdrawal @@ -913,93 +1329,144 @@ describe('Wallet', () => { expect(l1BalanceAfterWithdrawal.sub(l1BalanceBeforeWithdrawal).eq(amount)) .to.be.true; }).timeout(25_000); - - it('should withdraw USDC to the L1 network using custom bridge', async () => { - const amount = BigNumber.from(5); - const l2USDC = CustomBridge.l2Token; - const l1USDC = CustomBridge.l1Token; - const l2BalanceBeforeWithdrawal = await wallet.getBalance(l2USDC); - const l1BalanceBeforeWithdrawal = await wallet.getBalanceL1(l1USDC); - - const withdrawTx = await wallet.withdraw({ - token: l2USDC, - bridgeAddress: CustomBridge.l2Bridge, - to: await wallet.getAddress(), - amount: amount, - }); - await withdrawTx.waitFinalize(); - expect(await wallet.isWithdrawalFinalized(withdrawTx.hash)).to.be.false; - - const finalizeWithdrawTx = await wallet.finalizeWithdrawal( - withdrawTx.hash - ); - const result = await finalizeWithdrawTx.wait(); - const l2BalanceAfterWithdrawal = await wallet.getBalance(l2USDC); - const l1BalanceAfterWithdrawal = await wallet.getBalanceL1(l1USDC); - - expect(result).not.to.be.null; - expect(l2BalanceBeforeWithdrawal.sub(l2BalanceAfterWithdrawal).eq(amount)) - .to.be.true; - expect(l1BalanceAfterWithdrawal.sub(l1BalanceBeforeWithdrawal).eq(amount)) - .to.be.true; - }).timeout(25_000); }); describe('#getRequestExecuteTx()', () => { - it('should return request execute transaction', async () => { - const result = await wallet.getRequestExecuteTx({ - contractAddress: await provider.getMainContractAddress(), - calldata: '0x', - l2Value: 7_000_000_000, + const amount = 7_000_000_000; + if (IS_ETH_BASED) { + it('should return request execute transaction', async () => { + const result = await wallet.getRequestExecuteTx({ + contractAddress: await provider.getBridgehubContractAddress(), + calldata: '0x', + l2Value: amount, + }); + expect(result).not.to.be.null; }); - expect(result).not.to.be.null; - }); + } else { + it('should return request execute transaction', async () => { + const result = await wallet.getRequestExecuteTx({ + contractAddress: await wallet.getAddress(), + calldata: '0x', + l2Value: amount, + overrides: {nonce: 0}, + }); + expect(result).not.to.be.null; + }); + } }); describe('#estimateGasRequestExecute()', () => { - it('should return gas estimation for request execute transaction', async () => { - const result = await wallet.estimateGasRequestExecute({ - contractAddress: await provider.getMainContractAddress(), - calldata: '0x', - l2Value: 7_000_000_000, + if (IS_ETH_BASED) { + it('should return gas estimation for request execute transaction', async () => { + const result = await wallet.estimateGasRequestExecute({ + contractAddress: await provider.getBridgehubContractAddress(), + calldata: '0x', + l2Value: 7_000_000_000, + }); + expect(result.isZero()).to.be.false; }); - expect(result.isZero()).to.be.false; - }); + } else { + it('should return gas estimation for request execute transaction', async () => { + const tx = { + contractAddress: await wallet.getAddress(), + calldata: '0x', + l2Value: 7_000_000_000, + }; + + const approveParams = await wallet.getRequestExecuteAllowanceParams(tx); + await ( + await wallet.approveERC20( + approveParams.token, + approveParams.allowance + ) + ).wait(); + + const result = await wallet.estimateGasRequestExecute(tx); + expect(result.isZero()).to.be.false; + }).timeout(10_000); + } }); describe('#requestExecute()', () => { - it('should request transaction execution on L2 network', async () => { - const amount = 7_000_000_000; - const l2BalanceBeforeExecution = await wallet.getBalance(); - const l1BalanceBeforeExecution = await wallet.getBalanceL1(); - const tx = await wallet.requestExecute({ - contractAddress: await provider.getMainContractAddress(), - calldata: '0x', - l2Value: amount, - l2GasLimit: 900_000, - }); - const result = await tx.wait(); - const l2BalanceAfterExecution = await wallet.getBalance(); - const l1BalanceAfterExecution = await wallet.getBalanceL1(); - expect(result).not.to.be.null; - expect(l2BalanceAfterExecution.sub(l2BalanceBeforeExecution).gte(amount)) - .to.be.true; - expect(l1BalanceBeforeExecution.sub(l1BalanceAfterExecution).gte(amount)) - .to.be.true; - }).timeout(10_000); + if (IS_ETH_BASED) { + it('should request transaction execution on L2 network', async () => { + const amount = 7_000_000_000; + const l2BalanceBeforeExecution = await wallet.getBalance(); + const l1BalanceBeforeExecution = await wallet.getBalanceL1(); + const tx = await wallet.requestExecute({ + contractAddress: await provider.getBridgehubContractAddress(), + calldata: '0x', + l2Value: amount, + l2GasLimit: 900_000, + }); + const result = await tx.wait(); + const l2BalanceAfterExecution = await wallet.getBalance(); + const l1BalanceAfterExecution = await wallet.getBalanceL1(); + expect(result).not.to.be.null; + expect( + l2BalanceAfterExecution.sub(l2BalanceBeforeExecution).gte(amount) + ).to.be.true; + expect( + l1BalanceBeforeExecution.sub(l1BalanceAfterExecution).gte(amount) + ).to.be.true; + }).timeout(10_000); + } else { + it('should request transaction execution on L2 network', async () => { + const amount = 7_000_000_000; + const request = { + contractAddress: await wallet.getAddress(), + calldata: '0x', + l2Value: amount, + l2GasLimit: BigNumber.from(1_319_957), + operatorTip: 0, + gasPerPubdataByte: 800, + refundRecipient: await wallet.getAddress(), + overrides: { + maxFeePerGas: BigNumber.from(1_500_000_010), + maxPriorityFeePerGas: BigNumber.from(1_500_000_000), + gasLimit: BigNumber.from(238_654), + value: 0, + }, + }; + + const approveParams = + await wallet.getRequestExecuteAllowanceParams(request); + await ( + await wallet.approveERC20( + approveParams.token, + approveParams.allowance + ) + ).wait(); + + const l2BalanceBeforeExecution = await wallet.getBalance(); + const l1BalanceBeforeExecution = await wallet.getBalanceL1(); + + const tx = await wallet.requestExecute(request); + const result = await tx.wait(); + const l2BalanceAfterExecution = await wallet.getBalance(); + const l1BalanceAfterExecution = await wallet.getBalanceL1(); + expect(result).not.to.be.null; + expect( + l2BalanceAfterExecution.sub(l2BalanceBeforeExecution).gte(amount) + ).to.be.true; + expect( + l1BalanceBeforeExecution.sub(l1BalanceAfterExecution).gte(amount) + ).to.be.true; + }).timeout(10_000); + } }); describe('#transfer()', () => { it('should transfer ETH', async () => { const amount = 7_000_000_000; - const balanceBeforeTransfer = await provider.getBalance(RECEIVER); + const balanceBeforeTransfer = await provider.getBalance(ADDRESS2); const tx = await wallet.transfer({ - token: utils.ETH_ADDRESS, - to: RECEIVER, + token: utils.LEGACY_ETH_ADDRESS, + to: ADDRESS2, amount: amount, }); const result = await tx.wait(); - const balanceAfterTransfer = await provider.getBalance(RECEIVER); + const balanceAfterTransfer = await provider.getBalance(ADDRESS2); expect(result).not.to.be.null; expect(balanceAfterTransfer.sub(balanceBeforeTransfer).eq(amount)).to.be .true; @@ -1014,20 +1481,20 @@ describe('Wallet', () => { const paymasterTokenBalanceBeforeTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceBeforeTransfer = await wallet.getBalance(); const senderApprovalTokenBalanceBeforeTransfer = - await wallet.getBalance(TOKEN); - const receiverBalanceBeforeTransfer = await provider.getBalance(RECEIVER); + await wallet.getBalance(APPROVAL_TOKEN); + const receiverBalanceBeforeTransfer = await provider.getBalance(ADDRESS2); const tx = await wallet.transfer({ - token: utils.ETH_ADDRESS, - to: RECEIVER, + token: utils.LEGACY_ETH_ADDRESS, + to: ADDRESS2, amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -1039,12 +1506,12 @@ describe('Wallet', () => { const paymasterTokenBalanceAfterTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceAfterTransfer = await wallet.getBalance(); const senderApprovalTokenBalanceAfterTransfer = - await wallet.getBalance(TOKEN); - const receiverBalanceAfterTransfer = await provider.getBalance(RECEIVER); + await wallet.getBalance(APPROVAL_TOKEN); + const receiverBalanceAfterTransfer = await provider.getBalance(ADDRESS2); expect( paymasterBalanceBeforeTransfer.sub(paymasterBalanceAfterTransfer).gte(0) @@ -1076,18 +1543,18 @@ describe('Wallet', () => { const amount = 5; const l2DAI = await provider.l2TokenAddress(DAI_L1); const balanceBeforeTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); const tx = await wallet.transfer({ token: l2DAI, - to: RECEIVER, + to: ADDRESS2, amount: amount, }); const result = await tx.wait(); const balanceAfterTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); @@ -1106,24 +1573,24 @@ describe('Wallet', () => { const paymasterTokenBalanceBeforeTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceBeforeTransfer = await wallet.getBalance(l2DAI); const senderApprovalTokenBalanceBeforeTransfer = - await wallet.getBalance(TOKEN); + await wallet.getBalance(APPROVAL_TOKEN); const receiverBalanceBeforeTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); const tx = await wallet.transfer({ token: l2DAI, - to: RECEIVER, + to: ADDRESS2, amount: amount, paymasterParams: utils.getPaymasterParams(PAYMASTER, { type: 'ApprovalBased', - token: TOKEN, + token: APPROVAL_TOKEN, minimalAllowance: BigNumber.from(1), innerInput: new Uint8Array(), }), @@ -1135,13 +1602,13 @@ describe('Wallet', () => { const paymasterTokenBalanceAfterTransfer = await provider.getBalance( PAYMASTER, 'latest', - TOKEN + APPROVAL_TOKEN ); const senderBalanceAfterTransfer = await wallet.getBalance(l2DAI); const senderApprovalTokenBalanceAfterTransfer = - await wallet.getBalance(TOKEN); + await wallet.getBalance(APPROVAL_TOKEN); const receiverBalanceAfterTransfer = await provider.getBalance( - RECEIVER, + ADDRESS2, 'latest', l2DAI ); @@ -1171,13 +1638,30 @@ describe('Wallet', () => { .eq(amount) ).to.be.true; }).timeout(25_000); + + if (!IS_ETH_BASED) { + it('should transfer base token', async () => { + const amount = 7_000_000_000; + const balanceBeforeTransfer = await provider.getBalance(ADDRESS2); + const tx = await wallet.transfer({ + token: await wallet.getBaseToken(), + to: ADDRESS2, + amount: amount, + }); + const result = await tx.wait(); + const balanceAfterTransfer = await provider.getBalance(ADDRESS2); + expect(result).not.to.be.null; + expect(balanceAfterTransfer.sub(balanceBeforeTransfer).eq(amount)).to.be + .true; + }).timeout(25_000); + } }); describe('#signTransaction()', () => { it('should return a signed type EIP1559 transaction', async () => { const result = await wallet.signTransaction({ type: 2, - to: RECEIVER, + to: ADDRESS2, value: BigNumber.from(7_000_000_000), }); expect(result).not.to.be.null; @@ -1186,7 +1670,7 @@ describe('Wallet', () => { it('should return a signed EIP712 transaction', async () => { const result = await wallet.signTransaction({ type: utils.EIP712_TX_TYPE, - to: RECEIVER, + to: ADDRESS2, value: ethers.utils.parseEther('1'), }); expect(result).not.to.be.null; @@ -1196,8 +1680,8 @@ describe('Wallet', () => { try { await wallet.signTransaction({ type: utils.EIP712_TX_TYPE, - from: RECEIVER, - to: RECEIVER, + from: ADDRESS2, + to: ADDRESS2, value: 7_000_000_000, }); } catch (e) { diff --git a/tests/setup.ts b/tests/setup.ts index 76779890..01be616a 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -1,23 +1,16 @@ import { Provider, - types, Wallet, ContractFactory, Contract, + types, utils, } from '../src'; import {ethers} from 'ethers'; -import fs from 'fs'; -import {Il1Bridge} from '../src/typechain/Il1Bridge'; +import {ITestnetErc20TokenFactory} from '../typechain/ITestnetErc20TokenFactory'; -import TokensL1 from './files/tokens.json'; import Token from './files/Token.json'; import Paymaster from './files/Paymaster.json'; -import TokenL2Bridged from './files/TokenL2Bridged.json'; -import TokenL1 from './files/TokenL1.json'; -import CustomBridgeL1 from './files/CustomBridgeL1.json'; -import CustomBridgeL2 from './files/CustomBridgeL2.json'; -import DiamondProxy from './files/diamondProxy.json'; const PRIVATE_KEY = '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; @@ -27,6 +20,7 @@ const ethProvider = ethers.getDefaultProvider('http://127.0.0.1:8545'); const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider); +const DAI_L1 = '0x70a0F165d6f8054d0d0CF8dFd4DD2005f0AF6B55'; const SALT = '0x293328ad84b118194c65a0dc0defdb6483740d3163fd99b260907e15f2e2f642'; const TOKEN = '0x841c43Fa5d8fFfdB9efE3358906f7578d8700Dd4'; // deployed by using create2 and SALT @@ -89,84 +83,107 @@ async function deployPaymasterAndToken(): Promise<{ return {token: tokenAddress, paymaster: paymasterAddress}; } -// Creates token on L2 by depositing -async function createTokenL2(l1TokenAddress: string): Promise { +/* +Mints tokens on L1 in case L2 is non-ETH based chain. +It mints based token, provided alternative tokens (different from base token) and wETH. +*/ +async function mintTokensOnL1(alternativeToken: string) { + const bridgehub = await wallet.getBridgehubContract(); + const chainId = (await provider.getNetwork()).chainId; + const baseTokenAddress = await bridgehub.baseToken(chainId); + + if (baseTokenAddress !== utils.ETH_ADDRESS_IN_CONTRACTS) { + const baseToken = ITestnetErc20TokenFactory.connect( + baseTokenAddress, + wallet._signerL1() + ); + const baseTokenMintTx = await baseToken.mint( + await wallet.getAddress(), + ethers.utils.parseEther('20000') + ); + await baseTokenMintTx.wait(); + } + + const altToken = ITestnetErc20TokenFactory.connect( + alternativeToken, + wallet._signerL1() + ); + const altTokenMintTx = await altToken.mint( + await wallet.getAddress(), + ethers.utils.parseEther('20000') + ); + await altTokenMintTx.wait(); + console.log('Minting tokens on L1 finished'); +} + +/* +Send base token to L2 in case L2 in non-ETH base chain. +*/ +async function sendTokenToL2(l1TokenAddress: string) { const priorityOpResponse = await wallet.deposit({ token: l1TokenAddress, to: await wallet.getAddress(), - amount: 100, + amount: ethers.utils.parseEther('10000'), approveERC20: true, + approveBaseERC20: true, refundRecipient: await wallet.getAddress(), }); - await priorityOpResponse.waitFinalize(); - return await wallet.l2TokenAddress(l1TokenAddress); + const receipt = await priorityOpResponse.waitFinalize(); + console.log(`Send funds tx: ${receipt.transactionHash}`); } -async function deployCustomBridges() { - // deploy L2 token - const l2TokenFactory = new ContractFactory( - TokenL2Bridged.abi, - TokenL2Bridged.bytecode, - wallet - ); - const l2Token = (await l2TokenFactory.deploy('USDC', 'USDC', 18)) as Contract; +async function main() { + const baseToken = await wallet.getBaseToken(); + console.log(`Wallet address: ${await wallet.getAddress()}`); + console.log(`Base token L1: ${baseToken}`); - // deploy L1 token - const l1TokenFactory = new ethers.ContractFactory( - TokenL1.abi, - TokenL1.bytecode, - wallet._signerL1() + console.log( + `L1 base token balance before: ${await wallet.getBalanceL1(baseToken)}` ); - const l1Token = (await l1TokenFactory.deploy('USDC', 'USDC', 18)) as Contract; - - // mint token to L1 - const tx = await l1Token.mint(wallet.address, ethers.utils.parseEther('100')); - await tx.wait(); - - // deploy custom bridges - const gasPrice = (await ethProvider.getFeeData()).gasPrice!; - const zkSync = await wallet.getMainContract(); - const requiredValueToInitializeBridge = await zkSync.l2TransactionBaseCost( - gasPrice, - 10_000_000, - utils.REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT + console.log(`L2 base token balance before: ${await wallet.getBalance()}`); + + await mintTokensOnL1(baseToken); + await sendTokenToL2(baseToken); + + console.log( + `L1 base token balance after: ${await wallet.getBalanceL1(baseToken)}` ); - const l1BridgeFactory = new ethers.ContractFactory( - CustomBridgeL1.abi, - CustomBridgeL1.bytecode, - wallet._signerL1() + console.log(`L2 base token balance after: ${await wallet.getBalance()} \n`); + + if (baseToken !== utils.ETH_ADDRESS_IN_CONTRACTS) { + const l2EthAddress = await wallet.l2TokenAddress( + utils.ETH_ADDRESS_IN_CONTRACTS + ); + console.log(`Eth L1: ${utils.ETH_ADDRESS_IN_CONTRACTS}`); + console.log(`Eth L2: ${l2EthAddress}`); + + console.log(`L1 eth balance before: ${await wallet.getBalanceL1()}`); + console.log( + `L2 eth balance before: ${await wallet.getBalance(l2EthAddress)}` + ); + + await mintTokensOnL1(utils.ETH_ADDRESS_IN_CONTRACTS); + await sendTokenToL2(utils.ETH_ADDRESS_IN_CONTRACTS); + + console.log(`L1 eth balance after: ${await wallet.getBalanceL1()}`); + console.log( + `L2 eth balance after: ${await wallet.getBalance(l2EthAddress)}\n` + ); + } + + const l2DAIAddress = await wallet.l2TokenAddress(DAI_L1); + console.log(`DAI L1: ${DAI_L1}`); + console.log(`DAI L2: ${l2DAIAddress}`); + + console.log(`L1 DAI balance before: ${await wallet.getBalanceL1(DAI_L1)}`); + console.log( + `L2 DAI balance before: ${await wallet.getBalance(l2DAIAddress)}` ); - const l1Bridge = (await l1BridgeFactory.deploy( - [CustomBridgeL2.bytecode], - [l1Token.address, l2Token.address, DiamondProxy.address], - requiredValueToInitializeBridge, - { - gasPrice, - value: requiredValueToInitializeBridge, - gasLimit: 10_000_000, - } - )) as Il1Bridge; - - // connect L2 token to L2 custom bridge - await l2Token.setBridge(await l1Bridge.l2Bridge()); - - return { - l1Token: l1Token.address, - l2Token: l2Token.address, - l1Bridge: l1Bridge.address, - l2Bridge: await l1Bridge.l2Bridge(), - }; -} -/* -Deploy token to the L2 network through deposit transaction. -Deploy approval token and it's paymaster. -Deploy custom bridges for custom token. - */ -async function main() { - console.log('===== Depositing DAI to L2 ====='); - const l2TokenAddress = await createTokenL2(TokensL1[0].address); - console.log(`L2 DAI address: ${l2TokenAddress}`); + await mintTokensOnL1(DAI_L1); + await sendTokenToL2(DAI_L1); + console.log(`L1 DAI balance after: ${await wallet.getBalanceL1(DAI_L1)}`); + console.log(`L2 DAI balance after: ${await wallet.getBalance(l2DAIAddress)}`); console.log('===== Deploying token and paymaster ====='); const {token, paymaster} = await deployPaymasterAndToken(); @@ -174,21 +191,6 @@ async function main() { console.log(`Paymaster: ${paymaster}`); console.log(`Paymaster ETH balance: ${await provider.getBalance(paymaster)}`); console.log(`Wallet Crown balance: ${await wallet.getBalance(token)}`); - - console.log('===== Deploying custom bridges ====='); - const customAddresses = await deployCustomBridges(); - const {l1Token, l2Token, l1Bridge, l2Bridge} = customAddresses; - console.log(`L1 USDC address: ${l1Token}`); - console.log(`L2 USDC address: ${l2Token}`); - console.log(`L1 custom bridge address: ${l1Bridge}`); - console.log(`L2 custom bridge address: ${l2Bridge}`); - console.log(`L1 USDC balance: ${await wallet.getBalanceL1(l1Token)}`); - console.log(`L2 USDC balance: ${await wallet.getBalance(l2Token)}`); - - fs.writeFileSync( - 'tests/files/customBridge.json', - utils.toJSON(customAddresses) - ); } main() diff --git a/tests/unit/signer.test.ts b/tests/unit/signer.test.ts index c9b65ad1..7cdc30f9 100644 --- a/tests/unit/signer.test.ts +++ b/tests/unit/signer.test.ts @@ -2,19 +2,17 @@ import * as chai from 'chai'; import '../custom-matchers'; import {utils, EIP712Signer} from '../../src'; import {ethers, BigNumber} from 'ethers'; +import {ADDRESS1, ADDRESS2} from '../utils'; const {expect} = chai; describe('EIP712Signer', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - describe('#getSignInput()', () => { it('should return a populated transaction', async () => { const tx = { txType: utils.EIP712_TX_TYPE, - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, gasLimit: BigNumber.from(21_000), gasPerPubdataByteLimit: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, maxFeePerGas: BigNumber.from(250_000_000), @@ -29,9 +27,9 @@ describe('EIP712Signer', () => { const result = EIP712Signer.getSignInput({ type: utils.EIP712_TX_TYPE, - to: RECEIVER, + to: ADDRESS2, value: BigNumber.from(7_000_000), - from: ADDRESS, + from: ADDRESS1, nonce: 0, chainId: 270, gasPrice: BigNumber.from(250_000_000), @@ -44,8 +42,8 @@ describe('EIP712Signer', () => { it('should return a populated transaction with default values', async () => { const tx = { txType: utils.EIP712_TX_TYPE, - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, gasLimit: 0, gasPerPubdataByteLimit: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, maxFeePerGas: 0, @@ -60,8 +58,8 @@ describe('EIP712Signer', () => { const result = EIP712Signer.getSignInput({ type: utils.EIP712_TX_TYPE, - to: RECEIVER, - from: ADDRESS, + to: ADDRESS2, + from: ADDRESS1, }); expect(result).to.be.deep.equal(tx); }); diff --git a/tests/unit/smart-account.test.ts b/tests/unit/smart-account.test.ts index 4f58ad9e..33801092 100644 --- a/tests/unit/smart-account.test.ts +++ b/tests/unit/smart-account.test.ts @@ -10,26 +10,22 @@ import { } from '../../src/smart-account-utils'; import {BigNumber} from 'ethers'; import {_TypedDataEncoder, hashMessage} from '@ethersproject/hash'; +import {PRIVATE_KEY1, ADDRESS1, PRIVATE_KEY2, ADDRESS2} from '../utils'; const {expect} = chai; describe('signPayloadWithECDSA()', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - it('should return signature by signing EIP712 transaction hash', async () => { const tx: types.TransactionRequest = { chainId: 270, - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, value: 7_000_000_000, }; const txHash = EIP712Signer.getSignedDigest(tx); - const result = await signPayloadWithECDSA(txHash, PRIVATE_KEY); + const result = await signPayloadWithECDSA(txHash, PRIVATE_KEY1); expect(result).to.be.equal( '0x89905d36a3cdde117445d6c58627061a53f09cf0535d73719d82d4d96fe332541167e2e3d38ce3cb2751a0203eff2a71f55ad45dc91623587f5480ec1883281b1b' ); @@ -39,7 +35,7 @@ describe('signPayloadWithECDSA()', () => { const message = 'Hello World!'; const messageHash = hashMessage(message); - const result = await signPayloadWithECDSA(messageHash, PRIVATE_KEY); + const result = await signPayloadWithECDSA(messageHash, PRIVATE_KEY1); expect(result).to.be.equal( '0x7c15eb760c394b0ca49496e71d841378d8bfd4f9fb67e930eb5531485329ab7c67068d1f8ef4b480ec327214ee6ed203687e3fbe74b92367b259281e340d16fd1c' ); @@ -56,7 +52,7 @@ describe('signPayloadWithECDSA()', () => { }, {name: 'John', age: 30} ); - const result = await signPayloadWithECDSA(typedDataHash, PRIVATE_KEY); + const result = await signPayloadWithECDSA(typedDataHash, PRIVATE_KEY1); expect(result).to.be.equal( '0xbcaf0673c0c2b0e120165d207d42281d0c6e85f0a7f6b8044b0578a91cf5bda66b4aeb62aca4ae17012a38d71c9943e27285792fa7d788d848f849e3ea2e614b1b' ); @@ -64,13 +60,6 @@ describe('signPayloadWithECDSA()', () => { }); describe('signPayloadWithMultipleECDSA()', () => { - const ADDRESS1 = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY1 = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const ADDRESS2 = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const PRIVATE_KEY2 = - '0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3'; - it('should return signature by signing EIP712 transaction hash', async () => { const tx: TransactionRequest = { chainId: 270, @@ -125,51 +114,46 @@ describe('signPayloadWithMultipleECDSA()', () => { }); describe('populateTransaction()', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - const provider = Provider.getDefaultProvider(types.Network.Localhost); it('should populate `tx.from` to address derived from private key if it not set', async () => { const tx: TransactionRequest = { chainId: 270, - to: '0xa61464658AfeAf65CccaaFD3a512b69A83B77618', + to: ADDRESS2, value: BigNumber.from(7_000_000_000), type: 113, data: '0x', - gasPrice: BigNumber.from(250_000_000), - gasLimit: BigNumber.from(154_379), + gasPrice: BigNumber.from(100_000_000), + gasLimit: BigNumber.from(190_560), customData: { gasPerPubdata: 50_000, factoryDeps: [], }, - from: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049', + from: ADDRESS1, }; const result = await populateTransactionECDSA( { chainId: 270, - to: RECEIVER, + to: ADDRESS2, value: 7_000_000_000, }, - PRIVATE_KEY, + PRIVATE_KEY1, provider ); - expect(result).to.be.deepEqualExcluding(tx, ['nonce']); + expect(result).to.be.deepEqualExcluding(tx, ['nonce', 'gasLimit']); }); it('should throw an error when provider is not set', async () => { const tx: TransactionRequest = { chainId: 270, - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, value: 7_000_000_000, }; try { - await populateTransactionECDSA(tx, PRIVATE_KEY); + await populateTransactionECDSA(tx, PRIVATE_KEY1); } catch (error) { expect((error as Error).message).to.be.equal( 'Provider is required but is not provided!' @@ -179,21 +163,16 @@ describe('populateTransaction()', () => { }); describe('populateTransactionMultisig()', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const PRIVATE_KEY = - '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - it('should throw an error when multiple keys are not provided', async () => { const tx: TransactionRequest = { chainId: 270, - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, value: 7_000_000_000, }; try { - await populateTransactionMultisigECDSA(tx, PRIVATE_KEY); + await populateTransactionMultisigECDSA(tx, PRIVATE_KEY1); } catch (error) { expect((error as Error).message).to.be.equal( 'Multiple keys are required to build the transaction!' diff --git a/tests/unit/util.test.ts b/tests/unit/util.test.ts index dd201ecf..9905ef31 100644 --- a/tests/unit/util.test.ts +++ b/tests/unit/util.test.ts @@ -1,37 +1,40 @@ import {expect} from 'chai'; import {utils} from '../../src'; import {ethers, BigNumber} from 'ethers'; +import {ADDRESS1, ADDRESS2} from '../utils'; describe('utils', () => { - const ADDRESS = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; - const RECEIVER = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; - describe('#getHashedL2ToL1Msg()', () => { it('should return a hashed L2 to L1 message', async () => { const withdrawETHMessage = '0x6c0960f936615cf349d7f6344891b1e7ca7c72883f5dc04900000000000000000000000000000000000000000000000000000001a13b8600'; const withdrawETHMessageHash = '0x521bd25904766c83fe868d6a29cbffa011afd8a1754f6c9a52b053b693e42f18'; - const result = utils.getHashedL2ToL1Msg(ADDRESS, withdrawETHMessage, 0); + const result = utils.getHashedL2ToL1Msg(ADDRESS1, withdrawETHMessage, 0); expect(result).to.be.equal(withdrawETHMessageHash); }); }); describe('#isETH()', () => { + it('should return true for legacy L1 ETH address', async () => { + const result = utils.isETH(utils.LEGACY_ETH_ADDRESS); + expect(result).to.be.true; + }); + it('should return true for L1 ETH address', async () => { - const result = utils.isETH(utils.ETH_ADDRESS); + const result = utils.isETH(utils.ETH_ADDRESS_IN_CONTRACTS); expect(result).to.be.true; }); it('should return true for L2 ETH address', async () => { - const result = utils.isETH(utils.L2_ETH_TOKEN_ADDRESS); + const result = utils.isETH(utils.L2_BASE_TOKEN_ADDRESS); expect(result).to.be.true; }); }); describe('#createAddress()', () => { it('should return the correct address', async () => { - const address = utils.createAddress(ADDRESS, 1); + const address = utils.createAddress(ADDRESS1, 1); expect(address).to.be.equal('0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021'); }); }); @@ -39,7 +42,7 @@ describe('utils', () => { describe('#create2Address()', () => { it('should return the correct address', async () => { const address = utils.create2Address( - ADDRESS, + ADDRESS1, '0x010001cb6a6e8d5f6829522f19fa9568660e0a9cd53b2e8be4deb0a679452e41', '0x01', '0x01' @@ -132,7 +135,7 @@ describe('utils', () => { try { utils.serialize({ chainId: 270, - from: ADDRESS, + from: ADDRESS1, customData: { customSignature: '', }, @@ -150,7 +153,7 @@ describe('utils', () => { const result = utils.serialize({ type: 113, chainId: 270, - from: ADDRESS, + from: ADDRESS1, }); expect(result).to.be.equal(tx); }); @@ -165,8 +168,8 @@ describe('utils', () => { { type: 113, chainId: 270, - from: ADDRESS, - to: RECEIVER, + from: ADDRESS1, + to: ADDRESS2, value: 1_000_000, }, signature @@ -238,11 +241,11 @@ describe('utils', () => { maxPriorityFeePerGas: BigNumber.from(0), maxFeePerGas: BigNumber.from(0), gasLimit: BigNumber.from(0), - to: RECEIVER, + to: ADDRESS2, value: BigNumber.from(1000000), data: '0x', chainId: BigNumber.from(270), - from: ADDRESS, + from: ADDRESS1, customData: { gasPerPubdata: BigNumber.from(50000), factoryDeps: [], @@ -265,11 +268,11 @@ describe('utils', () => { maxPriorityFeePerGas: BigNumber.from(0), maxFeePerGas: BigNumber.from(0), gasLimit: BigNumber.from(0), - to: RECEIVER, + to: ADDRESS2, value: BigNumber.from(0), data: '0x', chainId: BigNumber.from(270), - from: ADDRESS, + from: ADDRESS1, customData: { gasPerPubdata: BigNumber.from(50000), factoryDeps: [], diff --git a/tests/utils.ts b/tests/utils.ts new file mode 100644 index 00000000..0a72a7d3 --- /dev/null +++ b/tests/utils.ts @@ -0,0 +1,13 @@ +export const ADDRESS1 = '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049'; +export const PRIVATE_KEY1 = + '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110'; +export const MNEMONIC1 = + 'stuff slice staff easily soup parent arm payment cotton trade scatter struggle'; +export const ADDRESS2 = '0xa61464658AfeAf65CccaaFD3a512b69A83B77618'; +export const PRIVATE_KEY2 = + '0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3'; +export const DAI_L1 = '0x70a0F165d6f8054d0d0CF8dFd4DD2005f0AF6B55'; +export const APPROVAL_TOKEN = '0x841c43Fa5d8fFfdB9efE3358906f7578d8700Dd4'; // Crown token +export const PAYMASTER = '0xa222f0c183AFA73a8Bc1AFb48D34C88c9Bf7A174'; // Crown token paymaster + +export const IS_ETH_BASED = true;