-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathcreateTokenBridgeFetchTokenBridgeContracts.ts
More file actions
88 lines (79 loc) · 2.77 KB
/
createTokenBridgeFetchTokenBridgeContracts.ts
File metadata and controls
88 lines (79 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Address, PublicClient, Transport, Chain } from 'viem';
import { tokenBridgeCreatorABI } from './contracts/TokenBridgeCreator';
import { Prettify } from './types/utils';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { TokenBridgeContracts } from './types/TokenBridgeContracts';
import { getTokenBridgeCreatorAddress } from './utils/getters';
export type CreateTokenBridgeFetchTokenBridgeContractsParams<TChain extends Chain | undefined> =
Prettify<
WithTokenBridgeCreatorAddressOverride<{
inbox: Address;
parentChainPublicClient: PublicClient<Transport, TChain>;
}>
>;
export async function createTokenBridgeFetchTokenBridgeContracts<TChain extends Chain | undefined>({
inbox,
parentChainPublicClient,
tokenBridgeCreatorAddressOverride,
}: CreateTokenBridgeFetchTokenBridgeContractsParams<TChain>): Promise<TokenBridgeContracts> {
const tokenBridgeCreatorAddress =
tokenBridgeCreatorAddressOverride ?? getTokenBridgeCreatorAddress(parentChainPublicClient);
// getting parent chain addresses
const [
parentChainRouter,
parentChainStandardGateway,
parentChainCustomGateway,
parentChainWethGateway,
parentChainWeth,
] = await parentChainPublicClient.readContract({
address: tokenBridgeCreatorAddress,
abi: tokenBridgeCreatorABI,
functionName: 'inboxToL1Deployment',
args: [inbox],
});
const parentChainMulticall = await parentChainPublicClient.readContract({
address: tokenBridgeCreatorAddress,
abi: tokenBridgeCreatorABI,
functionName: 'l1Multicall',
});
const parentChainContracts = {
router: parentChainRouter,
standardGateway: parentChainStandardGateway,
customGateway: parentChainCustomGateway,
wethGateway: parentChainWethGateway,
weth: parentChainWeth,
multicall: parentChainMulticall,
};
// getting orbit chain addresses
const [
orbitChainRouter,
orbitChainStandardGateway,
orbitChainCustomGateway,
orbitChainWethGateway,
orbitChainWeth,
orbitChainProxyAdmin,
orbitChainBeaconProxyFactory,
orbitChainUpgradeExecutor,
orbitChainMulticall,
] = await parentChainPublicClient.readContract({
address: tokenBridgeCreatorAddress,
abi: tokenBridgeCreatorABI,
functionName: 'inboxToL2Deployment',
args: [inbox],
});
const orbitChainContracts = {
router: orbitChainRouter,
standardGateway: orbitChainStandardGateway,
customGateway: orbitChainCustomGateway,
wethGateway: orbitChainWethGateway,
weth: orbitChainWeth,
proxyAdmin: orbitChainProxyAdmin,
beaconProxyFactory: orbitChainBeaconProxyFactory,
upgradeExecutor: orbitChainUpgradeExecutor,
multicall: orbitChainMulticall,
};
return {
parentChainContracts,
orbitChainContracts,
};
}