@polyester/sdk 0.35.0-devnet-20261111031027 → 0.35.0-devnet-20261111140253

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 (184) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/dist/catalogs/snapshot-validation.js +2 -1
  3. package/dist/catalogs/snapshot-validation.js.map +1 -1
  4. package/dist/gen/ai/v1/assistant_pb.d.ts +4164 -0
  5. package/dist/gen/ai/v1/assistant_pb.d.ts.map +1 -0
  6. package/dist/gen/ai/v1/assistant_pb.js +1174 -0
  7. package/dist/gen/ai/v1/assistant_pb.js.map +1 -0
  8. package/dist/gen/alerts/v1/price_alerts_pb.d.ts +776 -0
  9. package/dist/gen/alerts/v1/price_alerts_pb.d.ts.map +1 -0
  10. package/dist/gen/alerts/v1/price_alerts_pb.js +378 -0
  11. package/dist/gen/alerts/v1/price_alerts_pb.js.map +1 -0
  12. package/dist/gen/auth/v1/address_book_pb.d.ts +6 -0
  13. package/dist/gen/auth/v1/address_book_pb.d.ts.map +1 -1
  14. package/dist/gen/auth/v1/address_book_pb.js +6 -0
  15. package/dist/gen/auth/v1/address_book_pb.js.map +1 -1
  16. package/dist/gen/auth/v1/api_keys_pb.d.ts +242 -2
  17. package/dist/gen/auth/v1/api_keys_pb.d.ts.map +1 -1
  18. package/dist/gen/auth/v1/api_keys_pb.js +81 -2
  19. package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
  20. package/dist/gen/auth/v1/auth_pb.d.ts +48 -6
  21. package/dist/gen/auth/v1/auth_pb.d.ts.map +1 -1
  22. package/dist/gen/auth/v1/auth_pb.js +48 -6
  23. package/dist/gen/auth/v1/auth_pb.js.map +1 -1
  24. package/dist/gen/auth/v1/policies_pb.d.ts +83 -19
  25. package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
  26. package/dist/gen/auth/v1/policies_pb.js +74 -16
  27. package/dist/gen/auth/v1/policies_pb.js.map +1 -1
  28. package/dist/gen/auth/v1/social_verification_pb.d.ts +167 -11
  29. package/dist/gen/auth/v1/social_verification_pb.d.ts.map +1 -1
  30. package/dist/gen/auth/v1/social_verification_pb.js +41 -3
  31. package/dist/gen/auth/v1/social_verification_pb.js.map +1 -1
  32. package/dist/gen/auth/v1/subaccounts_pb.d.ts +17 -6
  33. package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
  34. package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
  35. package/dist/gen/chain/deposit/v1/deposit_pb.d.ts +4 -2
  36. package/dist/gen/chain/deposit/v1/deposit_pb.d.ts.map +1 -1
  37. package/dist/gen/chain/deposit/v1/deposit_pb.js.map +1 -1
  38. package/dist/gen/chain/guard/v1/guard_signer_pb.d.ts +5 -0
  39. package/dist/gen/chain/guard/v1/guard_signer_pb.d.ts.map +1 -1
  40. package/dist/gen/chain/guard/v1/guard_signer_pb.js.map +1 -1
  41. package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts +10 -0
  42. package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts.map +1 -1
  43. package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.js +1 -1
  44. package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.js.map +1 -1
  45. package/dist/gen/chain/lifecycle/v1/types_pb.d.ts +32 -4
  46. package/dist/gen/chain/lifecycle/v1/types_pb.d.ts.map +1 -1
  47. package/dist/gen/chain/lifecycle/v1/types_pb.js +32 -4
  48. package/dist/gen/chain/lifecycle/v1/types_pb.js.map +1 -1
  49. package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts +391 -42
  50. package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts.map +1 -1
  51. package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.js +103 -17
  52. package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.js.map +1 -1
  53. package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +170 -3
  54. package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts.map +1 -1
  55. package/dist/gen/chain/withdraw/v1/withdraw_pb.js +63 -2
  56. package/dist/gen/chain/withdraw/v1/withdraw_pb.js.map +1 -1
  57. package/dist/gen/claims/v1/claims_pb.d.ts +1 -1
  58. package/dist/gen/claims/v1/claims_pb.js +1 -1
  59. package/dist/gen/claims/v1/claims_pb.js.map +1 -1
  60. package/dist/gen/index.d.ts +9 -5
  61. package/dist/gen/index.js +5 -1
  62. package/dist/gen/ledger/v1/catalog_pb.d.ts +9 -1
  63. package/dist/gen/ledger/v1/catalog_pb.d.ts.map +1 -1
  64. package/dist/gen/ledger/v1/catalog_pb.js +9 -1
  65. package/dist/gen/ledger/v1/catalog_pb.js.map +1 -1
  66. package/dist/gen/marketdata/v1/marketdata_pb.d.ts +8 -0
  67. package/dist/gen/marketdata/v1/marketdata_pb.d.ts.map +1 -1
  68. package/dist/gen/marketdata/v1/marketdata_pb.js +1 -1
  69. package/dist/gen/marketdata/v1/marketdata_pb.js.map +1 -1
  70. package/dist/gen/orders/v1/orders_pb.d.ts +4 -4
  71. package/dist/gen/orders/v1/orders_pb.js.map +1 -1
  72. package/dist/gen/polyester/ratelimit/v1/types_pb.d.ts +20 -1
  73. package/dist/gen/polyester/ratelimit/v1/types_pb.d.ts.map +1 -1
  74. package/dist/gen/polyester/ratelimit/v1/types_pb.js +20 -1
  75. package/dist/gen/polyester/ratelimit/v1/types_pb.js.map +1 -1
  76. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts +1186 -127
  77. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts.map +1 -1
  78. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js +282 -5
  79. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js.map +1 -1
  80. package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts +253 -38
  81. package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts.map +1 -1
  82. package/dist/gen/swap/quickswap/v1/quickswap_pb.js +180 -36
  83. package/dist/gen/swap/quickswap/v1/quickswap_pb.js.map +1 -1
  84. package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.d.ts +933 -0
  85. package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.d.ts.map +1 -0
  86. package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.js +292 -0
  87. package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.js.map +1 -0
  88. package/dist/gen/system/v1/system_pb.d.ts +77 -0
  89. package/dist/gen/system/v1/system_pb.d.ts.map +1 -0
  90. package/dist/gen/system/v1/system_pb.js +34 -0
  91. package/dist/gen/system/v1/system_pb.js.map +1 -0
  92. package/dist/gen/tradews/v1/trade_ws_pb.d.ts +2 -2
  93. package/dist/gen/tradews/v1/trade_ws_pb.js.map +1 -1
  94. package/dist/index.d.ts +5 -5
  95. package/dist/services/api-keys/api-keys.codecs.js +10 -1
  96. package/dist/services/api-keys/api-keys.codecs.js.map +1 -1
  97. package/dist/services/api-keys/api-keys.schemas.d.ts +4 -0
  98. package/dist/services/api-keys/api-keys.schemas.d.ts.map +1 -1
  99. package/dist/services/api-keys/api-keys.schemas.js +3 -1
  100. package/dist/services/api-keys/api-keys.schemas.js.map +1 -1
  101. package/dist/services/auto-withdraw/auto-withdraw.codecs.d.ts +9 -2
  102. package/dist/services/auto-withdraw/auto-withdraw.codecs.d.ts.map +1 -1
  103. package/dist/services/auto-withdraw/auto-withdraw.codecs.js +9 -1
  104. package/dist/services/auto-withdraw/auto-withdraw.codecs.js.map +1 -1
  105. package/dist/services/auto-withdraw/auto-withdraw.d.ts +15 -4
  106. package/dist/services/auto-withdraw/auto-withdraw.d.ts.map +1 -1
  107. package/dist/services/auto-withdraw/auto-withdraw.js +24 -8
  108. package/dist/services/auto-withdraw/auto-withdraw.js.map +1 -1
  109. package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +394 -26
  110. package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts.map +1 -1
  111. package/dist/services/auto-withdraw/auto-withdraw.schemas.js +66 -11
  112. package/dist/services/auto-withdraw/auto-withdraw.schemas.js.map +1 -1
  113. package/dist/services/auto-withdraw/auto-withdraw.types.d.ts +3 -3
  114. package/dist/services/candles/candles.schemas.d.ts +10 -10
  115. package/dist/services/changelog/changelog.schemas.d.ts +17 -17
  116. package/dist/services/checkpoints/checkpoints.schemas.d.ts +2 -2
  117. package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
  118. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +3 -3
  119. package/dist/services/lifecycle/lifecycle.codecs.d.ts +2 -2
  120. package/dist/services/lifecycle/lifecycle.codecs.d.ts.map +1 -1
  121. package/dist/services/lifecycle/lifecycle.codecs.js +3 -1
  122. package/dist/services/lifecycle/lifecycle.codecs.js.map +1 -1
  123. package/dist/services/lifecycle/lifecycle.schemas.d.ts +64 -40
  124. package/dist/services/lifecycle/lifecycle.schemas.d.ts.map +1 -1
  125. package/dist/services/lifecycle/lifecycle.schemas.js +7 -1
  126. package/dist/services/lifecycle/lifecycle.schemas.js.map +1 -1
  127. package/dist/services/market-data/market-data.schemas.js +7 -2
  128. package/dist/services/market-data/market-data.schemas.js.map +1 -1
  129. package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
  130. package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
  131. package/dist/services/orders/order-errors.schemas.d.ts +1 -1
  132. package/dist/services/orders/orders-batch.schemas.d.ts +27 -27
  133. package/dist/services/orders/orders-input.schemas.d.ts +3 -3
  134. package/dist/services/orders/orders-output.schemas.d.ts +17 -17
  135. package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -15
  136. package/dist/services/policies/shared.codecs.js +24 -3
  137. package/dist/services/policies/shared.codecs.js.map +1 -1
  138. package/dist/services/policies/shared.d.ts +1 -1
  139. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +3 -3
  140. package/dist/services/social-verification/social-verification.codecs.js +13 -5
  141. package/dist/services/social-verification/social-verification.codecs.js.map +1 -1
  142. package/dist/services/social-verification/social-verification.d.ts +18 -3
  143. package/dist/services/social-verification/social-verification.d.ts.map +1 -1
  144. package/dist/services/social-verification/social-verification.js +26 -3
  145. package/dist/services/social-verification/social-verification.js.map +1 -1
  146. package/dist/services/social-verification/social-verification.schemas.d.ts +33 -7
  147. package/dist/services/social-verification/social-verification.schemas.d.ts.map +1 -1
  148. package/dist/services/social-verification/social-verification.schemas.js +35 -10
  149. package/dist/services/social-verification/social-verification.schemas.js.map +1 -1
  150. package/dist/services/social-verification/social-verification.types.d.ts +2 -2
  151. package/dist/services/subaccounts/subaccounts.schemas.d.ts +7 -7
  152. package/dist/services/trades/trades.schemas.d.ts +2 -2
  153. package/dist/services/trading-withdraws/trading-withdraws.d.ts +7 -1
  154. package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
  155. package/dist/services/trading-withdraws/trading-withdraws.js +11 -1
  156. package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
  157. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts +42 -1
  158. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts.map +1 -1
  159. package/dist/services/trading-withdraws/trading-withdraws.schemas.js +19 -3
  160. package/dist/services/trading-withdraws/trading-withdraws.schemas.js.map +1 -1
  161. package/dist/services/trading-withdraws/trading-withdraws.types.d.ts +2 -2
  162. package/dist/services/transfers/transfers.schemas.d.ts +4 -4
  163. package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
  164. package/dist/services/triggers/triggers-output.schemas.d.ts +30 -30
  165. package/dist/shared/catalog-config.d.ts +5 -0
  166. package/dist/shared/catalog-config.d.ts.map +1 -1
  167. package/dist/shared/catalog-config.js.map +1 -1
  168. package/dist/shared/error-detail.d.ts +6 -0
  169. package/dist/shared/error-detail.d.ts.map +1 -1
  170. package/dist/shared/error-detail.js.map +1 -1
  171. package/dist/shared/error-details/withdraw.js +11 -2
  172. package/dist/shared/error-details/withdraw.js.map +1 -1
  173. package/dist/shared/ledger-codes.d.ts +4 -2
  174. package/dist/shared/ledger-codes.d.ts.map +1 -1
  175. package/dist/shared/ledger-codes.js +6 -3
  176. package/dist/shared/ledger-codes.js.map +1 -1
  177. package/dist/shared/rate-limit.schemas.d.ts +2 -2
  178. package/dist/shared/rate-limit.schemas.d.ts.map +1 -1
  179. package/dist/shared/rate-limit.schemas.js +4 -1
  180. package/dist/shared/rate-limit.schemas.js.map +1 -1
  181. package/dist/shared/transports.d.ts +2 -1
  182. package/dist/shared/transports.d.ts.map +1 -1
  183. package/dist/shared/transports.js.map +1 -1
  184. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","#prepareWithdraw"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ValidationError, WithdrawDeadlineExpiredError } from \"../../shared/errors.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport { checksumEvmAddress, evmHexToBytes } from \"../../utils/evm.js\";\nimport type { ClientCatalog } from \"../../catalogs/types.js\";\nimport * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n renewTradingWithdrawPayload,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\n type TradingWithdrawIntentPayloadRequest,\n type ValidateWithdrawDestinationInput,\n type ValidateWithdrawDestinationResult,\n} from \"./trading-withdraws.schemas.js\";\nimport { buildTradingWithdrawWalletMessage } from \"./wallet-message.js\";\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n /**\n * Signs the UTF-8 message directly using EIP-191 personal_sign, without pre-hashing or switching chains.\n * For a viem account, use `(message) => account.signMessage({ message })`.\n */\n signMessage: (message: string) => Promise<Hex>;\n};\n\nexport type TradingWithdrawSigningConfig = {\n chainId: number;\n tradingGatewayAddress: Address;\n};\n\nexport type CreateTradingWithdrawToFundingServiceInput = CreateTradingWithdrawToFundingInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n};\n\nexport type CreateTradingWithdrawToExternalChainServiceInput =\n CreateTradingWithdrawToExternalChainInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n };\n\nexport type PreparedTradingWithdraw = Readonly<{\n /** When the backend stops accepting the currently signed request. */\n deadline: Date;\n /**\n * True once the deadline is less than a minute away. Wallet-signed\n * withdraws sign again on `submit` from then on, so callers can keep resubmitting the\n * same prepared withdraw, e.g. after a slow MFA step-up. Payload-signed withdraws\n * cannot be signed again: prepare again (same input, same idempotency key) instead.\n */\n isExpired: () => boolean;\n /**\n * Submits the payload and signature produced during preparation. Repeated calls only\n * change transport options such as the step-up token, unless the deadline is near:\n * wallet-signed withdraws then sign a fresh deadline and nonce with the same idempotency\n * key, and payload-signed withdraws throw `WithdrawDeadlineExpiredError` once it passes.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype SignedTradingWithdraw = {\n payload: TradingWithdrawIntentPayloadRequest;\n send: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n};\n\n// Leaves room for the request to reach the backend and for modest clock skew.\nconst PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 60_000;\n\nfunction deadlineMs(payload: TradingWithdrawIntentPayloadRequest): number {\n return Number(payload.deadlineTsSec) * 1000;\n}\n\nfunction preparedWithdraw(\n signed: SignedTradingWithdraw,\n resign?: (payload: TradingWithdrawIntentPayloadRequest) => Promise<SignedTradingWithdraw>,\n): PreparedTradingWithdraw {\n let current = signed;\n const isExpired = () =>\n Date.now() >= deadlineMs(current.payload) - PREPARED_WITHDRAW_EXPIRY_MARGIN_MS;\n return {\n get deadline() {\n return new Date(deadlineMs(current.payload));\n },\n isExpired,\n submit: async (options) => {\n if (resign && isExpired()) {\n current = await resign(renewTradingWithdrawPayload(current.payload));\n } else if (Date.now() >= deadlineMs(current.payload)) {\n throw new WithdrawDeadlineExpiredError(\n \"Withdraw signature deadline has passed. Prepare the withdraw again.\",\n );\n }\n return current.send(options);\n },\n };\n}\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction resolveTradingWithdrawTargetAccountId(params: {\n subaccountId: bigint | undefined;\n rootAccountId: string;\n}): bigint {\n if (params.subaccountId !== undefined) return params.subaccountId;\n return idToBigInt(params.rootAccountId, \"targetAccountId\");\n}\n\nasync function resolveTradingWithdrawSigningConfig(params: {\n fallback: TradingWithdrawSigningConfig;\n catalog?: ClientCatalog;\n}): Promise<TradingWithdrawSigningConfig> {\n if (!params.catalog) return params.fallback;\n\n try {\n await params.catalog.ensureReady();\n const gateway = params.catalog.zipper.getContractByName(\"tradingGateway\");\n const address = gateway?.address?.trim();\n if (!address?.startsWith(\"0x\")) return params.fallback;\n\n return {\n chainId: params.fallback.chainId,\n tradingGatewayAddress: checksumEvmAddress(address),\n };\n } catch {\n return params.fallback;\n }\n}\n\nasync function resolveWalletSignature(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n walletSigner: TradingWithdrawWalletSigner;\n targetAccountId: bigint;\n}): Promise<{ signerWallet: string; payloadSignature: Uint8Array }> {\n const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signMessage(\n buildTradingWithdrawWalletMessage({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet,\n accountId,\n targetAccountId: params.targetAccountId,\n }),\n );\n if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) {\n throw new ValidationError(\n \"Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.\",\n );\n }\n return {\n signerWallet,\n payloadSignature: evmHexToBytes(signature),\n };\n}\n\n/**\n * Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-191 signatures.\n */\nexport class TradingWithdrawsService {\n #client: Client<typeof Proto.WithdrawService>;\n #resolver?: SubaccountResolver;\n #signingConfig: TradingWithdrawSigningConfig;\n #catalog?: ClientCatalog;\n #scales: SdkScales;\n #toFundingInputSchema: ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>;\n #toExternalChainInputSchema: ReturnType<\n typeof createCreateTradingWithdrawToExternalChainInputSchema\n >;\n\n constructor(\n transports: AuthApiTransports,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n ) {\n this.#client = createClient(Proto.WithdrawService, transports.authApi);\n this.#resolver = resolver;\n this.#signingConfig = signingConfig;\n this.#catalog = catalog;\n this.#scales = scales;\n this.#toFundingInputSchema = createCreateTradingWithdrawToFundingInputSchema(scales);\n this.#toExternalChainInputSchema =\n createCreateTradingWithdrawToExternalChainInputSchema(scales);\n }\n\n /**\n * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one.\n */\n async validateDestination(\n input: ValidateWithdrawDestinationInput,\n options?: PolyesterRequestOptions,\n ): Promise<ValidateWithdrawDestinationResult> {\n const request = parse(ValidateWithdrawDestinationInputSchema, input);\n const response = await this.#client.validateWithdrawDestination(\n request,\n toConnectCallOptions(options),\n );\n return parse(ValidateWithdrawDestinationResultSchema, response);\n }\n\n /**\n * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.\n */\n async createToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToFunding(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-Funding withdrawal once so the exact request can be\n * resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toFundingInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n /**\n * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.\n */\n async createToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToExternalChain(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-external-chain withdrawal once so the exact request can\n * be resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toExternalChainInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n async #prepareWithdraw(\n validated: TradingWithdrawRequest,\n walletSigner: TradingWithdrawWalletSigner | undefined,\n ): Promise<PreparedTradingWithdraw> {\n if (walletSigner) {\n const signingConfig = await resolveTradingWithdrawSigningConfig({\n fallback: this.#signingConfig,\n catalog: this.#catalog,\n });\n const targetAccountId = resolveTradingWithdrawTargetAccountId({\n subaccountId: validated.subaccountId,\n rootAccountId: walletSigner.accountId,\n });\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n\n if (!validated.payloadSignature) {\n throw new ValidationError(\n \"Trading withdraw requires a wallet signer or payload signature.\",\n );\n }\n\n const request = removeUndefined({\n payload: validated.payload,\n payloadSignature: validated.payloadSignature,\n });\n return preparedWithdraw({\n payload: validated.payload,\n send: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateTradingWithdrawResultSchema, response);\n },\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAqFA,MAAM,qCAAqC;AAE3C,SAAS,WAAW,SAAsD;CACtE,OAAO,OAAO,QAAQ,aAAa,IAAI;AAC3C;AAEA,SAAS,iBACL,QACA,QACuB;CACvB,IAAI,UAAU;CACd,MAAM,kBACF,KAAK,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M,gBAAgB,MAAM,oCAAoC;IAC5D,UAAU,KAAKL;IACf,SAAS,KAAKC;GAClB,CAAC;GACD,MAAM,kBAAkB,sCAAsC;IAC1D,cAAc,UAAU;IACxB,eAAe,aAAa;GAChC,CAAC;GACD,MAAM,OAAO,OACT,YACiC;IACjC,MAAM,kBAAkB,MAAM,uBAAuB;KACjD;KACA;KACA;KACA;IACJ,CAAC;IACD,MAAM,UAAU,gBAAgB;KAC5B;KACA,cAAc,UAAU;KACxB,cAAc,gBAAgB;KAC9B,kBAAkB,gBAAgB;IACtC,CAAC;IACD,OAAO;KACH;KACA,MAAM,OAAO,YAAY;MACrB,MAAM,WAAW,MAAM,KAAKJ,QAAQ,4BAChC,SACA,qBAAqB,OAAO,CAChC;MACA,OAAO,MAAM,yCAAyC,QAAQ;KAClE;IACJ;GACJ;GACA,OAAO,iBAAiB,MAAM,KAAK,UAAU,OAAO,GAAG,IAAI;EAC/D;EAEA,IAAI,CAAC,UAAU,kBACX,MAAM,IAAI,gBACN,iEACJ;EAGJ,MAAM,UAAU,gBAAgB;GAC5B,SAAS,UAAU;GACnB,kBAAkB,UAAU;EAChC,CAAC;EACD,OAAO,iBAAiB;GACpB,SAAS,UAAU;GACnB,MAAM,OAAO,YAAY;IACrB,MAAM,WAAW,MAAM,KAAKA,QAAQ,sBAChC,SACA,qBAAqB,OAAO,CAChC;IACA,OAAO,MAAM,mCAAmC,QAAQ;GAC5D;EACJ,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","#prepareWithdraw"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ValidationError, WithdrawDeadlineExpiredError } from \"../../shared/errors.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport { checksumEvmAddress, evmHexToBytes } from \"../../utils/evm.js\";\nimport type { ClientCatalog } from \"../../catalogs/types.js\";\nimport * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n GetWalletBalancesInputSchema,\n GetWalletBalancesResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n renewTradingWithdrawPayload,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\n type GetWalletBalancesInput,\n type GetWalletBalancesResult,\n type TradingWithdrawIntentPayloadRequest,\n type ValidateWithdrawDestinationInput,\n type ValidateWithdrawDestinationResult,\n} from \"./trading-withdraws.schemas.js\";\nimport { buildTradingWithdrawWalletMessage } from \"./wallet-message.js\";\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n /**\n * Signs the UTF-8 message directly using EIP-191 personal_sign, without pre-hashing or switching chains.\n * For a viem account, use `(message) => account.signMessage({ message })`.\n */\n signMessage: (message: string) => Promise<Hex>;\n};\n\nexport type TradingWithdrawSigningConfig = {\n chainId: number;\n tradingGatewayAddress: Address;\n};\n\nexport type CreateTradingWithdrawToFundingServiceInput = CreateTradingWithdrawToFundingInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n};\n\nexport type CreateTradingWithdrawToExternalChainServiceInput =\n CreateTradingWithdrawToExternalChainInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n };\n\nexport type PreparedTradingWithdraw = Readonly<{\n /** When the backend stops accepting the currently signed request. */\n deadline: Date;\n /**\n * True once the deadline is less than a minute away. Wallet-signed\n * withdraws sign again on `submit` from then on, so callers can keep resubmitting the\n * same prepared withdraw, e.g. after a slow MFA step-up. Payload-signed withdraws\n * cannot be signed again: prepare again (same input, same idempotency key) instead.\n */\n isExpired: () => boolean;\n /**\n * Submits the payload and signature produced during preparation. Repeated calls only\n * change transport options such as the step-up token, unless the deadline is near:\n * wallet-signed withdraws then sign a fresh deadline and nonce with the same idempotency\n * key, and payload-signed withdraws throw `WithdrawDeadlineExpiredError` once it passes.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype SignedTradingWithdraw = {\n payload: TradingWithdrawIntentPayloadRequest;\n send: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n};\n\n// Leaves room for the request to reach the backend and for modest clock skew.\nconst PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 60_000;\n\nfunction deadlineMs(payload: TradingWithdrawIntentPayloadRequest): number {\n return Number(payload.deadlineTsSec) * 1000;\n}\n\nfunction preparedWithdraw(\n signed: SignedTradingWithdraw,\n resign?: (payload: TradingWithdrawIntentPayloadRequest) => Promise<SignedTradingWithdraw>,\n): PreparedTradingWithdraw {\n let current = signed;\n const isExpired = () =>\n Date.now() >= deadlineMs(current.payload) - PREPARED_WITHDRAW_EXPIRY_MARGIN_MS;\n return {\n get deadline() {\n return new Date(deadlineMs(current.payload));\n },\n isExpired,\n submit: async (options) => {\n if (resign && isExpired()) {\n current = await resign(renewTradingWithdrawPayload(current.payload));\n } else if (Date.now() >= deadlineMs(current.payload)) {\n throw new WithdrawDeadlineExpiredError(\n \"Withdraw signature deadline has passed. Prepare the withdraw again.\",\n );\n }\n return current.send(options);\n },\n };\n}\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction resolveTradingWithdrawTargetAccountId(params: {\n subaccountId: bigint | undefined;\n rootAccountId: string;\n}): bigint {\n if (params.subaccountId !== undefined) return params.subaccountId;\n return idToBigInt(params.rootAccountId, \"targetAccountId\");\n}\n\nasync function resolveTradingWithdrawSigningConfig(params: {\n fallback: TradingWithdrawSigningConfig;\n catalog?: ClientCatalog;\n}): Promise<TradingWithdrawSigningConfig> {\n if (!params.catalog) return params.fallback;\n\n try {\n await params.catalog.ensureReady();\n const gateway = params.catalog.zipper.getContractByName(\"tradingGateway\");\n const address = gateway?.address?.trim();\n if (!address?.startsWith(\"0x\")) return params.fallback;\n\n return {\n chainId: params.fallback.chainId,\n tradingGatewayAddress: checksumEvmAddress(address),\n };\n } catch {\n return params.fallback;\n }\n}\n\nasync function resolveWalletSignature(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n walletSigner: TradingWithdrawWalletSigner;\n targetAccountId: bigint;\n}): Promise<{ signerWallet: string; payloadSignature: Uint8Array }> {\n const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signMessage(\n buildTradingWithdrawWalletMessage({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet,\n accountId,\n targetAccountId: params.targetAccountId,\n }),\n );\n if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) {\n throw new ValidationError(\n \"Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.\",\n );\n }\n return {\n signerWallet,\n payloadSignature: evmHexToBytes(signature),\n };\n}\n\n/**\n * Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-191 signatures.\n */\nexport class TradingWithdrawsService {\n #client: Client<typeof Proto.WithdrawService>;\n #resolver?: SubaccountResolver;\n #signingConfig: TradingWithdrawSigningConfig;\n #catalog?: ClientCatalog;\n #scales: SdkScales;\n #toFundingInputSchema: ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>;\n #toExternalChainInputSchema: ReturnType<\n typeof createCreateTradingWithdrawToExternalChainInputSchema\n >;\n\n constructor(\n transports: AuthApiTransports,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n ) {\n this.#client = createClient(Proto.WithdrawService, transports.authApi);\n this.#resolver = resolver;\n this.#signingConfig = signingConfig;\n this.#catalog = catalog;\n this.#scales = scales;\n this.#toFundingInputSchema = createCreateTradingWithdrawToFundingInputSchema(scales);\n this.#toExternalChainInputSchema =\n createCreateTradingWithdrawToExternalChainInputSchema(scales);\n }\n\n /**\n * Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a\n * rejected withdrawal's refund (see the lifecycle step's `refundAddress`), which stays there\n * until moved. API keys need `read-balances`.\n */\n async getWalletBalances(\n input: GetWalletBalancesInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<GetWalletBalancesResult> {\n const request = parse(\n GetWalletBalancesInputSchema,\n resolveAccountScopedInput(input, this.#resolver),\n );\n const response = await this.#client.getWalletBalances(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(GetWalletBalancesResultSchema, response);\n }\n\n /**\n * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one.\n */\n async validateDestination(\n input: ValidateWithdrawDestinationInput,\n options?: PolyesterRequestOptions,\n ): Promise<ValidateWithdrawDestinationResult> {\n const request = parse(ValidateWithdrawDestinationInputSchema, input);\n const response = await this.#client.validateWithdrawDestination(\n request,\n toConnectCallOptions(options),\n );\n return parse(ValidateWithdrawDestinationResultSchema, response);\n }\n\n /**\n * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.\n */\n async createToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToFunding(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-Funding withdrawal once so the exact request can be\n * resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toFundingInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n /**\n * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.\n */\n async createToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToExternalChain(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-external-chain withdrawal once so the exact request can\n * be resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toExternalChainInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n async #prepareWithdraw(\n validated: TradingWithdrawRequest,\n walletSigner: TradingWithdrawWalletSigner | undefined,\n ): Promise<PreparedTradingWithdraw> {\n if (walletSigner) {\n const signingConfig = await resolveTradingWithdrawSigningConfig({\n fallback: this.#signingConfig,\n catalog: this.#catalog,\n });\n const targetAccountId = resolveTradingWithdrawTargetAccountId({\n subaccountId: validated.subaccountId,\n rootAccountId: walletSigner.accountId,\n });\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n\n if (!validated.payloadSignature) {\n throw new ValidationError(\n \"Trading withdraw requires a wallet signer or payload signature.\",\n );\n }\n\n const request = removeUndefined({\n payload: validated.payload,\n payloadSignature: validated.payloadSignature,\n });\n return preparedWithdraw({\n payload: validated.payload,\n send: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateTradingWithdrawResultSchema, response);\n },\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyFA,MAAM,qCAAqC;AAE3C,SAAS,WAAW,SAAsD;CACtE,OAAO,OAAO,QAAQ,aAAa,IAAI;AAC3C;AAEA,SAAS,iBACL,QACA,QACuB;CACvB,IAAI,UAAU;CACd,MAAM,kBACF,KAAK,IAAI,KAAK,WAAW,QAAQ,OAAO,IAAI;CAChD,OAAO;EACH,IAAI,WAAW;GACX,OAAO,IAAI,KAAK,WAAW,QAAQ,OAAO,CAAC;EAC/C;EACA;EACA,QAAQ,OAAO,YAAY;GACvB,IAAI,UAAU,UAAU,GACpB,UAAU,MAAM,OAAO,4BAA4B,QAAQ,OAAO,CAAC;QAChE,IAAI,KAAK,IAAI,KAAK,WAAW,QAAQ,OAAO,GAC/C,MAAM,IAAI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KAAKC;GAClB,CAAC;GACD,MAAM,kBAAkB,sCAAsC;IAC1D,cAAc,UAAU;IACxB,eAAe,aAAa;GAChC,CAAC;GACD,MAAM,OAAO,OACT,YACiC;IACjC,MAAM,kBAAkB,MAAM,uBAAuB;KACjD;KACA;KACA;KACA;IACJ,CAAC;IACD,MAAM,UAAU,gBAAgB;KAC5B;KACA,cAAc,UAAU;KACxB,cAAc,gBAAgB;KAC9B,kBAAkB,gBAAgB;IACtC,CAAC;IACD,OAAO;KACH;KACA,MAAM,OAAO,YAAY;MACrB,MAAM,WAAW,MAAM,KAAKJ,QAAQ,4BAChC,SACA,qBAAqB,OAAO,CAChC;MACA,OAAO,MAAM,yCAAyC,QAAQ;KAClE;IACJ;GACJ;GACA,OAAO,iBAAiB,MAAM,KAAK,UAAU,OAAO,GAAG,IAAI;EAC/D;EAEA,IAAI,CAAC,UAAU,kBACX,MAAM,IAAI,gBACN,iEACJ;EAGJ,MAAM,UAAU,gBAAgB;GAC5B,SAAS,UAAU;GACnB,kBAAkB,UAAU;EAChC,CAAC;EACD,OAAO,iBAAiB;GACpB,SAAS,UAAU;GACnB,MAAM,OAAO,YAAY;IACrB,MAAM,WAAW,MAAM,KAAKA,QAAQ,sBAChC,SACA,qBAAqB,OAAO,CAChC;IACA,OAAO,MAAM,mCAAmC,QAAQ;GAC5D;EACJ,CAAC;CACL;AACJ"}
