Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
90 changes: 0 additions & 90 deletions src/experimental/arbitrumDeposit/actions.ts

This file was deleted.

32 changes: 32 additions & 0 deletions src/experimental/arbitrumDeposit/depositEth.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting action in their own function, means user can either call it with depositEth(client, params) or client.depositEth(params)

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Account, Address, encodeFunctionData, WalletClient } from 'viem'
import { inboxAbi } from './abis/inbox'
import { localEthChain } from '../chains'
import { ArbitrumNetwork } from '../../lib/dataEntities/networks'

export type DepositEthParams = {
amount: bigint
account: Account | Address
gasPrice: bigint
to: ArbitrumNetwork
}
export async function depositEth(
walletClient: WalletClient,
{ amount, account, gasPrice, to }: DepositEthParams
) {
const signedTx = await walletClient.signTransaction({
to: to.ethBridge.inbox as Address,
value: amount,
data: encodeFunctionData({
abi: inboxAbi,
functionName: 'depositEth',
}),
from: typeof account === 'string' ? account : account.address,
account,
chain: localEthChain,
gas: BigInt('130000'),
maxFeePerGas: gasPrice,
maxPriorityFeePerGas: gasPrice,
})

return signedTx
}
16 changes: 16 additions & 0 deletions src/experimental/arbitrumDeposit/publicActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PublicClient } from 'viem'
import { sendDepositEth, SendDepositEthParams } from './sendDepositEth'

export type ArbitrumPublicActions = {
sendDepositEth: (args: SendDepositEthParams) => Promise<`0x${string}`>
}

export function arbitrumPublicActions() {
return <TClient extends PublicClient>(
publicClient: TClient
): ArbitrumPublicActions => {
return {
sendDepositEth: args => sendDepositEth(publicClient, args),
}
}
}
22 changes: 22 additions & 0 deletions src/experimental/arbitrumDeposit/sendDepositEth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { parseTransaction, PublicClient, serializeTransaction } from 'viem'

export type SendDepositEthParams = {
signedTx: any
}
export async function sendDepositEth(
publicClient: PublicClient,
{ signedTx }: SendDepositEthParams
) {
// Parse and serialize with L2 chain ID
const parsedTx = parseTransaction(signedTx.raw)
const serializedTx = serializeTransaction({
...parsedTx,
})

// Send to L2
const hash = await publicClient.sendRawTransaction({
serializedTransaction: serializedTx,
})

return hash
}
16 changes: 16 additions & 0 deletions src/experimental/arbitrumDeposit/walletActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { type WalletClient } from 'viem'
import { depositEth, DepositEthParams } from './depositEth'

export type ArbitrumWalletActions = {
depositEth: (args: DepositEthParams) => Promise<`0x${string}`>
}

export function arbitrumWalletActions() {
return <TClient extends WalletClient>(
walletClient: TClient
): ArbitrumWalletActions => {
return {
depositEth: args => depositEth(walletClient, args),
}
}
}
Loading