-
Notifications
You must be signed in to change notification settings - Fork 70
feat: add SequencerInbox setters #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3a1a87d
Feat: Add v1 SequencerInbox setters
chrstph-dvx 6faa3d6
Add WithAccount type
chrstph-dvx c352ffc
Add upgradeExecutor flag
chrstph-dvx e27405d
Add withUpgradeExecutor file
chrstph-dvx 4ca765e
Update export
chrstph-dvx 8bb0b9b
Prefix setters with prepare
chrstph-dvx eaa16aa
Replace prepare with build
chrstph-dvx 745f2c5
Add chainId to returned value in invalidateKeysetHash
chrstph-dvx 7c6e52c
Cleanup buildInvalidateKeysetHash
chrstph-dvx 51cf54a
Merge branch 'main' into add-chain-public-actions-setter
chrstph-dvx a429293
Review comments
chrstph-dvx f4a37ea
Add prepareUpgradeExecutorCallParameters
chrstph-dvx 0e74697
Rename buildSetIsbatchPoster to buildSetIsBatchPoster
chrstph-dvx e6dc732
Correct export
chrstph-dvx ba1bcb1
Rename buildSetKeyset to buildSetValidKeyset
chrstph-dvx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 { withUpgradeExecutor } from '../withUpgradeExecutor'; | ||
|
||
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, | ||
...withUpgradeExecutor({ | ||
to: sequencerInboxAddress, | ||
upgradeExecutor, | ||
args: [args.keysetHash], | ||
abi: sequencerInboxABI, | ||
functionName: 'setValidKeyset', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
This file contains hidden or 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 { withUpgradeExecutor } from '../withUpgradeExecutor'; | ||
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, | ||
...withUpgradeExecutor({ | ||
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 hidden or 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 { withUpgradeExecutor } from '../withUpgradeExecutor'; | ||
|
||
export type BuildSetKeysetParameters<Curried extends boolean = false> = Prettify< | ||
WithUpgradeExecutor< | ||
WithAccount< | ||
ActionParameters< | ||
{ | ||
keyset: Hex; | ||
}, | ||
'sequencerInbox', | ||
Curried | ||
> | ||
> | ||
> | ||
>; | ||
|
||
export type BuildSetKeysetReturnType = PrepareTransactionRequestReturnTypeWithChainId; | ||
|
||
export async function buildSetKeyset<TChain extends Chain | undefined>( | ||
client: PublicClient<Transport, TChain>, | ||
params: BuildSetKeysetParameters, | ||
): Promise<BuildSetKeysetReturnType> { | ||
const validatedPublicClient = validateParentChainPublicClient(client); | ||
const { account, upgradeExecutor, sequencerInbox: sequencerInboxAddress, ...args } = params; | ||
|
||
const request = await client.prepareTransactionRequest({ | ||
chain: client.chain, | ||
account, | ||
...withUpgradeExecutor({ | ||
to: sequencerInboxAddress, | ||
upgradeExecutor, | ||
args: [args.keyset], | ||
abi: sequencerInboxABI, | ||
functionName: 'setValidKeyset', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
This file contains hidden or 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 { withUpgradeExecutor } from '../withUpgradeExecutor'; | ||
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, | ||
...withUpgradeExecutor({ | ||
to: sequencerInboxAddress, | ||
upgradeExecutor, | ||
args: [args], | ||
abi: sequencerInboxABI, | ||
functionName: 'setMaxTimeVariation', | ||
}), | ||
} satisfies PrepareTransactionRequestParameters); | ||
|
||
return { ...request, chainId: validatedPublicClient.chain.id }; | ||
} |
This file contains hidden or 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 './buildSetKeyset'; | ||
export * from './buildSetMaxTimeVariation'; |
This file contains hidden or 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
This file contains hidden or 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,57 @@ | ||
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 } 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 withUpgradeExecutor<TAbi extends ABIs, TFunctionName extends FunctionName<TAbi>>( | ||
spsjvc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
params: EncodeFunctionDataParameters<TAbi, TFunctionName> & { | ||
to: Address; | ||
upgradeExecutor: false | Address; | ||
}, | ||
) { | ||
const { upgradeExecutor } = params; | ||
if (!upgradeExecutor) { | ||
return { | ||
to: params.to, | ||
data: encodeFunctionData(params), | ||
value: BigInt(0), | ||
spsjvc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}; | ||
} | ||
|
||
return { | ||
to: upgradeExecutor, | ||
data: upgradeExecutorEncodeFunctionData({ | ||
functionName: 'executeCall', | ||
spsjvc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
args: [ | ||
params.to, // target | ||
encodeFunctionData(params), // targetCallData | ||
], | ||
}), | ||
value: BigInt(0), | ||
spsjvc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.