@@ -123,6 +123,47 @@ declare const ValidateWithdrawDestinationResultSchema: v.UnionSchema<[v.SchemaWi
123
123
  canonicalDestinationAddress: string;
124
124
  }>]>], undefined>;
125
125
  type ValidateWithdrawDestinationResult = v.InferOutput<typeof ValidateWithdrawDestinationResultSchema>;
126
+ declare const WalletBalancesInputObjectSchema: v.StrictObjectSchema<{
127
+ readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
128
+ readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
129
+ }, undefined>], undefined>, undefined>;
130
+ }, undefined>;
131
+ type GetWalletBalancesInput = v.InferInput<typeof WalletBalancesInputObjectSchema>;
132
+ declare const GetWalletBalancesResultSchema: v.ObjectSchema<{
133
+ readonly smartAccountAddress: v.StringSchema<undefined>;
134
+ readonly balances: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
135
+ readonly zippedAssetId: v.NumberSchema<undefined>;
136
+ readonly unifiedAssetId: v.NumberSchema<undefined>;
137
+ readonly chainId: v.NumberSchema<undefined>;
138
+ readonly ztokenAddress: v.StringSchema<undefined>;
139
+ readonly amountE18: v.OptionalSchema<v.ObjectSchema<{
140
+ readonly hi: v.BigintSchema<undefined>;
141
+ readonly lo: v.BigintSchema<undefined>;
142
+ }, undefined>, undefined>;
143
+ }, undefined>, v.TransformAction<{
144
+ zippedAssetId: number;
145
+ unifiedAssetId: number;
146
+ chainId: number;
147
+ ztokenAddress: string;
148
+ amountE18?: {
149
+ hi: bigint;
150
+ lo: bigint;
151
+ } | undefined;
152
+ }, {
153
+ amount: string;
154
+ zippedAssetId: number;
155
+ unifiedAssetId: number;
156
+ chainId: number;
157
+ ztokenAddress: string;
158
+ }>]>, undefined>;
159
+ }, undefined>;
160
+ /**
161
+ * zTokens the account's smart account wallet holds on Polyester Chain, read live from the
162
+ * chain: for example a rejected withdrawal's refund, which stays there until moved. `amount`
163
+ * is a decimal string (zTokens have 18 decimals); `chainId` is a `GetDepositWithdrawConfig`
164
+ * chain. `balances` lists nonzero balances by `zippedAssetId` and is empty when there are none.
165
+ */
166
+ type GetWalletBalancesResult = v.InferOutput<typeof GetWalletBalancesResultSchema>;
126
167
  //#endregion
127
- export { CreateTradingWithdrawResult, CreateTradingWithdrawResultSchema, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, TradingWithdrawIntentPayloadRequest, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResult, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema };
168
+ export { CreateTradingWithdrawResult, CreateTradingWithdrawResultSchema, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, GetWalletBalancesResultSchema, TradingWithdrawIntentPayloadRequest, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResult, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema };
128
169
  //# sourceMappingURL=trading-withdraws.schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAkBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;EACT,mBAAmB;;iBAmDP,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GAqChF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CtF;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":";;;;;KAwBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;EACT,mBAAmB;;iBAmDP,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GAqChF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CtF;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;cAGL,iCAA+B,EAAA;;;;;KAOzB,yBAAyB,EAAE,kBAAkB;cAE5C,+BAA6B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyB9B,0BAA0B,EAAE,mBAAmB"}
@@ -1,8 +1,9 @@
1
1
  import { ConfigurationError } from "../../shared/errors.js";
2
- import { quantityInputToE18 } from "../../shared/decimal-surface.js";
2
+ import { U128Schema } from "../../shared/schemas.js";
3
+ import { quantityInputToE18, scaledToDecimalOutput } from "../../shared/decimal-surface.js";
3
4
  import { PositiveUint32InputSchema } from "../shared.js";
