From 6ae42981fed3986ace3f8d7197eae90de194d2d8 Mon Sep 17 00:00:00 2001 From: Christophe Date: Wed, 25 Sep 2024 20:00:17 +0200 Subject: [PATCH] Feat: Add v1 upgradeExecutor setters --- src/actions/buildAddExecutor.ts | 43 +++++++++++++++++++++ src/actions/buildRemoveExecutor.ts | 43 +++++++++++++++++++++ src/prepareUpgradeExecutorCallParameters.ts | 3 +- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/actions/buildAddExecutor.ts create mode 100644 src/actions/buildRemoveExecutor.ts diff --git a/src/actions/buildAddExecutor.ts b/src/actions/buildAddExecutor.ts new file mode 100644 index 00000000..f77d60d7 --- /dev/null +++ b/src/actions/buildAddExecutor.ts @@ -0,0 +1,43 @@ +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { upgradeExecutorABI } from '../contracts/UpgradeExecutor'; +import { + ActionParameters, + 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< + ActionParameters< + { + address: Address; + }, + 'upgradeExecutor', + Curried + > + > +>; + +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..25e84769 --- /dev/null +++ b/src/actions/buildRemoveExecutor.ts @@ -0,0 +1,43 @@ +import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; +import { upgradeExecutorABI } from '../contracts/UpgradeExecutor'; +import { + ActionParameters, + PrepareTransactionRequestReturnTypeWithChainId, + WithAccount, +} from '../types/Actions'; +import { Prettify } from '../types/utils'; +import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData'; +import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; + +export type BuildRemoveExecutorParameters = Prettify< + WithAccount< + ActionParameters< + { + address: Address; + }, + 'upgradeExecutor', + Curried + > + > +>; + +export type BuildRemoveExecutorReturnType = PrepareTransactionRequestReturnTypeWithChainId; + +export async function buildRemoveExecutor( + client: PublicClient, + { account, upgradeExecutor: upgradeExecutorAddress, params }: BuildRemoveExecutorParameters, +): 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<