@polyester/sdk 0.36.0-devnet-20261113022813 → 0.36.0-devnet-20261115165158

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 (289) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/dist/browser-core.js +1 -1
  3. package/dist/catalogs/index.d.ts +2 -2
  4. package/dist/catalogs/readers.d.ts.map +1 -1
  5. package/dist/catalogs/readers.js +1 -1
  6. package/dist/catalogs/readers.js.map +1 -1
  7. package/dist/catalogs/snapshot-validation.js +11 -7
  8. package/dist/catalogs/snapshot-validation.js.map +1 -1
  9. package/dist/catalogs/unknown-asset.d.ts.map +1 -1
  10. package/dist/catalogs/unknown-asset.js +4 -4
  11. package/dist/catalogs/unknown-asset.js.map +1 -1
  12. package/dist/catalogs/zipper-catalog.d.ts +2 -0
  13. package/dist/catalogs/zipper-catalog.d.ts.map +1 -1
  14. package/dist/catalogs/zipper-catalog.js.map +1 -1
  15. package/dist/core-client.d.ts.map +1 -1
  16. package/dist/core-client.js +2 -1
  17. package/dist/core-client.js.map +1 -1
  18. package/dist/gen/ai/v1/assistant_pb.d.ts +1 -1
  19. package/dist/gen/ai/v1/assistant_pb.js +1 -1
  20. package/dist/gen/alerts/v1/price_alerts_pb.d.ts +1 -1
  21. package/dist/gen/auth/v1/address_book_pb.d.ts +1 -1
  22. package/dist/gen/auth/v1/api_keys_pb.d.ts +6 -6
  23. package/dist/gen/auth/v1/api_keys_pb.js +5 -5
  24. package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
  25. package/dist/gen/auth/v1/auth_pb.d.ts +1 -1
  26. package/dist/gen/auth/v1/mfa_pb.d.ts +1 -1
  27. package/dist/gen/auth/v1/policies_pb.d.ts +10 -2
  28. package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
  29. package/dist/gen/auth/v1/policies_pb.js +9 -1
  30. package/dist/gen/auth/v1/policies_pb.js.map +1 -1
  31. package/dist/gen/auth/v1/profile_pb.d.ts +1 -1
  32. package/dist/gen/auth/v1/resolve_pb.d.ts +1 -1
  33. package/dist/gen/auth/v1/social_verification_pb.d.ts +1 -1
  34. package/dist/gen/auth/v1/subaccounts_pb.d.ts +8 -2
  35. package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
  36. package/dist/gen/auth/v1/subaccounts_pb.js +8 -2
  37. package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
  38. package/dist/gen/chain/analytics/v1/analytics_read_pb.d.ts +1 -1
  39. package/dist/gen/chain/deposit/v1/deposit_pb.d.ts +1 -1
  40. package/dist/gen/chain/guard/v1/guard_signer_pb.d.ts +1 -1
  41. package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts +1 -1
  42. package/dist/gen/chain/lifecycle/v1/types_pb.d.ts +1 -1
  43. package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts +1 -1
  44. package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +1 -1
  45. package/dist/gen/chain/zipper/v1/reason_pb.d.ts +1 -1
  46. package/dist/gen/chain/zipper/v1/zipper_pb.d.ts +48 -3
  47. package/dist/gen/chain/zipper/v1/zipper_pb.d.ts.map +1 -1
  48. package/dist/gen/chain/zipper/v1/zipper_pb.js +36 -2
  49. package/dist/gen/chain/zipper/v1/zipper_pb.js.map +1 -1
  50. package/dist/gen/changelog/v1/changelog_pb.d.ts +7 -4
  51. package/dist/gen/changelog/v1/changelog_pb.d.ts.map +1 -1
  52. package/dist/gen/changelog/v1/changelog_pb.js +2 -1
  53. package/dist/gen/changelog/v1/changelog_pb.js.map +1 -1
  54. package/dist/gen/checkpoints/v1/checkpoints_pb.d.ts +1 -1
  55. package/dist/gen/claims/v1/claims_pb.d.ts +1 -1
  56. package/dist/gen/fees/v1/fees_pb.d.ts +1 -1
  57. package/dist/gen/index.d.ts +2 -1
  58. package/dist/gen/index.js +22 -21
  59. package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts +126 -3
  60. package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts.map +1 -1
  61. package/dist/gen/ledger/read/v1/ledger_read_pb.js +17 -3
  62. package/dist/gen/ledger/read/v1/ledger_read_pb.js.map +1 -1
  63. package/dist/gen/marketdata/v1/asset_info_pb.d.ts +178 -0
  64. package/dist/gen/marketdata/v1/asset_info_pb.d.ts.map +1 -0
  65. package/dist/gen/marketdata/v1/asset_info_pb.js +45 -0
  66. package/dist/gen/marketdata/v1/asset_info_pb.js.map +1 -0
  67. package/dist/gen/marketdata/v1/heatmap_pb.d.ts +1 -1
  68. package/dist/gen/marketdata/v1/marketdata_pb.d.ts +13 -1
  69. package/dist/gen/marketdata/v1/marketdata_pb.d.ts.map +1 -1
  70. package/dist/gen/marketdata/v1/marketdata_pb.js +6 -1
  71. package/dist/gen/marketdata/v1/marketdata_pb.js.map +1 -1
  72. package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts +1 -1
  73. package/dist/gen/notifications/v1/notifications_pb.d.ts +1 -1
  74. package/dist/gen/orderbook/v1/orderbook_pb.d.ts +1 -1
  75. package/dist/gen/orders/v1/orders_pb.d.ts +1 -1
  76. package/dist/gen/orders/v1/orders_read_pb.d.ts +1 -1
  77. package/dist/gen/polyester/ratelimit/v1/types_pb.d.ts +1 -1
  78. package/dist/gen/polyester/type/v1/u128_pb.d.ts +1 -1
  79. package/dist/gen/privatews/v1/private_ws_pb.d.ts +1 -1
  80. package/dist/gen/ratelimit/v1/ratelimit_pb.d.ts +1 -1
  81. package/dist/gen/rewards/v1/rewards_pb.d.ts +1 -1
  82. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts +13 -1
  83. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts.map +1 -1
  84. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js +12 -0
  85. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js.map +1 -1
  86. package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts +14 -10
  87. package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts.map +1 -1
  88. package/dist/gen/swap/quickswap/v1/quickswap_pb.js +10 -7
  89. package/dist/gen/swap/quickswap/v1/quickswap_pb.js.map +1 -1
  90. package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.d.ts +3 -3
  91. package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.js.map +1 -1
  92. package/dist/gen/swap/v1/swap_pb.d.ts +1 -1
  93. package/dist/gen/system/v1/system_pb.d.ts +408 -3
  94. package/dist/gen/system/v1/system_pb.d.ts.map +1 -1
  95. package/dist/gen/system/v1/system_pb.js +221 -3
  96. package/dist/gen/system/v1/system_pb.js.map +1 -1
  97. package/dist/gen/tradews/v1/trade_ws_pb.d.ts +1 -1
  98. package/dist/gen/transfer/v1/internal_transfer_pb.d.ts +1 -1
  99. package/dist/gen/triggers/v1/triggers_pb.d.ts +7 -5
  100. package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
  101. package/dist/gen/triggers/v1/triggers_pb.js +6 -4
  102. package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
  103. package/dist/gen/vip/v1/vip_pb.d.ts +1 -1
  104. package/dist/index.d.ts +7 -4
  105. package/dist/index.js +1 -1
  106. package/dist/realtime/private-orders.d.ts +8 -0
  107. package/dist/realtime/private-orders.d.ts.map +1 -1
  108. package/dist/realtime/private-orders.js +38 -5
  109. package/dist/realtime/private-orders.js.map +1 -1
  110. package/dist/realtime/snapshot-then-stream.js +1 -1
  111. package/dist/server-core.js +3 -3
  112. package/dist/services/accounts/accounts.js +1 -1
  113. package/dist/services/accounts/accounts.schemas.js +1 -1
  114. package/dist/services/address-book/address-book.js +1 -1
  115. package/dist/services/address-book/address-book.schemas.d.ts.map +1 -1
  116. package/dist/services/address-book/address-book.schemas.js +4 -4
  117. package/dist/services/address-book/address-book.schemas.js.map +1 -1
  118. package/dist/services/api-keys/api-keys.codecs.d.ts +2 -2
  119. package/dist/services/api-keys/api-keys.codecs.js +2 -2
  120. package/dist/services/api-keys/api-keys.codecs.js.map +1 -1
  121. package/dist/services/api-keys/api-keys.js +1 -1
  122. package/dist/services/api-keys/api-keys.schemas.js +1 -1
  123. package/dist/services/assistant/assistant-events.schemas.d.ts +100 -71
  124. package/dist/services/assistant/assistant-events.schemas.d.ts.map +1 -1
  125. package/dist/services/assistant/assistant.js +1 -1
  126. package/dist/services/assistant/assistant.schemas.d.ts +1 -1
  127. package/dist/services/assistant/assistant.schemas.js +1 -1
  128. package/dist/services/auth/account-signer-auth.js +2 -2
  129. package/dist/services/auth/auth.js +1 -1
  130. package/dist/services/auth/profile/profile.js +2 -2
  131. package/dist/services/auto-withdraw/auto-withdraw.js +1 -1
  132. package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +13 -13
  133. package/dist/services/auto-withdraw/auto-withdraw.schemas.js +1 -1
  134. package/dist/services/balances/balances.d.ts +12 -1
  135. package/dist/services/balances/balances.d.ts.map +1 -1
  136. package/dist/services/balances/balances.js +38 -2
  137. package/dist/services/balances/balances.js.map +1 -1
  138. package/dist/services/balances/balances.schemas.d.ts +61 -25
  139. package/dist/services/balances/balances.schemas.d.ts.map +1 -1
  140. package/dist/services/balances/balances.schemas.js +24 -3
  141. package/dist/services/balances/balances.schemas.js.map +1 -1
  142. package/dist/services/balances/balances.types.d.ts +2 -2
  143. package/dist/services/candles/candles.js +2 -2
  144. package/dist/services/chain-analytics/chain-analytics.js +1 -1
  145. package/dist/services/changelog/changelog.js +1 -1
  146. package/dist/services/changelog/changelog.schemas.d.ts +38 -38
  147. package/dist/services/checkpoints/checkpoints.js +1 -1
  148. package/dist/services/checkpoints/checkpoints.schemas.d.ts +2 -2
  149. package/dist/services/claims/claims.js +1 -1
  150. package/dist/services/claims/claims.schemas.d.ts +2 -2
  151. package/dist/services/claims/claims.schemas.js +1 -1
  152. package/dist/services/deposit/deposit.js +1 -1
  153. package/dist/services/fees/fees.js +1 -1
  154. package/dist/services/guard-signer/guard-signer.js +1 -1
  155. package/dist/services/guard-signer/guard-signer.schemas.js +1 -1
  156. package/dist/services/heatmap/heatmap.js +2 -2
  157. package/dist/services/internal-transfers/internal-transfers.js +1 -1
  158. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +3 -3
  159. package/dist/services/lifecycle/lifecycle.js +3 -3
  160. package/dist/services/lifecycle/lifecycle.schemas.d.ts +40 -40
  161. package/dist/services/lifecycle/lifecycle.schemas.js +2 -2
  162. package/dist/services/market-data/market-data.d.ts +7 -1
  163. package/dist/services/market-data/market-data.d.ts.map +1 -1
  164. package/dist/services/market-data/market-data.js +14 -3
  165. package/dist/services/market-data/market-data.js.map +1 -1
  166. package/dist/services/market-data/market-data.schemas.d.ts +108 -1
  167. package/dist/services/market-data/market-data.schemas.d.ts.map +1 -1
  168. package/dist/services/market-data/market-data.schemas.js +42 -2
  169. package/dist/services/market-data/market-data.schemas.js.map +1 -1
  170. package/dist/services/market-data/market-data.types.d.ts +2 -2
  171. package/dist/services/market-overview/market-overview.js +2 -2
  172. package/dist/services/market-overview/market-overview.schemas.js +1 -1
  173. package/dist/services/notifications/notifications.js +1 -1
  174. package/dist/services/notifications/notifications.schemas.d.ts +1 -1
  175. package/dist/services/orderbook/orderbook.js +1 -1
  176. package/dist/services/orders/order-errors.schemas.d.ts +2 -2
  177. package/dist/services/orders/order-errors.schemas.d.ts.map +1 -1
  178. package/dist/services/orders/order-errors.schemas.js +8 -5
  179. package/dist/services/orders/order-errors.schemas.js.map +1 -1
  180. package/dist/services/orders/orders-batch.schemas.d.ts +48 -48
  181. package/dist/services/orders/orders-batch.schemas.d.ts.map +1 -1
  182. package/dist/services/orders/orders-batch.schemas.js +5 -4
  183. package/dist/services/orders/orders-batch.schemas.js.map +1 -1
  184. package/dist/services/orders/orders-input.schemas.d.ts +8 -8
  185. package/dist/services/orders/orders-input.schemas.js +3 -3
  186. package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
  187. package/dist/services/orders/orders-modify.schemas.js +4 -3
  188. package/dist/services/orders/orders-modify.schemas.js.map +1 -1
  189. package/dist/services/orders/orders-output.schemas.d.ts +17 -17
  190. package/dist/services/orders/orders-output.schemas.d.ts.map +1 -1
  191. package/dist/services/orders/orders-output.schemas.js +2 -10
  192. package/dist/services/orders/orders-output.schemas.js.map +1 -1
  193. package/dist/services/orders/orders-risk.schemas.js +3 -3
  194. package/dist/services/orders/orders.d.ts +6 -0
  195. package/dist/services/orders/orders.d.ts.map +1 -1
  196. package/dist/services/orders/orders.js +6 -2
  197. package/dist/services/orders/orders.js.map +1 -1
  198. package/dist/services/policies/api-key-policies/api-key-policies.js +1 -1
  199. package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -15
  200. package/dist/services/policies/shared.codecs.js +7 -4
  201. package/dist/services/policies/shared.codecs.js.map +1 -1
  202. package/dist/services/policies/shared.d.ts +1 -1
  203. package/dist/services/policies/subaccount-policies/subaccount-policies.js +2 -2
  204. package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +3 -3
  205. package/dist/services/price-alerts/price-alerts.js +1 -1
  206. package/dist/services/price-alerts/price-alerts.schemas.d.ts +10 -10
  207. package/dist/services/rate-limits/rate-limits.js +1 -1
  208. package/dist/services/rewards/rewards.js +1 -1
  209. package/dist/services/rewards/rewards.schemas.d.ts +4 -4
  210. package/dist/services/social-verification/social-verification.js +1 -1
  211. package/dist/services/social-verification/social-verification.schemas.js +1 -1
  212. package/dist/services/subaccounts/subaccounts.codecs.js +2 -1
  213. package/dist/services/subaccounts/subaccounts.codecs.js.map +1 -1
  214. package/dist/services/subaccounts/subaccounts.js +3 -3
  215. package/dist/services/subaccounts/subaccounts.schemas.d.ts +13 -13
  216. package/dist/services/system/system.codecs.d.ts +20 -0
  217. package/dist/services/system/system.codecs.d.ts.map +1 -0
  218. package/dist/services/system/system.codecs.js +57 -0
  219. package/dist/services/system/system.codecs.js.map +1 -0
  220. package/dist/services/system/system.d.ts +7 -0
  221. package/dist/services/system/system.d.ts.map +1 -1
  222. package/dist/services/system/system.js +14 -1
  223. package/dist/services/system/system.js.map +1 -1
  224. package/dist/services/system/system.schemas.d.ts +234 -0
  225. package/dist/services/system/system.schemas.d.ts.map +1 -0
  226. package/dist/services/system/system.schemas.js +78 -0
  227. package/dist/services/system/system.schemas.js.map +1 -0
  228. package/dist/services/system/system.types.d.ts +4 -0
  229. package/dist/services/trades/trades.js +2 -2
  230. package/dist/services/trades/trades.schemas.d.ts +2 -2
  231. package/dist/services/trading-withdraws/service.js +1 -1
  232. package/dist/services/trading-withdraws/service.js.map +1 -1
  233. package/dist/services/trading-withdraws/trading-withdraws.d.ts +10 -12
  234. package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
  235. package/dist/services/trading-withdraws/trading-withdraws.js +28 -20
  236. package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
  237. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts +0 -5
  238. package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts.map +1 -1
  239. package/dist/services/trading-withdraws/trading-withdraws.schemas.js +1 -5
  240. package/dist/services/trading-withdraws/trading-withdraws.schemas.js.map +1 -1
  241. package/dist/services/trading-withdraws/wallet-message.js +2 -2
  242. package/dist/services/trading-withdraws/wallet-message.js.map +1 -1
  243. package/dist/services/transfers/transfers.js +2 -2
  244. package/dist/services/triggers/trigger-child-order.schemas.js +3 -3
  245. package/dist/services/triggers/trigger-input.schemas.d.ts +3 -3
  246. package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
  247. package/dist/services/triggers/trigger-input.schemas.js +6 -5
  248. package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
  249. package/dist/services/triggers/triggers-output.schemas.d.ts +47 -48
  250. package/dist/services/triggers/triggers-output.schemas.d.ts.map +1 -1
  251. package/dist/services/triggers/triggers-output.schemas.js +1 -1
  252. package/dist/services/triggers/triggers.js +2 -2
  253. package/dist/services/vip/vip.js +1 -1
  254. package/dist/services/vip/vip.schemas.js +1 -1
  255. package/dist/services/zipper/zipper.js +1 -1
  256. package/dist/services/zipper/zipper.schemas.d.ts +2 -2
  257. package/dist/services/zipper/zipper.schemas.d.ts.map +1 -1
  258. package/dist/services/zipper/zipper.schemas.js +10 -3
  259. package/dist/services/zipper/zipper.schemas.js.map +1 -1
  260. package/dist/services/zipper/zipper.types.d.ts +2 -2
  261. package/dist/shared/catalog-config.d.ts +13 -1
  262. package/dist/shared/catalog-config.d.ts.map +1 -1
  263. package/dist/shared/catalog-config.js +6 -1
  264. package/dist/shared/catalog-config.js.map +1 -1
  265. package/dist/shared/error-details/alerts.js +1 -1
  266. package/dist/shared/error-details/assistant.js +1 -1
  267. package/dist/shared/error-details/auth.js +1 -1
  268. package/dist/shared/error-details/claims.js +1 -1
  269. package/dist/shared/error-details/internal-transfer.js +1 -1
  270. package/dist/shared/error-details/ledger.js +1 -1
  271. package/dist/shared/error-details/market-overview.js +1 -1
  272. package/dist/shared/error-details/notifications.js +1 -1
  273. package/dist/shared/error-details/orders.js +1 -1
  274. package/dist/shared/error-details/profile.js +1 -1
  275. package/dist/shared/error-details/rate-limit.js +1 -1
  276. package/dist/shared/error-details/withdraw.js +1 -1
  277. package/dist/shared/rate-limit.schemas.d.ts +1 -1
  278. package/dist/shared/rate-limit.schemas.js +1 -1
  279. package/dist/shared/transports.d.ts +2 -1
  280. package/dist/shared/transports.d.ts.map +1 -1
  281. package/dist/shared/transports.js +52 -9
  282. package/dist/shared/transports.js.map +1 -1
  283. package/dist/utils/base58-id.js +1 -1
  284. package/dist/utils/base58-id.js.map +1 -1
  285. package/dist/utils/cookies.js +1 -1
  286. package/dist/utils/numbers.js +3 -2
  287. package/dist/utils/numbers.js.map +1 -1
  288. package/dist/wired-services.js +17 -17
  289. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.schemas.d.ts","names":[],"sources":["../../../src/services/system/system.schemas.ts"],"mappings":";;;cAYa,6BAA2B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;KAkB5B,wBAAwB,EAAE,kBAAkB;;cAU3C,mBAAiB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgDlB,cAAc,EAAE,mBAAmB;cAElC,8BAA4B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAM7B,yBAAyB,EAAE,mBAAmB"}
