Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Nov 15, 2024
1 parent 93fed51 commit a7394e8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/experimental/arbitrumDeposit/abis/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const inboxAbi = [
name: 'depositEth',
outputs: [{ type: 'uint256' }],
stateMutability: 'payable',
type: 'function'
type: 'function',
},
{
inputs: [
Expand All @@ -15,28 +15,26 @@ export const inboxAbi = [
{ name: 'callValueRefundAddress', type: 'address' },
{ name: 'gasLimit', type: 'uint256' },
{ name: 'maxFeePerGas', type: 'uint256' },
{ name: 'data', type: 'bytes' }
{ name: 'data', type: 'bytes' },
],
name: 'createRetryableTicket',
outputs: [{ type: 'uint256' }],
stateMutability: 'payable',
type: 'function'
type: 'function',
},
{
anonymous: false,
inputs: [
{ indexed: false, name: 'messageNum', type: 'uint256' },
{ indexed: false, name: 'data', type: 'bytes' }
{ indexed: false, name: 'data', type: 'bytes' },
],
name: 'InboxMessageDelivered',
type: 'event'
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: false, name: 'messageNum', type: 'uint256' }
],
inputs: [{ indexed: false, name: 'messageNum', type: 'uint256' }],
name: 'InboxMessageDeliveredFromOrigin',
type: 'event'
}
] as const
type: 'event',
},
] as const
23 changes: 23 additions & 0 deletions src/experimental/arbitrumDeposit/prepareDepositEthTransaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Account, Address, encodeFunctionData, PublicClient } from 'viem'
import { inboxAbi } from './abis/inbox'

export type PrepareDepositEthTransaction = {
amount: bigint
account: Account
inbox: Address
}
export async function prepareDepositEthTransaction(
publicClient: PublicClient,
{ amount, account, inbox }: PrepareDepositEthTransaction
) {
return publicClient.prepareTransactionRequest({
chain: publicClient.chain,
to: inbox,
data: encodeFunctionData({
abi: inboxAbi,
functionName: 'depositEth',
}),
value: amount,
account,
})
}
62 changes: 62 additions & 0 deletions src/experimental/createArbitrumClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Address, PublicClient, WalletClient } from 'viem'
import { arbitrum, arbitrumNova, arbitrumSepolia } from 'viem/chains'
import { prepareDepositEthTransaction } from './arbitrumDeposit/prepareDepositEthTransaction'

function getInboxFromChainId(
chainId:
| typeof arbitrum.id
| typeof arbitrumNova.id
| typeof arbitrumSepolia.id
) {
return {
[arbitrum.id]: '0x...',
[arbitrumNova.id]: '0x...',
[arbitrumSepolia.id]: '0x...',
}[chainId]
}

export async function createArbitrumClient({
parentChainPublicClient,
parentChainWalletClient,
childChainPublicClient,
childChainWalletClient,
}: {
parentChainPublicClient: PublicClient
parentChainWalletClient: WalletClient
childChainPublicClient: PublicClient
childChainWalletClient: WalletClient
}): Promise<{
depositEth: (amount: bigint) => void
}> {
return {
async depositEth(amount: bigint) {
const tx = await prepareDepositEthTransaction(parentChainPublicClient, {
amount,
account: parentChainWalletClient.account!,
inbox: getInboxFromChainId(
childChainWalletClient.chain?.id!

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Lint on Node.js v20

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Unit) on Node.js v18

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Lint on Node.js v18

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Unit) on Node.js v20

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (16 decimals)

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (20 decimals)

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (20 decimals)

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (18 decimals)

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (18 decimals)

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.

Check failure on line 37 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (16 decimals)

Argument of type 'number' is not assignable to parameter of type '42161 | 42170 | 421614'.
) as Address,
})
const hash = await parentChainPublicClient.sendRawTransaction({
serializedTransaction: await parentChainWalletClient.signTransaction(
tx

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Lint on Node.js v20

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Unit) on Node.js v18

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Lint on Node.js v18

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Unit) on Node.js v20

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (16 decimals)

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (20 decimals)

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (20 decimals)

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (18 decimals)

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (18 decimals)

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.

Check failure on line 42 in src/experimental/createArbitrumClient.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (16 decimals)

Argument of type '{ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; blo...' is not assignable to parameter of type '({ data?: `0x${string}` | undefined; value?: bigint | undefined; from: `0x${string}`; to?: `0x${string}` | null | undefined; accessList?: undefined; account: { client: Client; entryPoint: { abi: Abi; address: `0x${string}`; version: EntryPointVersion; }; ... 20 more ...; publicKey?: undefined; }; ... 13 more ...; bl...'.
),
})

// Await on childChainPublicClient for the transaction
return hash
},
}
}

/**
* const { depositEth } = createArbitrumClient({
* parentChainPublicClient,
* parentChainWalletClient,
* childChainPublicClient,
* childChainWalletClient,
* })
*
* depositEth({ amount: 150000n })
*
*/

0 comments on commit a7394e8

Please sign in to comment.