Skip to content

Commit

Permalink
Clean up APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
zencephalon committed Oct 26, 2023
1 parent 47cc5c1 commit 878f603
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 44 deletions.
10 changes: 4 additions & 6 deletions site/docs/actions/public/L1/simulateDepositETH.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const { request } = await publicClient.simulateDepositETH({
args: {
to: '0xFd4F24676eD4588928213F37B126B53c07186F45',
gasLimit: 100000,
amount: 1n,
},
value: 1n,
portal: baseAddresses.portal,
account: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
})
Expand All @@ -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

Expand Down
26 changes: 10 additions & 16 deletions site/docs/actions/wallet/L1/writeDepositETH.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const hash = await walletClient.writeDepositETH({
args: {
to: '0xFd4F24676eD4588928213F37B126B53c07186F45',
gasLimit: 100000,
amount: 1n,
},
...baseAddresses,
value: 1n,
account: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
})
```
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const withdrawal: FinalizeWithdrawalTransactionParameters = {

const hash = await opStackL1WalletClient.writeFinalizeWithdrawalTranasction({
portal: baseAddresses.portal,
withdrawal,
args: { withdrawal },
account,
})
```
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/L1/simulateDepositETH.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ test('default', async () => {
args: {
to: accounts[0].address,
gasLimit: 100000,
amount: 1n,
},
value: 1n,
account: accounts[0].address,
...baseAddresses,
})
Expand Down
9 changes: 4 additions & 5 deletions src/actions/public/L1/simulateDepositETH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type SimulateDepositETHParameters<
_chainId = TChain extends Chain ? TChain['id'] : number,
> =
& { args: DepositETHParameters; portal: RawOrContractAddress<_chainId> }
& L1SimulateActionBaseType<TChain, TChainOverride, typeof ABI, typeof FUNCTION>
& Omit<L1SimulateActionBaseType<TChain, TChainOverride, typeof ABI, typeof FUNCTION>, 'value'>

export type SimulateDepositETHReturnType<
TChain extends Chain | undefined,
Expand All @@ -28,18 +28,17 @@ export async function simulateDepositETH<
>(
client: PublicClient<Transport, TChain>,
{
args: { to, gasLimit, data = '0x' },
args: { to, gasLimit, data = '0x', amount },
portal,
value,
...rest
}: SimulateDepositETHParameters<TChain, TChainOverride>,
): Promise<SimulateDepositETHReturnType<TChain, TChainOverride>> {
return simulateContract(client, {
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<typeof ABI, typeof FUNCTION, TChain, TChainOverride>)
}
8 changes: 4 additions & 4 deletions src/actions/wallet/L1/writeDepositETH.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ test('default', async () => {
to: accounts[0].address,
gasLimit: 21000,
data: '0x',
amount: 1n,
},
value: 1n,
...baseAddresses,
account: accounts[0].address,
}),
).toBeDefined()
})

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,
})
Expand All @@ -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)
})
18 changes: 10 additions & 8 deletions src/actions/wallet/L1/writeDepositETH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
>

/**
Expand All @@ -29,9 +32,8 @@ export async function writeDepositETH<
>(
client: WalletClient<Transport, TChain, TAccount>,
{
args: { to, gasLimit, data },
args: { to, gasLimit, data, amount },
portal,
value,
...rest
}: WriteDepositETHParameters<
TChain,
Expand All @@ -40,9 +42,9 @@ export async function writeDepositETH<
>,
): Promise<WriteContractReturnType> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions src/actions/wallet/L1/writeFinalizeWithdrawalTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,7 +38,7 @@ export async function writeFinalizeWithdrawalTranasction<
>(
client: WalletClient<Transport, TChain, TAccount>,
{
withdrawal,
args: { withdrawal },
portal,
...rest
}: WriteFinalizeWithdrawalTransactionParameters<
Expand Down
1 change: 1 addition & 0 deletions src/types/depositETH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export type DepositETHParameters = {
to: Address
gasLimit: number
data?: Hex
amount: bigint
}

0 comments on commit 878f603

Please sign in to comment.