-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add v1 upgradeExecutor setters
- Loading branch information
1 parent
6e77069
commit 6c8eef6
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |