@polyester/sdk 0.4.0 → 0.4.1

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 (240) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/_virtual/_rolldown/runtime.js +1 -15
  3. package/dist/catalogs/snapshot-validation.js +63 -63
  4. package/dist/catalogs/snapshot-validation.js.map +1 -1
  5. package/dist/services/accounts/accounts.js +1 -1
  6. package/dist/services/accounts/accounts.js.map +1 -1
  7. package/dist/services/accounts/accounts.schemas.d.ts +13 -13
  8. package/dist/services/accounts/accounts.schemas.d.ts.map +1 -1
  9. package/dist/services/accounts/accounts.schemas.js +11 -11
  10. package/dist/services/accounts/accounts.schemas.js.map +1 -1
  11. package/dist/services/address-book/address-book.js.map +1 -1
  12. package/dist/services/address-book/address-book.schemas.d.ts +751 -751
  13. package/dist/services/address-book/address-book.schemas.d.ts.map +1 -1
  14. package/dist/services/address-book/address-book.schemas.js +160 -159
  15. package/dist/services/address-book/address-book.schemas.js.map +1 -1
  16. package/dist/services/api-keys/api-keys.d.ts +6 -6
  17. package/dist/services/api-keys/api-keys.d.ts.map +1 -1
  18. package/dist/services/api-keys/api-keys.js.map +1 -1
  19. package/dist/services/api-keys/api-keys.schemas.d.ts +62 -62
  20. package/dist/services/api-keys/api-keys.schemas.d.ts.map +1 -1
  21. package/dist/services/api-keys/api-keys.schemas.js +34 -34
  22. package/dist/services/api-keys/api-keys.schemas.js.map +1 -1
  23. package/dist/services/auth/auth.d.ts +39 -39
  24. package/dist/services/auth/auth.d.ts.map +1 -1
  25. package/dist/services/auth/auth.js +19 -18
  26. package/dist/services/auth/auth.js.map +1 -1
  27. package/dist/services/auth/profile/profile.d.ts +2 -2
  28. package/dist/services/auth/profile/profile.d.ts.map +1 -1
  29. package/dist/services/auth/profile/profile.js +3 -2
  30. package/dist/services/auth/profile/profile.js.map +1 -1
  31. package/dist/services/auth/profile/profile.schemas.d.ts +41 -41
  32. package/dist/services/auth/profile/profile.schemas.d.ts.map +1 -1
  33. package/dist/services/auth/profile/profile.schemas.js +27 -27
  34. package/dist/services/auth/profile/profile.schemas.js.map +1 -1
  35. package/dist/services/auth/session.schemas.js +17 -17
  36. package/dist/services/auth/session.schemas.js.map +1 -1
  37. package/dist/services/balances/balances.d.ts.map +1 -1
  38. package/dist/services/balances/balances.js +3 -2
  39. package/dist/services/balances/balances.js.map +1 -1
  40. package/dist/services/balances/balances.schemas.d.ts +95 -95
  41. package/dist/services/balances/balances.schemas.d.ts.map +1 -1
  42. package/dist/services/balances/balances.schemas.js +61 -61
  43. package/dist/services/balances/balances.schemas.js.map +1 -1
  44. package/dist/services/candles/candles.d.ts.map +1 -1
  45. package/dist/services/candles/candles.js +5 -4
  46. package/dist/services/candles/candles.js.map +1 -1
  47. package/dist/services/candles/candles.schemas.d.ts +64 -64
  48. package/dist/services/candles/candles.schemas.d.ts.map +1 -1
  49. package/dist/services/candles/candles.schemas.js +47 -47
  50. package/dist/services/candles/candles.schemas.js.map +1 -1
  51. package/dist/services/chain-analytics/chain-analytics.js.map +1 -1
  52. package/dist/services/chain-analytics/chain-analytics.schemas.d.ts +68 -68
  53. package/dist/services/chain-analytics/chain-analytics.schemas.d.ts.map +1 -1
  54. package/dist/services/chain-analytics/chain-analytics.schemas.js +29 -29
  55. package/dist/services/chain-analytics/chain-analytics.schemas.js.map +1 -1
  56. package/dist/services/deposit/deposit.js.map +1 -1
  57. package/dist/services/deposit/deposit.schemas.d.ts +17 -17
  58. package/dist/services/deposit/deposit.schemas.d.ts.map +1 -1
  59. package/dist/services/deposit/deposit.schemas.js +11 -11
  60. package/dist/services/deposit/deposit.schemas.js.map +1 -1
  61. package/dist/services/guard-signer/guard-signer.js.map +1 -1
  62. package/dist/services/guard-signer/guard-signer.schemas.d.ts +75 -75
  63. package/dist/services/guard-signer/guard-signer.schemas.d.ts.map +1 -1
  64. package/dist/services/guard-signer/guard-signer.schemas.js +42 -42
  65. package/dist/services/guard-signer/guard-signer.schemas.js.map +1 -1
  66. package/dist/services/heatmap/heatmap.d.ts.map +1 -1
  67. package/dist/services/heatmap/heatmap.js +5 -4
  68. package/dist/services/heatmap/heatmap.js.map +1 -1
  69. package/dist/services/heatmap/heatmap.schemas.d.ts +138 -138
  70. package/dist/services/heatmap/heatmap.schemas.d.ts.map +1 -1
  71. package/dist/services/heatmap/heatmap.schemas.js +47 -47
  72. package/dist/services/heatmap/heatmap.schemas.js.map +1 -1
  73. package/dist/services/internal-transfers/internal-transfers.js.map +1 -1
  74. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +53 -53
  75. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts.map +1 -1
  76. package/dist/services/internal-transfers/internal-transfers.schemas.js +27 -27
  77. package/dist/services/internal-transfers/internal-transfers.schemas.js.map +1 -1
  78. package/dist/services/lifecycle/lifecycle.d.ts.map +1 -1
  79. package/dist/services/lifecycle/lifecycle.js +3 -2
  80. package/dist/services/lifecycle/lifecycle.js.map +1 -1
  81. package/dist/services/lifecycle/lifecycle.schemas.d.ts +614 -614
  82. package/dist/services/lifecycle/lifecycle.schemas.d.ts.map +1 -1
  83. package/dist/services/lifecycle/lifecycle.schemas.js +146 -146
  84. package/dist/services/lifecycle/lifecycle.schemas.js.map +1 -1
  85. package/dist/services/market-data/market-data.d.ts.map +1 -1
  86. package/dist/services/market-data/market-data.js +4 -3
  87. package/dist/services/market-data/market-data.js.map +1 -1
  88. package/dist/services/market-data/market-data.schemas.d.ts +19 -19
  89. package/dist/services/market-data/market-data.schemas.d.ts.map +1 -1
  90. package/dist/services/market-data/market-data.schemas.js +50 -50
  91. package/dist/services/market-data/market-data.schemas.js.map +1 -1
  92. package/dist/services/market-overview/market-overview.d.ts.map +1 -1
  93. package/dist/services/market-overview/market-overview.js +3 -2
  94. package/dist/services/market-overview/market-overview.js.map +1 -1
  95. package/dist/services/market-overview/market-overview.schemas.d.ts +37 -37
  96. package/dist/services/market-overview/market-overview.schemas.d.ts.map +1 -1
  97. package/dist/services/market-overview/market-overview.schemas.js +33 -33
  98. package/dist/services/market-overview/market-overview.schemas.js.map +1 -1
  99. package/dist/services/mfa/mfa.js +1 -1
  100. package/dist/services/mfa/mfa.js.map +1 -1
  101. package/dist/services/mfa/mfa.schemas.d.ts +206 -206
  102. package/dist/services/mfa/mfa.schemas.d.ts.map +1 -1
  103. package/dist/services/mfa/mfa.schemas.js +83 -83
  104. package/dist/services/mfa/mfa.schemas.js.map +1 -1
  105. package/dist/services/orderbook/orderbook.d.ts +2 -2
  106. package/dist/services/orderbook/orderbook.d.ts.map +1 -1
  107. package/dist/services/orderbook/orderbook.js +3 -2
  108. package/dist/services/orderbook/orderbook.js.map +1 -1
  109. package/dist/services/orderbook/orderbook.schemas.d.ts +23 -23
  110. package/dist/services/orderbook/orderbook.schemas.d.ts.map +1 -1
  111. package/dist/services/orderbook/orderbook.schemas.js +15 -15
  112. package/dist/services/orderbook/orderbook.schemas.js.map +1 -1
  113. package/dist/services/orders/order-errors.schemas.d.ts +18 -18
  114. package/dist/services/orders/order-errors.schemas.d.ts.map +1 -1
  115. package/dist/services/orders/order-errors.schemas.js +8 -8
  116. package/dist/services/orders/order-errors.schemas.js.map +1 -1
  117. package/dist/services/orders/orders-batch.schemas.d.ts +504 -504
  118. package/dist/services/orders/orders-batch.schemas.d.ts.map +1 -1
  119. package/dist/services/orders/orders-batch.schemas.js +117 -117
  120. package/dist/services/orders/orders-batch.schemas.js.map +1 -1
  121. package/dist/services/orders/orders-identifiers.schemas.js +5 -5
  122. package/dist/services/orders/orders-identifiers.schemas.js.map +1 -1
  123. package/dist/services/orders/orders-input.schemas.d.ts +648 -648
  124. package/dist/services/orders/orders-input.schemas.d.ts.map +1 -1
  125. package/dist/services/orders/orders-input.schemas.js +95 -95
  126. package/dist/services/orders/orders-input.schemas.js.map +1 -1
  127. package/dist/services/orders/orders-modify.schemas.d.ts +351 -351
  128. package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
  129. package/dist/services/orders/orders-modify.schemas.js +44 -44
  130. package/dist/services/orders/orders-modify.schemas.js.map +1 -1
  131. package/dist/services/orders/orders-output.schemas.d.ts +183 -183
  132. package/dist/services/orders/orders-output.schemas.d.ts.map +1 -1
  133. package/dist/services/orders/orders-output.schemas.js +49 -49
  134. package/dist/services/orders/orders-output.schemas.js.map +1 -1
  135. package/dist/services/orders/orders-risk.schemas.d.ts +226 -226
  136. package/dist/services/orders/orders-risk.schemas.d.ts.map +1 -1
  137. package/dist/services/orders/orders-risk.schemas.js +69 -69
  138. package/dist/services/orders/orders-risk.schemas.js.map +1 -1
  139. package/dist/services/orders/orders.d.ts +6 -6
  140. package/dist/services/orders/orders.d.ts.map +1 -1
  141. package/dist/services/orders/orders.js +4 -3
  142. package/dist/services/orders/orders.js.map +1 -1
  143. package/dist/services/policies/api-key-policies/api-key-policies.d.ts +6 -6
  144. package/dist/services/policies/api-key-policies/api-key-policies.d.ts.map +1 -1
  145. package/dist/services/policies/api-key-policies/api-key-policies.js.map +1 -1
  146. package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +105 -105
  147. package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts.map +1 -1
  148. package/dist/services/policies/api-key-policies/api-key-policies.schemas.js +49 -49
  149. package/dist/services/policies/api-key-policies/api-key-policies.schemas.js.map +1 -1
  150. package/dist/services/policies/shared.d.ts +5 -5
  151. package/dist/services/policies/shared.d.ts.map +1 -1
  152. package/dist/services/policies/shared.js +10 -10
  153. package/dist/services/policies/shared.js.map +1 -1
  154. package/dist/services/policies/subaccount-policies/subaccount-policies.d.ts +6 -6
  155. package/dist/services/policies/subaccount-policies/subaccount-policies.d.ts.map +1 -1
  156. package/dist/services/policies/subaccount-policies/subaccount-policies.js +3 -2
  157. package/dist/services/policies/subaccount-policies/subaccount-policies.js.map +1 -1
  158. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +124 -124
  159. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts.map +1 -1
  160. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js +75 -75
  161. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js.map +1 -1
  162. package/dist/services/shared.js +11 -11
  163. package/dist/services/shared.js.map +1 -1
  164. package/dist/services/social-verification/social-verification.d.ts +3 -3
  165. package/dist/services/social-verification/social-verification.d.ts.map +1 -1
  166. package/dist/services/social-verification/social-verification.js.map +1 -1
  167. package/dist/services/social-verification/social-verification.schemas.d.ts +54 -54
  168. package/dist/services/social-verification/social-verification.schemas.d.ts.map +1 -1
  169. package/dist/services/social-verification/social-verification.schemas.js +28 -28
  170. package/dist/services/social-verification/social-verification.schemas.js.map +1 -1
  171. package/dist/services/subaccounts/subaccounts.d.ts +14 -14
  172. package/dist/services/subaccounts/subaccounts.d.ts.map +1 -1
  173. package/dist/services/subaccounts/subaccounts.js +9 -8
  174. package/dist/services/subaccounts/subaccounts.js.map +1 -1
  175. package/dist/services/subaccounts/subaccounts.schemas.d.ts +135 -135
  176. package/dist/services/subaccounts/subaccounts.schemas.d.ts.map +1 -1
  177. package/dist/services/subaccounts/subaccounts.schemas.js +72 -72
  178. package/dist/services/subaccounts/subaccounts.schemas.js.map +1 -1
  179. package/dist/services/trades/trades.d.ts +2 -2
  180. package/dist/services/trades/trades.d.ts.map +1 -1
  181. package/dist/services/trades/trades.js +3 -2
  182. package/dist/services/trades/trades.js.map +1 -1
  183. package/dist/services/trades/trades.schemas.d.ts +31 -31
  184. package/dist/services/trades/trades.schemas.d.ts.map +1 -1
  185. package/dist/services/trades/trades.schemas.js +24 -24
  186. package/dist/services/trades/trades.schemas.js.map +1 -1
  187. package/dist/services/trading-withdraws/trading-withdraws.js +1 -1
  188. package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
  189. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts +45 -45
  190. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts.map +1 -1
  191. package/dist/services/trading-withdraws/trading-withdraws.schemas.js +36 -36
  192. package/dist/services/trading-withdraws/trading-withdraws.schemas.js.map +1 -1
  193. package/dist/services/transfers/transfers.d.ts.map +1 -1
  194. package/dist/services/transfers/transfers.js +3 -2
  195. package/dist/services/transfers/transfers.js.map +1 -1
  196. package/dist/services/transfers/transfers.schemas.d.ts +42 -42
  197. package/dist/services/transfers/transfers.schemas.d.ts.map +1 -1
  198. package/dist/services/transfers/transfers.schemas.js +30 -30
  199. package/dist/services/transfers/transfers.schemas.js.map +1 -1
  200. package/dist/services/triggers/trigger-child-order.schemas.js +23 -23
  201. package/dist/services/triggers/trigger-child-order.schemas.js.map +1 -1
  202. package/dist/services/triggers/trigger-input.schemas.d.ts +226 -226
  203. package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
  204. package/dist/services/triggers/trigger-input.schemas.js +53 -53
  205. package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
  206. package/dist/services/triggers/triggers-output.schemas.d.ts +209 -209
  207. package/dist/services/triggers/triggers-output.schemas.d.ts.map +1 -1
  208. package/dist/services/triggers/triggers-output.schemas.js +152 -152
  209. package/dist/services/triggers/triggers-output.schemas.js.map +1 -1
  210. package/dist/services/triggers/triggers.d.ts.map +1 -1
  211. package/dist/services/triggers/triggers.js +4 -3
  212. package/dist/services/triggers/triggers.js.map +1 -1
  213. package/dist/services/whiteboard/whiteboard.js.map +1 -1
  214. package/dist/services/whiteboard/whiteboard.schemas.d.ts +379 -379
  215. package/dist/services/whiteboard/whiteboard.schemas.d.ts.map +1 -1
  216. package/dist/services/whiteboard/whiteboard.schemas.js +71 -71
  217. package/dist/services/whiteboard/whiteboard.schemas.js.map +1 -1
  218. package/dist/services/zipper/zipper.js.map +1 -1
  219. package/dist/services/zipper/zipper.schemas.d.ts +1 -1
  220. package/dist/services/zipper/zipper.schemas.js +54 -54
  221. package/dist/services/zipper/zipper.schemas.js.map +1 -1
  222. package/dist/shared/account-scope.d.ts +6 -6
  223. package/dist/shared/account-scope.d.ts.map +1 -1
  224. package/dist/shared/account-scope.js +3 -3
  225. package/dist/shared/account-scope.js.map +1 -1
  226. package/dist/shared/connect-error-mapping.js +2 -2
  227. package/dist/shared/connect-error-mapping.js.map +1 -1
  228. package/dist/shared/rate-limit.schemas.d.ts +12 -12
  229. package/dist/shared/rate-limit.schemas.d.ts.map +1 -1
  230. package/dist/shared/rate-limit.schemas.js +7 -7
  231. package/dist/shared/rate-limit.schemas.js.map +1 -1
  232. package/dist/shared/schemas.js +26 -26
  233. package/dist/shared/schemas.js.map +1 -1
  234. package/dist/shared/validation.js +1 -6
  235. package/dist/shared/validation.js.map +1 -1
  236. package/dist/utils/connect-order-errors.js +2 -2
  237. package/dist/utils/connect-order-errors.js.map +1 -1
  238. package/package.json +3 -3
  239. package/dist/shared/validation.d.ts +0 -14
  240. package/dist/shared/validation.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"trades.schemas.js","names":["v"],"sources":["../../../src/services/trades/trades.schemas.ts"],"sourcesContent":["import * as v from \"../../shared/validation.js\";\nimport { tsNsToISO, tsNsToMs } from \"../../utils/time.js\";\nimport { SideSchema } from \"../shared.js\";\nimport { FeeAssetCodec, OrderSideCodec } from \"../orders/orders.codecs.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { optionalUint64DecimalFilterSchema } from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { TradeSideCodec } from \"./trades.codecs.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { E18_SCALE, scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { fromU128 } from \"../../utils/u128.js\";\n\nconst U128Schema = v.object({\n hi: v.bigint(),\n lo: v.bigint(),\n});\n\n/** Parses a generated user-trade fill into the SDK's JSON-safe public shape. */\nexport function createUserTradeSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n orderId: v.bigint(),\n symbolId: v.number(),\n side: v.number(),\n isMaker: v.boolean(),\n feeAsset: v.number(),\n qtyScaled: v.bigint(),\n priceTicks: v.bigint(),\n feeAmountE18: v.optional(U128Schema),\n referralShareAmountE18: v.optional(U128Schema),\n feeIsRebate: v.boolean(),\n tsNs: v.bigint(),\n matchId: v.bigint(),\n }),\n v.transform((t) => {\n const feeAsset = requiredEnumLabel(\n FeeAssetCodec.protoToOutput,\n t.feeAsset,\n \"UserTradeSchema\",\n \"fee asset\",\n );\n return {\n orderId: formatId(t.orderId),\n symbolId: t.symbolId,\n sideLabel: requiredEnumLabel(\n OrderSideCodec.protoToOutput,\n t.side,\n \"UserTradeSchema\",\n \"side\",\n ),\n liquidityLabel: t.isMaker ? (\"maker\" as const) : (\"taker\" as const),\n feeAsset,\n qty: scaledToDecimalOutput(t.qtyScaled, scales.baseQty(t.symbolId)),\n price: scaledToDecimalOutput(t.priceTicks, scales.price()),\n fee: scaledToDecimalOutput(fromU128(t.feeAmountE18), E18_SCALE),\n ...(t.referralShareAmountE18 === undefined\n ? {}\n : {\n referralShare: scaledToDecimalOutput(\n fromU128(t.referralShareAmountE18),\n E18_SCALE,\n ),\n }),\n feeIsRebate: t.feeIsRebate,\n tsNs: t.tsNs.toString(),\n tsIso: tsNsToISO(t.tsNs),\n tsMs: tsNsToMs(t.tsNs),\n matchId: t.matchId.toString(),\n };\n }),\n );\n}\n\n/** A JSON-safe authenticated trade fill returned by the SDK. */\nexport type Trade = v.InferOutput<ReturnType<typeof createUserTradeSchema>>;\n\n/** Validates filters accepted by {@link TradesService.list}. */\nexport const GetUserTradesInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n symbolId: v.pipe(\n v.optional(v.pipe(v.string(), v.trim())),\n v.transform((v) => {\n if (!v) return undefined;\n const sid = Number(v);\n return Number.isFinite(sid) && sid > 0 ? sid : undefined;\n }),\n ),\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? TradeSideCodec.inputToProto[v] : undefined)),\n ),\n startTsNs: optionalUint64DecimalFilterSchema(\"startTsNs\"),\n endTsNs: optionalUint64DecimalFilterSchema(\"endTsNs\"),\n limit: v.optional(v.number()),\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Filters accepted by {@link TradesService.list}. */\nexport type GetUserTradesInput = v.InferInput<typeof GetUserTradesInputSchema>;\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,aAAaA,mBAAE,OAAO;CACxB,IAAIA,mBAAE,OAAO;CACb,IAAIA,mBAAE,OAAO;AACjB,CAAC;;AAGD,SAAgB,sBAAsB,QAAmB;CACrD,OAAOA,mBAAE,KACLA,mBAAE,OAAO;EACL,SAASA,mBAAE,OAAO;EAClB,UAAUA,mBAAE,OAAO;EACnB,MAAMA,mBAAE,OAAO;EACf,SAASA,mBAAE,QAAQ;EACnB,UAAUA,mBAAE,OAAO;EACnB,WAAWA,mBAAE,OAAO;EACpB,YAAYA,mBAAE,OAAO;EACrB,cAAcA,mBAAE,SAAS,UAAU;EACnC,wBAAwBA,mBAAE,SAAS,UAAU;EAC7C,aAAaA,mBAAE,QAAQ;EACvB,MAAMA,mBAAE,OAAO;EACf,SAASA,mBAAE,OAAO;CACtB,CAAC,GACDA,mBAAE,WAAW,MAAM;EACf,MAAM,WAAW,kBACb,cAAc,eACd,EAAE,UACF,mBACA,WACJ;EACA,OAAO;GACH,SAAS,SAAS,EAAE,OAAO;GAC3B,UAAU,EAAE;GACZ,WAAW,kBACP,eAAe,eACf,EAAE,MACF,mBACA,MACJ;GACA,gBAAgB,EAAE,UAAW,UAAqB;GAClD;GACA,KAAK,sBAAsB,EAAE,WAAW,OAAO,QAAQ,EAAE,QAAQ,CAAC;GAClE,OAAO,sBAAsB,EAAE,YAAY,OAAO,MAAM,CAAC;GACzD,KAAK,sBAAsB,SAAS,EAAE,YAAY,GAAA,EAAY;GAC9D,GAAI,EAAE,2BAA2B,KAAA,IAC3B,CAAC,IACD,EACI,eAAe,sBACX,SAAS,EAAE,sBAAsB,GAAA,EAErC,EACJ;GACN,aAAa,EAAE;GACf,MAAM,EAAE,KAAK,SAAS;GACtB,OAAO,UAAU,EAAE,IAAI;GACvB,MAAM,SAAS,EAAE,IAAI;GACrB,SAAS,EAAE,QAAQ,SAAS;EAChC;CACJ,CAAC,CACL;AACJ;;AAMA,MAAa,2BAA2BA,mBAAE,KACtCA,mBAAE,aAAa;CACX,GAAG;CACH,UAAUA,mBAAE,KACRA,mBAAE,SAASA,mBAAE,KAAKA,mBAAE,OAAO,GAAGA,mBAAE,KAAK,CAAC,CAAC,GACvCA,mBAAE,WAAW,MAAM;EACf,IAAI,CAAC,GAAG,OAAO,KAAA;EACf,MAAM,MAAM,OAAO,CAAC;EACpB,OAAO,OAAO,SAAS,GAAG,KAAK,MAAM,IAAI,MAAM,KAAA;CACnD,CAAC,CACL;CACA,MAAMA,mBAAE,KACJA,mBAAE,SAAS,UAAU,GACrBA,mBAAE,WAAW,MAAO,IAAI,eAAe,aAAa,KAAK,KAAA,CAAU,CACvE;CACA,WAAW,kCAAkC,WAAW;CACxD,SAAS,kCAAkC,SAAS;CACpD,OAAOA,mBAAE,SAASA,mBAAE,OAAO,CAAC;CAC5B,WAAWA,mBAAE,SAASA,mBAAE,KAAKA,mBAAE,OAAO,GAAGA,mBAAE,KAAK,CAAC,CAAC;AACtD,CAAC,GACDA,mBAAE,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;AACpD,EAAE,CACN"}
