Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-weth-gateway-registration
Browse files Browse the repository at this point in the history
  • Loading branch information
TucksonDev committed Feb 28, 2024
2 parents f4b913c + 2186ccc commit 3ed5f2e
Show file tree
Hide file tree
Showing 34 changed files with 1,665 additions and 281 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Set up the local node
uses: OffchainLabs/actions/run-nitro-test-node@main
with:
nitro-testnode-ref: release
nitro-testnode-ref: transfer-ownership
# Use simple mode
no-simple: false
# RollupCreator on L1 is deployed by default
Expand Down
9 changes: 9 additions & 0 deletions examples/create-rollup-custom-fee-token/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Deployer private key
DEPLOYER_PRIVATE_KEY=

# Custom fee token address on the parent chain
CUSTOM_FEE_TOKEN_ADDRESS=

# Optional (these will be randomly generated if not provided)
BATCH_POSTER_PRIVATE_KEY=
VALIDATOR_PRIVATE_KEY=
10 changes: 8 additions & 2 deletions examples/create-rollup-custom-fee-token/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
createRollupPrepareTransactionReceipt,
} from '@arbitrum/orbit-sdk';
import { sanitizePrivateKey, generateChainId } from '@arbitrum/orbit-sdk/utils';
import { config } from 'dotenv';
config();

