1
- import { WalletClient , GetFunctionArgs } from 'viem' ;
1
+ import { PublicClient , WalletClient , GetFunctionArgs } from 'viem' ;
2
2
3
3
import { rollupCreator } from './contracts' ;
4
+ import { validParentChainId } from './types/ParentChain' ;
4
5
import { defaults } from './createRollupDefaults' ;
5
6
import { createRollupGetCallValue } from './createRollupGetCallValue' ;
6
7
import { createRollupGetMaxDataSize } from './createRollupGetMaxDataSize' ;
@@ -11,7 +12,7 @@ import {
11
12
import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress' ;
12
13
import { ChainConfig } from './types/ChainConfig' ;
13
14
import { isAnyTrustChainConfig } from './utils/isAnyTrustChainConfig' ;
14
- import type { OrbitClient } from './orbitClient ' ;
15
+ import { getValidChainId } from './utils/getters ' ;
15
16
16
17
export type CreateRollupFunctionInputs = GetFunctionArgs <
17
18
typeof rollupCreator . abi ,
@@ -25,16 +26,20 @@ export type CreateRollupParams = Pick<CreateRollupFunctionInputs[0], RequiredKey
25
26
26
27
export async function createRollup ( {
27
28
params,
28
- orbitClient ,
29
+ publicClient ,
29
30
walletClient,
30
31
} : {
31
32
params : CreateRollupParams ;
32
- orbitClient : OrbitClient ;
33
+ publicClient : PublicClient ;
33
34
walletClient : WalletClient ;
34
35
} ) : Promise < CreateRollupTransactionReceipt > {
35
- const chainId = orbitClient . getValidChainId ( ) ;
36
+ const chainId = getValidChainId ( publicClient ) ;
36
37
const account = walletClient . account ?. address ;
37
38
39
+ if ( ! validParentChainId ( chainId ) ) {
40
+ throw new Error ( 'chainId is undefined' ) ;
41
+ }
42
+
38
43
if ( typeof account === 'undefined' ) {
39
44
throw new Error ( 'account is undefined' ) ;
40
45
}
@@ -50,8 +55,8 @@ export async function createRollup({
50
55
const maxDataSize = createRollupGetMaxDataSize ( chainId ) ;
51
56
const paramsWithDefaults = { ...defaults , ...params , maxDataSize } ;
52
57
53
- const { request } = await orbitClient . simulateContract ( {
54
- address : orbitClient . getRollupCreatorAddress ( ) ,
58
+ const { request } = await publicClient . simulateContract ( {
59
+ address : rollupCreator . address [ chainId ] ,
55
60
abi : rollupCreator . abi ,
56
61
functionName : 'createRollup' ,
57
62
args : [ paramsWithDefaults ] ,
@@ -60,7 +65,7 @@ export async function createRollup({
60
65
} ) ;
61
66
62
67
const hash = await walletClient . writeContract ( request ) ;
63
- const txReceipt = await orbitClient . waitForTransactionReceipt ( { hash } ) ;
68
+ const txReceipt = await publicClient . waitForTransactionReceipt ( { hash } ) ;
64
69
65
70
return createRollupPrepareTransactionReceipt ( txReceipt ) ;
66
71
}
0 commit comments