1
+ {"version":3,"file":"trades.schemas.js","names":[],"sources":["../../../src/services/trades/trades.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { tsNsToISO, tsNsToMs } from \"../../utils/time.js\";\nimport { SideSchema } from \"../shared.js\";\nimport { FeeAssetCodec, OrderSideCodec } from \"../orders/orders.codecs.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { optionalUint64DecimalFilterSchema } from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { TradeSideCodec } from \"./trades.codecs.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { E18_SCALE, scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { fromU128 } from \"../../utils/u128.js\";\n\nconst U128Schema = v.object({\n hi: v.bigint(),\n lo: v.bigint(),\n});\n\n/** Parses a generated user-trade fill into the SDK's JSON-safe public shape. */\nexport function createUserTradeSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n orderId: v.bigint(),\n symbolId: v.number(),\n side: v.number(),\n isMaker: v.boolean(),\n feeAsset: v.number(),\n qtyScaled: v.bigint(),\n priceTicks: v.bigint(),\n feeAmountE18: v.optional(U128Schema),\n referralShareAmountE18: v.optional(U128Schema),\n feeIsRebate: v.boolean(),\n tsNs: v.bigint(),\n matchId: v.bigint(),\n }),\n v.transform((t) => {\n const feeAsset = requiredEnumLabel(\n FeeAssetCodec.protoToOutput,\n t.feeAsset,\n \"UserTradeSchema\",\n \"fee asset\",\n );\n return {\n orderId: formatId(t.orderId),\n symbolId: t.symbolId,\n sideLabel: requiredEnumLabel(\n OrderSideCodec.protoToOutput,\n t.side,\n \"UserTradeSchema\",\n \"side\",\n ),\n liquidityLabel: t.isMaker ? (\"maker\" as const) : (\"taker\" as const),\n feeAsset,\n qty: scaledToDecimalOutput(t.qtyScaled, scales.baseQty(t.symbolId)),\n price: scaledToDecimalOutput(t.priceTicks, scales.price()),\n fee: scaledToDecimalOutput(fromU128(t.feeAmountE18), E18_SCALE),\n ...(t.referralShareAmountE18 === undefined\n ? {}\n : {\n referralShare: scaledToDecimalOutput(\n fromU128(t.referralShareAmountE18),\n E18_SCALE,\n ),\n }),\n feeIsRebate: t.feeIsRebate,\n tsNs: t.tsNs.toString(),\n tsIso: tsNsToISO(t.tsNs),\n tsMs: tsNsToMs(t.tsNs),\n matchId: t.matchId.toString(),\n };\n }),\n );\n}\n\n/** A JSON-safe authenticated trade fill returned by the SDK. */\nexport type Trade = v.InferOutput<ReturnType<typeof createUserTradeSchema>>;\n\n/** Validates filters accepted by {@link TradesService.list}. */\nexport const GetUserTradesInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n symbolId: v.pipe(\n v.optional(v.pipe(v.string(), v.trim())),\n v.transform((v) => {\n if (!v) return undefined;\n const sid = Number(v);\n return Number.isFinite(sid) && sid > 0 ? sid : undefined;\n }),\n ),\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? TradeSideCodec.inputToProto[v] : undefined)),\n ),\n startTsNs: optionalUint64DecimalFilterSchema(\"startTsNs\"),\n endTsNs: optionalUint64DecimalFilterSchema(\"endTsNs\"),\n limit: v.optional(v.number()),\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\n/** Filters accepted by {@link TradesService.list}. */\nexport type GetUserTradesInput = v.InferInput<typeof GetUserTradesInputSchema>;\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,aAAa,EAAE,OAAO;CACxB,IAAI,EAAE,OAAO;CACb,IAAI,EAAE,OAAO;AACjB,CAAC;;AAGD,SAAgB,sBAAsB,QAAmB;CACrD,OAAO,EAAE,KACL,EAAE,OAAO;EACL,SAAS,EAAE,OAAO;EAClB,UAAU,EAAE,OAAO;EACnB,MAAM,EAAE,OAAO;EACf,SAAS,EAAE,QAAQ;EACnB,UAAU,EAAE,OAAO;EACnB,WAAW,EAAE,OAAO;EACpB,YAAY,EAAE,OAAO;EACrB,cAAc,EAAE,SAAS,UAAU;EACnC,wBAAwB,EAAE,SAAS,UAAU;EAC7C,aAAa,EAAE,QAAQ;EACvB,MAAM,EAAE,OAAO;EACf,SAAS,EAAE,OAAO;CACtB,CAAC,GACD,EAAE,WAAW,MAAM;EACf,MAAM,WAAW,kBACb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E,WAAW,EAAE,SAAS,GAAG,aAAa;CACpC,GAAG;CACH,cAAc,2BAA2B,OAAO;AACpD,EAAE,CACN"}
@@ -1,7 +1,7 @@
1
1
  import { ValidationError } from "../../shared/errors.js";
2
- import { parse } from "../../shared/validation.js";
3
2
  import { idToBigInt } from "../../utils/base58-id.js";
4
3
  import { checksumEvmAddress, evmHexToBytes, evmUtf8ToBytes, keccak256Hex } from "../../utils/evm.js";
4
+ import { parse } from "../../shared/validation.js";
5
5
  import { toConnectCallOptions } from "../../shared/request-options.js";
6
6
  import { removeUndefined } from "../../utils/remove-undefined.js";
7
7
  import { resolveAccountScopedInput } from "../subaccount-resolver.js";
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","v.parse","#prepareWithdraw"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ValidationError } from \"../../shared/errors.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport {\n checksumEvmAddress,\n evmHexToBytes,\n evmUtf8ToBytes,\n keccak256Hex,\n} 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 * as v from \"../../shared/validation.js\";\nimport {\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\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\";\n\nexport type TradingWithdrawWalletTypedData = ReturnType<typeof buildTradingWithdrawWalletTypedData>;\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n signTypedData: (typedData: TradingWithdrawWalletTypedData) => 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 /**\n * Submits the exact payload and signature produced during preparation.\n * Repeated calls only change transport options such as the step-up token.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction fromU128(value: TradingWithdrawIntentPayloadRequest[\"amountE18\"] | undefined): bigint {\n if (!value) return 0n;\n return (value.hi << 64n) + value.lo;\n}\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\nfunction buildTradingWithdrawWalletTypedData(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n signerWallet: Address;\n accountId: bigint;\n targetAccountId: bigint;\n}) {\n const payload = params.payload;\n const destinationAddress = (payload.destinationAddress ?? \"\").trim();\n const idempotencyKey = payload.idempotencyKey.trim();\n\n return {\n domain: {\n name: \"Polyester Trading Withdraw\",\n version: \"1\",\n chainId: params.signingConfig.chainId,\n verifyingContract: params.signingConfig.tradingGatewayAddress,\n },\n types: {\n WalletTradingWithdraw: [\n { name: \"signerWallet\", type: \"address\" },\n { name: \"actionType\", type: \"uint8\" },\n { name: \"accountId\", type: \"uint64\" },\n { name: \"targetAccountId\", type: \"uint64\" },\n { name: \"assetId\", type: \"uint32\" },\n { name: \"destinationChainId\", type: \"uint64\" },\n { name: \"amountQ\", type: \"uint128\" },\n { name: \"destinationHash\", type: \"bytes32\" },\n { name: \"deadlineTsSec\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint128\" },\n { name: \"idempotencyKeyHash\", type: \"bytes32\" },\n ],\n },\n primaryType: \"WalletTradingWithdraw\",\n message: {\n signerWallet: params.signerWallet,\n actionType: payload.action,\n accountId: params.accountId,\n targetAccountId: params.targetAccountId,\n assetId: payload.assetId,\n destinationChainId: payload.destinationChainId ?? 0n,\n amountQ: fromU128(payload.amountE18),\n destinationHash: keccak256Hex(evmUtf8ToBytes(destinationAddress)),\n deadlineTsSec: payload.deadlineTsSec,\n nonce: fromU128(payload.nonce),\n idempotencyKeyHash: keccak256Hex(evmUtf8ToBytes(idempotencyKey)),\n },\n } as const;\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();\n if (!signerWallet.startsWith(\"0x\")) {\n throw new ValidationError(\"Trading withdraw signer wallet is required.\");\n }\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signTypedData(\n buildTradingWithdrawWalletTypedData({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet: signerWallet as Address,\n accountId,\n targetAccountId: params.targetAccountId,\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-712 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 transport: Transport,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n ) {\n this.#client = createClient(Proto.WithdrawService, transport);\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 = v.parse(ValidateWithdrawDestinationInputSchema, input);\n const response = await this.#client.validateWithdrawDestination(\n request,\n toConnectCallOptions(options),\n );\n return v.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 EIP-712 typed data 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 = v.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 EIP-712 typed data 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 = v.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\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload: validated.payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload: validated.payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n submit: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return v.parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\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 {\n submit: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return v.parse(CreateTradingWithdrawResultSchema, response);\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAwEA,SAAS,SAAS,OAA6E;CAC3F,IAAI,CAAC,OAAO,OAAO;CACnB,QAAQ,MAAM,MAAM,OAAO,MAAM;AACrC;AAEA,SAAS,sCAAsC,QAGpC;CACP,IAAI,OAAO,iBAAiB,KAAA,GAAW,OAAO,OAAO;CACrD,OAAO,WAAW,OAAO,eAAe,iBAAiB;AAC7D;AAEA,eAAe,oCAAoC,QAGT;CACtC,IAAI,CAAC,O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AChC;GACA,OAAOQ,MAAQ,mCAAmC,QAAQ;EAC9D,EACJ;CACJ;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 } from \"../../shared/errors.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport {\n checksumEvmAddress,\n evmHexToBytes,\n evmUtf8ToBytes,\n keccak256Hex,\n} 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 { parse } from \"../../shared/validation.js\";\nimport {\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\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\";\n\nexport type TradingWithdrawWalletTypedData = ReturnType<typeof buildTradingWithdrawWalletTypedData>;\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n signTypedData: (typedData: TradingWithdrawWalletTypedData) => 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 /**\n * Submits the exact payload and signature produced during preparation.\n * Repeated calls only change transport options such as the step-up token.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction fromU128(value: TradingWithdrawIntentPayloadRequest[\"amountE18\"] | undefined): bigint {\n if (!value) return 0n;\n return (value.hi << 64n) + value.lo;\n}\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\nfunction buildTradingWithdrawWalletTypedData(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n signerWallet: Address;\n accountId: bigint;\n targetAccountId: bigint;\n}) {\n const payload = params.payload;\n const destinationAddress = (payload.destinationAddress ?? \"\").trim();\n const idempotencyKey = payload.idempotencyKey.trim();\n\n return {\n domain: {\n name: \"Polyester Trading Withdraw\",\n version: \"1\",\n chainId: params.signingConfig.chainId,\n verifyingContract: params.signingConfig.tradingGatewayAddress,\n },\n types: {\n WalletTradingWithdraw: [\n { name: \"signerWallet\", type: \"address\" },\n { name: \"actionType\", type: \"uint8\" },\n { name: \"accountId\", type: \"uint64\" },\n { name: \"targetAccountId\", type: \"uint64\" },\n { name: \"assetId\", type: \"uint32\" },\n { name: \"destinationChainId\", type: \"uint64\" },\n { name: \"amountQ\", type: \"uint128\" },\n { name: \"destinationHash\", type: \"bytes32\" },\n { name: \"deadlineTsSec\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint128\" },\n { name: \"idempotencyKeyHash\", type: \"bytes32\" },\n ],\n },\n primaryType: \"WalletTradingWithdraw\",\n message: {\n signerWallet: params.signerWallet,\n actionType: payload.action,\n accountId: params.accountId,\n targetAccountId: params.targetAccountId,\n assetId: payload.assetId,\n destinationChainId: payload.destinationChainId ?? 0n,\n amountQ: fromU128(payload.amountE18),\n destinationHash: keccak256Hex(evmUtf8ToBytes(destinationAddress)),\n deadlineTsSec: payload.deadlineTsSec,\n nonce: fromU128(payload.nonce),\n idempotencyKeyHash: keccak256Hex(evmUtf8ToBytes(idempotencyKey)),\n },\n } as const;\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();\n if (!signerWallet.startsWith(\"0x\")) {\n throw new ValidationError(\"Trading withdraw signer wallet is required.\");\n }\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signTypedData(\n buildTradingWithdrawWalletTypedData({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet: signerWallet as Address,\n accountId,\n targetAccountId: params.targetAccountId,\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-712 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 transport: Transport,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n ) {\n this.#client = createClient(Proto.WithdrawService, transport);\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 EIP-712 typed data 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 EIP-712 typed data 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\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload: validated.payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload: validated.payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n submit: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\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 {\n submit: 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":";;;;;;;;;;;AAwEA,SAAS,SAAS,OAA6E;CAC3F,IAAI,CAAC,OAAO,OAAO;CACnB,QAAQ,MAAM,MAAM,OAAO,MAAM;AACrC;AAEA,SAAS,sCAAsC,QAGpC;CACP,IAAI,OAAO,iBAAiB,KAAA,GAAW,OAAO,OAAO;CACrD,OAAO,WAAW,OAAO,eAAe,iBAAiB;AAC7D;AAEA,eAAe,oCAAoC,QAGT;CACtC,IAAI,CAAC,OAAO,SAAS,OAAO,OAAO;CAEnC,IAAI;EACA,MAAM,OAAO,QAAQ,YAAY;EAEjC,MAAM,UADU,OAAO,QAAQ,OAAO,kBAAkB,gBAClC,CAAC,EAAE,SAAS,KAAK;EACvC,IAAI,CAAC,SAAS,WAAW,IAAI,GAAG,OAAO,OAAO;EAE9C,OAAO;GACH,SAAS,OAAO,SAAS;GACzB,uBAAuB,mBAAmB,OAAO;EACrD;CACJ,QAAQ;EACJ,OAAO,OAAO;CAClB;AACJ;AAEA,SAAS,oCAAoC,QAM1C;CACC,MAAM,UAAU,OAAO;CACvB,MAAM,sB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AAO,KAAKC,iBAAiB,WAAW,YAAY;CACxD;CAEA,MAAMA,iBACF,WACA,cACgC;EAChC,IAAI,cAAc;GACd,MAAM,gBAAgB,MAAM,oCAAoC;IAC5D,UAAU,KAAKL;IACf,SAAS,KAAKC;GAClB,CAAC;GACD,MAAM,kBAAkB,sCAAsC;IAC1D,cAAc,UAAU;IACxB,eAAe,aAAa;GAChC,CAAC;GAED,MAAM,kBAAkB,MAAM,uBAAuB;IACjD;IACA,SAAS,UAAU;IACnB;IACA;GACJ,CAAC;GACD,MAAM,UAAU,gBAAgB;IAC5B,SAAS,UAAU;IACnB,cAAc,UAAU;IACxB,cAAc,gBAAgB;IAC9B,kBAAkB,gBAAgB;GACtC,CAAC;GACD,OAAO,EACH,QAAQ,OAAO,YAAY;IACvB,MAAM,WAAW,MAAM,KAAKJ,QAAQ,4BAChC,SACA,qBAAqB,OAAO,CAChC;IACA,OAAO,MAAM,yCAAyC,QAAQ;GAClE,EACJ;EACJ;EAEA,IAAI,CAAC,UAAU,kBACX,MAAM,IAAI,gBACN,iEACJ;EAGJ,MAAM,UAAU,gBAAgB;GAC5B,SAAS,UAAU;GACnB,kBAAkB,UAAU;EAChC,CAAC;EACD,OAAO,EACH,QAAQ,OAAO,YAAY;GACvB,MAAM,WAAW,MAAM,KAAKA,QAAQ,sBAChC,SACA,qBAAqB,OAAO,CAChC;GACA,OAAO,MAAM,mCAAmC,QAAQ;EAC5D,EACJ;CACJ;AACJ"}
@@ -1,7 +1,7 @@
1
- import { validation_d_exports } from "../../shared/validation.js";
2
1
  import { TradingWithdrawAction, WithdrawDestinationValidationCode } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
3
2
  import { SdkScales } from "../../shared/decimal-surface.js";
4
3
  import { U128Value } from "../../utils/u128.js";
4
+ import * as v from "valibot";
5
5
  //#region src/services/trading-withdraws/trading-withdraws.schemas.d.ts
6
6
  type TradingWithdrawIntentPayloadRequest = {
7
7
  action: TradingWithdrawAction;
@@ -18,17 +18,17 @@ type CreateTradingWithdrawRequestBase = {
18
18
  payload: TradingWithdrawIntentPayloadRequest;
19
19
  payloadSignature?: Uint8Array;
20
20
  };
21
- declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales): validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StrictObjectSchema<{
22
- readonly assetId: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.NumberSchema<undefined>, validation_d_exports.IntegerAction<number, undefined>, validation_d_exports.GtValueAction<number, 0, undefined>]>;
23
- readonly quantity: validation_d_exports.StringSchema<undefined>;
24
- readonly idempotencyKey: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
25
- readonly destinationAddress: validation_d_exports.OptionalSchema<validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction]>, "">;
26
- readonly signerWallet: validation_d_exports.OptionalSchema<validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction]>, "">;
27
- readonly payloadSignature: validation_d_exports.OptionalSchema<validation_d_exports.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
28
- readonly account: validation_d_exports.OptionalSchema<validation_d_exports.UnionSchema<[validation_d_exports.PicklistSchema<["active", "main"], undefined>, validation_d_exports.StrictObjectSchema<{
29
- readonly subaccountId: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
21
+ declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
22
+ readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>]>;
23
+ readonly quantity: v.StringSchema<undefined>;
24
+ readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
25
+ readonly destinationAddress: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
26
+ readonly signerWallet: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
27
+ readonly payloadSignature: v.OptionalSchema<v.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
28
+ readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
29
+ readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
30
30
  }, undefined>], undefined>, undefined>;