@@ -0,0 +1,78 @@
1
+ import { OptionalTimestampMsSchema, PublicIdSchema } from "../../shared/schemas.js";
2
+ import { enumLabelSchema } from "../../shared/proto-enum-codec.js";
3
+ import { STATUS_EVENT_KIND_VALUES, STATUS_EVENT_STATE_VALUES, StatusEventImpactCodec, StatusEventKindCodec, StatusEventServiceCodec, StatusEventStateCodec } from "./system.codecs.js";
4
+ import * as v from "valibot";
5
+ //#region src/services/system/system.schemas.ts
6
+ const ListStatusEventsInputSchema = v.pipe(v.strictObject({
7
+ /** States to include; omit or empty for current and upcoming (`scheduled`, `in_progress`). */
8
+ states: v.optional(v.array(v.picklist(STATUS_EVENT_STATE_VALUES))),
9
+ /** Kinds to include; omit or empty for both. */
10
+ kinds: v.optional(v.array(v.picklist(STATUS_EVENT_KIND_VALUES))),
11
+ /** Page size: default 50, at most 200. */
12
+ limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(200))),
13
+ /** Previous `nextPageToken`; resend the same `states` and `kinds` with it. */
14
+ pageToken: v.optional(v.pipe(v.string(), v.trim()))
15
+ }), v.transform(({ states, kinds, ...input }) => ({
16
+ ...input,
17
+ states: states?.map((state) => StatusEventStateCodec.inputToProto[state]),
18
+ kinds: kinds?.map((kind) => StatusEventKindCodec.inputToProto[kind])
19
+ })));
20
+ const StatusEventUpdateSchema = v.object({
21
+ /** Position on its event: 1 for the first note, then increasing by 1. */
22
+ id: v.number(),
23
+ message: v.string(),
24
+ createdAt: OptionalTimestampMsSchema
25
+ });
26
+ /** One scheduled maintenance or incident. Times are epoch milliseconds. */
27
+ const StatusEventSchema = v.pipe(v.object({
28
+ id: PublicIdSchema,
29
+ kind: enumLabelSchema(StatusEventKindCodec.protoToOutput),
30
+ state: enumLabelSchema(StatusEventStateCodec.protoToOutput),
31
+ title: v.string(),
32
+ message: v.string(),
33
+ startTime: OptionalTimestampMsSchema,
34
+ endTime: OptionalTimestampMsSchema,
35
+ services: v.array(enumLabelSchema(StatusEventServiceCodec.protoToOutput)),
36
+ markets: v.array(v.string()),
37
+ updatedAt: OptionalTimestampMsSchema,
38
+ impact: enumLabelSchema(StatusEventImpactCodec.protoToOutput),
39
+ assets: v.array(v.string()),
40
+ cancelledAt: OptionalTimestampMsSchema,
41
+ updates: v.array(StatusEventUpdateSchema),
42
+ detailsUrl: v.optional(v.string())
43
+ }), v.transform((event) => ({
44
+ /** Stable across updates; match events across pages by it. */
45
+ id: event.id,
46
+ kind: event.kind,
47
+ state: event.state,
48
+ title: event.title,
49
+ message: event.message,
50
+ startTime: event.startTime ?? null,
51
+ /** Always set for maintenance; null for an incident with no expected end yet. */
52
+ endTime: event.endTime ?? null,
53
+ services: event.services,
54
+ /** Affected market symbols such as `"BTC-USDT"`; empty when not limited to markets. */
55
+ markets: event.markets,
56
+ /** Affected asset codes such as `"SOL"`; empty when not limited to assets. */
57
+ assets: event.assets,
58
+ /** Incident severity; null for maintenance and an incident not yet assessed. */
59
+ impact: event.impact === "unspecified" ? null : event.impact,
60
+ updatedAt: event.updatedAt ?? null,
61
+ /** Set only when `state` is `"canceled"`. */
62
+ canceledAt: event.cancelledAt ?? null,
63
+ /** Progress notes, oldest first. */
64
+ updates: event.updates.map((update) => ({
65
+ ...update,
66
+ createdAt: update.createdAt ?? null
67
+ })),
68
+ /** HTTPS link to a long-form announcement; null when there is none. */
69
+ detailsUrl: event.detailsUrl ?? null
70
+ })));
71
+ const ListStatusEventsResultSchema = v.object({
72
+ events: v.array(StatusEventSchema),
73
+ nextPageToken: v.optional(v.string(), "")
74
+ });
75
+ //#endregion
76
+ export { ListStatusEventsInputSchema, ListStatusEventsResultSchema, StatusEventSchema };
77
+
78
+ //# sourceMappingURL=system.schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.schemas.js","names":[],"sources":["../../../src/services/system/system.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { enumLabelSchema } from \"../../shared/proto-enum-codec.js\";\nimport { OptionalTimestampMsSchema, PublicIdSchema } from \"../../shared/schemas.js\";\nimport {\n STATUS_EVENT_KIND_VALUES,\n STATUS_EVENT_STATE_VALUES,\n StatusEventImpactCodec,\n StatusEventKindCodec,\n StatusEventServiceCodec,\n StatusEventStateCodec,\n} from \"./system.codecs.js\";\n\nexport const ListStatusEventsInputSchema = v.pipe(\n v.strictObject({\n /** States to include; omit or empty for current and upcoming (`scheduled`, `in_progress`). */\n states: v.optional(v.array(v.picklist(STATUS_EVENT_STATE_VALUES))),\n /** Kinds to include; omit or empty for both. */\n kinds: v.optional(v.array(v.picklist(STATUS_EVENT_KIND_VALUES))),\n /** Page size: default 50, at most 200. */\n limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(200))),\n /** Previous `nextPageToken`; resend the same `states` and `kinds` with it. */\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n }),\n v.transform(({ states, kinds, ...input }) => ({\n ...input,\n states: states?.map((state) => StatusEventStateCodec.inputToProto[state]),\n kinds: kinds?.map((kind) => StatusEventKindCodec.inputToProto[kind]),\n })),\n);\n\nexport type ListStatusEventsInput = v.InferInput<typeof ListStatusEventsInputSchema>;\n\nconst StatusEventUpdateSchema = v.object({\n /** Position on its event: 1 for the first note, then increasing by 1. */\n id: v.number(),\n message: v.string(),\n createdAt: OptionalTimestampMsSchema,\n});\n\n/** One scheduled maintenance or incident. Times are epoch milliseconds. */\nexport const StatusEventSchema = v.pipe(\n v.object({\n id: PublicIdSchema,\n kind: enumLabelSchema(StatusEventKindCodec.protoToOutput),\n state: enumLabelSchema(StatusEventStateCodec.protoToOutput),\n title: v.string(),\n message: v.string(),\n startTime: OptionalTimestampMsSchema,\n endTime: OptionalTimestampMsSchema,\n services: v.array(enumLabelSchema(StatusEventServiceCodec.protoToOutput)),\n markets: v.array(v.string()),\n updatedAt: OptionalTimestampMsSchema,\n impact: enumLabelSchema(StatusEventImpactCodec.protoToOutput),\n assets: v.array(v.string()),\n cancelledAt: OptionalTimestampMsSchema,\n updates: v.array(StatusEventUpdateSchema),\n detailsUrl: v.optional(v.string()),\n }),\n v.transform((event) => ({\n /** Stable across updates; match events across pages by it. */\n id: event.id,\n kind: event.kind,\n state: event.state,\n title: event.title,\n message: event.message,\n startTime: event.startTime ?? null,\n /** Always set for maintenance; null for an incident with no expected end yet. */\n endTime: event.endTime ?? null,\n services: event.services,\n /** Affected market symbols such as `\"BTC-USDT\"`; empty when not limited to markets. */\n markets: event.markets,\n /** Affected asset codes such as `\"SOL\"`; empty when not limited to assets. */\n assets: event.assets,\n /** Incident severity; null for maintenance and an incident not yet assessed. */\n impact: event.impact === \"unspecified\" ? null : event.impact,\n updatedAt: event.updatedAt ?? null,\n /** Set only when `state` is `\"canceled\"`. */\n canceledAt: event.cancelledAt ?? null,\n /** Progress notes, oldest first. */\n updates: event.updates.map((update) => ({\n ...update,\n createdAt: update.createdAt ?? null,\n })),\n /** HTTPS link to a long-form announcement; null when there is none. */\n detailsUrl: event.detailsUrl ?? null,\n })),\n);\n\nexport type StatusEvent = v.InferOutput<typeof StatusEventSchema>;\n\nexport const ListStatusEventsResultSchema = v.object({\n events: v.array(StatusEventSchema),\n nextPageToken: v.optional(v.string(), \"\"),\n});\n\n/** One page of events, latest start first; an empty `nextPageToken` means no more. */\nexport type ListStatusEventsResult = v.InferOutput<typeof ListStatusEventsResultSchema>;\n"],"mappings":";;;;;AAYA,MAAa,8BAA8B,EAAE,KACzC,EAAE,a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;CACb,SAAS,MAAM;CACf,WAAW,MAAM,aAAa;;CAE9B,SAAS,MAAM,WAAW;CAC1B,UAAU,MAAM;;CAEhB,SAAS,MAAM;;CAEf,QAAQ,MAAM;;CAEd,QAAQ,MAAM,WAAW,gBAAgB,OAAO,MAAM;CACtD,WAAW,MAAM,aAAa;;CAE9B,YAAY,MAAM,eAAe;;CAEjC,SAAS,MAAM,QAAQ,KAAK,YAAY;EACpC,GAAG;EACH,WAAW,OAAO,aAAa;CACnC,EAAE;;CAEF,YAAY,MAAM,cAAc;AACpC,EAAE,CACN;AAIA,MAAa,+BAA+B,EAAE,OAAO;CACjD,QAAQ,EAAE,MAAM,iBAAiB;CACjC,eAAe,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;AAC5C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ListStatusEventsInput, ListStatusEventsResult, StatusEvent } from "./system.schemas.js";
2
+ import { SystemVersion } from "./system.js";
3
+ import { StatusEventImpact, StatusEventKind, StatusEventService, StatusEventState } from "./system.codecs.js";
4
+ export type { ListStatusEventsInput, ListStatusEventsResult, StatusEvent, StatusEventImpact, StatusEventKind, StatusEventService, StatusEventState, SystemVersion };
@@ -1,14 +1,14 @@
1
+ import { OrdersReadService, UserTradeBatchSchema } from "../../gen/orders/v1/orders_read_pb.js";
1
2
  import { parse } from "../../shared/validation.js";
