From 68e217f3ff031915e7ed8efca3af9ac51d48e070 Mon Sep 17 00:00:00 2001 From: Christophe Date: Mon, 10 Jun 2024 09:40:41 +0000 Subject: [PATCH] Remove decorator --- src/decorators/publicActionsParentChain.ts | 205 --------------------- src/types/Actions.ts | 45 ----- 2 files changed, 250 deletions(-) delete mode 100644 src/decorators/publicActionsParentChain.ts delete mode 100644 src/types/Actions.ts diff --git a/src/decorators/publicActionsParentChain.ts b/src/decorators/publicActionsParentChain.ts deleted file mode 100644 index 8544ec38..00000000 --- a/src/decorators/publicActionsParentChain.ts +++ /dev/null @@ -1,205 +0,0 @@ -import { Address, Chain, PublicClient, Transport } from 'viem'; -import { - getBatchCount, - GetBatchCountActionParameters, - GetBatchCountReturnType, -} from '../actions/getBatchCount'; -import { getBridge, GetBridgeActionParameters, GetBridgeReturnType } from '../actions/getBridge'; -import { - getDasKeySetInfo, - GetDasKeySetInfoActionParameters, - GetDasKeySetInfoReturnType, -} from '../actions/getDasKeySetInfo'; -import { - getDataAuthenticatedFlag, - GetDataAuthenticatedFlagActionParameters, - GetDataAuthenticatedFlagReturnType, -} from '../actions/getDataAuthenticatedFlag'; -import { - getHeaderLength, - GetHeaderLengthActionParameters, - GetHeaderLengthReturnType, -} from '../actions/getHeaderLength'; -import { - getInboxAccs, - GetInboxAccsActionParameters, - GetInboxAccsReturnType, -} from '../actions/getInboxAccs'; -import { - getKeysetCreationBlock, - GetKeysetCreationBlockActionParameters, - GetKeysetCreationBlockReturnType, -} from '../actions/getKeysetCreationBlock'; -import { - getMaxTimeVariation, - GetMaxTimeVariationActionParameters, - GetMaxTimeVariationReturnType, -} from '../actions/getMaxTimeVariation'; -import { - getTotalDelayedMessagesRead, - GetTotalDelayedMessagesReadActionParameters, - GetTotalDelayedMessagesReadReturnType, -} from '../actions/getTotalDelayedMessagesRead'; -import { - isBatchPoster, - IsBatchPosterActionParameters, - IsBatchPosterReturnType, -} from '../actions/isBatchPoster'; -import { - isValidKeysetHash, - IsValidKeysetHashActionParameters, - IsValidKeysetHashReturnType, -} from '../actions/isValidKeysetHash'; - -import { getRollup, GetRollupActionParameters, GetRollupReturnType } from '../actions/getRollup'; - -type Params = { sequencerInbox: Address } | void; - -export type PublicActionsParentChain = { - getBatchCount: ( - parameters: GetBatchCountActionParameters, - ) => Promise; - getBridge: (parameters: GetBridgeActionParameters) => Promise; - getDasKeySetInfo: ( - parameters: GetDasKeySetInfoActionParameters, - ) => Promise; - getDataAuthenticatedFlag: ( - parameters: GetDataAuthenticatedFlagActionParameters, - ) => Promise; - getHeaderLength: ( - parameters: GetHeaderLengthActionParameters, - ) => Promise; - getInboxAccs: ( - parameters: GetInboxAccsActionParameters, - ) => Promise; - getKeysetCreationBlock: ( - parameters: GetKeysetCreationBlockActionParameters, - ) => Promise; - getMaxTimeVariation: ( - parameters: GetMaxTimeVariationActionParameters, - ) => Promise; - getRollup: (parameters: GetRollupActionParameters) => Promise; - getTotalDelayedMessagesRead: ( - parameters: GetTotalDelayedMessagesReadActionParameters, - ) => Promise; - isBatchPoster: ( - parameters: IsBatchPosterActionParameters, - ) => Promise; - isValidKeysetHash: ( - parameters: IsValidKeysetHashActionParameters, - ) => Promise; -}; - -/** - * Simplifies the overall typing with curried sequencerInbox address - * - * By design, sequencerInbox is either passed initially from the decorator, or on each call - * - * Address passed through each call has the priority over the address passed to the decorator, for override - */ -function getSequencerInboxAddress(params: Params, args: { sequencerInbox?: Address }): Address { - if (params) { - return (args.sequencerInbox ?? params.sequencerInbox) as Address; - } - return args.sequencerInbox as Address; -} - -/** - * Public actions for parent chain - * - * @example - * import { publicActionsParentChain } from '@arbitrum/orbit-sdk' - * import { arbitrum } from 'viem/chains' - * - * export const publicClientParentChain = createPublicClient({ - * chain: arbitrum, - * transport: http(), - * }).extend(publicActionsParentChain({ - * sequencerInbox: '0x1c479675ad559DC151F6Ec7ed3FbF8ceE79582B6' - * })) - * - * const batchCount = await publicClientParentChain.getBatchCount() - */ -export function publicActionsParentChain< - TParams extends Params = void, - TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined, ->(params: void): (client: PublicClient) => PublicActionsParentChain; -export function publicActionsParentChain< - TParams extends Params = { sequencerInbox: Address }, - TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined, ->(params: TParams): (client: PublicClient) => PublicActionsParentChain; -export function publicActionsParentChain< - TParams extends Params, - TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined, ->(params: TParams) { - return (client: PublicClient) => { - // sequencerInbox is curried, sequencerInbox param is optional. - return { - getBatchCount: (args) => - getBatchCount(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getBridge: (args) => - getBridge(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getDasKeySetInfo: (args) => - getDasKeySetInfo(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getDataAuthenticatedFlag: (args) => - getDataAuthenticatedFlag(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getHeaderLength: (args) => - getHeaderLength(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getInboxAccs: (args) => - getInboxAccs(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getKeysetCreationBlock: (args) => - getKeysetCreationBlock(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getMaxTimeVariation: (args) => - getMaxTimeVariation(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getRollup: (args) => - getRollup(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - getTotalDelayedMessagesRead: (args) => - getTotalDelayedMessagesRead(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - isBatchPoster: (args) => - isBatchPoster(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - isValidKeysetHash: (args) => - isValidKeysetHash(client, { - ...args, - sequencerInbox: getSequencerInboxAddress(params, args), - }), - } satisfies PublicActionsParentChain< - TParams extends { sequencerInbox: Address } ? true : false - >; - }; -} diff --git a/src/types/Actions.ts b/src/types/Actions.ts deleted file mode 100644 index 5bf794cd..00000000 --- a/src/types/Actions.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Address } from 'viem'; -import { Prettify } from './utils'; - -type RemoveUndefinedArgs = T extends { args?: undefined } ? Omit : T; - -/** - * If the function has no args, `GetFunctionArgs` returns `{ args?: undefined }` - * we remove args from the returned type - * - * Contract address is required if no contract address was passed to the actions, otherwise it's optional - */ -export type WithContractAddress< - Args, - ContractName extends string, - Curried extends boolean = false, -> = Prettify< - RemoveUndefinedArgs< - Args & - (Curried extends true - ? { - [key in ContractName]?: Address; - } - : { [key in ContractName]: Address }) - > ->; - -/** - * 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; - } ->;