31
- }, undefined>, validation_d_exports.TransformAction<{
31
+ }, undefined>, v.TransformAction<{
32
32
  assetId: number;
33
33
  quantity: string;
34
34
  idempotencyKey: string;
@@ -39,18 +39,18 @@ declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScal
39
39
  subaccountId: string;
40
40
  } | undefined;
41
41
  }, CreateTradingWithdrawRequestBase>]>;
42
- declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales): validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StrictObjectSchema<{
43
- readonly assetId: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.NumberSchema<undefined>, validation_d_exports.IntegerAction<number, undefined>, validation_d_exports.GtValueAction<number, 0, undefined>]>;
44
- readonly quantity: validation_d_exports.StringSchema<undefined>;
45
- readonly destinationChainId: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.NumberSchema<undefined>, validation_d_exports.IntegerAction<number, undefined>, validation_d_exports.GtValueAction<number, 0, undefined>, validation_d_exports.MaxValueAction<number, number, undefined>]>;
46
- readonly destinationAddress: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
47
- readonly idempotencyKey: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
48
- readonly signerWallet: validation_d_exports.OptionalSchema<validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction]>, "">;
49
- readonly payloadSignature: validation_d_exports.OptionalSchema<validation_d_exports.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
50
- readonly account: validation_d_exports.OptionalSchema<validation_d_exports.UnionSchema<[validation_d_exports.PicklistSchema<["active", "main"], undefined>, validation_d_exports.StrictObjectSchema<{
51
- readonly subaccountId: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
42
+ declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
43
+ readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>]>;
44
+ readonly quantity: v.StringSchema<undefined>;
45
+ readonly destinationChainId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, number, undefined>]>;
46
+ readonly destinationAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
47
+ readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
48
+ readonly signerWallet: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
49
+ readonly payloadSignature: v.OptionalSchema<v.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
50
+ readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
51
+ readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
52
52
  }, undefined>], undefined>, undefined>;
