@polyester/sdk 0.14.2 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/core-client.js +1 -1
  3. package/dist/services/address-book/address-book.schemas.d.ts +1 -1
  4. package/dist/services/address-book/address-book.schemas.d.ts.map +1 -1
  5. package/dist/services/address-book/address-book.schemas.js +2 -1
  6. package/dist/services/address-book/address-book.schemas.js.map +1 -1
  7. package/dist/services/candles/candles.d.ts.map +1 -1
  8. package/dist/services/candles/candles.js +2 -1
  9. package/dist/services/candles/candles.js.map +1 -1
  10. package/dist/services/candles/candles.schemas.d.ts +1 -1
  11. package/dist/services/candles/candles.schemas.d.ts.map +1 -1
  12. package/dist/services/candles/candles.schemas.js +3 -2
  13. package/dist/services/candles/candles.schemas.js.map +1 -1
  14. package/dist/services/chain-analytics/chain-analytics.schemas.d.ts.map +1 -1
  15. package/dist/services/chain-analytics/chain-analytics.schemas.js +5 -5
  16. package/dist/services/chain-analytics/chain-analytics.schemas.js.map +1 -1
  17. package/dist/services/deposit/deposit.schemas.d.ts +3 -3
  18. package/dist/services/deposit/deposit.schemas.d.ts.map +1 -1
  19. package/dist/services/deposit/deposit.schemas.js +4 -4
  20. package/dist/services/deposit/deposit.schemas.js.map +1 -1
  21. package/dist/services/guard-signer/guard-signer.schemas.d.ts +2 -2
  22. package/dist/services/guard-signer/guard-signer.schemas.d.ts.map +1 -1
  23. package/dist/services/guard-signer/guard-signer.schemas.js +2 -1
  24. package/dist/services/guard-signer/guard-signer.schemas.js.map +1 -1
  25. package/dist/services/heatmap/heatmap.d.ts.map +1 -1
  26. package/dist/services/heatmap/heatmap.js +2 -1
  27. package/dist/services/heatmap/heatmap.js.map +1 -1
  28. package/dist/services/heatmap/heatmap.schemas.d.ts +1 -1
  29. package/dist/services/heatmap/heatmap.schemas.d.ts.map +1 -1
  30. package/dist/services/heatmap/heatmap.schemas.js +2 -1
  31. package/dist/services/heatmap/heatmap.schemas.js.map +1 -1
  32. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +2 -2
  33. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts.map +1 -1
  34. package/dist/services/internal-transfers/internal-transfers.schemas.js +3 -2
  35. package/dist/services/internal-transfers/internal-transfers.schemas.js.map +1 -1
  36. package/dist/services/lifecycle/lifecycle.schemas.d.ts +42 -42
  37. package/dist/services/market-data/market-data.d.ts.map +1 -1
  38. package/dist/services/market-data/market-data.js +2 -1
  39. package/dist/services/market-data/market-data.js.map +1 -1
  40. package/dist/services/market-data/market-data.schemas.d.ts +1 -1
  41. package/dist/services/market-data/market-data.schemas.js +2 -2
  42. package/dist/services/market-data/market-data.schemas.js.map +1 -1
  43. package/dist/services/market-overview/market-overview.schemas.d.ts +1 -1
  44. package/dist/services/market-overview/market-overview.schemas.js +2 -2
  45. package/dist/services/market-overview/market-overview.schemas.js.map +1 -1
  46. package/dist/services/orders/orders-input.schemas.d.ts +1 -1
  47. package/dist/services/orders/orders-modify.schemas.js +1 -1
  48. package/dist/services/orders/orders-output.schemas.d.ts +6 -6
  49. package/dist/services/orders/orders-risk.schemas.d.ts.map +1 -1
  50. package/dist/services/orders/orders-risk.schemas.js +3 -4
  51. package/dist/services/orders/orders-risk.schemas.js.map +1 -1
  52. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +9 -9
  53. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts.map +1 -1
  54. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js +17 -8
  55. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js.map +1 -1
  56. package/dist/services/shared.js +4 -2
  57. package/dist/services/shared.js.map +1 -1
  58. package/dist/services/subaccounts/subaccounts.schemas.d.ts +5 -5
  59. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts +2 -2
  60. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts.map +1 -1
  61. package/dist/services/trading-withdraws/trading-withdraws.schemas.js +3 -2
  62. package/dist/services/trading-withdraws/trading-withdraws.schemas.js.map +1 -1
  63. package/dist/services/trailing-oneof-inputs.js +3 -1
  64. package/dist/services/trailing-oneof-inputs.js.map +1 -1
  65. package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
  66. package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
  67. package/dist/services/triggers/trigger-input.schemas.js +3 -3
  68. package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
  69. package/dist/services/triggers/triggers-output.schemas.d.ts +18 -18
  70. package/dist/shared/decimal-surface.d.ts.map +1 -1
  71. package/dist/shared/decimal-surface.js.map +1 -1
  72. package/dist/shared/schemas.js +4 -4
  73. package/dist/shared/schemas.js.map +1 -1
  74. package/dist/utils/numbers.js +1 -10
  75. package/dist/utils/numbers.js.map +1 -1
  76. package/package.json +1 -1
@@ -216,7 +216,7 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
216
216
  readonly granteeAccountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
217
217
  readonly inviterAccountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
218
218
  readonly role: v.SchemaWithPipe<readonly [v.EnumSchema<typeof SubaccountRole$1, undefined>, v.TransformAction<SubaccountRole$1, "unspecified" | "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer">]>;
219
- readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof SubaccountInviteStatus$1, undefined>, v.TransformAction<SubaccountInviteStatus$1, "unspecified" | "pending" | "accepted" | "declined" | "cancelled">]>;
219
+ readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof SubaccountInviteStatus$1, undefined>, v.TransformAction<SubaccountInviteStatus$1, "unspecified" | "pending" | "cancelled" | "accepted" | "declined">]>;
220
220
  readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
221
221
  readonly seconds: v.BigintSchema<undefined>;
222
222
  readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
@@ -243,7 +243,7 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
243
243
  granteeAccountId: string;
244
244
  inviterAccountId: string;
245
245
  role: "unspecified" | "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer";
246
- status: "unspecified" | "pending" | "accepted" | "declined" | "cancelled";
246
+ status: "unspecified" | "pending" | "cancelled" | "accepted" | "declined";
247
247
  createdAt?: number | undefined;
248
248
  respondedAt?: number | undefined;
249
249
  granteeUsername: string;
@@ -261,7 +261,7 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
261
261
  granteeAccountId: string;
262
262
  inviterAccountId: string;
263
263
  role: "unspecified" | "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer";
264
- status: "unspecified" | "pending" | "accepted" | "declined" | "cancelled";
264
+ status: "unspecified" | "pending" | "cancelled" | "accepted" | "declined";
265
265
  createdAt?: number | undefined;
266
266
  respondedAt?: number | undefined;
267
267
  granteeUsername: string;
@@ -283,8 +283,8 @@ declare const SubaccountActivityEventSchema: v.ObjectSchema<{
283
283
  seconds: bigint;
284
284
  nanos: number;
285
285
  } | undefined, number | undefined>]>;
286
- readonly entityKind: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEntityKind, undefined>, v.TransformAction<ActivityEntityKind, "unspecified" | "api_key" | "account" | "subaccount" | "destination" | "session" | "member" | "policy" | "invite" | "security">]>;
287
- readonly eventAction: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEventAction, undefined>, v.TransformAction<ActivityEventAction, "unspecified" | "enabled" | "disabled" | "revoked" | "deleted" | "created" | "updated" | "removed" | "role_set" | "received" | "replied" | "failed" | "blocked" | "hold_placed" | "hold_released">]>;
286
+ readonly entityKind: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEntityKind, undefined>, v.TransformAction<ActivityEntityKind, "unspecified" | "api_key" | "account" | "subaccount" | "destination" | "session" | "policy" | "member" | "invite" | "security">]>;
287
+ readonly eventAction: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEventAction, undefined>, v.TransformAction<ActivityEventAction, "unspecified" | "enabled" | "disabled" | "revoked" | "failed" | "deleted" | "created" | "updated" | "removed" | "role_set" | "received" | "replied" | "blocked" | "hold_placed" | "hold_released">]>;
288
288
  readonly source: v.SchemaWithPipe<readonly [v.EnumSchema<typeof ActivityEventSource, undefined>, v.TransformAction<ActivityEventSource, "unspecified" | "web" | "mobile" | "api">]>;
289
289
  readonly ip: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
290
290
  readonly userAgent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -19,7 +19,7 @@ type CreateTradingWithdrawRequestBase = {
19
19
  payloadSignature?: Uint8Array;
20
20
  };
21
21
  declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
22
- readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>]>;
22
+ readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
23
23
  readonly quantity: v.StringSchema<undefined>;
24
24
  readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
25
25
  readonly destinationAddress: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
@@ -40,7 +40,7 @@ declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScal
40
40
  } | undefined;
41
41
  }, CreateTradingWithdrawRequestBase>]>;
42
42
  declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
43
- readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>]>;
43
+ readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
44
44
  readonly quantity: v.StringSchema<undefined>;
45
45
  readonly destinationChainId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, number, undefined>]>;
46
46
  readonly destinationAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAgBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;EACT,mBAAmB;;iBAoCP,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;GA+BhF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;GAqCtF;KAEW,sCAAsC,EAAE,WAChD,kBAAkB;KAOV,4CAA4C,EAAE,WACtD,kBAAkB;cAOT,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,mBAAmB;cAOlD,wCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;KAgBvC,mCAAmC,EAAE,kBACtC;cA4CE,yCAAuC,EAAA,aAAA,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,oCAAoC,EAAE,mBACvC"}
1
+ {"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAiBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;EACT,mBAAmB;;iBAoCP,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;GA+BhF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;GAqCtF;KAEW,sCAAsC,EAAE,WAChD,kBAAkB;KAOV,4CAA4C,EAAE,WACtD,kBAAkB;cAOT,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,mBAAmB;cAOlD,wCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;KAgBvC,mCAAmC,EAAE,kBACtC;cA4CE,yCAAuC,EAAA,aAAA,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,oCAAoC,EAAE,mBACvC"}
@@ -1,3 +1,4 @@
1
+ import { PositiveUint32InputSchema } from "../shared.js";
1
2
  import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
2
3
  import { quantityInputToE18 } from "../../shared/decimal-surface.js";
3
4
  import { toU128 } from "../../utils/u128.js";
@@ -32,7 +33,7 @@ function createTradingWithdrawPayload(input) {
32
33
  function createCreateTradingWithdrawToFundingInputSchema(scales) {
33
34
  return v.pipe(v.strictObject({
34
35
  ...AccountScopeInputEntries,
35
- assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),
36
+ assetId: PositiveUint32InputSchema,
36
37
  quantity: v.string(),
37
38
  idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
38
39
  destinationAddress: v.optional(v.pipe(v.string(), v.trim()), ""),
@@ -61,7 +62,7 @@ function createCreateTradingWithdrawToFundingInputSchema(scales) {
61
62
  function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
62
63
  return v.pipe(v.strictObject({
63
64
  ...AccountScopeInputEntries,
64
- assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),
65
+ assetId: PositiveUint32InputSchema,
65
66
  quantity: v.string(),
66
67
  destinationChainId: v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(Number.MAX_SAFE_INTEGER)),
67
68
  destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { quantityInputToE18, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { toU128, type U128Value } from \"../../utils/u128.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n payloadSignature?: Uint8Array;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n const nonce = BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0] ?? BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n"],"mappings":";;;;;;;AAcA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,i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KAAK,GAAG,EAAE,UAAU,CAAC,CAAC,EACzD,CAAC;AAID,MAAa,0CAA0C;AAKvD,MAAa,yCAAyC,EAAE,KACpD,EAAE,aAAa;CACX,oBAAoB,EAAE,KAClB,EAAE,OAAO,GACT,EAAE,QAAQ,GACV,EAAE,QAAQ,CAAC,GACX,EAAE,SAAS,OAAO,gBAAgB,CACtC;CACA,oBAAoB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AACnE,CAAC,GACD,EAAE,WAAW,WAAW;CACpB,oBAAoB,OAAO,MAAM,kBAAkB;CACnD,oBAAoB,MAAM;AAC9B,EAAE,CACN;AASA,MAAM,uCAAuC,EAAE,KAC3C,EAAE,OAAO;CACL,OAAO,EAAE,QAAQ,IAAI;CACrB,MAAM,EAAE,QAAA,CAA+C;CACvD,SAAS,EAAE,OAAO;CAClB,6BAA6B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AAC5E,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,uCAAuC,cAAc,OAAO;AACtE,EAAE,CACN;AAEA,MAAM,GAAA,IACyC,+BAC3C,GAAG,wCACH,uCAAuC;AAE3C,MAAM,yCAAyC,EAAE,KAC7C,EAAE,OAAO;CACL,OAAO,EAAE,QAAQ,KAAK;CACtB,MAAM,EAAE,SAAS;;;;;;;CAOjB,CAAC;CACD,SAAS,EAAE,OAAO;CAClB,6BAA6B,EAAE,OAAO;AAC1C,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,oCAAoC,OAAO;AACrD,EAAE,CACN;AAEA,MAAa,0CAA0C,EAAE,MAAM,CAC3D,sCACA,sCACJ,CAAC"}
1
+ {"version":3,"file":"trading-withdraws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PositiveUint32InputSchema } from \"../shared.js\";\nimport { quantityInputToE18, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { toU128, type U128Value } from \"../../utils/u128.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n payloadSignature?: Uint8Array;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n const nonce = BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0] ?? BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n"],"mappings":";;;;;;;;AAeA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,iBAAiB,KAAK,WAAW,MAAM;CACzE,IAAI,CAAC,QAAQ;EACT,MAAM,QAAQ,OAAO,KAAK,IAAI,CAAC;EAC/B,OAAO,UAAU,KAAK,KAAK;CAC/B;CAEA,MAAM,wBAAQ,IAAI,eAAe,CAAC;CAClC,OAAO,KAAK;CACZ,MAAM,QAAQ,MAAM,MAAM,OAAO,KAAK,IAAI,CAAC;CAC3C,OAAO,UAAU,KAAK,KAAK;AAC/B;AAEA,SAAS,6BAA6B,OAOE;CACpC,OAAO;EACH,QAAQ,MAAM;EACd,SAAS,MAAM;EACf,oBAAoB,MAAM;EAC1B,WAAW,OAA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AAE,OAAO;CAClB,6BAA6B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AAC5E,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,uCAAuC,cAAc,OAAO;AACtE,EAAE,CACN;AAEA,MAAM,GAAA,IACyC,+BAC3C,GAAG,wCACH,uCAAuC;AAE3C,MAAM,yCAAyC,EAAE,KAC7C,EAAE,OAAO;CACL,OAAO,EAAE,QAAQ,KAAK;CACtB,MAAM,EAAE,SAAS;;;;;;;CAOjB,CAAC;CACD,SAAS,EAAE,OAAO;CAClB,6BAA6B,EAAE,OAAO;AAC1C,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,oCAAoC,OAAO;AACrD,EAAE,CACN;AAEA,MAAa,0CAA0C,EAAE,MAAM,CAC3D,sCACA,sCACJ,CAAC"}
@@ -3,6 +3,8 @@ import { PROTOBUF_INT32_MAX } from "../shared/wire-bounds.js";
3
3
  import { CatalogConversionError } from "../catalogs/types.js";
4
4
  import { positiveDecimalInputToScaled } from "../shared/decimal-surface.js";
5
5
  //#region src/services/trailing-oneof-inputs.ts
6
+ /** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */
7
+ const MAX_SLIPPAGE_BPS = 1e4;
6
8
  function parseTrailingDistanceInput(scales, distance, fieldName) {
7
9
  if (distance.kind === "none") return {
8
10
  case: void 0,
@@ -43,6 +45,6 @@ function exceedsMax(value, max) {
43
45
  return max !== void 0 && value > max;
44
46
  }
45
47
  //#endregion
46
- export { parseSlippageInput, parseTrailingDistanceInput };
48
+ export { MAX_SLIPPAGE_BPS, parseSlippageInput, parseTrailingDistanceInput };
47
49
 
48
50
  //# sourceMappingURL=trailing-oneof-inputs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"trailing-oneof-inputs.js","names":[],"sources":["../../src/services/trailing-oneof-inputs.ts"],"sourcesContent":["import { positiveDecimalInputToScaled, type SdkScales } from \"../shared/decimal-surface.js\";\nimport { CatalogConversionError } from \"../catalogs/types.js\";\nimport { parseOptionalPositiveIntLike } from \"../utils/numbers.js\";\nimport { PROTOBUF_INT32_MAX } from \"../shared/wire-bounds.js\";\n\ntype PositiveIntLikeInput = string | number;\n\n/**\n * Trailing distance and slippage inputs: absolute price distances and\n * slippages are decimal price strings (e.g. \"0.50\"), converted to wire ticks\n * via the price scale; basis points are integers.\n */\nexport type TrailingDistanceInput =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\nexport type SlippageInput =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\ntype UnsetOneof = { case: undefined; value: undefined };\n\ntype TrailingDistanceOneof =\n | { case: \"trailingDistanceTicks\"; value: bigint }\n | { case: \"trailingDistanceBps\"; value: number }\n | UnsetOneof;\n\ntype SlippageOneof<TicksCase extends string, BpsCase extends string> =\n | { case: TicksCase; value: number }\n | { case: BpsCase; value: number }\n | UnsetOneof;\n\ntype SlippageOptions<TicksCase extends string, BpsCase extends string> = {\n fieldName: string;\n ticksCase: TicksCase;\n bpsCase: BpsCase;\n maxBps?: number;\n};\n\nexport function parseTrailingDistanceInput(\n scales: SdkScales,\n distance: TrailingDistanceInput,\n fieldName: string,\n): TrailingDistanceOneof {\n if (distance.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (distance.kind === \"distance\") {\n return {\n case: \"trailingDistanceTicks\",\n value: positiveDecimalInputToScaled(\n `${fieldName}.distance`,\n distance.distance,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(distance.bps);\n if (bps === undefined || bps > Number(PROTOBUF_INT32_MAX)) {\n throw new CatalogConversionError(\n `${fieldName}.bps`,\n `${fieldName}Bps must be a positive integer no greater than ${PROTOBUF_INT32_MAX}`,\n );\n }\n return { case: \"trailingDistanceBps\", value: bps };\n}\n\nexport function parseSlippageInput<const TicksCase extends string, const BpsCase extends string>(\n scales: SdkScales,\n slippage: SlippageInput | undefined,\n options: SlippageOptions<TicksCase, BpsCase>,\n): SlippageOneof<TicksCase, BpsCase> {\n if (!slippage || slippage.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (slippage.kind === \"slippage\") {\n const ticks = positiveDecimalInputToScaled(\n `${options.fieldName}.slippage`,\n slippage.slippage,\n scales.price(),\n );\n if (ticks > PROTOBUF_INT32_MAX) {\n throw new CatalogConversionError(\n `${options.fieldName}.slippage`,\n `${options.fieldName}.slippage exceeds the maximum supported price distance: ${slippage.slippage}`,\n );\n }\n return { case: options.ticksCase, value: Number(ticks) };\n }\n\n const bps = parseOptionalPositiveIntLike(slippage.bps);\n if (bps === undefined || bps <= 0 || exceedsMax(bps, options.maxBps)) {\n throw new CatalogConversionError(\n `${options.fieldName}.bps`,\n `${options.fieldName}Bps must be ${\n options.maxBps === undefined\n ? \"a positive integer\"\n : `between 1 and ${options.maxBps}`\n }`,\n );\n }\n return { case: options.bpsCase, value: bps };\n}\n\nfunction exceedsMax(value: number, max: number | undefined): boolean {\n return max !== undefined && value > max;\n}\n"],"mappings":";;;;;AAyCA,SAAgB,2BACZ,QACA,UACA,WACqB;CACrB,IAAI,SAAS,SAAS,QAClB,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAClB,OAAO;EACH,MAAM;EACN,OAAO,6BACH,GAAG,UAAU,YACb,SAAS,UACT,OAAO,MAAM,CACjB;CACJ;CAGJ,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,MAAM,OAAA,WAAyB,GACpD,MAAM,IAAI,uBACN,GAAG,UAAU,OACb,GAAG,UAAU,iDAAiD,oBAClE;CAEJ,OAAO;EAAE,MAAM;EAAuB,OAAO;CAAI;AACrD;AAEA,SAAgB,mBACZ,QACA,UACA,SACiC;CACjC,IAAI,CAAC,YAAY,SAAS,SAAS,QAC/B,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAAY;EAC9B,MAAM,QAAQ,6BACV,GAAG,QAAQ,UAAU,YACrB,SAAS,UACT,OAAO,MAAM,CACjB;EACA,IAAI,QAAA,aACA,MAAM,IAAI,uBACN,GAAG,QAAQ,UAAU,YACrB,GAAG,QAAQ,UAAU,0DAA0D,SAAS,UAC5F;EAEJ,OAAO;GAAE,MAAM,QAAQ;GAAW,OAAO,OAAO,KAAK;EAAE;CAC3D;CAEA,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,OAAO,KAAK,WAAW,KAAK,QAAQ,MAAM,GAC/D,MAAM,IAAI,uBACN,GAAG,QAAQ,UAAU,OACrB,GAAG,QAAQ,UAAU,cACjB,QAAQ,WAAW,KAAA,IACb,uBACA,iBAAiB,QAAQ,UAEvC;CAEJ,OAAO;EAAE,MAAM,QAAQ;EAAS,OAAO;CAAI;AAC/C;AAEA,SAAS,WAAW,OAAe,KAAkC;CACjE,OAAO,QAAQ,KAAA,KAAa,QAAQ;AACxC"}
1
+ {"version":3,"file":"trailing-oneof-inputs.js","names":[],"sources":["../../src/services/trailing-oneof-inputs.ts"],"sourcesContent":["import { positiveDecimalInputToScaled, type SdkScales } from \"../shared/decimal-surface.js\";\nimport { CatalogConversionError } from \"../catalogs/types.js\";\nimport { parseOptionalPositiveIntLike } from \"../utils/numbers.js\";\nimport { PROTOBUF_INT32_MAX } from \"../shared/wire-bounds.js\";\n\ntype PositiveIntLikeInput = string | number;\n\n/** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */\nexport const MAX_SLIPPAGE_BPS = 10_000;\n\n/**\n * Trailing distance and slippage inputs: absolute price distances and\n * slippages are decimal price strings (e.g. \"0.50\"), converted to wire ticks\n * via the price scale; basis points are integers.\n */\nexport type TrailingDistanceInput =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\nexport type SlippageInput =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\ntype UnsetOneof = { case: undefined; value: undefined };\n\ntype TrailingDistanceOneof =\n | { case: \"trailingDistanceTicks\"; value: bigint }\n | { case: \"trailingDistanceBps\"; value: number }\n | UnsetOneof;\n\ntype SlippageOneof<TicksCase extends string, BpsCase extends string> =\n | { case: TicksCase; value: number }\n | { case: BpsCase; value: number }\n | UnsetOneof;\n\ntype SlippageOptions<TicksCase extends string, BpsCase extends string> = {\n fieldName: string;\n ticksCase: TicksCase;\n bpsCase: BpsCase;\n maxBps?: number;\n};\n\nexport function parseTrailingDistanceInput(\n scales: SdkScales,\n distance: TrailingDistanceInput,\n fieldName: string,\n): TrailingDistanceOneof {\n if (distance.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (distance.kind === \"distance\") {\n return {\n case: \"trailingDistanceTicks\",\n value: positiveDecimalInputToScaled(\n `${fieldName}.distance`,\n distance.distance,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(distance.bps);\n if (bps === undefined || bps > Number(PROTOBUF_INT32_MAX)) {\n throw new CatalogConversionError(\n `${fieldName}.bps`,\n `${fieldName}Bps must be a positive integer no greater than ${PROTOBUF_INT32_MAX}`,\n );\n }\n return { case: \"trailingDistanceBps\", value: bps };\n}\n\nexport function parseSlippageInput<const TicksCase extends string, const BpsCase extends string>(\n scales: SdkScales,\n slippage: SlippageInput | undefined,\n options: SlippageOptions<TicksCase, BpsCase>,\n): SlippageOneof<TicksCase, BpsCase> {\n if (!slippage || slippage.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (slippage.kind === \"slippage\") {\n const ticks = positiveDecimalInputToScaled(\n `${options.fieldName}.slippage`,\n slippage.slippage,\n scales.price(),\n );\n if (ticks > PROTOBUF_INT32_MAX) {\n throw new CatalogConversionError(\n `${options.fieldName}.slippage`,\n `${options.fieldName}.slippage exceeds the maximum supported price distance: ${slippage.slippage}`,\n );\n }\n return { case: options.ticksCase, value: Number(ticks) };\n }\n\n const bps = parseOptionalPositiveIntLike(slippage.bps);\n if (bps === undefined || bps <= 0 || exceedsMax(bps, options.maxBps)) {\n throw new CatalogConversionError(\n `${options.fieldName}.bps`,\n `${options.fieldName}Bps must be ${\n options.maxBps === undefined\n ? \"a positive integer\"\n : `between 1 and ${options.maxBps}`\n }`,\n );\n }\n return { case: options.bpsCase, value: bps };\n}\n\nfunction exceedsMax(value: number, max: number | undefined): boolean {\n return max !== undefined && value > max;\n}\n"],"mappings":";;;;;;AAQA,MAAa,mBAAmB;AAoChC,SAAgB,2BACZ,QACA,UACA,WACqB;CACrB,IAAI,SAAS,SAAS,QAClB,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAClB,OAAO;EACH,MAAM;EACN,OAAO,6BACH,GAAG,UAAU,YACb,SAAS,UACT,OAAO,MAAM,CACjB;CACJ;CAGJ,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,MAAM,OAAA,WAAyB,GACpD,MAAM,IAAI,uBACN,GAAG,UAAU,OACb,GAAG,UAAU,iDAAiD,oBAClE;CAEJ,OAAO;EAAE,MAAM;EAAuB,OAAO;CAAI;AACrD;AAEA,SAAgB,mBACZ,QACA,UACA,SACiC;CACjC,IAAI,CAAC,YAAY,SAAS,SAAS,QAC/B,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAAY;EAC9B,MAAM,QAAQ,6BACV,GAAG,QAAQ,UAAU,YACrB,SAAS,UACT,OAAO,MAAM,CACjB;EACA,IAAI,QAAA,aACA,MAAM,IAAI,uBACN,GAAG,QAAQ,UAAU,YACrB,GAAG,QAAQ,UAAU,0DAA0D,SAAS,UAC5F;EAEJ,OAAO;GAAE,MAAM,QAAQ;GAAW,OAAO,OAAO,KAAK;EAAE;CAC3D;CAEA,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,OAAO,KAAK,WAAW,KAAK,QAAQ,MAAM,GAC/D,MAAM,IAAI,uBACN,GAAG,QAAQ,UAAU,OACrB,GAAG,QAAQ,UAAU,cACjB,QAAQ,WAAW,KAAA,IACb,uBACA,iBAAiB,QAAQ,UAEvC;CAEJ,OAAO;EAAE,MAAM,QAAQ;EAAS,OAAO;CAAI;AAC/C;AAEA,SAAS,WAAW,OAAe,KAAkC;CACjE,OAAO,QAAQ,KAAA,KAAa,QAAQ;AACxC"}
@@ -809,7 +809,7 @@ type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInpu
809
809
  declare const ListTriggersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
810
810
  readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
811
811
  readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
812
- readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
812
+ readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
813
813
  readonly triggerType: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["stop_loss", "take_profit", "trailing_stop", "twap", "ladder"], undefined>, undefined>, v.TransformAction<"twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop" | undefined, TriggerType>]>;
814
814
  readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>, 50>;
815
815
  readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
@@ -1030,7 +1030,7 @@ declare const ListTriggerEventsInputSchema: v.SchemaWithPipe<readonly [v.StrictO
1030
1030
  readonly triggerId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
1031
1031
  }, undefined>, v.TransformAction<{
1032
1032
  limit?: number | undefined;
1033
- eventType?: "updated" | "failed" | "fired" | "canceled" | undefined;
1033
+ eventType?: "failed" | "updated" | "fired" | "canceled" | undefined;
1034
1034
  pageToken: string;
1035
1035
  account?: "active" | "main" | {
1036
1036
  subaccountId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-input.schemas.d.ts","names":[],"sources":["../../../src/services/triggers/trigger-input.schemas.ts"],"mappings":";;;;;;iBAyVgB,+BAA+B,QAAQ,YAAS,EAAA,aAAA,EA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_pb.js";
2
2
  import { idToBigInt } from "../../utils/base58-id.js";
3
3
  import { parseOptionalPositiveBigIntLike, parseOptionalPositiveIntLike } from "../../utils/numbers.js";
4
+ import { PROTOBUF_INT64_MAX } from "../../shared/wire-bounds.js";
4
5
  import { idInputSchema } from "../../shared/schemas.js";
5
- import { PROTOBUF_INT32_MAX, PROTOBUF_INT64_MAX } from "../../shared/wire-bounds.js";
6
6
  import { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from "../shared.js";
7
7
  import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
8
8
  import { positiveDecimalInputToScaled } from "../../shared/decimal-surface.js";
9
9
  import { OrderSideCodec } from "../orders/order-enums.codecs.js";
10
- import { parseSlippageInput, parseTrailingDistanceInput } from "../trailing-oneof-inputs.js";
10
+ import { MAX_SLIPPAGE_BPS, parseSlippageInput, parseTrailingDistanceInput } from "../trailing-oneof-inputs.js";
11
11
  import "../../gen/triggers/v1/triggers_pb.js";
12
12
  import { TRIGGER_EVENT_TYPE_VALUES, TRIGGER_STATUS_FILTER_VALUES, TRIGGER_TYPE_VALUES, TriggerEventTypeCodec, TriggerStatusCodec, TriggerTypeCodec } from "./triggers.codecs.js";
13
13
  import { BaseTriggerFieldsSchema, ConditionalExecutionInputSchema, DecimalInputStringSchema, LimitConditionalExecutionInputSchema, TriggerSideInputSchema, TwapExecutionInputSchema, buildConditionalExecution, buildTriggerIntentBase, buildTwapExecution } from "./trigger-child-order.schemas.js";
@@ -59,7 +59,7 @@ function parseMaxSlippage(scales, slippage) {
59
59
  fieldName: "maxSlippage",
60
60
  ticksCase: "maxSlippageTicks",
61
61
  bpsCase: "maxSlippageBps",
62
- maxBps: Number(PROTOBUF_INT32_MAX)
62
+ maxBps: MAX_SLIPPAGE_BPS
63
63
  });
64
64
  }
65
65
  function parseMaxSlippagePatch(scales, slippage) {
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-input.schemas.js","names":["TriggerSideCodec"],"sources":["../../../src/services/triggers/trigger-input.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport * as v from \"valibot\";\nimport { idInputSchema } from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { PROTOBUF_INT32_MAX, PROTOBUF_INT64_MAX } from \"../../shared/wire-bounds.js\";\nimport {\n parseOptionalPositiveBigIntLike,\n parseOptionalPositiveIntLike,\n} from \"../../utils/numbers.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport {\n TRIGGER_EVENT_TYPE_VALUES,\n TRIGGER_STATUS_FILTER_VALUES,\n TRIGGER_TYPE_VALUES,\n TriggerEventTypeCodec,\n TriggerSideCodec,\n TriggerTypeCodec,\n TriggerStatusCodec,\n} from \"./triggers.codecs.js\";\nimport { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport {\n BaseTriggerFieldsSchema,\n ConditionalExecutionInputSchema,\n DecimalInputStringSchema,\n LimitConditionalExecutionInputSchema,\n TriggerSideInputSchema,\n TwapExecutionInputSchema,\n buildConditionalExecution,\n buildTriggerIntentBase,\n buildTwapExecution,\n type MaxSlippageOneof,\n type TrailingDistanceOneof,\n} from \"./trigger-child-order.schemas.js\";\nimport { parseSlippageInput, parseTrailingDistanceInput } from \"../trailing-oneof-inputs.js\";\n\nconst TriggerTypeSchema = v.picklist(TRIGGER_TYPE_VALUES);\nconst TriggerStatusFilterSchema = v.picklist(TRIGGER_STATUS_FILTER_VALUES);\nconst TriggerEventTypeSchema = v.picklist(TRIGGER_EVENT_TYPE_VALUES);\nconst TriggerIdInputSchema = idInputSchema(\"triggerId\");\n\nconst TriggerScopedInputEntries = {\n triggerId: TriggerIdInputSchema,\n ...AccountScopeInputEntries,\n};\n\nconst TriggerScopedInputSchema = v.pipe(\n v.strictObject(TriggerScopedInputEntries),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Absolute price distance, as a decimal price string (e.g. \"0.50\"). */\nconst PriceDistanceInputSchema = v.strictObject({\n kind: v.literal(\"distance\"),\n distance: DecimalInputStringSchema,\n});\n\n/** Absolute price slippage, as a decimal price string (e.g. \"0.25\"). */\nconst PriceSlippageInputSchema = v.strictObject({\n kind: v.literal(\"slippage\"),\n slippage: DecimalInputStringSchema,\n});\n\nconst TrailingDistanceInputSchema = v.union([\n PriceDistanceInputSchema,\n BpsStringOrNumberInputSchema,\n]);\n\nconst MaxSlippageInputSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nconst MaxSlippagePatchInputSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nconst ActivationPricePatchInputSchema = v.union([DecimalInputStringSchema, NoneInputSchema]);\n\nfunction parseTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof TrailingDistanceInputSchema>,\n): TrailingDistanceOneof {\n return parseTrailingDistanceInput(scales, distance, \"trailingDistance\");\n}\n\nfunction parseTwapMilliseconds(\n value: string | number,\n fieldName: \"durationMs\" | \"sliceIntervalMs\",\n minimum: bigint,\n): bigint {\n const parsed = parseOptionalPositiveBigIntLike(value);\n if (parsed === undefined || parsed < minimum || parsed > PROTOBUF_INT64_MAX) {\n throw new Error(\n `${fieldName} must be between ${minimum} and ${PROTOBUF_INT64_MAX} milliseconds`,\n );\n }\n return parsed;\n}\n\nfunction parseMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageInputSchema> | undefined,\n): MaxSlippageOneof {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps: Number(PROTOBUF_INT32_MAX),\n });\n}\n\nfunction parseMaxSlippagePatch(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippagePatchInputSchema>,\n): MaxSlippageOneof {\n if (slippage.kind === \"none\") {\n return { case: \"maxSlippageTicks\", value: 0 };\n }\n return parseMaxSlippage(scales, slippage);\n}\n\nfunction createConditionalTriggerInputSchema<const TriggerType extends \"stop_loss\" | \"take_profit\">(\n scales: SdkScales,\n triggerType: TriggerType,\n) {\n const sharedEntries = {\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(triggerType),\n triggerPrice: DecimalInputStringSchema,\n };\n\n const sellInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"sell\"),\n execution: ConditionalExecutionInputSchema,\n });\n const buyInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"buy\"),\n execution: LimitConditionalExecutionInputSchema,\n });\n\n function transformInput(\n input: v.InferOutput<typeof sellInputSchema> | v.InferOutput<typeof buyInputSchema>,\n ) {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n const strategy = {\n triggerPriceTicks: positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n side: TriggerSideCodec.inputToProto[input.side],\n child: buildConditionalExecution(input.execution, scales),\n };\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy:\n triggerType === \"stop_loss\"\n ? ({ case: \"stopLoss\", value: strategy } as const)\n : ({ case: \"takeProfit\", value: strategy } as const),\n },\n };\n }\n\n return [\n v.pipe(\n sellInputSchema,\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input: v.InferOutput<typeof sellInputSchema>) => transformInput(input)),\n ),\n v.pipe(\n buyInputSchema,\n v.transform((input: v.InferOutput<typeof buyInputSchema>) => transformInput(input)),\n ),\n ] as const;\n}\n\nfunction createTrailingStopTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"trailing_stop\"),\n trailingDistance: TrailingDistanceInputSchema,\n activationPrice: v.optional(DecimalInputStringSchema),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n }),\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"Trailing-stop triggers must use the quote fee asset\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"trailingStop\",\n value: {\n trailingDistance: parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage: parseMaxSlippage(scales, input.maxSlippage),\n side: ProtoOrders.Side.SELL,\n },\n } as const,\n },\n };\n }),\n );\n}\n\nfunction createTwapTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"twap\"),\n side: TriggerSideInputSchema,\n durationMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"durationMs\", 1_000n)),\n ),\n sliceIntervalMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"sliceIntervalMs\", 100n)),\n ),\n execution: TwapExecutionInputSchema,\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.check(\n (input) => input.sliceIntervalMs <= input.durationMs,\n \"sliceIntervalMs cannot exceed durationMs\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"twap\",\n value: {\n side: input.side,\n durationMs: input.durationMs,\n sliceIntervalMs: input.sliceIntervalMs,\n execution: buildTwapExecution(input.execution, scales),\n },\n } as const,\n },\n };\n }),\n );\n}\n\nfunction createLadderTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"ladder\"),\n side: TriggerSideInputSchema,\n priceMin: DecimalInputStringSchema,\n priceMax: DecimalInputStringSchema,\n levels: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.pipe(v.number(), v.integer())]),\n v.transform((value) => {\n const levels = parseOptionalPositiveIntLike(value);\n if (!levels || levels < 2 || levels > 100) {\n throw new Error(\"levels must be between 2 and 100\");\n }\n return levels;\n }),\n ),\n postOnly: v.optional(v.boolean(), false),\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"ladder\",\n value: {\n side: input.side,\n priceMinTicks: positiveDecimalInputToScaled(\n \"priceMin\",\n input.priceMin,\n scales.price(),\n ),\n priceMaxTicks: positiveDecimalInputToScaled(\n \"priceMax\",\n input.priceMax,\n scales.price(),\n ),\n levels: input.levels,\n postOnly: input.postOnly,\n },\n } as const,\n },\n };\n }),\n v.check(\n (output) =>\n output.trigger.strategy.value.priceMinTicks <\n output.trigger.strategy.value.priceMaxTicks,\n \"priceMin must be less than priceMax\",\n ),\n );\n}\n\n/** Builds the create-trigger boundary schema using catalog scales keyed by symbol ID. */\nexport function createCreateTriggerInputSchema(scales: SdkScales) {\n return v.union([\n ...createConditionalTriggerInputSchema(scales, \"stop_loss\"),\n ...createConditionalTriggerInputSchema(scales, \"take_profit\"),\n createTrailingStopTriggerInputSchema(scales),\n createTwapTriggerInputSchema(scales),\n createLadderTriggerInputSchema(scales),\n ]);\n}\n\n/** Public input for creating a standalone trigger. */\nexport type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInputSchema>>;\n\n/** Public filters for listing triggers in an account scope. */\nexport const ListTriggersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n parentOrderId: v.pipe(\n v.optional(v.pipe(v.string(), v.trim())),\n v.transform((value) => (value ? idToBigInt(value, \"parentOrderId\") : undefined)),\n ),\n symbolId: v.optional(SymbolIdInputSchema),\n status: v.pipe(\n v.optional(v.array(TriggerStatusFilterSchema)),\n v.transform(\n (values) => values?.map((value) => TriggerStatusCodec.inputToProto[value]) ?? [],\n ),\n ),\n triggerType: v.pipe(\n v.optional(TriggerTypeSchema),\n v.transform((value) =>\n value\n ? TriggerTypeCodec.inputToProto[value]\n : Proto.TriggerType.TRIGGER_TYPE_UNSPECIFIED,\n ),\n ),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000)), 50),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Public filters for listing triggers. */\nexport type ListTriggersInput = v.InferInput<typeof ListTriggersInputSchema>;\n\nexport const CancelTriggerInputSchema = TriggerScopedInputSchema;\nexport type CancelTriggerInput = v.InferInput<typeof CancelTriggerInputSchema>;\n\nexport const GetTriggerInputSchema = CancelTriggerInputSchema;\nexport type GetTriggerInput = v.InferInput<typeof GetTriggerInputSchema>;\n\nexport const PauseTriggerInputSchema = TriggerScopedInputSchema;\nexport type PauseTriggerInput = v.InferInput<typeof PauseTriggerInputSchema>;\n\nexport const ResumeTriggerInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: SymbolIdInputSchema,\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\nexport type ResumeTriggerInput = v.InferInput<typeof ResumeTriggerInputSchema>;\n\nexport function createModifyTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: SymbolIdInputSchema,\n triggerPrice: v.optional(DecimalInputStringSchema),\n limitPrice: v.optional(DecimalInputStringSchema),\n trailingDistance: v.optional(TrailingDistanceInputSchema),\n activationPrice: v.optional(ActivationPricePatchInputSchema),\n maxSlippage: v.optional(MaxSlippagePatchInputSchema),\n }),\n v.check(\n (input) =>\n input.triggerPrice !== undefined ||\n input.limitPrice !== undefined ||\n input.trailingDistance !== undefined ||\n input.activationPrice !== undefined ||\n input.maxSlippage !== undefined,\n \"At least one patch field is required\",\n ),\n v.transform(({ account, ...input }) => ({\n triggerId: input.triggerId,\n subaccountId: accountScopeToSubaccountId(account),\n symbolId: input.symbolId,\n triggerPriceTicks:\n input.triggerPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n limitPriceTicks:\n input.limitPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\"limitPrice\", input.limitPrice, scales.price()),\n trailingDistance:\n input.trailingDistance === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? undefined\n : typeof input.activationPrice !== \"string\"\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage:\n input.maxSlippage === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseMaxSlippagePatch(scales, input.maxSlippage),\n })),\n );\n}\n\n/**\n * A trigger patch. Omitted fields remain unchanged; `{ kind: \"none\" }` clears\n * `activationPrice` or `maxSlippage`.\n */\nexport type ModifyTriggerInput = v.InferInput<ReturnType<typeof createModifyTriggerInputSchema>>;\n\nexport const ListTriggerEventsInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000))),\n eventType: v.optional(TriggerEventTypeSchema),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n eventType:\n input.eventType === undefined\n ? undefined\n : TriggerEventTypeCodec.inputToProto[input.eventType],\n })),\n);\n\nexport type ListTriggerEventsInput = v.InferInput<typeof ListTriggerEventsInputSchema>;\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAM,oBAAoB,EAAE,SAAS,mBAAmB;AACxD,MAAM,4BAA4B,EAAE,SAAS,4BAA4B;AACzE,MAAM,yBAAyB,EAAE,SAAS,yBAAyB;AAGnE,MAAM,4BAA4B;CAC9B,WAHyB,cAAc,WAGT;CAC9B,GAAG;AACP;AAEA,MAAM,2BAA2B,EAAE,KAC/B,EAAE,aAAa,yBAAyB,GACxC,EAAE,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;AACpD,EAAE,CACN;;AAGA,MAAM,2BAA2B,EAAE,aAAa;CAC5C,MAAM,EAAE,QAAQ,UAAU;CAC1B,UAAU;AACd,CAAC;;AAGD,MAAM,2BAA2B,EAAE,aAAa;CAC5C,MAAM,EAAE,QAAQ,UAAU;CAC1B,UAAU;AACd,CAAC;AAED,MAAM,8BAA8B,EAAE,MAAM,CACxC,0BACA,4BACJ,CAAC;AAED,MAAM,yBAAyB,EAAE,MAAM;CACnC;CACA;CACA;AACJ,CAAC;AAED,MAAM,8BAA8B,EAAE,MAAM;CACxC;CACA;CACA;AACJ,CAAC;AAED,MAAM,kCAAkC,EAAE,MAAM,CAAC,0BAA0B,eAAe,CAAC;AAE3F,SAAS,sBACL,QACA,UACqB;CACrB,OAAO,2BAA2B,QAAQ,UAAU,kBAAkB;AAC1E;AAEA,SAAS,sBACL,OACA,WACA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,IACf;GAAE,MAAM,KAAA;GAAW,OAAO,KAAA;EAAU,IACrC,sBAAsB,QAAQ,MAAM,WAAW;CAC7D,EAAE,CACN;AACJ;AAQA,MAAa,+BAA+B,EAAE,KAC1C,EAAE,aAAa;CACX,GAAG;CACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAI,CAAC,CAAC;CACjF,WAAW,EAAE,SAAS,sBAAsB;CAC5C,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE;AAC1D,CAAC,GACD,EAAE,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;CAChD,WACI,MAAM,cAAc,KAAA,IACd,KAAA,IACA,sBAAsB,aAAa,MAAM;AACvD,EAAE,CACN"}
1
+ {"version":3,"file":"trigger-input.schemas.js","names":["TriggerSideCodec"],"sources":["../../../src/services/triggers/trigger-input.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport * as v from \"valibot\";\nimport { idInputSchema } from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { PROTOBUF_INT64_MAX } from \"../../shared/wire-bounds.js\";\nimport {\n parseOptionalPositiveBigIntLike,\n parseOptionalPositiveIntLike,\n} from \"../../utils/numbers.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport {\n TRIGGER_EVENT_TYPE_VALUES,\n TRIGGER_STATUS_FILTER_VALUES,\n TRIGGER_TYPE_VALUES,\n TriggerEventTypeCodec,\n TriggerSideCodec,\n TriggerTypeCodec,\n TriggerStatusCodec,\n} from \"./triggers.codecs.js\";\nimport { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport {\n BaseTriggerFieldsSchema,\n ConditionalExecutionInputSchema,\n DecimalInputStringSchema,\n LimitConditionalExecutionInputSchema,\n TriggerSideInputSchema,\n TwapExecutionInputSchema,\n buildConditionalExecution,\n buildTriggerIntentBase,\n buildTwapExecution,\n type MaxSlippageOneof,\n type TrailingDistanceOneof,\n} from \"./trigger-child-order.schemas.js\";\nimport {\n MAX_SLIPPAGE_BPS,\n parseSlippageInput,\n parseTrailingDistanceInput,\n} from \"../trailing-oneof-inputs.js\";\n\nconst TriggerTypeSchema = v.picklist(TRIGGER_TYPE_VALUES);\nconst TriggerStatusFilterSchema = v.picklist(TRIGGER_STATUS_FILTER_VALUES);\nconst TriggerEventTypeSchema = v.picklist(TRIGGER_EVENT_TYPE_VALUES);\nconst TriggerIdInputSchema = idInputSchema(\"triggerId\");\n\nconst TriggerScopedInputEntries = {\n triggerId: TriggerIdInputSchema,\n ...AccountScopeInputEntries,\n};\n\nconst TriggerScopedInputSchema = v.pipe(\n v.strictObject(TriggerScopedInputEntries),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Absolute price distance, as a decimal price string (e.g. \"0.50\"). */\nconst PriceDistanceInputSchema = v.strictObject({\n kind: v.literal(\"distance\"),\n distance: DecimalInputStringSchema,\n});\n\n/** Absolute price slippage, as a decimal price string (e.g. \"0.25\"). */\nconst PriceSlippageInputSchema = v.strictObject({\n kind: v.literal(\"slippage\"),\n slippage: DecimalInputStringSchema,\n});\n\nconst TrailingDistanceInputSchema = v.union([\n PriceDistanceInputSchema,\n BpsStringOrNumberInputSchema,\n]);\n\nconst MaxSlippageInputSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nconst MaxSlippagePatchInputSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nconst ActivationPricePatchInputSchema = v.union([DecimalInputStringSchema, NoneInputSchema]);\n\nfunction parseTrailingDistance(\n scales: SdkScales,\n distance: v.InferOutput<typeof TrailingDistanceInputSchema>,\n): TrailingDistanceOneof {\n return parseTrailingDistanceInput(scales, distance, \"trailingDistance\");\n}\n\nfunction parseTwapMilliseconds(\n value: string | number,\n fieldName: \"durationMs\" | \"sliceIntervalMs\",\n minimum: bigint,\n): bigint {\n const parsed = parseOptionalPositiveBigIntLike(value);\n if (parsed === undefined || parsed < minimum || parsed > PROTOBUF_INT64_MAX) {\n throw new Error(\n `${fieldName} must be between ${minimum} and ${PROTOBUF_INT64_MAX} milliseconds`,\n );\n }\n return parsed;\n}\n\nfunction parseMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageInputSchema> | undefined,\n): MaxSlippageOneof {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps: MAX_SLIPPAGE_BPS,\n });\n}\n\nfunction parseMaxSlippagePatch(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippagePatchInputSchema>,\n): MaxSlippageOneof {\n if (slippage.kind === \"none\") {\n return { case: \"maxSlippageTicks\", value: 0 };\n }\n return parseMaxSlippage(scales, slippage);\n}\n\nfunction createConditionalTriggerInputSchema<const TriggerType extends \"stop_loss\" | \"take_profit\">(\n scales: SdkScales,\n triggerType: TriggerType,\n) {\n const sharedEntries = {\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(triggerType),\n triggerPrice: DecimalInputStringSchema,\n };\n\n const sellInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"sell\"),\n execution: ConditionalExecutionInputSchema,\n });\n const buyInputSchema = v.strictObject({\n ...sharedEntries,\n side: v.literal(\"buy\"),\n execution: LimitConditionalExecutionInputSchema,\n });\n\n function transformInput(\n input: v.InferOutput<typeof sellInputSchema> | v.InferOutput<typeof buyInputSchema>,\n ) {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n const strategy = {\n triggerPriceTicks: positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n side: TriggerSideCodec.inputToProto[input.side],\n child: buildConditionalExecution(input.execution, scales),\n };\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy:\n triggerType === \"stop_loss\"\n ? ({ case: \"stopLoss\", value: strategy } as const)\n : ({ case: \"takeProfit\", value: strategy } as const),\n },\n };\n }\n\n return [\n v.pipe(\n sellInputSchema,\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input: v.InferOutput<typeof sellInputSchema>) => transformInput(input)),\n ),\n v.pipe(\n buyInputSchema,\n v.transform((input: v.InferOutput<typeof buyInputSchema>) => transformInput(input)),\n ),\n ] as const;\n}\n\nfunction createTrailingStopTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"trailing_stop\"),\n trailingDistance: TrailingDistanceInputSchema,\n activationPrice: v.optional(DecimalInputStringSchema),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n }),\n v.check(\n (input) => input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"Trailing-stop triggers must use the quote fee asset\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"trailingStop\",\n value: {\n trailingDistance: parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage: parseMaxSlippage(scales, input.maxSlippage),\n side: ProtoOrders.Side.SELL,\n },\n } as const,\n },\n };\n }),\n );\n}\n\nfunction createTwapTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"twap\"),\n side: TriggerSideInputSchema,\n durationMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"durationMs\", 1_000n)),\n ),\n sliceIntervalMs: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.number()]),\n v.transform((value) => parseTwapMilliseconds(value, \"sliceIntervalMs\", 100n)),\n ),\n execution: TwapExecutionInputSchema,\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.check(\n (input) => input.sliceIntervalMs <= input.durationMs,\n \"sliceIntervalMs cannot exceed durationMs\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"twap\",\n value: {\n side: input.side,\n durationMs: input.durationMs,\n sliceIntervalMs: input.sliceIntervalMs,\n execution: buildTwapExecution(input.execution, scales),\n },\n } as const,\n },\n };\n }),\n );\n}\n\nfunction createLadderTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...BaseTriggerFieldsSchema.entries,\n triggerType: v.literal(\"ladder\"),\n side: TriggerSideInputSchema,\n priceMin: DecimalInputStringSchema,\n priceMax: DecimalInputStringSchema,\n levels: v.pipe(\n v.union([v.pipe(v.string(), v.trim()), v.pipe(v.number(), v.integer())]),\n v.transform((value) => {\n const levels = parseOptionalPositiveIntLike(value);\n if (!levels || levels < 2 || levels > 100) {\n throw new Error(\"levels must be between 2 and 100\");\n }\n return levels;\n }),\n ),\n postOnly: v.optional(v.boolean(), false),\n }),\n v.check(\n (input) =>\n input.side !== ProtoOrders.Side.SELL ||\n input.feeAsset === ProtoOrders.FeeAsset.QUOTE,\n \"SELL triggers must use the quote fee asset\",\n ),\n v.transform((input) => {\n const { subaccountId, intent } = buildTriggerIntentBase(input, scales);\n return {\n subaccountId,\n trigger: {\n ...intent,\n strategy: {\n case: \"ladder\",\n value: {\n side: input.side,\n priceMinTicks: positiveDecimalInputToScaled(\n \"priceMin\",\n input.priceMin,\n scales.price(),\n ),\n priceMaxTicks: positiveDecimalInputToScaled(\n \"priceMax\",\n input.priceMax,\n scales.price(),\n ),\n levels: input.levels,\n postOnly: input.postOnly,\n },\n } as const,\n },\n };\n }),\n v.check(\n (output) =>\n output.trigger.strategy.value.priceMinTicks <\n output.trigger.strategy.value.priceMaxTicks,\n \"priceMin must be less than priceMax\",\n ),\n );\n}\n\n/** Builds the create-trigger boundary schema using catalog scales keyed by symbol ID. */\nexport function createCreateTriggerInputSchema(scales: SdkScales) {\n return v.union([\n ...createConditionalTriggerInputSchema(scales, \"stop_loss\"),\n ...createConditionalTriggerInputSchema(scales, \"take_profit\"),\n createTrailingStopTriggerInputSchema(scales),\n createTwapTriggerInputSchema(scales),\n createLadderTriggerInputSchema(scales),\n ]);\n}\n\n/** Public input for creating a standalone trigger. */\nexport type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInputSchema>>;\n\n/** Public filters for listing triggers in an account scope. */\nexport const ListTriggersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n parentOrderId: v.pipe(\n v.optional(v.pipe(v.string(), v.trim())),\n v.transform((value) => (value ? idToBigInt(value, \"parentOrderId\") : undefined)),\n ),\n symbolId: v.optional(SymbolIdInputSchema),\n status: v.pipe(\n v.optional(v.array(TriggerStatusFilterSchema)),\n v.transform(\n (values) => values?.map((value) => TriggerStatusCodec.inputToProto[value]) ?? [],\n ),\n ),\n triggerType: v.pipe(\n v.optional(TriggerTypeSchema),\n v.transform((value) =>\n value\n ? TriggerTypeCodec.inputToProto[value]\n : Proto.TriggerType.TRIGGER_TYPE_UNSPECIFIED,\n ),\n ),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000)), 50),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Public filters for listing triggers. */\nexport type ListTriggersInput = v.InferInput<typeof ListTriggersInputSchema>;\n\nexport const CancelTriggerInputSchema = TriggerScopedInputSchema;\nexport type CancelTriggerInput = v.InferInput<typeof CancelTriggerInputSchema>;\n\nexport const GetTriggerInputSchema = CancelTriggerInputSchema;\nexport type GetTriggerInput = v.InferInput<typeof GetTriggerInputSchema>;\n\nexport const PauseTriggerInputSchema = TriggerScopedInputSchema;\nexport type PauseTriggerInput = v.InferInput<typeof PauseTriggerInputSchema>;\n\nexport const ResumeTriggerInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: SymbolIdInputSchema,\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\nexport type ResumeTriggerInput = v.InferInput<typeof ResumeTriggerInputSchema>;\n\nexport function createModifyTriggerInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n symbolId: SymbolIdInputSchema,\n triggerPrice: v.optional(DecimalInputStringSchema),\n limitPrice: v.optional(DecimalInputStringSchema),\n trailingDistance: v.optional(TrailingDistanceInputSchema),\n activationPrice: v.optional(ActivationPricePatchInputSchema),\n maxSlippage: v.optional(MaxSlippagePatchInputSchema),\n }),\n v.check(\n (input) =>\n input.triggerPrice !== undefined ||\n input.limitPrice !== undefined ||\n input.trailingDistance !== undefined ||\n input.activationPrice !== undefined ||\n input.maxSlippage !== undefined,\n \"At least one patch field is required\",\n ),\n v.transform(({ account, ...input }) => ({\n triggerId: input.triggerId,\n subaccountId: accountScopeToSubaccountId(account),\n symbolId: input.symbolId,\n triggerPriceTicks:\n input.triggerPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"triggerPrice\",\n input.triggerPrice,\n scales.price(),\n ),\n limitPriceTicks:\n input.limitPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\"limitPrice\", input.limitPrice, scales.price()),\n trailingDistance:\n input.trailingDistance === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseTrailingDistance(scales, input.trailingDistance),\n activationPriceTicks:\n input.activationPrice === undefined\n ? undefined\n : typeof input.activationPrice !== \"string\"\n ? 0n\n : positiveDecimalInputToScaled(\n \"activationPrice\",\n input.activationPrice,\n scales.price(),\n ),\n maxSlippage:\n input.maxSlippage === undefined\n ? ({ case: undefined, value: undefined } as const)\n : parseMaxSlippagePatch(scales, input.maxSlippage),\n })),\n );\n}\n\n/**\n * A trigger patch. Omitted fields remain unchanged; `{ kind: \"none\" }` clears\n * `activationPrice` or `maxSlippage`.\n */\nexport type ModifyTriggerInput = v.InferInput<ReturnType<typeof createModifyTriggerInputSchema>>;\n\nexport const ListTriggerEventsInputSchema = v.pipe(\n v.strictObject({\n ...TriggerScopedInputEntries,\n limit: v.optional(v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(1000))),\n eventType: v.optional(TriggerEventTypeSchema),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n eventType:\n input.eventType === undefined\n ? undefined\n : TriggerEventTypeCodec.inputToProto[input.eventType],\n })),\n);\n\nexport type ListTriggerEventsInput = v.InferInput<typeof ListTriggerEventsInputSchema>;\n"],"mappings":";;;;;;;;;;;;;;;AA4CA,MAAM,oBAAoB,EAAE,SAAS,mBAAmB;AACxD,MAAM,4BAA4B,EAAE,SAAS,4BAA4B;AACzE,MAAM,yBAAyB,EAAE,SAAS,yBAAyB;AAGnE,MAAM,4BAA4B;CAC9B,WAHyB,cAAc,WAGT;CAC9B,GAAG;AACP;AAEA,MAAM,2BAA2B,EAAE,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are const CreateTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSche
31
31
  type CreateTriggerResult = v.InferOutput<typeof CreateTriggerResultSchema>;
32
32
  declare const CancelTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
33
33
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
34
- readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused">]>;
34
+ readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
35
35
  readonly tsNs: v.BigintSchema<undefined>;
36
36
  }, undefined>, v.TransformAction<{
37
37
  triggerId: string;
38
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
38
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
39
39
  tsNs: bigint;
40
40
  }, {
41
41
  ts: number;
42
42
  tsNs: string;
43
43
  triggerId: string;
44
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
44
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
45
45
  }>]>;
46
46
  type CancelTriggerResult = v.InferOutput<typeof CancelTriggerResultSchema>;
47
47
  declare const ModifyTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
48
48
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
49
- readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused">]>;
49
+ readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
50
50
  readonly tsNs: v.BigintSchema<undefined>;
51
51
  }, undefined>, v.TransformAction<{
52
52
  triggerId: string;
53
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
53
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
54
54
  tsNs: bigint;
55
55
  }, {
56
56
  ts: number;
57
57
  tsNs: string;
58
58
  triggerId: string;
59
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
59
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
60
60
  }>]>;
61
61
  type ModifyTriggerResult = v.InferOutput<typeof ModifyTriggerResultSchema>;
62
62
  declare const PauseTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
63
63
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
64
- readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused">]>;
64
+ readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
65
65
  readonly tsNs: v.BigintSchema<undefined>;
66
66
  }, undefined>, v.TransformAction<{
67
67
  triggerId: string;
68
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
68
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
69
69
  tsNs: bigint;
70
70
  }, {
71
71
  ts: number;
72
72
  tsNs: string;
73
73
  triggerId: string;
74
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
74
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
75
75
  }>]>;
76
76
  type PauseTriggerResult = v.InferOutput<typeof PauseTriggerResultSchema>;
77
77
  declare const ResumeTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
78
78
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
79
- readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused">]>;
79
+ readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
80
80
  readonly tsNs: v.BigintSchema<undefined>;
81
81
  }, undefined>, v.TransformAction<{
82
82
  triggerId: string;
83
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
83
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
84
84
  tsNs: bigint;
85
85
  }, {
86
86
  ts: number;
87
87
  tsNs: string;
88
88
  triggerId: string;
89
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
89
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
90
90
  }>]>;
