Skip to content

Commit d53231d

Browse files
committed
Feat: Add v1 upgradeExecutor setters
1 parent 03117ca commit d53231d

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/actions/addExecutor.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {
2+
Address,
3+
Chain,
4+
PrepareTransactionRequestParameters,
5+
PrepareTransactionRequestReturnType,
6+
PublicClient,
7+
Transport,
8+
encodeFunctionData,
9+
} from 'viem';
10+
import { upgradeExecutor } from '../contracts';
11+
import { ActionParameters, WithAccount } from '../types/Actions';
12+
import { Prettify } from '../types/utils';
13+
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData';
14+
15+
export type AddExecutorParameters<Curried extends boolean = false> = Prettify<
16+
WithAccount<
17+
ActionParameters<
18+
{
19+
address: Address;
20+
},
21+
'upgradeExecutor',
22+
Curried
23+
>
24+
>
25+
>;
26+
27+
export type AddExecutorReturnType = PrepareTransactionRequestReturnType;
28+
29+
function upgradeExecutorFunctionData({ address }: AddExecutorParameters) {
30+
return encodeFunctionData({
31+
abi: upgradeExecutor.abi,
32+
functionName: 'grantRole',
33+
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, address],
34+
});
35+
}
36+
37+
export async function addExecutor<TChain extends Chain | undefined>(
38+
client: PublicClient<Transport, TChain>,
39+
args: AddExecutorParameters,
40+
): Promise<AddExecutorReturnType> {
41+
const data = upgradeExecutorFunctionData(args);
42+
43+
return client.prepareTransactionRequest({
44+
to: args.upgradeExecutor,
45+
value: BigInt(0),
46+
chain: client.chain,
47+
data,
48+
account: args.account,
49+
} satisfies PrepareTransactionRequestParameters);
50+
}

src/actions/removeExecutor.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {
2+
Address,
3+
Chain,
4+
PrepareTransactionRequestParameters,
5+
PrepareTransactionRequestReturnType,
6+
PublicClient,
7+
Transport,
8+
encodeFunctionData,
9+
} from 'viem';
10+
import { upgradeExecutor } from '../contracts';
11+
import { ActionParameters, WithAccount } from '../types/Actions';
12+
import { Prettify } from '../types/utils';
13+
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData';
14+
15+
export type RemoveExecutorParameters<Curried extends boolean = false> = Prettify<
16+
WithAccount<
17+
ActionParameters<
18+
{
19+
address: Address;
20+
},
21+
'upgradeExecutor',
22+
Curried
23+
>
24+
>
25+
>;
26+
27+
export type RemoveExecutorReturnType = PrepareTransactionRequestReturnType;
28+
29+
function upgradeExecutorFunctionData({ address }: RemoveExecutorParameters) {
30+
return encodeFunctionData({
31+
abi: upgradeExecutor.abi,
32+
functionName: 'revokeRole',
33+
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, address],
34+
});
35+
}
36+
37+
export async function removeExecutor<TChain extends Chain | undefined>(
38+
client: PublicClient<Transport, TChain>,
39+
args: RemoveExecutorParameters,
40+
): Promise<RemoveExecutorReturnType> {
41+
const data = upgradeExecutorFunctionData(args);
42+
43+
return client.prepareTransactionRequest({
44+
to: args.upgradeExecutor,
45+
value: BigInt(0),
46+
chain: client.chain,
47+
data,
48+
account: args.account,
49+
} satisfies PrepareTransactionRequestParameters);
50+
}

0 commit comments

Comments
 (0)