53
- }, undefined>, validation_d_exports.TransformAction<{
53
+ }, undefined>, v.TransformAction<{
54
54
  assetId: number;
55
55
  quantity: string;
56
56
  destinationChainId: number;
@@ -62,29 +62,29 @@ declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: S
62
62
  subaccountId: string;
63
63
  } | undefined;
64
64
  }, CreateTradingWithdrawRequestBase>]>;
65
- type CreateTradingWithdrawToFundingInput = validation_d_exports.InferInput<ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>>;
66
- type CreateTradingWithdrawToExternalChainInput = validation_d_exports.InferInput<ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>>;
67
- declare const CreateTradingWithdrawResultSchema: validation_d_exports.ObjectSchema<{
68
- readonly intentId: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
65
+ type CreateTradingWithdrawToFundingInput = v.InferInput<ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>>;
66
+ type CreateTradingWithdrawToExternalChainInput = v.InferInput<ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>>;
67
+ declare const CreateTradingWithdrawResultSchema: v.ObjectSchema<{
68
+ readonly intentId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
69
69
  }, undefined>;
70
- type CreateTradingWithdrawResult = validation_d_exports.InferOutput<typeof CreateTradingWithdrawResultSchema>;
71
- declare const ValidateWithdrawDestinationInputSchema: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StrictObjectSchema<{
72
- readonly destinationChainId: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.NumberSchema<undefined>, validation_d_exports.IntegerAction<number, undefined>, validation_d_exports.GtValueAction<number, 0, undefined>, validation_d_exports.MaxValueAction<number, number, undefined>]>;
73
- readonly destinationAddress: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
74
- }, undefined>, validation_d_exports.TransformAction<{
70
+ type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;
71
+ declare const ValidateWithdrawDestinationInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
72
+ readonly destinationChainId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, number, undefined>]>;
73
+ readonly destinationAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
74
+ }, undefined>, v.TransformAction<{
75
75
  destinationChainId: number;
76
76
  destinationAddress: string;
77
77
  }, {
78
78
  destinationChainId: bigint;
79
79
  destinationAddress: string;
80
80
  }>]>;