4
5
  import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
5
- import { toU128 } from "../../utils/u128.js";
6
+ import { fromU128, toU128 } from "../../utils/u128.js";
6
7
  import "../../gen/chain/withdraw/v1/withdraw_pb.js";
7
8
  import { TradingWithdrawActionCodec, WithdrawDestinationValidationCodeCodec } from "./trading-withdraws.codecs.js";
8
9
  import * as v from "valibot";
@@ -143,7 +144,22 @@ const InvalidWithdrawDestinationResultSchema = v.pipe(v.object({
143
144
  code: InvalidWithdrawDestinationCodeCodec[result.code]
144
145
  })));
145
146
  const ValidateWithdrawDestinationResultSchema = v.union([ValidWithdrawDestinationResultSchema, InvalidWithdrawDestinationResultSchema]);
147
+ const WalletBalancesInputObjectSchema = v.strictObject({ ...AccountScopeInputEntries });
148
+ const GetWalletBalancesInputSchema = v.pipe(WalletBalancesInputObjectSchema, v.transform(({ account }) => ({ subaccountId: accountScopeToSubaccountId(account) })));
149
+ const GetWalletBalancesResultSchema = v.object({
150
+ smartAccountAddress: v.string(),
151
+ balances: v.array(v.pipe(v.object({
152
+ zippedAssetId: v.number(),
153
+ unifiedAssetId: v.number(),
154
+ chainId: v.number(),
155
+ ztokenAddress: v.string(),
156
+ amountE18: v.optional(U128Schema)
157
+ }), v.transform(({ amountE18, ...balance }) => ({
158
+ ...balance,
159
+ amount: scaledToDecimalOutput(fromU128(amountE18), 18)
160
+ }))))
161
+ });
146
162
  //#endregion