function withFallbackPrivateKey(privateKey: string | undefined): `0x${string}` {
if (typeof privateKey === 'undefined') {
if (typeof privateKey === 'undefined' || privateKey === '') {
return generatePrivateKey();
}

Expand All @@ -27,6 +29,10 @@ if (typeof process.env.DEPLOYER_PRIVATE_KEY === 'undefined') {
throw new Error(`Please provide the "DEPLOYER_PRIVATE_KEY" environment variable`);
}

if (typeof process.env.CUSTOM_FEE_TOKEN_ADDRESS === 'undefined') {
throw new Error(`Please provide the "CUSTOM_FEE_TOKEN_ADDRESS" environment variable`);
}

// load or generate a random batch poster account
const batchPosterPrivateKey = withFallbackPrivateKey(process.env.BATCH_POSTER_PRIVATE_KEY);
const batchPoster = privateKeyToAccount(batchPosterPrivateKey).address;
Expand All @@ -49,7 +55,7 @@ async function main() {
// generate a random chain id
const chainId = generateChainId();
// set the custom fee token
const nativeToken: Address = '0xf861378b543525ae0c47d33c90c954dc774ac1f9';
const nativeToken: Address = process.env.CUSTOM_FEE_TOKEN_ADDRESS as `0x${string}`;

// create the chain config
const chainConfig = prepareChainConfig({
Expand Down
6 changes: 6 additions & 0 deletions examples/create-rollup-eth/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Required
DEPLOYER_PRIVATE_KEY=

# Optional (these will be randomly generated if not provided)
BATCH_POSTER_PRIVATE_KEY=
VALIDATOR_PRIVATE_KEY=
4 changes: 3 additions & 1 deletion examples/create-rollup-eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
createRollupPrepareTransactionReceipt,
} from '@arbitrum/orbit-sdk';
import { sanitizePrivateKey, generateChainId } from '@arbitrum/orbit-sdk/utils';
import { config } from 'dotenv';
config();

function withFallbackPrivateKey(privateKey: string | undefined): `0x${string}` {
if (typeof privateKey === 'undefined') {
if (typeof privateKey === 'undefined' || privateKey === '') {
return generatePrivateKey();
}

Expand Down
4 changes: 4 additions & 0 deletions examples/prepare-node-config/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Required
ORBIT_DEPLOYMENT_TRANSACTION_HASH=
BATCH_POSTER_PRIVATE_KEY=
VALIDATOR_PRIVATE_KEY=
23 changes: 18 additions & 5 deletions examples/prepare-node-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { writeFile } from 'fs/promises';
import { Chain, createPublicClient, http } from 'viem';
import { arbitrumSepolia } from 'viem/chains';
import {
Expand All @@ -6,13 +7,25 @@ import {
createRollupPrepareTransactionReceipt,
prepareNodeConfig,
} from '@arbitrum/orbit-sdk';

import { writeFile } from 'fs/promises';
import { config } from 'dotenv';
config();

function getRpcUrl(chain: Chain) {
return chain.rpcUrls.default.http[0];
}

if (typeof process.env.ORBIT_DEPLOYMENT_TRANSACTION_HASH === 'undefined') {
throw new Error(`Please provide the "ORBIT_DEPLOYMENT_TRANSACTION_HASH" environment variable`);
}

if (typeof process.env.BATCH_POSTER_PRIVATE_KEY === 'undefined') {
throw new Error(`Please provide the "BATCH_POSTER_PRIVATE_KEY" environment variable`);
}

if (typeof process.env.VALIDATOR_PRIVATE_KEY === 'undefined') {
throw new Error(`Please provide the "VALIDATOR_PRIVATE_KEY" environment variable`);
}

// set the parent chain and create a public client for it
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createPublicClient({
Expand All @@ -22,7 +35,7 @@ const parentChainPublicClient = createPublicClient({

async function main() {
// tx hash for the transaction to create rollup
const txHash = '0x22bb24020ee839e4a266960aa73c6bf5b02621e2de3f2a755c9f2869014140d7';
const txHash = process.env.ORBIT_DEPLOYMENT_TRANSACTION_HASH as `0x${string}`;

// get the transaction
const tx = createRollupPrepareTransaction(
Expand All @@ -44,8 +57,8 @@ async function main() {
chainName: 'My Orbit Chain',
chainConfig,
coreContracts,
batchPosterPrivateKey: 'INSERT_BATCH_POSTER_PRIVATE_KEY_HERE',
validatorPrivateKey: 'INSERT_VALIDATOR_PRIVATE_KEY_HERE',
batchPosterPrivateKey: process.env.BATCH_POSTER_PRIVATE_KEY as `0x${string}`,
validatorPrivateKey: process.env.VALIDATOR_PRIVATE_KEY as `0x${string}`,
parentChainId: parentChain.id,
parentChainRpcUrl: getRpcUrl(parentChain),
});
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"build": "tsc --project ./tsconfig.json --module commonjs --outDir ./src/dist --declaration",
"dev": "yarn build --watch",
"generate": "wagmi generate",
"generate:node-config-type": "yarn build && node ./src/dist/scripts/generateNodeConfigType.js",
"postgenerate:node-config-type": "prettier --write ./src/types/NodeConfig.generated.ts",
"test:unit": "vitest unit.test",
"test:integration": "vitest integration.test",
"postinstall": "patch-package",
Expand All @@ -23,6 +25,7 @@
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.8.3",
"ts-morph": "^21.0.1",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
}
Expand Down
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ import { parseEther } from 'viem';
export const createRollupDefaultRetryablesFees = parseEther('0.125');

export const createTokenBridgeDefaultRetryablesFees = parseEther('0.02');
export const createTokenBridgeDefaultGasLimit = 5_000_000n;
70 changes: 0 additions & 70 deletions src/createRollup.ts

This file was deleted.

18 changes: 12 additions & 6 deletions src/createRollupEnoughCustomFeeTokenAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import { validParentChainId } from './types/ParentChain';
import { fetchAllowance } from './utils/erc20';
import { createRollupDefaultRetryablesFees } from './constants';

export type CreateRollupEnoughCustomFeeTokenAllowanceParams = {
nativeToken: Address;
account: Address;
publicClient: PublicClient;
};
import { Prettify } from './types/utils';
import { WithRollupCreatorAddressOverride } from './types/createRollupTypes';

export type CreateRollupEnoughCustomFeeTokenAllowanceParams = Prettify<
WithRollupCreatorAddressOverride<{
nativeToken: Address;
account: Address;
publicClient: PublicClient;
}>
>;

export async function createRollupEnoughCustomFeeTokenAllowance({
nativeToken,
account,
publicClient,
rollupCreatorAddressOverride,
}: CreateRollupEnoughCustomFeeTokenAllowanceParams) {
const chainId = publicClient.chain?.id;

Expand All @@ -25,7 +31,7 @@ export async function createRollupEnoughCustomFeeTokenAllowance({
const allowance = await fetchAllowance({
address: nativeToken,
owner: account,
spender: rollupCreator.address[chainId],
spender: rollupCreatorAddressOverride ?? rollupCreator.address[chainId],
publicClient,
});

Expand Down
2 changes: 1 addition & 1 deletion src/createRollupGetCallValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreateRollupParams } from './createRollup';
import { CreateRollupParams } from './types/createRollupTypes';
import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress';
import { createRollupDefaultRetryablesFees } from './constants';

Expand Down
2 changes: 1 addition & 1 deletion src/createRollupPrepareConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseEther, zeroAddress } from 'viem';

import { ChainConfig } from './types/ChainConfig';
import { CreateRollupFunctionInputs } from './createRollup';
import { CreateRollupFunctionInputs } from './types/createRollupTypes';
import { prepareChainConfig } from './prepareChainConfig';

type RequiredKeys = 'chainId' | 'owner';
Expand Down
20 changes: 13 additions & 7 deletions src/createRollupPrepareCustomFeeTokenApprovalTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ import { validParentChainId } from './types/ParentChain';
import { rollupCreator } from './contracts';
import { createRollupDefaultRetryablesFees } from './constants';

export type CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams = {
amount?: bigint;
nativeToken: Address;
account: Address;
publicClient: PublicClient;
};
import { Prettify } from './types/utils';
import { WithRollupCreatorAddressOverride } from './types/createRollupTypes';

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

export async function createRollupPrepareCustomFeeTokenApprovalTransactionRequest({
amount = createRollupDefaultRetryablesFees,
nativeToken,
account,
publicClient,
rollupCreatorAddressOverride,
}: CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams) {
const chainId = publicClient.chain?.id;

Expand All @@ -27,7 +33,7 @@ export async function createRollupPrepareCustomFeeTokenApprovalTransactionReques
const request = await approvePrepareTransactionRequest({
address: nativeToken,
owner: account,
spender: rollupCreator.address[chainId],
spender: rollupCreatorAddressOverride ?? rollupCreator.address[chainId],
amount,
publicClient,
});
Expand Down
2 changes: 1 addition & 1 deletion src/createRollupPrepareTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Transaction, decodeFunctionData } from 'viem';

import { rollupCreator } from './contracts';
import { CreateRollupFunctionInputs } from './createRollup';
import { CreateRollupFunctionInputs } from './types/createRollupTypes';

function createRollupDecodeFunctionData(data: `0x${string}`) {
return decodeFunctionData({
Expand Down
Loading

0 comments on commit 3ed5f2e

Please sign in to comment.