91
91
  type ResumeTriggerResult = v.InferOutput<typeof ResumeTriggerResultSchema>;
92
92
  type StopDetailsOutput = {
@@ -528,7 +528,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
528
528
  triggerId: string;
529
529
  subaccountId: string;
530
530
  symbolId: number;
531
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
531
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
532
532
  parentOrderId: string | undefined;
533
533
  qty: string;
534
534
  feeAsset: "unspecified" | "quote" | "base";
@@ -669,7 +669,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
669
669
  triggerId: string;
670
670
  subaccountId: string;
671
671
  symbolId: number;
672
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
672
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
673
673
  parentOrderId: string | undefined;
674
674
  qty: string;
675
675
  feeAsset: "unspecified" | "quote" | "base";
@@ -810,7 +810,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
810
810
  triggerId: string;
811
811
  subaccountId: string;
812
812
  symbolId: number;
813
- status: "unspecified" | "cancelled" | "created" | "failed" | "completed" | "armed" | "running" | "paused";
813
+ status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
814
814
  parentOrderId: string | undefined;
815
815
  qty: string;
816
816
  feeAsset: "unspecified" | "quote" | "base";
@@ -994,7 +994,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
994
994
  subaccountId: string;
995
995
  symbolId: number;
996
996
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
997
- eventType: "unspecified" | "updated" | "failed" | "fired" | "canceled";
997
+ eventType: "unspecified" | "failed" | "updated" | "fired" | "canceled";
998
998
  ts: number;
999
999
  childSeq: number;
1000
1000
  childOrderId: string | undefined;
@@ -1006,7 +1006,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1006
1006
  subaccountId: string;
1007
1007
  symbolId: number;
1008
1008
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1009
- eventType: "unspecified" | "updated" | "failed" | "fired" | "canceled";
1009
+ eventType: "unspecified" | "failed" | "updated" | "fired" | "canceled";
1010
1010
  ts: number;
1011
1011
  childSeq: number;
1012
1012
  childOrderId: string | undefined;
@@ -1018,7 +1018,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1018
1018
  subaccountId: string;
1019
1019
  symbolId: number;
1020
1020
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1021
- eventType: "unspecified" | "updated" | "failed" | "fired" | "canceled";
1021
+ eventType: "unspecified" | "failed" | "updated" | "fired" | "canceled";
1022
1022
  ts: number;
1023
1023
  childSeq: number;
1024
1024
  childOrderId: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"decimal-surface.d.ts","names":[],"sources":["../../src/shared/decimal-surface.ts"],"mappings":";;;;;;;UAiCiB;EACb,SAAS;EACT;EACA,QAAQ,MAAM;EACd,YAAY,MAAM;EAClB,aAAa;EACb,kBAAkB"}