147
- export { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload };
163
+ export { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, GetWalletBalancesInputSchema, GetWalletBalancesResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload };
148
164
 
149
165
  //# sourceMappingURL=trading-withdraws.schemas.js.map
@@ -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 { 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 { ConfigurationError } from \"../../shared/errors.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 throw new ConfigurationError(\"Secure nonce generation requires crypto.getRandomValues.\");\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0]!;\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 deadline: Date | undefined;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(\n input.deadline\n ? Math.floor(input.deadline.getTime() / 1000)\n : Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS,\n ),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\n/** The same withdraw with a fresh default deadline and nonce, for signing again. */\nexport function renewTradingWithdrawPayload(\n payload: TradingWithdrawIntentPayloadRequest,\n): TradingWithdrawIntentPayloadRequest {\n return {\n ...payload,\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\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 * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\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 deadline: input.deadline,\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 * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\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 deadline: input.deadline,\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":";;;;;;;;;AAgBA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,iBAAiB,KAAK,WAA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raws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PositiveUint32InputSchema } from \"../shared.js\";\nimport {\n E18_SCALE,\n quantityInputToE18,\n scaledToDecimalOutput,\n type SdkScales,\n} 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 { fromU128, toU128, type U128Value } from \"../../utils/u128.js\";\nimport { U128Schema } from \"../../shared/schemas.js\";\nimport { ConfigurationError } from \"../../shared/errors.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 throw new ConfigurationError(\"Secure nonce generation requires crypto.getRandomValues.\");\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0]!;\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 deadline: Date | undefined;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(\n input.deadline\n ? Math.floor(input.deadline.getTime() / 1000)\n : Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS,\n ),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\n/** The same withdraw with a fresh default deadline and nonce, for signing again. */\nexport function renewTradingWithdrawPayload(\n payload: TradingWithdrawIntentPayloadRequest,\n): TradingWithdrawIntentPayloadRequest {\n return {\n ...payload,\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\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 * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\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 deadline: input.deadline,\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 * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\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 deadline: input.deadline,\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\nconst WalletBalancesInputObjectSchema = v.strictObject({ ...AccountScopeInputEntries });\n\nexport const GetWalletBalancesInputSchema = v.pipe(\n WalletBalancesInputObjectSchema,\n v.transform(({ account }) => ({ subaccountId: accountScopeToSubaccountId(account) })),\n);\n\nexport type GetWalletBalancesInput = v.InferInput<typeof WalletBalancesInputObjectSchema>;\n\nexport const GetWalletBalancesResultSchema = v.object({\n smartAccountAddress: v.string(),\n balances: v.array(\n v.pipe(\n v.object({\n zippedAssetId: v.number(),\n unifiedAssetId: v.number(),\n chainId: v.number(),\n ztokenAddress: v.string(),\n amountE18: v.optional(U128Schema),\n }),\n v.transform(({ amountE18, ...balance }) => ({\n ...balance,\n amount: scaledToDecimalOutput(fromU128(amountE18), E18_SCALE),\n })),\n ),\n ),\n});\n\n/**\n * zTokens the account's smart account wallet holds on Polyester Chain, read live from the\n * chain: for example a rejected withdrawal's refund, which stays there until moved. `amount`\n * is a decimal string (zTokens have 18 decimals); `chainId` is a `GetDepositWithdrawConfig`\n * chain. `balances` lists nonzero balances by `zippedAssetId` and is empty when there are none.\n */\nexport type GetWalletBalancesResult = v.InferOutput<typeof GetWalletBalancesResultSchema>;\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,iBAAiB,KAAK,WAAW,MAAM;CACzE,IAAI,CAAC,QACD,MAAM,IAAI,mBAAmB,0DAA0D;CAG3F,MAAM,wBAAQ,IAAI,eAAe,CAAC;CAClC,OAAO,KAAK;CACZ,MAAM,QAAQ,MAAM;CACpB,OAAO,UAAU,KAAK,KAAK;AAC/B;AAEA,SAAS,6BAA6B,OAQE;CACpC,OAAO;EACH,QAAQ,MAAM;EAC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AE,OAAO;EACL,eAAe,EAAE,OAAO;EACxB,gBAAgB,EAAE,OAAO;EACzB,SAAS,EAAE,OAAO;EAClB,eAAe,EAAE,OAAO;EACxB,WAAW,EAAE,SAAS,UAAU;CACpC,CAAC,GACD,EAAE,WAAW,EAAE,WAAW,GAAG,eAAe;EACxC,GAAG;EACH,QAAQ,sBAAsB,SAAS,SAAS,GAAA,EAAY;CAChE,EAAE,CACN,CACJ;AACJ,CAAC"}
@@ -1,3 +1,3 @@
1
- import { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
1
+ import { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
2
2
  import { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner } from "./trading-withdraws.js";
3
- export type { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult };
3
+ export type { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingInput, CreateTradingWithdrawToFundingServiceInput, GetWalletBalancesInput, GetWalletBalancesResult, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult };
@@ -84,7 +84,7 @@ declare const LedgerTransferSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
84
84
  assetId: number;
85
85
  amount: string;
86
86
  balanceAfter: string | undefined;
87
- type: "unspecified" | "internal_transfer" | "deposit" | "withdraw" | "maker_fee" | "taker_fee" | "trade_base" | "trade_quote" | "rebate" | "funding_to_trading" | "trading_to_funding" | "trading_withdraw_reserve" | "funding_user_transfer" | "trading_withdraw_request_fee" | "trading_withdraw_fee_leg" | "quickswap_polyester_fee" | "quickswap_broker_fee" | "quickswap_affiliate_fee" | "fee_sweep" | "fee_refill" | "system_adjustment";
87
+ type: "unspecified" | "internal_transfer" | "deposit" | "withdraw" | "maker_fee" | "taker_fee" | "trade_base" | "trade_quote" | "rebate" | "funding_to_trading" | "trading_to_funding" | "trading_withdraw_reserve" | "funding_user_transfer" | "trading_withdraw_request_fee" | "trading_withdraw_fee_leg" | "quickswap_polyester_fee" | "quickswap_broker_fee" | "quickswap_affiliate_fee" | "fee_sweep" | "fee_refill" | "system_adjustment" | "withdraw_failed";
88
88
  accountCode: "unspecified" | "trading" | "funding";
89
89
  timestamp: number;
90
90
  isDebit: boolean;
@@ -98,7 +98,7 @@ declare const ListTransfersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjec
98
98
  readonly reversed: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
99
99
  readonly timestampMin: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, number, undefined>, v.TransformAction<number, bigint>]>, undefined>;
100
100
  readonly timestampMax: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, number, undefined>, v.TransformAction<number, bigint>]>, undefined>;
