From 2d2793b60994623310deebf0426d99b4cb5eca51 Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 24 Sep 2024 16:58:17 +0200 Subject: [PATCH] feat: Add v1 arbOwnerPublic setters --- src/actions/buildAddChainOwner.ts | 42 +++++++++++++++++++ src/actions/buildRemoveChainOwner.ts | 41 ++++++++++++++++++ src/actions/buildSetMaxTxGasLimit.ts | 41 ++++++++++++++++++ src/actions/buildSetParentPricePerUnit.ts | 41 ++++++++++++++++++ .../buildSetParentPricingRewardRate.ts | 42 +++++++++++++++++++ .../buildSetParentPricingRewardRecipient.ts | 42 +++++++++++++++++++ src/actions/buildSetSpeedLimit.ts | 41 ++++++++++++++++++ src/types/Actions.ts | 8 ++-- src/types/validateChildChainPublicClient.ts | 16 +++++++ 9 files changed, 310 insertions(+), 4 deletions(-) create mode 100644 src/actions/buildAddChainOwner.ts create mode 100644 src/actions/buildRemoveChainOwner.ts create mode 100644 src/actions/buildSetMaxTxGasLimit.ts create mode 100644 src/actions/buildSetParentPricePerUnit.ts create mode 100644 src/actions/buildSetParentPricingRewardRate.ts create mode 100644 src/actions/buildSetParentPricingRewardRecipient.ts create mode 100644 src/actions/buildSetSpeedLimit.ts create mode 100644 src/types/validateChildChainPublicClient.ts diff --git a/src/actions/buildAddChainOwner.ts b/src/actions/buildAddChainOwner.ts new file mode 100644 index 00000000..69e49cf2 --- /dev/null +++ b/src/actions/buildAddChainOwner.ts @@ -0,0 +1,42 @@ +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; + +export type BuildAddChainOwnerParameters = Prettify< + WithUpgradeExecutor< + WithAccount<{ + params: { + newOwner: Address; + }; + }> + > +>; +export type BuildAddChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildAddChainOwner( + client: PublicClient, + { account, upgradeExecutor, params }: BuildAddChainOwnerParameters, +): Promise { + const validatedPublicClient = validateChildChainPublicClient(client); + + const request = await client.prepareTransactionRequest({ + chain: client.chain as Chain | undefined, + account, + ...prepareUpgradeExecutorCallParameters({ + to: arbOwnerAddress, + upgradeExecutor, + args: [params.newOwner], + abi: arbOwnerABI, + functionName: 'addChainOwner', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; +} diff --git a/src/actions/buildRemoveChainOwner.ts b/src/actions/buildRemoveChainOwner.ts new file mode 100644 index 00000000..cfbb2696 --- /dev/null +++ b/src/actions/buildRemoveChainOwner.ts @@ -0,0 +1,41 @@ +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; + +export type BuildRemoveChainOwnerParameters = Prettify< + WithUpgradeExecutor< + WithAccount<{ + params: { owner: Address }; + }> + > +>; + +export type BuildRemoveChainOwnerReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildRemoveChainOwner( + client: PublicClient, + { account, upgradeExecutor, params }: BuildRemoveChainOwnerParameters, +): Promise { + const validatedPublicClient = validateChildChainPublicClient(client); + + const request = await client.prepareTransactionRequest({ + chain: client.chain as Chain | undefined, + account, + ...prepareUpgradeExecutorCallParameters({ + to: arbOwnerAddress, + upgradeExecutor, + args: [params.owner], + abi: arbOwnerABI, + functionName: 'removeChainOwner', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; +} diff --git a/src/actions/buildSetMaxTxGasLimit.ts b/src/actions/buildSetMaxTxGasLimit.ts new file mode 100644 index 00000000..a7b06ecd --- /dev/null +++ b/src/actions/buildSetMaxTxGasLimit.ts @@ -0,0 +1,41 @@ +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; + +export type BuildSetMaxTxGasLimitParameters = Prettify< + WithUpgradeExecutor< + WithAccount<{ + params: { limit: bigint }; + }> + > +>; + +export type BuildSetMaxTxGasLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildSetMaxTxGasLimit( + client: PublicClient, + { account, upgradeExecutor, params }: BuildSetMaxTxGasLimitParameters, +): Promise { + const validatedPublicClient = validateChildChainPublicClient(client); + + const request = await client.prepareTransactionRequest({ + chain: client.chain as Chain | undefined, + account, + ...prepareUpgradeExecutorCallParameters({ + to: arbOwnerAddress, + upgradeExecutor, + args: [params.limit], + abi: arbOwnerABI, + functionName: 'setMaxTxGasLimit', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; +} diff --git a/src/actions/buildSetParentPricePerUnit.ts b/src/actions/buildSetParentPricePerUnit.ts new file mode 100644 index 00000000..d09b0441 --- /dev/null +++ b/src/actions/buildSetParentPricePerUnit.ts @@ -0,0 +1,41 @@ +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; + +export type BuildSetParentPricePerUnitParameters = Prettify< + WithUpgradeExecutor< + WithAccount<{ + params: { pricePerUnit: bigint }; + }> + > +>; + +export type BuildSetParentPricePerUnitReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildSetParentPricePerUnit( + client: PublicClient, + { account, upgradeExecutor, params }: BuildSetParentPricePerUnitParameters, +): Promise { + const validatedPublicClient = validateChildChainPublicClient(client); + + const request = await client.prepareTransactionRequest({ + chain: validatedPublicClient.chain, + account, + ...prepareUpgradeExecutorCallParameters({ + to: arbOwnerAddress, + upgradeExecutor, + args: [params.pricePerUnit], + abi: arbOwnerABI, + functionName: 'setL1PricePerUnit', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; +} diff --git a/src/actions/buildSetParentPricingRewardRate.ts b/src/actions/buildSetParentPricingRewardRate.ts new file mode 100644 index 00000000..89853f57 --- /dev/null +++ b/src/actions/buildSetParentPricingRewardRate.ts @@ -0,0 +1,42 @@ +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; + +export type BuildSetParentPricingRewardRateParameters = Prettify< + WithUpgradeExecutor< + WithAccount<{ + params: { weiPerUnit: bigint }; + }> + > +>; + +export type BuildSetParentPricingRewardRateReturnType = + PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildSetParentPricingRewardRate( + client: PublicClient, + { account, upgradeExecutor, params }: BuildSetParentPricingRewardRateParameters, +): Promise { + const validatedPublicClient = validateChildChainPublicClient(client); + + const request = await client.prepareTransactionRequest({ + chain: client.chain, + account, + ...prepareUpgradeExecutorCallParameters({ + to: arbOwnerAddress, + upgradeExecutor, + args: [params.weiPerUnit], + abi: arbOwnerABI, + functionName: 'setL1PricingRewardRate', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; +} diff --git a/src/actions/buildSetParentPricingRewardRecipient.ts b/src/actions/buildSetParentPricingRewardRecipient.ts new file mode 100644 index 00000000..d5f79a10 --- /dev/null +++ b/src/actions/buildSetParentPricingRewardRecipient.ts @@ -0,0 +1,42 @@ +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; + +export type BuildSetParentPricingRewardRecipientParameters = Prettify< + WithUpgradeExecutor< + WithAccount<{ + params: { recipient: Address }; + }> + > +>; + +export type BuildSetParentPricingRewardRecipientReturnType = + PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildSetParentPricingRewardRecipient( + client: PublicClient, + { account, upgradeExecutor, params }: BuildSetParentPricingRewardRecipientParameters, +): Promise { + const validatedPublicClient = validateChildChainPublicClient(client); + + const request = await client.prepareTransactionRequest({ + chain: client.chain, + account, + ...prepareUpgradeExecutorCallParameters({ + to: arbOwnerAddress, + upgradeExecutor, + args: [params.recipient], + abi: arbOwnerABI, + functionName: 'setL1PricingRewardRecipient', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; +} diff --git a/src/actions/buildSetSpeedLimit.ts b/src/actions/buildSetSpeedLimit.ts new file mode 100644 index 00000000..c01a11a8 --- /dev/null +++ b/src/actions/buildSetSpeedLimit.ts @@ -0,0 +1,41 @@ +import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { arbOwnerABI, arbOwnerAddress } from '../contracts/ArbOwner'; +import { + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, + WithUpgradeExecutor, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; +import { validateChildChainPublicClient } from '../types/validateChildChainPublicClient'; + +export type BuildSetSpeedLimitParameters = Prettify< + WithUpgradeExecutor< + WithAccount<{ + params: { limit: bigint }; + }> + > +>; + +export type BuildSetSpeedLimitReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildSetSpeedLimit( + client: PublicClient, + { account, upgradeExecutor, params }: BuildSetSpeedLimitParameters, +): Promise { + const validatedPublicClient = validateChildChainPublicClient(client); + + const request = await client.prepareTransactionRequest({ + chain: client.chain, + account, + ...prepareUpgradeExecutorCallParameters({ + to: arbOwnerAddress, + upgradeExecutor, + args: [params.limit], + abi: arbOwnerABI, + functionName: 'setSpeedLimit', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: validatedPublicClient.chain.id }; +} diff --git a/src/types/Actions.ts b/src/types/Actions.ts index 71093865..dd028e92 100644 --- a/src/types/Actions.ts +++ b/src/types/Actions.ts @@ -12,11 +12,11 @@ type isEmptyObject = Args extends Record ? true : false; export type ActionParameters = Prettify< Curried extends false ? isEmptyObject extends true - ? { [key in ContractName]: Address } // Contract wasn't curried. Args is an empty object. Only requires the contract name - : { params: Args } & { [key in ContractName]: Address } // Contract wasn't curried. Args is not empty. Requires both params and contract name + ? { [key in ContractName]: Address } | { sequencerInbox: Address } // Contract wasn't curried. Args is an empty object. Only requires the contract name + : { params: Args } & ({ [key in ContractName]: Address } | { sequencerInbox: Address }) // Contract wasn't curried. Args is not empty. Requires both params and contract name : isEmptyObject extends true - ? { [key in ContractName]: Address } | void // Contract was curried. Args is empty. Only requires the contract name. Allows no parameters - : { params: Args } & { [key in ContractName]?: Address } // Contract was curried. Args is not empty. Requires params, contract name is optional + ? { [key in ContractName]: Address } | { sequencerInbox: Address } | void // Contract was curried. Args is empty. Only requires the contract name. Allows no parameters + : { params: Args } & ({ [key in ContractName]?: Address } | { sequencerInbox?: Address }) // Contract was curried. Args is not empty. Requires params, contract name is optional >; export type WithAccount = Args & { 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; +}