81
- type ValidateWithdrawDestinationInput = validation_d_exports.InferInput<typeof ValidateWithdrawDestinationInputSchema>;
82
- declare const ValidateWithdrawDestinationResultSchema: validation_d_exports.UnionSchema<[validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.ObjectSchema<{
83
- readonly valid: validation_d_exports.LiteralSchema<true, undefined>;
84
- readonly code: validation_d_exports.LiteralSchema<WithdrawDestinationValidationCode.VALID, undefined>;
85
- readonly message: validation_d_exports.StringSchema<undefined>;
86
- readonly canonicalDestinationAddress: validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.StringSchema<undefined>, validation_d_exports.TrimAction, validation_d_exports.MinLengthAction<string, 1, undefined>]>;
87
- }, undefined>, validation_d_exports.TransformAction<{
81
+ type ValidateWithdrawDestinationInput = v.InferInput<typeof ValidateWithdrawDestinationInputSchema>;
82
+ declare const ValidateWithdrawDestinationResultSchema: v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
83
+ readonly valid: v.LiteralSchema<true, undefined>;
84
+ readonly code: v.LiteralSchema<WithdrawDestinationValidationCode.VALID, undefined>;
85
+ readonly message: v.StringSchema<undefined>;
86
+ readonly canonicalDestinationAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
87
+ }, undefined>, v.TransformAction<{
88
88
  valid: true;
89
89
  code: WithdrawDestinationValidationCode.VALID;
90
90
  message: string;
@@ -94,12 +94,12 @@ declare const ValidateWithdrawDestinationResultSchema: validation_d_exports.Unio
94
94
  valid: true;
95
95
  message: string;
96
96
  canonicalDestinationAddress: string;
97
- }>]>, validation_d_exports.SchemaWithPipe<readonly [validation_d_exports.ObjectSchema<{
98
- readonly valid: validation_d_exports.LiteralSchema<false, undefined>;
99
- readonly code: validation_d_exports.PicklistSchema<[WithdrawDestinationValidationCode.RESULT_UNSPECIFIED, WithdrawDestinationValidationCode.INVALID_ADDRESS, WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN, WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT, WithdrawDestinationValidationCode.TOKEN_CONTRACT, WithdrawDestinationValidationCode.DENYLISTED_ADDRESS], undefined>;
100
- readonly message: validation_d_exports.StringSchema<undefined>;
101
- readonly canonicalDestinationAddress: validation_d_exports.StringSchema<undefined>;
102
- }, undefined>, validation_d_exports.TransformAction<{
97
+ }>]>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
98
+ readonly valid: v.LiteralSchema<false, undefined>;
99
+ readonly code: v.PicklistSchema<[WithdrawDestinationValidationCode.RESULT_UNSPECIFIED, WithdrawDestinationValidationCode.INVALID_ADDRESS, WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN, WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT, WithdrawDestinationValidationCode.TOKEN_CONTRACT, WithdrawDestinationValidationCode.DENYLISTED_ADDRESS], undefined>;
100
+ readonly message: v.StringSchema<undefined>;
101
+ readonly canonicalDestinationAddress: v.StringSchema<undefined>;
102
+ }, undefined>, v.TransformAction<{
103
103
  valid: false;
104
104
  code: WithdrawDestinationValidationCode.RESULT_UNSPECIFIED | WithdrawDestinationValidationCode.INVALID_ADDRESS | WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN | WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT | WithdrawDestinationValidationCode.TOKEN_CONTRACT | WithdrawDestinationValidationCode.DENYLISTED_ADDRESS;
105
105
  message: string;
@@ -110,7 +110,7 @@ declare const ValidateWithdrawDestinationResultSchema: validation_d_exports.Unio
110
110
  message: string;
111
111
  canonicalDestinationAddress: string;
112
112
  }>]>], undefined>;
