From 20390ad3fbf1700d905222ac0e01af2dd5ed21dc Mon Sep 17 00:00:00 2001 From: Sam McCord Date: Wed, 21 Aug 2024 09:22:02 -0600 Subject: [PATCH 1/4] feat(v4): use filter at top level for operators instead of filteroperator --- packages/utils/src/types/actions.ts | 19 ++++++++------- packages/utils/src/types/filters.ts | 36 +++++++++++++++-------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/utils/src/types/actions.ts b/packages/utils/src/types/actions.ts index f0e1f9ac5..b170b39b4 100644 --- a/packages/utils/src/types/actions.ts +++ b/packages/utils/src/types/actions.ts @@ -1,20 +1,19 @@ +import { UUID } from 'crypto' import { - type PublicClient, type Address, + type PublicClient, type SimulateContractReturnType, type TransactionRequest, } from 'viem' +import { ZodSchema, z } from 'zod' +import { PluginActionNotImplementedError } from '../errors' +import { EthAddressSchema } from './common' import { - FilterOperatorSchema, - NumericSchema, + FilterSchema, type FilterOperator, - type TransactionFilter, + type TransactionFilter } from './filters' -import { PluginActionNotImplementedError } from '../errors' import type { MintIntentParams } from './intents' -import { ZodSchema, z } from 'zod' -import { EthAddressSchema } from './common' -import { UUID } from 'crypto' import { QuestCompletionPayload } from './quests' export type SwapActionParams = { @@ -216,7 +215,7 @@ export const StakeActionFormSchema = BaseStakeActionFormaSchema export const MintActionFormSchema = z.object({ contractAddress: EthAddressSchema, tokenId: z.number().optional(), - amount: z.union([NumericSchema, FilterOperatorSchema]), + amount: FilterSchema, amountOperator: QuestInputActionParamsAmountOperatorEnum.optional(), }) @@ -224,7 +223,7 @@ export const MintActionDetailSchema = z.object({ chainId: z.number(), contractAddress: EthAddressSchema, tokenId: z.number().optional(), - amount: z.union([NumericSchema, FilterOperatorSchema]), + amount: FilterSchema, amountOperator: QuestInputActionParamsAmountOperatorEnum.optional(), }) diff --git a/packages/utils/src/types/filters.ts b/packages/utils/src/types/filters.ts index 5c80ebb3f..5afc73c03 100644 --- a/packages/utils/src/types/filters.ts +++ b/packages/utils/src/types/filters.ts @@ -66,13 +66,13 @@ export type FilterOperator = export type ArrayOperator = | { - $some?: FilterOperator[] + $some?: Filter[] } | { - $first?: FilterOperator + $first?: Filter } | { - $last?: FilterOperator + $last?: Filter } | { $nth?: NthFilter @@ -81,33 +81,33 @@ export type ArrayOperator = export const ArrayOperatorSchema: z.ZodType = z.union([ z.object({ $some: z - .lazy(() => FilterOperatorSchema) + .lazy(() => FilterSchema) .array() .optional(), }), - z.object({ $first: z.lazy(() => FilterOperatorSchema).optional() }), - z.object({ $last: z.lazy(() => FilterOperatorSchema).optional() }), - z.object({ $nth: z.lazy(() => NthFilterSchema).optional() }), + z.object({ $first: z.lazy(() => FilterSchema).optional() }), + z.object({ $last: z.lazy(() => FilterSchema).optional() }), + z.object({ $nth: z.lazy(() => FilterSchema).optional() }), ]) export type LogicalOperator = | { - $and?: FilterOperator[] + $and?: Filter[] } | { - $or?: FilterOperator[] + $or?: Filter[] } export const LogicalOperatorSchema: z.ZodType = z.union([ z.object({ $and: z - .lazy(() => FilterOperatorSchema) + .lazy(() => FilterSchema) .array() .optional(), }), z.object({ $or: z - .lazy(() => FilterOperatorSchema) + .lazy(() => FilterSchema) .array() .optional(), }), @@ -121,16 +121,16 @@ export const FilterOperatorSchema = z.union([ ]) export type TransactionFilter = { - [K in keyof Transaction]: FilterOperator + [K in keyof Partial]: Filter } -export const TransactionFilterSchema = z.record( +export const TransactionFilterSchema: z.ZodType = z.record( z.string(), - FilterOperatorSchema, + z.lazy(() => FilterSchema), ) -type Primitive = string | number | boolean -export const PrimitiveSchema = z.union([z.string(), z.number(), z.boolean()]) +type Primitive = string | number | boolean | bigint +export const PrimitiveSchema = z.union([z.string(), z.number(), z.boolean(), z.bigint()]) export type FilterObject = { [key: string]: Filter @@ -171,12 +171,14 @@ export const AbiParamFilterSchema = z export type Filter = | Primitive + | Array | FilterObject | FilterArray | FilterOperator | Abi export const FilterSchema = z.union([ PrimitiveSchema, + PrimitiveSchema.array(), FilterObjectSchema, FilterOperatorSchema, z.lazy(() => FilterSchema.array()), @@ -188,7 +190,7 @@ export const FilterArraySchema = FilterSchema.array() export type NthFilter = { index: bigint | number | string - value: TransactionFilter | FilterObject + value: TransactionFilter | Filter } export const NthFilterSchema = z.object({ index: z.union([z.bigint(), z.number(), z.string()]), From ab67847e37e4cb67011f5723c665c345fd8b81ea Mon Sep 17 00:00:00 2001 From: Sam McCord Date: Wed, 21 Aug 2024 11:56:14 -0600 Subject: [PATCH 2/4] feat(utils): expand mint params to encapsulate all combinations of filters --- .changeset/dry-ducks-sleep.md | 5 +++++ packages/utils/src/index.ts | 3 +++ packages/utils/src/types/filters.ts | 2 +- packages/utils/src/types/index.ts | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/dry-ducks-sleep.md diff --git a/.changeset/dry-ducks-sleep.md b/.changeset/dry-ducks-sleep.md new file mode 100644 index 000000000..ae7be4cd3 --- /dev/null +++ b/.changeset/dry-ducks-sleep.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-utils": minor +--- + +allow any combination of filters in mint params diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 12b42d13c..c4aa450f3 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,3 +1,4 @@ + export { CHAIN_TO_TOKENS, Chains, @@ -93,6 +94,7 @@ export type { PremintValidationParams, PremintActionDetail, PremintActionForm, + Primitive, } from './types' export { @@ -141,6 +143,7 @@ export { PremintActionDetailSchema, PremintActionFormSchema, // Filter Schemas + // Primitive, NumericSchema, NumericOperatorSchema, BitmaskFilterSchema, diff --git a/packages/utils/src/types/filters.ts b/packages/utils/src/types/filters.ts index 5afc73c03..ff586cce6 100644 --- a/packages/utils/src/types/filters.ts +++ b/packages/utils/src/types/filters.ts @@ -129,7 +129,7 @@ export const TransactionFilterSchema: z.ZodType = z.record( z.lazy(() => FilterSchema), ) -type Primitive = string | number | boolean | bigint +export type Primitive = string | number | boolean | bigint export const PrimitiveSchema = z.union([z.string(), z.number(), z.boolean(), z.bigint()]) export type FilterObject = { diff --git a/packages/utils/src/types/index.ts b/packages/utils/src/types/index.ts index a5c953e32..4369305ae 100644 --- a/packages/utils/src/types/index.ts +++ b/packages/utils/src/types/index.ts @@ -101,6 +101,7 @@ export { export { ActionType, OrderType } from './actions' export type { + Primitive, FilterObject, BitmaskFilter, NthFilter, From ad77e7cd4060f3fd3bda31663df6d21ccde68e46 Mon Sep 17 00:00:00 2001 From: Sam McCord Date: Wed, 21 Aug 2024 12:06:16 -0600 Subject: [PATCH 3/4] chore: remove commented export --- packages/utils/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index c4aa450f3..c1e857320 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -143,7 +143,6 @@ export { PremintActionDetailSchema, PremintActionFormSchema, // Filter Schemas - // Primitive, NumericSchema, NumericOperatorSchema, BitmaskFilterSchema, From 0e4eb4c462f889c6c9552c1c3211c6e76bc9a469 Mon Sep 17 00:00:00 2001 From: sammccord Date: Wed, 21 Aug 2024 18:10:54 +0000 Subject: [PATCH 4/4] chore: format --- packages/utils/src/index.ts | 1 - packages/utils/src/types/actions.ts | 2 +- packages/utils/src/types/filters.ts | 7 ++++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index c1e857320..4ba593955 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,4 +1,3 @@ - export { CHAIN_TO_TOKENS, Chains, diff --git a/packages/utils/src/types/actions.ts b/packages/utils/src/types/actions.ts index b170b39b4..13b5f0175 100644 --- a/packages/utils/src/types/actions.ts +++ b/packages/utils/src/types/actions.ts @@ -11,7 +11,7 @@ import { EthAddressSchema } from './common' import { FilterSchema, type FilterOperator, - type TransactionFilter + type TransactionFilter, } from './filters' import type { MintIntentParams } from './intents' import { QuestCompletionPayload } from './quests' diff --git a/packages/utils/src/types/filters.ts b/packages/utils/src/types/filters.ts index ff586cce6..be2de3c34 100644 --- a/packages/utils/src/types/filters.ts +++ b/packages/utils/src/types/filters.ts @@ -130,7 +130,12 @@ export const TransactionFilterSchema: z.ZodType = z.record( ) export type Primitive = string | number | boolean | bigint -export const PrimitiveSchema = z.union([z.string(), z.number(), z.boolean(), z.bigint()]) +export const PrimitiveSchema = z.union([ + z.string(), + z.number(), + z.boolean(), + z.bigint(), +]) export type FilterObject = { [key: string]: Filter