diff --git a/src/actions/buildAddExecutor.ts b/src/actions/buildAddExecutor.ts new file mode 100644 index 00000000..b946a20f --- /dev/null +++ b/src/actions/buildAddExecutor.ts @@ -0,0 +1,36 @@ +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { upgradeExecutorABI } from '../contracts/UpgradeExecutor'; +import { PrepareTransactionRequestReturnTypeWithChainId, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; + +export type BuildAddExecutorParameters = Prettify< + WithAccount<{ + params: { + address: Address; + }; + upgradeExecutor: Address; + }> +>; + +export type BuildAddExecutorReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildAddExecutor( + client: PublicClient, + { account, upgradeExecutor: upgradeExecutorAddress, params }: BuildAddExecutorParameters, +): Promise { + const request = await client.prepareTransactionRequest({ + chain: client.chain as Chain | undefined, + account, + ...prepareUpgradeExecutorCallParameters({ + to: upgradeExecutorAddress, + upgradeExecutor: upgradeExecutorAddress, + args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, params.address], + abi: upgradeExecutorABI, + functionName: 'grantRole', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: client.chain.id }; +} diff --git a/src/actions/buildRemoveExecutor.ts b/src/actions/buildRemoveExecutor.ts new file mode 100644 index 00000000..f873ae7f --- /dev/null +++ b/src/actions/buildRemoveExecutor.ts @@ -0,0 +1,36 @@ +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { upgradeExecutorABI } from '../contracts/UpgradeExecutor'; +import { PrepareTransactionRequestReturnTypeWithChainId, WithAccount } from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; + +export type RemoveExecutorParameters = Prettify< + WithAccount<{ + params: { + address: Address; + }; + upgradeExecutor: Address; + }> +>; + +export type RemoveExecutorReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildRemoveExecutor( + client: PublicClient, + { account, upgradeExecutor: upgradeExecutorAddress, params }: RemoveExecutorParameters, +): Promise { + const request = await client.prepareTransactionRequest({ + chain: client.chain as Chain | undefined, + account, + ...prepareUpgradeExecutorCallParameters({ + to: upgradeExecutorAddress, + upgradeExecutor: upgradeExecutorAddress, + args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, params.address], + abi: upgradeExecutorABI, + functionName: 'revokeRole', + }), + } satisfies PrepareTransactionRequestParameters); + + return { ...request, chainId: client.chain.id }; +} diff --git a/src/prepareUpgradeExecutorCallParameters.ts b/src/prepareUpgradeExecutorCallParameters.ts index dcde21c0..617995d5 100644 --- a/src/prepareUpgradeExecutorCallParameters.ts +++ b/src/prepareUpgradeExecutorCallParameters.ts @@ -10,8 +10,9 @@ import { upgradeExecutorEncodeFunctionData, UpgradeExecutorFunctionName, } from './upgradeExecutorEncodeFunctionData'; +import { upgradeExecutorABI } from './contracts/UpgradeExecutor'; -type ABIs = typeof sequencerInboxABI | typeof arbOwnerABI; +type ABIs = typeof sequencerInboxABI | typeof arbOwnerABI | typeof upgradeExecutorABI; type FunctionName = GetFunctionName; type EncodeFunctionDataParameters< 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 & {