Skip to content

Commit

Permalink
rename some publicclient to orbitclient
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Dec 27, 2023
1 parent bb9b34b commit db96d7d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 44 deletions.
8 changes: 4 additions & 4 deletions examples/create-rollup-eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const validator = privateKeyToAccount(validatorPrivateKey).address;

// set the parent chain and create a public client for it
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createOrbitClient({
const parentChainOrbitClient = createOrbitClient({
chain: parentChain,
transport: http(),
});
Expand Down Expand Up @@ -77,17 +77,17 @@ async function main() {
validators: [validator],
},
account: deployer.address,
publicClient: parentChainPublicClient,
publicClient: parentChainOrbitClient,
});

// sign and send the transaction
const txHash = await parentChainPublicClient.sendRawTransaction({
const txHash = await parentChainOrbitClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(request),
});

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

console.log(`Deployed in ${getBlockExplorerUrl(parentChain)}/tx/${txReceipt.transactionHash}`);
Expand Down
8 changes: 4 additions & 4 deletions examples/set-valid-keyset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const keyset =

// set the parent chain and create a public client for it
const parentChain = arbitrumSepolia;
const parentChainPublicClient = createOrbitClient({
const parentChainOrbitClient = createOrbitClient({
chain: parentChain,
transport: http(),
});
Expand All @@ -42,16 +42,16 @@ async function main() {
},
keyset,
account: deployer.address,
publicClient: parentChainPublicClient,
publicClient: parentChainOrbitClient,
});

// sign and send the transaction
const txHash = await parentChainPublicClient.sendRawTransaction({
const txHash = await parentChainOrbitClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(txRequest),
});

