Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-upgradeexecutorfetchprivilegedaccounts
Browse files Browse the repository at this point in the history
  • Loading branch information
TucksonDev authored Jan 8, 2024
2 parents d2c0ddc + 2a7d274 commit b05a446
Show file tree
Hide file tree
Showing 31 changed files with 197 additions and 135 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ARBISCAN_API_KEY=
PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659

25 changes: 24 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ jobs:
- name: Install node_modules
uses: OffchainLabs/actions/node-modules/install@main

check-formatting:
name: 'Check Formatting'
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Restore node_modules
uses: OffchainLabs/actions/node-modules/restore@main

- name: Check formatting with Prettier
run: yarn prettier:check

test-unit:
name: Test (Unit)
runs-on: ubuntu-latest
Expand Down Expand Up @@ -67,7 +81,16 @@ jobs:
- name: Set up the local node
uses: OffchainLabs/actions/run-nitro-test-node@main
with:
ref: 'use-tokenbridge-creator'
# todo: update once merged
nitro-testnode-ref: 937af32a3c92a9913121fb64229e2c6f91065ac2
# don't deploy the regular token bridge using arbitrum-sdk, as it will be deployed through the TokenBridgeCreator
no-token-bridge: true
# RollupCreator on L1 is deployed by default
# RollupCreator on L2 is deployed with --l3node
l3-node: true
# TokenBridgeCreator on L1 is deployed with --tokenbridge
# TokenBridgeCreator on L2 is deployed with --l3-token-bridge
args: --tokenbridge --l3-token-bridge

