From 8c5caaa07e9aab14391498616951e3445ff6c0f0 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 1 Jul 2024 11:57:59 +0000 Subject: [PATCH] Rename setMaxTxGasLimit --- src/actions/addChainOwner.ts | 57 +++++++++--------- src/actions/removeChainOwner.ts | 58 +++++++++---------- src/actions/setMaxTxGasLimit.ts | 58 +++++++++---------- src/actions/setParentPricePerUnit.ts | 58 +++++++++---------- src/actions/setParentPricingRewardRate.ts | 56 +++++++++--------- .../setParentPricingRewardRecipient.ts | 58 +++++++++---------- src/actions/setSpeedLimit.ts | 56 +++++++++--------- src/types/validateChildChainPublicClient.ts | 16 +++++ 8 files changed, 216 insertions(+), 201 deletions(-) create mode 100644 src/types/validateChildChainPublicClient.ts diff --git a/src/actions/addChainOwner.ts b/src/actions/addChainOwner.ts index 27c2e581..6d612af2 100644 --- a/src/actions/addChainOwner.ts +++ b/src/actions/addChainOwner.ts @@ -1,43 +1,42 @@ -import { - Address, - Chain, - PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { arbOwner } from '../contracts'; -import { WithAccount } from '../types/Actions'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; export type AddChainOwnerParameters = Prettify< - WithAccount<{ - newOwner: Address; - }> + WithUpgradeExecutor< + WithAccount<{ + newOwner: Address; + }> + > >; -export type AddChainOwnerReturnType = PrepareTransactionRequestReturnType; - -function arbOwnerFunctionData({ newOwner }: AddChainOwnerParameters) { - return encodeFunctionData({ - abi: arbOwner.abi, - functionName: 'addChainOwner', - args: [newOwner], - }); -} +export type AddChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId; export async function addChainOwner( client: PublicClient, - args: AddChainOwnerParameters, + params: AddChainOwnerParameters, ): Promise { - const data = arbOwnerFunctionData(args); + const validatedPublicClient = validateChildChainPublicClient(client); + const { account, upgradeExecutor, newOwner } = params; - return client.prepareTransactionRequest({ - to: arbOwner.address, - value: BigInt(0), + const request = await client.prepareTransactionRequest({ chain: client.chain, - data, - account: args.account, + account, + ...withUpgradeExecutor({ + to: arbOwner.address, + upgradeExecutor, + args: [newOwner], + abi: arbOwner.abi, + functionName: 'addChainOwner', + }), } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } diff --git a/src/actions/removeChainOwner.ts b/src/actions/removeChainOwner.ts index 04e6d9d5..97c86988 100644 --- a/src/actions/removeChainOwner.ts +++ b/src/actions/removeChainOwner.ts @@ -1,43 +1,43 @@ -import { - Address, - Chain, - PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { arbOwner } from '../contracts'; -import { WithAccount } from '../types/Actions'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { validateParentChainPublicClient } from '../types/ParentChain'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; export type RemoveChainOwnerParameters = Prettify< - WithAccount<{ - owner: Address; - }> + WithUpgradeExecutor< + WithAccount<{ + owner: Address; + }> + > >; -export type RemoveChainOwnerReturnType = PrepareTransactionRequestReturnType; - -function arbOwnerFunctionData({ owner }: RemoveChainOwnerParameters) { - return encodeFunctionData({ - abi: arbOwner.abi, - functionName: 'removeChainOwner', - args: [owner], - }); -} +export type RemoveChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId; export async function removeChainOwner( client: PublicClient, - args: RemoveChainOwnerParameters, + params: RemoveChainOwnerParameters, ): Promise { - const data = arbOwnerFunctionData(args); + const validatedPublicClient = validateChildChainPublicClient(client); + const { account, upgradeExecutor, owner } = params; - return client.prepareTransactionRequest({ - to: arbOwner.address, - value: BigInt(0), + const request = await client.prepareTransactionRequest({ chain: client.chain, - data, - account: args.account, + account, + ...withUpgradeExecutor({ + to: arbOwner.address, + upgradeExecutor, + args: [owner], + abi: arbOwner.abi, + functionName: 'removeChainOwner', + }), } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } diff --git a/src/actions/setMaxTxGasLimit.ts b/src/actions/setMaxTxGasLimit.ts index c414f8df..1e838142 100644 --- a/src/actions/setMaxTxGasLimit.ts +++ b/src/actions/setMaxTxGasLimit.ts @@ -1,42 +1,42 @@ -import { - Chain, - PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { arbOwner } from '../contracts'; -import { WithAccount } from '../types/Actions'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; export type SetMaxTxGasLimitParameters = Prettify< - WithAccount<{ - limit: bigint; - }> + WithUpgradeExecutor< + WithAccount<{ + limit: bigint; + }> + > >; -export type SetMaxTxGasLimitReturnType = PrepareTransactionRequestReturnType; +export type SetMaxTxGasLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId; -function arbOwnerFunctionData({ limit }: SetMaxTxGasLimitParameters) { - return encodeFunctionData({ - abi: arbOwner.abi, - functionName: 'setMaxTxGasLimit', - args: [limit], - }); -} - -export async function setL1PricingRewardRecipient( +export async function setMaxTxGasLimit( client: PublicClient, - args: SetMaxTxGasLimitParameters, + params: SetMaxTxGasLimitParameters, ): Promise { - const data = arbOwnerFunctionData(args); + const validatedPublicClient = validateChildChainPublicClient(client); + const { account, upgradeExecutor, limit } = params; - return client.prepareTransactionRequest({ - to: arbOwner.address, - value: BigInt(0), + const request = await client.prepareTransactionRequest({ chain: client.chain, - data, - account: args.account, + account, + ...withUpgradeExecutor({ + to: arbOwner.address, + upgradeExecutor, + args: [limit], + abi: arbOwner.abi, + functionName: 'setMaxTxGasLimit', + }), } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } diff --git a/src/actions/setParentPricePerUnit.ts b/src/actions/setParentPricePerUnit.ts index ef726318..fabbbac0 100644 --- a/src/actions/setParentPricePerUnit.ts +++ b/src/actions/setParentPricePerUnit.ts @@ -1,42 +1,42 @@ -import { - Chain, - PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { arbOwner } from '../contracts'; -import { WithAccount } from '../types/Actions'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; export type SetParentPricePerUnitParameters = Prettify< - WithAccount<{ - pricePerUnit: bigint; - }> + WithUpgradeExecutor< + WithAccount<{ + pricePerUnit: bigint; + }> + > >; -export type SetParentPricePerUnitReturnType = PrepareTransactionRequestReturnType; - -function arbOwnerFunctionData({ pricePerUnit }: SetParentPricePerUnitParameters) { - return encodeFunctionData({ - abi: arbOwner.abi, - functionName: 'setL1PricePerUnit', - args: [pricePerUnit], - }); -} +export type SetParentPricePerUnitReturnType = PrepareTransactionRequestReturnTypeWithChainId; export async function setParentPricePerUnit( client: PublicClient, - args: SetParentPricePerUnitParameters, + params: SetParentPricePerUnitParameters, ): Promise { - const data = arbOwnerFunctionData(args); + const validatedPublicClient = validateChildChainPublicClient(client); + const { account, upgradeExecutor, pricePerUnit } = params; - return client.prepareTransactionRequest({ - to: arbOwner.address, - value: BigInt(0), - chain: client.chain, - data, - account: args.account, + const request = await client.prepareTransactionRequest({ + chain: validatedPublicClient.chain, + account, + ...withUpgradeExecutor({ + to: arbOwner.address, + upgradeExecutor, + args: [pricePerUnit], + abi: arbOwner.abi, + functionName: 'setL1PricePerUnit', + }), } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } diff --git a/src/actions/setParentPricingRewardRate.ts b/src/actions/setParentPricingRewardRate.ts index c101b087..549a39ee 100644 --- a/src/actions/setParentPricingRewardRate.ts +++ b/src/actions/setParentPricingRewardRate.ts @@ -1,42 +1,42 @@ -import { - Chain, - PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { arbOwner } from '../contracts'; -import { WithAccount } from '../types/Actions'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; export type SetParentPricingRewardRateParameters = Prettify< - WithAccount<{ - weiPerUnit: bigint; - }> + WithUpgradeExecutor< + WithAccount<{ + weiPerUnit: bigint; + }> + > >; -export type SetParentPricingRewardRateReturnType = PrepareTransactionRequestReturnType; - -function arbOwnerFunctionData({ weiPerUnit }: SetParentPricingRewardRateParameters) { - return encodeFunctionData({ - abi: arbOwner.abi, - functionName: 'setL1PricingRewardRate', - args: [weiPerUnit], - }); -} +export type SetParentPricingRewardRateReturnType = PrepareTransactionRequestReturnTypeWithChainId; export async function setParentPricingRewardRate( client: PublicClient, - args: SetParentPricingRewardRateParameters, + params: SetParentPricingRewardRateParameters, ): Promise { - const data = arbOwnerFunctionData(args); + const validatedPublicClient = validateChildChainPublicClient(client); + const { account, upgradeExecutor, weiPerUnit } = params; - return client.prepareTransactionRequest({ - to: arbOwner.address, - value: BigInt(0), + const request = await client.prepareTransactionRequest({ chain: client.chain, - data, - account: args.account, + account, + ...withUpgradeExecutor({ + to: arbOwner.address, + upgradeExecutor, + args: [weiPerUnit], + abi: arbOwner.abi, + functionName: 'setL1PricingRewardRate', + }), } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } diff --git a/src/actions/setParentPricingRewardRecipient.ts b/src/actions/setParentPricingRewardRecipient.ts index 99568ba2..7d622305 100644 --- a/src/actions/setParentPricingRewardRecipient.ts +++ b/src/actions/setParentPricingRewardRecipient.ts @@ -1,43 +1,43 @@ -import { - Address, - Chain, - PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { arbOwner } from '../contracts'; -import { WithAccount } from '../types/Actions'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; export type SetParentPricingRewardRecipientParameters = Prettify< - WithAccount<{ - recipient: Address; - }> + WithUpgradeExecutor< + WithAccount<{ + recipient: Address; + }> + > >; -export type SetParentPricingRewardRecipientReturnType = PrepareTransactionRequestReturnType; - -function arbOwnerFunctionData({ recipient }: SetParentPricingRewardRecipientParameters) { - return encodeFunctionData({ - abi: arbOwner.abi, - functionName: 'setL1PricingRewardRecipient', - args: [recipient], - }); -} +export type SetParentPricingRewardRecipientReturnType = + PrepareTransactionRequestReturnTypeWithChainId; export async function setParentPricingRewardRecipient( client: PublicClient, - args: SetParentPricingRewardRecipientParameters, + params: SetParentPricingRewardRecipientParameters, ): Promise { - const data = arbOwnerFunctionData(args); + const validatedPublicClient = validateChildChainPublicClient(client); + const { account, upgradeExecutor, recipient } = params; - return client.prepareTransactionRequest({ - to: arbOwner.address, - value: BigInt(0), + const request = await client.prepareTransactionRequest({ chain: client.chain, - data, - account: args.account, + account, + ...withUpgradeExecutor({ + to: arbOwner.address, + upgradeExecutor, + args: [recipient], + abi: arbOwner.abi, + functionName: 'setL1PricingRewardRecipient', + }), } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } diff --git a/src/actions/setSpeedLimit.ts b/src/actions/setSpeedLimit.ts index 9495fa86..7e329ca7 100644 --- a/src/actions/setSpeedLimit.ts +++ b/src/actions/setSpeedLimit.ts @@ -1,42 +1,42 @@ -import { - Chain, - PrepareTransactionRequestParameters, - PrepareTransactionRequestReturnType, - PublicClient, - Transport, - encodeFunctionData, -} from 'viem'; +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; import { arbOwner } from '../contracts'; -import { WithAccount } from '../types/Actions'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; import { Prettify } from '../types/utils'; +import { withUpgradeExecutor } from '../withUpgradeExecutor'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; export type SetSpeedLimitParameters = Prettify< - WithAccount<{ - limit: bigint; - }> + WithUpgradeExecutor< + WithAccount<{ + limit: bigint; + }> + > >; -export type SetSpeedLimitReturnType = PrepareTransactionRequestReturnType; - -function arbOwnerFunctionData({ limit }: SetSpeedLimitParameters) { - return encodeFunctionData({ - abi: arbOwner.abi, - functionName: 'setSpeedLimit', - args: [limit], - }); -} +export type SetSpeedLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId; export async function setSpeedLimit( client: PublicClient, - args: SetSpeedLimitParameters, + params: SetSpeedLimitParameters, ): Promise { - const data = arbOwnerFunctionData(args); + const validatedPublicClient = validateChildChainPublicClient(client); + const { account, upgradeExecutor, limit } = params; - return client.prepareTransactionRequest({ - to: arbOwner.address, - value: BigInt(0), + const request = await client.prepareTransactionRequest({ chain: client.chain, - data, - account: args.account, + account, + ...withUpgradeExecutor({ + to: arbOwner.address, + upgradeExecutor, + args: [limit], + abi: arbOwner.abi, + functionName: 'setSpeedLimit', + }), } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; } diff --git a/src/types/validateChildChainPublicClient.ts b/src/types/validateChildChainPublicClient.ts new file mode 100644 index 00000000..dc8be6d2 --- /dev/null +++ b/src/types/validateChildChainPublicClient.ts @@ -0,0 +1,16 @@ +import { Chain, PublicClient, Transport } from 'viem'; +import { Prettify } from './utils'; + +export type ChildChainPublicClient = Prettify< + PublicClient & { chain: NonNullable } +>; + +export function validateChildChainPublicClient( + publicClient: PublicClient, +): ChildChainPublicClient { + if (!publicClient.chain) { + throw new Error('client.chain is undefined'); + } + + return publicClient as ChildChainPublicClient; +}