diff --git a/.changeset/grumpy-humans-protect.md b/.changeset/grumpy-humans-protect.md new file mode 100644 index 0000000..30d216b --- /dev/null +++ b/.changeset/grumpy-humans-protect.md @@ -0,0 +1,9 @@ +--- +"op-viem": major +--- + +Leave alpha. + +- writeDepositETH and simulateDepositETH now take an `args.amount` instead of using a value arg. +- getSecondsToNextL2Output throws an error if the passed latestL2BlockNumber is less than the latestBlockNumber reported by the l2OutputOracle. +- writeFinalizeWithdrawalTransaction takes an `args` parameter like most other actions. diff --git a/site/docs/actions/public/L1/simulateDepositETH.md b/site/docs/actions/public/L1/simulateDepositETH.md index e7ccf14..8809e9f 100644 --- a/site/docs/actions/public/L1/simulateDepositETH.md +++ b/site/docs/actions/public/L1/simulateDepositETH.md @@ -17,8 +17,8 @@ const { request } = await publicClient.simulateDepositETH({ args: { to: '0xFd4F24676eD4588928213F37B126B53c07186F45', gasLimit: 100000, + amount: 1n, }, - value: 1n, portal: baseAddresses.portal, account: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045', }) @@ -40,11 +40,9 @@ Returns a `request` that can be passed to Viem's `writeContract` and a `result` - **Type:** `number` - The minimum gas limit to use for the deposit transaction. -### value - -- **Type:** `bigint` - -The amount of ETH to deposit. +- #### amount + - **Type:** `bigint` + - The amount of ETH to deposit. ### portal diff --git a/site/docs/actions/wallet/L1/writeDepositETH.md b/site/docs/actions/wallet/L1/writeDepositETH.md index caad08d..6744191 100644 --- a/site/docs/actions/wallet/L1/writeDepositETH.md +++ b/site/docs/actions/wallet/L1/writeDepositETH.md @@ -16,9 +16,9 @@ const hash = await walletClient.writeDepositETH({ args: { to: '0xFd4F24676eD4588928213F37B126B53c07186F45', gasLimit: 100000, + amount: 1n, }, ...baseAddresses, - value: 1n, account: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045', }) ``` @@ -31,23 +31,17 @@ Returns a transaction hash of the deposit transaction. ### args -#### to +- #### to + - **Type:** `Address` + - The address to deposit the tokens to. -- **Type:** `Address` - -The address to deposit the tokens to. - -#### gasLimit - -- **Type:** `number` - -The minimum gas limit to use for the deposit transaction. - -### value - -- **Type:** `bigint` +- #### gasLimit + - **Type:** `number` + - The minimum gas limit to use for the deposit transaction. -The amount of ETH to deposit. +- #### amount + - **Type:** `bigint` + - The amount of ETH to deposit. ### portal diff --git a/site/docs/actions/wallet/L1/writeDepositTransaction.md b/site/docs/actions/wallet/L1/writeDepositTransaction.md index fd29bb9..46c5a1e 100644 --- a/site/docs/actions/wallet/L1/writeDepositTransaction.md +++ b/site/docs/actions/wallet/L1/writeDepositTransaction.md @@ -107,6 +107,11 @@ A [Transaction Hash](https://viem.sh/docs/glossary/terms#hash). - **Default:** `0x` - The calldata of the L2 transaction +- ### mint (optional) + - **Type:** `bigint` + - **Default** `0` + - Value in wei sent with this transaction. This value will be credited to the balance of the caller address on L2 _before_ the L2 transaction created by this transaction is made. + ```ts await walletClient.writeDepositTransaction({ args: { // [!code focus:7] @@ -133,20 +138,6 @@ await walletClient.writeDepositTransaction({ }) ``` -### value (optional) - -- **Type:** `number` - -Value in wei sent with this transaction. This value will be credited to the balance of the caller address on L2 _before_ the L2 transaction created by this transaction is made. - -```ts -await walletClient.writeDepositTransaction({ - args, - portalAddress: portal, - value: parseEther(1), // [!code focus:1] -}) -``` - ::: tip `account`, `accessList`, `chain`, `dataSuffix`, `gasPrice`, `maxFeePerGas`, `maxPriorityFeePerGas`, and `nonce` can all also be passed and behave as with any viem writeContract call. See [their documentation](https://viem.sh/docs/contract/writeContract.html#writecontract) for more details. ::: diff --git a/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md b/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md index 0aee8e6..f9ad149 100644 --- a/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md +++ b/site/docs/actions/wallet/L1/writeFinalizeWithdrawalTransaction.md @@ -12,7 +12,7 @@ const withdrawal: FinalizeWithdrawalTransactionParameters = { const hash = await opStackL1WalletClient.writeFinalizeWithdrawalTranasction({ portal: baseAddresses.portal, - withdrawal, + args: { withdrawal }, account, }) ``` diff --git a/src/_test/live.test.ts b/src/_test/live.test.ts index 03bc073..99430d6 100644 --- a/src/_test/live.test.ts +++ b/src/_test/live.test.ts @@ -30,7 +30,7 @@ test('correctly retrieves L2 hash', async () => { const args: DepositTransactionParameters = { to: account.address, - value: 1n, + mint: 1n, data: '0x', gasLimit: 0n, isCreation: false, @@ -48,7 +48,6 @@ test('correctly retrieves L2 hash', async () => { const depositHash = await walletClient.writeDepositTransaction({ ...baseGoerliAddresses, args, - value: 1n, }) console.log('depositHash', depositHash) diff --git a/src/actions/public/L1/getSecondsToNextL2Output.ts b/src/actions/public/L1/getSecondsToNextL2Output.ts index d2eb1a6..02f94c7 100644 --- a/src/actions/public/L1/getSecondsToNextL2Output.ts +++ b/src/actions/public/L1/getSecondsToNextL2Output.ts @@ -44,6 +44,10 @@ export async function getSecondsToNextL2Output address, } as ReadContractParameters) + if (latestL2BlockNumber < latestBlockNumber) { + throw new Error(`latestBlock ${latestBlockNumber} is great than latestL2BlockNumber ${latestL2BlockNumber}!`) + } + const blocksTillUpdate = interval - (latestL2BlockNumber - latestBlockNumber) // NOTE(Wilson): incase there is some problem // e.g. output posting has stalled or the wrong latestL2BlockNumber is passed diff --git a/src/actions/public/L1/simulateDepositETH.test.ts b/src/actions/public/L1/simulateDepositETH.test.ts index 3e53778..f39ec36 100644 --- a/src/actions/public/L1/simulateDepositETH.test.ts +++ b/src/actions/public/L1/simulateDepositETH.test.ts @@ -10,8 +10,8 @@ test('default', async () => { args: { to: accounts[0].address, gasLimit: 100000, + amount: 1n, }, - value: 1n, account: accounts[0].address, ...baseAddresses, }) diff --git a/src/actions/public/L1/simulateDepositETH.ts b/src/actions/public/L1/simulateDepositETH.ts index fdbfcf4..5f56b47 100644 --- a/src/actions/public/L1/simulateDepositETH.ts +++ b/src/actions/public/L1/simulateDepositETH.ts @@ -10,7 +10,7 @@ export type SimulateDepositETHParameters< _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> } - & L1SimulateActionBaseType + & Omit, 'value'> export type SimulateDepositETHReturnType< TChain extends Chain | undefined, @@ -28,9 +28,8 @@ export async function simulateDepositETH< >( client: PublicClient, { - args: { to, gasLimit, data = '0x' }, + args: { to, gasLimit, data = '0x', amount }, portal, - value, ...rest }: SimulateDepositETHParameters, ): Promise> { @@ -38,8 +37,8 @@ export async function simulateDepositETH< address: resolveAddress(portal), abi: ABI, functionName: FUNCTION, - args: [to, value, gasLimit, false, data], - value, + args: [to, amount, gasLimit, false, data], + value: amount, ...rest, } as unknown as SimulateContractParameters) } diff --git a/src/actions/wallet/L1/writeDepositETH.test.ts b/src/actions/wallet/L1/writeDepositETH.test.ts index 974a064..422dbbe 100644 --- a/src/actions/wallet/L1/writeDepositETH.test.ts +++ b/src/actions/wallet/L1/writeDepositETH.test.ts @@ -15,8 +15,8 @@ test('default', async () => { to: accounts[0].address, gasLimit: 21000, data: '0x', + amount: 1n, }, - value: 1n, ...baseAddresses, account: accounts[0].address, }), @@ -24,15 +24,15 @@ test('default', async () => { }) test('correctly deposits ETH', async () => { + const amount = 1n const args: DepositETHParameters = { to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb', gasLimit: 25000, data: '0x', + amount, } - const value = 1n const hash = await writeDepositETH(walletClient, { args, - value, ...baseAddresses, account: accounts[0].address, }) @@ -52,7 +52,7 @@ test('correctly deposits ETH', async () => { expect(deposit.args.to.toLowerCase()).toEqual(args.to) const expectOpaqueData = encodePacked( ['uint', 'uint', 'uint64', 'bool', 'bytes'], - [value, value, BigInt(args.gasLimit), false, '0x'], + [amount, amount, BigInt(args.gasLimit), false, '0x'], ) expect(deposit.args.opaqueData).toEqual(expectOpaqueData) }) diff --git a/src/actions/wallet/L1/writeDepositETH.ts b/src/actions/wallet/L1/writeDepositETH.ts index 2b8a3d2..e1fa46c 100644 --- a/src/actions/wallet/L1/writeDepositETH.ts +++ b/src/actions/wallet/L1/writeDepositETH.ts @@ -11,10 +11,13 @@ export type WriteDepositETHParameters< _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> } - & L1WriteActionBaseType< - TChain, - TAccount, - TChainOverride + & Omit< + L1WriteActionBaseType< + TChain, + TAccount, + TChainOverride + >, + 'value' > /** @@ -29,9 +32,8 @@ export async function writeDepositETH< >( client: WalletClient, { - args: { to, gasLimit, data }, + args: { to, gasLimit, data, amount }, portal, - value, ...rest }: WriteDepositETHParameters< TChain, @@ -40,9 +42,9 @@ export async function writeDepositETH< >, ): Promise { return writeDepositTransaction(client, { - args: { to, value, gasLimit: BigInt(gasLimit), data }, + args: { to, value: amount, gasLimit: BigInt(gasLimit), data }, portal: resolveAddress(portal), - value, + value: amount, ...rest, } as unknown as WriteDepositTransactionParameters< TChain, diff --git a/src/actions/wallet/L1/writeDepositTransaction.test.ts b/src/actions/wallet/L1/writeDepositTransaction.test.ts index f985c1d..a3c5b19 100644 --- a/src/actions/wallet/L1/writeDepositTransaction.test.ts +++ b/src/actions/wallet/L1/writeDepositTransaction.test.ts @@ -17,8 +17,8 @@ test('default', async () => { gasLimit: 25000n, data: '0x', isCreation: false, + mint: 0n, }, - value: 0n, ...baseAddresses, account: accounts[0].address, }), @@ -32,6 +32,7 @@ test('sends transaction to correct infered address', async () => { gasLimit: 0n, data: '0x', isCreation: false, + mint: 1n, } const gas = await estimateGas(rollupPublicClient, { @@ -45,7 +46,6 @@ test('sends transaction to correct infered address', async () => { const hash = await writeDepositTransaction(walletClient, { args, - value: 1n, ...baseAddresses, account: accounts[0].address, }) @@ -65,8 +65,8 @@ test('sends transaction to correct explicit address', async () => { to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb', value: 1n, gasLimit: 25000n, + mint: 1n, }, - value: 1n, portal: portal, account: accounts[0].address, }) @@ -84,10 +84,10 @@ test('creates correct deposit transaction', async () => { gasLimit: 25000n, data: '0x', isCreation: false, + mint: 1n, } const hash = await writeDepositTransaction(walletClient, { args, - value: args.value!, ...baseAddresses, account: accounts[0].address, }) @@ -119,13 +119,13 @@ test('correctly passes arugments', async () => { gasLimit: 25000n, data: '0x', isCreation: false, + mint: 2n, } const hash = await writeDepositTransaction(walletClient, { args, ...baseAddresses, account: accounts[0].address, - value: 2n, }) await mine(testClient, { blocks: 1 }) @@ -145,13 +145,13 @@ test('uses defaults for data, isCreation, and value', async () => { const args: DepositTransactionParameters = { to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb', gasLimit: 25000n, + mint: 0n, } const hash = await writeDepositTransaction(walletClient, { args, ...baseAddresses, account: accounts[0].address, - value: 0n, }) await mine(testClient, { blocks: 1 }) @@ -173,8 +173,8 @@ test('errors if portal not passed', async () => { args: { to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb', gasLimit: 25000n, + mint: 0n, }, - value: 0n, account: accounts[0].address, }) ).rejects.toThrowError('Invalid address') diff --git a/src/actions/wallet/L1/writeDepositTransaction.ts b/src/actions/wallet/L1/writeDepositTransaction.ts index 68a4b9c..0bcc693 100644 --- a/src/actions/wallet/L1/writeDepositTransaction.ts +++ b/src/actions/wallet/L1/writeDepositTransaction.ts @@ -22,6 +22,7 @@ export type DepositTransactionParameters = { value?: bigint isCreation?: boolean data?: Hex + mint?: bigint } export type WriteDepositTransactionParameters< @@ -31,10 +32,13 @@ export type WriteDepositTransactionParameters< _chainId = TChain extends Chain ? TChain['id'] : number, > = & { args: DepositTransactionParameters; portal: RawOrContractAddress<_chainId> } - & L1WriteActionBaseType< - TChain, - TAccount, - TChainOverride + & Omit< + L1WriteActionBaseType< + TChain, + TAccount, + TChainOverride + >, + 'value' > /** @@ -59,7 +63,7 @@ export async function writeDepositTransaction< >( client: WalletClient, { - args: { to, value = 0n, gasLimit, isCreation = false, data = '0x' }, + args: { to, value = 0n, gasLimit, isCreation = false, data = '0x', mint = 0n }, portal, ...rest }: WriteDepositTransactionParameters< @@ -73,6 +77,7 @@ export async function writeDepositTransaction< abi: ABI, functionName: FUNCTION, args: [to, value, gasLimit, isCreation, data], + value: mint, ...rest, } as unknown as WriteContractParameters< typeof ABI, diff --git a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.test.ts b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.test.ts index 82a8acb..775b3ac 100644 --- a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.test.ts +++ b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.test.ts @@ -21,7 +21,7 @@ test('succesfully submits finalizeWithdrawalTransaction', async () => { const hash = await writeFinalizeWithdrawalTranasction(walletClient, { ...baseAddresses, - withdrawal, + args: { withdrawal }, account: accounts[0].address, }) await mine(testClient, { blocks: 1 }) diff --git a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts index 3118549..13f1ce3 100644 --- a/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts +++ b/src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts @@ -17,7 +17,7 @@ export type WriteFinalizeWithdrawalTransactionParameters< TChainOverride extends Chain | undefined = Chain | undefined, _chainId = TChain extends Chain ? TChain['id'] : number, > = - & { withdrawal: FinalizeWithdrawalTransactionParameters; portal: RawOrContractAddress<_chainId> } + & { args: { withdrawal: FinalizeWithdrawalTransactionParameters }; portal: RawOrContractAddress<_chainId> } & L1WriteActionBaseType< TChain, TAccount, @@ -38,7 +38,7 @@ export async function writeFinalizeWithdrawalTranasction< >( client: WalletClient, { - withdrawal, + args: { withdrawal }, portal, ...rest }: WriteFinalizeWithdrawalTransactionParameters< diff --git a/src/types/depositETH.ts b/src/types/depositETH.ts index bb0310a..fba6ca8 100644 --- a/src/types/depositETH.ts +++ b/src/types/depositETH.ts @@ -8,4 +8,5 @@ export type DepositETHParameters = { to: Address gasLimit: number data?: Hex + amount: bigint } diff --git a/vitest.config.ts b/vitest.config.ts index 13c627d..d042548 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -19,7 +19,7 @@ export default defineConfig({ lines: 95, statements: 95, functions: 90, - branches: 93.82, + branches: 90, thresholdAutoUpdate: true, reporter: ['text', 'json-summary', 'json'], exclude: [