-
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 SequencerInbox setters (#117)
- Loading branch information
1 parent
4b6abaf
commit 3170519
Showing
7 changed files
with
299 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,49 @@ | ||
import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { sequencerInboxABI } from '../contracts/SequencerInbox'; | ||
import { | ||
ActionParameters, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
WithAccount, | ||
WithUpgradeExecutor, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildInvalidateKeysetHashParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
keysetHash: Hex; | ||
}, | ||
'sequencerInbox', | ||
Curried | ||
> | ||
> | ||
> | ||
>; | ||
|
||
export type BuildInvalidateKeysetHashReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildInvalidateKeysetHash<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
params: BuildInvalidateKeysetHashParameters, | ||
): Promise<BuildInvalidateKeysetHashReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: sequencerInboxAddress, | ||
upgradeExecutor, | ||
args: [args.keysetHash], | ||
abi: sequencerInboxABI, | ||
functionName: 'setValidKeyset', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.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,63 @@ | ||
import { Address, Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { sequencerInboxABI } from '../contracts/SequencerInbox'; | ||
import { | ||
ActionParameters, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
WithAccount, | ||
WithUpgradeExecutor, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
|
||
type Args = { | ||
batchPoster: Address; | ||
}; | ||
|
||
export type BuildSetIsBatchPosterParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor<WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>> | ||
>; | ||
|
||
export type BuildSetIsBatchPosterReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
async function buildSetIsBatchPoster<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
params: BuildSetIsBatchPosterParameters & { enable: boolean }, | ||
): Promise<BuildSetIsBatchPosterReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: sequencerInboxAddress, | ||
upgradeExecutor, | ||
args: [args.batchPoster, args.enable], | ||
abi: sequencerInboxABI, | ||
functionName: 'setIsBatchPoster', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} | ||
|
||
export async function buildEnableBatchPoster<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: BuildSetIsBatchPosterParameters, | ||
): Promise<BuildSetIsBatchPosterReturnType> { | ||
return buildSetIsBatchPoster(client, { | ||
...args, | ||
enable: true, | ||
}); | ||
} | ||
|
||
export async function buildDisableBatchPoster<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
args: BuildSetIsBatchPosterParameters, | ||
): Promise<BuildSetIsBatchPosterReturnType> { | ||
return buildSetIsBatchPoster(client, { | ||
...args, | ||
enable: false, | ||
}); | ||
} |
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,45 @@ | ||
import { Chain, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { sequencerInboxABI } from '../contracts/SequencerInbox'; | ||
import { | ||
ActionParameters, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
WithAccount, | ||
WithUpgradeExecutor, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
|
||
type Args = { | ||
delayBlocks: bigint; | ||
futureBlocks: bigint; | ||
delaySeconds: bigint; | ||
futureSeconds: bigint; | ||
}; | ||
export type BuildSetMaxTimeVariationParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor<WithAccount<ActionParameters<Args, 'sequencerInbox', Curried>>> | ||
>; | ||
|
||
export type BuildSetMaxTimeVariationReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetMaxTimeVariation<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
params: BuildSetMaxTimeVariationParameters, | ||
): Promise<BuildSetMaxTimeVariationReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: sequencerInboxAddress, | ||
upgradeExecutor, | ||
args: [args], | ||
abi: sequencerInboxABI, | ||
functionName: 'setMaxTimeVariation', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.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,49 @@ | ||
import { Chain, Hex, PrepareTransactionRequestParameters, PublicClient, Transport } from 'viem'; | ||
import { sequencerInboxABI } from '../contracts/SequencerInbox'; | ||
import { | ||
ActionParameters, | ||
PrepareTransactionRequestReturnTypeWithChainId, | ||
WithAccount, | ||
WithUpgradeExecutor, | ||
} from '../types/Actions'; | ||
import { Prettify } from '../types/utils'; | ||
import { validateParentChainPublicClient } from '../types/ParentChain'; | ||
import { prepareUpgradeExecutorCallParameters } from '../prepareUpgradeExecutorCallParameters'; | ||
|
||
export type BuildSetValidKeysetParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
keyset: Hex; | ||
}, | ||
'sequencerInbox', | ||
Curried | ||
> | ||
> | ||
> | ||
>; | ||
|
||
export type BuildSetValidKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetValidKeyset<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
params: BuildSetValidKeysetParameters, | ||
): Promise<BuildSetValidKeysetReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain, | ||
account, | ||
...prepareUpgradeExecutorCallParameters({ | ||
to: sequencerInboxAddress, | ||
upgradeExecutor, | ||
args: [args.keyset], | ||
abi: sequencerInboxABI, | ||
functionName: 'setValidKeyset', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.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,3 +1,7 @@ | ||
export * from './getMaxTimeVariation'; | ||
export * from './isBatchPoster'; | ||
export * from './isValidKeysetHash'; | ||
export * from './buildInvalidateKeysetHash'; | ||
export * from './buildSetIsBatchPoster'; | ||
export * from './buildSetValidKeyset'; | ||
export * from './buildSetMaxTimeVariation'; |
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,76 @@ | ||
import { | ||
Address, | ||
encodeFunctionData as viemEncodeFunctionData, | ||
EncodeFunctionDataParameters as ViemEncodeFunctionDataParameters, | ||
} from 'viem'; | ||
import { GetFunctionName } from './types/utils'; | ||
import { sequencerInboxABI } from './contracts/SequencerInbox'; | ||
import { arbOwnerABI } from './contracts/ArbOwner'; | ||
import { | ||
upgradeExecutorEncodeFunctionData, | ||
UpgradeExecutorFunctionName, | ||
} from './upgradeExecutorEncodeFunctionData'; | ||
|
||
type ABIs = typeof sequencerInboxABI | typeof arbOwnerABI; | ||
type FunctionName<TAbi extends ABIs> = GetFunctionName<TAbi>; | ||
|
||
type EncodeFunctionDataParameters< | ||
TAbi extends ABIs, | ||
TFunctionName extends FunctionName<TAbi>, | ||
> = ViemEncodeFunctionDataParameters<TAbi, TFunctionName>; | ||
|
||
function encodeFunctionData<TAbi extends ABIs, TFunctionName extends GetFunctionName<TAbi>>({ | ||
abi, | ||
functionName, | ||
args, | ||
}: EncodeFunctionDataParameters<TAbi, TFunctionName>) { | ||
return viemEncodeFunctionData({ | ||
abi, | ||
functionName, | ||
args, | ||
} as unknown as ViemEncodeFunctionDataParameters<TAbi, TFunctionName>); | ||
} | ||
|
||
export function prepareUpgradeExecutorCallParameters< | ||
TAbi extends ABIs, | ||
TFunctionName extends FunctionName<TAbi>, | ||
>( | ||
params: EncodeFunctionDataParameters<TAbi, TFunctionName> & | ||
( | ||
| { | ||
to: Address; | ||
upgradeExecutor: false; | ||
value?: bigint; | ||
} | ||
| { | ||
to: Address; | ||
upgradeExecutor: Address; | ||
value?: bigint; | ||
upgradeExecutorFunctionName?: Extract< | ||
UpgradeExecutorFunctionName, | ||
'execute' | 'executeCall' | ||
>; | ||
} | ||
), | ||
) { | ||
const { upgradeExecutor, value = BigInt(0) } = params; | ||
if (!upgradeExecutor) { | ||
return { | ||
to: params.to, | ||
data: encodeFunctionData(params), | ||
value, | ||
}; | ||
} | ||
|
||
return { | ||
to: upgradeExecutor, | ||
data: upgradeExecutorEncodeFunctionData({ | ||
functionName: params.upgradeExecutorFunctionName ?? 'executeCall', | ||
args: [ | ||
params.to, // target | ||
encodeFunctionData(params), // targetCallData | ||
], | ||
}), | ||
value, | ||
}; | ||
} |
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