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 #138

Merged
Merged
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
50 changes: 50 additions & 0 deletions src/actions/addExecutor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Address,
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { upgradeExecutor } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData';

export type AddExecutorParameters<Curried extends boolean = false> = Prettify<
WithAccount<
ActionParameters<
{
address: Address;
},
'upgradeExecutor',
Curried
>
>
>;

export type AddExecutorReturnType = PrepareTransactionRequestReturnType;

function upgradeExecutorFunctionData({ address }: AddExecutorParameters) {
return encodeFunctionData({
abi: upgradeExecutor.abi,
functionName: 'grantRole',
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, address],
});
}

export async function addExecutor<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: AddExecutorParameters,
): Promise<AddExecutorReturnType> {
const data = upgradeExecutorFunctionData(args);

return client.prepareTransactionRequest({
to: args.upgradeExecutor,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
50 changes: 50 additions & 0 deletions src/actions/removeExecutor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
Address,
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { upgradeExecutor } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData';

export type RemoveExecutorParameters<Curried extends boolean = false> = Prettify<
WithAccount<
ActionParameters<
{
address: Address;
},
'upgradeExecutor',
Curried
>
>
>;

export type RemoveExecutorReturnType = PrepareTransactionRequestReturnType;

function upgradeExecutorFunctionData({ address }: RemoveExecutorParameters) {
return encodeFunctionData({
abi: upgradeExecutor.abi,
functionName: 'revokeRole',
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, address],
});
}

export async function removeExecutor<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: RemoveExecutorParameters,
): Promise<RemoveExecutorReturnType> {
const data = upgradeExecutorFunctionData(args);

return client.prepareTransactionRequest({
to: args.upgradeExecutor,
value: BigInt(0),
chain: client.chain,
data,
account: args.account,
} satisfies PrepareTransactionRequestParameters);
}
Loading