From 4f87d514979e1e29f53af46418cd1402716e2eeb Mon Sep 17 00:00:00 2001 From: Christophe Date: Thu, 27 Jun 2024 18:22:50 +0000 Subject: [PATCH 1/6] Feat: Add v1 SequencerInbox getters Closes FS-535 --- src/actions/getMaxTimeVariation.ts | 33 ++++++++++++++++++++++++++++++ src/actions/isBatchPoster.ts | 27 ++++++++++++++++++++++++ src/actions/isValidKeysetHash.ts | 31 ++++++++++++++++++++++++++++ src/types/Actions.ts | 24 ++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 src/actions/getMaxTimeVariation.ts create mode 100644 src/actions/isBatchPoster.ts create mode 100644 src/actions/isValidKeysetHash.ts create mode 100644 src/types/Actions.ts diff --git a/src/actions/getMaxTimeVariation.ts b/src/actions/getMaxTimeVariation.ts new file mode 100644 index 00000000..617b8a1d --- /dev/null +++ b/src/actions/getMaxTimeVariation.ts @@ -0,0 +1,33 @@ +import { Chain, PublicClient, Transport } from 'viem'; +import { sequencerInbox } from '../contracts'; +import { ActionParameters } from '../types/Actions'; + +export type GetMaxTimeVariationParameters = ActionParameters< + {}, + 'sequencerInbox', + Curried +>; + +export type GetMaxTimeVariationReturnType = { + delayBlocks: bigint; + futureBlocks: bigint; + delaySeconds: bigint; + futureSeconds: bigint; +}; + +export async function getMaxTimeVariation( + client: PublicClient, + args: GetMaxTimeVariationParameters, +): Promise { + const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({ + abi: sequencerInbox.abi, + functionName: 'maxTimeVariation', + address: args.sequencerInbox, + }); + return { + delayBlocks, + futureBlocks, + delaySeconds, + futureSeconds, + }; +} diff --git a/src/actions/isBatchPoster.ts b/src/actions/isBatchPoster.ts new file mode 100644 index 00000000..e878735a --- /dev/null +++ b/src/actions/isBatchPoster.ts @@ -0,0 +1,27 @@ +import { Address, Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; +import { sequencerInbox } from '../contracts'; +import { ActionParameters } from '../types/Actions'; + +type Args = { + batchPoster: Address; +}; +type SequencerInboxABI = typeof sequencerInbox.abi; +export type IsBatchPosterParameters = ActionParameters< + Args, + 'sequencerInbox', + Curried +>; + +export type IsBatchPosterReturnType = ReadContractReturnType; + +export async function isBatchPoster( + client: PublicClient, + args: IsBatchPosterParameters, +): Promise { + return client.readContract({ + abi: sequencerInbox.abi, + functionName: 'isBatchPoster', + address: args.sequencerInbox, + args: [args.batchPoster], + }); +} diff --git a/src/actions/isValidKeysetHash.ts b/src/actions/isValidKeysetHash.ts new file mode 100644 index 00000000..b1896205 --- /dev/null +++ b/src/actions/isValidKeysetHash.ts @@ -0,0 +1,31 @@ +import { Chain, Hex, PublicClient, ReadContractReturnType, Transport } from 'viem'; +import { sequencerInbox } from '../contracts'; +import { ActionParameters } from '../types/Actions'; + +type Args = { + keysetHash: Hex; +}; +type SequencerInboxABI = typeof sequencerInbox.abi; + +export type IsValidKeysetHashParameters = ActionParameters< + Args, + 'sequencerInbox', + Curried +>; + +export type IsValidKeysetHashReturnType = ReadContractReturnType< + SequencerInboxABI, + 'isValidKeysetHash' +>; + +export async function isValidKeysetHash( + client: PublicClient, + args: IsValidKeysetHashParameters, +): Promise { + return client.readContract({ + abi: sequencerInbox.abi, + functionName: 'isValidKeysetHash', + address: args.sequencerInbox, + args: [args.keysetHash], + }); +} diff --git a/src/types/Actions.ts b/src/types/Actions.ts new file mode 100644 index 00000000..9072c656 --- /dev/null +++ b/src/types/Actions.ts @@ -0,0 +1,24 @@ +import { Address } from 'viem'; +import { Prettify } from './utils'; + +type RemoveUndefinedArgs = T extends { args?: undefined } ? Omit : T; + +/** + * Actions require contract address, but as part of decorators, the address might have been passed already to the decorator. + * + * If the address was passed to the decorator, it's now optional (we still allow overrides of the address per action). + * If the action doesn't have any other parameters beside the contract address, then parameters can either be { contract: address } or void + */ +export type ActionParameters = Prettify< + Curried extends false + ? RemoveUndefinedArgs + : Args extends { args?: undefined } + ? + | { + [key in ContractName]: Address; + } + | void + : Args & { + [key in ContractName]?: Address; + } +>; From c9627be92f617ff1956dfb7f7f0c9678a139f7d0 Mon Sep 17 00:00:00 2001 From: Christophe Date: Tue, 2 Jul 2024 09:57:33 +0000 Subject: [PATCH 2/6] Refine ActionParameters type --- src/types/Actions.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/types/Actions.ts b/src/types/Actions.ts index 9072c656..0327ffba 100644 --- a/src/types/Actions.ts +++ b/src/types/Actions.ts @@ -1,8 +1,6 @@ import { Address } from 'viem'; import { Prettify } from './utils'; -type RemoveUndefinedArgs = T extends { args?: undefined } ? Omit : T; - /** * Actions require contract address, but as part of decorators, the address might have been passed already to the decorator. * @@ -11,8 +9,8 @@ type RemoveUndefinedArgs = T extends { args?: undefined } ? Omit : */ export type ActionParameters = Prettify< Curried extends false - ? RemoveUndefinedArgs - : Args extends { args?: undefined } + ? Args & { [key in ContractName]: Address } + : Args extends Record ? | { [key in ContractName]: Address; From a57924e448b5a6f9064c602178f9f8d3fd81d953 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 15 Jul 2024 15:46:19 +0000 Subject: [PATCH 3/6] Remove unecessary generic type --- src/actions/getMaxTimeVariation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/getMaxTimeVariation.ts b/src/actions/getMaxTimeVariation.ts index 617b8a1d..b82fc32e 100644 --- a/src/actions/getMaxTimeVariation.ts +++ b/src/actions/getMaxTimeVariation.ts @@ -17,7 +17,7 @@ export type GetMaxTimeVariationReturnType = { export async function getMaxTimeVariation( client: PublicClient, - args: GetMaxTimeVariationParameters, + args: GetMaxTimeVariationParameters, ): Promise { const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({ abi: sequencerInbox.abi, From 497ae61ed772fb903fe38f2d4b25cbf687eb40b1 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 10:34:06 +0000 Subject: [PATCH 4/6] Update ABI paths --- src/actions/getMaxTimeVariation.ts | 4 ++-- src/actions/isBatchPoster.ts | 10 ++++++---- src/actions/isValidKeysetHash.ts | 7 +++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/actions/getMaxTimeVariation.ts b/src/actions/getMaxTimeVariation.ts index b82fc32e..b0bfe82c 100644 --- a/src/actions/getMaxTimeVariation.ts +++ b/src/actions/getMaxTimeVariation.ts @@ -1,5 +1,5 @@ import { Chain, PublicClient, Transport } from 'viem'; -import { sequencerInbox } from '../contracts'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters } from '../types/Actions'; export type GetMaxTimeVariationParameters = ActionParameters< @@ -20,7 +20,7 @@ export async function getMaxTimeVariation( args: GetMaxTimeVariationParameters, ): Promise { const [delayBlocks, futureBlocks, delaySeconds, futureSeconds] = await client.readContract({ - abi: sequencerInbox.abi, + abi: sequencerInboxABI, functionName: 'maxTimeVariation', address: args.sequencerInbox, }); diff --git a/src/actions/isBatchPoster.ts b/src/actions/isBatchPoster.ts index e878735a..f71b773f 100644 --- a/src/actions/isBatchPoster.ts +++ b/src/actions/isBatchPoster.ts @@ -1,25 +1,27 @@ import { Address, Chain, PublicClient, ReadContractReturnType, Transport } from 'viem'; -import { sequencerInbox } from '../contracts'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters } from '../types/Actions'; type Args = { batchPoster: Address; }; -type SequencerInboxABI = typeof sequencerInbox.abi; export type IsBatchPosterParameters = ActionParameters< Args, 'sequencerInbox', Curried >; -export type IsBatchPosterReturnType = ReadContractReturnType; +export type IsBatchPosterReturnType = ReadContractReturnType< + typeof sequencerInboxABI, + 'isBatchPoster' +>; export async function isBatchPoster( client: PublicClient, args: IsBatchPosterParameters, ): Promise { return client.readContract({ - abi: sequencerInbox.abi, + abi: sequencerInboxABI, functionName: 'isBatchPoster', address: args.sequencerInbox, args: [args.batchPoster], diff --git a/src/actions/isValidKeysetHash.ts b/src/actions/isValidKeysetHash.ts index b1896205..1a5e7007 100644 --- a/src/actions/isValidKeysetHash.ts +++ b/src/actions/isValidKeysetHash.ts @@ -1,11 +1,10 @@ import { Chain, Hex, PublicClient, ReadContractReturnType, Transport } from 'viem'; -import { sequencerInbox } from '../contracts'; +import { sequencerInboxABI } from '../contracts/SequencerInbox'; import { ActionParameters } from '../types/Actions'; type Args = { keysetHash: Hex; }; -type SequencerInboxABI = typeof sequencerInbox.abi; export type IsValidKeysetHashParameters = ActionParameters< Args, @@ -14,7 +13,7 @@ export type IsValidKeysetHashParameters = Actio >; export type IsValidKeysetHashReturnType = ReadContractReturnType< - SequencerInboxABI, + typeof sequencerInboxABI, 'isValidKeysetHash' >; @@ -23,7 +22,7 @@ export async function isValidKeysetHash( args: IsValidKeysetHashParameters, ): Promise { return client.readContract({ - abi: sequencerInbox.abi, + abi: sequencerInboxABI, functionName: 'isValidKeysetHash', address: args.sequencerInbox, args: [args.keysetHash], From d5b70035d3557088f1608b5f5c2126e84fa4e2c5 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 10:41:54 +0000 Subject: [PATCH 5/6] Export actions --- src/actions/index.ts | 5 +++++ src/index.ts | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 src/actions/index.ts diff --git a/src/actions/index.ts b/src/actions/index.ts new file mode 100644 index 00000000..9b7e4c3f --- /dev/null +++ b/src/actions/index.ts @@ -0,0 +1,5 @@ +import { getMaxTimeVariation } from './getMaxTimeVariation'; +import { isBatchPoster } from './isBatchPoster'; +import { isValidKeysetHash } from './isValidKeysetHash'; + +export { getMaxTimeVariation, isBatchPoster, isValidKeysetHash }; diff --git a/src/index.ts b/src/index.ts index 3f143780..0c9e81e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -137,6 +137,7 @@ import { getConsensusReleaseByWasmModuleRoot, GetConsensusReleaseByWasmModuleRoot, } from './wasmModuleRoot'; +import { getMaxTimeVariation, isBatchPoster, isValidKeysetHash } from './actions'; export { arbOwnerPublicActions, @@ -251,4 +252,8 @@ export { isKnownWasmModuleRoot, getConsensusReleaseByWasmModuleRoot, GetConsensusReleaseByWasmModuleRoot, + // + getMaxTimeVariation, + isBatchPoster, + isValidKeysetHash, }; From d4eda1c6028ca5b938cbb0af26a5b85824746b50 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 19 Aug 2024 10:47:12 +0000 Subject: [PATCH 6/6] Update exports --- src/actions/index.ts | 8 +++----- src/index.ts | 6 +----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/actions/index.ts b/src/actions/index.ts index 9b7e4c3f..63164981 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -1,5 +1,3 @@ -import { getMaxTimeVariation } from './getMaxTimeVariation'; -import { isBatchPoster } from './isBatchPoster'; -import { isValidKeysetHash } from './isValidKeysetHash'; - -export { getMaxTimeVariation, isBatchPoster, isValidKeysetHash }; +export * from './getMaxTimeVariation'; +export * from './isBatchPoster'; +export * from './isValidKeysetHash'; diff --git a/src/index.ts b/src/index.ts index 0c9e81e4..db767cbe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -137,7 +137,7 @@ import { getConsensusReleaseByWasmModuleRoot, GetConsensusReleaseByWasmModuleRoot, } from './wasmModuleRoot'; -import { getMaxTimeVariation, isBatchPoster, isValidKeysetHash } from './actions'; +export * from './actions'; export { arbOwnerPublicActions, @@ -252,8 +252,4 @@ export { isKnownWasmModuleRoot, getConsensusReleaseByWasmModuleRoot, GetConsensusReleaseByWasmModuleRoot, - // - getMaxTimeVariation, - isBatchPoster, - isValidKeysetHash, };