2
3
  import { removeUndefined } from "../../utils/remove-undefined.js";
3
4
  import { toConnectCallOptions } from "../../shared/request-options.js";
4
5
  import { deliverBatch } from "../../shared/subscription-errors.js";
5
6
  import { resolveAccountScopedInput } from "../subaccount-resolver.js";
6
- import { OrdersReadService, UserTradeBatchSchema } from "../../gen/orders/v1/orders_read_pb.js";
7
7
  import { GetUserTradesInputSchema, formatUserTrade } from "./trades.schemas.js";
8
8
  import { createOrderTransferSchema } from "../orders/orders-output.schemas.js";
9
9
  import { connectReadyGatedProtoChannel } from "../../realtime/ready-gated-subscription.js";
10
- import { createClient } from "@connectrpc/connect";
11
10
  import * as v from "valibot";
11
+ import { createClient } from "@connectrpc/connect";
12
12
  //#region src/services/trades/trades.ts
13
13
  /**
14
14
  * Reads and streams authenticated user trade fills.
@@ -63,7 +63,7 @@ declare function createUserTradeSchema(scales: SdkScales): v.SchemaWithPipe<read
63
63
  referralShare?: string | undefined;
64
64
  orderId: string;
65
65
  symbolId: number;
66
- sideLabel: "unspecified" | "buy" | "sell";
66
+ sideLabel: "buy" | "sell" | "unspecified";
67
67
  liquidityLabel: "maker" | "taker";
68
68
  feeAsset: "unspecified" | "quote" | "base";
69
69
  qty: string;
@@ -169,7 +169,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
169
169
  readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
170
170
  readonly lineageId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
171
171
  readonly throughGeneration: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
172
- }, undefined>], undefined>], ({ input }: v.UnionIssue<v.StringIssue | v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1>> | v.GtValueIssue<number, 0> | v.CheckIssue<bigint> | v.MaxValueIssue<number, 1000> | v.NeverIssue | v.UnionIssue<v.StringIssue | v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1>> | v.GtValueIssue<number, 0> | v.CheckIssue<bigint> | v.MaxValueIssue<number, 1000> | v.NeverIssue>>) => "Provide at most one of orderId or lineageId" | "throughGeneration requires lineageId" | "symbolId is required when afterMatchId is set" | "Invalid trade filters">, v.TransformAction<{
172
+ }, undefined>], undefined>], ({ input }: v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1>> | v.GtValueIssue<number, 0> | v.CheckIssue<bigint> | v.MaxValueIssue<number, 1000> | v.NeverIssue | v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1>> | v.GtValueIssue<number, 0> | v.CheckIssue<bigint> | v.MaxValueIssue<number, 1000> | v.NeverIssue>>) => "Provide at most one of orderId or lineageId" | "throughGeneration requires lineageId" | "symbolId is required when afterMatchId is set" | "Invalid trade filters">, v.TransformAction<{
173
173
  symbolId?: number | undefined;
174
174
  afterMatchId?: undefined;
175
175
  side?: Side.BUY | Side.SELL | undefined;
@@ -5,7 +5,7 @@ import { TradingWithdrawsService } from "./trading-withdraws.js";
5
5
  const tradingWithdrawsService = defineService((context) => new TradingWithdrawsService(context.transports, context.resolver, {
6
6
  chainId: context.environment.chain.id,
7
7
  tradingGatewayAddress: context.environment.contracts.tradingGatewayAddress
8
- }, context.scales, context.catalog));
8
+ }, context.scales, context.catalog, context.auth));
9
9
  //#endregion
10
10
  export { tradingWithdrawsService };
11
11
 
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","names":[],"sources":["../../../src/services/trading-withdraws/service.ts"],"sourcesContent":["import { defineService } from \"../../core-client.js\";\nimport { TradingWithdrawsService } from \"./trading-withdraws.js\";\n\n/** Returns the client's TradingWithdrawsService, creating it on first use. */\nexport const tradingWithdrawsService = defineService(\n (context) =>\n new TradingWithdrawsService(\n context.transports,\n context.resolver,\n {\n chainId: context.environment.chain.id,\n tradingGatewayAddress: context.environment.contracts.tradingGatewayAddress,\n },\n context.scales,\n context.catalog,\n ),\n);\n"],"mappings":";;;;AAIA,MAAa,0BAA0B,eAClC,YACG,IAAI,wBACA,QAAQ,YACR,QAAQ,UACR;CACI,SAAS,QAAQ,YAAY,MAAM;CACnC,uBAAuB,QAAQ,YAAY,UAAU;AACzD,GACA,QAAQ,QACR,QAAQ,OACZ,CACR"}
1
+ {"version":3,"file":"service.js","names":[],"sources":["../../../src/services/trading-withdraws/service.ts"],"sourcesContent":["import { defineService } from \"../../core-client.js\";\nimport { TradingWithdrawsService } from \"./trading-withdraws.js\";\n\n/** Returns the client's TradingWithdrawsService, creating it on first use. */\nexport const tradingWithdrawsService = defineService(\n (context) =>\n new TradingWithdrawsService(\n context.transports,\n context.resolver,\n {\n chainId: context.environment.chain.id,\n tradingGatewayAddress: context.environment.contracts.tradingGatewayAddress,\n },\n context.scales,\n context.catalog,\n context.auth,\n ),\n);\n"],"mappings":";;;;AAIA,MAAa,0BAA0B,eAClC,YACG,IAAI,wBACA,QAAQ,YACR,QAAQ,UACR;CACI,SAAS,QAAQ,YAAY,MAAM;CACnC,uBAAuB,QAAQ,YAAY,UAAU;AACzD,GACA,QAAQ,QACR,QAAQ,SACR,QAAQ,IACZ,CACR"}
@@ -1,5 +1,5 @@
1
1
  import { ClientCatalog } from "../../catalogs/types.js";
