-
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.
- Loading branch information
1 parent
3ada665
commit c25cf41
Showing
3 changed files
with
52 additions
and
74 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 |
---|---|---|
@@ -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 }; | ||
} |
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 |
---|---|---|
@@ -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 }; | ||
} |
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