// wait for the transaction receipt
const txReceipt = await parentChainPublicClient.waitForTransactionReceipt({
const txReceipt = await parentChainOrbitClient.waitForTransactionReceipt({
hash: txHash,
});

Expand Down
10 changes: 5 additions & 5 deletions src/createRollup.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const deployer = getTestPrivateKeyAccount();
const batchPoster = deployer.address;
const validators = [deployer.address];

const publicClient = createOrbitClient({
const orbitClient = createOrbitClient({
chain: nitroTestnodeL2,
transport: http(),
});
Expand Down Expand Up @@ -46,16 +46,16 @@ it(`successfully deploys core contracts through rollup creator`, async () => {
validators,
},
account: deployer.address,
publicClient,
orbitClient: orbitClient,
});

// sign and send the transaction
const txHash = await publicClient.sendRawTransaction({
const txHash = await orbitClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(request),
});

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

const [arg] = tx.getInputs();
// assert all inputs are correct
Expand All @@ -69,7 +69,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 orbitClient.waitForTransactionReceipt({ hash: txHash }),
);

expect(txReceipt.status).toEqual('success');
Expand Down
17 changes: 8 additions & 9 deletions src/createRollup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PublicClient, WalletClient, GetFunctionArgs } from 'viem';
import { WalletClient, GetFunctionArgs } from 'viem';

import { rollupCreator } from './contracts';
import { validParentChainId } from './types/ParentChain';
import { defaults } from './createRollupDefaults';
import { createRollupGetCallValue } from './createRollupGetCallValue';
import { createRollupGetMaxDataSize } from './createRollupGetMaxDataSize';
Expand All @@ -12,7 +11,7 @@ import {
import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress';
import { ChainConfig } from './types/ChainConfig';
import { isAnyTrustChainConfig } from './utils/isAnyTrustChainConfig';
import { OrbitClient } from './orbitClient';
import type { OrbitClient } from './orbitClient';

export type CreateRollupFunctionInputs = GetFunctionArgs<
typeof rollupCreator.abi,
Expand All @@ -26,14 +25,14 @@ export type CreateRollupParams = Pick<CreateRollupFunctionInputs[0], RequiredKey

export async function createRollup({
params,
publicClient,
orbitClient,
walletClient,
}: {
params: CreateRollupParams;
publicClient: OrbitClient;
orbitClient: OrbitClient;
walletClient: WalletClient;
}): Promise<CreateRollupTransactionReceipt> {
const chainId = publicClient.getValidChainId();
const chainId = orbitClient.getValidChainId();
const account = walletClient.account?.address;

if (typeof account === 'undefined') {
Expand All @@ -51,8 +50,8 @@ export async function createRollup({
const maxDataSize = createRollupGetMaxDataSize(chainId);
const paramsWithDefaults = { ...defaults, ...params, maxDataSize };

const { request } = await publicClient.simulateContract({
address: publicClient.getRollupCreatorAddress(),
const { request } = await orbitClient.simulateContract({
address: orbitClient.getRollupCreatorAddress(),
abi: rollupCreator.abi,
functionName: 'createRollup',
args: [paramsWithDefaults],
Expand All @@ -61,7 +60,7 @@ export async function createRollup({
});

const hash = await walletClient.writeContract(request);
const txReceipt = await publicClient.waitForTransactionReceipt({ hash });
const txReceipt = await orbitClient.waitForTransactionReceipt({ hash });

return createRollupPrepareTransactionReceipt(txReceipt);
}
15 changes: 4 additions & 11 deletions src/createRollupEnoughCustomFeeTokenAllowance.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
import { Address } from 'viem';

import { validParentChainId } from './types/ParentChain';
import { fetchAllowance } from './utils/erc20';
import { deterministicFactoriesDeploymentEstimatedFees } from './constants';
import { OrbitClient } from './orbitClient';

export type CreateRollupEnoughCustomFeeTokenAllowanceParams = {
nativeToken: Address;
account: Address;
publicClient: OrbitClient;
orbitClient: OrbitClient;
};

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

if (!validParentChainId(chainId)) {
throw new Error('chainId is undefined');
}

const allowance = await fetchAllowance({
address: nativeToken,
owner: account,
spender: publicClient.getRollupCreatorAddress(),
publicClient,
spender: orbitClient.getRollupCreatorAddress(),
publicClient: orbitClient,
});

return allowance >= deterministicFactoriesDeploymentEstimatedFees;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ export type CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams =
amount?: bigint;
nativeToken: Address;
account: Address;
publicClient: OrbitClient;
orbitClient: OrbitClient;
};

export async function createRollupPrepareCustomFeeTokenApprovalTransactionRequest({
amount = maxInt256,
nativeToken,
account,
publicClient,
orbitClient,
}: CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams) {
const chainId = publicClient.getValidChainId();
const spender = publicClient.getRollupCreatorAddress();
const chainId = orbitClient.getValidChainId();
const spender = orbitClient.getRollupCreatorAddress();

const request = await approvePrepareTransactionRequest({
address: nativeToken,
owner: account,
spender,
amount,
publicClient,
publicClient: orbitClient,
});

return { ...request, chainId };
Expand Down
12 changes: 6 additions & 6 deletions src/createRollupPrepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function createRollupEncodeFunctionData(args: CreateRollupFunctionInputs) {
export async function createRollupPrepareTransactionRequest({
params,
account,
publicClient,
orbitClient,
}: {
params: CreateRollupParams;
account: Address;
publicClient: OrbitClient;
orbitClient: OrbitClient;
}) {
const chainId = publicClient.getValidChainId();
const chainId = orbitClient.getValidChainId();

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

Expand All @@ -40,9 +40,9 @@ export async function createRollupPrepareTransactionRequest({
const maxDataSize = createRollupGetMaxDataSize(chainId);
const paramsWithDefaults = { ...defaults, ...params, maxDataSize };

const request = await publicClient.prepareTransactionRequest({
chain: publicClient.chain,
to: publicClient.getRollupCreatorAddress(),
const request = await orbitClient.prepareTransactionRequest({
chain: orbitClient.chain,
to: orbitClient.getRollupCreatorAddress(),
data: createRollupEncodeFunctionData([paramsWithDefaults]),
value: createRollupGetCallValue(paramsWithDefaults),
account,
Expand Down

0 comments on commit db96d7d

Please sign in to comment.