-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
- Loading branch information
There are no files selected for viewing
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, | ||
}) | ||
} |
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 GitHub Actions / Lint on Node.js v20
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Unit) on Node.js v18
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Lint on Node.js v18
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Unit) on Node.js v20
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (16 decimals)
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (20 decimals)
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (20 decimals)
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20 with L3
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (18 decimals)
Check failure on line 37 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (18 decimals)
|
||
) as Address, | ||
}) | ||
const hash = await parentChainPublicClient.sendRawTransaction({ | ||
serializedTransaction: await parentChainWalletClient.signTransaction( | ||
tx | ||
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Lint on Node.js v20
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Unit) on Node.js v18
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Lint on Node.js v18
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Unit) on Node.js v20
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (16 decimals)
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (20 decimals)
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (20 decimals)
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20 with L3
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token (18 decimals)
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (18 decimals)
Check failure on line 42 in src/experimental/createArbitrumClient.ts GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token (16 decimals)
|
||
), | ||
}) | ||
|
||
// Await on childChainPublicClient for the transaction | ||
return hash | ||
}, | ||
} | ||
} | ||
|
||
/** | ||
* const { depositEth } = createArbitrumClient({ | ||
* parentChainPublicClient, | ||
* parentChainWalletClient, | ||
* childChainPublicClient, | ||
* childChainWalletClient, | ||
* }) | ||
* | ||
* depositEth({ amount: 150000n }) | ||
* | ||
*/ |