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 Jul 9, 2024
1 parent 6e77069 commit 6c8eef6
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
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);
}

0 comments on commit 6c8eef6

Please sign in to comment.