101
- readonly transferCode: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["deposit", "withdraw", "maker_fee", "taker_fee", "internal_transfer", "trade_base", "trade_quote", "rebate", "funding_to_trading", "trading_to_funding", "trading_withdraw_reserve", "funding_user_transfer", "trading_withdraw_request_fee", "trading_withdraw_fee_leg", "quickswap_polyester_fee", "quickswap_broker_fee", "quickswap_affiliate_fee", "fee_sweep", "fee_refill", "system_adjustment"], undefined>, v.TransformAction<"internal_transfer" | "deposit" | "withdraw" | "maker_fee" | "taker_fee" | "trade_base" | "trade_quote" | "rebate" | "funding_to_trading" | "trading_to_funding" | "trading_withdraw_reserve" | "funding_user_transfer" | "trading_withdraw_request_fee" | "trading_withdraw_fee_leg" | "quickswap_polyester_fee" | "quickswap_broker_fee" | "quickswap_affiliate_fee" | "fee_sweep" | "fee_refill" | "system_adjustment", TransferCode.DEPOSIT | TransferCode.WITHDRAW | TransferCode.MAKER_FEE | TransferCode.TAKER_FEE | TransferCode.INTERNAL_TRANSFER | TransferCode.TRADE_BASE | TransferCode.TRADE_QUOTE | TransferCode.REBATE | TransferCode.FUNDING_TO_TRADING | TransferCode.TRADING_TO_FUNDING | TransferCode.TRADING_WITHDRAW_RESERVE | TransferCode.FUNDING_USER_TRANSFER | TransferCode.TRADING_WITHDRAW_REQUEST_FEE | TransferCode.TRADING_WITHDRAW_FEE_LEG | TransferCode.QUICKSWAP_POLYESTER_FEE | TransferCode.QUICKSWAP_BROKER_FEE | TransferCode.QUICKSWAP_AFFILIATE_FEE | TransferCode.FEE_SWEEP | TransferCode.FEE_REFILL | TransferCode.SYSTEM_ADJUSTMENT>]>, undefined>;
101
+ readonly transferCode: v.OptionalSchema<v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["deposit", "withdraw", "maker_fee", "taker_fee", "internal_transfer", "trade_base", "trade_quote", "rebate", "funding_to_trading", "trading_to_funding", "trading_withdraw_reserve", "funding_user_transfer", "trading_withdraw_request_fee", "trading_withdraw_fee_leg", "quickswap_polyester_fee", "quickswap_broker_fee", "quickswap_affiliate_fee", "fee_sweep", "fee_refill", "system_adjustment", "withdraw_failed"], undefined>, v.TransformAction<"internal_transfer" | "deposit" | "withdraw" | "maker_fee" | "taker_fee" | "trade_base" | "trade_quote" | "rebate" | "funding_to_trading" | "trading_to_funding" | "trading_withdraw_reserve" | "funding_user_transfer" | "trading_withdraw_request_fee" | "trading_withdraw_fee_leg" | "quickswap_polyester_fee" | "quickswap_broker_fee" | "quickswap_affiliate_fee" | "fee_sweep" | "fee_refill" | "system_adjustment" | "withdraw_failed", TransferCode.DEPOSIT | TransferCode.WITHDRAW | TransferCode.MAKER_FEE | TransferCode.TAKER_FEE | TransferCode.INTERNAL_TRANSFER | TransferCode.TRADE_BASE | TransferCode.TRADE_QUOTE | TransferCode.REBATE | TransferCode.FUNDING_TO_TRADING | TransferCode.TRADING_TO_FUNDING | TransferCode.TRADING_WITHDRAW_RESERVE | TransferCode.FUNDING_USER_TRANSFER | TransferCode.TRADING_WITHDRAW_REQUEST_FEE | TransferCode.TRADING_WITHDRAW_FEE_LEG | TransferCode.QUICKSWAP_POLYESTER_FEE | TransferCode.QUICKSWAP_BROKER_FEE | TransferCode.QUICKSWAP_AFFILIATE_FEE | TransferCode.FEE_SWEEP | TransferCode.FEE_REFILL | TransferCode.SYSTEM_ADJUSTMENT | TransferCode.WITHDRAW_FAILED>]>, undefined>;
102
102
  readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
103
103
  readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
104
104
  readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
@@ -109,7 +109,7 @@ declare const ListTransfersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjec
109
109
  reversed: boolean;
110
110
  timestampMin?: bigint | undefined;
111
111
  timestampMax?: bigint | undefined;
