From a5e69bc632733d08087e9fcdcba21199fb1cc6d1 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 14:20:17 -0400 Subject: [PATCH 01/12] deposit erc20 v2 --- package.json | 2 +- pnpm-lock.yaml | 72 ++++++++++++++---- src/actions/public/L1/simulateDepositERC20.ts | 75 ++++++++++++++++--- src/actions/wallet/L1/writeDepositERC20.ts | 11 ++- src/types/l1Actions.ts | 26 ++++++- 5 files changed, 156 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 9a05665b..c0a79a9e 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,7 @@ }, "peerDependencies": { "typescript": ">=5.0.4", - "viem": "1.x" + "viem": "2.0.0-alpha.17" }, "peerDependenciesMeta": { "typescript": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9a9fe909..4f5fe35f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -15,8 +15,8 @@ importers: specifier: ^0.15.0 version: 0.15.0(typescript@5.0.4)(wagmi@1.4.1) viem: - specifier: 1.x - version: 1.10.9(typescript@5.0.4)(zod@3.22.2) + specifier: 2.0.0-alpha.17 + version: 2.0.0-alpha.17(typescript@5.0.4) devDependencies: '@biomejs/biome': specifier: 1.0.0 @@ -83,7 +83,7 @@ importers: version: 0.34.4 wagmi: specifier: ^1.3.11 - version: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@1.10.9) + version: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) site: devDependencies: @@ -1104,7 +1104,7 @@ packages: react: 18.2.0 react-dom: 18.2.0(react@18.2.0) viem: 1.10.9(typescript@5.0.4)(zod@3.22.2) - wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@1.10.9) + wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) transitivePeerDependencies: - bufferutil - typescript @@ -1775,7 +1775,7 @@ packages: resolution: {integrity: sha512-osvveYtyzdEVbt3OfwwXFr4P2iVBL5u1Q3q4ONBfDY/UpOuXmOlbgwc1xECEboY8wIays8Yt6onaWMUdUbfl0A==} dependencies: '@noble/curves': 1.1.0 - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 '@scure/base': 1.1.3 dev: true @@ -2416,14 +2416,14 @@ packages: prettier: 2.8.8 typescript: 5.0.4 viem: 1.10.9(typescript@5.0.4)(zod@3.22.2) - wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@1.10.9) + wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) zod: 3.22.2 transitivePeerDependencies: - bufferutil - utf-8-validate dev: true - /@wagmi/connectors@3.1.1(react@18.2.0)(typescript@5.0.4)(viem@1.10.9): + /@wagmi/connectors@3.1.1(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17): resolution: {integrity: sha512-ewOV40AlrXcX018qckU0V9OCsDgHhs+KZjQJZhlplqRtc2ijjS62B5kcypXkcTtfU5qXUBA9KEwPsSTxGdT4ag==} peerDependencies: typescript: '>=5.0.4' @@ -2443,7 +2443,7 @@ packages: abitype: 0.8.7(typescript@5.0.4)(zod@3.22.2) eventemitter3: 4.0.7 typescript: 5.0.4 - viem: 1.10.9(typescript@5.0.4)(zod@3.22.2) + viem: 2.0.0-alpha.17(typescript@5.0.4) transitivePeerDependencies: - '@react-native-async-storage/async-storage' - bufferutil @@ -2454,7 +2454,7 @@ packages: - utf-8-validate - zod - /@wagmi/core@1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@1.10.9): + /@wagmi/core@1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17): resolution: {integrity: sha512-b6LDFL0vZSCNcIHjnJzv++hakavTTt1/2WEQg2S5eEnaHTp7UoQlwfCyjKeiBhRih4yF34N06ea8cyEVjyjXrw==} peerDependencies: typescript: '>=5.0.4' @@ -2463,11 +2463,11 @@ packages: typescript: optional: true dependencies: - '@wagmi/connectors': 3.1.1(react@18.2.0)(typescript@5.0.4)(viem@1.10.9) + '@wagmi/connectors': 3.1.1(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) abitype: 0.8.7(typescript@5.0.4)(zod@3.22.2) eventemitter3: 4.0.7 typescript: 5.0.4 - viem: 1.10.9(typescript@5.0.4)(zod@3.22.2) + viem: 2.0.0-alpha.17(typescript@5.0.4) zustand: 4.4.1(@types/react@18.2.21)(react@18.2.0) transitivePeerDependencies: - '@react-native-async-storage/async-storage' @@ -2828,6 +2828,19 @@ packages: jsonparse: 1.3.1 through: 2.3.8 + /abitype@0.10.0(typescript@5.0.4): + resolution: {integrity: sha512-QvMHEUzgI9nPj9TWtUGnS2scas80/qaL5PBxGdwWhhvzqXfOph+IEiiiWrzuisu3U3JgDQVruW9oLbJoQ3oZ3A==} + peerDependencies: + typescript: '>=5.0.4' + zod: ^3 >=3.22.0 + peerDependenciesMeta: + typescript: + optional: true + zod: + optional: true + dependencies: + typescript: 5.0.4 + /abitype@0.8.7(typescript@5.0.4)(zod@3.22.2): resolution: {integrity: sha512-wQ7hV8Yg/yKmGyFpqrNZufCxbszDe5es4AZGYPBitocfSqXtjrTG9JMWFcc4N30ukl2ve48aBTwt7NJxVQdU3w==} peerDependencies: @@ -4600,6 +4613,13 @@ packages: dependencies: ws: 8.13.0 + /isows@1.0.3(ws@8.13.0): + resolution: {integrity: sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg==} + peerDependencies: + ws: '*' + dependencies: + ws: 8.13.0 + /istanbul-lib-coverage@3.2.0: resolution: {integrity: sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==} engines: {node: '>=8'} @@ -6354,6 +6374,28 @@ packages: - utf-8-validate - zod + /viem@2.0.0-alpha.17(typescript@5.0.4): + resolution: {integrity: sha512-oxC8mWdrcBMDHQHAzCGIPwOJ4ceyInbojj1aDxfEfITI+IVhDq6VxtxCJuM4DbcKq74uogs6GkXkyOlcPIovbg==} + peerDependencies: + typescript: '>=5.0.4' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@adraffy/ens-normalize': 1.9.4 + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@scure/bip32': 1.3.2 + '@scure/bip39': 1.2.1 + abitype: 0.10.0(typescript@5.0.4) + isows: 1.0.3(ws@8.13.0) + typescript: 5.0.4 + ws: 8.13.0 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + - zod + /vite-node@0.34.4(@types/node@20.6.0): resolution: {integrity: sha512-ho8HtiLc+nsmbwZMw8SlghESEE3KxJNp04F/jPUCLVvaURwt0d+r9LxEqCX5hvrrOQ0GSyxbYr5ZfRYhQ0yVKQ==} engines: {node: '>=v14.18.0'} @@ -6589,7 +6631,7 @@ packages: '@vue/shared': 3.3.4 dev: true - /wagmi@1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@1.10.9): + /wagmi@1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17): resolution: {integrity: sha512-v3xd+uYZfLCAs1I4fLU7U9hg/gCw+Ud005J7kNR0mi20BcFAEU1EDN1LxHxpjUV0qKhOzSlMlrLjJyBCmSYhFA==} peerDependencies: react: '>=17.0.0' @@ -6602,12 +6644,12 @@ packages: '@tanstack/query-sync-storage-persister': 4.35.0 '@tanstack/react-query': 4.35.0(react-dom@18.2.0)(react@18.2.0) '@tanstack/react-query-persist-client': 4.35.0(@tanstack/react-query@4.35.0) - '@wagmi/core': 1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@1.10.9) + '@wagmi/core': 1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) abitype: 0.8.7(typescript@5.0.4)(zod@3.22.2) react: 18.2.0 typescript: 5.0.4 use-sync-external-store: 1.2.0(react@18.2.0) - viem: 1.10.9(typescript@5.0.4)(zod@3.22.2) + viem: 2.0.0-alpha.17(typescript@5.0.4) transitivePeerDependencies: - '@react-native-async-storage/async-storage' - '@types/react' diff --git a/src/actions/public/L1/simulateDepositERC20.ts b/src/actions/public/L1/simulateDepositERC20.ts index 4e7d715e..7bb98d24 100644 --- a/src/actions/public/L1/simulateDepositERC20.ts +++ b/src/actions/public/L1/simulateDepositERC20.ts @@ -1,4 +1,13 @@ -import type { Chain, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport } from 'viem' +import type { + Account, + Address, + Chain, + ContractFunctionArgs, + PublicClient, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from 'viem' import { simulateContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { ABI, type DepositERC20Parameters, FUNCTION } from '../../../types/depositERC20.js' @@ -7,15 +16,36 @@ import type { L1SimulateActionBaseType } from '../../../types/l1Actions.js' export type SimulateDepositERC20Parameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositERC20Parameters; l1StandardBridge: RawOrContractAddress<_chainId> } - & L1SimulateActionBaseType + & L1SimulateActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride, + TAccountOverride + > export type SimulateDepositERC20ReturnType< - TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, -> = SimulateContractReturnType + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, + TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = + | Account + | Address + | undefined, +> = SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride +> /** * Simulates a deposit of ERC20 tokens to L2 @@ -24,20 +54,47 @@ export type SimulateDepositERC20ReturnType< */ export async function simulateDepositERC20< TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TAccount extends Account | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( client: PublicClient, { args: { l1Token, l2Token, to, amount, minGasLimit, extraData = '0x' }, l1StandardBridge, ...rest - }: SimulateDepositERC20Parameters, -): Promise> { + }: SimulateDepositERC20Parameters, +): Promise< + SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > +> { return simulateContract(client, { address: resolveAddress(l1StandardBridge), abi: ABI, functionName: FUNCTION, args: [l1Token, l2Token, to, amount, minGasLimit, extraData], ...rest, - } as unknown as SimulateContractParameters) + } as unknown as SimulateContractParameters< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride, + TAccountOverride + >) as unknown as SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > } diff --git a/src/actions/wallet/L1/writeDepositERC20.ts b/src/actions/wallet/L1/writeDepositERC20.ts index a5b9a8fa..54a2cf73 100644 --- a/src/actions/wallet/L1/writeDepositERC20.ts +++ b/src/actions/wallet/L1/writeDepositERC20.ts @@ -1,4 +1,12 @@ -import type { Account, Chain, Transport, WalletClient, WriteContractParameters, WriteContractReturnType } from 'viem' +import type { + Account, + Chain, + ContractFunctionArgs, + Transport, + WalletClient, + WriteContractParameters, + WriteContractReturnType, +} from 'viem' import { writeContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { ABI, type DepositERC20Parameters, FUNCTION } from '../../../types/depositERC20.js' @@ -47,6 +55,7 @@ export async function writeDepositERC20< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/types/l1Actions.ts b/src/types/l1Actions.ts index fef14e12..22fee5f7 100644 --- a/src/types/l1Actions.ts +++ b/src/types/l1Actions.ts @@ -1,4 +1,13 @@ -import type { Abi, Account, Chain, SendTransactionParameters, SimulateContractParameters } from 'viem' +import type { + Abi, + Account, + Address, + Chain, + ContractFunctionArgs, + ContractFunctionName, + SendTransactionParameters, + SimulateContractParameters, +} from 'viem' export type L1WriteActionBaseType< TChain extends Chain | undefined = Chain, @@ -14,11 +23,20 @@ export type L1WriteActionBaseType< > export type L1SimulateActionBaseType< + TAbi extends Abi | readonly unknown[] = Abi, + TFunctioName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + > = ContractFunctionName, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + TFunctioName + > = ContractFunctionArgs, TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, - TAbi extends Abi | readonly unknown[] = Abi, - TFunctioName extends string = string, + TAccountOverride extends Account | Address | undefined = undefined, > = Omit< - SimulateContractParameters, + SimulateContractParameters, 'abi' | 'functionName' | 'args' | 'address' > From a91cbbee1437e2193a01add6ac78fad4231d66c2 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:12:58 -0400 Subject: [PATCH 02/12] migrate L1 wallet actions to v2 --- src/actions/wallet/L1/writeContractDeposit.ts | 26 ++++++++++++++++--- .../wallet/L1/writeDepositTransaction.ts | 6 +++++ .../L1/writeFinalizeWithdrawalTransaction.ts | 15 ++++++++++- .../L1/writeProveWithdrawalTransaction.ts | 15 ++++++++++- src/actions/wallet/L1/writeSendMessage.ts | 6 +++++ 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/actions/wallet/L1/writeContractDeposit.ts b/src/actions/wallet/L1/writeContractDeposit.ts index 4ec49a8e..89baf4f0 100644 --- a/src/actions/wallet/L1/writeContractDeposit.ts +++ b/src/actions/wallet/L1/writeContractDeposit.ts @@ -3,6 +3,8 @@ import { type Account, type Address, type Chain, + type ContractFunctionArgs, + type ContractFunctionName, encodeFunctionData, type EncodeFunctionDataParameters, type Transport, @@ -17,7 +19,15 @@ import { writeDepositTransaction, type WriteDepositTransactionParameters } from export type WriteContractDepositParameters< TAbi extends Abi | readonly unknown[] = Abi, - TFunctionName extends string = string, + TFunctionName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + > = ContractFunctionName, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + TFunctionName + > = ContractFunctionArgs, TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, @@ -34,6 +44,7 @@ export type WriteContractDepositParameters< WriteContractParameters< TAbi, TFunctionName, + TArgs, TChain, TAccount, TChainOverride @@ -56,7 +67,15 @@ export async function writeContractDeposit< TChain extends Chain | undefined, TAccount extends Account | undefined, const TAbi extends Abi | readonly unknown[], - TFunctionName extends string, + TFunctionName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + >, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + TFunctionName + >, TChainOverride extends Chain | undefined, >( client: WalletClient, @@ -74,6 +93,7 @@ export async function writeContractDeposit< }: WriteContractDepositParameters< TAbi, TFunctionName, + TArgs, TChain, TAccount, TChainOverride @@ -83,7 +103,7 @@ export async function writeContractDeposit< abi, args, functionName, - } as unknown as EncodeFunctionDataParameters) + } as unknown as EncodeFunctionDataParameters>) if (!account_) { throw new Error('No account found') } diff --git a/src/actions/wallet/L1/writeDepositTransaction.ts b/src/actions/wallet/L1/writeDepositTransaction.ts index 0bcc693f..6b97e5ba 100644 --- a/src/actions/wallet/L1/writeDepositTransaction.ts +++ b/src/actions/wallet/L1/writeDepositTransaction.ts @@ -3,6 +3,7 @@ import type { Account, Address, Chain, + ContractFunctionArgs, Hex, Transport, WalletClient, @@ -82,6 +83,11 @@ export async function writeDepositTransaction< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs< + typeof ABI, + 'payable', + typeof FUNCTION + >, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts index 13f1ce3c..a3b86b15 100644 --- a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts +++ b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts @@ -1,5 +1,13 @@ import { optimismPortalABI } from '@eth-optimism/contracts-ts' -import type { Account, Chain, Transport, WalletClient, WriteContractParameters, WriteContractReturnType } from 'viem' +import type { + Account, + Chain, + ContractFunctionArgs, + Transport, + WalletClient, + WriteContractParameters, + WriteContractReturnType, +} from 'viem' import { writeContract } from 'viem/actions' import type { _ } from 'vitest/dist/reporters-cb94c88b.js' import type { MessagePassedEvent } from '../../../index.js' @@ -56,6 +64,11 @@ export async function writeFinalizeWithdrawalTranasction< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs< + typeof ABI, + 'nonpayable', + typeof FUNCTION + >, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts b/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts index 6d202762..be412c22 100644 --- a/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts +++ b/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts @@ -1,5 +1,13 @@ import { optimismPortalABI } from '@eth-optimism/contracts-ts' -import type { Account, Chain, Transport, WalletClient, WriteContractParameters, WriteContractReturnType } from 'viem' +import type { + Account, + Chain, + ContractFunctionArgs, + Transport, + WalletClient, + WriteContractParameters, + WriteContractReturnType, +} from 'viem' import { writeContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import type { L1WriteActionBaseType } from '../../../types/l1Actions.js' @@ -55,6 +63,11 @@ export async function writeProveWithdrawalTransaction< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs< + typeof ABI, + 'nonpayable', + typeof FUNCTION + >, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L1/writeSendMessage.ts b/src/actions/wallet/L1/writeSendMessage.ts index 1abaa8d2..0f8a1c2b 100644 --- a/src/actions/wallet/L1/writeSendMessage.ts +++ b/src/actions/wallet/L1/writeSendMessage.ts @@ -3,6 +3,7 @@ import type { Account, Address, Chain, + ContractFunctionArgs, Hex, Transport, WalletClient, @@ -67,6 +68,11 @@ export async function writeSendMessage< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs< + typeof ABI, + 'payable', + typeof FUNCTION + >, TChain, TAccount, TChainOverride From 6a210fb6129b4930a0df048e594758917102caf7 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:13:37 -0400 Subject: [PATCH 03/12] migrate L2 wallet actions to v2 --- src/actions/wallet/L2/writeWithdrawERC20.ts | 24 +++++++++++++-- src/actions/wallet/L2/writeWithdrawETH.ts | 11 +++++-- src/types/l2Actions.ts | 34 ++++++++++++++++++--- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/actions/wallet/L2/writeWithdrawERC20.ts b/src/actions/wallet/L2/writeWithdrawERC20.ts index 05dd2abf..f6d74e8e 100644 --- a/src/actions/wallet/L2/writeWithdrawERC20.ts +++ b/src/actions/wallet/L2/writeWithdrawERC20.ts @@ -1,4 +1,12 @@ -import type { Account, Chain, Transport, WalletClient, WriteContractParameters, WriteContractReturnType } from 'viem' +import type { + Account, + Chain, + ContractFunctionArgs, + Transport, + WalletClient, + WriteContractParameters, + WriteContractReturnType, +} from 'viem' import { writeContract } from 'viem/actions' import type { L2WriteContractParameters } from '../../../types/l2Actions.js' import { opStackL2ChainContracts, OpStackL2Contract } from '../../../types/opStackContracts.js' @@ -10,7 +18,14 @@ export type WriteWithdrawERC20Parameters< TChainOverride extends Chain | undefined = Chain | undefined, > = & { args: WithdrawToParameters } - & L2WriteContractParameters + & L2WriteContractParameters< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride + > /** * Withdraws ERC20 tokens to an L1 address. @@ -44,6 +59,11 @@ export async function writeWithdrawERC20< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs< + typeof ABI, + 'payable', + typeof FUNCTION + >, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L2/writeWithdrawETH.ts b/src/actions/wallet/L2/writeWithdrawETH.ts index 18cceeb5..a8ed6b89 100644 --- a/src/actions/wallet/L2/writeWithdrawETH.ts +++ b/src/actions/wallet/L2/writeWithdrawETH.ts @@ -1,4 +1,4 @@ -import type { Account, Chain, Transport, WalletClient, WriteContractReturnType } from 'viem' +import type { Account, Chain, ContractFunctionArgs, Transport, WalletClient, WriteContractReturnType } from 'viem' import type { L2WriteContractParameters } from '../../../types/l2Actions.js' import { type ABI, type FUNCTION, OVM_ETH, type WithdrawETHParameters } from '../../../types/withdrawTo.js' import { writeWithdrawERC20, type WriteWithdrawERC20Parameters } from './writeWithdrawERC20.js' @@ -9,7 +9,14 @@ export type WriteWithdrawETHParameters< TChainOverride extends Chain | undefined = Chain | undefined, > = & { args: WithdrawETHParameters } - & L2WriteContractParameters + & L2WriteContractParameters< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride + > /** * Withdraws ETH to an L1 address. diff --git a/src/types/l2Actions.ts b/src/types/l2Actions.ts index 34feacb0..180e9cc0 100644 --- a/src/types/l2Actions.ts +++ b/src/types/l2Actions.ts @@ -1,22 +1,46 @@ -import type { Abi, Account, Chain, SimulateContractParameters, WriteContractParameters } from 'viem' +import type { + Abi, + Account, + Chain, + ContractFunctionArgs, + ContractFunctionName, + SimulateContractParameters, + WriteContractParameters, +} from 'viem' export type L2WriteContractParameters< TAbi extends Abi | readonly unknown[] = Abi, - TFunctioName extends string = string, + TFunctioName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + > = ContractFunctionName, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + TFunctioName + > = ContractFunctionArgs, TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, > = Omit< - WriteContractParameters, + WriteContractParameters, 'abi' | 'functionName' | 'args' | 'address' > export type L2SimulateContractParameters< TAbi extends Abi | readonly unknown[] = Abi, - TFunctioName extends string = string, + TFunctioName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + > = ContractFunctionName, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + TFunctioName + > = ContractFunctionArgs, TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, > = Omit< - SimulateContractParameters, + SimulateContractParameters, 'abi' | 'functionName' | 'args' | 'address' > From 466a0fb2e0bda5ec238821d76c6ccf12cef91a95 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:21:17 -0400 Subject: [PATCH 04/12] cleanup --- src/actions/public/L1/simulateDepositERC20.ts | 10 +++++----- src/actions/wallet/L1/writeDepositERC20.ts | 2 +- src/actions/wallet/L2/writeWithdrawERC20.ts | 2 +- src/actions/wallet/L2/writeWithdrawETH.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/actions/public/L1/simulateDepositERC20.ts b/src/actions/public/L1/simulateDepositERC20.ts index 7bb98d24..49f90d49 100644 --- a/src/actions/public/L1/simulateDepositERC20.ts +++ b/src/actions/public/L1/simulateDepositERC20.ts @@ -23,7 +23,7 @@ export type SimulateDepositERC20Parameters< & L1SimulateActionBaseType< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TChainOverride, TAccountOverride @@ -40,7 +40,7 @@ export type SimulateDepositERC20ReturnType< > = SimulateContractReturnType< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TAccount, TChainOverride, @@ -68,7 +68,7 @@ export async function simulateDepositERC20< SimulateContractReturnType< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TAccount, TChainOverride, @@ -84,14 +84,14 @@ export async function simulateDepositERC20< } as unknown as SimulateContractParameters< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TChainOverride, TAccountOverride >) as unknown as SimulateContractReturnType< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TAccount, TChainOverride, diff --git a/src/actions/wallet/L1/writeDepositERC20.ts b/src/actions/wallet/L1/writeDepositERC20.ts index 54a2cf73..ef4d2d78 100644 --- a/src/actions/wallet/L1/writeDepositERC20.ts +++ b/src/actions/wallet/L1/writeDepositERC20.ts @@ -55,7 +55,7 @@ export async function writeDepositERC20< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L2/writeWithdrawERC20.ts b/src/actions/wallet/L2/writeWithdrawERC20.ts index f6d74e8e..eac85c11 100644 --- a/src/actions/wallet/L2/writeWithdrawERC20.ts +++ b/src/actions/wallet/L2/writeWithdrawERC20.ts @@ -21,7 +21,7 @@ export type WriteWithdrawERC20Parameters< & L2WriteContractParameters< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L2/writeWithdrawETH.ts b/src/actions/wallet/L2/writeWithdrawETH.ts index a8ed6b89..5640f190 100644 --- a/src/actions/wallet/L2/writeWithdrawETH.ts +++ b/src/actions/wallet/L2/writeWithdrawETH.ts @@ -12,7 +12,7 @@ export type WriteWithdrawETHParameters< & L2WriteContractParameters< typeof ABI, typeof FUNCTION, - ContractFunctionArgs, + ContractFunctionArgs, TChain, TAccount, TChainOverride From 71262e72c6df6232bcee0963c59c727ba678d7a8 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:49:18 -0400 Subject: [PATCH 05/12] migrate L1 public actions to v2 --- src/actions/public/L1/simulateDepositETH.ts | 64 ++++++++++++++++--- .../public/L1/simulateDepositTransaction.ts | 55 ++++++++++++---- .../simulateFinalizeWithdrawalTransaction.ts | 55 ++++++++++++---- .../L1/simulateProveWithdrawalTransaction.ts | 55 ++++++++++++---- 4 files changed, 187 insertions(+), 42 deletions(-) diff --git a/src/actions/public/L1/simulateDepositETH.ts b/src/actions/public/L1/simulateDepositETH.ts index 5f56b47a..d32855a2 100644 --- a/src/actions/public/L1/simulateDepositETH.ts +++ b/src/actions/public/L1/simulateDepositETH.ts @@ -1,4 +1,13 @@ -import type { Chain, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport } from 'viem' +import type { + Account, + Address, + Chain, + ContractFunctionArgs, + PublicClient, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from 'viem' import { simulateContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { ABI, type DepositETHParameters, FUNCTION } from '../../../types/depositETH.js' @@ -7,15 +16,36 @@ import type { L1SimulateActionBaseType } from '../../../types/l1Actions.js' export type SimulateDepositETHParameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> } - & Omit, 'value'> + & L1SimulateActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride, + TAccountOverride + > export type SimulateDepositETHReturnType< - TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, -> = SimulateContractReturnType + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, + TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = + | Account + | Address + | undefined, +> = SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride +> /** * Simulates a deposit of ETH to L2 @@ -24,15 +54,17 @@ export type SimulateDepositETHReturnType< */ export async function simulateDepositETH< TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TAccount extends Account | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( client: PublicClient, { args: { to, gasLimit, data = '0x', amount }, portal, ...rest - }: SimulateDepositETHParameters, -): Promise> { + }: SimulateDepositETHParameters, +): Promise> { return simulateContract(client, { address: resolveAddress(portal), abi: ABI, @@ -40,5 +72,19 @@ export async function simulateDepositETH< args: [to, amount, gasLimit, false, data], value: amount, ...rest, - } as unknown as SimulateContractParameters) + } as unknown as SimulateContractParameters< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride + >) as unknown as SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > } diff --git a/src/actions/public/L1/simulateDepositTransaction.ts b/src/actions/public/L1/simulateDepositTransaction.ts index 9aeed079..65742f12 100644 --- a/src/actions/public/L1/simulateDepositTransaction.ts +++ b/src/actions/public/L1/simulateDepositTransaction.ts @@ -1,4 +1,13 @@ -import type { Chain, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport } from 'viem' +import type { + Account, + Address, + Chain, + ContractFunctionArgs, + PublicClient, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from 'viem' import { simulateContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { type L1SimulateActionBaseType } from '../../../types/l1Actions.js' @@ -7,24 +16,35 @@ import { ABI, type DepositTransactionParameters, FUNCTION } from '../../wallet/L export type SimulateDepositTransactionParameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositTransactionParameters; portal: RawOrContractAddress<_chainId> } & L1SimulateActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TChainOverride, - typeof ABI, - typeof FUNCTION + TAccountOverride > export type SimulateDepositTransactionReturnType< - TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, + TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = + | Account + | Address + | undefined, > = SimulateContractReturnType< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, - TChainOverride + TAccount, + TChainOverride, + TAccountOverride > /** @@ -35,7 +55,9 @@ export type SimulateDepositTransactionReturnType< */ export async function simulateDepositTransaction< TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TAccount extends Account | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( client: PublicClient, { @@ -44,9 +66,10 @@ export async function simulateDepositTransaction< ...rest }: SimulateDepositTransactionParameters< TChain, - TChainOverride + TChainOverride, + TAccountOverride >, -): Promise> { +): Promise> { return simulateContract(client, { address: resolveAddress(portal), abi: ABI, @@ -56,7 +79,17 @@ export async function simulateDepositTransaction< } as unknown as SimulateContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, - TChainOverride - >) + TChainOverride, + TAccountOverride + >) as unknown as SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > } diff --git a/src/actions/public/L1/simulateFinalizeWithdrawalTransaction.ts b/src/actions/public/L1/simulateFinalizeWithdrawalTransaction.ts index eb3bba98..0ab72735 100644 --- a/src/actions/public/L1/simulateFinalizeWithdrawalTransaction.ts +++ b/src/actions/public/L1/simulateFinalizeWithdrawalTransaction.ts @@ -1,4 +1,13 @@ -import type { Chain, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport } from 'viem' +import type { + Account, + Address, + Chain, + ContractFunctionArgs, + PublicClient, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from 'viem' import { simulateContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { type L1SimulateActionBaseType } from '../../../types/l1Actions.js' @@ -11,24 +20,35 @@ import { export type SimulateFinalizeWithdrawalTransactionParameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = & { withdrawal: FinalizeWithdrawalTransactionParameters; portal: RawOrContractAddress<_chainId> } & L1SimulateActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TChainOverride, - typeof ABI, - typeof FUNCTION + TAccountOverride > export type SimulateFinalizeWithdrawalTransactionReturnType< - TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, + TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = + | Account + | Address + | undefined, > = SimulateContractReturnType< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, - TChainOverride + TAccount, + TChainOverride, + TAccountOverride > /** @@ -39,7 +59,9 @@ export type SimulateFinalizeWithdrawalTransactionReturnType< */ export async function simulateFinalizeWithdrawalTransaction< TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TAccount extends Account | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( client: PublicClient, { @@ -48,9 +70,10 @@ export async function simulateFinalizeWithdrawalTransaction< ...rest }: SimulateFinalizeWithdrawalTransactionParameters< TChain, - TChainOverride + TChainOverride, + TAccountOverride >, -): Promise> { +): Promise> { return simulateContract(client, { address: resolveAddress(portal), abi: ABI, @@ -60,7 +83,17 @@ export async function simulateFinalizeWithdrawalTransaction< } as unknown as SimulateContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, - TChainOverride - >) + TChainOverride, + TAccountOverride + >) as unknown as SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > } diff --git a/src/actions/public/L1/simulateProveWithdrawalTransaction.ts b/src/actions/public/L1/simulateProveWithdrawalTransaction.ts index a59e02d1..81c984a9 100644 --- a/src/actions/public/L1/simulateProveWithdrawalTransaction.ts +++ b/src/actions/public/L1/simulateProveWithdrawalTransaction.ts @@ -1,4 +1,13 @@ -import type { Chain, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport } from 'viem' +import type { + Account, + Address, + Chain, + ContractFunctionArgs, + PublicClient, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from 'viem' import { simulateContract } from 'viem/actions' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { type L1SimulateActionBaseType } from '../../../types/l1Actions.js' @@ -11,24 +20,35 @@ import { export type SimulateProveWithdrawalTransactionParameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: ProveWithdrawalTransactionParameters; portal: RawOrContractAddress<_chainId> } & L1SimulateActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TChainOverride, - typeof ABI, - typeof FUNCTION + TAccountOverride > export type SimulateProveWithdrawalTransactionReturnType< - TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, + TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = + | Account + | Address + | undefined, > = SimulateContractReturnType< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, - TChainOverride + TAccount, + TChainOverride, + TAccountOverride > /** @@ -40,7 +60,9 @@ export type SimulateProveWithdrawalTransactionReturnType< */ export async function simulateProveWithdrawalTransaction< TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, + TAccount extends Account | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( client: PublicClient, { @@ -49,9 +71,10 @@ export async function simulateProveWithdrawalTransaction< ...rest }: SimulateProveWithdrawalTransactionParameters< TChain, - TChainOverride + TChainOverride, + TAccountOverride >, -): Promise> { +): Promise> { return simulateContract(client, { address: resolveAddress(portal), abi: ABI, @@ -61,7 +84,17 @@ export async function simulateProveWithdrawalTransaction< } as unknown as SimulateContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, - TChainOverride - >) + TChainOverride, + TAccountOverride + >) as unknown as SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > } From 661aef4171b0684a4a4c91108413dd9d7d958cbf Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:12:39 -0400 Subject: [PATCH 06/12] migrate L2 public actions to v2 --- .../public/L2/simulateWithdrawERC20.ts | 62 ++++++++++++++++--- src/actions/public/L2/simulateWithdrawETH.ts | 56 ++++++++++++++--- src/types/l2Actions.ts | 18 +++--- 3 files changed, 108 insertions(+), 28 deletions(-) diff --git a/src/actions/public/L2/simulateWithdrawERC20.ts b/src/actions/public/L2/simulateWithdrawERC20.ts index 39b76984..05d6514b 100644 --- a/src/actions/public/L2/simulateWithdrawERC20.ts +++ b/src/actions/public/L2/simulateWithdrawERC20.ts @@ -1,4 +1,13 @@ -import type { Chain, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport } from 'viem' +import type { + Account, + Address, + Chain, + ContractFunctionArgs, + PublicClient, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from 'viem' import { simulateContract } from 'viem/actions' import type { L2SimulateContractParameters } from '../../../types/l2Actions.js' import { opStackL2ChainContracts } from '../../../types/opStackContracts.js' @@ -7,14 +16,35 @@ import { ABI, FUNCTION, type WithdrawToParameters } from '../../../types/withdra export type SimulateWithdrawERC20Parameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, > = & { args: WithdrawToParameters } - & L2SimulateContractParameters + & L2SimulateContractParameters< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride, + TAccountOverride + > export type SimulateWithdrawERC20ReturnType< - TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, -> = SimulateContractReturnType + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, + TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = + | Account + | Address + | undefined, +> = SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride +> /** * Simulates a withdrawal of ERC20 tokens to an L1 address. @@ -26,15 +56,18 @@ export type SimulateWithdrawERC20ReturnType< * @param {Hex} [extraData] the extra data for the withdrawal */ export async function simulateWithdrawERC20< - TChain extends Chain | undefined = Chain, - TChainOverride extends Chain | undefined = Chain | undefined, + TChain extends Chain | undefined, + TAccount extends Account | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >(client: PublicClient, { args: { l2Token, to, amount, minGasLimit, extraData = '0x' }, ...rest }: SimulateWithdrawERC20Parameters< TChain, - TChainOverride ->): Promise> { + TChainOverride, + TAccountOverride +>): Promise> { return simulateContract(client, { abi: ABI, functionName: FUNCTION, @@ -44,7 +77,16 @@ export async function simulateWithdrawERC20< } as unknown as SimulateContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs, TChain, TChainOverride - >) + >) as unknown as SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > } diff --git a/src/actions/public/L2/simulateWithdrawETH.ts b/src/actions/public/L2/simulateWithdrawETH.ts index fe444d46..0eec82a7 100644 --- a/src/actions/public/L2/simulateWithdrawETH.ts +++ b/src/actions/public/L2/simulateWithdrawETH.ts @@ -1,4 +1,12 @@ -import type { Chain, PublicClient, Transport } from 'viem' +import type { + Account, + Address, + Chain, + ContractFunctionArgs, + PublicClient, + SimulateContractReturnType, + Transport, +} from 'viem' import type { L2SimulateContractParameters } from '../../../types/l2Actions.js' import { type ABI, type FUNCTION, OVM_ETH, type WithdrawETHParameters } from '../../../types/withdrawTo.js' import { @@ -10,14 +18,27 @@ import { export type SimulateWithdrawETHParameters< TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, > = & { args: WithdrawETHParameters } - & L2SimulateContractParameters + & L2SimulateContractParameters< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride, + TAccountOverride + > export type SimulateWithdrawETHReturnType< - TChain extends Chain | undefined, - TChainOverride extends Chain | undefined = undefined, -> = SimulateWithdrawERC20ReturnType + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, + TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = + | Account + | Address + | undefined, +> = SimulateWithdrawERC20ReturnType /** * Simulates a withdrawal of ETH to an L1 address. @@ -28,20 +49,35 @@ export type SimulateWithdrawETHReturnType< * @param {Hex} [extraData] the extra data for the withdrawal */ export async function simulateWithdrawETH< - TChain extends Chain | undefined = Chain, - TChainOverride extends Chain | undefined = Chain | undefined, + TChain extends Chain | undefined, + TAccount extends Account | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >(client: PublicClient, { args: { to, amount, minGasLimit, extraData = '0x' }, ...rest }: SimulateWithdrawETHParameters< TChain, - TChainOverride ->): Promise> { + TChainOverride, + TAccountOverride +>): Promise> { return simulateWithdrawERC20(client, { args: { l2Token: OVM_ETH, to, amount, minGasLimit, extraData }, // NOTE: msg.value must = amount or transaction will revert // https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/universal/StandardBridge.sol#L306 value: amount, ...rest, - } as unknown as SimulateWithdrawERC20Parameters) + } as unknown as SimulateWithdrawERC20Parameters< + TChain, + TChainOverride, + TAccountOverride + >) as unknown as SimulateContractReturnType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride, + TAccountOverride + > } diff --git a/src/types/l2Actions.ts b/src/types/l2Actions.ts index 180e9cc0..620efeb0 100644 --- a/src/types/l2Actions.ts +++ b/src/types/l2Actions.ts @@ -1,6 +1,7 @@ import type { Abi, Account, + Address, Chain, ContractFunctionArgs, ContractFunctionName, @@ -10,37 +11,38 @@ import type { export type L2WriteContractParameters< TAbi extends Abi | readonly unknown[] = Abi, - TFunctioName extends ContractFunctionName< + TFunctionName extends ContractFunctionName< TAbi, 'nonpayable' | 'payable' > = ContractFunctionName, TArgs extends ContractFunctionArgs< TAbi, 'nonpayable' | 'payable', - TFunctioName - > = ContractFunctionArgs, + TFunctionName + > = ContractFunctionArgs, TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, > = Omit< - WriteContractParameters, + WriteContractParameters, 'abi' | 'functionName' | 'args' | 'address' > export type L2SimulateContractParameters< TAbi extends Abi | readonly unknown[] = Abi, - TFunctioName extends ContractFunctionName< + TFunctionName extends ContractFunctionName< TAbi, 'nonpayable' | 'payable' > = ContractFunctionName, TArgs extends ContractFunctionArgs< TAbi, 'nonpayable' | 'payable', - TFunctioName - > = ContractFunctionArgs, + TFunctionName + > = ContractFunctionArgs, TChain extends Chain | undefined = Chain, TChainOverride extends Chain | undefined = Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, > = Omit< - SimulateContractParameters, + SimulateContractParameters, 'abi' | 'functionName' | 'args' | 'address' > From 85d740630e873e119291a33b661f3bdffc6ee1c9 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:55:01 -0400 Subject: [PATCH 07/12] migrate everything else --- src/_test/utils.ts | 1 - src/actions/public/L2/estimateFees.ts | 25 ++++++--- src/actions/public/L2/estimateL1Fee.ts | 23 ++++++-- src/actions/public/L2/estimateL1GasUsed.ts | 23 ++++++-- .../wallet/L1/writeDepositTransaction.ts | 17 +++--- src/decorators/publicL1OpStackActions.ts | 51 +++++++++-------- src/decorators/publicL2OpStackActions.ts | 46 ++++++++++++---- src/decorators/walletL1OpStackActions.ts | 55 ++++++++++++------- src/types/gasPriceOracle.ts | 9 ++- src/utils/transactionSerializer.ts | 9 ++- 10 files changed, 176 insertions(+), 83 deletions(-) diff --git a/src/_test/utils.ts b/src/_test/utils.ts index 8f96ffce..889bea22 100644 --- a/src/_test/utils.ts +++ b/src/_test/utils.ts @@ -47,7 +47,6 @@ export const rollupAnvilChain = { ...base, id: 8453, name: 'Rollup Localhost', - network: 'localhost', nativeCurrency: { decimals: 18, name: 'Ether', diff --git a/src/actions/public/L2/estimateFees.ts b/src/actions/public/L2/estimateFees.ts index 4c137378..e0187972 100644 --- a/src/actions/public/L2/estimateFees.ts +++ b/src/actions/public/L2/estimateFees.ts @@ -1,9 +1,11 @@ import { type Abi, + type ContractFunctionName, encodeFunctionData, type EncodeFunctionDataParameters, type EstimateGasParameters, type PublicClient, + type TransactionSerializableEIP1559, type Transport, } from 'viem' import { type Chain } from 'viem/chains' @@ -12,7 +14,9 @@ import { estimateL1Fee } from './estimateL1Fee.js' export type EstimateFeesParameters< TAbi extends Abi | readonly unknown[], - TFunctionName extends string | undefined = undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, > = & OracleTransactionParameters & GasPriceOracleParameters @@ -21,7 +25,9 @@ export type EstimateFeesParameters< export type EstimateFees = < TChain extends Chain | undefined, TAbi extends Abi | readonly unknown[], - TFunctionName extends string | undefined = undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, >( client: PublicClient, options: EstimateFeesParameters, @@ -45,11 +51,16 @@ export const estimateFees: EstimateFees = async (client, options) => { functionName: options.functionName, } as EncodeFunctionDataParameters) const [l1Fee, l2Gas, l2GasPrice] = await Promise.all([ - estimateL1Fee(client, { - ...options, - // account must be undefined or else viem will return undefined - account: undefined as any, - }), + estimateL1Fee( + client, + { + ...options, + // account must be undefined or else viem will return undefined + account: undefined as any, + } as unknown as + & EncodeFunctionDataParameters> + & Omit, + ), client.estimateGas({ to: options.to, account: options.account, diff --git a/src/actions/public/L2/estimateL1Fee.ts b/src/actions/public/L2/estimateL1Fee.ts index 0809cd09..e9c05b59 100644 --- a/src/actions/public/L2/estimateL1Fee.ts +++ b/src/actions/public/L2/estimateL1Fee.ts @@ -1,5 +1,12 @@ import { gasPriceOracleABI, gasPriceOracleAddress } from '@eth-optimism/contracts-ts' -import { type Abi, type PublicClient, type Transport } from 'viem' +import { + type Abi, + type ContractFunctionName, + type EncodeFunctionDataParameters, + type PublicClient, + type TransactionSerializableEIP1559, + type Transport, +} from 'viem' import { readContract } from 'viem/actions' import { type Chain } from 'viem/chains' import type { OracleTransactionParameters } from '../../../types/gasPriceOracle.js' @@ -7,7 +14,9 @@ import { serializeEip1559Transaction } from '../../../utils/transactionSerialize export type EstimateL1FeeParameters< TAbi extends Abi, - TFunctionName extends string | undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, > = OracleTransactionParameters /** @@ -16,7 +25,9 @@ export type EstimateL1FeeParameters< export type GasPriceOracleEstimator = < TChain extends Chain | undefined, TAbi extends Abi | readonly unknown[], - TFunctionName extends string | undefined = undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, >( client: PublicClient, options: OracleTransactionParameters, @@ -36,7 +47,11 @@ export const estimateL1Fee: GasPriceOracleEstimator = async ( client, options, ) => { - const data = serializeEip1559Transaction(options) + const data = serializeEip1559Transaction( + options as unknown as + & EncodeFunctionDataParameters> + & Omit, + ) return readContract(client, { address: gasPriceOracleAddress['420'], abi: gasPriceOracleABI, diff --git a/src/actions/public/L2/estimateL1GasUsed.ts b/src/actions/public/L2/estimateL1GasUsed.ts index 9083d479..f57bfabf 100644 --- a/src/actions/public/L2/estimateL1GasUsed.ts +++ b/src/actions/public/L2/estimateL1GasUsed.ts @@ -1,5 +1,12 @@ import { gasPriceOracleABI } from '@eth-optimism/contracts-ts' -import { type Abi, type PublicClient, type Transport } from 'viem' +import { + type Abi, + type ContractFunctionName, + type EncodeFunctionDataParameters, + type PublicClient, + type TransactionSerializableEIP1559, + type Transport, +} from 'viem' import { readContract } from 'viem/actions' import { type Chain } from 'viem/chains' import { opStackL2ChainContracts } from '../../../index.js' @@ -8,7 +15,9 @@ import { serializeEip1559Transaction } from '../../../utils/transactionSerialize export type EstimateL1GasUsedParameters< TAbi extends Abi, - TFunctionName extends string | undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, > = OracleTransactionParameters /** @@ -17,7 +26,9 @@ export type EstimateL1GasUsedParameters< export type GasPriceOracleEstimator = < TChain extends Chain | undefined, TAbi extends Abi | readonly unknown[], - TFunctionName extends string | undefined = undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, >( client: PublicClient, options: OracleTransactionParameters, @@ -36,7 +47,11 @@ export const estimateL1GasUsed: GasPriceOracleEstimator = async ( client, options, ) => { - const data = serializeEip1559Transaction(options) + const data = serializeEip1559Transaction( + options as unknown as + & EncodeFunctionDataParameters> + & Omit, + ) return readContract(client, { address: opStackL2ChainContracts.gasPriceOracle.address, abi: gasPriceOracleABI, diff --git a/src/actions/wallet/L1/writeDepositTransaction.ts b/src/actions/wallet/L1/writeDepositTransaction.ts index 6b97e5ba..fca07bdc 100644 --- a/src/actions/wallet/L1/writeDepositTransaction.ts +++ b/src/actions/wallet/L1/writeDepositTransaction.ts @@ -30,16 +30,13 @@ export type WriteDepositTransactionParameters< TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, - _chainId = TChain extends Chain ? TChain['id'] : number, -> = - & { args: DepositTransactionParameters; portal: RawOrContractAddress<_chainId> } - & Omit< - L1WriteActionBaseType< - TChain, - TAccount, - TChainOverride - >, - 'value' +> // _chainId = TChain extends Chain ? TChain['id'] : number, + = + & { args: DepositTransactionParameters; portal: RawOrContractAddress } + & L1WriteActionBaseType< + TChain, + TAccount, + TChainOverride > /** diff --git a/src/decorators/publicL1OpStackActions.ts b/src/decorators/publicL1OpStackActions.ts index d34512d2..6c3dc220 100644 --- a/src/decorators/publicL1OpStackActions.ts +++ b/src/decorators/publicL1OpStackActions.ts @@ -1,4 +1,4 @@ -import type { Chain, PublicClient, Transport } from 'viem' +import type { Account, Address, Chain, PublicClient, Transport } from 'viem' import { getL2HashesForDepositTx, type GetL2HashesForDepositTxParamters, @@ -59,6 +59,7 @@ import { export type PublicL1OpStackActions< TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, > = { getL2HashesForDepositTx: ( args: GetL2HashesForDepositTxParamters, @@ -77,40 +78,45 @@ export type PublicL1OpStackActions< readFinalizedWithdrawals: (args: ReadFinalizedWithdrawalsParameters) => Promise readProvenWithdrawals: (args: ReadProvenWithdrawalsParameters) => Promise - simulateDepositERC20: < - TChainOverride extends Chain | undefined = Chain | undefined, - >( - args: SimulateDepositERC20Parameters, - ) => Promise> simulateDepositETH: < - TChainOverride extends Chain | undefined = Chain | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( - args: SimulateDepositETHParameters, - ) => Promise> - simulateDepositTransaction: < - TChainOverride extends Chain | undefined = Chain | undefined, + args: SimulateDepositETHParameters, + ) => Promise> + simulateDepositERC20: < + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( - args: SimulateDepositTransactionParameters, - ) => Promise> - - simulateFinalizeWithdrawalTransaction: < - TChainOverride extends Chain | undefined = Chain | undefined, + args: SimulateDepositERC20Parameters, + ) => Promise> + simulateDepositTransaction: < + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( - args: SimulateFinalizeWithdrawalTransactionParameters, - ) => Promise> + args: SimulateDepositTransactionParameters, + ) => Promise> simulateProveWithdrawTransaction: < - TChainOverride extends Chain | undefined = Chain | undefined, + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( - args: SimulateProveWithdrawalTransactionParameters, - ) => Promise> + args: SimulateProveWithdrawalTransactionParameters, + ) => Promise> + simulateFinalizeWithdrawalTransaction: < + TChainOverride extends Chain | undefined, + TAccountOverride extends Account | Address | undefined = undefined, + >( + args: SimulateFinalizeWithdrawalTransactionParameters, + ) => Promise> } export function publicL1OpStackActions< TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, >( client: PublicClient, -): PublicL1OpStackActions { +): PublicL1OpStackActions { return { getL2HashesForDepositTx: (args) => getL2HashesForDepositTx(client, args), @@ -122,7 +128,6 @@ export function publicL1OpStackActions< simulateDepositETH: (args) => simulateDepositETH(client, args), simulateDepositERC20: (args) => simulateDepositERC20(client, args), simulateDepositTransaction: (args) => simulateDepositTransaction(client, args), - readFinalizedWithdrawals: (args) => readFinalizedWithdrawals(client, args), readProvenWithdrawals: (args) => readProvenWithdrawals(client, args), diff --git a/src/decorators/publicL2OpStackActions.ts b/src/decorators/publicL2OpStackActions.ts index 083065f7..dfd79603 100644 --- a/src/decorators/publicL2OpStackActions.ts +++ b/src/decorators/publicL2OpStackActions.ts @@ -1,4 +1,4 @@ -import type { Abi, Chain, PublicClient, Transport } from 'viem' +import type { Abi, Account, Address, Chain, ContractFunctionName, PublicClient, Transport } from 'viem' import { estimateFees, type EstimateFeesParameters } from '../actions/public/L2/estimateFees.js' import { estimateL1Fee } from '../actions/public/L2/estimateL1Fee.js' import { estimateL1GasUsed } from '../actions/public/L2/estimateL1GasUsed.js' @@ -25,7 +25,10 @@ import { import { type OracleTransactionParameters } from '../types/gasPriceOracle.js' -export type PublicL2OpStackActions = { +export type PublicL2OpStackActions< + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, +> = { /** * Estimate the l1 gas price portion for a transaction * @example @@ -34,13 +37,20 @@ export type PublicL2OpStackActions( - args: EstimateFeesParameters, - ) => Promise - estimateL1Fee: ( + estimateL1Fee: < + TAbi extends Abi | readonly unknown[], + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, + >( args: OracleTransactionParameters, ) => Promise - estimateL1GasUsed: ( + estimateL1GasUsed: < + TAbi extends Abi | readonly unknown[], + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, + >( args: OracleTransactionParameters, ) => Promise @@ -53,23 +63,37 @@ export type PublicL2OpStackActions( - args: SimulateWithdrawERC20Parameters, + args: SimulateWithdrawERC20Parameters, ) => Promise< SimulateWithdrawERC20ReturnType< TChain, - TChainOverride + TAccount, + TChainOverride, + TAccountOverride > > + estimateFees: < + TAbi extends Abi | readonly unknown[], + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, + >( + args: EstimateFeesParameters, + ) => Promise simulateWithdrawETH: < TChainOverride extends Chain | undefined = undefined, + TAccountOverride extends Account | Address | undefined = undefined, >( - args: SimulateWithdrawETHParameters, + args: SimulateWithdrawETHParameters, ) => Promise< SimulateWithdrawETHReturnType< TChain, - TChainOverride + TAccount, + TChainOverride, + TAccountOverride > > } diff --git a/src/decorators/walletL1OpStackActions.ts b/src/decorators/walletL1OpStackActions.ts index 7d92beb6..c0110be4 100644 --- a/src/decorators/walletL1OpStackActions.ts +++ b/src/decorators/walletL1OpStackActions.ts @@ -1,4 +1,12 @@ -import type { Abi, Account, Chain, Transport, WriteContractReturnType } from 'viem' +import type { + Abi, + Account, + Chain, + ContractFunctionArgs, + ContractFunctionName, + Transport, + WriteContractReturnType, +} from 'viem' import type { WalletClient } from 'viem' import { writeContractDeposit, type WriteContractDepositParameters } from '../actions/wallet/L1/writeContractDeposit.js' import { writeDepositERC20, type WriteDepositERC20Parameters } from '../actions/wallet/L1/writeDepositERC20.js' @@ -21,21 +29,8 @@ export type WalletL1OpStackActions< TChain extends Chain | undefined = Chain | undefined, TAccount extends Account | undefined = Account | undefined, > = { - writeContractDeposit: < - TAbi extends Abi | readonly unknown[] = Abi, - TFunctionName extends string = string, - TChainOverride extends Chain | undefined = Chain | undefined, - >( - args: WriteContractDepositParameters< - TAbi, - TFunctionName, - TChain, - TAccount, - TChainOverride - >, - ) => Promise writeDepositERC20: < - TChainOverride extends Chain | undefined = Chain | undefined, + TChainOverride extends Chain | undefined = undefined, >( args: WriteDepositERC20Parameters, ) => Promise @@ -45,7 +40,7 @@ export type WalletL1OpStackActions< args: WriteDepositETHParameters, ) => Promise writeDepositTransaction: < - TChainOverride extends Chain | undefined = Chain | undefined, + TChainOverride extends Chain | undefined = undefined, >( args: WriteDepositTransactionParameters< TChain, @@ -53,8 +48,17 @@ export type WalletL1OpStackActions< TChainOverride >, ) => Promise + writeProveWithdrawalTransaction: < + TChainOverride extends Chain | undefined = undefined, + >( + args: WriteProveWithdrawalTransactionParameters< + TChain, + TAccount, + TChainOverride + >, + ) => Promise writeFinalizeWithdrawalTransaction: < - TChainOverride extends Chain | undefined = Chain | undefined, + TChainOverride extends Chain | undefined = undefined, >( args: WriteFinalizeWithdrawalTransactionParameters< TChain, @@ -62,10 +66,23 @@ export type WalletL1OpStackActions< TChainOverride >, ) => Promise - writeProveWithdrawalTransaction: < + writeContractDeposit: < + TFunctionName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + >, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + TFunctionName + >, TChainOverride extends Chain | undefined = Chain | undefined, + TAbi extends Abi | readonly unknown[] = Abi, >( - args: WriteProveWithdrawalTransactionParameters< + args: WriteContractDepositParameters< + TAbi, + TFunctionName, + TArgs, TChain, TAccount, TChainOverride diff --git a/src/types/gasPriceOracle.ts b/src/types/gasPriceOracle.ts index b54799c2..dbbb34f8 100644 --- a/src/types/gasPriceOracle.ts +++ b/src/types/gasPriceOracle.ts @@ -1,6 +1,7 @@ import type { Abi, BlockTag, + ContractFunctionName, EncodeFunctionDataParameters, PublicClient, TransactionSerializableEIP1559, @@ -32,7 +33,9 @@ export type GasPriceOracleParameters = BlockOptions */ export type OracleTransactionParameters< TAbi extends Abi | readonly unknown[], - TFunctionName extends string | undefined = undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, > = & EncodeFunctionDataParameters & Omit @@ -43,7 +46,9 @@ export type OracleTransactionParameters< export type GasPriceOracleEstimator = < TChain extends Chain | undefined, TAbi extends Abi | readonly unknown[], - TFunctionName extends string | undefined = undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, >( client: PublicClient, options: OracleTransactionParameters, diff --git a/src/utils/transactionSerializer.ts b/src/utils/transactionSerializer.ts index 73dd7276..d507343f 100644 --- a/src/utils/transactionSerializer.ts +++ b/src/utils/transactionSerializer.ts @@ -1,5 +1,6 @@ import { type Abi, + type ContractFunctionName, encodeFunctionData, type EncodeFunctionDataParameters, serializeTransaction, @@ -12,13 +13,17 @@ import { */ export function serializeEip1559Transaction< TAbi extends Abi | readonly unknown[], - TFunctionName extends string | undefined = undefined, + TFunctionName extends + | ContractFunctionName + | undefined = ContractFunctionName, >( options: & EncodeFunctionDataParameters & Omit, ): TransactionSerializedEIP1559 { - const encodedFunctionData = encodeFunctionData(options) + const encodedFunctionData = encodeFunctionData( + options as unknown as EncodeFunctionDataParameters>, + ) const serializedTransaction = serializeTransaction({ ...options, data: encodedFunctionData, From d9ce04dff30a0264ce1bef4255470b5cad04b63e Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 18:00:45 -0400 Subject: [PATCH 08/12] version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c0a79a9e..8728c45f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "op-viem", - "version": "1.1.0", + "version": "1.3.0-alpha", "type": "module", "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", From 4be65e392062783dd472ee59d2bcf5beffe85177 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 25 Oct 2023 19:54:16 -0400 Subject: [PATCH 09/12] revert writel1action base type change --- src/actions/wallet/L1/writeDepositERC20.ts | 3 +++ src/actions/wallet/L1/writeDepositETH.ts | 20 +++++++++++-------- .../wallet/L1/writeDepositTransaction.ts | 3 +++ .../L1/writeFinalizeWithdrawalTransaction.ts | 3 +++ .../L1/writeProveWithdrawalTransaction.ts | 3 +++ src/actions/wallet/L1/writeSendMessage.ts | 3 +++ src/types/l1Actions.ts | 20 ++++++++++++------- 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/actions/wallet/L1/writeDepositERC20.ts b/src/actions/wallet/L1/writeDepositERC20.ts index ef4d2d78..4bd2f2f4 100644 --- a/src/actions/wallet/L1/writeDepositERC20.ts +++ b/src/actions/wallet/L1/writeDepositERC20.ts @@ -20,6 +20,9 @@ export type WriteDepositERC20Parameters< > = & { args: DepositERC20Parameters; l1StandardBridge: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L1/writeDepositETH.ts b/src/actions/wallet/L1/writeDepositETH.ts index e1fa46cd..f4a8f8ef 100644 --- a/src/actions/wallet/L1/writeDepositETH.ts +++ b/src/actions/wallet/L1/writeDepositETH.ts @@ -1,9 +1,13 @@ -import type { Account, Chain, Transport, WalletClient, WriteContractReturnType } from 'viem' +import { optimismPortalABI } from '@eth-optimism/contracts-ts' +import type { Account, Chain, ContractFunctionArgs, Transport, WalletClient, WriteContractReturnType } from 'viem' import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js' import { type DepositETHParameters } from '../../../types/depositETH.js' import type { L1WriteActionBaseType } from '../../../types/l1Actions.js' import { writeDepositTransaction, type WriteDepositTransactionParameters } from './writeDepositTransaction.js' +export const ABI = optimismPortalABI +export const FUNCTION = 'depositTransaction' + export type WriteDepositETHParameters< TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, @@ -11,13 +15,13 @@ export type WriteDepositETHParameters< _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> } - & Omit< - L1WriteActionBaseType< - TChain, - TAccount, - TChainOverride - >, - 'value' + & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride > /** diff --git a/src/actions/wallet/L1/writeDepositTransaction.ts b/src/actions/wallet/L1/writeDepositTransaction.ts index fca07bdc..b72fb69b 100644 --- a/src/actions/wallet/L1/writeDepositTransaction.ts +++ b/src/actions/wallet/L1/writeDepositTransaction.ts @@ -34,6 +34,9 @@ export type WriteDepositTransactionParameters< = & { args: DepositTransactionParameters; portal: RawOrContractAddress } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts index a3b86b15..7de88c4d 100644 --- a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts +++ b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts @@ -27,6 +27,9 @@ export type WriteFinalizeWithdrawalTransactionParameters< > = & { args: { withdrawal: FinalizeWithdrawalTransactionParameters }; portal: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts b/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts index be412c22..324e6dc8 100644 --- a/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts +++ b/src/actions/wallet/L1/writeProveWithdrawalTransaction.ts @@ -26,6 +26,9 @@ export type WriteProveWithdrawalTransactionParameters< > = & { args: ProveWithdrawalTransactionParameters; portal: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L1/writeSendMessage.ts b/src/actions/wallet/L1/writeSendMessage.ts index 0f8a1c2b..e80cb8af 100644 --- a/src/actions/wallet/L1/writeSendMessage.ts +++ b/src/actions/wallet/L1/writeSendMessage.ts @@ -31,6 +31,9 @@ export type WriteSendMessageParameters< > = & { args: SendMessageParameters; l1CrossDomainMessenger: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride diff --git a/src/types/l1Actions.ts b/src/types/l1Actions.ts index 22fee5f7..c989d59d 100644 --- a/src/types/l1Actions.ts +++ b/src/types/l1Actions.ts @@ -5,21 +5,27 @@ import type { Chain, ContractFunctionArgs, ContractFunctionName, - SendTransactionParameters, SimulateContractParameters, + WriteContractParameters, } from 'viem' export type L1WriteActionBaseType< + TAbi extends Abi | readonly unknown[] = Abi, + TFunctionName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + > = ContractFunctionName, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + TFunctionName + > = ContractFunctionArgs, TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, > = Omit< - SendTransactionParameters< - TChain, - TAccount, - TChainOverride - >, - 'chain' + WriteContractParameters, + 'abi' | 'functionName' | 'args' | 'address' > export type L1SimulateActionBaseType< From 4634f9c1880a76f3fde0e2f99385e60f2df8dd77 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:48:37 -0500 Subject: [PATCH 10/12] update to viem beta --- package.json | 2 +- pnpm-lock.yaml | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 8728c45f..30429bee 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,7 @@ }, "peerDependencies": { "typescript": ">=5.0.4", - "viem": "2.0.0-alpha.17" + "viem": "2.0.0-beta.0" }, "peerDependenciesMeta": { "typescript": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f5fe35f..fe2efd8f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,8 +15,8 @@ importers: specifier: ^0.15.0 version: 0.15.0(typescript@5.0.4)(wagmi@1.4.1) viem: - specifier: 2.0.0-alpha.17 - version: 2.0.0-alpha.17(typescript@5.0.4) + specifier: 2.0.0-beta.0 + version: 2.0.0-beta.0(typescript@5.0.4) devDependencies: '@biomejs/biome': specifier: 1.0.0 @@ -83,7 +83,7 @@ importers: version: 0.34.4 wagmi: specifier: ^1.3.11 - version: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) + version: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0) site: devDependencies: @@ -1104,7 +1104,7 @@ packages: react: 18.2.0 react-dom: 18.2.0(react@18.2.0) viem: 1.10.9(typescript@5.0.4)(zod@3.22.2) - wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) + wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0) transitivePeerDependencies: - bufferutil - typescript @@ -2416,14 +2416,14 @@ packages: prettier: 2.8.8 typescript: 5.0.4 viem: 1.10.9(typescript@5.0.4)(zod@3.22.2) - wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) + wagmi: 1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0) zod: 3.22.2 transitivePeerDependencies: - bufferutil - utf-8-validate dev: true - /@wagmi/connectors@3.1.1(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17): + /@wagmi/connectors@3.1.1(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0): resolution: {integrity: sha512-ewOV40AlrXcX018qckU0V9OCsDgHhs+KZjQJZhlplqRtc2ijjS62B5kcypXkcTtfU5qXUBA9KEwPsSTxGdT4ag==} peerDependencies: typescript: '>=5.0.4' @@ -2443,7 +2443,7 @@ packages: abitype: 0.8.7(typescript@5.0.4)(zod@3.22.2) eventemitter3: 4.0.7 typescript: 5.0.4 - viem: 2.0.0-alpha.17(typescript@5.0.4) + viem: 2.0.0-beta.0(typescript@5.0.4) transitivePeerDependencies: - '@react-native-async-storage/async-storage' - bufferutil @@ -2454,7 +2454,7 @@ packages: - utf-8-validate - zod - /@wagmi/core@1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17): + /@wagmi/core@1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0): resolution: {integrity: sha512-b6LDFL0vZSCNcIHjnJzv++hakavTTt1/2WEQg2S5eEnaHTp7UoQlwfCyjKeiBhRih4yF34N06ea8cyEVjyjXrw==} peerDependencies: typescript: '>=5.0.4' @@ -2463,11 +2463,11 @@ packages: typescript: optional: true dependencies: - '@wagmi/connectors': 3.1.1(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) + '@wagmi/connectors': 3.1.1(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0) abitype: 0.8.7(typescript@5.0.4)(zod@3.22.2) eventemitter3: 4.0.7 typescript: 5.0.4 - viem: 2.0.0-alpha.17(typescript@5.0.4) + viem: 2.0.0-beta.0(typescript@5.0.4) zustand: 4.4.1(@types/react@18.2.21)(react@18.2.0) transitivePeerDependencies: - '@react-native-async-storage/async-storage' @@ -6374,8 +6374,8 @@ packages: - utf-8-validate - zod - /viem@2.0.0-alpha.17(typescript@5.0.4): - resolution: {integrity: sha512-oxC8mWdrcBMDHQHAzCGIPwOJ4ceyInbojj1aDxfEfITI+IVhDq6VxtxCJuM4DbcKq74uogs6GkXkyOlcPIovbg==} + /viem@2.0.0-beta.0(typescript@5.0.4): + resolution: {integrity: sha512-KsUh16uhSvTSI/tCBuMqjCvvdVIKDI4lAFWQ4hMPofBLw9W0UEmFk8hd+e/NlNc/fI24eghHmkTYLBRancIBkg==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -6631,7 +6631,7 @@ packages: '@vue/shared': 3.3.4 dev: true - /wagmi@1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17): + /wagmi@1.4.1(@types/react@18.2.21)(react-dom@18.2.0)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0): resolution: {integrity: sha512-v3xd+uYZfLCAs1I4fLU7U9hg/gCw+Ud005J7kNR0mi20BcFAEU1EDN1LxHxpjUV0qKhOzSlMlrLjJyBCmSYhFA==} peerDependencies: react: '>=17.0.0' @@ -6644,12 +6644,12 @@ packages: '@tanstack/query-sync-storage-persister': 4.35.0 '@tanstack/react-query': 4.35.0(react-dom@18.2.0)(react@18.2.0) '@tanstack/react-query-persist-client': 4.35.0(@tanstack/react-query@4.35.0) - '@wagmi/core': 1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-alpha.17) + '@wagmi/core': 1.4.1(@types/react@18.2.21)(react@18.2.0)(typescript@5.0.4)(viem@2.0.0-beta.0) abitype: 0.8.7(typescript@5.0.4)(zod@3.22.2) react: 18.2.0 typescript: 5.0.4 use-sync-external-store: 1.2.0(react@18.2.0) - viem: 2.0.0-alpha.17(typescript@5.0.4) + viem: 2.0.0-beta.0(typescript@5.0.4) transitivePeerDependencies: - '@react-native-async-storage/async-storage' - '@types/react' From 15836e11cc45efa02fc7a33180635902312bf721 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Mon, 6 Nov 2023 16:58:14 -0500 Subject: [PATCH 11/12] omit value from l1 actions --- src/actions/public/L1/simulateDepositETH.ts | 17 +++++++++------- src/actions/wallet/L1/writeDepositETH.ts | 17 +++++++++------- .../wallet/L1/writeDepositTransaction.ts | 20 ++++++++++--------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/actions/public/L1/simulateDepositETH.ts b/src/actions/public/L1/simulateDepositETH.ts index d32855a2..d43fc4d1 100644 --- a/src/actions/public/L1/simulateDepositETH.ts +++ b/src/actions/public/L1/simulateDepositETH.ts @@ -20,13 +20,16 @@ export type SimulateDepositETHParameters< _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> } - & L1SimulateActionBaseType< - typeof ABI, - typeof FUNCTION, - ContractFunctionArgs, - TChain, - TChainOverride, - TAccountOverride + & Omit< + L1SimulateActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride, + TAccountOverride + >, + 'value' > export type SimulateDepositETHReturnType< diff --git a/src/actions/wallet/L1/writeDepositETH.ts b/src/actions/wallet/L1/writeDepositETH.ts index f4a8f8ef..be18e534 100644 --- a/src/actions/wallet/L1/writeDepositETH.ts +++ b/src/actions/wallet/L1/writeDepositETH.ts @@ -15,13 +15,16 @@ export type WriteDepositETHParameters< _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> } - & L1WriteActionBaseType< - typeof ABI, - typeof FUNCTION, - ContractFunctionArgs, - TChain, - TAccount, - TChainOverride + & Omit< + L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride + >, + 'value' > /** diff --git a/src/actions/wallet/L1/writeDepositTransaction.ts b/src/actions/wallet/L1/writeDepositTransaction.ts index b72fb69b..13ee3408 100644 --- a/src/actions/wallet/L1/writeDepositTransaction.ts +++ b/src/actions/wallet/L1/writeDepositTransaction.ts @@ -30,16 +30,18 @@ export type WriteDepositTransactionParameters< TChain extends Chain | undefined = Chain, TAccount extends Account | undefined = Account | undefined, TChainOverride extends Chain | undefined = Chain | undefined, -> // _chainId = TChain extends Chain ? TChain['id'] : number, - = +> = & { args: DepositTransactionParameters; portal: RawOrContractAddress } - & L1WriteActionBaseType< - typeof ABI, - typeof FUNCTION, - ContractFunctionArgs, - TChain, - TAccount, - TChainOverride + & Omit< + L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TAccount, + TChainOverride + >, + 'value' > /** From f31b0293b9a18c31f9f332d48555a43a1b84c2e5 Mon Sep 17 00:00:00 2001 From: Lukas Rosario <36800180+lukasrosario@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:41:35 -0500 Subject: [PATCH 12/12] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 30429bee..ca2ee5ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "op-viem", - "version": "1.3.0-alpha", + "version": "1.3.1-alpha", "type": "module", "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js",