Skip to content
Open
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
27 changes: 27 additions & 0 deletions src/actions/hasRole.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than hasRole, i think we also want to include upgradeExecutorFetchPrivilegedAccounts?

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Address, Chain, PublicClient, ReadContractReturnType, Transport } from 'viem';
import { upgradeExecutorABI } from '../contracts/UpgradeExecutor';
import { UpgradeExecutorRole } from '../upgradeExecutorEncodeFunctionData';
import { ActionParameters } from '../types/Actions';

export type HasRoleParameters<Curried extends boolean = false> = ActionParameters<
{
role: UpgradeExecutorRole;
address: Address;
},
'upgradeExecutor',
Curried
>;

export type HasRoleReturnType = ReadContractReturnType<typeof upgradeExecutorABI, 'hasRole'>;

export async function hasRole<TChain extends Chain>(
client: PublicClient<Transport, TChain>,
{ upgradeExecutor, params }: HasRoleParameters,
): Promise<HasRoleReturnType> {
return client.readContract({
abi: upgradeExecutorABI,
functionName: 'hasRole',
address: upgradeExecutor,
args: [params.role, params.address],
});
}