112
- transferCode?: TransferCode.DEPOSIT | TransferCode.WITHDRAW | TransferCode.MAKER_FEE | TransferCode.TAKER_FEE | TransferCode.INTERNAL_TRANSFER | TransferCode.TRADE_BASE | TransferCode.TRADE_QUOTE | TransferCode.REBATE | TransferCode.FUNDING_TO_TRADING | TransferCode.TRADING_TO_FUNDING | TransferCode.TRADING_WITHDRAW_RESERVE | TransferCode.FUNDING_USER_TRANSFER | TransferCode.TRADING_WITHDRAW_REQUEST_FEE | TransferCode.TRADING_WITHDRAW_FEE_LEG | TransferCode.QUICKSWAP_POLYESTER_FEE | TransferCode.QUICKSWAP_BROKER_FEE | TransferCode.QUICKSWAP_AFFILIATE_FEE | TransferCode.FEE_SWEEP | TransferCode.FEE_REFILL | TransferCode.SYSTEM_ADJUSTMENT | undefined;
112
+ transferCode?: TransferCode.DEPOSIT | TransferCode.WITHDRAW | TransferCode.MAKER_FEE | TransferCode.TAKER_FEE | TransferCode.INTERNAL_TRANSFER | TransferCode.TRADE_BASE | TransferCode.TRADE_QUOTE | TransferCode.REBATE | TransferCode.FUNDING_TO_TRADING | TransferCode.TRADING_TO_FUNDING | TransferCode.TRADING_WITHDRAW_RESERVE | TransferCode.FUNDING_USER_TRANSFER | TransferCode.TRADING_WITHDRAW_REQUEST_FEE | TransferCode.TRADING_WITHDRAW_FEE_LEG | TransferCode.QUICKSWAP_POLYESTER_FEE | TransferCode.QUICKSWAP_BROKER_FEE | TransferCode.QUICKSWAP_AFFILIATE_FEE | TransferCode.FEE_SWEEP | TransferCode.FEE_REFILL | TransferCode.SYSTEM_ADJUSTMENT | TransferCode.WITHDRAW_FAILED | undefined;
113
113
  pageToken: string;
114
114
  account?: "active" | "main" | {
115
115
  subaccountId: string;
@@ -121,7 +121,7 @@ declare const ListTransfersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjec
121
121
  ledger: number;
122
122
  limit?: number | undefined;
123
123
  reversed: boolean;
124
- transferCode?: TransferCode.DEPOSIT | TransferCode.WITHDRAW | TransferCode.MAKER_FEE | TransferCode.TAKER_FEE | TransferCode.INTERNAL_TRANSFER | TransferCode.TRADE_BASE | TransferCode.TRADE_QUOTE | TransferCode.REBATE | TransferCode.FUNDING_TO_TRADING | TransferCode.TRADING_TO_FUNDING | TransferCode.TRADING_WITHDRAW_RESERVE | TransferCode.FUNDING_USER_TRANSFER | TransferCode.TRADING_WITHDRAW_REQUEST_FEE | TransferCode.TRADING_WITHDRAW_FEE_LEG | TransferCode.QUICKSWAP_POLYESTER_FEE | TransferCode.QUICKSWAP_BROKER_FEE | TransferCode.QUICKSWAP_AFFILIATE_FEE | TransferCode.FEE_SWEEP | TransferCode.FEE_REFILL | TransferCode.SYSTEM_ADJUSTMENT | undefined;
124
+ transferCode?: TransferCode.DEPOSIT | TransferCode.WITHDRAW | TransferCode.MAKER_FEE | TransferCode.TAKER_FEE | TransferCode.INTERNAL_TRANSFER | TransferCode.TRADE_BASE | TransferCode.TRADE_QUOTE | TransferCode.REBATE | TransferCode.FUNDING_TO_TRADING | TransferCode.TRADING_TO_FUNDING | TransferCode.TRADING_WITHDRAW_RESERVE | TransferCode.FUNDING_USER_TRANSFER | TransferCode.TRADING_WITHDRAW_REQUEST_FEE | TransferCode.TRADING_WITHDRAW_FEE_LEG | TransferCode.QUICKSWAP_POLYESTER_FEE | TransferCode.QUICKSWAP_BROKER_FEE | TransferCode.QUICKSWAP_AFFILIATE_FEE | TransferCode.FEE_SWEEP | TransferCode.FEE_REFILL | TransferCode.SYSTEM_ADJUSTMENT | TransferCode.WITHDRAW_FAILED | undefined;
125
125
  pageToken: string;
126
126
  }>]>;
127
127
  type ListTransfersInput = v.InferInput<typeof ListTransfersInputSchema>;
@@ -1113,7 +1113,7 @@ type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInpu
1113
1113
  declare const ListTriggersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
1114
1114
  readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
1115
1115
  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>;
1116
- readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "canceled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("completed" | "failed" | "canceled" | "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)[]>]>;
1116
+ readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "canceled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
1117
1117
  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>]>;
1118
1118
  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>;
1119
1119
  readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
@@ -1334,7 +1334,7 @@ declare const ListTriggerEventsInputSchema: v.SchemaWithPipe<readonly [v.StrictO
1334
1334
  readonly triggerId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
1335
1335
  }, undefined>, v.TransformAction<{
1336
1336
  limit?: number | undefined;
1337
- eventType?: "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused" | undefined;
1337
+ eventType?: "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused" | undefined;
1338
1338
  pageToken: string;
1339
1339
  account?: "active" | "main" | {
1340
1340
  subaccountId: string;
@@ -29,62 +29,62 @@ declare const CreateTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSche
29
29
  type CreateTriggerResult = v.InferOutput<typeof CreateTriggerResultSchema>;
30
30
  declare const CancelTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
31
31
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
32
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
32
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running">]>;
33
33
  readonly tsNs: v.BigintSchema<undefined>;
34
34
  }, undefined>, v.TransformAction<{
35
35
  triggerId: string;
36
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
36
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
37
37
  tsNs: bigint;
38
38
  }, {
39
39
  ts: number;
40
40
  tsNs: string;
41
41
  triggerId: string;
42
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
42
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
43
43
  }>]>;
44
44
  type CancelTriggerResult = v.InferOutput<typeof CancelTriggerResultSchema>;
45
45
  declare const ModifyTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
46
46
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
47
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
47
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running">]>;
48
48
  readonly tsNs: v.BigintSchema<undefined>;
49
49
  }, undefined>, v.TransformAction<{
50
50
  triggerId: string;
51
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
51
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
52
52
  tsNs: bigint;
53
53
  }, {
54
54
  ts: number;
55
55
  tsNs: string;
56
56
  triggerId: string;
57
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
57
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
58
58
  }>]>;
59
59
  type ModifyTriggerResult = v.InferOutput<typeof ModifyTriggerResultSchema>;
60
60
  declare const PauseTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
61
61
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
62
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
62
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running">]>;
63
63
  readonly tsNs: v.BigintSchema<undefined>;
64
64
  }, undefined>, v.TransformAction<{
65
65
  triggerId: string;
66
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
66
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
67
67
  tsNs: bigint;
68
68
  }, {
69
69
  ts: number;
70
70
  tsNs: string;
71
71
  triggerId: string;
72
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
72
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
73
73
  }>]>;
74
74
  type PauseTriggerResult = v.InferOutput<typeof PauseTriggerResultSchema>;
75
75
  declare const ResumeTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
76
76
  readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
77
- readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused">]>;
77
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running">]>;
78
78
  readonly tsNs: v.BigintSchema<undefined>;
79
79
  }, undefined>, v.TransformAction<{
80
80
  triggerId: string;
81
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
81
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
82
82
  tsNs: bigint;
83
83
  }, {
84
84
  ts: number;
85
85
  tsNs: string;
86
86
  triggerId: string;
87
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
87
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
88
88
  }>]>;
89
89
  type ResumeTriggerResult = v.InferOutput<typeof ResumeTriggerResultSchema>;
