@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,150 @@
|
|
1
|
+
import type { Address } from "viem";
|
2
|
+
import { type Client, fromRlp, keccak256, toRlp, type Transport } from "viem";
|
3
|
+
import type { Account, DeriveAccount } from "viem";
|
4
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
5
|
+
import type { Hex } from "viem";
|
6
|
+
import type { OneOf, Prettify } from "viem";
|
7
|
+
import {
|
8
|
+
getBlock,
|
9
|
+
type GetBlockErrorType,
|
10
|
+
getProof,
|
11
|
+
type GetProofErrorType,
|
12
|
+
} from "viem/actions";
|
13
|
+
import { contracts } from "../contracts.js";
|
14
|
+
import type { ErrorType } from "../errors/utils.js";
|
15
|
+
import type { GetAccountParameter } from "../types/account.js";
|
16
|
+
import type { Withdrawal } from "../types/withdrawal.js";
|
17
|
+
import {
|
18
|
+
getWithdrawalHashStorageSlot,
|
19
|
+
type GetWithdrawalHashStorageSlotErrorType,
|
20
|
+
} from "../utils/getWithdrawalHashStorageSlot.js";
|
21
|
+
import type { GetL2OutputReturnType } from "./getL2Output.js";
|
22
|
+
import type { ProveWithdrawalParameters } from "./proveWithdrawal.js";
|
23
|
+
|
24
|
+
const outputRootProofVersion =
|
25
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000" as const;
|
26
|
+
|
27
|
+
export type BuildProveWithdrawalParameters<
|
28
|
+
chain extends Chain | undefined = Chain | undefined,
|
29
|
+
account extends Account | undefined = Account | undefined,
|
30
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
31
|
+
accountOverride extends Account | Address | undefined =
|
32
|
+
| Account
|
33
|
+
| Address
|
34
|
+
| undefined,
|
35
|
+
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
36
|
+
> = GetAccountParameter<account, accountOverride, false> &
|
37
|
+
GetChainParameter<chain, chainOverride> & {
|
38
|
+
withdrawal: Withdrawal;
|
39
|
+
} & OneOf<{ output: GetL2OutputReturnType }>;
|
40
|
+
|
41
|
+
export type BuildProveWithdrawalReturnType<
|
42
|
+
chain extends Chain | undefined = Chain | undefined,
|
43
|
+
account extends Account | undefined = Account | undefined,
|
44
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
45
|
+
accountOverride extends Account | Address | undefined =
|
46
|
+
| Account
|
47
|
+
| Address
|
48
|
+
| undefined,
|
49
|
+
> = Prettify<
|
50
|
+
Pick<
|
51
|
+
ProveWithdrawalParameters,
|
52
|
+
"l2OutputIndex" | "outputRootProof" | "withdrawalProof" | "withdrawal"
|
53
|
+
> & {
|
54
|
+
account: DeriveAccount<account, accountOverride>;
|
55
|
+
targetChain: DeriveChain<chain, chainOverride>;
|
56
|
+
}
|
57
|
+
>;
|
58
|
+
|
59
|
+
export type BuildProveWithdrawalErrorType =
|
60
|
+
| GetBlockErrorType
|
61
|
+
| GetProofErrorType
|
62
|
+
| GetWithdrawalHashStorageSlotErrorType
|
63
|
+
| ErrorType;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Builds the transaction that proves a withdrawal was initiated on an L2. Used in the Withdrawal flow.
|
67
|
+
*
|
68
|
+
* @param client - Client to use
|
69
|
+
* @param parameters - {@link BuildProveWithdrawalParameters}
|
70
|
+
* @returns The prove withdraw transaction request. {@link BuildProveWithdrawalReturnType}
|
71
|
+
*/
|
72
|
+
export async function buildProveWithdrawal<
|
73
|
+
chain extends Chain | undefined,
|
74
|
+
account extends Account | undefined,
|
75
|
+
chainOverride extends Chain | undefined = undefined,
|
76
|
+
accountOverride extends Account | Address | undefined = undefined,
|
77
|
+
>(
|
78
|
+
client: Client<Transport, chain, account>,
|
79
|
+
args: BuildProveWithdrawalParameters<
|
80
|
+
chain,
|
81
|
+
account,
|
82
|
+
chainOverride,
|
83
|
+
accountOverride
|
84
|
+
>,
|
85
|
+
): Promise<
|
86
|
+
BuildProveWithdrawalReturnType<chain, account, chainOverride, accountOverride>
|
87
|
+
> {
|
88
|
+
const { account, chain = client.chain, output, withdrawal } = args;
|
89
|
+
|
90
|
+
const { withdrawalHash } = withdrawal;
|
91
|
+
const { l2BlockNumber } = output;
|
92
|
+
|
93
|
+
const slot = getWithdrawalHashStorageSlot({ withdrawalHash });
|
94
|
+
const [proof, block] = await Promise.all([
|
95
|
+
getProof(client, {
|
96
|
+
address: contracts.l2ToL1MessagePasser.address,
|
97
|
+
storageKeys: [slot],
|
98
|
+
blockNumber: l2BlockNumber,
|
99
|
+
}),
|
100
|
+
getBlock(client, {
|
101
|
+
blockNumber: l2BlockNumber,
|
102
|
+
}),
|
103
|
+
]);
|
104
|
+
|
105
|
+
return {
|
106
|
+
account,
|
107
|
+
l2OutputIndex: output?.outputIndex,
|
108
|
+
outputRootProof: {
|
109
|
+
latestBlockhash: block.hash,
|
110
|
+
messagePasserStorageRoot: proof.storageHash,
|
111
|
+
stateRoot: block.stateRoot,
|
112
|
+
version: outputRootProofVersion,
|
113
|
+
},
|
114
|
+
targetChain: chain,
|
115
|
+
withdrawalProof: maybeAddProofNode(
|
116
|
+
keccak256(slot),
|
117
|
+
proof.storageProof[0].proof,
|
118
|
+
),
|
119
|
+
withdrawal,
|
120
|
+
} as unknown as BuildProveWithdrawalReturnType<
|
121
|
+
chain,
|
122
|
+
account,
|
123
|
+
chainOverride,
|
124
|
+
accountOverride
|
125
|
+
>;
|
126
|
+
}
|
127
|
+
|
128
|
+
/** @internal */
|
129
|
+
export function maybeAddProofNode(key: string, proof: readonly Hex[]) {
|
130
|
+
const lastProofRlp = proof[proof.length - 1];
|
131
|
+
const lastProof = fromRlp(lastProofRlp);
|
132
|
+
if (lastProof.length !== 17) return proof;
|
133
|
+
|
134
|
+
const modifiedProof = [...proof];
|
135
|
+
for (const item of lastProof) {
|
136
|
+
// Find any nodes located inside of the branch node.
|
137
|
+
if (!Array.isArray(item)) continue;
|
138
|
+
// Check if the key inside the node matches the key we're looking for. We remove the first
|
139
|
+
// two characters (0x) and then we remove one more character (the first nibble) since this
|
140
|
+
// is the identifier for the type of node we're looking at. In this case we don't actually
|
141
|
+
// care what type of node it is because a branch node would only ever be the final proof
|
142
|
+
// element if (1) it includes the leaf node we're looking for or (2) it stores the value
|
143
|
+
// within itself. If (1) then this logic will work, if (2) then this won't find anything
|
144
|
+
// and we won't append any proof elements, which is exactly what we would want.
|
145
|
+
const suffix = item[0].slice(3);
|
146
|
+
if (typeof suffix !== "string" || !key.endsWith(suffix)) continue;
|
147
|
+
modifiedProof.push(toRlp(item));
|
148
|
+
}
|
149
|
+
return modifiedProof;
|
150
|
+
}
|
@@ -0,0 +1,103 @@
|
|
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 { l1StandardBridge } 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 { DepositERC20Request } from "../types/deposit.js";
|
18
|
+
import { parseDepositRequest } from "../utils/parseDepositRequest.js";
|
19
|
+
|
20
|
+
export type DepositERC20Parameters<
|
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, "l1StandardBridge"> & {
|
41
|
+
/** L2 transaction request. */
|
42
|
+
request: DepositERC20Request;
|
43
|
+
/**
|
44
|
+
* Gas limit for transaction execution on the L1.
|
45
|
+
*/
|
46
|
+
gas?: bigint | undefined;
|
47
|
+
};
|
48
|
+
export type DepositERC20ReturnType = Hash;
|
49
|
+
export type DepositERC20ErrorType = WriteContractErrorType | ErrorType;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @param client - Client to use
|
53
|
+
* @param parameters - {@link DepositERC20Parameters}
|
54
|
+
* @returns The L1 transaction hash. {@link DepositERC20ReturnType}
|
55
|
+
*/
|
56
|
+
export async function depositERC20<
|
57
|
+
chain extends Chain | undefined,
|
58
|
+
account extends Account | undefined,
|
59
|
+
chainOverride extends Chain | undefined = undefined,
|
60
|
+
>(
|
61
|
+
client: Client<Transport, chain, account>,
|
62
|
+
parameters: DepositERC20Parameters<chain, account, chainOverride>,
|
63
|
+
) {
|
64
|
+
const {
|
65
|
+
account,
|
66
|
+
chain = client.chain,
|
67
|
+
gas,
|
68
|
+
maxFeePerGas,
|
69
|
+
maxPriorityFeePerGas,
|
70
|
+
nonce,
|
71
|
+
request: { l1Token, l2Token, amount, to },
|
72
|
+
targetChain,
|
73
|
+
} = parameters;
|
74
|
+
|
75
|
+
const l1StandardBridgeAddress = (() => {
|
76
|
+
if (parameters.l1StandardBridgeAddress) {
|
77
|
+
return parameters.l1StandardBridgeAddress;
|
78
|
+
}
|
79
|
+
if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
|
80
|
+
return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
|
81
|
+
})();
|
82
|
+
|
83
|
+
const { functionName, args } = parseDepositRequest({
|
84
|
+
type: "erc20",
|
85
|
+
l1Token,
|
86
|
+
l2Token,
|
87
|
+
amount,
|
88
|
+
to,
|
89
|
+
});
|
90
|
+
|
91
|
+
return writeContract(client, {
|
92
|
+
account: account!,
|
93
|
+
abi: l1StandardBridge,
|
94
|
+
address: l1StandardBridgeAddress,
|
95
|
+
chain,
|
96
|
+
functionName,
|
97
|
+
args,
|
98
|
+
maxFeePerGas,
|
99
|
+
maxPriorityFeePerGas,
|
100
|
+
nonce,
|
101
|
+
gas,
|
102
|
+
} satisfies WriteContractParameters as any);
|
103
|
+
}
|
@@ -0,0 +1,102 @@
|
|
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 { l1StandardBridge } 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 { DepositETHRequest } from "../types/deposit.js";
|
18
|
+
import { parseDepositRequest } from "../utils/parseDepositRequest.js";
|
19
|
+
|
20
|
+
export type DepositETHParameters<
|
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, "l1StandardBridge"> & {
|
41
|
+
/** L2 transaction request. */
|
42
|
+
request: DepositETHRequest;
|
43
|
+
/**
|
44
|
+
* Gas limit for transaction execution on the L1.
|
45
|
+
*/
|
46
|
+
gas?: bigint | undefined;
|
47
|
+
};
|
48
|
+
export type DepositETHReturnType = Hash;
|
49
|
+
export type DepositETHErrorType = WriteContractErrorType | ErrorType;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @param client - Client to use
|
53
|
+
* @param parameters - {@link DepositERC20Parameters}
|
54
|
+
* @returns The L1 transaction hash. {@link DepositERC20ReturnType}
|
55
|
+
*/
|
56
|
+
export async function depositETH<
|
57
|
+
chain extends Chain | undefined,
|
58
|
+
account extends Account | undefined,
|
59
|
+
chainOverride extends Chain | undefined = undefined,
|
60
|
+
>(
|
61
|
+
client: Client<Transport, chain, account>,
|
62
|
+
parameters: DepositETHParameters<chain, account, chainOverride>,
|
63
|
+
) {
|
64
|
+
const {
|
65
|
+
account,
|
66
|
+
chain = client.chain,
|
67
|
+
gas,
|
68
|
+
maxFeePerGas,
|
69
|
+
maxPriorityFeePerGas,
|
70
|
+
nonce,
|
71
|
+
request: { amount, to },
|
72
|
+
targetChain,
|
73
|
+
} = parameters;
|
74
|
+
|
75
|
+
const l1StandardBridgeAddress = (() => {
|
76
|
+
if (parameters.l1StandardBridgeAddress) {
|
77
|
+
return parameters.l1StandardBridgeAddress;
|
78
|
+
}
|
79
|
+
if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
|
80
|
+
return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
|
81
|
+
})();
|
82
|
+
|
83
|
+
const { functionName, args } = parseDepositRequest({
|
84
|
+
type: "eth",
|
85
|
+
amount,
|
86
|
+
to,
|
87
|
+
});
|
88
|
+
|
89
|
+
return writeContract(client, {
|
90
|
+
account: account!,
|
91
|
+
abi: l1StandardBridge,
|
92
|
+
address: l1StandardBridgeAddress,
|
93
|
+
chain,
|
94
|
+
functionName,
|
95
|
+
args,
|
96
|
+
maxFeePerGas,
|
97
|
+
maxPriorityFeePerGas,
|
98
|
+
nonce,
|
99
|
+
gas,
|
100
|
+
value: amount,
|
101
|
+
} satisfies WriteContractParameters as any);
|
102
|
+
}
|
@@ -0,0 +1,101 @@
|
|
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 { l1StandardBridge } 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 { DepositMNTRequest } from "../types/deposit.js";
|
18
|
+
import { parseDepositRequest } from "../utils/parseDepositRequest.js";
|
19
|
+
|
20
|
+
export type DepositMNTParameters<
|
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, "l1StandardBridge"> & {
|
41
|
+
/** L2 transaction request. */
|
42
|
+
request: DepositMNTRequest;
|
43
|
+
/**
|
44
|
+
* Gas limit for transaction execution on the L1.
|
45
|
+
*/
|
46
|
+
gas?: bigint | undefined;
|
47
|
+
};
|
48
|
+
export type DepositMNTReturnType = Hash;
|
49
|
+
export type DepositMNTErrorType = WriteContractErrorType | ErrorType;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @param client - Client to use
|
53
|
+
* @param parameters - {@link DepositMNTParameters}
|
54
|
+
* @returns The L1 transaction hash. {@link DepositMNTReturnType}
|
55
|
+
*/
|
56
|
+
export async function depositMNT<
|
57
|
+
chain extends Chain | undefined,
|
58
|
+
account extends Account | undefined,
|
59
|
+
chainOverride extends Chain | undefined = undefined,
|
60
|
+
>(
|
61
|
+
client: Client<Transport, chain, account>,
|
62
|
+
parameters: DepositMNTParameters<chain, account, chainOverride>,
|
63
|
+
) {
|
64
|
+
const {
|
65
|
+
account,
|
66
|
+
chain = client.chain,
|
67
|
+
gas,
|
68
|
+
maxFeePerGas,
|
69
|
+
maxPriorityFeePerGas,
|
70
|
+
nonce,
|
71
|
+
request: { amount, to },
|
72
|
+
targetChain,
|
73
|
+
} = parameters;
|
74
|
+
|
75
|
+
const l1StandardBridgeAddress = (() => {
|
76
|
+
if (parameters.l1StandardBridgeAddress) {
|
77
|
+
return parameters.l1StandardBridgeAddress;
|
78
|
+
}
|
79
|
+
if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
|
80
|
+
return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
|
81
|
+
})();
|
82
|
+
|
83
|
+
const { functionName, args } = parseDepositRequest({
|
84
|
+
type: "mnt",
|
85
|
+
amount,
|
86
|
+
to,
|
87
|
+
});
|
88
|
+
|
89
|
+
return writeContract(client, {
|
90
|
+
account: account!,
|
91
|
+
abi: l1StandardBridge,
|
92
|
+
address: l1StandardBridgeAddress,
|
93
|
+
chain,
|
94
|
+
functionName,
|
95
|
+
args,
|
96
|
+
maxFeePerGas,
|
97
|
+
maxPriorityFeePerGas,
|
98
|
+
nonce,
|
99
|
+
gas,
|
100
|
+
} satisfies WriteContractParameters as any);
|
101
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import type { Address } from "viem";
|
2
|
+
|
3
|
+
import type { Client, Transport } from "viem";
|
4
|
+
import type { Account } from "viem";
|
5
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
6
|
+
import type { UnionEvaluate, UnionOmit } from "viem";
|
7
|
+
import {
|
8
|
+
estimateContractGas,
|
9
|
+
type EstimateContractGasErrorType,
|
10
|
+
type EstimateContractGasParameters,
|
11
|
+
} from "viem/actions";
|
12
|
+
import type { FormattedTransactionRequest } from "viem/utils";
|
13
|
+
import { l1StandardBridge } 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 { DepositERC20Request } from "../types/deposit.js";
|
18
|
+
import { parseDepositRequest } from "../utils/parseDepositRequest.js";
|
19
|
+
|
20
|
+
export type EstimateDepositERC20GasParameters<
|
21
|
+
chain extends Chain | undefined = Chain | undefined,
|
22
|
+
account extends Account | undefined = Account | undefined,
|
23
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
24
|
+
///
|
25
|
+
derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
26
|
+
> = UnionEvaluate<
|
27
|
+
UnionOmit<
|
28
|
+
FormattedTransactionRequest<derivedChain>,
|
29
|
+
| "accessList"
|
30
|
+
| "data"
|
31
|
+
| "from"
|
32
|
+
| "gas"
|
33
|
+
| "gasPrice"
|
34
|
+
| "to"
|
35
|
+
| "type"
|
36
|
+
| "value"
|
37
|
+
>
|
38
|
+
> &
|
39
|
+
GetAccountParameter<account, Account | Address> &
|
40
|
+
GetChainParameter<chain, chainOverride> &
|
41
|
+
GetContractAddressParameter<derivedChain, "l1StandardBridge"> & {
|
42
|
+
/** L2 transaction request. */
|
43
|
+
request: DepositERC20Request;
|
44
|
+
/** Gas limit for transaction execution on the L1. */
|
45
|
+
gas?: bigint | undefined;
|
46
|
+
};
|
47
|
+
|
48
|
+
export type EstimateDepositERC20GasReturnType = bigint;
|
49
|
+
|
50
|
+
export type EstimateDepositERC20GasErrorType =
|
51
|
+
| EstimateContractGasErrorType
|
52
|
+
| ErrorType;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @param client - Client to use
|
56
|
+
* @param parameters - {@link EstimateDepositERC20GasParameters}
|
57
|
+
* @returns The L1 transaction hash. {@link EstimateDepositERC20GasReturnType}
|
58
|
+
*/
|
59
|
+
export async function estimateDepositERC20Gas<
|
60
|
+
chain extends Chain | undefined,
|
61
|
+
account extends Account | undefined,
|
62
|
+
chainOverride extends Chain | undefined = undefined,
|
63
|
+
>(
|
64
|
+
client: Client<Transport, chain, account>,
|
65
|
+
parameters: EstimateDepositERC20GasParameters<chain, account, chainOverride>,
|
66
|
+
) {
|
67
|
+
const {
|
68
|
+
account,
|
69
|
+
chain = client.chain,
|
70
|
+
gas,
|
71
|
+
maxFeePerGas,
|
72
|
+
maxPriorityFeePerGas,
|
73
|
+
nonce,
|
74
|
+
request: { l1Token, l2Token, amount, to },
|
75
|
+
targetChain,
|
76
|
+
} = parameters;
|
77
|
+
|
78
|
+
const l1StandardBridgeAddress = (() => {
|
79
|
+
if (parameters.l1StandardBridgeAddress) {
|
80
|
+
return parameters.l1StandardBridgeAddress;
|
81
|
+
}
|
82
|
+
if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
|
83
|
+
return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
|
84
|
+
})();
|
85
|
+
|
86
|
+
const { functionName, args } = parseDepositRequest({
|
87
|
+
type: "erc20",
|
88
|
+
l1Token,
|
89
|
+
l2Token,
|
90
|
+
amount,
|
91
|
+
to,
|
92
|
+
});
|
93
|
+
|
94
|
+
const params = {
|
95
|
+
account,
|
96
|
+
abi: l1StandardBridge,
|
97
|
+
address: l1StandardBridgeAddress,
|
98
|
+
functionName,
|
99
|
+
args,
|
100
|
+
gas,
|
101
|
+
maxFeePerGas,
|
102
|
+
maxPriorityFeePerGas,
|
103
|
+
nonce,
|
104
|
+
// TODO: Not sure `chain` is necessary since it's not used downstream
|
105
|
+
// in `estimateContractGas` or `estimateGas`
|
106
|
+
// @ts-ignore
|
107
|
+
chain,
|
108
|
+
} satisfies EstimateContractGasParameters<
|
109
|
+
typeof l1StandardBridge,
|
110
|
+
typeof functionName
|
111
|
+
>;
|
112
|
+
return estimateContractGas(client, params as any);
|
113
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import type { Address } from "viem";
|
2
|
+
|
3
|
+
import type { Client, Transport } from "viem";
|
4
|
+
import type { Account } from "viem";
|
5
|
+
import type { Chain, DeriveChain, GetChainParameter } from "viem";
|
6
|
+
import type { UnionEvaluate, UnionOmit } from "viem";
|
7
|
+
import {
|
8
|
+
estimateContractGas,
|
9
|
+
type EstimateContractGasErrorType,
|
10
|
+
type EstimateContractGasParameters,
|
11
|
+
} from "viem/actions";
|
12
|
+
import type { FormattedTransactionRequest } from "viem/utils";
|
13
|
+
import { l1StandardBridge } 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 { DepositETHRequest } from "../types/deposit.js";
|
18
|
+
import { parseDepositRequest } from "../utils/parseDepositRequest.js";
|
19
|
+
|
20
|
+
export type EstimateDepositETHGasParameters<
|
21
|
+
chain extends Chain | undefined = Chain | undefined,
|
22
|
+
account extends Account | undefined = Account | undefined,
|
23
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
24
|
+
///
|
25
|
+
derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
|
26
|
+
> = UnionEvaluate<
|
27
|
+
UnionOmit<
|
28
|
+
FormattedTransactionRequest<derivedChain>,
|
29
|
+
| "accessList"
|
30
|
+
| "data"
|
31
|
+
| "from"
|
32
|
+
| "gas"
|
33
|
+
| "gasPrice"
|
34
|
+
| "to"
|
35
|
+
| "type"
|
36
|
+
| "value"
|
37
|
+
>
|
38
|
+
> &
|
39
|
+
GetAccountParameter<account, Account | Address> &
|
40
|
+
GetChainParameter<chain, chainOverride> &
|
41
|
+
GetContractAddressParameter<derivedChain, "l1StandardBridge"> & {
|
42
|
+
/** L2 transaction request. */
|
43
|
+
request: DepositETHRequest;
|
44
|
+
/** Gas limit for transaction execution on the L1. */
|
45
|
+
gas?: bigint | undefined;
|
46
|
+
};
|
47
|
+
|
48
|
+
export type EstimateDepositETHGasReturnType = bigint;
|
49
|
+
|
50
|
+
export type EstimateDepositETHGasErrorType =
|
51
|
+
| EstimateContractGasErrorType
|
52
|
+
| ErrorType;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @param client - Client to use
|
56
|
+
* @param parameters - {@link EstimateDepositETHGasParameters}
|
57
|
+
* @returns The L1 transaction hash. {@link EstimateDepositETHGasReturnType}
|
58
|
+
*/
|
59
|
+
export async function estimateDepositETHGas<
|
60
|
+
chain extends Chain | undefined,
|
61
|
+
account extends Account | undefined,
|
62
|
+
chainOverride extends Chain | undefined = undefined,
|
63
|
+
>(
|
64
|
+
client: Client<Transport, chain, account>,
|
65
|
+
parameters: EstimateDepositETHGasParameters<chain, account, chainOverride>,
|
66
|
+
) {
|
67
|
+
const {
|
68
|
+
account,
|
69
|
+
chain = client.chain,
|
70
|
+
gas,
|
71
|
+
maxFeePerGas,
|
72
|
+
maxPriorityFeePerGas,
|
73
|
+
nonce,
|
74
|
+
request: { amount, to },
|
75
|
+
targetChain,
|
76
|
+
} = parameters;
|
77
|
+
|
78
|
+
const l1StandardBridgeAddress = (() => {
|
79
|
+
if (parameters.l1StandardBridgeAddress) {
|
80
|
+
return parameters.l1StandardBridgeAddress;
|
81
|
+
}
|
82
|
+
if (chain) return targetChain!.contracts.l1StandardBridge[chain.id].address;
|
83
|
+
return Object.values(targetChain!.contracts.l1StandardBridge)[0].address;
|
84
|
+
})();
|
85
|
+
|
86
|
+
const { functionName, args } = parseDepositRequest({
|
87
|
+
type: "eth",
|
88
|
+
amount,
|
89
|
+
to,
|
90
|
+
});
|
91
|
+
|
92
|
+
const params = {
|
93
|
+
account,
|
94
|
+
abi: l1StandardBridge,
|
95
|
+
address: l1StandardBridgeAddress,
|
96
|
+
functionName,
|
97
|
+
args,
|
98
|
+
gas,
|
99
|
+
maxFeePerGas,
|
100
|
+
maxPriorityFeePerGas,
|
101
|
+
nonce,
|
102
|
+
// TODO: Not sure `chain` is necessary since it's not used downstream
|
103
|
+
// in `estimateContractGas` or `estimateGas`
|
104
|
+
// @ts-ignore
|
105
|
+
chain,
|
106
|
+
// @ts-ignore
|
107
|
+
value: amount,
|
108
|
+
} satisfies EstimateContractGasParameters<
|
109
|
+
typeof l1StandardBridge,
|
110
|
+
typeof functionName
|
111
|
+
>;
|
112
|
+
return estimateContractGas(client, params as any);
|
113
|
+
}
|