113
- type ValidateWithdrawDestinationResult = validation_d_exports.InferOutput<typeof ValidateWithdrawDestinationResultSchema>;
113
+ type ValidateWithdrawDestinationResult = v.InferOutput<typeof ValidateWithdrawDestinationResultSchema>;
114
114
  //#endregion
115
115
  export { CreateTradingWithdrawResult, CreateTradingWithdrawResultSchema, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, TradingWithdrawIntentPayloadRequest, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResult, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema };
116
116
  //# 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":";;;;;KAgBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;EACT,mBAAmB;;iBAoCP,gDAAgD,QAAQ,YAAS,qBAAA,yBAAA,qBAAA;;;;;;;;;;;;;;;;;;;;GA+BhF;iBAEe,sDAAsD,QAAQ,YAAS,qBAAA,yBAAA,qBAAA;;;;;;;;;;;;;;;;;;;;;;GAqCtF;KAEW,sCAAsC,qBAAE,WAChD,kBAAkB;KAOV,4CAA4C,qBAAE,WACtD,kBAAkB;cAOT,mCAAiC,qBAAA;;;KAIlC,8BAA8B,qBAAE,mBAAmB;cAOlD,wCAAsC,qBAAA,yBAAA,qBAAA;;;;;;;;;;KAgBvC,mCAAmC,qBAAE,kBACtC;cA4CE,yCAAuC,qBAAA,aAAA,qBAAA,yBAAA,qBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,oCAAoC,qBAAE,mBACvC"}
1
+ {"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAgBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;EACT,mBAAmB;;iBAoCP,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;GA+BhF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;GAqCtF;KAEW,sCAAsC,EAAE,WAChD,kBAAkB;KAOV,4CAA4C,EAAE,WACtD,kBAAkB;cAOT,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,mBAAmB;cAOlD,wCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;KAgBvC,mCAAmC,EAAE,kBACtC;cA4CE,yCAAuC,EAAA,aAAA,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,oCAAoC,EAAE,mBACvC"}
@@ -1,9 +1,9 @@
1
- import { validation_exports } from "../../shared/validation.js";
2
1
  import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
3
2
  import { quantityInputToE18 } from "../../shared/decimal-surface.js";
4
3
  import { toU128 } from "../../utils/u128.js";
5
4
  import "../../gen/chain/withdraw/v1/withdraw_pb.js";
6
5
  import { TradingWithdrawActionCodec, WithdrawDestinationValidationCodeCodec } from "./trading-withdraws.codecs.js";
6
+ import * as v from "valibot";
7
7
  //#region src/services/trading-withdraws/trading-withdraws.schemas.ts
8
8
  const DEFAULT_DEADLINE_SECONDS = 300;
9
9
  function createNonce() {
@@ -30,15 +30,15 @@ function createTradingWithdrawPayload(input) {
30
30
  };
31
31
  }
