Skip to content

Commit 2c4642e

Browse files
authored
Merge branch 'main' into add-upgradeexecutor-setters
2 parents be60b3d + 7804ca2 commit 2c4642e

7 files changed

+134
-4
lines changed

audit-ci.jsonc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@
6565
// from: @arbitrum/token-bridge-contracts>@openzeppelin/contracts-upgradeable
6666
// from: @arbitrum/nitro-contracts>@openzeppelin/contracts
6767
// from: @arbitrum/token-bridge-contracts>@openzeppelin/contracts
68-
"GHSA-9vx6-7xxf-x967"
68+
"GHSA-9vx6-7xxf-x967",
69+
// https://github.com/advisories/GHSA-64vr-g452-qvp3
70+
// Vite DOM Clobbering gadget found in vite bundled scripts that leads to XSS
71+
// vite is not used in production
72+
// from: vitest > vite
73+
"GHSA-64vr-g452-qvp3",
74+
// https://github.com/advisories/GHSA-9cwx-2883-4wfx
75+
// server.fs.deny bypassed when using ?import&raw
76+
// vite is not used in production
77+
// from: vitest > vite
78+
"GHSA-9cwx-2883-4wfx",
79+
// https://github.com/advisories/GHSA-gcx4-mw62-g8wm
80+
// DOM Clobbering Gadget found in rollup bundled scripts that leads to XSS
81+
// vite is not used in production
82+
// from: vitest > vite
83+
"GHSA-gcx4-mw62-g8wm"
6984
]
7085
}

src/createRollupPrepareTransactionRequest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type CreateRollupPrepareTransactionRequestParams<TChain extends Chain | u
3232
WithRollupCreatorAddressOverride<{
3333
params: CreateRollupParams;
3434
account: Address;
35+
value?: bigint;
3536
publicClient: PublicClient<Transport, TChain>;
3637
gasOverrides?: TransactionRequestGasOverrides;
3738
}>
@@ -40,6 +41,7 @@ export type CreateRollupPrepareTransactionRequestParams<TChain extends Chain | u
4041
export async function createRollupPrepareTransactionRequest<TChain extends Chain | undefined>({
4142
params,
4243
account,
44+
value,
4345
publicClient,
4446
gasOverrides,
4547
rollupCreatorAddressOverride,
@@ -81,7 +83,7 @@ export async function createRollupPrepareTransactionRequest<TChain extends Chain
8183
chain: publicClient.chain,
8284
to: rollupCreatorAddressOverride ?? getRollupCreatorAddress(publicClient),
8385
data: createRollupEncodeFunctionData([paramsWithDefaults]),
84-
value: createRollupGetCallValue(paramsWithDefaults),
86+
value: value ?? createRollupGetCallValue(paramsWithDefaults),
8587
account,
8688
// if the base gas limit override was provided, hardcode gas to 0 to skip estimation
8789
// we'll set the actual value in the code below

src/createTokenBridge.integration.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,4 +436,52 @@ describe('createTokenBridge', () => {
436436
checkTokenBridgeContracts(tokenBridgeContracts);
437437
checkWethGateways(tokenBridgeContracts, { customFeeToken: true });
438438
});
439+
440+
it('should throw when createTokenBridge is called multiple times', async () => {
441+
const testnodeInformation = getInformationFromTestnode();
442+
443+
const tokenBridgeCreator = await deployTokenBridgeCreator({
444+
publicClient: nitroTestnodeL1Client,
445+
});
446+
447+
const cfg = {
448+
rollupOwner: l2RollupOwner.address,
449+
rollupAddress: testnodeInformation.rollup,
450+
account: l2RollupOwner,
451+
parentChainPublicClient: nitroTestnodeL1Client,
452+
orbitChainPublicClient: nitroTestnodeL2Client,
453+
tokenBridgeCreatorAddressOverride: tokenBridgeCreator,
454+
gasOverrides: {
455+
gasLimit: {
456+
base: 6_000_000n,
457+
},
458+
},
459+
retryableGasOverrides: {
460+
maxGasForFactory: {
461+
base: 20_000_000n,
462+
},
463+
maxGasForContracts: {
464+
base: 20_000_000n,
465+
},
466+
maxSubmissionCostForFactory: {
467+
base: 4_000_000_000_000n,
468+
},
469+
maxSubmissionCostForContracts: {
470+
base: 4_000_000_000_000n,
471+
},
472+
},
473+
setWethGatewayGasOverrides: {
474+
gasLimit: {
475+
base: 100_000n,
476+
},
477+
},
478+
};
479+
const { tokenBridgeContracts } = await createTokenBridge(cfg);
480+
await expect(createTokenBridge(cfg)).rejects.toThrowError(
481+
`Token bridge contracts for Rollup ${testnodeInformation.rollup} are already deployed`,
482+
);
483+
484+
checkTokenBridgeContracts(tokenBridgeContracts);
485+
checkWethGateways(tokenBridgeContracts, { customFeeToken: false });
486+
});
439487
});