- name: Copy .env
run: cp ./.env.example ./.env
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/dist
src/generated.ts
src/examples/prepare-node-config/node-config.json
8 changes: 4 additions & 4 deletions examples/create-rollup-custom-fee-token/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function main() {

if (!(await createRollupEnoughCustomFeeTokenAllowance(allowanceParams))) {
const approvalTxRequest = await createRollupPrepareCustomFeeTokenApprovalTransactionRequest(
allowanceParams
allowanceParams,
);

// sign and send the transaction
Expand All @@ -88,13 +88,13 @@ async function main() {
const approvalTxReceipt = createRollupPrepareTransactionReceipt(
await parentChainPublicClient.waitForTransactionReceipt({
hash: approvalTxHash,
})
}),
);

console.log(
`Tokens approved in ${getBlockExplorerUrl(parentChain)}/tx/${
approvalTxReceipt.transactionHash
}`
}`,
);
}

Expand Down Expand Up @@ -122,7 +122,7 @@ async function main() {

// get the transaction receipt after waiting for the transaction to complete
const txReceipt = createRollupPrepareTransactionReceipt(
await parentChainPublicClient.waitForTransactionReceipt({ hash: txHash })
await parentChainPublicClient.waitForTransactionReceipt({ hash: txHash }),
);

console.log(`Deployed in ${getBlockExplorerUrl(parentChain)}/tx/${txReceipt.transactionHash}`);
Expand Down
2 changes: 1 addition & 1 deletion examples/create-rollup-eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function main() {

// get the transaction receipt after waiting for the transaction to complete
const txReceipt = createRollupPrepareTransactionReceipt(
await parentChainPublicClient.waitForTransactionReceipt({ hash: txHash })
await parentChainPublicClient.waitForTransactionReceipt({ hash: txHash }),
);

console.log(`Deployed in ${getBlockExplorerUrl(parentChain)}/tx/${txReceipt.transactionHash}`);
Expand Down
4 changes: 2 additions & 2 deletions examples/prepare-node-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ async function main() {

// get the transaction
const tx = createRollupPrepareTransaction(
await parentChainPublicClient.getTransaction({ hash: txHash })
await parentChainPublicClient.getTransaction({ hash: txHash }),
);

// get the transaction receipt
const txReceipt = createRollupPrepareTransactionReceipt(
await parentChainPublicClient.getTransactionReceipt({ hash: txHash })
await parentChainPublicClient.getTransactionReceipt({ hash: txHash }),
);

// get the chain config from the transaction inputs
Expand Down
2 changes: 1 addition & 1 deletion examples/set-valid-keyset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function main() {
const txReceipt = await parentChainPublicClient.waitForTransactionReceipt({ hash: txHash });

console.log(
`Keyset updated in ${getBlockExplorerUrl(parentChain)}/tx/${txReceipt.transactionHash}`
`Keyset updated in ${getBlockExplorerUrl(parentChain)}/tx/${txReceipt.transactionHash}`,
);
}

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
"generate": "wagmi generate",
"test:unit": "vitest unit.test",
"test:integration": "vitest integration.test",
"postinstall": "patch-package"
"postinstall": "patch-package",
"prettier:check": "prettier --check '**/*.{ts,md,json,yml}'",
"prettier:format": "prettier --write '**/*.{ts,md,json,yml}'"
},
"devDependencies": {
"@offchainlabs/prettier-config": "0.2.1",
"@wagmi/cli": "^1.5.2",
"dotenv": "^16.3.1",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.8.3",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
}
Expand Down
4 changes: 4 additions & 0 deletions prettier.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
...require('@offchainlabs/prettier-config'),
// override here
};
7 changes: 1 addition & 6 deletions src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ const nitroTestnodeL2 = defineChain({
testnet: true,
});

export const chains = [
sepolia,
arbitrumSepolia,
nitroTestnodeL1,
nitroTestnodeL2,
] as const;
export const chains = [sepolia, arbitrumSepolia, nitroTestnodeL1, nitroTestnodeL2] as const;

export { sepolia, arbitrumSepolia, nitroTestnodeL1, nitroTestnodeL2 };
7 changes: 3 additions & 4 deletions src/createRollup.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ it(`successfully deploys core contracts through rollup creator`, async () => {
});

// get the transaction
const tx = createRollupPrepareTransaction(
await publicClient.getTransaction({ hash: txHash })
);
const tx = createRollupPrepareTransaction(await publicClient.getTransaction({ hash: txHash }));

const [arg] = tx.getInputs();
// assert all inputs are correct
Expand All @@ -70,8 +68,9 @@ it(`successfully deploys core contracts through rollup creator`, async () => {

// get the transaction receipt after waiting for the transaction to complete
const txReceipt = createRollupPrepareTransactionReceipt(
await publicClient.waitForTransactionReceipt({ hash: txHash })
await publicClient.waitForTransactionReceipt({ hash: txHash }),
);

expect(txReceipt.status).toEqual('success');
expect(() => txReceipt.getCoreContracts()).not.toThrowError();
});
17 changes: 6 additions & 11 deletions src/createRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export type CreateRollupFunctionInputs = GetFunctionArgs<

type RequiredKeys = 'config' | 'batchPoster' | 'validators';

export type CreateRollupParams = Pick<
CreateRollupFunctionInputs[0],
RequiredKeys
> &
export type CreateRollupParams = Pick<CreateRollupFunctionInputs[0], RequiredKeys> &
Partial<Omit<CreateRollupFunctionInputs[0], RequiredKeys>>;

export async function createRollup({
Expand All @@ -48,23 +45,21 @@ export async function createRollup({

const chainConfig: ChainConfig = JSON.parse(params.config.chainConfig);

if (
isCustomFeeTokenAddress(params.nativeToken) &&
!isAnyTrustChainConfig(chainConfig)
) {
if (isCustomFeeTokenAddress(params.nativeToken) && !isAnyTrustChainConfig(chainConfig)) {
throw new Error(
`Custom fee token can only be used on AnyTrust chains. Set "arbitrum.DataAvailabilityCommittee" to "true" in the chain config.`
`Custom fee token can only be used on AnyTrust chains. Set "arbitrum.DataAvailabilityCommittee" to "true" in the chain config.`,
);
}

const maxDataSize = createRollupGetMaxDataSize(chainId);
const paramsWithDefaults = { ...defaults, ...params, maxDataSize };

const { request } = await publicClient.simulateContract({
address: rollupCreator.address[chainId],
abi: rollupCreator.abi,
functionName: 'createRollup',
args: [{ ...defaults, ...params, maxDataSize }],
value: createRollupGetCallValue(params),
args: [paramsWithDefaults],
value: createRollupGetCallValue(paramsWithDefaults),
account,
});

Expand Down
14 changes: 4 additions & 10 deletions src/createRollupPrepareConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ import { prepareChainConfig } from './prepareChainConfig';

type RequiredKeys = 'chainId' | 'owner';

export type CreateRollupPrepareConfigResult =
CreateRollupFunctionInputs[0]['config'];
export type CreateRollupPrepareConfigResult = CreateRollupFunctionInputs[0]['config'];

export type CreateRollupPrepareConfigParams = Pick<
CreateRollupPrepareConfigResult,
RequiredKeys
> &
Partial<
Omit<CreateRollupPrepareConfigResult | 'chainConfig', RequiredKeys>
> & {
export type CreateRollupPrepareConfigParams = Pick<CreateRollupPrepareConfigResult, RequiredKeys> &
Partial<Omit<CreateRollupPrepareConfigResult | 'chainConfig', RequiredKeys>> & {
chainConfig?: ChainConfig;
};

Expand Down Expand Up @@ -50,7 +44,7 @@ export function createRollupPrepareConfig({
prepareChainConfig({
chainId: Number(params.chainId),
arbitrum: { InitialChainOwner: params.owner },
})
}),
),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { approvePrepareTransactionRequest } from './utils/erc20';
import { validParentChainId } from './types/ParentChain';
import { rollupCreator } from './contracts';

export type CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams =
{
amount?: bigint;
nativeToken: Address;
account: Address;
publicClient: PublicClient;
};
export type CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams = {
amount?: bigint;
nativeToken: Address;
account: Address;
publicClient: PublicClient;
};

export async function createRollupPrepareCustomFeeTokenApprovalTransactionRequest({
amount = maxInt256,
Expand Down
8 changes: 2 additions & 6 deletions src/createRollupPrepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export type CreateRollupTransaction = Transaction & {
getInputs(): CreateRollupFunctionInputs;
};

export function createRollupPrepareTransaction(
tx: Transaction
): CreateRollupTransaction {
export function createRollupPrepareTransaction(tx: Transaction): CreateRollupTransaction {
return {
...tx,
getInputs: function () {
Expand All @@ -29,9 +27,7 @@ export function createRollupPrepareTransaction(
}

if (typeof args === 'undefined') {
throw new Error(
`[createRollupPrepareTransaction] failed to decode function data`
);
throw new Error(`[createRollupPrepareTransaction] failed to decode function data`);
}

return args;
Expand Down
16 changes: 4 additions & 12 deletions src/createRollupPrepareTransactionReceipt.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
TransactionReceipt,
getAbiItem,
getEventSelector,
Log,
decodeEventLog,
} from 'viem';
import { TransactionReceipt, getAbiItem, getEventSelector, Log, decodeEventLog } from 'viem';

import { rollupCreator } from './contracts';
import { CoreContracts } from './types/CoreContracts';
Expand All @@ -16,7 +10,7 @@ function findRollupCreatedEventLog(txReceipt: TransactionReceipt) {

if (typeof log === 'undefined') {
throw new Error(
`No "RollupCreated" logs found in logs for transaction: ${txReceipt.transactionHash}`
`No "RollupCreated" logs found in logs for transaction: ${txReceipt.transactionHash}`,
);
}

Expand All @@ -27,9 +21,7 @@ function decodeRollupCreatedEventLog(log: Log<bigint, number>) {
const decodedEventLog = decodeEventLog({ ...log, abi: rollupCreator.abi });

if (decodedEventLog.eventName !== 'RollupCreated') {
throw new Error(
`Expected "RollupCreated" event but found: ${decodedEventLog.eventName}`
);
throw new Error(`Expected "RollupCreated" event but found: ${decodedEventLog.eventName}`);
}

return decodedEventLog;
Expand All @@ -40,7 +32,7 @@ export type CreateRollupTransactionReceipt = TransactionReceipt & {
};

export function createRollupPrepareTransactionReceipt(
txReceipt: TransactionReceipt
txReceipt: TransactionReceipt,
): CreateRollupTransactionReceipt {
return {
...txReceipt,
Expand Down
20 changes: 8 additions & 12 deletions src/createRollupPrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, PublicClient, encodeFunctionData } from 'viem';

import { CreateRollupParams } from './createRollup';
import { CreateRollupFunctionInputs, CreateRollupParams } from './createRollup';
import { defaults } from './createRollupDefaults';
import { createRollupGetCallValue } from './createRollupGetCallValue';
import { createRollupGetMaxDataSize } from './createRollupGetMaxDataSize';
Expand All @@ -10,13 +10,11 @@ import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress';
import { ChainConfig } from './types/ChainConfig';
import { isAnyTrustChainConfig } from './utils/isAnyTrustChainConfig';

function createRollupEncodeFunctionData(
params: CreateRollupParams & { maxDataSize: bigint }
) {
function createRollupEncodeFunctionData(args: CreateRollupFunctionInputs) {
return encodeFunctionData({
abi: rollupCreator.abi,
functionName: 'createRollup',
args: [{ ...defaults, ...params }],
args,
});
}

Expand All @@ -37,22 +35,20 @@ export async function createRollupPrepareTransactionRequest({

const chainConfig: ChainConfig = JSON.parse(params.config.chainConfig);

if (
isCustomFeeTokenAddress(params.nativeToken) &&
!isAnyTrustChainConfig(chainConfig)
) {
if (isCustomFeeTokenAddress(params.nativeToken) && !isAnyTrustChainConfig(chainConfig)) {
throw new Error(
`Custom fee token can only be used on AnyTrust chains. Set "arbitrum.DataAvailabilityCommittee" to "true" in the chain config.`
`Custom fee token can only be used on AnyTrust chains. Set "arbitrum.DataAvailabilityCommittee" to "true" in the chain config.`,
);
}

const maxDataSize = createRollupGetMaxDataSize(chainId);
const paramsWithDefaults = { ...defaults, ...params, maxDataSize };

const request = await publicClient.prepareTransactionRequest({
chain: publicClient.chain,
to: rollupCreator.address[chainId],
data: createRollupEncodeFunctionData({ ...params, maxDataSize }),
value: createRollupGetCallValue(params),
data: createRollupEncodeFunctionData([paramsWithDefaults]),
value: createRollupGetCallValue(paramsWithDefaults),
account,
});

Expand Down
Loading

0 comments on commit b05a446

Please sign in to comment.