Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add write contract deposit docs #151

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions site/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export default defineConfig({
{
text: 'L1',
items: [
{
text: 'writeContractDeposit',
link: '/docs/actions/wallet/L1/writeContractDeposit',
},
{
text: 'writeDepositERC20',
link: '/docs/actions/wallet/L1/writeDepositERC20',
Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/public/L1/getOutputForL2Block.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ The block number of the L2 block for which to get the output.

### l2OutputOracle

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The address of the L2OutputOracle contract where the `getOutputForL2Block` call will be made.
4 changes: 2 additions & 2 deletions site/docs/actions/public/L1/getSecondsToFinalizable.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Returns a `number` representative of the seconds until withdrawal finalization.

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The address of the `OptimismPortal` contract where the `readProvenWithdrawals` call will be made.

### l2OutputOracle

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The address of the L2OutputOracle contract where the `FINALIZATION_PERIOD_SECONDS` call will be made.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/public/L1/getSecondsToNextL2Output.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ The latest L2 block number.

### l2OutputOracle

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The address of the L2OutputOracle contract.
2 changes: 1 addition & 1 deletion site/docs/actions/public/L1/readFinalizedWithdrawals.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Returns a `boolean` for whether the withdrawal has been finalized.

### portalAddress

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract where the sendMessage call should be made.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/public/L1/readProvenWithdrawals.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ProvenWithdrawal = {

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract where the sendMessage call should be made.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/public/L1/simulateDepositERC20.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Returns a `request` that can be passed to Viem's `writeContract` and a `result`

### l1StandardBridge

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `L1StandardBridge` contract.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/public/L1/simulateDepositETH.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The amount of ETH to deposit.

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/public/L1/simulateDepositTransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ await publicClient.simulateDepositTransaction({

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract where the depositTransaction call should be made.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type FinalizeWithdrawalTransactionParameters = {

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ await walletClient.simulateProveWithdrawalTransaction({

### portal(optional)

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract where the sendMessage call should be made.

Expand Down
94 changes: 94 additions & 0 deletions site/docs/actions/wallet/L1/writeContractDeposit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# writeContractDeposit

Creates an L1 to L2 transaction by depositing into a contract on L2. This function serves as a specialized version of Viem's `writeContract`, adapted for L1 -> L2 transactions.

```ts [example.ts]
import { erc721ABI } from 'wagmi'
import { writeContractDeposit } from 'your-library'
import { walletClient } from 'your-library-client-setup'
import { baseAddresses } from 'your-library/chains'

const txHash = await writeContractDeposit(walletClient, {
abi: erc721ABI,
address: '0x6171f829e107f70b58d67594c6b62a7d3eb7f23b',
functionName: 'approve',
args: ['0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', 2048n],
account: '0xYourAccountAddress',
l2GasLimit: 100000n,
...baseAddresses,
})
```

## Return Value

Returns a transaction hash for the L2 transaction being initiated. The transaction hash conforms to Viem's [`WriteContractReturnType`](https://viem.sh/docs/glossary/types#writecontractreturntype).

## Parameters

### abi

- **Type:** `Abi | readonly unknown[]`

The ABI (Application Binary Interface) related to the contract.

### address

- **Type:** `Address`

The contract address on L2 that you are interacting with.

### functionName

- **Type:** `string`

The contract function name to call on L2.

### args

- **Type:** `Array`

The arguments to pass to the function. Must match the function signature.

### account

- **Type:** `Account | Address`

Account address initiating the L2 transaction. If not supplied, defaults to `client.account`.

### l2GasLimit

- **Type:** `bigint`

Gas limit for the L2 transaction.

### l2MsgValue (Optional)

- **Type:** `bigint`

The Ether value sent along with the L2 transaction. Defaults to `0n`.

### strict (Optional)

- **Type:** `boolean`

If set to `true`, throws an error when called from a smart contract account. Defaults to `true`.

### portal

- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract, or equivalent, facilitating the L1 to L2 transition.

## Notes

- The function will throw an error if `strict` is `true` and the `account` is a smart contract. This is to mitigate unexpected behavior due to [address aliasing](https://github.com/ethereum-optimism/optimism/blob/develop/specs/deposits.md#address-aliasing).

- The function uses `encodeFunctionData` to create calldata for the L2 transaction, thus requiring ABI, function name, and args.

- This function wraps around `writeDepositTransaction` and adds additional logic to cater to L2 transactions from L1.

## Errors

- Throws "No account found" if no `account` is supplied and none is set in the `client`.

- Throws a strict mode error when called from a smart contract account with `strict` set to `true`.
2 changes: 1 addition & 1 deletion site/docs/actions/wallet/L1/writeDepositERC20.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Extra data to include in the transaction.

### l1StandardBridge

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `L1StandardBridge` contract.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/wallet/L1/writeDepositETH.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The amount of ETH to deposit.

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/wallet/L1/writeDepositTransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ await walletClient.writeDepositTransaction({

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract where the depositTransaction call should be made.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ type FinalizeWithdrawalTransactionParameters = {

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ await walletClient.writeProveWithdrawalTransaction({

### portal

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `OptimismPortal` contract where the sendMessage call should be made.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/actions/wallet/L1/writeSendMessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ await walletClient.writeSendMessage({

### l1CrossDomainMessenger

- **Type:** [`RawOrContractAddress`](https://viem.sh/docs/glossary/types#raworcontractaddress)
- **Type:** [`RawOrContractAddress`](https://opviem.sh/docs/glossary/types.html#raworcontractaddress)

The `L1CrossDomainMessenger` contract where the sendMessage call should be made.

Expand Down
Loading