Skip to content

Commit

Permalink
chore: format code with prettier (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc authored Dec 22, 2023
1 parent 223a95f commit a22d8fc
Show file tree
Hide file tree
Showing 27 changed files with 83 additions and 122 deletions.
14 changes: 14 additions & 0 deletions .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
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 };
6 changes: 2 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,7 +68,7 @@ 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');
Expand Down
12 changes: 3 additions & 9 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,12 +45,9 @@ 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.`,
);
}

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
7 changes: 2 additions & 5 deletions src/createRollupPrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ 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.`,
);
}

Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
CreateRollupPrepareConfigParams,
CreateRollupPrepareConfigResult,
} from './createRollupPrepareConfig';
import {
prepareChainConfig,
PrepareChainConfigParams,
} from './prepareChainConfig';
import { prepareChainConfig, PrepareChainConfigParams } from './prepareChainConfig';
import {
createRollupEnoughCustomFeeTokenAllowance,
CreateRollupEnoughCustomFeeTokenAllowanceParams,
Expand Down
7 changes: 2 additions & 5 deletions src/prepareChainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export const defaults = {
daoForkBlock: null,
daoForkSupport: true,
eip150Block: 0,
eip150Hash:
'0x0000000000000000000000000000000000000000000000000000000000000000',
eip150Hash: '0x0000000000000000000000000000000000000000000000000000000000000000',
eip155Block: 0,
eip158Block: 0,
byzantiumBlock: 0,
Expand Down Expand Up @@ -37,9 +36,7 @@ export type PrepareChainConfigParams = Pick<ChainConfig, 'chainId'> &
Partial<Omit<ChainConfigArbitrumParams, 'InitialChainOwner'>>;
};

export function prepareChainConfig(
params: PrepareChainConfigParams
): ChainConfig {
export function prepareChainConfig(params: PrepareChainConfigParams): ChainConfig {
return {
...defaults,
...params,
Expand Down
13 changes: 3 additions & 10 deletions src/prepareNodeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import {
import { ChainConfig } from './types/ChainConfig';
import { CoreContracts } from './types/CoreContracts';
import { ParentChainId, validParentChainId } from './types/ParentChain';
import {
sepolia,
arbitrumSepolia,
nitroTestnodeL1,
nitroTestnodeL2,
} from './chains';
import { sepolia, arbitrumSepolia, nitroTestnodeL1, nitroTestnodeL2 } from './chains';

function sanitizePrivateKey(privateKey: string) {
return privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
Expand All @@ -22,7 +17,7 @@ function stringifyInfoJson(infoJson: NodeConfigChainInfoJson): string {
}

function stringifyBackendsJson(
backendsJson: NodeConfigDataAvailabilityRpcAggregatorBackendsJson
backendsJson: NodeConfigDataAvailabilityRpcAggregatorBackendsJson,
): string {
return JSON.stringify(backendsJson);
}
Expand Down Expand Up @@ -58,9 +53,7 @@ export function prepareNodeConfig({
parentChainRpcUrl: string;
}): NodeConfig {
if (!validParentChainId(parentChainId)) {
throw new Error(
`[prepareNodeConfig] invalid parent chain id: ${parentChainId}`
);
throw new Error(`[prepareNodeConfig] invalid parent chain id: ${parentChainId}`);
}

const config: NodeConfig = {
Expand Down
4 changes: 2 additions & 2 deletions src/types/NodeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export type NodeConfigChainInfoJson = [
'validator-wallet-creator': string;
'deployed-at': number;
};
}
},
];

export type NodeConfigDataAvailabilityRpcAggregatorBackendsJson = [
{
url: string;
pubkey: string;
signermask: number;
}
},
];

export type NodeConfig = {
Expand Down
2 changes: 1 addition & 1 deletion src/types/ParentChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type ParentChain = (typeof chains)[number];
export type ParentChainId = ParentChain['id'];

export function validParentChainId(
parentChainId: number | undefined
parentChainId: number | undefined,
): parentChainId is ParentChainId {
const ids = chains.map((chain) => chain.id) as Number[];
return ids.includes(Number(parentChainId));
Expand Down
Loading

0 comments on commit a22d8fc

Please sign in to comment.