-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add weth gateway registration (#44)
- Loading branch information
1 parent
2186ccc
commit 3f7b15a
Showing
7 changed files
with
482 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Address, PublicClient } from 'viem'; | ||
import { validParentChainId } from './types/ParentChain'; | ||
import { CoreContracts } from './types/CoreContracts'; | ||
import { createRollupFetchTransactionHash } from './createRollupFetchTransactionHash'; | ||
import { createRollupPrepareTransactionReceipt } from './createRollupPrepareTransactionReceipt'; | ||
|
||
export type CreateRollupFetchCoreContractsParams = { | ||
rollup: Address; | ||
publicClient: PublicClient; | ||
}; | ||
|
||
export async function createRollupFetchCoreContracts({ | ||
rollup, | ||
publicClient, | ||
}: CreateRollupFetchCoreContractsParams): Promise<CoreContracts> { | ||
const chainId = publicClient.chain?.id; | ||
|
||
if (!validParentChainId(chainId)) { | ||
throw new Error('chainId is undefined'); | ||
} | ||
|
||
// getting core contract addresses | ||
const transactionHash = await createRollupFetchTransactionHash({ | ||
rollup, | ||
publicClient, | ||
}); | ||
|
||
const transactionReceipt = createRollupPrepareTransactionReceipt( | ||
await publicClient.waitForTransactionReceipt({ | ||
hash: transactionHash, | ||
}), | ||
); | ||
|
||
return transactionReceipt.getCoreContracts(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/createTokenBridgePrepareSetWethGatewayTransactionReceipt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { PublicClient, TransactionReceipt } from 'viem'; | ||
import { L1ToL2MessageStatus, L1TransactionReceipt } from '@arbitrum/sdk'; | ||
import { TransactionReceipt as EthersTransactionReceipt } from '@ethersproject/abstract-provider'; | ||
|
||
import { publicClientToProvider } from './ethers-compat/publicClientToProvider'; | ||
import { viemTransactionReceiptToEthersTransactionReceipt } from './ethers-compat/viemTransactionReceiptToEthersTransactionReceipt'; | ||
import { ethersTransactionReceiptToViemTransactionReceipt } from './ethers-compat/ethersTransactionReceiptToViemTransactionReceipt'; | ||
|
||
type RedeemedRetryableTicket = { | ||
status: L1ToL2MessageStatus.REDEEMED; | ||
l2TxReceipt: EthersTransactionReceipt; | ||
}; | ||
|
||
export type WaitForRetryablesParameters = { | ||
orbitPublicClient: PublicClient; | ||
}; | ||
|
||
export type WaitForRetryablesResult = [TransactionReceipt]; | ||
|
||
export type CreateTokenBridgeSetWethGatewayTransactionReceipt = TransactionReceipt & { | ||
waitForRetryables(params: WaitForRetryablesParameters): Promise<WaitForRetryablesResult>; | ||
}; | ||
|
||
export function createTokenBridgePrepareSetWethGatewayTransactionReceipt( | ||
txReceipt: TransactionReceipt, | ||
): CreateTokenBridgeSetWethGatewayTransactionReceipt { | ||
return { | ||
...txReceipt, | ||
waitForRetryables: async function ({ | ||
orbitPublicClient, | ||
}: WaitForRetryablesParameters): Promise<WaitForRetryablesResult> { | ||
const ethersTxReceipt = viemTransactionReceiptToEthersTransactionReceipt(txReceipt); | ||
const parentChainTxReceipt = new L1TransactionReceipt(ethersTxReceipt); | ||
const orbitProvider = publicClientToProvider(orbitPublicClient); | ||
const messages = await parentChainTxReceipt.getL1ToL2Messages(orbitProvider); | ||
const messagesResults = await Promise.all(messages.map((message) => message.waitForStatus())); | ||
|
||
if (messagesResults.length !== 1) { | ||
throw Error(`Unexpected number of retryable tickets: ${messagesResults.length}`); | ||
} | ||
|
||
if (messagesResults[0].status !== L1ToL2MessageStatus.REDEEMED) { | ||
throw Error(`Unexpected status for retryable ticket: ${messages[0].retryableCreationId}`); | ||
} | ||
|
||
return ( | ||
// these type casts are both fine as we already checked everything above | ||
(messagesResults as unknown as [RedeemedRetryableTicket]) | ||
// | ||
.map((result) => | ||
ethersTransactionReceiptToViemTransactionReceipt(result.l2TxReceipt), | ||
) as WaitForRetryablesResult | ||
); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.