Skip to content

Commit

Permalink
Feat: Add v1 upgradeExecutor setters
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Sep 27, 2024
1 parent 7804ca2 commit 6ae4298
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/actions/buildAddExecutor.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = Prettify<
WithAccount<
ActionParameters<
{
address: Address;
},
'upgradeExecutor',
Curried
>
>
>;

export type BuildAddExecutorReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildAddExecutor<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor: upgradeExecutorAddress, params }: BuildAddExecutorParameters,
): Promise<BuildAddExecutorReturnType> {
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 };
}
43 changes: 43 additions & 0 deletions src/actions/buildRemoveExecutor.ts
Original file line number Diff line number Diff line change
@@ -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<Curried extends boolean = false> = Prettify<
WithAccount<
ActionParameters<
{
address: Address;
},
'upgradeExecutor',
Curried
>
>
>;

export type BuildRemoveExecutorReturnType = PrepareTransactionRequestReturnTypeWithChainId;

export async function buildRemoveExecutor<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ account, upgradeExecutor: upgradeExecutorAddress, params }: BuildRemoveExecutorParameters,
): Promise<BuildRemoveExecutorReturnType> {
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 };
}
3 changes: 2 additions & 1 deletion src/prepareUpgradeExecutorCallParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TAbi extends ABIs> = GetFunctionName<TAbi>;

type EncodeFunctionDataParameters<
Expand Down

0 comments on commit 6ae4298

Please sign in to comment.