1
+ {"version":3,"file":"decimal-surface.d.ts","names":[],"sources":["../../src/shared/decimal-surface.ts"],"mappings":";;;;;;;UAwCiB;EACb,SAAS;EACT;EACA,QAAQ,MAAM;EACd,YAAY,MAAM;EAClB,aAAa;EACb,kBAAkB"}
@@ -1 +1 @@
1
- {"version":3,"file":"decimal-surface.js","names":[],"sources":["../../src/shared/decimal-surface.ts"],"sourcesContent":["/**\n * Internal scaled⇄decimal bridge for the SDK's public decimal-string surface.\n *\n * The wire protocol carries scaled integers (price ticks, per-asset scaled\n * quantities); the public SDK surface carries plain decimal strings. Output\n * schemas convert exactly (no rounding, trailing zeros trimmed); input schemas\n * accept zero padding but reject fractional precision that remains above the\n * scale after trailing zeros are removed. Scaled integers must not escape\n * through any service input or output.\n */\nimport {\n scaledToDecimal,\n tryDecimalToScaled,\n type DecimalToScaledFailure,\n} from \"../catalogs/decimal.js\";\nimport {\n CatalogConversionError,\n CatalogLookupError,\n CatalogNotReadyError,\n type ClientCatalog,\n type PairCatalogKey,\n} from \"../catalogs/types.js\";\nimport { PRICE_SCALE } from \"../catalogs/readers.js\";\nimport { PROTOBUF_INT64_MAX } from \"./wire-bounds.js\";\n\n/** On-chain unified-asset amounts (`amountE18`) are always 18-decimal scaled. */\nexport const E18_SCALE = 18;\n\n/**\n * Resolves wire scales for the SDK's internal decimal conversion. Backed by\n * the client catalog; `ready()` must be awaited before the synchronous lookups\n * are used so the catalog can answer them.\n */\nexport interface SdkScales {\n ready(): Promise<void>;\n price(): number;\n baseQty(pair: PairCatalogKey): number;\n quoteAmount(pair: PairCatalogKey): number;\n ledgerAmount(ledgerAssetId: number): number;\n zippedAssetAmount(zippedAssetId: number): number;\n}\n\n/**\n * Catalog-backed scale resolver. Takes a getter so it can be constructed\n * before the owning client has assigned its catalog.\n */\nexport function createCatalogSdkScales(getCatalog: () => ClientCatalog): SdkScales {\n return {\n ready: async () => {\n await getCatalog().ensureReady();\n },\n price: () => PRICE_SCALE,\n baseQty: (pair) => requirePair(getCatalog(), pair).baseAsset.quantityScale,\n quoteAmount: (pair) => requirePair(getCatalog(), pair).quoteAsset.quantityScale,\n ledgerAmount: (ledgerAssetId) => {\n const ledger = getCatalog().ledger;\n if (!ledger.isKnownAssetId(ledgerAssetId)) {\n throw new CatalogLookupError(\"ledger\", \"ledgerId\", ledgerAssetId);\n }\n return ledger.requireAssetByLedgerId(ledgerAssetId).quantityScale;\n },\n zippedAssetAmount: (zippedAssetId) =>\n getCatalog().zipper.requireAssetChainByZippedAssetId(zippedAssetId).asset.quantityScale,\n };\n}\n\nfunction requirePair(catalog: ClientCatalog, pair: PairCatalogKey) {\n return typeof pair === \"string\" || (typeof pair === \"object\" && \"symbol\" in pair)\n ? catalog.market.requirePairBySymbol(typeof pair === \"string\" ? pair : pair.symbol)\n : catalog.market.requirePairBySymbolId(typeof pair === \"number\" ? pair : pair.symbolId);\n}\n\n/** Output direction: exact scaled→decimal conversion (`1500000n`@6 → `\"1.5\"`). */\nexport function scaledToDecimalOutput(value: bigint, scale: number): string {\n return scaledToDecimal(value, scale);\n}\n\nfunction conversionFailureMessage(\n field: string,\n value: string,\n failure: DecimalToScaledFailure,\n): string {\n return failure.reason === \"precision\"\n ? `${field} supports at most ${failure.maxDecimals} decimal places: ${value}`\n : `${field} must be a non-negative decimal number: ${value}`;\n}\n\n/**\n * Input direction: strict decimal→scaled conversion. Throws\n * CatalogConversionError for non-decimal input or inexact excess precision.\n */\nexport function decimalInputToScaled(field: string, value: string, scale: number): bigint {\n const result = tryDecimalToScaled(value.trim(), scale);\n if (!result.ok) {\n throw new CatalogConversionError(\n field,\n conversionFailureMessage(field, value, result.failure),\n );\n }\n return result.scaled;\n}\n\nfunction unboundedPositiveDecimalInputToScaled(\n field: string,\n value: string,\n scale: number,\n): bigint {\n const scaled = decimalInputToScaled(field, value, scale);\n if (scaled <= 0n) {\n throw new CatalogConversionError(field, `${field} must be greater than 0: ${value}`);\n }\n return scaled;\n}\n\n/**\n * Converts a positive decimal input to a scaled protobuf `int64` value.\n * Rejects values above the wire-format ceiling before serialization.\n */\nexport function positiveDecimalInputToScaled(field: string, value: string, scale: number): bigint {\n const scaled = unboundedPositiveDecimalInputToScaled(field, value, scale);\n if (scaled > PROTOBUF_INT64_MAX) {\n throw new CatalogConversionError(\n field,\n `${field} exceeds the maximum supported value: ${value}`,\n );\n }\n return scaled;\n}\n\n/**\n * Decimal quantity → PolyesterChain E18 ledger units.\n * Input precision is capped at the asset's quantityScale; the wire value is\n * always upscaled to E18 (trading balances / amount_e18 convention).\n */\nexport function quantityInputToE18(params: {\n scales: SdkScales;\n assetId: number;\n quantity: string;\n field?: string;\n}): bigint {\n const field = params.field ?? \"quantity\";\n const assetScale = params.scales.ledgerAmount(params.assetId);\n if (assetScale > E18_SCALE) {\n throw new CatalogConversionError(\n field,\n `${field} asset quantityScale ${assetScale} exceeds E18 ledger scale`,\n );\n }\n return (\n unboundedPositiveDecimalInputToScaled(field, params.quantity, assetScale) *\n 10n ** BigInt(E18_SCALE - assetScale)\n );\n}\n\nexport interface ReadyGate {\n /** Queues or delivers one transition while the gate remains active. */\n run(deliver: () => void): void;\n /** Drops pending transitions and permanently prevents future delivery. */\n close(): void;\n}\n\ninterface ReadyGateHandlers {\n onDeliveryError?: (error: unknown) => void;\n onTerminalError: (error: unknown) => void;\n}\n\nconst READY_GATE_MAX_PENDING_DELIVERIES = 1_024;\n\n/**\n * Transition event delivery behind catalog readiness. Events arriving before the\n * catalog can resolve scales are queued and flushed in arrival order once it\n * is ready. Delivery errors are isolated from the transport. Readiness failure\n * or queue overflow is terminal because dropping an event would break stream\n * continuity; the owning subscription must visibly terminate when notified.\n */\nexport function createReadyGate(\n ready: () => Promise<void>,\n handlers: ReadyGateHandlers,\n): ReadyGate {\n let state: \"pending\" | \"open\" | \"closed\" = \"pending\";\n const queue: Array<() => void> = [];\n\n const deliverIsolated = (deliver: () => void) => {\n try {\n deliver();\n } catch (error) {\n handlers.onDeliveryError?.(error);\n }\n };\n\n const closeWithError = (error: unknown) => {\n if (state === \"closed\") return;\n state = \"closed\";\n queue.length = 0;\n handlers.onTerminalError(error);\n };\n\n Promise.resolve()\n .then(ready)\n .then(\n () => {\n if (state !== \"pending\") return;\n state = \"open\";\n for (const deliver of queue.splice(0)) deliverIsolated(deliver);\n },\n (error) => {\n if (state !== \"pending\") return;\n closeWithError(error);\n },\n );\n\n return {\n run(deliver) {\n if (state === \"open\") deliverIsolated(deliver);\n else if (state === \"pending\") {\n if (queue.length === READY_GATE_MAX_PENDING_DELIVERIES) {\n closeWithError(new CatalogNotReadyError());\n return;\n }\n queue.push(deliver);\n }\n },\n close() {\n if (state === \"closed\") return;\n state = \"closed\";\n queue.length = 0;\n },\n };\n}\n"],"mappings":";;;;;;;AA8CA,SAAgB,uBAAuB,YAA4C;CAC/E,OAAO;EACH,OAAO,YAAY;GACf,MAAM,WAAW,CAAC,CAAC,YAAY;EACnC;EACA,aAAA;EACA,UAAU,SAAS,YAAY,WAAW,GAAG,IAAI,CAAC,CAAC,UAAU;EAC7D,cAAc,SAAS,YAAY,WAAW,GAAG,IAAI,CAAC,CAAC,WAAW;EAClE,eAA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Content":["/**\n * Internal scaled⇄decimal bridge for the SDK's public decimal-string surface.\n *\n * The wire protocol carries scaled integers (price ticks, per-asset scaled\n * quantities); the public SDK surface carries plain decimal strings. Output\n * schemas convert exactly (no rounding, trailing zeros trimmed); input schemas\n * accept zero padding but reject fractional precision that remains above the\n * scale after trailing zeros are removed. Scaled integers must not escape\n * through any service input or output.\n */\nimport {\n scaledToDecimal,\n tryDecimalToScaled,\n type DecimalToScaledFailure,\n} from \"../catalogs/decimal.js\";\nimport {\n CatalogConversionError,\n CatalogLookupError,\n CatalogNotReadyError,\n type ClientCatalog,\n type PairCatalogKey,\n} from \"../catalogs/types.js\";\nimport { PRICE_SCALE } from \"../catalogs/readers.js\";\nimport { PROTOBUF_INT64_MAX } from \"./wire-bounds.js\";\n\n/** On-chain unified-asset amounts (`amountE18`) are always 18-decimal scaled. */\nexport const E18_SCALE = 18;\n\n/**\n * Policy notional caps (`max_order_notional`) are canonical quote microunits:\n * one unit is 0.000001 USDT, per the `auth.v1` policy contract. Fixed by the\n * protocol rather than per-pair, so it needs no catalog lookup.\n */\nexport const QUOTE_NOTIONAL_SCALE = 6;\n\n/**\n * Resolves wire scales for the SDK's internal decimal conversion. Backed by\n * the client catalog; `ready()` must be awaited before the synchronous lookups\n * are used so the catalog can answer them.\n */\nexport interface SdkScales {\n ready(): Promise<void>;\n price(): number;\n baseQty(pair: PairCatalogKey): number;\n quoteAmount(pair: PairCatalogKey): number;\n ledgerAmount(ledgerAssetId: number): number;\n zippedAssetAmount(zippedAssetId: number): number;\n}\n\n/**\n * Catalog-backed scale resolver. Takes a getter so it can be constructed\n * before the owning client has assigned its catalog.\n */\nexport function createCatalogSdkScales(getCatalog: () => ClientCatalog): SdkScales {\n return {\n ready: async () => {\n await getCatalog().ensureReady();\n },\n price: () => PRICE_SCALE,\n baseQty: (pair) => requirePair(getCatalog(), pair).baseAsset.quantityScale,\n quoteAmount: (pair) => requirePair(getCatalog(), pair).quoteAsset.quantityScale,\n ledgerAmount: (ledgerAssetId) => {\n const ledger = getCatalog().ledger;\n if (!ledger.isKnownAssetId(ledgerAssetId)) {\n throw new CatalogLookupError(\"ledger\", \"ledgerId\", ledgerAssetId);\n }\n return ledger.requireAssetByLedgerId(ledgerAssetId).quantityScale;\n },\n zippedAssetAmount: (zippedAssetId) =>\n getCatalog().zipper.requireAssetChainByZippedAssetId(zippedAssetId).asset.quantityScale,\n };\n}\n\nfunction requirePair(catalog: ClientCatalog, pair: PairCatalogKey) {\n return typeof pair === \"string\" || (typeof pair === \"object\" && \"symbol\" in pair)\n ? catalog.market.requirePairBySymbol(typeof pair === \"string\" ? pair : pair.symbol)\n : catalog.market.requirePairBySymbolId(typeof pair === \"number\" ? pair : pair.symbolId);\n}\n\n/** Output direction: exact scaled→decimal conversion (`1500000n`@6 → `\"1.5\"`). */\nexport function scaledToDecimalOutput(value: bigint, scale: number): string {\n return scaledToDecimal(value, scale);\n}\n\nfunction conversionFailureMessage(\n field: string,\n value: string,\n failure: DecimalToScaledFailure,\n): string {\n return failure.reason === \"precision\"\n ? `${field} supports at most ${failure.maxDecimals} decimal places: ${value}`\n : `${field} must be a non-negative decimal number: ${value}`;\n}\n\n/**\n * Input direction: strict decimal→scaled conversion. Throws\n * CatalogConversionError for non-decimal input or inexact excess precision.\n */\nexport function decimalInputToScaled(field: string, value: string, scale: number): bigint {\n const result = tryDecimalToScaled(value.trim(), scale);\n if (!result.ok) {\n throw new CatalogConversionError(\n field,\n conversionFailureMessage(field, value, result.failure),\n );\n }\n return result.scaled;\n}\n\nfunction unboundedPositiveDecimalInputToScaled(\n field: string,\n value: string,\n scale: number,\n): bigint {\n const scaled = decimalInputToScaled(field, value, scale);\n if (scaled <= 0n) {\n throw new CatalogConversionError(field, `${field} must be greater than 0: ${value}`);\n }\n return scaled;\n}\n\n/**\n * Converts a positive decimal input to a scaled protobuf `int64` value.\n * Rejects values above the wire-format ceiling before serialization.\n */\nexport function positiveDecimalInputToScaled(field: string, value: string, scale: number): bigint {\n const scaled = unboundedPositiveDecimalInputToScaled(field, value, scale);\n if (scaled > PROTOBUF_INT64_MAX) {\n throw new CatalogConversionError(\n field,\n `${field} exceeds the maximum supported value: ${value}`,\n );\n }\n return scaled;\n}\n\n/**\n * Decimal quantity → PolyesterChain E18 ledger units.\n * Input precision is capped at the asset's quantityScale; the wire value is\n * always upscaled to E18 (trading balances / amount_e18 convention).\n */\nexport function quantityInputToE18(params: {\n scales: SdkScales;\n assetId: number;\n quantity: string;\n field?: string;\n}): bigint {\n const field = params.field ?? \"quantity\";\n const assetScale = params.scales.ledgerAmount(params.assetId);\n if (assetScale > E18_SCALE) {\n throw new CatalogConversionError(\n field,\n `${field} asset quantityScale ${assetScale} exceeds E18 ledger scale`,\n );\n }\n return (\n unboundedPositiveDecimalInputToScaled(field, params.quantity, assetScale) *\n 10n ** BigInt(E18_SCALE - assetScale)\n );\n}\n\nexport interface ReadyGate {\n /** Queues or delivers one transition while the gate remains active. */\n run(deliver: () => void): void;\n /** Drops pending transitions and permanently prevents future delivery. */\n close(): void;\n}\n\ninterface ReadyGateHandlers {\n onDeliveryError?: (error: unknown) => void;\n onTerminalError: (error: unknown) => void;\n}\n\nconst READY_GATE_MAX_PENDING_DELIVERIES = 1_024;\n\n/**\n * Transition event delivery behind catalog readiness. Events arriving before the\n * catalog can resolve scales are queued and flushed in arrival order once it\n * is ready. Delivery errors are isolated from the transport. Readiness failure\n * or queue overflow is terminal because dropping an event would break stream\n * continuity; the owning subscription must visibly terminate when notified.\n */\nexport function createReadyGate(\n ready: () => Promise<void>,\n handlers: ReadyGateHandlers,\n): ReadyGate {\n let state: \"pending\" | \"open\" | \"closed\" = \"pending\";\n const queue: Array<() => void> = [];\n\n const deliverIsolated = (deliver: () => void) => {\n try {\n deliver();\n } catch (error) {\n handlers.onDeliveryError?.(error);\n }\n };\n\n const closeWithError = (error: unknown) => {\n if (state === \"closed\") return;\n state = \"closed\";\n queue.length = 0;\n handlers.onTerminalError(error);\n };\n\n Promise.resolve()\n .then(ready)\n .then(\n () => {\n if (state !== \"pending\") return;\n state = \"open\";\n for (const deliver of queue.splice(0)) deliverIsolated(deliver);\n },\n (error) => {\n if (state !== \"pending\") return;\n closeWithError(error);\n },\n );\n\n return {\n run(deliver) {\n if (state === \"open\") deliverIsolated(deliver);\n else if (state === \"pending\") {\n if (queue.length === READY_GATE_MAX_PENDING_DELIVERIES) {\n closeWithError(new CatalogNotReadyError());\n return;\n }\n queue.push(deliver);\n }\n },\n close() {\n if (state === \"closed\") return;\n state = \"closed\";\n queue.length = 0;\n },\n };\n}\n"],"mappings":";;;;;;;AAqDA,SAAgB,uBAAuB,YAA4C;CAC/E,OAAO;EACH,OAAO,YAAY;GACf,MAAM,WAAW,CAAC,CAAC,YAAY;EACnC;EACA,aAAA;EACA,UAAU,SAAS,YAAY,WAAW,GAAG,IAAI,CAAC,CAAC,UAAU;EAC7D,cAAc,SAAS,YAAY,WAAW,GAAG,IAAI,CAAC,CAAC,WAAW;EAClE,eAAe,kBAAkB;GAC7B,MAAM,SAAS,WAAW,CAAC,CAAC;GAC5B,IAAI,CAAC,OAAO,eAAe,aAAa,GACpC,MAAM,IAAI,mBAAmB,UAAU,YAAY,aAAa;GAEpE,OAAO,OAAO,uBAAuB,aAAa,CAAC,CAAC;EACxD;EACA,oBAAoB,kBAChB,WAAW,CAAC,CAAC,OAAO,iCAAiC,aAAa,CAAC,CAAC,MAAM;CAClF;AACJ;AAEA,SAAS,YAAY,SAAwB,MAAsB;CAC/D,OAAO,OAAO,SAAS,YAAa,OAAO,SAAS,YAAY,YAAY,OACtE,QAAQ,OAAO,oBAAoB,OAAO,SAAS,WAAW,OAAO,KAAK,MAAM,IAChF,QAAQ,OAAO,sBAAsB,OAAO,SAAS,WAAW,OAAO,KAAK,QAAQ;AAC9F;;AAGA,SAAgB,sBAAsB,OAAe,OAAuB;CACxE,OAAO,gBAAgB,OAAO,KAAK;AACvC;AAEA,SAAS,yBACL,OACA,OACA,SACM;CACN,OAAO,QAAQ,WAAW,cACpB,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