Skip to content

Commit

Permalink
Add upgradeExecutor flag
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Jul 15, 2024
1 parent 3ada665 commit c25cf41
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 74 deletions.
61 changes: 25 additions & 36 deletions src/actions/addExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
import {
Address,
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { upgradeExecutor } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { PrepareTransactionRequestReturnTypeWithChainId, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData';
import { withUpgradeExecutor } from '../withUpgradeExecutor';

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

export type AddExecutorReturnType = PrepareTransactionRequestReturnType;

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

export async function addExecutor<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: AddExecutorParameters,
params: AddExecutorParameters,
): Promise<AddExecutorReturnType> {
const data = upgradeExecutorFunctionData(args);
if (!client.chain) {
throw new Error("[addExecutor] client doesn't have a chain property");
}
const { account, upgradeExecutor: upgradeExecutorAddress, address } = params;

return client.prepareTransactionRequest({
to: args.upgradeExecutor,
value: BigInt(0),
const request = await client.prepareTransactionRequest({
chain: client.chain,
data,
account: args.account,
account,
...withUpgradeExecutor({
to: upgradeExecutorAddress,
upgradeExecutor: upgradeExecutorAddress,
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, address],
abi: upgradeExecutor.abi,
functionName: 'grantRole',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: client.chain.id };
}
61 changes: 25 additions & 36 deletions src/actions/removeExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,39 @@
import {
Address,
Chain,
PrepareTransactionRequestParameters,
PrepareTransactionRequestReturnType,
PublicClient,
Transport,
encodeFunctionData,
} from 'viem';
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem';
import { upgradeExecutor } from '../contracts';
import { ActionParameters, WithAccount } from '../types/Actions';
import { PrepareTransactionRequestReturnTypeWithChainId, WithAccount } from '../types/Actions';
import { Prettify } from '../types/utils';
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData';
import { withUpgradeExecutor } from '../withUpgradeExecutor';

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

export type RemoveExecutorReturnType = PrepareTransactionRequestReturnType;

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

export async function removeExecutor<TChain extends Chain | undefined>(
client: PublicClient<Transport, TChain>,
args: RemoveExecutorParameters,
params: RemoveExecutorParameters,
): Promise<RemoveExecutorReturnType> {
const data = upgradeExecutorFunctionData(args);
if (!client.chain) {
throw new Error("[removeExecutor] client doesn't have a chain property");
}
const { account, upgradeExecutor: upgradeExecutorAddress, address } = params;

return client.prepareTransactionRequest({
to: args.upgradeExecutor,
value: BigInt(0),
const request = await client.prepareTransactionRequest({
chain: client.chain,
data,
account: args.account,
account,
...withUpgradeExecutor({
to: upgradeExecutorAddress,
upgradeExecutor: upgradeExecutorAddress,
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, address],
abi: upgradeExecutor.abi,
functionName: 'revokeRole',
}),
} satisfies PrepareTransactionRequestParameters);

return { ...request, chainId: client.chain.id };
}
4 changes: 2 additions & 2 deletions src/withUpgradeExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
EncodeFunctionDataParameters as ViemEncodeFunctionDataParameters,
} from 'viem';
import { GetFunctionName } from './types/utils';
import { arbOwner, sequencerInbox } from './contracts';
import { arbOwner, sequencerInbox, upgradeExecutor } from './contracts';
import { upgradeExecutorEncodeFunctionData } from './upgradeExecutorEncodeFunctionData';

type ABIs = typeof sequencerInbox.abi | typeof arbOwner.abi;
type ABIs = typeof sequencerInbox.abi | typeof arbOwner.abi | typeof upgradeExecutor.abi;
type FunctionName<TAbi extends ABIs> = GetFunctionName<TAbi>;

type EncodeFunctionDataParameters<
Expand Down

0 comments on commit c25cf41

Please sign in to comment.