2
- import { AuthApiTransports } from "../../shared/transports.js";
2
+ import { ApiKeyEd25519AuthProvider, AuthApiTransports, JwtAuthProvider } from "../../shared/transports.js";
3
3
  import { PolyesterMutationOptions, PolyesterRequestOptions } from "../../shared/request-options.js";
4
4
  import { SubaccountResolver } from "../subaccount-resolver.js";
5
5
  import { SdkScales } from "../../shared/decimal-surface.js";
@@ -29,26 +29,24 @@ type PreparedTradingWithdraw = Readonly<{
29
29
  /** When the backend stops accepting the currently signed request. */
30
30
  deadline: Date;
31
31
  /**
32
- * True once the deadline is less than a minute away. Wallet-signed
33
- * withdraws sign again on `submit` from then on, so callers can keep resubmitting the
34
- * same prepared withdraw, e.g. after a slow MFA step-up. Payload-signed withdraws
35
- * cannot be signed again: prepare again (same input, same idempotency key) instead.
32
+ * True once the deadline is less than a minute away. The withdraw signs again on
33
+ * `submit` from then on, so callers can keep resubmitting the same prepared withdraw,
34
+ * e.g. after a slow MFA step-up.
36
35
  */
37
36
  isExpired: () => boolean;
38
37
  /**
39
38
  * Submits the payload and signature produced during preparation. Repeated calls only
40
- * change transport options such as the step-up token, unless the deadline is near:
41
- * wallet-signed withdraws then sign a fresh deadline and nonce with the same idempotency
42
- * key, and payload-signed withdraws throw `WithdrawDeadlineExpiredError` once it passes.
39
+ * change transport options such as the step-up token, unless the deadline is near: the
40
+ * withdraw then signs a fresh deadline and nonce with the same idempotency key.
43
41
  */
44
42
  submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;
45
43
  }>;
46
44
  /**
47
- * Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-191 signatures.
45
+ * Creates durable Trading withdrawal intents, signed by the client's API key or a wallet (EIP-191).
48
46
  */