90
90
  type StopDetailsOutput = {
@@ -619,14 +619,14 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
619
619
  triggerId: string;
620
620
  subaccountId: string;
621
621
  symbolId: number;
622
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
622
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
623
623
  parentOrderId: string | undefined;
624
624
  qty: string;
625
625
  feeAsset: "unspecified" | "quote" | "base";
626
626
  selfTradePreventionMode: "unspecified" | "expire_taker" | "expire_maker" | "expire_both";
627
627
  configuration: {
628
628
  type: "stop_loss" | "take_profit";
629
- side: "unspecified" | "buy" | "sell";
629
+ side: "buy" | "sell" | "unspecified";
630
630
  triggerPrice: string;
631
631
  triggerPriceSource: "unspecified" | "last" | "index" | "mark";
632
632
  execution: {
@@ -679,7 +679,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
679
679
  readonly postOnly?: undefined;
680
680
  } | {
681
681
  type: "trailing_stop";
682
- side: "unspecified" | "buy" | "sell";
682
+ side: "buy" | "sell" | "unspecified";
683
683
  trailingDistance: {
684
684
  kind: "distance";
685
685
  distance: string;
@@ -719,7 +719,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
719
719
  readonly postOnly?: undefined;
720
720
  } | {
721
721
  type: "twap";
722
- side: "unspecified" | "buy" | "sell";
722
+ side: "buy" | "sell" | "unspecified";
723
723
  durationMs: number;
724
724
  sliceIntervalMs: number;
725
725
  execution: {
@@ -759,7 +759,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
759
759
  readonly postOnly?: undefined;
760
760
  } | {
761
761
  type: "ladder";
762
- side: "unspecified" | "buy" | "sell";
762
+ side: "buy" | "sell" | "unspecified";
763
763
  priceMin: string;
764
764
  priceMax: string;
765
765
  levels: number;
@@ -803,14 +803,14 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
803
803
  triggerId: string;
804
804
  subaccountId: string;
805
805
  symbolId: number;
806
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
806
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
807
807
  parentOrderId: string | undefined;
808
808
  qty: string;
809
809
  feeAsset: "unspecified" | "quote" | "base";
810
810
  selfTradePreventionMode: "unspecified" | "expire_taker" | "expire_maker" | "expire_both";
811
811
  configuration: {
812
812
  type: "stop_loss" | "take_profit";
813
- side: "unspecified" | "buy" | "sell";
813
+ side: "buy" | "sell" | "unspecified";
814
814
  triggerPrice: string;
815
815
  triggerPriceSource: "unspecified" | "last" | "index" | "mark";
816
816
  execution: {
@@ -863,7 +863,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
863
863
  readonly postOnly?: undefined;
864
864
  } | {
865
865
  type: "trailing_stop";
866
- side: "unspecified" | "buy" | "sell";
866
+ side: "buy" | "sell" | "unspecified";
867
867
  trailingDistance: {
868
868
  kind: "distance";
869
869
  distance: string;
@@ -903,7 +903,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
903
903
  readonly postOnly?: undefined;
904
904
  } | {
905
905
  type: "twap";
906
- side: "unspecified" | "buy" | "sell";
906
+ side: "buy" | "sell" | "unspecified";
907
907
  durationMs: number;
908
908
  sliceIntervalMs: number;
909
909
  execution: {
@@ -943,7 +943,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
943
943
  readonly postOnly?: undefined;
944
944
  } | {
945
945
  type: "ladder";
946
- side: "unspecified" | "buy" | "sell";
946
+ side: "buy" | "sell" | "unspecified";
947
947
  priceMin: string;
948
948
  priceMax: string;
949
949
  levels: number;
@@ -987,14 +987,14 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
987
987
  triggerId: string;
988
988
  subaccountId: string;
989
989
  symbolId: number;
990
- status: "unspecified" | "completed" | "failed" | "canceled" | "created" | "armed" | "running" | "paused";
990
+ status: "unspecified" | "failed" | "canceled" | "completed" | "paused" | "created" | "armed" | "running";
991
991
  parentOrderId: string | undefined;
992
992
  qty: string;
993
993
  feeAsset: "unspecified" | "quote" | "base";
994
994
  selfTradePreventionMode: "unspecified" | "expire_taker" | "expire_maker" | "expire_both";
995
995
  configuration: {
996
996
  type: "stop_loss" | "take_profit";
997
- side: "unspecified" | "buy" | "sell";
997
+ side: "buy" | "sell" | "unspecified";
998
998
  triggerPrice: string;
999
999
  triggerPriceSource: "unspecified" | "last" | "index" | "mark";
1000
1000
  execution: {
@@ -1047,7 +1047,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
1047
1047
  readonly postOnly?: undefined;
1048
1048
  } | {
1049
1049
  type: "trailing_stop";
1050
- side: "unspecified" | "buy" | "sell";
1050
+ side: "buy" | "sell" | "unspecified";
1051
1051
  trailingDistance: {
1052
1052
  kind: "distance";
1053
1053
  distance: string;
@@ -1087,7 +1087,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
1087
1087
  readonly postOnly?: undefined;
1088
1088
  } | {
1089
1089
  type: "twap";
1090
- side: "unspecified" | "buy" | "sell";
1090
+ side: "buy" | "sell" | "unspecified";
1091
1091
  durationMs: number;
1092
1092
  sliceIntervalMs: number;
1093
1093
  execution: {
@@ -1127,7 +1127,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
1127
1127
  readonly postOnly?: undefined;
1128
1128
  } | {
1129
1129
  type: "ladder";
1130
- side: "unspecified" | "buy" | "sell";
1130
+ side: "buy" | "sell" | "unspecified";
1131
1131
  priceMin: string;
1132
1132
  priceMax: string;
1133
1133
  levels: number;
@@ -1217,7 +1217,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1217
1217
  subaccountId: string;
1218
1218
  symbolId: number;
1219
1219
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1220
- eventType: "unspecified" | "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused";
1220
+ eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused";
1221
1221
  ts: number;
1222
1222
  tsNs: string;
1223
1223
  childSeq: number;
@@ -1232,7 +1232,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1232
1232
  subaccountId: string;
1233
1233
  symbolId: number;
1234
1234
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1235
- eventType: "unspecified" | "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused";
1235
+ eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused";
1236
1236
  ts: number;
1237
1237
  tsNs: string;
1238
1238
  childSeq: number;
@@ -1247,7 +1247,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
1247
1247
  subaccountId: string;
1248
1248
  symbolId: number;
1249
1249
  triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
1250
- eventType: "unspecified" | "failed" | "canceled" | "updated" | "armed" | "fired" | "activated" | "fire_refused";
1250
+ eventType: "unspecified" | "failed" | "canceled" | "armed" | "updated" | "fired" | "activated" | "fire_refused";
1251
1251
  ts: number;
1252
1252
  tsNs: string;
1253
1253
  childSeq: number;
@@ -12,6 +12,11 @@ interface AssetConfig {
12
12
  quantityScale: number;
13
13
  /** Scale for public candle and market-overview base volume. Absent on older snapshots. */
14
14
  marketDataVolumeScale?: number;
15
+ /**
16
+ * Whether balances of this asset count toward total equity; `false` still reports them but
17
+ * values them at nothing. Absent means unknown (older servers or snapshots), never `false`.
18
+ */
19
+ includedInEquity?: boolean;
15
20
  }
16
21
  interface PairConfig {
17
22
  symbolId: number;
@@ -1 +1 @@
1
- {"version":3,"file":"catalog-config.d.ts","names":[],"sources":["../../src/shared/catalog-config.ts"],"mappings":";KAAY;EACR;;KAGQ;cASC;UASI;EACb;EACA;EACA;EACA;EACA;;EAEA;;UAGa;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;;EAEA;EACA;EACA;EACA,QAAQ;;UAGK;EACb,QAAQ;EACR,OAAO;;EAEP;EACA;;;;;;;KAQQ;UASK;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA,kBAAkB;;EAElB;;EAEA;;UAGa;EACb;EACA;;UAGa;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb,QAAQ;;UAGK;EACb;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV;;UAGa;EACb;EACA;EACA;EACA;EACA;;UAGa;EACb,QAAQ;EACR,QAAQ;EACR,WAAW;EACX"}
1
+ {"version":3,"file":"catalog-config.d.ts","names":[],"sources":["../../src/shared/catalog-config.ts"],"mappings":";KAAY;EACR;;KAGQ;cASC;UASI;EACb;EACA;EACA;EACA;EACA;;EAEA;;;;;EAKA;;UAGa;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;;EAEA;EACA;EACA;EACA,QAAQ;;UAGK;EACb,QAAQ;EACR,OAAO;;EAEP;EACA;;;;;;;KAQQ;UASK;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA,kBAAkB;;EAElB;;EAEA;;UAGa;EACb;EACA;;UAGa;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb,QAAQ;;UAGK;EACb;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV;;UAGa;EACb;EACA;EACA;EACA;EACA;;UAGa;EACb,QAAQ;EACR,QAAQ;EACR,WAAW;EACX"}