diff --git a/src/main/java/io/zksync/abi/ZkTypeEncoder.java b/src/main/java/io/zksync/abi/ZkTypeEncoder.java index 3362f81..52965e8 100644 --- a/src/main/java/io/zksync/abi/ZkTypeEncoder.java +++ b/src/main/java/io/zksync/abi/ZkTypeEncoder.java @@ -188,17 +188,15 @@ static String encodeBytes(BytesType bytesType) { byte[] value = bytesType.getValue(); int length = value.length; int mod = length % MAX_BYTE_LENGTH; - String val = Numeric.toHexString(value); byte[] dest; if (mod != 0) { int padding = MAX_BYTE_LENGTH - mod; dest = new byte[padding]; - return Numeric.toHexStringNoPrefix(dest) + Numeric.toHexStringNoPrefix(value); + return Numeric.toHexStringNoPrefix(value) + Numeric.toHexStringNoPrefix(dest); } else { dest = value; } - String x = Numeric.toHexString(value); return Numeric.toHexStringNoPrefix(dest); } diff --git a/src/main/java/io/zksync/protocol/JsonRpc2_0ZkSync.java b/src/main/java/io/zksync/protocol/JsonRpc2_0ZkSync.java index 8ab4eab..b1ec5dd 100755 --- a/src/main/java/io/zksync/protocol/JsonRpc2_0ZkSync.java +++ b/src/main/java/io/zksync/protocol/JsonRpc2_0ZkSync.java @@ -218,22 +218,11 @@ public Request estimateL1ToL2Execute(String contractAddress, } public Transaction getWithdrawTransaction(WithdrawTransaction tx, ContractGasProvider gasProvider, TransactionManager transactionManager) throws Exception { - boolean isEthBasedChain = isEthBasedChain(); - - if (tx.tokenAddress != null && - !tx.tokenAddress.isEmpty() && - tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS) && - !isEthBasedChain){ + tx.tokenAddress = tx.tokenAddress == null ? ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS : tx.tokenAddress; + if (tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS) || tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS)){ tx.tokenAddress = l2TokenAddress(ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS); - } else if (tx.tokenAddress == null || - tx.tokenAddress.isEmpty() || - isBaseToken(tx.tokenAddress)){ - tx.tokenAddress = ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS; } - if (tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS)){ - tx.tokenAddress = ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS; - } if (tx.from == null && tx.to == null){ throw new Error("Withdrawal target address is undefined!"); } @@ -241,7 +230,7 @@ public Transaction getWithdrawTransaction(WithdrawTransaction tx, ContractGasPro tx.to = tx.to == null ? tx.from : tx.to; tx.options = tx.options == null ? new TransactionOptions() : tx.options; - if (ZkSyncAddresses.isEth(tx.tokenAddress)){ + if (tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS)){ if (tx.options.getValue() == null){ tx.options.setValue(tx.amount); } @@ -253,7 +242,7 @@ public Transaction getWithdrawTransaction(WithdrawTransaction tx, ContractGasPro } IEthToken ethL2Token = IEthToken.load(ZkSyncAddresses.L2_ETH_TOKEN_ADDRESS, this, transactionManager, gasProvider); - String data = ethL2Token.encodeWithdraw(tx.to, passedValue); + String data = ethL2Token.encodeWithdraw(tx.to); Eip712Meta meta = new Eip712Meta(BigInteger.valueOf(50000), null, null, tx.paymasterParams); return new Transaction(tx.from, ZkSyncAddresses.L2_ETH_TOKEN_ADDRESS, BigInteger.ZERO, BigInteger.ZERO, tx.amount, data, meta); @@ -275,17 +264,9 @@ public Transaction getWithdrawTransaction(WithdrawTransaction tx, ContractGasPro } public Transaction getTransferTransaction(TransferTransaction tx, TransactionManager transactionManager, ContractGasProvider gasProvider){ - boolean isEthBasedChain = isEthBasedChain(); - - if (tx.tokenAddress != null && - !tx.tokenAddress.isEmpty() && - tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS) && - !isEthBasedChain){ + tx.tokenAddress = tx.tokenAddress == null ? ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS : tx.tokenAddress; + if (tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS) || tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS)){ tx.tokenAddress = l2TokenAddress(ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS); - } else if (tx.tokenAddress == null || - tx.tokenAddress.isEmpty() || - isBaseToken(tx.tokenAddress)){ - tx.tokenAddress = ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS; } tx.to = tx.to == null ? tx.from : tx.to; @@ -299,7 +280,7 @@ public Transaction getTransferTransaction(TransferTransaction tx, TransactionMan } Eip712Meta meta = new Eip712Meta(tx.gasPerPubData, null, null, tx.paymasterParams); - if (tx.tokenAddress == null || tx.tokenAddress == ZkSyncAddresses.LEGACY_ETH_ADDRESS || isBaseToken(tx.tokenAddress)){ + if (tx.tokenAddress.equalsIgnoreCase(ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS)){ return new Transaction(tx.from, tx.to, BigInteger.ZERO, gasPrice, tx.amount, "0x", meta); } ERC20 token = ERC20.load(tx.tokenAddress, this, transactionManager, gasProvider); diff --git a/src/main/java/io/zksync/protocol/account/Wallet.java b/src/main/java/io/zksync/protocol/account/Wallet.java index 34ad0e1..f107e56 100644 --- a/src/main/java/io/zksync/protocol/account/Wallet.java +++ b/src/main/java/io/zksync/protocol/account/Wallet.java @@ -97,7 +97,7 @@ public String getAddress(){ */ public L2BridgeContracts getL2BridgeContracts(){ BridgeAddresses bridgeAddresses = providerL2.zksGetBridgeContracts().sendAsync().join().getResult(); - return new L2BridgeContracts(bridgeAddresses.getL2Erc20DefaultBridge(), bridgeAddresses.getL2WethBridge(), providerL2, transactionManager, feeProviderL2); + return new L2BridgeContracts(bridgeAddresses.l2Erc20DefaultBridge, bridgeAddresses.l2WethBridge, bridgeAddresses.l2SharedDefaultBridge, providerL2, transactionManager, feeProviderL2); } public CompletableFuture getDeploymentNonce(){ @@ -295,7 +295,7 @@ public RemoteCall execute(String contractAddress, Function f * @return Prepared get balance call */ public RemoteCall getBalance() { - return getBalance(getAddress(), getBaseToken().sendAsync().join(), ZkBlockParameterName.COMMITTED); + return getBalance(getAddress(), ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS, ZkBlockParameterName.COMMITTED); } /** @@ -329,10 +329,10 @@ public RemoteCall getBalance(String address, String token) { * @return Prepared get balance call */ public RemoteCall getBalance(String address, String token, DefaultBlockParameter at) { - if (token.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS)){ - token = ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS; + if (token.equalsIgnoreCase(ZkSyncAddresses.LEGACY_ETH_ADDRESS) || token.equalsIgnoreCase(ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS)){ + token = l2TokenAddress(ZkSyncAddresses.ETH_ADDRESS_IN_CONTRACTS); } - if (providerL2.isBaseToken(token)) { + if (token.equalsIgnoreCase(ZkSyncAddresses.L2_BASE_TOKEN_ADDRESS)) { return new RemoteCall<>(() -> this.providerL2.ethGetBalance(address, at).sendAsync().join().getBalance()); } else { diff --git a/src/main/java/io/zksync/protocol/account/WalletL1.java b/src/main/java/io/zksync/protocol/account/WalletL1.java index 3519795..410191f 100644 --- a/src/main/java/io/zksync/protocol/account/WalletL1.java +++ b/src/main/java/io/zksync/protocol/account/WalletL1.java @@ -5,6 +5,7 @@ import io.zksync.methods.response.FullDepositFee; import io.zksync.methods.response.L2toL1Log; import io.zksync.methods.response.ZkTransactionReceipt; +import io.zksync.methods.response.ZksMessageProof; import io.zksync.protocol.ZkSync; import io.zksync.protocol.core.BridgeAddresses; import io.zksync.protocol.core.L2ToL1MessageProof; @@ -13,10 +14,7 @@ import io.zksync.transaction.type.*; import io.zksync.utils.WalletUtils; import io.zksync.utils.ZkSyncAddresses; -import io.zksync.wrappers.ERC20; -import io.zksync.wrappers.IBridgehub; -import io.zksync.wrappers.IL1Bridge; -import io.zksync.wrappers.IZkSync; +import io.zksync.wrappers.*; import lombok.Getter; import org.jetbrains.annotations.Nullable; import org.web3j.abi.EventValues; @@ -33,10 +31,7 @@ import org.web3j.protocol.Web3j; import org.web3j.protocol.core.*; import org.web3j.protocol.core.methods.request.Transaction; -import org.web3j.protocol.core.methods.response.EthEstimateGas; -import org.web3j.protocol.core.methods.response.EthSendTransaction; -import org.web3j.protocol.core.methods.response.Log; -import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.protocol.core.methods.response.*; import org.web3j.tx.Contract; import org.web3j.tx.RawTransactionManager; import org.web3j.tx.TransactionManager; @@ -71,7 +66,7 @@ public class WalletL1 { protected final TransactionReceiptProcessor transactionReceiptProcessorL1; protected final ContractGasProvider gasProvider; protected final String mainContractAddress; - protected final IZkSync contract; + protected final IZkSyncHyperchain contract; protected final EthSigner signer; protected final Credentials credentials; public WalletL1(Web3j providerL1, ZkSync providerL2, TransactionManager transactionManager, ContractGasProvider gasProvider, Credentials credentials) { @@ -80,7 +75,7 @@ public WalletL1(Web3j providerL1, ZkSync providerL2, TransactionManager transact this.transactionManager = transactionManager; this.gasProvider = gasProvider; this.mainContractAddress = providerL2.zksMainContract().sendAsync().join().getResult(); - this.contract = IZkSync.load(providerL2.zksMainContract().sendAsync().join().getResult(), providerL1, transactionManager, gasProvider); + this.contract = IZkSyncHyperchain.load(providerL2.zksMainContract().sendAsync().join().getResult(), providerL1, transactionManager, gasProvider); this.credentials = credentials; this.signer = new PrivateKeyEthSigner(credentials, providerL1.ethChainId().sendAsync().join().getChainId().longValue()); this.transactionReceiptProcessorL1 = new PollingTransactionReceiptProcessor(providerL1, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH); @@ -100,9 +95,9 @@ public WalletL1(Web3j providerL1, ZkSync providerL2, Credentials credentials){ * * @return IZkSync */ - public IZkSync getMainContract(){ + public IZkSyncHyperchain getMainContract(){ if (contract == null){ - return IZkSync.load(providerL2.zksMainContract().sendAsync().join().getResult(), providerL1, transactionManager, gasProvider); + return IZkSyncHyperchain.load(providerL2.zksMainContract().sendAsync().join().getResult(), providerL1, transactionManager, gasProvider); } return contract; } @@ -454,7 +449,7 @@ private Request _depositBaseTokenToNonETHBasedChain(Depos IBridgehub bridgehub = getBridgehubContract(); BigInteger chainId = providerL2.ethChainId().sendAsync().join().getChainId(); String baseTokenAddress = getBaseToken().sendAsync().join(); - IL1Bridge sharedL1Bridge = getL1BridgeContracts().sharedL1Bridge; + IL1SharedBridge sharedL1Bridge = getL1BridgeContracts().sharedL1Bridge; GetDepositTransaction depositTransaction = _getDepositBaseTokenOnNonETHBasedChainTx(transaction); RequestExecuteTransaction tx = depositTransaction.requestExecuteTransaction; @@ -479,7 +474,7 @@ private Request _depositBaseTokenToNonETHBasedChain(Depos private Request _depositETHToNonETHBasedChain(DepositTransaction transaction) throws Exception { String baseTokenAddress = getBaseToken().sendAsync().join(); - IL1Bridge sharedL1Bridge = getL1BridgeContracts().sharedL1Bridge; + IL1SharedBridge sharedL1Bridge = getL1BridgeContracts().sharedL1Bridge; GetDepositTransaction depositTransaction = _getDepositETHOnNonETHBasedChainTx(transaction); Transaction tx = depositTransaction.tx; @@ -647,7 +642,7 @@ private GetDepositTransaction _getDepositBaseTokenOnNonETHBasedChainTx(DepositTr private GetDepositTransaction _getDepositETHOnNonETHBasedChainTx(DepositTransaction transaction) throws Exception { IBridgehub bridgehub = getBridgehubContract(); BigInteger chainId = providerL2.ethChainId().sendAsync().join().getChainId(); - IL1Bridge sharedBridge = getL1BridgeContracts().sharedL1Bridge; + IL1SharedBridge sharedBridge = getL1BridgeContracts().sharedL1Bridge; _getDepositTxWithDefaults(transaction); @@ -916,12 +911,39 @@ public RemoteCall getFullRequiredDepositFee(DepositTransaction t return fullFee; }); } + public CompletableFuture isWithdrawalFinalized(String txHash){ + return isWithdrawalFinalized(txHash, 0); + } + + public CompletableFuture isWithdrawalFinalized(String txHash, int index){ + ZkTransactionReceipt receipt = providerL2.zksGetTransactionReceipt(txHash).sendAsync().join().getResult(); + int logIndex = getWithdrawalLogIndex(receipt.getLogs(), index); + Log log = receipt.getLogs().get(logIndex); - public void getPriorityOpConfirmation(String txHash, int index){ + int l2ToL1LogIndex = getWithdrawalL2ToL1LogIndex(receipt.getl2ToL1Logs(), index); + String sender = Numeric.prependHexPrefix(log.getTopics().get(1).substring(26)); + + CompletableFuture proof = providerL2.zksGetL2ToL1LogProof(txHash, l2ToL1LogIndex).sendAsync(); + CompletableFuture chainId = providerL2.ethChainId().sendAsync(); + + IL1SharedBridge sharedBridge; + if (providerL2.isBaseToken(sender)){ + sharedBridge = getL1BridgeContracts().sharedL1Bridge; + }else{ + IL2SharedBridge sharedBridgeL2 = IL2SharedBridge.load(sender, providerL2, credentials, gasProvider); + String l1BridgeAddress = sharedBridgeL2.l1SharedBridge().sendAsync().join(); + sharedBridge = IL1SharedBridge.load(l1BridgeAddress, providerL1, credentials, gasProvider); + } + + if (proof.join() == null){ + throw new Error("Log proof not found!"); + } + + return sharedBridge.isWithdrawalFinalized(chainId.join().getChainId(), receipt.getL1BatchNumber(), BigInteger.valueOf(proof.join().getId())).sendAsync(); } - public RemoteFunctionCall finalizeWithdraw(String txHash, int index) throws Exception { + public CompletableFuture finalizeWithdraw(String txHash, int index) throws Exception { ZkTransactionReceipt receipt = providerL2.zksGetTransactionReceipt(txHash).sendAsync().join().getResult(); int logIndex = getWithdrawalLogIndex(receipt.getLogs(), index); @@ -940,9 +962,21 @@ public RemoteFunctionCall finalizeWithdraw(String txHash, in merkle_proof.add(Numeric.hexStringToByteArray(l2ToL1MessageProof.getProof().get(i))); } - IL1Bridge il1Bridge = IL1Bridge.load(getL1BridgeContracts().sharedL1Bridge.getContractAddress(), providerL1, transactionManager, gasProvider); + String il1BridgeAddress = getL1BridgeContracts().sharedL1Bridge.getContractAddress(); + + String calldata = IL1SharedBridge.encodeFinalizeWithdrawal( + providerL2.ethChainId().sendAsync().join().getChainId(), + l1BatchNumber, + BigInteger.valueOf(l2ToL1MessageProof.getId()), + receipt.getL1BatchTxIndex(), + bytes_data, + merkle_proof + ); + + Transaction tx = Transaction.createEthCallTransaction(credentials.getAddress(), il1BridgeAddress, calldata); + BigInteger gas = providerL1.ethEstimateGas(tx).sendAsync().join().getAmountUsed(); - return il1Bridge.finalizeWithdrawal(providerL2.ethChainId().sendAsync().join().getChainId(), l1BatchNumber, BigInteger.valueOf(l2ToL1MessageProof.getId()), receipt.getL1BatchTxIndex(), bytes_data, merkle_proof); + return providerL1.ethSendRawTransaction(Numeric.toHexStringNoPrefix(TransactionEncoder.signMessage(RawTransaction.createTransaction(providerL1.ethGetTransactionCount(signer.getAddress(), DefaultBlockParameterName.LATEST).sendAsync().join().getTransactionCount(), providerL1.ethGasPrice().sendAsync().join().getGasPrice(), gas, il1BridgeAddress, calldata), credentials))).sendAsync(); } public int getWithdrawalLogIndex(List logs, int index){ diff --git a/src/main/java/io/zksync/protocol/core/BridgeAddresses.java b/src/main/java/io/zksync/protocol/core/BridgeAddresses.java index 02ba6db..6e994ae 100644 --- a/src/main/java/io/zksync/protocol/core/BridgeAddresses.java +++ b/src/main/java/io/zksync/protocol/core/BridgeAddresses.java @@ -8,10 +8,10 @@ @NoArgsConstructor @Data public class BridgeAddresses { - private String l1Erc20DefaultBridge; - private String l2Erc20DefaultBridge; - private String l1WethBridge; - private String l2WethBridge; - private String l1SharedDefaultBridge; - private String l2SharedDefaultBridge; + public String l1Erc20DefaultBridge; + public String l2Erc20DefaultBridge; + public String l1WethBridge; + public String l2WethBridge; + public String l1SharedDefaultBridge; + public String l2SharedDefaultBridge; } diff --git a/src/main/java/io/zksync/transaction/type/DepositTransaction.java b/src/main/java/io/zksync/transaction/type/DepositTransaction.java index bf9f416..9a802eb 100644 --- a/src/main/java/io/zksync/transaction/type/DepositTransaction.java +++ b/src/main/java/io/zksync/transaction/type/DepositTransaction.java @@ -91,22 +91,6 @@ public Transaction toTx(String from, String calldata){ return new Transaction(from, options.getNonce(), options.getGasPrice(), BigInteger.ZERO, bridgeAddress, options.getValue(), calldata, options.getChainId().longValue(), options.getMaxPriorityFeePerGas(), options.getMaxFeePerGas()); } - public Transaction toFunctionCallTx(String from, IL1Bridge bridge){ - String data = bridge.encodeDeposit(from, tokenAddress, amount, l2GasLimit, gasPerPubdataByte, refoundRecepient, options.getValue()); - return new Transaction( - from, - options.getNonce(), - options.getGasPrice(), - options.getGasLimit(), - bridge.getContractAddress(), - options.getValue(), - data, - options.getChainId().longValue(), - options.getMaxPriorityFeePerGas(), - options.getMaxFeePerGas()); - } - - @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/src/main/java/io/zksync/transaction/type/L1BridgeContracts.java b/src/main/java/io/zksync/transaction/type/L1BridgeContracts.java index 2fe11d1..c261f05 100644 --- a/src/main/java/io/zksync/transaction/type/L1BridgeContracts.java +++ b/src/main/java/io/zksync/transaction/type/L1BridgeContracts.java @@ -1,6 +1,7 @@ package io.zksync.transaction.type; import io.zksync.wrappers.IL1Bridge; +import io.zksync.wrappers.IL1SharedBridge; import org.web3j.crypto.Credentials; import org.web3j.protocol.Web3j; import org.web3j.tx.TransactionManager; @@ -9,15 +10,15 @@ public class L1BridgeContracts { public IL1Bridge erc20L1Bridge; public IL1Bridge wethL1Bridge; - public IL1Bridge sharedL1Bridge; + public IL1SharedBridge sharedL1Bridge; - public L1BridgeContracts(IL1Bridge erc20L1Bridge, IL1Bridge wethL1Bridge, IL1Bridge sharedL1Bridge) { + public L1BridgeContracts(IL1Bridge erc20L1Bridge, IL1Bridge wethL1Bridge, IL1SharedBridge sharedL1Bridge) { this.erc20L1Bridge = erc20L1Bridge; this.wethL1Bridge = wethL1Bridge; this.sharedL1Bridge = sharedL1Bridge; } public L1BridgeContracts(String erc20L1Bridge, String wethL1Bridge, String sharedL1Bridge, Web3j providerL1, TransactionManager manager, ContractGasProvider gasProvider) { - this(IL1Bridge.load(erc20L1Bridge, providerL1, manager, gasProvider), IL1Bridge.load(wethL1Bridge, providerL1, manager, gasProvider), IL1Bridge.load(sharedL1Bridge, providerL1, manager, gasProvider)); + this(IL1Bridge.load(erc20L1Bridge, providerL1, manager, gasProvider), IL1Bridge.load(wethL1Bridge, providerL1, manager, gasProvider), IL1SharedBridge.load(sharedL1Bridge, providerL1, manager, gasProvider)); } } diff --git a/src/main/java/io/zksync/transaction/type/L2BridgeContracts.java b/src/main/java/io/zksync/transaction/type/L2BridgeContracts.java index b84099f..7690804 100644 --- a/src/main/java/io/zksync/transaction/type/L2BridgeContracts.java +++ b/src/main/java/io/zksync/transaction/type/L2BridgeContracts.java @@ -3,6 +3,7 @@ import io.zksync.protocol.ZkSync; import io.zksync.wrappers.IL1Bridge; import io.zksync.wrappers.IL2Bridge; +import io.zksync.wrappers.IL2SharedBridge; import org.web3j.protocol.Web3j; import org.web3j.tx.TransactionManager; import org.web3j.tx.gas.ContractGasProvider; @@ -10,13 +11,15 @@ public class L2BridgeContracts { public IL2Bridge erc20L2Bridge; public IL2Bridge wethL2Bridge; + public IL2SharedBridge sharedL2Bridge; - public L2BridgeContracts(IL2Bridge erc20L1Bridge, IL2Bridge wethL1Bridge) { + public L2BridgeContracts(IL2Bridge erc20L1Bridge, IL2Bridge wethL1Bridge, IL2SharedBridge sharedL2Bridge) { this.erc20L2Bridge = erc20L1Bridge; this.wethL2Bridge = wethL1Bridge; + this.sharedL2Bridge = sharedL2Bridge; } - public L2BridgeContracts(String erc20L2Bridge, String wethL2Bridge, ZkSync providerL2, TransactionManager manager, ContractGasProvider gasProvider) { - this(IL2Bridge.load(erc20L2Bridge, providerL2, manager, gasProvider), IL2Bridge.load(wethL2Bridge, providerL2, manager, gasProvider)); + public L2BridgeContracts(String erc20L2Bridge, String wethL2Bridge, String sharedL2Bridge, ZkSync providerL2, TransactionManager manager, ContractGasProvider gasProvider) { + this(IL2Bridge.load(erc20L2Bridge, providerL2, manager, gasProvider), IL2Bridge.load(wethL2Bridge, providerL2, manager, gasProvider), IL2SharedBridge.load(sharedL2Bridge, providerL2, manager, gasProvider)); } } diff --git a/src/main/java/io/zksync/wrappers/IBridgehub.java b/src/main/java/io/zksync/wrappers/IBridgehub.java index a9ed70e..8780fae 100644 --- a/src/main/java/io/zksync/wrappers/IBridgehub.java +++ b/src/main/java/io/zksync/wrappers/IBridgehub.java @@ -58,7 +58,7 @@ public class IBridgehub extends Contract { public static final String FUNC_CREATENEWCHAIN = "createNewChain"; - public static final String FUNC_GETSTATETRANSITION = "getStateTransition"; + public static final String FUNC_GETHYPERCHAIN = "getHyperchain"; public static final String FUNC_L2TRANSACTIONBASECOST = "l2TransactionBaseCost"; @@ -258,8 +258,8 @@ public RemoteFunctionCall createNewChain(BigInteger _chainId return executeRemoteCallTransaction(function); } - public RemoteFunctionCall getStateTransition(BigInteger _chainId) { - final Function function = new Function(FUNC_GETSTATETRANSITION, + public RemoteFunctionCall getHyperchain(BigInteger _chainId) { + final Function function = new Function(FUNC_GETHYPERCHAIN, Arrays.asList(new Uint256(_chainId)), Arrays.>asList(new TypeReference
() {})); return executeRemoteCallSingleValueReturn(function, String.class); diff --git a/src/main/java/io/zksync/wrappers/IContractDeployer.java b/src/main/java/io/zksync/wrappers/IContractDeployer.java index 3c360b6..b0ad1b3 100644 --- a/src/main/java/io/zksync/wrappers/IContractDeployer.java +++ b/src/main/java/io/zksync/wrappers/IContractDeployer.java @@ -9,15 +9,11 @@ import org.web3j.abi.EventEncoder; import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.Address; -import org.web3j.abi.datatypes.Bool; -import org.web3j.abi.datatypes.DynamicBytes; -import org.web3j.abi.datatypes.DynamicStruct; import org.web3j.abi.datatypes.Event; import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.StaticStruct; import org.web3j.abi.datatypes.Type; import org.web3j.abi.datatypes.generated.Bytes32; -import org.web3j.abi.datatypes.generated.Uint256; import org.web3j.abi.datatypes.generated.Uint8; import org.web3j.crypto.Credentials; import org.web3j.protocol.Web3j; @@ -52,12 +48,6 @@ public class IContractDeployer extends Contract { public static final String FUNC_CREATEACCOUNT = "createAccount"; - public static final String FUNC_EXTENDEDACCOUNTVERSION = "extendedAccountVersion"; - - public static final String FUNC_FORCEDEPLOYONADDRESS = "forceDeployOnAddress"; - - public static final String FUNC_FORCEDEPLOYONADDRESSES = "forceDeployOnAddresses"; - public static final String FUNC_GETACCOUNTINFO = "getAccountInfo"; public static final String FUNC_GETNEWADDRESSCREATE = "getNewAddressCreate"; @@ -201,7 +191,7 @@ public RemoteFunctionCall create(byte[] _salt, byte[] _bytec FUNC_CREATE, Arrays.asList(new Bytes32(_salt), new Bytes32(_bytecodeHash), - new DynamicBytes(_input)), + new org.web3j.abi.datatypes.DynamicBytes(_input)), Collections.>emptyList()); return executeRemoteCallTransaction(function, weiValue); } @@ -211,7 +201,7 @@ public RemoteFunctionCall create2(byte[] _salt, byte[] _byte FUNC_CREATE2, Arrays.asList(new Bytes32(_salt), new Bytes32(_bytecodeHash), - new DynamicBytes(_input)), + new org.web3j.abi.datatypes.DynamicBytes(_input)), Collections.>emptyList()); return executeRemoteCallTransaction(function, weiValue); } @@ -221,47 +211,23 @@ public RemoteFunctionCall create2Account(byte[] _salt, byte[ FUNC_CREATE2ACCOUNT, Arrays.asList(new Bytes32(_salt), new Bytes32(_bytecodeHash), - new DynamicBytes(_input), + new org.web3j.abi.datatypes.DynamicBytes(_input), new Uint8(_aaVersion)), Collections.>emptyList()); return executeRemoteCallTransaction(function, weiValue); } - public RemoteFunctionCall createAccount(byte[] param0, byte[] _bytecodeHash, byte[] _input, BigInteger _aaVersion, BigInteger weiValue) { + public RemoteFunctionCall createAccount(byte[] _salt, byte[] _bytecodeHash, byte[] _input, BigInteger _aaVersion, BigInteger weiValue) { final Function function = new Function( FUNC_CREATEACCOUNT, - Arrays.asList(new Bytes32(param0), + Arrays.asList(new Bytes32(_salt), new Bytes32(_bytecodeHash), - new DynamicBytes(_input), + new org.web3j.abi.datatypes.DynamicBytes(_input), new Uint8(_aaVersion)), Collections.>emptyList()); return executeRemoteCallTransaction(function, weiValue); } - public RemoteFunctionCall extendedAccountVersion(String _address) { - final Function function = new Function(FUNC_EXTENDEDACCOUNTVERSION, - Arrays.asList(new Address(160, _address)), - Arrays.>asList(new TypeReference() {})); - return executeRemoteCallSingleValueReturn(function, BigInteger.class); - } - - public RemoteFunctionCall forceDeployOnAddress(ForceDeployment _deployment, String _sender, BigInteger weiValue) { - final Function function = new Function( - FUNC_FORCEDEPLOYONADDRESS, - Arrays.asList(_deployment, - new Address(160, _sender)), - Collections.>emptyList()); - return executeRemoteCallTransaction(function, weiValue); - } - - public RemoteFunctionCall forceDeployOnAddresses(List _deployments, BigInteger weiValue) { - final Function function = new Function( - FUNC_FORCEDEPLOYONADDRESSES, - Arrays.asList(new org.web3j.abi.datatypes.DynamicArray(ForceDeployment.class, _deployments)), - Collections.>emptyList()); - return executeRemoteCallTransaction(function, weiValue); - } - public RemoteFunctionCall getAccountInfo(String _address) { final Function function = new Function(FUNC_GETACCOUNTINFO, Arrays.asList(new Address(160, _address)), @@ -272,7 +238,7 @@ public RemoteFunctionCall getAccountInfo(String _address) { public RemoteFunctionCall getNewAddressCreate(String _sender, BigInteger _senderNonce) { final Function function = new Function(FUNC_GETNEWADDRESSCREATE, Arrays.asList(new Address(160, _sender), - new Uint256(_senderNonce)), + new org.web3j.abi.datatypes.generated.Uint256(_senderNonce)), Arrays.>asList(new TypeReference
() {})); return executeRemoteCallSingleValueReturn(function, String.class); } @@ -282,7 +248,7 @@ public RemoteFunctionCall getNewAddressCreate2(String _sender, byte[] _b Arrays.asList(new Address(160, _sender), new Bytes32(_bytecodeHash), new Bytes32(_salt), - new DynamicBytes(_input)), + new org.web3j.abi.datatypes.DynamicBytes(_input)), Arrays.>asList(new TypeReference
() {})); return executeRemoteCallSingleValueReturn(function, String.class); } @@ -321,40 +287,6 @@ public static IContractDeployer load(String contractAddress, Web3j web3j, Transa return new IContractDeployer(contractAddress, web3j, transactionManager, contractGasProvider); } - public static class ForceDeployment extends DynamicStruct { - public byte[] bytecodeHash; - - public String newAddress; - - public Boolean callConstructor; - - public BigInteger value; - - public byte[] input; - - public ForceDeployment(byte[] bytecodeHash, String newAddress, Boolean callConstructor, BigInteger value, byte[] input) { - super(new Bytes32(bytecodeHash), - new Address(160, newAddress), - new Bool(callConstructor), - new Uint256(value), - new DynamicBytes(input)); - this.bytecodeHash = bytecodeHash; - this.newAddress = newAddress; - this.callConstructor = callConstructor; - this.value = value; - this.input = input; - } - - public ForceDeployment(Bytes32 bytecodeHash, Address newAddress, Bool callConstructor, Uint256 value, DynamicBytes input) { - super(bytecodeHash, newAddress, callConstructor, value, input); - this.bytecodeHash = bytecodeHash.getValue(); - this.newAddress = newAddress.getValue(); - this.callConstructor = callConstructor.getValue(); - this.value = value.getValue(); - this.input = input.getValue(); - } - } - public static class AccountInfo extends StaticStruct { public BigInteger supportedAAVersion; diff --git a/src/main/java/io/zksync/wrappers/IEthToken.java b/src/main/java/io/zksync/wrappers/IEthToken.java index f09f23a..fba05a1 100644 --- a/src/main/java/io/zksync/wrappers/IEthToken.java +++ b/src/main/java/io/zksync/wrappers/IEthToken.java @@ -284,7 +284,7 @@ public RemoteFunctionCall transferFromTo(String _from, Strin return executeRemoteCallTransaction(function); } - public String encodeWithdraw(String _l1Receiver, BigInteger weiValue) { + public String encodeWithdraw(String _l1Receiver) { final Function function = new Function( FUNC_WITHDRAW, Arrays.asList(new Address(160, _l1Receiver)), diff --git a/src/main/java/io/zksync/wrappers/IL1Bridge.java b/src/main/java/io/zksync/wrappers/IL1Bridge.java index 141eeb6..89a9c26 100644 --- a/src/main/java/io/zksync/wrappers/IL1Bridge.java +++ b/src/main/java/io/zksync/wrappers/IL1Bridge.java @@ -1,18 +1,13 @@ package io.zksync.wrappers; import io.reactivex.Flowable; - -import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; - -import io.zksync.abi.ZkFunctionEncoder; import org.web3j.abi.EventEncoder; -import org.web3j.abi.FunctionEncoder; import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; @@ -32,10 +27,8 @@ import org.web3j.protocol.core.methods.response.BaseEventResponse; import org.web3j.protocol.core.methods.response.Log; import org.web3j.protocol.core.methods.response.TransactionReceipt; -import org.web3j.protocol.exceptions.TransactionException; import org.web3j.tx.Contract; import org.web3j.tx.TransactionManager; -import org.web3j.tx.gas.ContractEIP1559GasProvider; import org.web3j.tx.gas.ContractGasProvider; /** @@ -351,19 +344,6 @@ public RemoteFunctionCall claimFailedDeposit(BigInteger _cha return executeRemoteCallTransaction(function); } - public String encodeDeposit(String _l2Receiver, String _l1Token, BigInteger _amount, BigInteger _l2TxGasLimit, BigInteger _l2TxGasPerPubdataByte, String _refundRecipient, BigInteger weiValue) { - final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function( - FUNC_DEPOSIT, - Arrays.asList(new Address(160, _l2Receiver), - new Address(160, _l1Token), - new Uint256(_amount), - new Uint256(_l2TxGasLimit), - new Uint256(_l2TxGasPerPubdataByte), - new Address(160, _refundRecipient)), - Collections.>emptyList()); - return FunctionEncoder.encode(function); - } - public RemoteFunctionCall deposit(BigInteger _chainId, String _l2Receiver, String _l1Token, BigInteger _mintValue, BigInteger _amount, BigInteger _l2TxGasLimit, BigInteger _l2TxGasPerPubdataByte, String _refundRecipient, BigInteger weiValue) { final Function function = new Function( FUNC_DEPOSIT, @@ -387,20 +367,19 @@ public RemoteFunctionCall depositHappened(BigInteger _chainId, byte[] _l return executeRemoteCallSingleValueReturn(function, byte[].class); } - public RemoteFunctionCall finalizeWithdrawal(BigInteger _chainId, BigInteger _l2BatchNumber, BigInteger _l2MessageIndex, BigInteger _l2TxNumberInBatch, byte[] _message, List _merkleProof) throws TransactionException, IOException { + public RemoteFunctionCall finalizeWithdrawal(BigInteger _chainId, BigInteger _l2BatchNumber, BigInteger _l2MessageIndex, BigInteger _l2TxNumberInBatch, byte[] _message, List _merkleProof) { final Function function = new Function( - FUNC_FINALIZEWITHDRAWAL, + FUNC_FINALIZEWITHDRAWAL, Arrays.asList(new Uint256(_chainId), - new Uint256(_l2BatchNumber), - new Uint256(_l2MessageIndex), - new org.web3j.abi.datatypes.generated.Uint16(_l2TxNumberInBatch), - new DynamicBytes(_message), - new DynamicArray( - Bytes32.class, - org.web3j.abi.Utils.typeMap(_merkleProof, Bytes32.class))), + new Uint256(_l2BatchNumber), + new Uint256(_l2MessageIndex), + new org.web3j.abi.datatypes.generated.Uint16(_l2TxNumberInBatch), + new DynamicBytes(_message), + new DynamicArray( + Bytes32.class, + org.web3j.abi.Utils.typeMap(_merkleProof, Bytes32.class))), Collections.>emptyList()); - - return new RemoteFunctionCall(function, () -> this.send(this.contractAddress, ZkFunctionEncoder.encode(function), BigInteger.ZERO, this.gasProvider.getGasPrice(FUNC_FINALIZEWITHDRAWAL), this.gasProvider.getGasLimit(FUNC_FINALIZEWITHDRAWAL), false)); + return executeRemoteCallTransaction(function); } public RemoteFunctionCall isWithdrawalFinalizedShared(BigInteger _chainId, BigInteger _l2BatchNumber, BigInteger _l2MessageIndex) { diff --git a/src/main/java/io/zksync/wrappers/IL1SharedBridge.java b/src/main/java/io/zksync/wrappers/IL1SharedBridge.java index d8e835d..25e6ccd 100644 --- a/src/main/java/io/zksync/wrappers/IL1SharedBridge.java +++ b/src/main/java/io/zksync/wrappers/IL1SharedBridge.java @@ -7,7 +7,10 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; + +import io.zksync.abi.ZkFunctionEncoder; import org.web3j.abi.EventEncoder; +import org.web3j.abi.FunctionEncoder; import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; @@ -44,7 +47,9 @@ public class IL1SharedBridge extends Contract { public static final String BINARY = "Bin file was not provided"; - public static final String FUNC_BRIDGEHUB = "bridgehub"; + public static final String FUNC_BRIDGE_HUB = "BRIDGE_HUB"; + + public static final String FUNC_L1_WETH_TOKEN = "L1_WETH_TOKEN"; public static final String FUNC_BRIDGEHUBCONFIRML2TRANSACTION = "bridgehubConfirmL2Transaction"; @@ -66,15 +71,17 @@ public class IL1SharedBridge extends Contract { public static final String FUNC_ISWITHDRAWALFINALIZED = "isWithdrawalFinalized"; - public static final String FUNC_L1WETHADDRESS = "l1WethAddress"; - public static final String FUNC_L2BRIDGEADDRESS = "l2BridgeAddress"; public static final String FUNC_LEGACYBRIDGE = "legacyBridge"; public static final String FUNC_RECEIVEETH = "receiveEth"; - public static final String FUNC_SETERAFIRSTPOSTUPGRADEBATCH = "setEraFirstPostUpgradeBatch"; + public static final String FUNC_SETERALEGACYBRIDGELASTDEPOSITTIME = "setEraLegacyBridgeLastDepositTime"; + + public static final String FUNC_SETERAPOSTDIAMONDUPGRADEFIRSTBATCH = "setEraPostDiamondUpgradeFirstBatch"; + + public static final String FUNC_SETERAPOSTLEGACYBRIDGEUPGRADEFIRSTBATCH = "setEraPostLegacyBridgeUpgradeFirstBatch"; public static final Event BRIDGEHUBDEPOSITBASETOKENINITIATED_EVENT = new Event("BridgehubDepositBaseTokenInitiated", Arrays.>asList(new TypeReference(true) {}, new TypeReference
(true) {}, new TypeReference
() {}, new TypeReference() {})); @@ -340,8 +347,15 @@ public Flowable withdrawalFinalize return withdrawalFinalizedSharedBridgeEventFlowable(filter); } - public RemoteFunctionCall bridgehub() { - final Function function = new Function(FUNC_BRIDGEHUB, + public RemoteFunctionCall BRIDGE_HUB() { + final Function function = new Function(FUNC_BRIDGE_HUB, + Arrays.asList(), + Arrays.>asList(new TypeReference
() {})); + return executeRemoteCallSingleValueReturn(function, String.class); + } + + public RemoteFunctionCall L1_WETH_TOKEN() { + final Function function = new Function(FUNC_L1_WETH_TOKEN, Arrays.asList(), Arrays.>asList(new TypeReference
() {})); return executeRemoteCallSingleValueReturn(function, String.class); @@ -436,6 +450,21 @@ public RemoteFunctionCall depositLegacyErc20Bridge(String _m return executeRemoteCallTransaction(function, weiValue); } + public static String encodeFinalizeWithdrawal(BigInteger _chainId, BigInteger _l2BatchNumber, BigInteger _l2MessageIndex, BigInteger _l2TxNumberInBatch, byte[] _message, List _merkleProof) { + final Function function = new Function( + FUNC_FINALIZEWITHDRAWAL, + Arrays.asList(new Uint256(_chainId), + new Uint256(_l2BatchNumber), + new Uint256(_l2MessageIndex), + new org.web3j.abi.datatypes.generated.Uint16(_l2TxNumberInBatch), + new DynamicBytes(_message), + new DynamicArray( + Bytes32.class, + org.web3j.abi.Utils.typeMap(_merkleProof, Bytes32.class))), + Collections.>emptyList()); + return ZkFunctionEncoder.encode(function); + } + public RemoteFunctionCall finalizeWithdrawal(BigInteger _chainId, BigInteger _l2BatchNumber, BigInteger _l2MessageIndex, BigInteger _l2TxNumberInBatch, byte[] _message, List _merkleProof) { final Function function = new Function( FUNC_FINALIZEWITHDRAWAL, @@ -474,13 +503,6 @@ public RemoteFunctionCall isWithdrawalFinalized(BigInteger _chainId, Bi return executeRemoteCallSingleValueReturn(function, Boolean.class); } - public RemoteFunctionCall l1WethAddress() { - final Function function = new Function(FUNC_L1WETHADDRESS, - Arrays.asList(), - Arrays.>asList(new TypeReference
() {})); - return executeRemoteCallSingleValueReturn(function, String.class); - } - public RemoteFunctionCall l2BridgeAddress(BigInteger _chainId) { final Function function = new Function(FUNC_L2BRIDGEADDRESS, Arrays.asList(new Uint256(_chainId)), @@ -503,10 +525,27 @@ public RemoteFunctionCall receiveEth(BigInteger _chainId, Bi return executeRemoteCallTransaction(function, weiValue); } - public RemoteFunctionCall setEraFirstPostUpgradeBatch(BigInteger _eraFirstPostUpgradeBatch) { + public RemoteFunctionCall setEraLegacyBridgeLastDepositTime(BigInteger _eraLegacyBridgeLastDepositBatch, BigInteger _eraLegacyBridgeLastDepositTxNumber) { + final Function function = new Function( + FUNC_SETERALEGACYBRIDGELASTDEPOSITTIME, + Arrays.asList(new Uint256(_eraLegacyBridgeLastDepositBatch), + new Uint256(_eraLegacyBridgeLastDepositTxNumber)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteFunctionCall setEraPostDiamondUpgradeFirstBatch(BigInteger _eraPostDiamondUpgradeFirstBatch) { + final Function function = new Function( + FUNC_SETERAPOSTDIAMONDUPGRADEFIRSTBATCH, + Arrays.asList(new Uint256(_eraPostDiamondUpgradeFirstBatch)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteFunctionCall setEraPostLegacyBridgeUpgradeFirstBatch(BigInteger _eraPostLegacyBridgeUpgradeFirstBatch) { final Function function = new Function( - FUNC_SETERAFIRSTPOSTUPGRADEBATCH, - Arrays.asList(new Uint256(_eraFirstPostUpgradeBatch)), + FUNC_SETERAPOSTLEGACYBRIDGEUPGRADEFIRSTBATCH, + Arrays.asList(new Uint256(_eraPostLegacyBridgeUpgradeFirstBatch)), Collections.>emptyList()); return executeRemoteCallTransaction(function); } diff --git a/src/main/java/io/zksync/wrappers/IL2Bridge.java b/src/main/java/io/zksync/wrappers/IL2Bridge.java index 8055cd4..4b0e8a6 100644 --- a/src/main/java/io/zksync/wrappers/IL2Bridge.java +++ b/src/main/java/io/zksync/wrappers/IL2Bridge.java @@ -56,7 +56,7 @@ protected IL2Bridge(String contractAddress, Web3j web3j, TransactionManager tran super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); } - public RemoteFunctionCall finalizeDeposit(String _l1Sender, String _l2Receiver, String _l1Token, BigInteger _amount, byte[] _data, BigInteger weiValue) { + public RemoteFunctionCall finalizeDeposit(String _l1Sender, String _l2Receiver, String _l1Token, BigInteger _amount, byte[] _data) { final Function function = new Function( FUNC_FINALIZEDEPOSIT, Arrays.asList(new Address(160, _l1Sender), @@ -65,7 +65,7 @@ public RemoteFunctionCall finalizeDeposit(String _l1Sender, new org.web3j.abi.datatypes.generated.Uint256(_amount), new org.web3j.abi.datatypes.DynamicBytes(_data)), Collections.>emptyList()); - return executeRemoteCallTransaction(function, weiValue); + return executeRemoteCallTransaction(function); } public RemoteFunctionCall l1Bridge() { diff --git a/src/main/java/io/zksync/wrappers/IL2SharedBridge.java b/src/main/java/io/zksync/wrappers/IL2SharedBridge.java new file mode 100644 index 0000000..b301773 --- /dev/null +++ b/src/main/java/io/zksync/wrappers/IL2SharedBridge.java @@ -0,0 +1,238 @@ +package io.zksync.wrappers; + +import io.reactivex.Flowable; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.web3j.abi.EventEncoder; +import org.web3j.abi.TypeReference; +import org.web3j.abi.datatypes.Address; +import org.web3j.abi.datatypes.Event; +import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.Type; +import org.web3j.abi.datatypes.generated.Uint256; +import org.web3j.crypto.Credentials; +import org.web3j.protocol.Web3j; +import org.web3j.protocol.core.DefaultBlockParameter; +import org.web3j.protocol.core.RemoteFunctionCall; +import org.web3j.protocol.core.methods.request.EthFilter; +import org.web3j.protocol.core.methods.response.BaseEventResponse; +import org.web3j.protocol.core.methods.response.Log; +import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.tx.Contract; +import org.web3j.tx.TransactionManager; +import org.web3j.tx.gas.ContractGasProvider; + +/** + *

Auto generated code. + *

Do not modify! + *

Please use the web3j command line tools, + * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the + * codegen module to update. + * + *

Generated with web3j version 1.5.0. + */ +@SuppressWarnings("rawtypes") +public class IL2SharedBridge extends Contract { + public static final String BINARY = "Bin file was not provided"; + + public static final String FUNC_FINALIZEDEPOSIT = "finalizeDeposit"; + + public static final String FUNC_L1BRIDGE = "l1Bridge"; + + public static final String FUNC_L1SHAREDBRIDGE = "l1SharedBridge"; + + public static final String FUNC_L1TOKENADDRESS = "l1TokenAddress"; + + public static final String FUNC_L2TOKENADDRESS = "l2TokenAddress"; + + public static final String FUNC_WITHDRAW = "withdraw"; + + public static final Event FINALIZEDEPOSIT_EVENT = new Event("FinalizeDeposit", + Arrays.>asList(new TypeReference

(true) {}, new TypeReference
(true) {}, new TypeReference
(true) {}, new TypeReference() {})); + ; + + public static final Event WITHDRAWALINITIATED_EVENT = new Event("WithdrawalInitiated", + Arrays.>asList(new TypeReference
(true) {}, new TypeReference
(true) {}, new TypeReference
(true) {}, new TypeReference() {})); + ; + + @Deprecated + protected IL2SharedBridge(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + protected IL2SharedBridge(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, credentials, contractGasProvider); + } + + @Deprecated + protected IL2SharedBridge(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + protected IL2SharedBridge(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); + } + + public static List getFinalizeDepositEvents(TransactionReceipt transactionReceipt) { + List valueList = staticExtractEventParametersWithLog(FINALIZEDEPOSIT_EVENT, transactionReceipt); + ArrayList responses = new ArrayList(valueList.size()); + for (EventValuesWithLog eventValues : valueList) { + FinalizeDepositEventResponse typedResponse = new FinalizeDepositEventResponse(); + typedResponse.log = eventValues.getLog(); + typedResponse.l1Sender = (String) eventValues.getIndexedValues().get(0).getValue(); + typedResponse.l2Receiver = (String) eventValues.getIndexedValues().get(1).getValue(); + typedResponse.l2Token = (String) eventValues.getIndexedValues().get(2).getValue(); + typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); + responses.add(typedResponse); + } + return responses; + } + + public static FinalizeDepositEventResponse getFinalizeDepositEventFromLog(Log log) { + EventValuesWithLog eventValues = staticExtractEventParametersWithLog(FINALIZEDEPOSIT_EVENT, log); + FinalizeDepositEventResponse typedResponse = new FinalizeDepositEventResponse(); + typedResponse.log = log; + typedResponse.l1Sender = (String) eventValues.getIndexedValues().get(0).getValue(); + typedResponse.l2Receiver = (String) eventValues.getIndexedValues().get(1).getValue(); + typedResponse.l2Token = (String) eventValues.getIndexedValues().get(2).getValue(); + typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); + return typedResponse; + } + + public Flowable finalizeDepositEventFlowable(EthFilter filter) { + return web3j.ethLogFlowable(filter).map(log -> getFinalizeDepositEventFromLog(log)); + } + + public Flowable finalizeDepositEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { + EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); + filter.addSingleTopic(EventEncoder.encode(FINALIZEDEPOSIT_EVENT)); + return finalizeDepositEventFlowable(filter); + } + + public static List getWithdrawalInitiatedEvents(TransactionReceipt transactionReceipt) { + List valueList = staticExtractEventParametersWithLog(WITHDRAWALINITIATED_EVENT, transactionReceipt); + ArrayList responses = new ArrayList(valueList.size()); + for (EventValuesWithLog eventValues : valueList) { + WithdrawalInitiatedEventResponse typedResponse = new WithdrawalInitiatedEventResponse(); + typedResponse.log = eventValues.getLog(); + typedResponse.l2Sender = (String) eventValues.getIndexedValues().get(0).getValue(); + typedResponse.l1Receiver = (String) eventValues.getIndexedValues().get(1).getValue(); + typedResponse.l2Token = (String) eventValues.getIndexedValues().get(2).getValue(); + typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); + responses.add(typedResponse); + } + return responses; + } + + public static WithdrawalInitiatedEventResponse getWithdrawalInitiatedEventFromLog(Log log) { + EventValuesWithLog eventValues = staticExtractEventParametersWithLog(WITHDRAWALINITIATED_EVENT, log); + WithdrawalInitiatedEventResponse typedResponse = new WithdrawalInitiatedEventResponse(); + typedResponse.log = log; + typedResponse.l2Sender = (String) eventValues.getIndexedValues().get(0).getValue(); + typedResponse.l1Receiver = (String) eventValues.getIndexedValues().get(1).getValue(); + typedResponse.l2Token = (String) eventValues.getIndexedValues().get(2).getValue(); + typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); + return typedResponse; + } + + public Flowable withdrawalInitiatedEventFlowable(EthFilter filter) { + return web3j.ethLogFlowable(filter).map(log -> getWithdrawalInitiatedEventFromLog(log)); + } + + public Flowable withdrawalInitiatedEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { + EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); + filter.addSingleTopic(EventEncoder.encode(WITHDRAWALINITIATED_EVENT)); + return withdrawalInitiatedEventFlowable(filter); + } + + public RemoteFunctionCall finalizeDeposit(String _l1Sender, String _l2Receiver, String _l1Token, BigInteger _amount, byte[] _data) { + final Function function = new Function( + FUNC_FINALIZEDEPOSIT, + Arrays.asList(new Address(160, _l1Sender), + new Address(160, _l2Receiver), + new Address(160, _l1Token), + new Uint256(_amount), + new org.web3j.abi.datatypes.DynamicBytes(_data)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + public RemoteFunctionCall l1Bridge() { + final Function function = new Function(FUNC_L1BRIDGE, + Arrays.asList(), + Arrays.>asList(new TypeReference
() {})); + return executeRemoteCallSingleValueReturn(function, String.class); + } + + public RemoteFunctionCall l1SharedBridge() { + final Function function = new Function(FUNC_L1SHAREDBRIDGE, + Arrays.asList(), + Arrays.>asList(new TypeReference
() {})); + return executeRemoteCallSingleValueReturn(function, String.class); + } + + public RemoteFunctionCall l1TokenAddress(String _l2Token) { + final Function function = new Function(FUNC_L1TOKENADDRESS, + Arrays.asList(new Address(160, _l2Token)), + Arrays.>asList(new TypeReference
() {})); + return executeRemoteCallSingleValueReturn(function, String.class); + } + + public RemoteFunctionCall l2TokenAddress(String _l1Token) { + final Function function = new Function(FUNC_L2TOKENADDRESS, + Arrays.asList(new Address(160, _l1Token)), + Arrays.>asList(new TypeReference
() {})); + return executeRemoteCallSingleValueReturn(function, String.class); + } + + public RemoteFunctionCall withdraw(String _l1Receiver, String _l2Token, BigInteger _amount) { + final Function function = new Function( + FUNC_WITHDRAW, + Arrays.asList(new Address(160, _l1Receiver), + new Address(160, _l2Token), + new Uint256(_amount)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + + @Deprecated + public static IL2SharedBridge load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return new IL2SharedBridge(contractAddress, web3j, credentials, gasPrice, gasLimit); + } + + @Deprecated + public static IL2SharedBridge load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return new IL2SharedBridge(contractAddress, web3j, transactionManager, gasPrice, gasLimit); + } + + public static IL2SharedBridge load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + return new IL2SharedBridge(contractAddress, web3j, credentials, contractGasProvider); + } + + public static IL2SharedBridge load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return new IL2SharedBridge(contractAddress, web3j, transactionManager, contractGasProvider); + } + + public static class FinalizeDepositEventResponse extends BaseEventResponse { + public String l1Sender; + + public String l2Receiver; + + public String l2Token; + + public BigInteger amount; + } + + public static class WithdrawalInitiatedEventResponse extends BaseEventResponse { + public String l2Sender; + + public String l1Receiver; + + public String l2Token; + + public BigInteger amount; + } +} diff --git a/src/main/java/io/zksync/wrappers/IZkSyncStateTransition.java b/src/main/java/io/zksync/wrappers/IZkSyncHyperchain.java similarity index 95% rename from src/main/java/io/zksync/wrappers/IZkSyncStateTransition.java rename to src/main/java/io/zksync/wrappers/IZkSyncHyperchain.java index 2ea270c..3bfa07e 100644 --- a/src/main/java/io/zksync/wrappers/IZkSyncStateTransition.java +++ b/src/main/java/io/zksync/wrappers/IZkSyncHyperchain.java @@ -40,6 +40,7 @@ import org.web3j.protocol.core.methods.response.BaseEventResponse; import org.web3j.protocol.core.methods.response.Log; import org.web3j.protocol.core.methods.response.TransactionReceipt; +import org.web3j.tuples.generated.Tuple3; import org.web3j.tx.Contract; import org.web3j.tx.TransactionManager; import org.web3j.tx.gas.ContractGasProvider; @@ -54,7 +55,7 @@ *

Generated with web3j version 1.5.0. */ @SuppressWarnings("rawtypes") -public class IZkSyncStateTransition extends Contract { +public class IZkSyncHyperchain extends Contract { public static final String BINARY = "Bin file was not provided"; public static final String FUNC_ACCEPTADMIN = "acceptAdmin"; @@ -119,6 +120,8 @@ public class IZkSyncStateTransition extends Contract { public static final String FUNC_GETPUBDATAPRICINGMODE = "getPubdataPricingMode"; + public static final String FUNC_GETSEMVERPROTOCOLVERSION = "getSemverProtocolVersion"; + public static final String FUNC_GETSTATETRANSITIONMANAGER = "getStateTransitionManager"; public static final String FUNC_GETTOTALBATCHESCOMMITTED = "getTotalBatchesCommitted"; @@ -171,14 +174,14 @@ public class IZkSyncStateTransition extends Contract { public static final String FUNC_SETPRIORITYTXMAXGASLIMIT = "setPriorityTxMaxGasLimit"; + public static final String FUNC_SETPUBDATAPRICINGMODE = "setPubdataPricingMode"; + public static final String FUNC_SETTOKENMULTIPLIER = "setTokenMultiplier"; public static final String FUNC_SETTRANSACTIONFILTERER = "setTransactionFilterer"; public static final String FUNC_SETVALIDATOR = "setValidator"; - public static final String FUNC_SETVALIDIUMMODE = "setValidiumMode"; - public static final String FUNC_STOREDBATCHHASH = "storedBatchHash"; public static final String FUNC_TRANSFERETHTOSHAREDBRIDGE = "transferEthToSharedBridge"; @@ -203,10 +206,6 @@ public class IZkSyncStateTransition extends Contract { Arrays.>asList(new TypeReference(true) {}, new TypeReference(true) {})); ; - public static final Event ETHWITHDRAWALFINALIZED_EVENT = new Event("EthWithdrawalFinalized", - Arrays.>asList(new TypeReference

(true) {}, new TypeReference() {})); - ; - public static final Event EXECUTEUPGRADE_EVENT = new Event("ExecuteUpgrade", Arrays.>asList(new TypeReference() {})); ; @@ -264,20 +263,20 @@ public class IZkSyncStateTransition extends Contract { ; @Deprecated - protected IZkSyncStateTransition(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + protected IZkSyncHyperchain(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); } - protected IZkSyncStateTransition(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + protected IZkSyncHyperchain(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { super(BINARY, contractAddress, web3j, credentials, contractGasProvider); } @Deprecated - protected IZkSyncStateTransition(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + protected IZkSyncHyperchain(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); } - protected IZkSyncStateTransition(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + protected IZkSyncHyperchain(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider); } @@ -415,38 +414,6 @@ public Flowable blocksVerificationEventFlowable return blocksVerificationEventFlowable(filter); } - public static List getEthWithdrawalFinalizedEvents(TransactionReceipt transactionReceipt) { - List valueList = staticExtractEventParametersWithLog(ETHWITHDRAWALFINALIZED_EVENT, transactionReceipt); - ArrayList responses = new ArrayList(valueList.size()); - for (EventValuesWithLog eventValues : valueList) { - EthWithdrawalFinalizedEventResponse typedResponse = new EthWithdrawalFinalizedEventResponse(); - typedResponse.log = eventValues.getLog(); - typedResponse.to = (String) eventValues.getIndexedValues().get(0).getValue(); - typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); - responses.add(typedResponse); - } - return responses; - } - - public static EthWithdrawalFinalizedEventResponse getEthWithdrawalFinalizedEventFromLog(Log log) { - EventValuesWithLog eventValues = staticExtractEventParametersWithLog(ETHWITHDRAWALFINALIZED_EVENT, log); - EthWithdrawalFinalizedEventResponse typedResponse = new EthWithdrawalFinalizedEventResponse(); - typedResponse.log = log; - typedResponse.to = (String) eventValues.getIndexedValues().get(0).getValue(); - typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); - return typedResponse; - } - - public Flowable ethWithdrawalFinalizedEventFlowable(EthFilter filter) { - return web3j.ethLogFlowable(filter).map(log -> getEthWithdrawalFinalizedEventFromLog(log)); - } - - public Flowable ethWithdrawalFinalizedEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { - EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); - filter.addSingleTopic(EventEncoder.encode(ETHWITHDRAWALFINALIZED_EVENT)); - return ethWithdrawalFinalizedEventFlowable(filter); - } - public static List getExecuteUpgradeEvents(TransactionReceipt transactionReceipt) { List valueList = staticExtractEventParametersWithLog(EXECUTEUPGRADE_EVENT, transactionReceipt); ArrayList responses = new ArrayList(valueList.size()); @@ -915,12 +882,12 @@ public RemoteFunctionCall baseTokenGasPriceMultiplierNominator() { return executeRemoteCallSingleValueReturn(function, BigInteger.class); } - public RemoteFunctionCall bridgehubRequestL2Transaction(BridgehubL2TransactionRequest _request, BigInteger weiValue) { + public RemoteFunctionCall bridgehubRequestL2Transaction(BridgehubL2TransactionRequest _request) { final Function function = new Function( FUNC_BRIDGEHUBREQUESTL2TRANSACTION, Arrays.asList(_request), Collections.>emptyList()); - return executeRemoteCallTransaction(function, weiValue); + return executeRemoteCallTransaction(function); } public RemoteFunctionCall changeFeeParams(FeeParams _newFeeParams) { @@ -1154,6 +1121,23 @@ public RemoteFunctionCall getPubdataPricingMode() { return executeRemoteCallSingleValueReturn(function, BigInteger.class); } + public RemoteFunctionCall> getSemverProtocolVersion() { + final Function function = new Function(FUNC_GETSEMVERPROTOCOLVERSION, + Arrays.asList(), + Arrays.>asList(new TypeReference() {}, new TypeReference() {}, new TypeReference() {})); + return new RemoteFunctionCall>(function, + new Callable>() { + @Override + public Tuple3 call() throws Exception { + List results = executeCallMultipleValueReturn(function); + return new Tuple3( + (BigInteger) results.get(0).getValue(), + (BigInteger) results.get(1).getValue(), + (BigInteger) results.get(2).getValue()); + } + }); + } + public RemoteFunctionCall getStateTransitionManager() { final Function function = new Function(FUNC_GETSTATETRANSITIONMANAGER, Arrays.asList(), @@ -1378,6 +1362,14 @@ public RemoteFunctionCall setPriorityTxMaxGasLimit(BigIntege return executeRemoteCallTransaction(function); } + public RemoteFunctionCall setPubdataPricingMode(BigInteger _pricingMode) { + final Function function = new Function( + FUNC_SETPUBDATAPRICINGMODE, + Arrays.asList(new Uint8(_pricingMode)), + Collections.>emptyList()); + return executeRemoteCallTransaction(function); + } + public RemoteFunctionCall setTokenMultiplier(BigInteger _nominator, BigInteger _denominator) { final Function function = new Function( FUNC_SETTOKENMULTIPLIER, @@ -1404,14 +1396,6 @@ public RemoteFunctionCall setValidator(String _validator, Bo return executeRemoteCallTransaction(function); } - public RemoteFunctionCall setValidiumMode(BigInteger _validiumMode) { - final Function function = new Function( - FUNC_SETVALIDIUMMODE, - Arrays.asList(new Uint8(_validiumMode)), - Collections.>emptyList()); - return executeRemoteCallTransaction(function); - } - public RemoteFunctionCall storedBatchHash(BigInteger _batchNumber) { final Function function = new Function(FUNC_STOREDBATCHHASH, Arrays.asList(new Uint256(_batchNumber)), @@ -1445,21 +1429,21 @@ public RemoteFunctionCall upgradeChainFromVersion(BigInteger } @Deprecated - public static IZkSyncStateTransition load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { - return new IZkSyncStateTransition(contractAddress, web3j, credentials, gasPrice, gasLimit); + public static IZkSyncHyperchain load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { + return new IZkSyncHyperchain(contractAddress, web3j, credentials, gasPrice, gasLimit); } @Deprecated - public static IZkSyncStateTransition load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { - return new IZkSyncStateTransition(contractAddress, web3j, transactionManager, gasPrice, gasLimit); + public static IZkSyncHyperchain load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { + return new IZkSyncHyperchain(contractAddress, web3j, transactionManager, gasPrice, gasLimit); } - public static IZkSyncStateTransition load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { - return new IZkSyncStateTransition(contractAddress, web3j, credentials, contractGasProvider); + public static IZkSyncHyperchain load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { + return new IZkSyncHyperchain(contractAddress, web3j, credentials, contractGasProvider); } - public static IZkSyncStateTransition load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { - return new IZkSyncStateTransition(contractAddress, web3j, transactionManager, contractGasProvider); + public static IZkSyncHyperchain load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { + return new IZkSyncHyperchain(contractAddress, web3j, transactionManager, contractGasProvider); } public static class FacetCut extends DynamicStruct { @@ -1998,12 +1982,6 @@ public static class BlocksVerificationEventResponse extends BaseEventResponse { public BigInteger currentLastVerifiedBatch; } - public static class EthWithdrawalFinalizedEventResponse extends BaseEventResponse { - public String to; - - public BigInteger amount; - } - public static class ExecuteUpgradeEventResponse extends BaseEventResponse { public DiamondCutData diamondCut; } diff --git a/src/test/java/io/zksync/integration/account/WalletTest.java b/src/test/java/io/zksync/integration/account/WalletTest.java index 895f326..2a29679 100644 --- a/src/test/java/io/zksync/integration/account/WalletTest.java +++ b/src/test/java/io/zksync/integration/account/WalletTest.java @@ -434,8 +434,9 @@ public void testWithdrawEth() throws Exception { TransactionReceipt result = testWallet.withdraw(transaction).sendAsync().join(); TransactionReceipt receipt = testWallet.getTransactionReceiptProcessor().waitFinalized(result.getTransactionHash()); - TransactionReceipt finalizeWithdraw = testWallet.finalizeWithdraw(receipt.getTransactionHash(), 0).sendAsync().join(); - + assertFalse(testWallet.isWithdrawalFinalized(receipt.getTransactionHash(), 0).join()); + EthSendTransaction finalizeWithdraw = testWallet.finalizeWithdraw(receipt.getTransactionHash(), 0).join(); + assertNotNull(finalizeWithdraw.getResult()); BigInteger senderAfter = testWallet.getBalance().sendAsync().join(); assertNotNull(receipt); @@ -476,7 +477,8 @@ public void testWithdrawErc20() throws Exception { TransactionReceipt result = testWallet.withdraw(transaction).sendAsync().join(); TransactionReceipt receipt = testWallet.getTransactionReceiptProcessor().waitFinalized(result.getTransactionHash()); - TransactionReceipt finalizeWithdraw = testWallet.finalizeWithdraw(receipt.getTransactionHash(), 0).sendAsync().join(); + EthSendTransaction finalizeWithdraw = testWallet.finalizeWithdraw(receipt.getTransactionHash(), 0).join(); + assertNotNull(finalizeWithdraw.getResult()); BigInteger senderAfter = testWallet.getBalance(l2DAI).sendAsync().join(); assertNotNull(receipt);