diff --git a/package.json b/package.json index 9a05665..ca2ee5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "op-viem", - "version": "1.1.0", + "version": "1.3.1-alpha", "type": "module", "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", @@ -107,7 +107,7 @@ }, "peerDependencies": { "typescript": ">=5.0.4", - "viem": "1.x" + "viem": "2.0.0-beta.0" }, "peerDependenciesMeta": { "typescript": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9a9fe90..fe2efd8 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-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@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-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@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-beta.0) 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-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@1.10.9): + /@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: 1.10.9(typescript@5.0.4)(zod@3.22.2) + 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@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-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@1.10.9) + '@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: 1.10.9(typescript@5.0.4)(zod@3.22.2) + 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' @@ -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-beta.0(typescript@5.0.4): + resolution: {integrity: sha512-KsUh16uhSvTSI/tCBuMqjCvvdVIKDI4lAFWQ4hMPofBLw9W0UEmFk8hd+e/NlNc/fI24eghHmkTYLBRancIBkg==} + 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-beta.0): 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-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: 1.10.9(typescript@5.0.4)(zod@3.22.2) + viem: 2.0.0-beta.0(typescript@5.0.4) transitivePeerDependencies: - '@react-native-async-storage/async-storage' - '@types/react' diff --git a/src/_test/utils.ts b/src/_test/utils.ts index 8f96ffc..889bea2 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/L1/simulateDepositERC20.ts b/src/actions/public/L1/simulateDepositERC20.ts index 4e7d715..49f90d4 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/public/L1/simulateDepositETH.ts b/src/actions/public/L1/simulateDepositETH.ts index 5f56b47..d43fc4d 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,39 @@ 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'> + & Omit< + L1SimulateActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, + TChain, + TChainOverride, + TAccountOverride + >, + 'value' + > 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 +57,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 +75,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 9aeed07..65742f1 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 eb3bba9..0ab7273 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 a59e02d..81c984a 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 + > } diff --git a/src/actions/public/L2/estimateFees.ts b/src/actions/public/L2/estimateFees.ts index 4c13737..e018797 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 0809cd0..e9c05b5 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 9083d47..f57bfab 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/public/L2/simulateWithdrawERC20.ts b/src/actions/public/L2/simulateWithdrawERC20.ts index 39b7698..05d6514 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 fe444d4..0eec82a 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/actions/wallet/L1/writeContractDeposit.ts b/src/actions/wallet/L1/writeContractDeposit.ts index 4ec49a8..89baf4f 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/writeDepositERC20.ts b/src/actions/wallet/L1/writeDepositERC20.ts index a5b9a8f..4bd2f2f 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' @@ -12,6 +20,9 @@ export type WriteDepositERC20Parameters< > = & { args: DepositERC20Parameters; l1StandardBridge: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride @@ -47,6 +58,7 @@ export async function writeDepositERC20< } as unknown as WriteContractParameters< 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 e1fa46c..be18e53 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, @@ -13,6 +17,9 @@ export type WriteDepositETHParameters< & { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> } & Omit< 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 0bcc693..13ee340 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, @@ -29,11 +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> } + & { args: DepositTransactionParameters; portal: RawOrContractAddress } & Omit< L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride @@ -82,6 +85,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 13f1ce3..7de88c4 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' @@ -19,6 +27,9 @@ export type WriteFinalizeWithdrawalTransactionParameters< > = & { args: { withdrawal: FinalizeWithdrawalTransactionParameters }; portal: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride @@ -56,6 +67,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 6d20276..324e6dc 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' @@ -18,6 +26,9 @@ export type WriteProveWithdrawalTransactionParameters< > = & { args: ProveWithdrawalTransactionParameters; portal: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride @@ -55,6 +66,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 1abaa8d..e80cb8a 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, @@ -30,6 +31,9 @@ export type WriteSendMessageParameters< > = & { args: SendMessageParameters; l1CrossDomainMessenger: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< + typeof ABI, + typeof FUNCTION, + ContractFunctionArgs, TChain, TAccount, TChainOverride @@ -67,6 +71,11 @@ export async function writeSendMessage< } as unknown as WriteContractParameters< typeof ABI, typeof FUNCTION, + ContractFunctionArgs< + typeof ABI, + 'payable', + typeof FUNCTION + >, TChain, TAccount, TChainOverride diff --git a/src/actions/wallet/L2/writeWithdrawERC20.ts b/src/actions/wallet/L2/writeWithdrawERC20.ts index 05dd2ab..eac85c1 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 18cceeb..5640f19 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/decorators/publicL1OpStackActions.ts b/src/decorators/publicL1OpStackActions.ts index d34512d..6c3dc22 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 083065f..dfd7960 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 7d92beb..c0110be 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 b54799c..dbbb34f 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/types/l1Actions.ts b/src/types/l1Actions.ts index fef14e1..c989d59 100644 --- a/src/types/l1Actions.ts +++ b/src/types/l1Actions.ts @@ -1,24 +1,48 @@ -import type { Abi, Account, Chain, SendTransactionParameters, SimulateContractParameters } from 'viem' +import type { + Abi, + Account, + Address, + Chain, + ContractFunctionArgs, + ContractFunctionName, + 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< + 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' > diff --git a/src/types/l2Actions.ts b/src/types/l2Actions.ts index 34feacb..620efeb 100644 --- a/src/types/l2Actions.ts +++ b/src/types/l2Actions.ts @@ -1,22 +1,48 @@ -import type { Abi, Account, Chain, SimulateContractParameters, WriteContractParameters } from 'viem' +import type { + Abi, + Account, + Address, + Chain, + ContractFunctionArgs, + ContractFunctionName, + SimulateContractParameters, + WriteContractParameters, +} from 'viem' export type L2WriteContractParameters< TAbi extends Abi | readonly unknown[] = Abi, - TFunctioName 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, > = Omit< - WriteContractParameters, + WriteContractParameters, 'abi' | 'functionName' | 'args' | 'address' > export type L2SimulateContractParameters< TAbi extends Abi | readonly unknown[] = Abi, - TFunctioName extends string = string, + TFunctionName extends ContractFunctionName< + TAbi, + 'nonpayable' | 'payable' + > = ContractFunctionName, + TArgs extends ContractFunctionArgs< + TAbi, + 'nonpayable' | 'payable', + 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' > diff --git a/src/utils/transactionSerializer.ts b/src/utils/transactionSerializer.ts index 73dd727..d507343 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,