Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add v1 upgradeExecutor setters #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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