@mantleio/viem 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +54 -0
- package/dist/cjs/abis.js +3338 -0
- package/dist/cjs/abis.js.map +1 -0
- package/dist/cjs/actions/buildProveWithdrawal.js +55 -0
- package/dist/cjs/actions/buildProveWithdrawal.js.map +1 -0
- package/dist/cjs/actions/depositERC20.js +37 -0
- package/dist/cjs/actions/depositERC20.js.map +1 -0
- package/dist/cjs/actions/depositETH.js +36 -0
- package/dist/cjs/actions/depositETH.js.map +1 -0
- package/dist/cjs/actions/depositMNT.js +35 -0
- package/dist/cjs/actions/depositMNT.js.map +1 -0
- package/dist/cjs/actions/estimateDepositERC20Gas.js +38 -0
- package/dist/cjs/actions/estimateDepositERC20Gas.js.map +1 -0
- package/dist/cjs/actions/estimateDepositETHGas.js +37 -0
- package/dist/cjs/actions/estimateDepositETHGas.js.map +1 -0
- package/dist/cjs/actions/estimateDepositMNTGas.js +36 -0
- package/dist/cjs/actions/estimateDepositMNTGas.js.map +1 -0
- package/dist/cjs/actions/estimateFinalizeWithdrawalGas.js +29 -0
- package/dist/cjs/actions/estimateFinalizeWithdrawalGas.js.map +1 -0
- package/dist/cjs/actions/estimateInitiateERC20WithdrawalGas.js +30 -0
- package/dist/cjs/actions/estimateInitiateERC20WithdrawalGas.js.map +1 -0
- package/dist/cjs/actions/estimateInitiateETHWithdrawalGas.js +29 -0
- package/dist/cjs/actions/estimateInitiateETHWithdrawalGas.js.map +1 -0
- package/dist/cjs/actions/estimateInitiateMNTWithdrawalGas.js +30 -0
- package/dist/cjs/actions/estimateInitiateMNTWithdrawalGas.js.map +1 -0
- package/dist/cjs/actions/estimateProveWithdrawalGas.js +29 -0
- package/dist/cjs/actions/estimateProveWithdrawalGas.js.map +1 -0
- package/dist/cjs/actions/finalizeWithdrawal.js +28 -0
- package/dist/cjs/actions/finalizeWithdrawal.js.map +1 -0
- package/dist/cjs/actions/getL2Output.js +31 -0
- package/dist/cjs/actions/getL2Output.js.map +1 -0
- package/dist/cjs/actions/getPortalVersion.js +24 -0
- package/dist/cjs/actions/getPortalVersion.js.map +1 -0
- package/dist/cjs/actions/getTimeToFinalize.js +46 -0
- package/dist/cjs/actions/getTimeToFinalize.js.map +1 -0
- package/dist/cjs/actions/getTimeToNextL2Output.js +62 -0
- package/dist/cjs/actions/getTimeToNextL2Output.js.map +1 -0
- package/dist/cjs/actions/getTimeToProve.js +12 -0
- package/dist/cjs/actions/getTimeToProve.js.map +1 -0
- package/dist/cjs/actions/getWithdrawalStatus.js +133 -0
- package/dist/cjs/actions/getWithdrawalStatus.js.map +1 -0
- package/dist/cjs/actions/initiateERC20Withdrawal.js +29 -0
- package/dist/cjs/actions/initiateERC20Withdrawal.js.map +1 -0
- package/dist/cjs/actions/initiateETHWithdrawal.js +28 -0
- package/dist/cjs/actions/initiateETHWithdrawal.js.map +1 -0
- package/dist/cjs/actions/initiateMNTWithdrawal.js +29 -0
- package/dist/cjs/actions/initiateMNTWithdrawal.js.map +1 -0
- package/dist/cjs/actions/proveWithdrawal.js +28 -0
- package/dist/cjs/actions/proveWithdrawal.js.map +1 -0
- package/dist/cjs/actions/waitForNextL2Output.js +31 -0
- package/dist/cjs/actions/waitForNextL2Output.js.map +1 -0
- package/dist/cjs/actions/waitToFinalize.js +10 -0
- package/dist/cjs/actions/waitToFinalize.js.map +1 -0
- package/dist/cjs/actions/waitToProve.js +24 -0
- package/dist/cjs/actions/waitToProve.js.map +1 -0
- package/dist/cjs/chainConfig.js +12 -0
- package/dist/cjs/chainConfig.js.map +1 -0
- package/dist/cjs/chains/index.js +8 -0
- package/dist/cjs/chains/index.js.map +1 -0
- package/dist/cjs/chains/mantle.js +53 -0
- package/dist/cjs/chains/mantle.js.map +1 -0
- package/dist/cjs/chains/mantleSepoliaTestnet.js +54 -0
- package/dist/cjs/chains/mantleSepoliaTestnet.js.map +1 -0
- package/dist/cjs/contracts.js +16 -0
- package/dist/cjs/contracts.js.map +1 -0
- package/dist/cjs/decorators/publicL1.js +38 -0
- package/dist/cjs/decorators/publicL1.js.map +1 -0
- package/dist/cjs/decorators/publicL2.js +18 -0
- package/dist/cjs/decorators/publicL2.js.map +1 -0
- package/dist/cjs/decorators/walletL1.js +20 -0
- package/dist/cjs/decorators/walletL1.js.map +1 -0
- package/dist/cjs/decorators/walletL2.js +16 -0
- package/dist/cjs/decorators/walletL2.js.map +1 -0
- package/dist/cjs/errors/utils.js +3 -0
- package/dist/cjs/errors/utils.js.map +1 -0
- package/dist/cjs/errors/withdrawal.js +17 -0
- package/dist/cjs/errors/withdrawal.js.map +1 -0
- package/dist/cjs/formatters.js +51 -0
- package/dist/cjs/formatters.js.map +1 -0
- package/dist/cjs/index.js +59 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/parsers.js +58 -0
- package/dist/cjs/parsers.js.map +1 -0
- package/dist/cjs/serializers.js +53 -0
- package/dist/cjs/serializers.js.map +1 -0
- package/dist/cjs/types/account.js +3 -0
- package/dist/cjs/types/account.js.map +1 -0
- package/dist/cjs/types/block.js +3 -0
- package/dist/cjs/types/block.js.map +1 -0
- package/dist/cjs/types/chain.js +3 -0
- package/dist/cjs/types/chain.js.map +1 -0
- package/dist/cjs/types/contract.js +3 -0
- package/dist/cjs/types/contract.js.map +1 -0
- package/dist/cjs/types/deposit.js +3 -0
- package/dist/cjs/types/deposit.js.map +1 -0
- package/dist/cjs/types/l1Actions.js +8 -0
- package/dist/cjs/types/l1Actions.js.map +1 -0
- package/dist/cjs/types/l2Actions.js +11 -0
- package/dist/cjs/types/l2Actions.js.map +1 -0
- package/dist/cjs/types/transaction.js +3 -0
- package/dist/cjs/types/transaction.js.map +1 -0
- package/dist/cjs/types/withdrawal.js +3 -0
- package/dist/cjs/types/withdrawal.js.map +1 -0
- package/dist/cjs/utils/extractTransactionDepositedLogs.js +13 -0
- package/dist/cjs/utils/extractTransactionDepositedLogs.js.map +1 -0
- package/dist/cjs/utils/extractWithdrawalMessageLogs.js +13 -0
- package/dist/cjs/utils/extractWithdrawalMessageLogs.js.map +1 -0
- package/dist/cjs/utils/getL2TransactionHash.js +29 -0
- package/dist/cjs/utils/getL2TransactionHash.js.map +1 -0
- package/dist/cjs/utils/getL2TransactionHashes.js +10 -0
- package/dist/cjs/utils/getL2TransactionHashes.js.map +1 -0
- package/dist/cjs/utils/getSourceHash.js +17 -0
- package/dist/cjs/utils/getSourceHash.js.map +1 -0
- package/dist/cjs/utils/getWithdrawalHashStorageSlot.js +9 -0
- package/dist/cjs/utils/getWithdrawalHashStorageSlot.js.map +1 -0
- package/dist/cjs/utils/getWithdrawals.js +9 -0
- package/dist/cjs/utils/getWithdrawals.js.map +1 -0
- package/dist/cjs/utils/opaqueDataToDepositData.js +32 -0
- package/dist/cjs/utils/opaqueDataToDepositData.js.map +1 -0
- package/dist/cjs/utils/parseDepositRequest.js +43 -0
- package/dist/cjs/utils/parseDepositRequest.js.map +1 -0
- package/dist/cjs/utils/parseInitWithdrawRequest.js +55 -0
- package/dist/cjs/utils/parseInitWithdrawRequest.js.map +1 -0
- package/dist/cjs/utils/poll.js +26 -0
- package/dist/cjs/utils/poll.js.map +1 -0
- package/dist/cjs/utils/promise/withCache.js +47 -0
- package/dist/cjs/utils/promise/withCache.js.map +1 -0
- package/dist/cjs/utils/wait.js +7 -0
- package/dist/cjs/utils/wait.js.map +1 -0
- package/dist/esm/abis.js +3335 -0
- package/dist/esm/abis.js.map +1 -0
- package/dist/esm/actions/buildProveWithdrawal.js +67 -0
- package/dist/esm/actions/buildProveWithdrawal.js.map +1 -0
- package/dist/esm/actions/depositERC20.js +39 -0
- package/dist/esm/actions/depositERC20.js.map +1 -0
- package/dist/esm/actions/depositETH.js +38 -0
- package/dist/esm/actions/depositETH.js.map +1 -0
- package/dist/esm/actions/depositMNT.js +37 -0
- package/dist/esm/actions/depositMNT.js.map +1 -0
- package/dist/esm/actions/estimateDepositERC20Gas.js +43 -0
- package/dist/esm/actions/estimateDepositERC20Gas.js.map +1 -0
- package/dist/esm/actions/estimateDepositETHGas.js +43 -0
- package/dist/esm/actions/estimateDepositETHGas.js.map +1 -0
- package/dist/esm/actions/estimateDepositMNTGas.js +41 -0
- package/dist/esm/actions/estimateDepositMNTGas.js.map +1 -0
- package/dist/esm/actions/estimateFinalizeWithdrawalGas.js +34 -0
- package/dist/esm/actions/estimateFinalizeWithdrawalGas.js.map +1 -0
- package/dist/esm/actions/estimateInitiateERC20WithdrawalGas.js +35 -0
- package/dist/esm/actions/estimateInitiateERC20WithdrawalGas.js.map +1 -0
- package/dist/esm/actions/estimateInitiateETHWithdrawalGas.js +34 -0
- package/dist/esm/actions/estimateInitiateETHWithdrawalGas.js.map +1 -0
- package/dist/esm/actions/estimateInitiateMNTWithdrawalGas.js +35 -0
- package/dist/esm/actions/estimateInitiateMNTWithdrawalGas.js.map +1 -0
- package/dist/esm/actions/estimateProveWithdrawalGas.js +34 -0
- package/dist/esm/actions/estimateProveWithdrawalGas.js.map +1 -0
- package/dist/esm/actions/finalizeWithdrawal.js +30 -0
- package/dist/esm/actions/finalizeWithdrawal.js.map +1 -0
- package/dist/esm/actions/getL2Output.js +33 -0
- package/dist/esm/actions/getL2Output.js.map +1 -0
- package/dist/esm/actions/getPortalVersion.js +26 -0
- package/dist/esm/actions/getPortalVersion.js.map +1 -0
- package/dist/esm/actions/getTimeToFinalize.js +48 -0
- package/dist/esm/actions/getTimeToFinalize.js.map +1 -0
- package/dist/esm/actions/getTimeToNextL2Output.js +68 -0
- package/dist/esm/actions/getTimeToNextL2Output.js.map +1 -0
- package/dist/esm/actions/getTimeToProve.js +14 -0
- package/dist/esm/actions/getTimeToProve.js.map +1 -0
- package/dist/esm/actions/getWithdrawalStatus.js +138 -0
- package/dist/esm/actions/getWithdrawalStatus.js.map +1 -0
- package/dist/esm/actions/initiateERC20Withdrawal.js +31 -0
- package/dist/esm/actions/initiateERC20Withdrawal.js.map +1 -0
- package/dist/esm/actions/initiateETHWithdrawal.js +30 -0
- package/dist/esm/actions/initiateETHWithdrawal.js.map +1 -0
- package/dist/esm/actions/initiateMNTWithdrawal.js +31 -0
- package/dist/esm/actions/initiateMNTWithdrawal.js.map +1 -0
- package/dist/esm/actions/proveWithdrawal.js +30 -0
- package/dist/esm/actions/proveWithdrawal.js.map +1 -0
- package/dist/esm/actions/waitForNextL2Output.js +33 -0
- package/dist/esm/actions/waitForNextL2Output.js.map +1 -0
- package/dist/esm/actions/waitToFinalize.js +11 -0
- package/dist/esm/actions/waitToFinalize.js.map +1 -0
- package/dist/esm/actions/waitToProve.js +26 -0
- package/dist/esm/actions/waitToProve.js.map +1 -0
- package/dist/esm/chainConfig.js +9 -0
- package/dist/esm/chainConfig.js.map +1 -0
- package/dist/esm/chains/index.js +3 -0
- package/dist/esm/chains/index.js.map +1 -0
- package/dist/esm/chains/mantle.js +50 -0
- package/dist/esm/chains/mantle.js.map +1 -0
- package/dist/esm/chains/mantleSepoliaTestnet.js +51 -0
- package/dist/esm/chains/mantleSepoliaTestnet.js.map +1 -0
- package/dist/esm/contracts.js +13 -0
- package/dist/esm/contracts.js.map +1 -0
- package/dist/esm/decorators/publicL1.js +35 -0
- package/dist/esm/decorators/publicL1.js.map +1 -0
- package/dist/esm/decorators/publicL2.js +15 -0
- package/dist/esm/decorators/publicL2.js.map +1 -0
- package/dist/esm/decorators/walletL1.js +17 -0
- package/dist/esm/decorators/walletL1.js.map +1 -0
- package/dist/esm/decorators/walletL2.js +13 -0
- package/dist/esm/decorators/walletL2.js.map +1 -0
- package/dist/esm/errors/utils.js +2 -0
- package/dist/esm/errors/utils.js.map +1 -0
- package/dist/esm/errors/withdrawal.js +12 -0
- package/dist/esm/errors/withdrawal.js.map +1 -0
- package/dist/esm/formatters.js +48 -0
- package/dist/esm/formatters.js.map +1 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/parsers.js +54 -0
- package/dist/esm/parsers.js.map +1 -0
- package/dist/esm/serializers.js +48 -0
- package/dist/esm/serializers.js.map +1 -0
- package/dist/esm/types/account.js +2 -0
- package/dist/esm/types/account.js.map +1 -0
- package/dist/esm/types/block.js +2 -0
- package/dist/esm/types/block.js.map +1 -0
- package/dist/esm/types/chain.js +2 -0
- package/dist/esm/types/chain.js.map +1 -0
- package/dist/esm/types/contract.js +2 -0
- package/dist/esm/types/contract.js.map +1 -0
- package/dist/esm/types/deposit.js +2 -0
- package/dist/esm/types/deposit.js.map +1 -0
- package/dist/esm/types/l1Actions.js +5 -0
- package/dist/esm/types/l1Actions.js.map +1 -0
- package/dist/esm/types/l2Actions.js +7 -0
- package/dist/esm/types/l2Actions.js.map +1 -0
- package/dist/esm/types/transaction.js +2 -0
- package/dist/esm/types/transaction.js.map +1 -0
- package/dist/esm/types/withdrawal.js +2 -0
- package/dist/esm/types/withdrawal.js.map +1 -0
- package/dist/esm/utils/extractTransactionDepositedLogs.js +10 -0
- package/dist/esm/utils/extractTransactionDepositedLogs.js.map +1 -0
- package/dist/esm/utils/extractWithdrawalMessageLogs.js +10 -0
- package/dist/esm/utils/extractWithdrawalMessageLogs.js.map +1 -0
- package/dist/esm/utils/getL2TransactionHash.js +26 -0
- package/dist/esm/utils/getL2TransactionHash.js.map +1 -0
- package/dist/esm/utils/getL2TransactionHashes.js +7 -0
- package/dist/esm/utils/getL2TransactionHashes.js.map +1 -0
- package/dist/esm/utils/getSourceHash.js +14 -0
- package/dist/esm/utils/getSourceHash.js.map +1 -0
- package/dist/esm/utils/getWithdrawalHashStorageSlot.js +6 -0
- package/dist/esm/utils/getWithdrawalHashStorageSlot.js.map +1 -0
- package/dist/esm/utils/getWithdrawals.js +6 -0
- package/dist/esm/utils/getWithdrawals.js.map +1 -0
- package/dist/esm/utils/opaqueDataToDepositData.js +29 -0
- package/dist/esm/utils/opaqueDataToDepositData.js.map +1 -0
- package/dist/esm/utils/parseDepositRequest.js +39 -0
- package/dist/esm/utils/parseDepositRequest.js.map +1 -0
- package/dist/esm/utils/parseInitWithdrawRequest.js +51 -0
- package/dist/esm/utils/parseInitWithdrawRequest.js.map +1 -0
- package/dist/esm/utils/poll.js +26 -0
- package/dist/esm/utils/poll.js.map +1 -0
- package/dist/esm/utils/promise/withCache.js +57 -0
- package/dist/esm/utils/promise/withCache.js.map +1 -0
- package/dist/esm/utils/wait.js +4 -0
- package/dist/esm/utils/wait.js.map +1 -0
- package/dist/types/abis.d.ts +3110 -0
- package/dist/types/abis.d.ts.map +1 -0
- package/dist/types/actions/buildProveWithdrawal.d.ts +34 -0
- package/dist/types/actions/buildProveWithdrawal.d.ts.map +1 -0
- package/dist/types/actions/depositERC20.d.ts +29 -0
- package/dist/types/actions/depositERC20.d.ts.map +1 -0
- package/dist/types/actions/depositETH.d.ts +29 -0
- package/dist/types/actions/depositETH.d.ts.map +1 -0
- package/dist/types/actions/depositMNT.d.ts +29 -0
- package/dist/types/actions/depositMNT.d.ts.map +1 -0
- package/dist/types/actions/estimateDepositERC20Gas.d.ts +26 -0
- package/dist/types/actions/estimateDepositERC20Gas.d.ts.map +1 -0
- package/dist/types/actions/estimateDepositETHGas.d.ts +26 -0
- package/dist/types/actions/estimateDepositETHGas.d.ts.map +1 -0
- package/dist/types/actions/estimateDepositMNTGas.d.ts +26 -0
- package/dist/types/actions/estimateDepositMNTGas.d.ts.map +1 -0
- package/dist/types/actions/estimateFinalizeWithdrawalGas.d.ts +26 -0
- package/dist/types/actions/estimateFinalizeWithdrawalGas.d.ts.map +1 -0
- package/dist/types/actions/estimateInitiateERC20WithdrawalGas.d.ts +25 -0
- package/dist/types/actions/estimateInitiateERC20WithdrawalGas.d.ts.map +1 -0
- package/dist/types/actions/estimateInitiateETHWithdrawalGas.d.ts +25 -0
- package/dist/types/actions/estimateInitiateETHWithdrawalGas.d.ts.map +1 -0
- package/dist/types/actions/estimateInitiateMNTWithdrawalGas.d.ts +25 -0
- package/dist/types/actions/estimateInitiateMNTWithdrawalGas.d.ts.map +1 -0
- package/dist/types/actions/estimateProveWithdrawalGas.d.ts +35 -0
- package/dist/types/actions/estimateProveWithdrawalGas.d.ts.map +1 -0
- package/dist/types/actions/finalizeWithdrawal.d.ts +29 -0
- package/dist/types/actions/finalizeWithdrawal.d.ts.map +1 -0
- package/dist/types/actions/getL2Output.d.ts +24 -0
- package/dist/types/actions/getL2Output.d.ts.map +1 -0
- package/dist/types/actions/getPortalVersion.d.ts +23 -0
- package/dist/types/actions/getPortalVersion.d.ts.map +1 -0
- package/dist/types/actions/getTimeToFinalize.d.ts +26 -0
- package/dist/types/actions/getTimeToFinalize.d.ts.map +1 -0
- package/dist/types/actions/getTimeToNextL2Output.d.ts +35 -0
- package/dist/types/actions/getTimeToNextL2Output.d.ts.map +1 -0
- package/dist/types/actions/getTimeToProve.d.ts +24 -0
- package/dist/types/actions/getTimeToProve.d.ts.map +1 -0
- package/dist/types/actions/getWithdrawalStatus.d.ts +22 -0
- package/dist/types/actions/getWithdrawalStatus.d.ts.map +1 -0
- package/dist/types/actions/initiateERC20Withdrawal.d.ts +27 -0
- package/dist/types/actions/initiateERC20Withdrawal.d.ts.map +1 -0
- package/dist/types/actions/initiateETHWithdrawal.d.ts +27 -0
- package/dist/types/actions/initiateETHWithdrawal.d.ts.map +1 -0
- package/dist/types/actions/initiateMNTWithdrawal.d.ts +27 -0
- package/dist/types/actions/initiateMNTWithdrawal.d.ts.map +1 -0
- package/dist/types/actions/proveWithdrawal.d.ts +36 -0
- package/dist/types/actions/proveWithdrawal.d.ts.map +1 -0
- package/dist/types/actions/waitForNextL2Output.d.ts +29 -0
- package/dist/types/actions/waitForNextL2Output.d.ts.map +1 -0
- package/dist/types/actions/waitToFinalize.d.ts +14 -0
- package/dist/types/actions/waitToFinalize.d.ts.map +1 -0
- package/dist/types/actions/waitToProve.d.ts +27 -0
- package/dist/types/actions/waitToProve.d.ts.map +1 -0
- package/dist/types/chainConfig.d.ts +43 -0
- package/dist/types/chainConfig.d.ts.map +1 -0
- package/dist/types/chains/index.d.ts +3 -0
- package/dist/types/chains/index.d.ts.map +1 -0
- package/dist/types/chains/mantle.d.ts +299 -0
- package/dist/types/chains/mantle.d.ts.map +1 -0
- package/dist/types/chains/mantleSepoliaTestnet.d.ts +299 -0
- package/dist/types/chains/mantleSepoliaTestnet.d.ts.map +1 -0
- package/dist/types/contracts.d.ts +21 -0
- package/dist/types/contracts.d.ts.map +1 -0
- package/dist/types/decorators/publicL1.d.ts +35 -0
- package/dist/types/decorators/publicL1.d.ts.map +1 -0
- package/dist/types/decorators/publicL2.d.ts +16 -0
- package/dist/types/decorators/publicL2.d.ts.map +1 -0
- package/dist/types/decorators/walletL1.d.ts +17 -0
- package/dist/types/decorators/walletL1.d.ts.map +1 -0
- package/dist/types/decorators/walletL2.d.ts +13 -0
- package/dist/types/decorators/walletL2.d.ts.map +1 -0
- package/dist/types/errors/utils.d.ts +4 -0
- package/dist/types/errors/utils.d.ts.map +1 -0
- package/dist/types/errors/withdrawal.d.ts +17 -0
- package/dist/types/errors/withdrawal.d.ts.map +1 -0
- package/dist/types/formatters.d.ts +20 -0
- package/dist/types/formatters.d.ts.map +1 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/parsers.d.ts +8 -0
- package/dist/types/parsers.d.ts.map +1 -0
- package/dist/types/serializers.d.ts +13 -0
- package/dist/types/serializers.d.ts.map +1 -0
- package/dist/types/types/account.d.ts +7 -0
- package/dist/types/types/account.d.ts.map +1 -0
- package/dist/types/types/block.d.ts +13 -0
- package/dist/types/types/block.d.ts.map +1 -0
- package/dist/types/types/chain.d.ts +9 -0
- package/dist/types/types/chain.d.ts.map +1 -0
- package/dist/types/types/contract.d.ts +14 -0
- package/dist/types/types/contract.d.ts.map +1 -0
- package/dist/types/types/deposit.d.ts +35 -0
- package/dist/types/types/deposit.d.ts.map +1 -0
- package/dist/types/types/l1Actions.d.ts +856 -0
- package/dist/types/types/l1Actions.d.ts.map +1 -0
- package/dist/types/types/l2Actions.d.ts +3 -0
- package/dist/types/types/l2Actions.d.ts.map +1 -0
- package/dist/types/types/transaction.d.ts +58 -0
- package/dist/types/types/transaction.d.ts.map +1 -0
- package/dist/types/types/withdrawal.d.ts +39 -0
- package/dist/types/types/withdrawal.d.ts.map +1 -0
- package/dist/types/utils/extractTransactionDepositedLogs.d.ts +450 -0
- package/dist/types/utils/extractTransactionDepositedLogs.d.ts.map +1 -0
- package/dist/types/utils/extractWithdrawalMessageLogs.d.ts +160 -0
- package/dist/types/utils/extractWithdrawalMessageLogs.d.ts.map +1 -0
- package/dist/types/utils/getL2TransactionHash.d.ts +12 -0
- package/dist/types/utils/getL2TransactionHash.d.ts.map +1 -0
- package/dist/types/utils/getL2TransactionHashes.d.ts +11 -0
- package/dist/types/utils/getL2TransactionHashes.d.ts.map +1 -0
- package/dist/types/utils/getSourceHash.d.ts +25 -0
- package/dist/types/utils/getSourceHash.d.ts.map +1 -0
- package/dist/types/utils/getWithdrawalHashStorageSlot.d.ts +10 -0
- package/dist/types/utils/getWithdrawalHashStorageSlot.d.ts.map +1 -0
- package/dist/types/utils/getWithdrawals.d.ts +12 -0
- package/dist/types/utils/getWithdrawals.d.ts.map +1 -0
- package/dist/types/utils/opaqueDataToDepositData.d.ts +16 -0
- package/dist/types/utils/opaqueDataToDepositData.d.ts.map +1 -0
- package/dist/types/utils/parseDepositRequest.d.ts +11 -0
- package/dist/types/utils/parseDepositRequest.d.ts.map +1 -0
- package/dist/types/utils/parseInitWithdrawRequest.d.ts +11 -0
- package/dist/types/utils/parseInitWithdrawRequest.d.ts.map +1 -0
- package/dist/types/utils/poll.d.ts +15 -0
- package/dist/types/utils/poll.d.ts.map +1 -0
- package/dist/types/utils/promise/withCache.d.ts +41 -0
- package/dist/types/utils/promise/withCache.d.ts.map +1 -0
- package/dist/types/utils/wait.d.ts +2 -0
- package/dist/types/utils/wait.d.ts.map +1 -0
- package/package.json +113 -0
- package/src/mantle/abis.ts +3339 -0
- package/src/mantle/actions/buildProveWithdrawal.ts +150 -0
- package/src/mantle/actions/depositERC20.ts +103 -0
- package/src/mantle/actions/depositETH.ts +102 -0
- package/src/mantle/actions/depositMNT.ts +101 -0
- package/src/mantle/actions/estimateDepositERC20Gas.ts +113 -0
- package/src/mantle/actions/estimateDepositETHGas.ts +113 -0
- package/src/mantle/actions/estimateDepositMNTGas.ts +111 -0
- package/src/mantle/actions/estimateFinalizeWithdrawalGas.ts +102 -0
- package/src/mantle/actions/estimateInitiateERC20WithdrawalGas.ts +106 -0
- package/src/mantle/actions/estimateInitiateETHWithdrawalGas.ts +105 -0
- package/src/mantle/actions/estimateInitiateMNTWithdrawalGas.ts +106 -0
- package/src/mantle/actions/estimateProveWithdrawalGas.ts +114 -0
- package/src/mantle/actions/finalizeWithdrawal.ts +95 -0
- package/src/mantle/actions/getL2Output.ts +75 -0
- package/src/mantle/actions/getPortalVersion.ts +57 -0
- package/src/mantle/actions/getTimeToFinalize.ts +85 -0
- package/src/mantle/actions/getTimeToNextL2Output.ts +132 -0
- package/src/mantle/actions/getTimeToProve.ts +58 -0
- package/src/mantle/actions/getWithdrawalStatus.ts +225 -0
- package/src/mantle/actions/initiateERC20Withdrawal.ts +93 -0
- package/src/mantle/actions/initiateETHWithdrawal.ts +90 -0
- package/src/mantle/actions/initiateMNTWithdrawal.ts +91 -0
- package/src/mantle/actions/proveWithdrawal.ts +107 -0
- package/src/mantle/actions/waitForNextL2Output.ts +87 -0
- package/src/mantle/actions/waitToFinalize.ts +33 -0
- package/src/mantle/actions/waitToProve.ts +83 -0
- package/src/mantle/chainConfig.ts +9 -0
- package/src/mantle/chains/index.ts +2 -0
- package/src/mantle/chains/mantle.ts +51 -0
- package/src/mantle/chains/mantleSepoliaTestnet.ts +52 -0
- package/src/mantle/contracts.ts +14 -0
- package/src/mantle/decorators/publicL1.ts +182 -0
- package/src/mantle/decorators/publicL2.ts +96 -0
- package/src/mantle/decorators/walletL1.ts +67 -0
- package/src/mantle/decorators/walletL2.ts +55 -0
- package/src/mantle/errors/utils.ts +1 -0
- package/src/mantle/errors/withdrawal.ts +24 -0
- package/src/mantle/formatters.ts +64 -0
- package/src/mantle/index.ts +179 -0
- package/src/mantle/parsers.ts +97 -0
- package/src/mantle/serializers.ts +106 -0
- package/src/mantle/types/account.ts +25 -0
- package/src/mantle/types/block.ts +34 -0
- package/src/mantle/types/chain.ts +10 -0
- package/src/mantle/types/contract.ts +26 -0
- package/src/mantle/types/deposit.ts +40 -0
- package/src/mantle/types/l1Actions.ts +21 -0
- package/src/mantle/types/l2Actions.ts +6 -0
- package/src/mantle/types/transaction.ts +108 -0
- package/src/mantle/types/withdrawal.ts +45 -0
- package/src/mantle/utils/extractTransactionDepositedLogs.ts +33 -0
- package/src/mantle/utils/extractWithdrawalMessageLogs.ts +33 -0
- package/src/mantle/utils/getL2TransactionHash.ts +51 -0
- package/src/mantle/utils/getL2TransactionHashes.ts +21 -0
- package/src/mantle/utils/getSourceHash.ts +62 -0
- package/src/mantle/utils/getWithdrawalHashStorageSlot.ts +27 -0
- package/src/mantle/utils/getWithdrawals.ts +25 -0
- package/src/mantle/utils/opaqueDataToDepositData.ts +58 -0
- package/src/mantle/utils/parseDepositRequest.ts +67 -0
- package/src/mantle/utils/parseInitWithdrawRequest.ts +68 -0
- package/src/mantle/utils/poll.ts +45 -0
- package/src/mantle/utils/promise/withCache.ts +81 -0
- package/src/mantle/utils/wait.ts +3 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
import type { Address } from "viem";
|
2
|
+
import type { Client, Transport } from "viem";
|
3
|
+
import type { Account } from "viem";
|
4
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
5
|
+
import type { Hash } from "viem";
|
6
|
+
import type { UnionEvaluate, UnionOmit } from "viem";
|
7
|
+
import {
|
8
|
+
writeContract,
|
9
|
+
type WriteContractErrorType,
|
10
|
+
type WriteContractParameters,
|
11
|
+
} from "viem/actions";
|
12
|
+
import type { FormattedTransactionRequest } from "viem/utils";
|
13
|
+
import { portalAbi } from "../abis.js";
|
14
|
+
import type { ErrorType } from "../errors/utils.js";
|
15
|
+
import type { GetAccountParameter } from "../types/account.js";
|
16
|
+
import type { GetContractAddressParameter } from "../types/contract.js";
|
17
|
+
import type { Withdrawal } from "../types/withdrawal.js";
|
18
|
+
import type { EstimateFinalizeWithdrawalGasErrorType } from "./estimateFinalizeWithdrawalGas.js";
|
19
|
+
|
20
|
+
export type FinalizeWithdrawalParameters<
|
21
|
+
chain extends Chain | undefined = Chain | undefined,
|
22
|
+
account extends Account | undefined = Account | undefined,
|
23
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
24
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
25
|
+
> = UnionEvaluate<
|
26
|
+
UnionOmit<
|
27
|
+
FormattedTransactionRequest<_derivedChain>,
|
28
|
+
| "accessList"
|
29
|
+
| "data"
|
30
|
+
| "from"
|
31
|
+
| "gas"
|
32
|
+
| "gasPrice"
|
33
|
+
| "to"
|
34
|
+
| "type"
|
35
|
+
| "value"
|
36
|
+
>
|
37
|
+
> &
|
38
|
+
GetAccountParameter<account, Account | Address> &
|
39
|
+
GetChainParameter<chain, chainOverride> &
|
40
|
+
GetContractAddressParameter<_derivedChain, "portal"> & {
|
41
|
+
/**
|
42
|
+
* Gas limit for transaction execution on the L1.
|
43
|
+
*/
|
44
|
+
gas?: bigint | undefined;
|
45
|
+
withdrawal: Withdrawal;
|
46
|
+
};
|
47
|
+
export type FinalizeWithdrawalReturnType = Hash;
|
48
|
+
export type FinalizeWithdrawalErrorType =
|
49
|
+
| EstimateFinalizeWithdrawalGasErrorType
|
50
|
+
| WriteContractErrorType
|
51
|
+
| ErrorType;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @param client - Client to use
|
55
|
+
* @param parameters - {@link FinalizeWithdrawalParameters}
|
56
|
+
* @returns The finalize transaction hash. {@link FinalizeWithdrawalReturnType}
|
57
|
+
*/
|
58
|
+
export async function finalizeWithdrawal<
|
59
|
+
chain extends Chain | undefined,
|
60
|
+
account extends Account | undefined,
|
61
|
+
chainOverride extends Chain | undefined = undefined,
|
62
|
+
>(
|
63
|
+
client: Client<Transport, chain, account>,
|
64
|
+
parameters: FinalizeWithdrawalParameters<chain, account, chainOverride>,
|
65
|
+
): Promise<FinalizeWithdrawalReturnType> {
|
66
|
+
const {
|
67
|
+
account,
|
68
|
+
chain = client.chain,
|
69
|
+
gas,
|
70
|
+
maxFeePerGas,
|
71
|
+
maxPriorityFeePerGas,
|
72
|
+
nonce,
|
73
|
+
targetChain,
|
74
|
+
withdrawal,
|
75
|
+
} = parameters;
|
76
|
+
|
77
|
+
const portalAddress = (() => {
|
78
|
+
if (parameters.portalAddress) return parameters.portalAddress;
|
79
|
+
if (chain) return targetChain!.contracts.portal[chain.id].address;
|
80
|
+
return Object.values(targetChain!.contracts.portal)[0].address;
|
81
|
+
})();
|
82
|
+
|
83
|
+
return writeContract(client, {
|
84
|
+
account: account!,
|
85
|
+
abi: portalAbi,
|
86
|
+
address: portalAddress,
|
87
|
+
chain,
|
88
|
+
functionName: "finalizeWithdrawalTransaction",
|
89
|
+
args: [withdrawal],
|
90
|
+
gas,
|
91
|
+
maxFeePerGas,
|
92
|
+
maxPriorityFeePerGas,
|
93
|
+
nonce,
|
94
|
+
} satisfies WriteContractParameters as any);
|
95
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import type { Account, Client, Transport } from "viem";
|
2
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
3
|
+
import type { Hex } from "viem";
|
4
|
+
import type { OneOf } from "viem";
|
5
|
+
import { readContract, type ReadContractErrorType } from "viem/actions";
|
6
|
+
import { l2OutputOracleAbi } from "../abis.js";
|
7
|
+
import type { ErrorType } from "../errors/utils.js";
|
8
|
+
import type { TargetChain } from "../types/chain.js";
|
9
|
+
import type { GetContractAddressParameter } from "../types/contract.js";
|
10
|
+
|
11
|
+
export type GetL2OutputParameters<
|
12
|
+
chain extends Chain | undefined = Chain | undefined,
|
13
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
14
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
15
|
+
> = GetChainParameter<chain, chainOverride> &
|
16
|
+
OneOf<
|
17
|
+
| GetContractAddressParameter<_derivedChain, "l2OutputOracle">
|
18
|
+
| GetContractAddressParameter<_derivedChain, "portal">
|
19
|
+
> & {
|
20
|
+
l2BlockNumber: bigint;
|
21
|
+
};
|
22
|
+
export type GetL2OutputReturnType = {
|
23
|
+
outputIndex: bigint;
|
24
|
+
outputRoot: Hex;
|
25
|
+
timestamp: bigint;
|
26
|
+
l2BlockNumber: bigint;
|
27
|
+
};
|
28
|
+
export type GetL2OutputErrorType = ReadContractErrorType | ErrorType;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @param client - Client to use
|
32
|
+
* @param parameters - {@link GetL2OutputParameters}
|
33
|
+
* @returns The L2 output. {@link GetL2OutputReturnType}
|
34
|
+
*/
|
35
|
+
export async function getL2Output<
|
36
|
+
chain extends Chain | undefined,
|
37
|
+
account extends Account | undefined,
|
38
|
+
chainOverride extends Chain | undefined = undefined,
|
39
|
+
>(
|
40
|
+
client: Client<Transport, chain, account>,
|
41
|
+
parameters: GetL2OutputParameters<chain, chainOverride>,
|
42
|
+
): Promise<GetL2OutputReturnType> {
|
43
|
+
const { chain = client.chain, l2BlockNumber, targetChain } = parameters;
|
44
|
+
|
45
|
+
const l2OutputOracleAddress = (() => {
|
46
|
+
if (parameters.l2OutputOracleAddress) {
|
47
|
+
return parameters.l2OutputOracleAddress;
|
48
|
+
}
|
49
|
+
if (chain) {
|
50
|
+
return (targetChain as unknown as TargetChain)!.contracts.l2OutputOracle[
|
51
|
+
chain.id
|
52
|
+
].address;
|
53
|
+
}
|
54
|
+
return (
|
55
|
+
Object.values(
|
56
|
+
(targetChain as unknown as TargetChain)!.contracts.l2OutputOracle,
|
57
|
+
) as any
|
58
|
+
)[0].address;
|
59
|
+
})();
|
60
|
+
|
61
|
+
const outputIndex = await readContract(client, {
|
62
|
+
address: l2OutputOracleAddress,
|
63
|
+
abi: l2OutputOracleAbi,
|
64
|
+
functionName: "getL2OutputIndexAfter",
|
65
|
+
args: [l2BlockNumber],
|
66
|
+
});
|
67
|
+
const output = await readContract(client, {
|
68
|
+
address: l2OutputOracleAddress,
|
69
|
+
abi: l2OutputOracleAbi,
|
70
|
+
functionName: "getL2Output",
|
71
|
+
args: [outputIndex],
|
72
|
+
});
|
73
|
+
|
74
|
+
return { outputIndex, ...output };
|
75
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import type { Client, Transport } from "viem";
|
2
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
3
|
+
import { readContract, type ReadContractErrorType } from "viem/actions";
|
4
|
+
import { portal2Abi } from "../abis.js";
|
5
|
+
import type { ErrorType } from "../errors/utils.js";
|
6
|
+
import type { GetContractAddressParameter } from "../types/contract.js";
|
7
|
+
import { withCache } from "../utils/promise/withCache.js";
|
8
|
+
|
9
|
+
export type GetPortalVersionParameters<
|
10
|
+
chain extends Chain | undefined = Chain | undefined,
|
11
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
12
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
13
|
+
> = GetChainParameter<chain, chainOverride> &
|
14
|
+
GetContractAddressParameter<_derivedChain, "portal">;
|
15
|
+
|
16
|
+
export type GetPortalVersionReturnType = {
|
17
|
+
major: number;
|
18
|
+
minor: number;
|
19
|
+
patch: number;
|
20
|
+
};
|
21
|
+
|
22
|
+
export type GetPortalVersionErrorType = ReadContractErrorType | ErrorType;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @param client - Client to use
|
26
|
+
* @param parameters - {@link GetPortalVersionParameters}
|
27
|
+
* @returns The version object.
|
28
|
+
*/
|
29
|
+
export async function getPortalVersion<
|
30
|
+
chain extends Chain | undefined,
|
31
|
+
chainOverride extends Chain | undefined = undefined,
|
32
|
+
>(
|
33
|
+
client: Client<Transport, chain>,
|
34
|
+
parameters: GetPortalVersionParameters<chain, chainOverride>,
|
35
|
+
) {
|
36
|
+
const { chain = client.chain, targetChain } = parameters;
|
37
|
+
|
38
|
+
const portalAddress = (() => {
|
39
|
+
if (parameters.portalAddress) return parameters.portalAddress;
|
40
|
+
if (chain) return targetChain!.contracts.portal[chain.id].address;
|
41
|
+
return Object.values(targetChain!.contracts.portal)[0].address;
|
42
|
+
})();
|
43
|
+
|
44
|
+
const version = await withCache(
|
45
|
+
() =>
|
46
|
+
readContract(client, {
|
47
|
+
abi: portal2Abi,
|
48
|
+
address: portalAddress,
|
49
|
+
functionName: "version",
|
50
|
+
}),
|
51
|
+
{ cacheKey: ["portalVersion", portalAddress].join("."), cacheTime: 300 },
|
52
|
+
);
|
53
|
+
|
54
|
+
const [major, minor, patch] = version.split(".").map(Number);
|
55
|
+
|
56
|
+
return { major, minor, patch };
|
57
|
+
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
import type { Client, Transport } from "viem";
|
2
|
+
import type { Account } from "viem";
|
3
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
4
|
+
import type { Hash } from "viem";
|
5
|
+
import { multicall, type MulticallErrorType } from "viem/actions";
|
6
|
+
import { l2OutputOracleAbi, portalAbi } from "../abis.js";
|
7
|
+
import type { ErrorType } from "../errors/utils.js";
|
8
|
+
import type { GetContractAddressParameter } from "../types/contract.js";
|
9
|
+
|
10
|
+
export type GetTimeToFinalizeParameters<
|
11
|
+
chain extends Chain | undefined = Chain | undefined,
|
12
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
13
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
14
|
+
> = GetChainParameter<chain, chainOverride> &
|
15
|
+
GetContractAddressParameter<_derivedChain, "l2OutputOracle" | "portal"> & {
|
16
|
+
withdrawalHash: Hash;
|
17
|
+
};
|
18
|
+
export type GetTimeToFinalizeReturnType = {
|
19
|
+
/** The finalization period (in seconds). */
|
20
|
+
period: number;
|
21
|
+
/** Seconds until the withdrawal can be finalized. */
|
22
|
+
seconds: number;
|
23
|
+
/** Timestamp of when the withdrawal can be finalized. */
|
24
|
+
timestamp: number;
|
25
|
+
};
|
26
|
+
export type GetTimeToFinalizeErrorType = MulticallErrorType | ErrorType;
|
27
|
+
|
28
|
+
const buffer = 10;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @param client - Client to use
|
32
|
+
* @param parameters - {@link GetTimeToFinalizeParameters}
|
33
|
+
* @returns Time until finalize. {@link GetTimeToFinalizeReturnType}
|
34
|
+
*/
|
35
|
+
export async function getTimeToFinalize<
|
36
|
+
chain extends Chain | undefined,
|
37
|
+
account extends Account | undefined,
|
38
|
+
chainOverride extends Chain | undefined = undefined,
|
39
|
+
>(
|
40
|
+
client: Client<Transport, chain, account>,
|
41
|
+
parameters: GetTimeToFinalizeParameters<chain, chainOverride>,
|
42
|
+
): Promise<GetTimeToFinalizeReturnType> {
|
43
|
+
const { chain = client.chain, withdrawalHash, targetChain } = parameters;
|
44
|
+
|
45
|
+
const portalAddress = (() => {
|
46
|
+
if (parameters.portalAddress) return parameters.portalAddress;
|
47
|
+
if (chain) return targetChain!.contracts.portal[chain.id].address;
|
48
|
+
return Object.values(targetChain!.contracts.portal)[0].address;
|
49
|
+
})();
|
50
|
+
|
51
|
+
const l2OutputOracleAddress = (() => {
|
52
|
+
if (parameters.l2OutputOracleAddress) {
|
53
|
+
return parameters.l2OutputOracleAddress;
|
54
|
+
}
|
55
|
+
if (chain) return targetChain!.contracts.l2OutputOracle[chain.id].address;
|
56
|
+
return Object.values(targetChain!.contracts.l2OutputOracle)[0].address;
|
57
|
+
})();
|
58
|
+
const [[_outputRoot, proveTimestamp, _l2OutputIndex], period] =
|
59
|
+
await multicall(client, {
|
60
|
+
allowFailure: false,
|
61
|
+
contracts: [
|
62
|
+
{
|
63
|
+
abi: portalAbi,
|
64
|
+
address: portalAddress,
|
65
|
+
functionName: "provenWithdrawals",
|
66
|
+
args: [withdrawalHash],
|
67
|
+
},
|
68
|
+
{
|
69
|
+
abi: l2OutputOracleAbi,
|
70
|
+
address: l2OutputOracleAddress,
|
71
|
+
functionName: "FINALIZATION_PERIOD_SECONDS",
|
72
|
+
},
|
73
|
+
],
|
74
|
+
});
|
75
|
+
|
76
|
+
const secondsSinceProven = Date.now() / 1000 - Number(proveTimestamp);
|
77
|
+
const secondsToFinalize = Number(period) - secondsSinceProven;
|
78
|
+
|
79
|
+
const seconds = Math.floor(
|
80
|
+
secondsToFinalize < 0 ? 0 : secondsToFinalize + buffer,
|
81
|
+
);
|
82
|
+
const timestamp = Date.now() + seconds * 1000;
|
83
|
+
|
84
|
+
return { period: Number(period), seconds, timestamp };
|
85
|
+
}
|
@@ -0,0 +1,132 @@
|
|
1
|
+
import type { Account, Client, Transport } from "viem";
|
2
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
3
|
+
import {
|
4
|
+
multicall,
|
5
|
+
type MulticallErrorType,
|
6
|
+
readContract,
|
7
|
+
type ReadContractErrorType,
|
8
|
+
} from "viem/actions";
|
9
|
+
import { l2OutputOracleAbi } from "../abis.js";
|
10
|
+
import type { ErrorType } from "../errors/utils.js";
|
11
|
+
import type { GetContractAddressParameter } from "../types/contract.js";
|
12
|
+
|
13
|
+
export type GetTimeToNextL2OutputParameters<
|
14
|
+
chain extends Chain | undefined = Chain | undefined,
|
15
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
16
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
17
|
+
> = GetChainParameter<chain, chainOverride> &
|
18
|
+
GetContractAddressParameter<_derivedChain, "l2OutputOracle"> & {
|
19
|
+
/**
|
20
|
+
* The buffer to account for discrepancies between non-deterministic time intervals.
|
21
|
+
* @default 1.1
|
22
|
+
*/
|
23
|
+
intervalBuffer?: number | undefined;
|
24
|
+
l2BlockNumber: bigint;
|
25
|
+
};
|
26
|
+
export type GetTimeToNextL2OutputReturnType = {
|
27
|
+
/** The interval (in seconds) between L2 outputs. */
|
28
|
+
interval: number;
|
29
|
+
/**
|
30
|
+
* Seconds until the next L2 output.
|
31
|
+
* `0` if the next L2 output has already been submitted.
|
32
|
+
*/
|
33
|
+
seconds: number;
|
34
|
+
/**
|
35
|
+
* Estimated timestamp of the next L2 output.
|
36
|
+
* `undefined` if the next L2 output has already been submitted.
|
37
|
+
*/
|
38
|
+
timestamp?: number | undefined;
|
39
|
+
};
|
40
|
+
export type GetTimeToNextL2OutputErrorType =
|
41
|
+
| MulticallErrorType
|
42
|
+
| ReadContractErrorType
|
43
|
+
| ErrorType;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @param client - Client to use
|
47
|
+
* @param parameters - {@link GetTimeToNextL2OutputParameters}
|
48
|
+
* @returns The L2 transaction hash. {@link GetTimeToNextL2OutputReturnType}
|
49
|
+
*/
|
50
|
+
export async function getTimeToNextL2Output<
|
51
|
+
chain extends Chain | undefined,
|
52
|
+
account extends Account | undefined,
|
53
|
+
chainOverride extends Chain | undefined = undefined,
|
54
|
+
>(
|
55
|
+
client: Client<Transport, chain, account>,
|
56
|
+
parameters: GetTimeToNextL2OutputParameters<chain, chainOverride>,
|
57
|
+
): Promise<GetTimeToNextL2OutputReturnType> {
|
58
|
+
const {
|
59
|
+
intervalBuffer = 1.1,
|
60
|
+
chain = client.chain,
|
61
|
+
l2BlockNumber,
|
62
|
+
targetChain,
|
63
|
+
} = parameters;
|
64
|
+
|
65
|
+
const l2OutputOracleAddress = (() => {
|
66
|
+
if (parameters.l2OutputOracleAddress) {
|
67
|
+
return parameters.l2OutputOracleAddress;
|
68
|
+
}
|
69
|
+
if (chain) return targetChain!.contracts.l2OutputOracle[chain.id].address;
|
70
|
+
return Object.values(targetChain!.contracts.l2OutputOracle)[0].address;
|
71
|
+
})();
|
72
|
+
|
73
|
+
const [latestOutputIndex, blockTime, blockInterval] = await multicall(
|
74
|
+
client,
|
75
|
+
{
|
76
|
+
allowFailure: false,
|
77
|
+
contracts: [
|
78
|
+
{
|
79
|
+
abi: l2OutputOracleAbi,
|
80
|
+
address: l2OutputOracleAddress,
|
81
|
+
functionName: "latestOutputIndex",
|
82
|
+
},
|
83
|
+
{
|
84
|
+
abi: l2OutputOracleAbi,
|
85
|
+
address: l2OutputOracleAddress,
|
86
|
+
functionName: "L2_BLOCK_TIME",
|
87
|
+
},
|
88
|
+
{
|
89
|
+
abi: l2OutputOracleAbi,
|
90
|
+
address: l2OutputOracleAddress,
|
91
|
+
functionName: "SUBMISSION_INTERVAL",
|
92
|
+
},
|
93
|
+
],
|
94
|
+
},
|
95
|
+
);
|
96
|
+
const latestOutput = await readContract(client, {
|
97
|
+
abi: l2OutputOracleAbi,
|
98
|
+
address: l2OutputOracleAddress,
|
99
|
+
functionName: "getL2Output",
|
100
|
+
args: [latestOutputIndex],
|
101
|
+
});
|
102
|
+
const latestOutputTimestamp = Number(latestOutput.timestamp) * 1000;
|
103
|
+
|
104
|
+
const interval = Number(blockInterval * blockTime);
|
105
|
+
const intervalWithBuffer = Math.ceil(interval * intervalBuffer);
|
106
|
+
|
107
|
+
const now = Date.now();
|
108
|
+
|
109
|
+
const seconds = (() => {
|
110
|
+
// If the current timestamp is lesser than the latest L2 output timestamp,
|
111
|
+
// then we assume that the L2 output has already been submitted.
|
112
|
+
if (now < latestOutputTimestamp) return 0;
|
113
|
+
|
114
|
+
// If the latest L2 output block is newer than the provided L2 block number,
|
115
|
+
// then we assume that the L2 output has already been submitted.
|
116
|
+
if (latestOutput.l2BlockNumber > l2BlockNumber) return 0;
|
117
|
+
|
118
|
+
const elapsedBlocks = Number(l2BlockNumber - latestOutput.l2BlockNumber);
|
119
|
+
|
120
|
+
const elapsed = Math.ceil((now - latestOutputTimestamp) / 1000);
|
121
|
+
const secondsToNextOutput =
|
122
|
+
intervalWithBuffer - (elapsed % intervalWithBuffer);
|
123
|
+
return elapsedBlocks < blockInterval
|
124
|
+
? secondsToNextOutput
|
125
|
+
: Math.floor(elapsedBlocks / Number(blockInterval)) * intervalWithBuffer +
|
126
|
+
secondsToNextOutput;
|
127
|
+
})();
|
128
|
+
|
129
|
+
const timestamp = seconds > 0 ? now + seconds * 1000 : undefined;
|
130
|
+
|
131
|
+
return { interval, seconds, timestamp };
|
132
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { Account, Client, Transport } from "viem";
|
2
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
3
|
+
import type { TransactionReceipt } from "viem";
|
4
|
+
import type { OneOf } from "viem";
|
5
|
+
import type { ErrorType } from "../errors/utils.js";
|
6
|
+
import type { GetContractAddressParameter } from "../types/contract.js";
|
7
|
+
import {
|
8
|
+
getTimeToNextL2Output,
|
9
|
+
type GetTimeToNextL2OutputErrorType,
|
10
|
+
type GetTimeToNextL2OutputParameters,
|
11
|
+
type GetTimeToNextL2OutputReturnType,
|
12
|
+
} from "./getTimeToNextL2Output.js";
|
13
|
+
|
14
|
+
export type GetTimeToProveParameters<
|
15
|
+
chain extends Chain | undefined = Chain | undefined,
|
16
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
17
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
18
|
+
> = GetChainParameter<chain, chainOverride> &
|
19
|
+
OneOf<
|
20
|
+
| GetContractAddressParameter<_derivedChain, "l2OutputOracle">
|
21
|
+
| GetContractAddressParameter<_derivedChain, "portal">
|
22
|
+
> & {
|
23
|
+
/**
|
24
|
+
* The buffer to account for discrepancies between non-deterministic time intervals.
|
25
|
+
* @default 1.1
|
26
|
+
*/
|
27
|
+
intervalBuffer?:
|
28
|
+
| GetTimeToNextL2OutputParameters["intervalBuffer"]
|
29
|
+
| undefined;
|
30
|
+
receipt: TransactionReceipt;
|
31
|
+
};
|
32
|
+
|
33
|
+
export type GetTimeToProveReturnType = GetTimeToNextL2OutputReturnType;
|
34
|
+
|
35
|
+
export type GetTimeToProveErrorType =
|
36
|
+
| GetTimeToNextL2OutputErrorType
|
37
|
+
| ErrorType;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @param client - Client to use
|
41
|
+
* @param parameters - {@link GetTimeToNextL2OutputParameters}
|
42
|
+
* @returns Time until prove step is ready. {@link GetTimeToNextL2OutputReturnType}
|
43
|
+
*/
|
44
|
+
export async function getTimeToProve<
|
45
|
+
chain extends Chain | undefined,
|
46
|
+
account extends Account | undefined,
|
47
|
+
chainOverride extends Chain | undefined = undefined,
|
48
|
+
>(
|
49
|
+
client: Client<Transport, chain, account>,
|
50
|
+
parameters: GetTimeToProveParameters<chain, chainOverride>,
|
51
|
+
): Promise<GetTimeToProveReturnType> {
|
52
|
+
const { receipt } = parameters;
|
53
|
+
|
54
|
+
return getTimeToNextL2Output(client, {
|
55
|
+
...parameters,
|
56
|
+
l2BlockNumber: receipt.blockNumber,
|
57
|
+
} as GetTimeToNextL2OutputParameters);
|
58
|
+
}
|