49
47
  declare class TradingWithdrawsService {
50
48
  #private;
51
- constructor(transports: AuthApiTransports, resolver: SubaccountResolver | undefined, signingConfig: TradingWithdrawSigningConfig, scales: SdkScales, catalog?: ClientCatalog);
49
+ constructor(transports: AuthApiTransports, resolver: SubaccountResolver | undefined, signingConfig: TradingWithdrawSigningConfig, scales: SdkScales, catalog?: ClientCatalog, auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider);
52
50
  /**
53
51
  * Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a
54
52
  * rejected withdrawal's refund (see the lifecycle step's `refundAddress`), which stays there
@@ -60,7 +58,7 @@ declare class TradingWithdrawsService {
60
58
  */
61
59
  validateDestination(input: ValidateWithdrawDestinationInput, options?: PolyesterRequestOptions): Promise<ValidateWithdrawDestinationResult>;
62
60
  /**
63
- * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.
61
+ * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.
64
62
  */
65
63
  createToFunding(input: CreateTradingWithdrawToFundingServiceInput, options?: PolyesterMutationOptions): Promise<CreateTradingWithdrawResult>;
66
64
  /**
@@ -69,7 +67,7 @@ declare class TradingWithdrawsService {
69
67
  */
70
68
  prepareToFunding(input: CreateTradingWithdrawToFundingServiceInput): Promise<PreparedTradingWithdraw>;
71
69
  /**
72
- * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.
70
+ * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.
73
71
  */
74
72
  createToExternalChain(input: CreateTradingWithdrawToExternalChainServiceInput, options?: PolyesterMutationOptions): Promise<CreateTradingWithdrawResult>;
75
73
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"mappings":";;;;;;;;KAwCY;EACR;EACA;;;;;EAKA,cAAc,oBAAoB,QAAQ;;KAGlC;EACR;EACA,uBAAuB;;KAGf,6CAA6C;EACrD,eAAe;;KAGP,mDACR;EACI,eAAe;;KAGX,0BAA0B;;EAElC,UAAU;;;;;;;EAOV;;;;;;;EAOA,SAAS,UAAU,6BAA6B,QAAQ;;;;;cAwG/C;;EAYL,YAAA,YAAY,mBACZ,UAAU,gCACV,eAAe,8BACf,QAAQ,WACR,UAAU;;;;;;EAiBR,kBACF,QAAO,wBACP,UAAU,0BACX,QAAQ;;;;EAeL,oBACF,OAAO,kCACP,UAAU,0BACX,QAAQ;;;;EAYL,gBACF,OAAO,4CACP,UAAU,2BACX,QAAQ;;;;;EASL,iBACF,OAAO,6CACR,QAAQ;;;;EAWL,sBACF,OAAO,kDACP,UAAU,2BACX,QAAQ;;;;;EASL,uBACF,OAAO,mDACR,QAAQ"}
1
+ {"version":3,"file":"trading-withdraws.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"mappings":";;;;;;;;KA8CY;EACR;EACA;;;;;EAKA,cAAc,oBAAoB,QAAQ;;KAGlC;EACR;EACA,uBAAuB;;KAGf,6CAA6C;EACrD,eAAe;;KAGP,mDACR;EACI,eAAe;;KAGX,0BAA0B;;EAElC,UAAU;;;;;;EAMV;;;;;;EAMA,SAAS,UAAU,6BAA6B,QAAQ;;;;;cAoG/C;;EAaL,YAAA,YAAY,mBACZ,UAAU,gCACV,eAAe,8BACf,QAAQ,WACR,UAAU,eACV,OAAO,kBAAkB;;;;;;EAkBvB,kBACF,QAAO,wBACP,UAAU,0BACX,QAAQ;;;;EAeL,oBACF,OAAO,kCACP,UAAU,0BACX,QAAQ;;;;EAYL,gBACF,OAAO,4CACP,UAAU,2BACX,QAAQ;;;;;EASL,iBACF,OAAO,6CACR,QAAQ;;;;EAWL,sBACF,OAAO,kDACP,UAAU,2BACX,QAAQ;;;;;EASL,uBACF,OAAO,mDACR,QAAQ"}
@@ -1,13 +1,15 @@
1
- import { ValidationError, WithdrawDeadlineExpiredError } from "../../shared/errors.js";
1
+ import { TradingWithdrawIntentPayloadSchema, WithdrawService } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
2
+ import { ConfigurationError, ValidationError } from "../../shared/errors.js";
3
+ import { signApiKeyEd25519Payload } from "../../shared/transports.js";
2
4
  import { checksumEvmAddress, evmHexToBytes } from "../../utils/evm.js";
3
5
  import { parse } from "../../shared/validation.js";
4
6
  import { removeUndefined } from "../../utils/remove-undefined.js";
5
7
  import { toConnectCallOptions } from "../../shared/request-options.js";
6
8
  import { idToBigInt } from "../../utils/base58-id.js";
7
9
  import { resolveAccountScopedInput } from "../subaccount-resolver.js";
8
- import { WithdrawService } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
9
10
  import { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, GetWalletBalancesInputSchema, GetWalletBalancesResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload } from "./trading-withdraws.schemas.js";
10
11
  import { buildTradingWithdrawWalletMessage } from "./wallet-message.js";
12
+ import { create, toBinary } from "@bufbuild/protobuf";
11
13
  import { createClient } from "@connectrpc/connect";
12
14
  //#region src/services/trading-withdraws/trading-withdraws.ts
13
15
  const PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 6e4;
@@ -23,8 +25,7 @@ function preparedWithdraw(signed, resign) {
23
25
  },
24
26
  isExpired,
25
27
  submit: async (options) => {
26
- if (resign && isExpired()) current = await resign(renewTradingWithdrawPayload(current.payload));
27
- else if (Date.now() >= deadlineMs(current.payload)) throw new WithdrawDeadlineExpiredError("Withdraw signature deadline has passed. Prepare the withdraw again.");
28
+ if (isExpired()) current = await resign(renewTradingWithdrawPayload(current.payload));
28
29
  return current.send(options);
29
30
  }
30
31
  };
@@ -64,7 +65,7 @@ async function resolveWalletSignature(params) {
64
65
  };
65
66
  }
66
67
  /**
67
- * Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-191 signatures.
68
+ * Creates durable Trading withdrawal intents, signed by the client's API key or a wallet (EIP-191).
68
69
  */
