UNPKG

@mysten/suins

Version:
1 lines 7.56 kB
{"version":3,"file":"pricing_config.mjs","names":["vec_map.VecMap"],"sources":["../../../src/contracts/suins/pricing_config.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\nimport {\n\tMoveTuple,\n\tMoveStruct,\n\tnormalizeMoveArguments,\n\ttype RawTransactionArgument,\n} from '../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nimport { type Transaction } from '@mysten/sui/transactions';\nimport * as vec_map from './deps/sui/vec_map.js';\nconst $moduleName = '@suins/core::pricing_config';\nexport const Range = new MoveTuple({\n\tname: `${$moduleName}::Range`,\n\tfields: [bcs.u64(), bcs.u64()],\n});\nexport const PricingConfig = new MoveStruct({\n\tname: `${$moduleName}::PricingConfig`,\n\tfields: {\n\t\tpricing: vec_map.VecMap(Range, bcs.u64()),\n\t},\n});\nexport const RenewalConfig = new MoveStruct({\n\tname: `${$moduleName}::RenewalConfig`,\n\tfields: {\n\t\tconfig: PricingConfig,\n\t},\n});\nexport interface CalculateBasePriceArguments {\n\tconfig: RawTransactionArgument<string>;\n\tlength: RawTransactionArgument<number | bigint>;\n}\nexport interface CalculateBasePriceOptions {\n\tpackage?: string;\n\targuments:\n\t\t| CalculateBasePriceArguments\n\t\t| [config: RawTransactionArgument<string>, length: RawTransactionArgument<number | bigint>];\n}\n/**\n * Calculates the base price for a given length.\n *\n * - Base price type is abstracted away. We can switch to a different base. Our\n * core base will become USDC.\n * - The price is calculated based on the length of the domain name and the\n * available ranges.\n */\nexport function calculateBasePrice(options: CalculateBasePriceOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, 'u64'] satisfies (string | null)[];\n\tconst parameterNames = ['config', 'length'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing_config',\n\t\t\tfunction: 'calculate_base_price',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface NewArguments {\n\tranges: RawTransactionArgument<string[]>;\n\tprices: RawTransactionArgument<number | bigint[]>;\n}\nexport interface NewOptions {\n\tpackage?: string;\n\targuments:\n\t\t| NewArguments\n\t\t| [ranges: RawTransactionArgument<string[]>, prices: RawTransactionArgument<number | bigint[]>];\n}\n/**\n * Creates a new PricingConfig with the given ranges and prices.\n *\n * - The ranges should be sorted in `ascending order` and should not overlap.\n * - The length of the ranges and prices should be the same.\n *\n * All the ranges are inclusive (e.g. [3,5]: includes 3, 4, and 5).\n */\nexport function _new(options: NewOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = ['vector<null>', 'vector<u64>'] satisfies (string | null)[];\n\tconst parameterNames = ['ranges', 'prices'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing_config',\n\t\t\tfunction: 'new',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface IsBetweenInclusiveArguments {\n\trange: RawTransactionArgument<string>;\n\tlength: RawTransactionArgument<number | bigint>;\n}\nexport interface IsBetweenInclusiveOptions {\n\tpackage?: string;\n\targuments:\n\t\t| IsBetweenInclusiveArguments\n\t\t| [range: RawTransactionArgument<string>, length: RawTransactionArgument<number | bigint>];\n}\n/** Checks if the value is between the range (inclusive). */\nexport function isBetweenInclusive(options: IsBetweenInclusiveOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null, 'u64'] satisfies (string | null)[];\n\tconst parameterNames = ['range', 'length'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing_config',\n\t\t\tfunction: 'is_between_inclusive',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface PricingArguments {\n\tconfig: RawTransactionArgument<string>;\n}\nexport interface PricingOptions {\n\tpackage?: string;\n\targuments: PricingArguments | [config: RawTransactionArgument<string>];\n}\n/** Returns the pricing config for usage in external apps. */\nexport function pricing(options: PricingOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['config'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing_config',\n\t\t\tfunction: 'pricing',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface NewRenewalConfigArguments {\n\tconfig: RawTransactionArgument<string>;\n}\nexport interface NewRenewalConfigOptions {\n\tpackage?: string;\n\targuments: NewRenewalConfigArguments | [config: RawTransactionArgument<string>];\n}\n/** Constructor for Renewal<T> that initializes it with a PricingConfig. */\nexport function newRenewalConfig(options: NewRenewalConfigOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['config'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing_config',\n\t\t\tfunction: 'new_renewal_config',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface NewRangeArguments {\n\trange: RawTransactionArgument<number | bigint[]>;\n}\nexport interface NewRangeOptions {\n\tpackage?: string;\n\targuments: NewRangeArguments | [range: RawTransactionArgument<number | bigint[]>];\n}\nexport function newRange(options: NewRangeOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = ['vector<u64>'] satisfies (string | null)[];\n\tconst parameterNames = ['range'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing_config',\n\t\t\tfunction: 'new_range',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface ConfigArguments {\n\trenewal: RawTransactionArgument<string>;\n}\nexport interface ConfigOptions {\n\tpackage?: string;\n\targuments: ConfigArguments | [renewal: RawTransactionArgument<string>];\n}\nexport function config(options: ConfigOptions) {\n\tconst packageAddress = options.package ?? '@suins/core';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['renewal'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing_config',\n\t\t\tfunction: 'config',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,cAAc;AACpB,MAAa,QAAQ,IAAI,UAAU;CAClC,MAAM,GAAG,YAAY;CACrB,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,KAAK,CAAC;CAC9B,CAAC;AACF,MAAa,gBAAgB,IAAI,WAAW;CAC3C,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,SAASA,OAAe,OAAO,IAAI,KAAK,CAAC,EACzC;CACD,CAAC;AACF,MAAa,gBAAgB,IAAI,WAAW;CAC3C,MAAM,GAAG,YAAY;CACrB,QAAQ,EACP,QAAQ,eACR;CACD,CAAC"}