src/createTokenBridge.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,58 @@ import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress';
3434
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
3535
import { TransactionRequestGasOverrides } from './utils/gasOverrides';
3636
import { getBlockExplorerUrl } from './utils/getBlockExplorerUrl';
37+
import { tokenBridgeCreatorABI } from './contracts/TokenBridgeCreator';
38+
import { getTokenBridgeCreatorAddress } from './utils';
39+
import { rollupABI } from './contracts/Rollup';
40+
41+
/**
42+
* If token bridge was already deployed, `createTokenBridge` will fail when waiting for retryables.
43+
* This function returns true if token bridge was deployed previously.
44+
*
45+
* @param {String} assertTokenBridgeDoesntExistParams.parentChainPublicClient - The parent chain Viem Public Client
46+
* @param {String} assertTokenBridgeDoesntExistParams.orbitChainPublicClient - The orbit chain Viem Public Client
47+
* @param {String=} assertTokenBridgeDoesntExistParams.tokenBridgeCreatorAddress - The TokenBridgeCreator address.
48+
* Default to getTokenBridgeCreatorAddress(parentChainPublicClient) if not provided
49+
* @param {String} assertTokenBridgeDoesntExistParams.rollupAddress - The address of the rollup on the parent chain
50+
*
51+
* @returns true if token bridge was already deployed
52+
*/
53+
export async function isTokenBridgeDeployed<
54+
TParentChain extends Chain | undefined,
55+
TOrbitChain extends Chain | undefined,
56+
>({
57+
parentChainPublicClient,
58+
orbitChainPublicClient,
59+
tokenBridgeCreatorAddress,
60+
rollupAddress,
61+
}: {
62+
parentChainPublicClient: PublicClient<Transport, TParentChain>;
63+
orbitChainPublicClient: PublicClient<Transport, TOrbitChain>;
64+
tokenBridgeCreatorAddress?: Address;
65+
rollupAddress: Address;
66+
}) {
67+
const inbox = await parentChainPublicClient.readContract({
68+
address: rollupAddress,
69+
abi: rollupABI,
70+
functionName: 'inbox',
71+
});
72+
73+
const [router] = await parentChainPublicClient.readContract({
74+
address: tokenBridgeCreatorAddress ?? getTokenBridgeCreatorAddress(parentChainPublicClient),
75+
abi: tokenBridgeCreatorABI,
76+
functionName: 'inboxToL2Deployment',
77+
args: [inbox],
78+
});
79+
80+
if (router) {
81+
const code = await orbitChainPublicClient.getBytecode({ address: router });
82+
if (code) {
83+
return true;
84+
}
85+
}
86+
87+
return false;
88+
}
3789

3890
export type CreateTokenBridgeParams<
3991
TParentChain extends Chain | undefined,
@@ -171,6 +223,17 @@ export async function createTokenBridge<
171223
}: CreateTokenBridgeParams<TParentChain, TOrbitChain>): Promise<
172224
CreateTokenBridgeResults<TParentChain, TOrbitChain>
173225
> {
226+
const isTokenBridgeAlreadyDeployed = await isTokenBridgeDeployed({
227+
parentChainPublicClient,
228+
orbitChainPublicClient,
229+
tokenBridgeCreatorAddress: tokenBridgeCreatorAddressOverride,
230+
rollupAddress,
231+
});
232+
233+
if (isTokenBridgeAlreadyDeployed) {
234+
throw new Error(`Token bridge contracts for Rollup ${rollupAddress} are already deployed`);
235+
}
236+
174237
const isCustomFeeTokenBridge = isCustomFeeTokenAddress(nativeTokenAddress);
175238
if (isCustomFeeTokenBridge) {
176239
// set the custom fee token

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import {
8080
CreateTokenBridgeParams,
8181
CreateTokenBridgeResults,
8282
createTokenBridge,
83+
isTokenBridgeDeployed,
8384
} from './createTokenBridge';
8485
import {
8586
createTokenBridgeEnoughCustomFeeTokenAllowance,
@@ -210,6 +211,7 @@ export {
210211
prepareKeyset,
211212
utils,
212213
//
214+
isTokenBridgeDeployed,
213215
CreateTokenBridgeParams,
214216
CreateTokenBridgeResults,
215217
createTokenBridge,

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@arbitrum/orbit-sdk",
33
"description": "TypeScript SDK for building Arbitrum Orbit chains",
4-
"version": "0.19.0",
4+
"version": "0.20.0-beta.1",
55
"main": "./dist/index.js",
66
"files": [
77
"./dist"

src/utils/getArbOSVersion.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ it('returns the ArbOS version of Arbitrum One', async () => {
1010
transport: http(),
1111
});
1212

13-
expect(await getArbOSVersion(arbitrumOneClient)).toBe(31);
13+
expect(await getArbOSVersion(arbitrumOneClient)).toBe(32);
1414
});
1515

1616
it('throws if the chain is not an Arbitrum chain', async () => {

0 commit comments

Comments
 (0)