69
70
  var TradingWithdrawsService = class {
70
71
  #client;
@@ -72,10 +73,12 @@ var TradingWithdrawsService = class {
72
73
  #signingConfig;
73
74
  #catalog;
74
75
  #scales;
76
+ #auth;
75
77
  #toFundingInputSchema;
76
78
  #toExternalChainInputSchema;
77
- constructor(transports, resolver, signingConfig, scales, catalog) {
79
+ constructor(transports, resolver, signingConfig, scales, catalog, auth) {
78
80
  this.#client = createClient(WithdrawService, transports.authApi);
81
+ this.#auth = auth;
79
82
  this.#resolver = resolver;
80
83
  this.#signingConfig = signingConfig;
81
84
  this.#catalog = catalog;
@@ -102,7 +105,7 @@ var TradingWithdrawsService = class {
102
105
  return parse(ValidateWithdrawDestinationResultSchema, response);
103
106
  }
104
107
  /**
105
- * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.
108
+ * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.
106
109
  */
107
110
  async createToFunding(input, options) {
108
111
  return (await this.prepareToFunding(input)).submit(options);
@@ -119,7 +122,7 @@ var TradingWithdrawsService = class {
119
122
  return this.#prepareWithdraw(validated, walletSigner);
120
123
  }
121
124
  /**
122
- * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.
125
+ * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.
123
126
  */
124
127
  async createToExternalChain(input, options) {
125
128
  return (await this.prepareToExternalChain(input)).submit(options);
@@ -168,18 +171,23 @@ var TradingWithdrawsService = class {
168
171
  };
169
172
  return preparedWithdraw(await sign(validated.payload), sign);
170
173
  }
171
- if (!validated.payloadSignature) throw new ValidationError("Trading withdraw requires a wallet signer or payload signature.");
172
- const request = removeUndefined({
173
- payload: validated.payload,
174
- payloadSignature: validated.payloadSignature
175
- });
176
- return preparedWithdraw({
177
- payload: validated.payload,
178
- send: async (options) => {
179
- const response = await this.#client.createTradingWithdraw(request, toConnectCallOptions(options));
180
- return parse(CreateTradingWithdrawResultSchema, response);
181
- }
182
- });
174
+ const auth = this.#auth;
175
+ if (auth?.kind !== "api-key-ed25519") throw new ConfigurationError("Trading withdraw requires a wallet signer or API-key auth.");
176
+ if (validated.subaccountId !== void 0) throw new ValidationError("API-key trading withdraws cannot target a subaccount. Use `account: \"main\"` or a wallet signer.");
177
+ const sign = async (payload) => {
178
+ const payloadSignature = await signApiKeyEd25519Payload(auth, toBinary(TradingWithdrawIntentPayloadSchema, create(TradingWithdrawIntentPayloadSchema, payload)));
179
+ return {
180
+ payload,
181
+ send: async (options) => {
182
+ const response = await this.#client.createTradingWithdraw({
183
+ payload,
184
+ payloadSignature
185
+ }, toConnectCallOptions(options));
186
+ return parse(CreateTradingWithdrawResultSchema, response);
187
+ }
188
+ };
189
+ };
190
+ return preparedWithdraw(await sign(validated.payload), sign);
183
191
  }
184
192
  };
185
193
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","#prepareWithdraw"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ValidationError, WithdrawDeadlineExpiredError } from \"../../shared/errors.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport { checksumEvmAddress, evmHexToBytes } from \"../../utils/evm.js\";\nimport type { ClientCatalog } from \"../../catalogs/types.js\";\nimport * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n GetWalletBalancesInputSchema,\n GetWalletBalancesResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n renewTradingWithdrawPayload,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\n type GetWalletBalancesInput,\n type GetWalletBalancesResult,\n type TradingWithdrawIntentPayloadRequest,\n type ValidateWithdrawDestinationInput,\n type ValidateWithdrawDestinationResult,\n} from \"./trading-withdraws.schemas.js\";\nimport { buildTradingWithdrawWalletMessage } from \"./wallet-message.js\";\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n /**\n * Signs the UTF-8 message directly using EIP-191 personal_sign, without pre-hashing or switching chains.\n * For a viem account, use `(message) => account.signMessage({ message })`.\n */\n signMessage: (message: string) => Promise<Hex>;\n};\n\nexport type TradingWithdrawSigningConfig = {\n chainId: number;\n tradingGatewayAddress: Address;\n};\n\nexport type CreateTradingWithdrawToFundingServiceInput = CreateTradingWithdrawToFundingInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n};\n\nexport type CreateTradingWithdrawToExternalChainServiceInput =\n CreateTradingWithdrawToExternalChainInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n };\n\nexport type PreparedTradingWithdraw = Readonly<{\n /** When the backend stops accepting the currently signed request. */\n deadline: Date;\n /**\n * True once the deadline is less than a minute away. Wallet-signed\n * withdraws sign again on `submit` from then on, so callers can keep resubmitting the\n * same prepared withdraw, e.g. after a slow MFA step-up. Payload-signed withdraws\n * cannot be signed again: prepare again (same input, same idempotency key) instead.\n */\n isExpired: () => boolean;\n /**\n * Submits the payload and signature produced during preparation. Repeated calls only\n * change transport options such as the step-up token, unless the deadline is near:\n * wallet-signed withdraws then sign a fresh deadline and nonce with the same idempotency\n * key, and payload-signed withdraws throw `WithdrawDeadlineExpiredError` once it passes.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype SignedTradingWithdraw = {\n payload: TradingWithdrawIntentPayloadRequest;\n send: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n};\n\n// Leaves room for the request to reach the backend and for modest clock skew.\nconst PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 60_000;\n\nfunction deadlineMs(payload: TradingWithdrawIntentPayloadRequest): number {\n return Number(payload.deadlineTsSec) * 1000;\n}\n\nfunction preparedWithdraw(\n signed: SignedTradingWithdraw,\n resign?: (payload: TradingWithdrawIntentPayloadRequest) => Promise<SignedTradingWithdraw>,\n): PreparedTradingWithdraw {\n let current = signed;\n const isExpired = () =>\n Date.now() >= deadlineMs(current.payload) - PREPARED_WITHDRAW_EXPIRY_MARGIN_MS;\n return {\n get deadline() {\n return new Date(deadlineMs(current.payload));\n },\n isExpired,\n submit: async (options) => {\n if (resign && isExpired()) {\n current = await resign(renewTradingWithdrawPayload(current.payload));\n } else if (Date.now() >= deadlineMs(current.payload)) {\n throw new WithdrawDeadlineExpiredError(\n \"Withdraw signature deadline has passed. Prepare the withdraw again.\",\n );\n }\n return current.send(options);\n },\n };\n}\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction resolveTradingWithdrawTargetAccountId(params: {\n subaccountId: bigint | undefined;\n rootAccountId: string;\n}): bigint {\n if (params.subaccountId !== undefined) return params.subaccountId;\n return idToBigInt(params.rootAccountId, \"targetAccountId\");\n}\n\nasync function resolveTradingWithdrawSigningConfig(params: {\n fallback: TradingWithdrawSigningConfig;\n catalog?: ClientCatalog;\n}): Promise<TradingWithdrawSigningConfig> {\n if (!params.catalog) return params.fallback;\n\n try {\n await params.catalog.ensureReady();\n const gateway = params.catalog.zipper.getContractByName(\"tradingGateway\");\n const address = gateway?.address?.trim();\n if (!address?.startsWith(\"0x\")) return params.fallback;\n\n return {\n chainId: params.fallback.chainId,\n tradingGatewayAddress: checksumEvmAddress(address),\n };\n } catch {\n return params.fallback;\n }\n}\n\nasync function resolveWalletSignature(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n walletSigner: TradingWithdrawWalletSigner;\n targetAccountId: bigint;\n}): Promise<{ signerWallet: string; payloadSignature: Uint8Array }> {\n const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signMessage(\n buildTradingWithdrawWalletMessage({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet,\n accountId,\n targetAccountId: params.targetAccountId,\n }),\n );\n if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) {\n throw new ValidationError(\n \"Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.\",\n );\n }\n return {\n signerWallet,\n payloadSignature: evmHexToBytes(signature),\n };\n}\n\n/**\n * Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-191 signatures.\n */\nexport class TradingWithdrawsService {\n #client: Client<typeof Proto.WithdrawService>;\n #resolver?: SubaccountResolver;\n #signingConfig: TradingWithdrawSigningConfig;\n #catalog?: ClientCatalog;\n #scales: SdkScales;\n #toFundingInputSchema: ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>;\n #toExternalChainInputSchema: ReturnType<\n typeof createCreateTradingWithdrawToExternalChainInputSchema\n >;\n\n constructor(\n transports: AuthApiTransports,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n ) {\n this.#client = createClient(Proto.WithdrawService, transports.authApi);\n this.#resolver = resolver;\n this.#signingConfig = signingConfig;\n this.#catalog = catalog;\n this.#scales = scales;\n this.#toFundingInputSchema = createCreateTradingWithdrawToFundingInputSchema(scales);\n this.#toExternalChainInputSchema =\n createCreateTradingWithdrawToExternalChainInputSchema(scales);\n }\n\n /**\n * Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a\n * rejected withdrawal's refund (see the lifecycle step's `refundAddress`), which stays there\n * until moved. API keys need `read-balances`.\n */\n async getWalletBalances(\n input: GetWalletBalancesInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<GetWalletBalancesResult> {\n const request = parse(\n GetWalletBalancesInputSchema,\n resolveAccountScopedInput(input, this.#resolver),\n );\n const response = await this.#client.getWalletBalances(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(GetWalletBalancesResultSchema, response);\n }\n\n /**\n * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one. API keys need `read-withdraw-validation`.\n */\n async validateDestination(\n input: ValidateWithdrawDestinationInput,\n options?: PolyesterRequestOptions,\n ): Promise<ValidateWithdrawDestinationResult> {\n const request = parse(ValidateWithdrawDestinationInputSchema, input);\n const response = await this.#client.validateWithdrawDestination(\n request,\n toConnectCallOptions(options),\n );\n return parse(ValidateWithdrawDestinationResultSchema, response);\n }\n\n /**\n * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.\n */\n async createToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToFunding(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-Funding withdrawal once so the exact request can be\n * resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toFundingInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n /**\n * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.\n */\n async createToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToExternalChain(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-external-chain withdrawal once so the exact request can\n * be resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toExternalChainInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n async #prepareWithdraw(\n validated: TradingWithdrawRequest,\n walletSigner: TradingWithdrawWalletSigner | undefined,\n ): Promise<PreparedTradingWithdraw> {\n if (walletSigner) {\n const signingConfig = await resolveTradingWithdrawSigningConfig({\n fallback: this.#signingConfig,\n catalog: this.#catalog,\n });\n const targetAccountId = resolveTradingWithdrawTargetAccountId({\n subaccountId: validated.subaccountId,\n rootAccountId: walletSigner.accountId,\n });\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n\n if (!validated.payloadSignature) {\n throw new ValidationError(\n \"Trading withdraw requires a wallet signer or payload signature.\",\n );\n }\n\n const request = removeUndefined({\n payload: validated.payload,\n payloadSignature: validated.payloadSignature,\n });\n return preparedWithdraw({\n payload: validated.payload,\n send: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateTradingWithdrawResultSchema, response);\n },\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyFA,MAAM,qCAAqC;AAE3C,SAAS,WAAW,SAAsD;CACtE,OAAO,OAAO,QAAQ,aAAa,IAAI;AAC3C;AAEA,SAAS,iBACL,QACA,QACuB;CACvB,IAAI,UAAU;CACd,MAAM,kBACF,KAAK,IAAI,KAAK,WAAW,QAAQ,OAAO,IAAI;CAChD,OAAO;EACH,IAAI,WAAW;GACX,OAAO,IAAI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,SAAS;EAClF,MAAM,YAAY,MAAM,KAAKK,6BAA6B,aAAa;EACvE,OAAO,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;GACD,MAAM,OAAO,OACT,YACiC;IACjC,MAAM,kBAAkB,MAAM,uBAAuB;KACjD;KACA;KACA;KACA;IACJ,CAAC;IACD,MAAM,UAAU,gBAAgB;KAC5B;KACA,cAAc,UAAU;KACxB,cAAc,gBAAgB;KAC9B,kBAAkB,gBAAgB;IACtC,CAAC;IACD,OAAO;KACH;KACA,MAAM,OAAO,YAAY;MACrB,MAAM,WAAW,MAAM,KAAKJ,QAAQ,4BAChC,SACA,qBAAqB,OAAO,CAChC;MACA,OAAO,MAAM,yCAAyC,QAAQ;KAClE;IACJ;GACJ;GACA,OAAO,iBAAiB,MAAM,KAAK,UAAU,OAAO,GAAG,IAAI;EAC/D;EAEA,IAAI,CAAC,UAAU,kBACX,MAAM,IAAI,gBACN,iEACJ;EAGJ,MAAM,UAAU,gBAAgB;GAC5B,SAAS,UAAU;GACnB,kBAAkB,UAAU;EAChC,CAAC;EACD,OAAO,iBAAiB;GACpB,SAAS,UAAU;GACnB,MAAM,OAAO,YAAY;IACrB,MAAM,WAAW,MAAM,KAAKA,QAAQ,sBAChC,SACA,qBAAqB,OAAO,CAChC;IACA,OAAO,MAAM,mCAAmC,QAAQ;GAC5D;EACJ,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#auth","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","#prepareWithdraw","Proto.TradingWithdrawIntentPayloadSchema"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ConfigurationError, ValidationError } from \"../../shared/errors.js\";\nimport { create, toBinary } from \"@bufbuild/protobuf\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport { checksumEvmAddress, evmHexToBytes } from \"../../utils/evm.js\";\nimport type { ClientCatalog } from \"../../catalogs/types.js\";\nimport * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n signApiKeyEd25519Payload,\n type ApiKeyEd25519AuthProvider,\n type AuthApiTransports,\n type JwtAuthProvider,\n} from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n GetWalletBalancesInputSchema,\n GetWalletBalancesResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n renewTradingWithdrawPayload,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\n type GetWalletBalancesInput,\n type GetWalletBalancesResult,\n type TradingWithdrawIntentPayloadRequest,\n type ValidateWithdrawDestinationInput,\n type ValidateWithdrawDestinationResult,\n} from \"./trading-withdraws.schemas.js\";\nimport { buildTradingWithdrawWalletMessage } from \"./wallet-message.js\";\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n /**\n * Signs the UTF-8 message directly using EIP-191 personal_sign, without pre-hashing or switching chains.\n * For a viem account, use `(message) => account.signMessage({ message })`.\n */\n signMessage: (message: string) => Promise<Hex>;\n};\n\nexport type TradingWithdrawSigningConfig = {\n chainId: number;\n tradingGatewayAddress: Address;\n};\n\nexport type CreateTradingWithdrawToFundingServiceInput = CreateTradingWithdrawToFundingInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n};\n\nexport type CreateTradingWithdrawToExternalChainServiceInput =\n CreateTradingWithdrawToExternalChainInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n };\n\nexport type PreparedTradingWithdraw = Readonly<{\n /** When the backend stops accepting the currently signed request. */\n deadline: Date;\n /**\n * True once the deadline is less than a minute away. The withdraw signs again on\n * `submit` from then on, so callers can keep resubmitting the same prepared withdraw,\n * e.g. after a slow MFA step-up.\n */\n isExpired: () => boolean;\n /**\n * Submits the payload and signature produced during preparation. Repeated calls only\n * change transport options such as the step-up token, unless the deadline is near: the\n * withdraw then signs a fresh deadline and nonce with the same idempotency key.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype SignedTradingWithdraw = {\n payload: TradingWithdrawIntentPayloadRequest;\n send: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n};\n\n// Leaves room for the request to reach the backend and for modest clock skew.\nconst PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 60_000;\n\nfunction deadlineMs(payload: TradingWithdrawIntentPayloadRequest): number {\n return Number(payload.deadlineTsSec) * 1000;\n}\n\nfunction preparedWithdraw(\n signed: SignedTradingWithdraw,\n resign: (payload: TradingWithdrawIntentPayloadRequest) => Promise<SignedTradingWithdraw>,\n): PreparedTradingWithdraw {\n let current = signed;\n const isExpired = () =>\n Date.now() >= deadlineMs(current.payload) - PREPARED_WITHDRAW_EXPIRY_MARGIN_MS;\n return {\n get deadline() {\n return new Date(deadlineMs(current.payload));\n },\n isExpired,\n submit: async (options) => {\n if (isExpired()) {\n current = await resign(renewTradingWithdrawPayload(current.payload));\n }\n return current.send(options);\n },\n };\n}\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction resolveTradingWithdrawTargetAccountId(params: {\n subaccountId: bigint | undefined;\n rootAccountId: string;\n}): bigint {\n if (params.subaccountId !== undefined) return params.subaccountId;\n return idToBigInt(params.rootAccountId, \"targetAccountId\");\n}\n\nasync function resolveTradingWithdrawSigningConfig(params: {\n fallback: TradingWithdrawSigningConfig;\n catalog?: ClientCatalog;\n}): Promise<TradingWithdrawSigningConfig> {\n if (!params.catalog) return params.fallback;\n\n try {\n await params.catalog.ensureReady();\n const gateway = params.catalog.zipper.getContractByName(\"tradingGateway\");\n const address = gateway?.address?.trim();\n if (!address?.startsWith(\"0x\")) return params.fallback;\n\n return {\n chainId: params.fallback.chainId,\n tradingGatewayAddress: checksumEvmAddress(address),\n };\n } catch {\n return params.fallback;\n }\n}\n\nasync function resolveWalletSignature(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n walletSigner: TradingWithdrawWalletSigner;\n targetAccountId: bigint;\n}): Promise<{ signerWallet: string; payloadSignature: Uint8Array }> {\n const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signMessage(\n buildTradingWithdrawWalletMessage({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet,\n accountId,\n targetAccountId: params.targetAccountId,\n }),\n );\n if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) {\n throw new ValidationError(\n \"Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.\",\n );\n }\n return {\n signerWallet,\n payloadSignature: evmHexToBytes(signature),\n };\n}\n\n/**\n * Creates durable Trading withdrawal intents, signed by the client's API key or a wallet (EIP-191).\n */\nexport class TradingWithdrawsService {\n #client: Client<typeof Proto.WithdrawService>;\n #resolver?: SubaccountResolver;\n #signingConfig: TradingWithdrawSigningConfig;\n #catalog?: ClientCatalog;\n #scales: SdkScales;\n #auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider;\n #toFundingInputSchema: ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>;\n #toExternalChainInputSchema: ReturnType<\n typeof createCreateTradingWithdrawToExternalChainInputSchema\n >;\n\n constructor(\n transports: AuthApiTransports,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider,\n ) {\n this.#client = createClient(Proto.WithdrawService, transports.authApi);\n this.#auth = auth;\n this.#resolver = resolver;\n this.#signingConfig = signingConfig;\n this.#catalog = catalog;\n this.#scales = scales;\n this.#toFundingInputSchema = createCreateTradingWithdrawToFundingInputSchema(scales);\n this.#toExternalChainInputSchema =\n createCreateTradingWithdrawToExternalChainInputSchema(scales);\n }\n\n /**\n * Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a\n * rejected withdrawal's refund (see the lifecycle step's `refundAddress`), which stays there\n * until moved. API keys need `read-balances`.\n */\n async getWalletBalances(\n input: GetWalletBalancesInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<GetWalletBalancesResult> {\n const request = parse(\n GetWalletBalancesInputSchema,\n resolveAccountScopedInput(input, this.#resolver),\n );\n const response = await this.#client.getWalletBalances(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(GetWalletBalancesResultSchema, response);\n }\n\n /**\n * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one. API keys need `read-withdraw-validation`.\n */\n async validateDestination(\n input: ValidateWithdrawDestinationInput,\n options?: PolyesterRequestOptions,\n ): Promise<ValidateWithdrawDestinationResult> {\n const request = parse(ValidateWithdrawDestinationInputSchema, input);\n const response = await this.#client.validateWithdrawDestination(\n request,\n toConnectCallOptions(options),\n );\n return parse(ValidateWithdrawDestinationResultSchema, response);\n }\n\n /**\n * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.\n */\n async createToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToFunding(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-Funding withdrawal once so the exact request can be\n * resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toFundingInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n /**\n * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.\n */\n async createToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToExternalChain(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-external-chain withdrawal once so the exact request can\n * be resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toExternalChainInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n async #prepareWithdraw(\n validated: TradingWithdrawRequest,\n walletSigner: TradingWithdrawWalletSigner | undefined,\n ): Promise<PreparedTradingWithdraw> {\n if (walletSigner) {\n const signingConfig = await resolveTradingWithdrawSigningConfig({\n fallback: this.#signingConfig,\n catalog: this.#catalog,\n });\n const targetAccountId = resolveTradingWithdrawTargetAccountId({\n subaccountId: validated.subaccountId,\n rootAccountId: walletSigner.accountId,\n });\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n\n const auth = this.#auth;\n if (auth?.kind !== \"api-key-ed25519\") {\n throw new ConfigurationError(\n \"Trading withdraw requires a wallet signer or API-key auth.\",\n );\n }\n // CreateTradingWithdrawRequest has no subaccount field: the API key decides the account.\n if (validated.subaccountId !== undefined) {\n throw new ValidationError(\n 'API-key trading withdraws cannot target a subaccount. Use `account: \"main\"` or a wallet signer.',\n );\n }\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n // The backend verifies the signature over the payload's protobuf encoding.\n const payloadSignature = await signApiKeyEd25519Payload(\n auth,\n toBinary(\n Proto.TradingWithdrawIntentPayloadSchema,\n create(Proto.TradingWithdrawIntentPayloadSchema, payload),\n ),\n );\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n { payload, payloadSignature },\n toConnectCallOptions(options),\n );\n return parse(CreateTradingWithdrawResultSchema, response);\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A0C,OAAO,CAC5D,CACJ;GACA,OAAO;IACH;IACA,MAAM,OAAO,YAAY;KACrB,MAAM,WAAW,MAAM,KAAKV,QAAQ,sBAChC;MAAE;MAAS;KAAiB,GAC5B,qBAAqB,OAAO,CAChC;KACA,OAAO,MAAM,mCAAmC,QAAQ;IAC5D;GACJ;EACJ;EACA,OAAO,iBAAiB,MAAM,KAAK,UAAU,OAAO,GAAG,IAAI;CAC/D;AACJ"}
@@ -16,7 +16,6 @@ type TradingWithdrawIntentPayloadRequest = {
16
16
  type CreateTradingWithdrawRequestBase = {
17
17
  subaccountId: bigint | undefined;
18
18
  payload: TradingWithdrawIntentPayloadRequest;
19
- payloadSignature?: Uint8Array;
20
19
  };
21
20
  declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
22
21
  readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
@@ -24,7 +23,6 @@ declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScal
24
23
  readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
25
24
  readonly destinationAddress: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
26
25
  readonly signerWallet: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
27
- readonly payloadSignature: v.OptionalSchema<v.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
28
26
  /**
29
27
  * When the signed authorization lapses. Defaults to five minutes from now
30
28
  * on the device clock.
@@ -39,7 +37,6 @@ declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScal
39
37
  idempotencyKey: string;
40
38
  destinationAddress: string;
41
39
  signerWallet: string;
42
- payloadSignature?: Uint8Array<ArrayBuffer> | undefined;
43
40
  deadline?: Date | undefined;
44
41
  account?: "active" | "main" | {
45
42
  subaccountId: string;
@@ -52,7 +49,6 @@ declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: S
52
49
  readonly destinationAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
53
50
  readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
54
51
  readonly signerWallet: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
55
- readonly payloadSignature: v.OptionalSchema<v.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
56
52
  /**
57
53
  * When the signed authorization lapses. Defaults to five minutes from now
58
54
  * on the device clock.
@@ -68,7 +64,6 @@ declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: S
68
64
  destinationAddress: string;
69
65
  idempotencyKey: string;
70
66
  signerWallet: string;
71
- payloadSignature?: Uint8Array<ArrayBuffer> | undefined;
72
67
  deadline?: Date | undefined;
73
68
  account?: "active" | "main" | {
74
69
  subaccountId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAwBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;EACT,mBAAmB;;iBAmDP,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GAqChF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CtF;KAEW,sCAAsC,EAAE,WAChD,kBAAkB;KAOV,4CAA4C,EAAE,WACtD,kBAAkB;cAOT,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,mBAAmB;cAOlD,wCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;KAgBvC,mCAAmC,EAAE,kBACtC;cA4CE,yCAAuC,EAAA,aAAA,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,oCAAoC,EAAE,mBACvC;cAGL,iCAA+B,EAAA;;;;;KAOzB,yBAAyB,EAAE,kBAAkB;cAE5C,+BAA6B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyB9B,0BAA0B,EAAE,mBAAmB"}
1
+ {"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAwBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;;iBAmDG,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;GAmChF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCtF;KAEW,sCAAsC,EAAE,WAChD,kBAAkB;KAOV,4CAA4C,EAAE,WACtD,kBAAkB;cAOT,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,mBAAmB;cAOlD,wCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;KAgBvC,mCAAmC,EAAE,kBACtC;cA4CE,yCAAuC,EAAA,aAAA,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,oCAAoC,EAAE,mBACvC;cAGL,iCAA+B,EAAA;;;;;KAOzB,yBAAyB,EAAE,kBAAkB;cAE5C,+BAA6B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyB9B,0BAA0B,EAAE,mBAAmB"}
@@ -1,10 +1,10 @@
1
+ import "../../gen/chain/withdraw/v1/withdraw_pb.js";
1
2
  import { ConfigurationError } from "../../shared/errors.js";
2
3
  import { U128Schema } from "../../shared/schemas.js";
3
4
  import { quantityInputToE18, scaledToDecimalOutput } from "../../shared/decimal-surface.js";
4
5
  import { PositiveUint32InputSchema } from "../shared.js";
5
6
  import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
6
7
  import { fromU128, toU128 } from "../../utils/u128.js";
7
- import "../../gen/chain/withdraw/v1/withdraw_pb.js";
8
8
  import { TradingWithdrawActionCodec, WithdrawDestinationValidationCodeCodec } from "./trading-withdraws.codecs.js";
9
9
  import * as v from "valibot";
10
10
  //#region src/services/trading-withdraws/trading-withdraws.schemas.ts
@@ -45,7 +45,6 @@ function createCreateTradingWithdrawToFundingInputSchema(scales) {
45
45
  idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
46
46
  destinationAddress: v.optional(v.pipe(v.string(), v.trim()), ""),
47
47
  signerWallet: v.optional(v.pipe(v.string(), v.trim()), ""),
48
- payloadSignature: v.optional(v.instance(Uint8Array)),
49
48
  /**
50
49
  * When the signed authorization lapses. Defaults to five minutes from now
51
50
  * on the device clock.
@@ -59,7 +58,6 @@ function createCreateTradingWithdrawToFundingInputSchema(scales) {
59
58
  });
60
59
  return {
61
60
  subaccountId: accountScopeToSubaccountId(input.account),
62
- payloadSignature: input.payloadSignature,
63
61
  payload: createTradingWithdrawPayload({
64
62
  action: TradingWithdrawActionCodec.inputToProto.to_funding,
65
63
  assetId: input.assetId,
@@ -81,7 +79,6 @@ function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
81
79
  destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),
82
80
  idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
83
81
  signerWallet: v.optional(v.pipe(v.string(), v.trim()), ""),
84
- payloadSignature: v.optional(v.instance(Uint8Array)),
85
82
  /**
86
83
  * When the signed authorization lapses. Defaults to five minutes from now
87
84
  * on the device clock.
@@ -95,7 +92,6 @@ function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
95
92
  });
96
93
  return {
97
94
  subaccountId: accountScopeToSubaccountId(input.account),
98
- payloadSignature: input.payloadSignature,
99
95
  payload: createTradingWithdrawPayload({
100
96
  action: TradingWithdrawActionCodec.inputToProto.to_external_chain,
101
97
  assetId: input.assetId,
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PositiveUint32InputSchema } from \"../shared.js\";\nimport {\n E18_SCALE,\n quantityInputToE18,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { fromU128, toU128, type U128Value } from \"../../utils/u128.js\";\nimport { U128Schema } from \"../../shared/schemas.js\";\nimport { ConfigurationError } from \"../../shared/errors.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n payloadSignature?: Uint8Array;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n throw new ConfigurationError(\"Secure nonce generation requires crypto.getRandomValues.\");\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0]!;\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n deadline: Date | undefined;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(\n input.deadline\n ? Math.floor(input.deadline.getTime() / 1000)\n : Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS,\n ),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\n/** The same withdraw with a fresh default deadline and nonce, for signing again. */\nexport function renewTradingWithdrawPayload(\n payload: TradingWithdrawIntentPayloadRequest,\n): TradingWithdrawIntentPayloadRequest {\n return {\n ...payload,\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n /**\n * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n deadline: input.deadline,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n /**\n * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n deadline: input.deadline,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n\nconst WalletBalancesInputObjectSchema = v.strictObject({ ...AccountScopeInputEntries });\n\nexport const GetWalletBalancesInputSchema = v.pipe(\n WalletBalancesInputObjectSchema,\n v.transform(({ account }) => ({ subaccountId: accountScopeToSubaccountId(account) })),\n);\n\nexport type GetWalletBalancesInput = v.InferInput<typeof WalletBalancesInputObjectSchema>;\n\nexport const GetWalletBalancesResultSchema = v.object({\n smartAccountAddress: v.string(),\n balances: v.array(\n v.pipe(\n v.object({\n zippedAssetId: v.number(),\n unifiedAssetId: v.number(),\n chainId: v.number(),\n ztokenAddress: v.string(),\n amountE18: v.optional(U128Schema),\n }),\n v.transform(({ amountE18, ...balance }) => ({\n ...balance,\n amount: scaledToDecimalOutput(fromU128(amountE18), E18_SCALE),\n })),\n ),\n ),\n});\n\n/**\n * zTokens the account's smart account wallet holds on Polyester Chain, read live from the\n * chain: for example a rejected withdrawal's refund, which stays there until moved. `amount`\n * is a decimal string (zTokens have 18 decimals); `chainId` is a `GetDepositWithdrawConfig`\n * chain. `balances` lists nonzero balances by `zippedAssetId` and is empty when there are none.\n */\nexport type GetWalletBalancesResult = v.InferOutput<typeof GetWalletBalancesResultSchema>;\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,iBAAiB,KAAK,WAAW,MAAM;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AAE,GAAG,yBAAyB,CAAC;AAEtF,MAAa,+BAA+B,EAAE,KAC1C,iCACA,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,2BAA2B,OAAO,EAAE,EAAE,CACxF;AAIA,MAAa,gCAAgC,EAAE,OAAO;CAClD,qBAAqB,EAAE,OAAO;CAC9B,UAAU,EAAE,MACR,EAAE,KACE,EAAE,OAAO;EACL,eAAe,EAAE,OAAO;EACxB,gBAAgB,EAAE,OAAO;EACzB,SAAS,EAAE,OAAO;EAClB,eAAe,EAAE,OAAO;EACxB,WAAW,EAAE,SAAS,UAAU;CACpC,CAAC,GACD,EAAE,WAAW,EAAE,WAAW,GAAG,eAAe;EACxC,GAAG;EACH,QAAQ,sBAAsB,SAAS,SAAS,GAAA,EAAY;CAChE,EAAE,CACN,CACJ;AACJ,CAAC"}
1
+ {"version":3,"file":"trading-withdraws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PositiveUint32InputSchema } from \"../shared.js\";\nimport {\n E18_SCALE,\n quantityInputToE18,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { fromU128, toU128, type U128Value } from \"../../utils/u128.js\";\nimport { U128Schema } from \"../../shared/schemas.js\";\nimport { ConfigurationError } from \"../../shared/errors.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n throw new ConfigurationError(\"Secure nonce generation requires crypto.getRandomValues.\");\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0]!;\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n deadline: Date | undefined;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(\n input.deadline\n ? Math.floor(input.deadline.getTime() / 1000)\n : Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS,\n ),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\n/** The same withdraw with a fresh default deadline and nonce, for signing again. */\nexport function renewTradingWithdrawPayload(\n payload: TradingWithdrawIntentPayloadRequest,\n): TradingWithdrawIntentPayloadRequest {\n return {\n ...payload,\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n /**\n * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n deadline: input.deadline,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n /**\n * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n deadline: input.deadline,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n\nconst WalletBalancesInputObjectSchema = v.strictObject({ ...AccountScopeInputEntries });\n\nexport const GetWalletBalancesInputSchema = v.pipe(\n WalletBalancesInputObjectSchema,\n v.transform(({ account }) => ({ subaccountId: accountScopeToSubaccountId(account) })),\n);\n\nexport type GetWalletBalancesInput = v.InferInput<typeof WalletBalancesInputObjectSchema>;\n\nexport const GetWalletBalancesResultSchema = v.object({\n smartAccountAddress: v.string(),\n balances: v.array(\n v.pipe(\n v.object({\n zippedAssetId: v.number(),\n unifiedAssetId: v.number(),\n chainId: v.number(),\n ztokenAddress: v.string(),\n amountE18: v.optional(U128Schema),\n }),\n v.transform(({ amountE18, ...balance }) => ({\n ...balance,\n amount: scaledToDecimalOutput(fromU128(amountE18), E18_SCALE),\n })),\n ),\n ),\n});\n\n/**\n * zTokens the account's smart account wallet holds on Polyester Chain, read live from the\n * chain: for example a rejected withdrawal's refund, which stays there until moved. `amount`\n * is a decimal string (zTokens have 18 decimals); `chainId` is a `GetDepositWithdrawConfig`\n * chain. `balances` lists nonzero balances by `zippedAssetId` and is empty when there are none.\n */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