32
32
  function createCreateTradingWithdrawToFundingInputSchema(scales) {
33
- return validation_exports.pipe(validation_exports.strictObject({
33
+ return v.pipe(v.strictObject({
34
34
  ...AccountScopeInputEntries,
35
- assetId: validation_exports.pipe(validation_exports.number(), validation_exports.integer(), validation_exports.gtValue(0)),
36
- quantity: validation_exports.string(),
37
- idempotencyKey: validation_exports.pipe(validation_exports.string(), validation_exports.trim(), validation_exports.minLength(1)),
38
- destinationAddress: validation_exports.optional(validation_exports.pipe(validation_exports.string(), validation_exports.trim()), ""),
39
- signerWallet: validation_exports.optional(validation_exports.pipe(validation_exports.string(), validation_exports.trim()), ""),
40
- payloadSignature: validation_exports.optional(validation_exports.instance(Uint8Array))
41
- }), validation_exports.transform((input) => {
35
+ assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),
36
+ quantity: v.string(),
37
+ idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
38
+ destinationAddress: v.optional(v.pipe(v.string(), v.trim()), ""),
39
+ signerWallet: v.optional(v.pipe(v.string(), v.trim()), ""),
40
+ payloadSignature: v.optional(v.instance(Uint8Array))
41
+ }), v.transform((input) => {
42
42
  const quantityScaled = quantityInputToE18({
43
43
  scales,
44
44
  assetId: input.assetId,
@@ -59,16 +59,16 @@ function createCreateTradingWithdrawToFundingInputSchema(scales) {
59
59
  }));
60
60
  }
61
61
  function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
62
- return validation_exports.pipe(validation_exports.strictObject({
62
+ return v.pipe(v.strictObject({
63
63
  ...AccountScopeInputEntries,
64
- assetId: validation_exports.pipe(validation_exports.number(), validation_exports.integer(), validation_exports.gtValue(0)),
65
- quantity: validation_exports.string(),
66
- destinationChainId: validation_exports.pipe(validation_exports.number(), validation_exports.integer(), validation_exports.gtValue(0), validation_exports.maxValue(Number.MAX_SAFE_INTEGER)),
67
- destinationAddress: validation_exports.pipe(validation_exports.string(), validation_exports.trim(), validation_exports.minLength(1)),
68
- idempotencyKey: validation_exports.pipe(validation_exports.string(), validation_exports.trim(), validation_exports.minLength(1)),
69
- signerWallet: validation_exports.optional(validation_exports.pipe(validation_exports.string(), validation_exports.trim()), ""),
70
- payloadSignature: validation_exports.optional(validation_exports.instance(Uint8Array))
71
- }), validation_exports.transform((input) => {
64
+ assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),
65
+ quantity: v.string(),
66
+ destinationChainId: v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(Number.MAX_SAFE_INTEGER)),
67
+ destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),
68
+ idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
69
+ signerWallet: v.optional(v.pipe(v.string(), v.trim()), ""),
70
+ payloadSignature: v.optional(v.instance(Uint8Array))
71
+ }), v.transform((input) => {
72
72
  const quantityScaled = quantityInputToE18({
73
73
  scales,
74
74
  assetId: input.assetId,
@@ -88,28 +88,28 @@ function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
88
88
  };
89
89
  }));
90
90
  }
91
- const CreateTradingWithdrawResultSchema = validation_exports.object({ intentId: validation_exports.pipe(validation_exports.string(), validation_exports.trim(), validation_exports.minLength(1)) });
91
+ const CreateTradingWithdrawResultSchema = v.object({ intentId: v.pipe(v.string(), v.trim(), v.minLength(1)) });
92
92
  const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;
93
- const ValidateWithdrawDestinationInputSchema = validation_exports.pipe(validation_exports.strictObject({
94
- destinationChainId: validation_exports.pipe(validation_exports.number(), validation_exports.integer(), validation_exports.gtValue(0), validation_exports.maxValue(Number.MAX_SAFE_INTEGER)),
95
- destinationAddress: validation_exports.pipe(validation_exports.string(), validation_exports.trim(), validation_exports.minLength(1))
96
- }), validation_exports.transform((input) => ({
93
+ const ValidateWithdrawDestinationInputSchema = v.pipe(v.strictObject({
94
+ destinationChainId: v.pipe(v.number(), v.integer(), v.gtValue(0), v.maxValue(Number.MAX_SAFE_INTEGER)),
95
+ destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1))
96
+ }), v.transform((input) => ({
97
97
  destinationChainId: BigInt(input.destinationChainId),
98
98
  destinationAddress: input.destinationAddress
99
99
  })));
100
- const ValidWithdrawDestinationResultSchema = validation_exports.pipe(validation_exports.object({
101
- valid: validation_exports.literal(true),
102
- code: validation_exports.literal(1),
103
- message: validation_exports.string(),
104
- canonicalDestinationAddress: validation_exports.pipe(validation_exports.string(), validation_exports.trim(), validation_exports.minLength(1))
105
- }), validation_exports.transform((result) => ({
100
+ const ValidWithdrawDestinationResultSchema = v.pipe(v.object({
101
+ valid: v.literal(true),
102
+ code: v.literal(1),
103
+ message: v.string(),
104
+ canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1))
105
+ }), v.transform((result) => ({
106
106
  ...result,
107
107
  code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code]
108
108
  })));
109
109
  const { [1]: _validWithdrawDestinationCode, ...InvalidWithdrawDestinationCodeCodec } = WithdrawDestinationValidationCodeCodec.protoToOutput;
110
- const InvalidWithdrawDestinationResultSchema = validation_exports.pipe(validation_exports.object({
111
- valid: validation_exports.literal(false),
112
- code: validation_exports.picklist([
110
+ const InvalidWithdrawDestinationResultSchema = v.pipe(v.object({
111
+ valid: v.literal(false),
112
+ code: v.picklist([
113
113
  0,
114
114
  2,
115
115
  3,
@@ -117,13 +117,13 @@ const InvalidWithdrawDestinationResultSchema = validation_exports.pipe(validatio
117
117
  5,
118
118
  6
119
119
  ]),
120
- message: validation_exports.string(),
121
- canonicalDestinationAddress: validation_exports.string()
122
- }), validation_exports.transform((result) => ({
120
+ message: v.string(),
121
+ canonicalDestinationAddress: v.string()
122
+ }), v.transform((result) => ({
123
123
  ...result,
124
124
  code: InvalidWithdrawDestinationCodeCodec[result.code]
125
125
  })));
126
- const ValidateWithdrawDestinationResultSchema = validation_exports.union([ValidWithdrawDestinationResultSchema, InvalidWithdrawDestinationResultSchema]);
126
+ const ValidateWithdrawDestinationResultSchema = v.union([ValidWithdrawDestinationResultSchema, InvalidWithdrawDestinationResultSchema]);
127
127
  //#endregion
128
128
  export { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema };
129
129
 
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.schemas.js","names":["v"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"../../shared/validation.js\";\nimport { quantityInputToE18, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { toU128, type U128Value } from \"../../utils/u128.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n payloadSignature?: Uint8Array;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n const nonce = BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0] ?? BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n"],"mappings":";;;;;;;AAcA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,iBAAiB,KAAK,WAAW,MAAM;CACzE,IAAI,CAAC,QAAQ;EACT,MAAM,QAAQ,OAAO,KAAK,IAAI,CAAC;EAC/B,OAAO,UAAU,KAAK,KAAK;CAC/B;CAEA,MAAM,wBAAQ,IAAI,eAAe,CAAC;CAClC,OAAO,KAAK;CACZ,MAAM,QAAQ,MAAM,MAAM,OAAO,KAAK,IAAI,CAAC;CAC3C,OAAO,UAAU,KAAK,KAAK;AAC/B;AAEA,SAAS,6BAA6B,OAOE;CACpC,OAAO;EACH,QAAQ,MAAM;EACd,SAAS,MAAM;EACf,oBAAoB,MAAM;EAC1B,WAAW,OAAO,MAAM,cAAc;EACtC,eAAe,OAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI,wBAAwB;EAC9E,OAAO,OAAO,YAAY,CAAC;EAC3B,oBAAoB,MAAM;EAC1B,gBAAgB,MAAM;CAC1B;AACJ;AAEA,SAAgB,gDAAgD,QAAmB;CAC/E,OAAOA,mBAAE,KACLA,mBAAE,aAAa;EACX,GAAG;EACH,SAASA,mBAAE,KAAKA,mBAAE,OAAO,GAAGA,mBAAE,QAAQ,GAAGA,mBAAE,QAAQ,CAAC,CAAC;EACrD,UAAUA,mBAAE,OAAO;EACnB,gBAAgBA,mBAAE,KAAKA,mBAAE,OAAO,GAAGA,mBAAE,KAAK,GAAGA,mBAAE,UAAU,CAAC,CAAC;EAC3D,oBAAoBA,mBAAE,SAASA,mBAAE,KAAKA,mBAAE,OAAO,GAAGA,mBAAE,KAAK,CAAC,GAAG,EAAE;EAC/D,cAAcA,mBAAE,SAASA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CA,mBAAE,KAC7CA,mBAAE,OAAO;CACL,OAAOA,mBAAE,QAAQ,KAAK;CACtB,MAAMA,mBAAE,SAAS;;;;;;;CAOjB,CAAC;CACD,SAASA,mBAAE,OAAO;CAClB,6BAA6BA,mBAAE,OAAO;AAC1C,CAAC,GACDA,mBAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,oCAAoC,OAAO;AACrD,EAAE,CACN;AAEA,MAAa,0CAA0CA,mBAAE,MAAM,CAC3D,sCACA,sCACJ,CAAC"}
1
+ {"version":3,"file":"trading-withdraws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { quantityInputToE18, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { toU128, type U128Value } from \"../../utils/u128.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n payloadSignature?: Uint8Array;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n const nonce = BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0] ?? BigInt(Date.now());\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: v.pipe(v.number(), v.integer(), v.gtValue(0)),\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n"],"mappings":";;;;;;;AAcA,MAAM,2BAA2B;AAmBj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ts"],"mappings":";;;;;;;;;UAmBU,gCAAgC,mBAAmB;EACzD;;;;;cAMS;;EAQL,YAAA,WAAW,WACX,UAAU,mBACV,UAAU,gCACV,QAAQ;;;;EAYN,KACF,QAAO,oBACP,UAAU,0BACX;IAAU,WAAW;IAAkB;;;;;EAY1C,UAAU,OAAO"}
1
+ {"version":3,"file":"transfers.d.ts","names":[],"sources":["../../../src/services/transfers/transfers.ts"],"mappings":";;;;;;;;;UAoBU,gCAAgC,mBAAmB;EACzD;;;;;cAMS;;EAQL,YAAA,WAAW,WACX,UAAU,mBACV,UAAU,gCACV,QAAQ;;;;EAYN,KACF,QAAO,oBACP,UAAU,0BACX;IAAU,WAAW;IAAkB;;;;;EAY1C,UAAU,OAAO"}
@@ -1,4 +1,4 @@
1
- import { parse, validation_exports } from "../../shared/validation.js";
1
+ import { parse } from "../../shared/validation.js";
2
2
  import { toConnectCallOptions } from "../../shared/request-options.js";
3
3
  import { resolveAccountScopedInput } from "../subaccount-resolver.js";
4
4
  import { LedgerReadService, TransferRowSchema } from "../../gen/ledger/read/v1/ledger_read_pb.js";
@@ -6,6 +6,7 @@ import { publicationHandlerErrorContext } from "../../shared/subscription-errors
6
6
  import { createReadyGate } from "../../shared/decimal-surface.js";
7
7
  import { ListTransfersInputSchema, createLedgerTransferSchema } from "./transfers.schemas.js";
8
8
  import { createClient } from "@connectrpc/connect";
9
+ import * as v from "valibot";
9
10
  //#region src/services/transfers/transfers.ts
10
11
  /**
11
12
  * Reads and streams ledger transfer activity for the authenticated account scope.
@@ -32,7 +33,7 @@ var TransfersService = class {
32
33
  const validatedInput = parse(ListTransfersInputSchema, resolved);
33
34
  const res = await this.#client.listTransfers(validatedInput, toConnectCallOptions(options));
34
35
  return {
35
- transfers: parse(validation_exports.array(this.#ledgerTransferSchema), res.transfers),
36
+ transfers: parse(v.array(this.#ledgerTransferSchema), res.transfers),
36
37
  nextPageToken: res.nextPageToken
37
38
  };
38
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transfers.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","#scales","#ledgerTransferSchema","v.parse","v","Proto.TransferRowSchema"],"sources":["../../../src/services/transfers/transfers.ts"],"sourcesContent":["import * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport * as v from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { createReadyGate, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n createLedgerTransferSchema,\n ListTransfersInputSchema,\n type LedgerTransfer,\n type ListTransfersInput,\n} from \"./transfers.schemas.js\";\n\ninterface SubscribeTransfersInput extends BaseSubscribeInput<LedgerTransfer> {\n accountId: string;\n}\n\n/**\n * Reads and streams ledger transfer activity for the authenticated account scope.\n */\nexport class TransfersService {\n #client: Client<typeof Proto.LedgerReadService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #ledgerTransferSchema: ReturnType<typeof createLedgerTransferSchema>;\n\n constructor(\n transport: Transport,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#client = createClient(Proto.LedgerReadService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#ledgerTransferSchema = createLedgerTransferSchema(scales);\n }\n\n /**\n * Returns ledger transfers for the resolved account scope with limit, direction, timestamp, code, ledger, and page-token filters.\n */\n async list(\n input: ListTransfersInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ transfers: LedgerTransfer[]; nextPageToken: string }> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = v.parse(ListTransfersInputSchema, resolved);\n const res = await this.#client.listTransfers(validatedInput, toConnectCallOptions(options));\n const transfers = v.parse(v.array(this.#ledgerTransferSchema), res.transfers);\n return { transfers, nextPageToken: res.nextPageToken };\n }\n\n /**\n * Subscribes to private ledger transfer updates on private:ledger:transfers:{accountId}:proto and emits parsed transfer rows.\n */\n subscribe(input: SubscribeTransfersInput): () => void {\n const channel = `private:ledger:transfers:${input.accountId}:proto`;\n const gate = createReadyGate(\n () => this.#scales.ready(),\n (error) => input.onError?.(publicationHandlerErrorContext(channel, error)),\n );\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.TransferRowSchema,\n onPublication: (m) => {\n gate.run(() => {\n const tr = v.parse(this.#ledgerTransferSchema, m);\n input.onEvent(tr);\n });\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,IAAa,mBAAb,MAA8B;CAC1B;CACA;CACA;CACA;CACA;CAEA,YACI,WACA,UACA,UACA,QACF;EACE,KAAKA,UAAU,aAAaC,mBAAyB,SAAS;EAC9D,KAAKC,YAAY;EACjB,KAAKC,YAAY;EACjB,KAAKC,UAAU;EACf,KAAKC,wBAAwB,2BAA2B,MAAM;CAClE;;;;CAKA,MAAM,KACF,QAA4B,CAAC,GAC7B,SAC+D;EAC/D,MAAM,KAAKD,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,iBAAiBG,MAAQ,0BAA0B,QAAQ;EACjE,MAAM,MAAM,MAAM,KAAKN,QAAQ,cAAc,gBAAgB,qBAAqB,OAAO,CAAC;EAE1F,OAAO;GAAE,WADSM,MAAQC,mBAAE,MAAM,KAAKF,qBAAqB,GAAG,IAAI,SAClD;GAAG,eAAe,IAAI;EAAc;CACzD;;;;CAKA,UAAU,OAA4C;EAClD,MAAM,UAAU,4BAA4B,MAAM,UAAU;EAC5D,MAAM,OAAO,sBACH,KAAKD,QAAQ,MAAM,IACxB,UAAU,MAAM,UAAU,+BAA+B,SAAS,KAAK,CAAC,CAC7E;EACA,OAAO,KAAKF,UAAU,oBAAoB;GACtC;GACA,QAAQM;GACR,gBAAgB,MAAM;IAClB,KAAK,UAAU;KACX,MAAM,KAAKF,MAAQ,KAAKD,uBAAuB,CAAC;KAChD,MAAM,QAAQ,EAAE;IACpB,CAAC;GACL;GACA,aAAa,MAAM;GACnB,gBAAgB,MAAM;GACtB,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"transfers.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","#scales","#ledgerTransferSchema","Proto.TransferRowSchema"],"sources":["../../../src/services/transfers/transfers.ts"],"sourcesContent":["import * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { createReadyGate, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n createLedgerTransferSchema,\n ListTransfersInputSchema,\n type LedgerTransfer,\n type ListTransfersInput,\n} from \"./transfers.schemas.js\";\n\ninterface SubscribeTransfersInput extends BaseSubscribeInput<LedgerTransfer> {\n accountId: string;\n}\n\n/**\n * Reads and streams ledger transfer activity for the authenticated account scope.\n */\nexport class TransfersService {\n #client: Client<typeof Proto.LedgerReadService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n #scales: SdkScales;\n #ledgerTransferSchema: ReturnType<typeof createLedgerTransferSchema>;\n\n constructor(\n transport: Transport,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n scales: SdkScales,\n ) {\n this.#client = createClient(Proto.LedgerReadService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n this.#scales = scales;\n this.#ledgerTransferSchema = createLedgerTransferSchema(scales);\n }\n\n /**\n * Returns ledger transfers for the resolved account scope with limit, direction, timestamp, code, ledger, and page-token filters.\n */\n async list(\n input: ListTransfersInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ transfers: LedgerTransfer[]; nextPageToken: string }> {\n await this.#scales.ready();\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(ListTransfersInputSchema, resolved);\n const res = await this.#client.listTransfers(validatedInput, toConnectCallOptions(options));\n const transfers = parse(v.array(this.#ledgerTransferSchema), res.transfers);\n return { transfers, nextPageToken: res.nextPageToken };\n }\n\n /**\n * Subscribes to private ledger transfer updates on private:ledger:transfers:{accountId}:proto and emits parsed transfer rows.\n */\n subscribe(input: SubscribeTransfersInput): () => void {\n const channel = `private:ledger:transfers:${input.accountId}:proto`;\n const gate = createReadyGate(\n () => this.#scales.ready(),\n (error) => input.onError?.(publicationHandlerErrorContext(channel, error)),\n );\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.TransferRowSchema,\n onPublication: (m) => {\n gate.run(() => {\n const tr = parse(this.#ledgerTransferSchema, m);\n input.onEvent(tr);\n });\n },\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,IAAa,mBAAb,MAA8B;CAC1B;CACA;CACA;CACA;CACA;CAEA,YACI,WACA,UACA,UACA,QACF;EACE,KAAKA,UAAU,aAAaC,mBAAyB,SAAS;EAC9D,KAAKC,YAAY;EACjB,KAAKC,YAAY;EACjB,KAAKC,UAAU;EACf,KAAKC,wBAAwB,2BAA2B,MAAM;CAClE;;;;CAKA,MAAM,KACF,QAA4B,CAAC,GAC7B,SAC+D;EAC/D,MAAM,KAAKD,QAAQ,MAAM;EACzB,MAAM,WAAW,0BAA0B,OAAO,KAAKD,SAAS;EAChE,MAAM,iBAAiB,MAAM,0BAA0B,QAAQ;EAC/D,MAAM,MAAM,MAAM,KAAKH,QAAQ,cAAc,gBAAgB,qBAAqB,OAAO,CAAC;EAE1F,OAAO;GAAE,WADS,MAAM,EAAE,MAAM,KAAKK,qBAAqB,GAAG,IAAI,SAChD;GAAG,eAAe,IAAI;EAAc;CACzD;;;;CAKA,UAAU,OAA4C;EAClD,MAAM,UAAU,4BAA4B,MAAM,UAAU;EAC5D,MAAM,OAAO,sBACH,KAAKD,QAAQ,MAAM,IACxB,UAAU,MAAM,UAAU,+BAA+B,SAAS,KAAK,CAAC,CAC7E;EACA,OAAO,KAAKF,UAAU,oBAAoB;GACtC;GACA,QAAQI;GACR,gBAAgB,MAAM;IAClB,KAAK,UAAU;KACX,MAAM,KAAK,MAAM,KAAKD,uBAAuB,CAAC;KAC9C,MAAM,QAAQ,EAAE;IACpB,CAAC;GACL;GACA,aAAa,MAAM;GACnB,gBAAgB,MAAM;GACtB,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}