Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/scripting/examples/getChainDeploymentInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { z } from 'zod';
import { parseAbi } from 'viem';
import { runScript } from '../scriptUtils';
import { addressSchema, bigintSchema } from '../schemas/common';
import { toPublicClient, findChain } from '../viemTransforms';
import { createRollupFetchTransactionHash } from '../../createRollupFetchTransactionHash';
import { createRollupPrepareTransaction } from '../../createRollupPrepareTransaction';
import { createRollupPrepareTransactionReceipt } from '../../createRollupPrepareTransactionReceipt';
import { getArbOSVersion } from '../../utils/getArbOSVersion';
import { ChainConfig } from '../../types/ChainConfig';

export const schema = z
.strictObject({
parentChainRpcUrl: z.url(),
parentChainId: z.number(),
rollup: addressSchema,
chainName: z.string(),
rollupDeploymentBlockNumber: bigintSchema.optional(),
})
.transform((input) => ({
rollup: input.rollup,
chainName: input.chainName,
parentChainPublicClient: toPublicClient(
input.parentChainRpcUrl,
findChain(input.parentChainId),
),
parentChainId: input.parentChainId,
rollupDeploymentBlockNumber: input.rollupDeploymentBlockNumber,
}));

export const execute = async (input: z.output<typeof schema>) => {
const { rollup, chainName, parentChainPublicClient, parentChainId, rollupDeploymentBlockNumber } =
input;

const transactionHash = await createRollupFetchTransactionHash({
rollup,
publicClient: parentChainPublicClient,
fromBlock: rollupDeploymentBlockNumber,
});

const [txData, txReceiptData, stakeToken, parentChainIsArbitrum] = await Promise.all([
parentChainPublicClient.getTransaction({ hash: transactionHash }),
parentChainPublicClient.getTransactionReceipt({ hash: transactionHash }),
parentChainPublicClient.readContract({
address: rollup,
abi: parseAbi(['function stakeToken() view returns (address)']),
functionName: 'stakeToken',
}),
getArbOSVersion(parentChainPublicClient)
.then(() => true)
.catch(() => false),
]);

const chainConfig: ChainConfig = JSON.parse(
createRollupPrepareTransaction(txData).getInputs()[0].config.chainConfig,
);

const coreContracts = createRollupPrepareTransactionReceipt(txReceiptData).getCoreContracts();

return {
chainId: chainConfig.chainId,
parentChainId,
parentChainIsArbitrum,
chainName,
chainConfig,
rollup: {
rollup: coreContracts.rollup,
bridge: coreContracts.bridge,
inbox: coreContracts.inbox,
sequencerInbox: coreContracts.sequencerInbox,
validatorWalletCreator: coreContracts.validatorWalletCreator,
stakeToken,
deployedAtBlockNumber: coreContracts.deployedAtBlockNumber,
},
};
};

runScript(schema, execute);
14 changes: 14 additions & 0 deletions src/scripting/schemaCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ vi.mock('../createRollupFetchCoreContracts', () => ({
vi.mock('../createRollupFetchTransactionHash', () => ({
createRollupFetchTransactionHash: _mocks.fn('createRollupFetchTransactionHash'),
}));
vi.mock('../createRollupPrepareTransaction', () => ({
createRollupPrepareTransaction: _mocks.fnSync('createRollupPrepareTransaction', {
getInputs: () => [{ config: { chainConfig: '{"chainId":99999}' } }],
}),
}));
vi.mock('../createRollupPrepareTransactionReceipt', () => ({
createRollupPrepareTransactionReceipt: _mocks.fnSync(
'createRollupPrepareTransactionReceipt',
_mocks.trackedObject('createRollupTransactionReceipt'),
),
}));
vi.mock('../utils/getArbOSVersion', () => ({
getArbOSVersion: _mocks.fn('getArbOSVersion'),
}));
vi.mock('../utils/erc20', () => ({
fetchAllowance: _mocks.fn('fetchAllowance'),
fetchDecimals: _mocks.fn('fetchDecimals'),
Expand Down
1 change: 0 additions & 1 deletion src/scripting/schemaCoverage.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ import {
schema as createTokenBridgeExampleSchema,
execute as createTokenBridgeExampleExecute,
} from './examples/createTokenBridge';

describe('schema coverage', () => {
it('getValidators', async () => {
await assertSchemaCoverage(
Expand Down
Loading