-
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
7804ca2
commit 6ae4298
Showing
3 changed files
with
88 additions
and
1 deletion.
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,43 @@ | ||
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { upgradeExecutorABI } from '../contracts/UpgradeExecutor'; | ||
import { | ||
ActionParameters, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
WithAccount, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildAddExecutorParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
address: Address; | ||
}, | ||
'upgradeExecutor', | ||
Curried | ||
> | ||
> | ||
>; | ||
|
||
export type BuildAddExecutorReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildAddExecutor<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ account, upgradeExecutor: upgradeExecutorAddress, params }: BuildAddExecutorParameters, | ||
): Promise<BuildAddExecutorReturnType> { | ||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: upgradeExecutorAddress, | ||
upgradeExecutor: upgradeExecutorAddress, | ||
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, params.address], | ||
abi: upgradeExecutorABI, | ||
functionName: 'grantRole', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: client.chain.id }; | ||
} |
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,43 @@ | ||
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { upgradeExecutorABI } from '../contracts/UpgradeExecutor'; | ||
import { | ||
ActionParameters, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
WithAccount, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildRemoveExecutorParameters<Curried extends boolean = false> = Prettify< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
address: Address; | ||
}, | ||
'upgradeExecutor', | ||
Curried | ||
> | ||
> | ||
>; | ||
|
||
export type BuildRemoveExecutorReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildRemoveExecutor<TChain extends Chain>( | ||
client: PublicClient<Transport, TChain>, | ||
{ account, upgradeExecutor: upgradeExecutorAddress, params }: BuildRemoveExecutorParameters, | ||
): Promise<BuildRemoveExecutorReturnType> { | ||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain as Chain | undefined, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: upgradeExecutorAddress, | ||
upgradeExecutor: upgradeExecutorAddress, | ||
args: [UPGRADE_EXECUTOR_ROLE_EXECUTOR, params.address], | ||
abi: upgradeExecutorABI, | ||
functionName: 'revokeRole', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: client.chain.id }; | ||
} |
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