@symmio/trading-react 4.3.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/dist/account-layer/automatic-timelock-attempt.d.ts +11 -0
  2. package/dist/account-layer/automatic-timelock-attempt.d.ts.map +1 -0
  3. package/dist/account-layer/automatic-timelock-attempt.js +41 -0
  4. package/dist/account-layer/automatic-timelock-attempt.js.map +1 -0
  5. package/dist/account-layer/index.d.ts +9 -0
  6. package/dist/account-layer/index.d.ts.map +1 -1
  7. package/dist/account-layer/index.js +41 -32
  8. package/dist/account-layer/use-active-virtual-account-by-key.d.ts +33 -0
  9. package/dist/account-layer/use-active-virtual-account-by-key.d.ts.map +1 -0
  10. package/dist/account-layer/use-active-virtual-account-by-key.js +27 -0
  11. package/dist/account-layer/use-active-virtual-account-by-key.js.map +1 -0
  12. package/dist/account-layer/use-add-margin.d.ts +2 -2
  13. package/dist/account-layer/use-add-margin.d.ts.map +1 -1
  14. package/dist/account-layer/use-add-margin.js +28 -17
  15. package/dist/account-layer/use-add-margin.js.map +1 -1
  16. package/dist/account-layer/use-allocate.d.ts +2 -2
  17. package/dist/account-layer/use-allocate.d.ts.map +1 -1
  18. package/dist/account-layer/use-allocate.js +28 -17
  19. package/dist/account-layer/use-allocate.js.map +1 -1
  20. package/dist/account-layer/use-automatic-timelock-recovery.d.ts +25 -0
  21. package/dist/account-layer/use-automatic-timelock-recovery.d.ts.map +1 -0
  22. package/dist/account-layer/use-automatic-timelock-recovery.js +26 -0
  23. package/dist/account-layer/use-automatic-timelock-recovery.js.map +1 -0
  24. package/dist/account-layer/use-automatic-timelock.d.ts +48 -0
  25. package/dist/account-layer/use-automatic-timelock.d.ts.map +1 -0
  26. package/dist/account-layer/use-automatic-timelock.js +189 -0
  27. package/dist/account-layer/use-automatic-timelock.js.map +1 -0
  28. package/dist/account-layer/use-create-sub-accounts.d.ts +9 -4
  29. package/dist/account-layer/use-create-sub-accounts.d.ts.map +1 -1
  30. package/dist/account-layer/use-create-sub-accounts.js +11 -13
  31. package/dist/account-layer/use-create-sub-accounts.js.map +1 -1
  32. package/dist/account-layer/use-deallocate-and-initiate-withdraw.d.ts +3 -3
  33. package/dist/account-layer/use-deallocate-and-initiate-withdraw.d.ts.map +1 -1
  34. package/dist/account-layer/use-deallocate-and-initiate-withdraw.js +32 -21
  35. package/dist/account-layer/use-deallocate-and-initiate-withdraw.js.map +1 -1
  36. package/dist/account-layer/use-deallocate.d.ts +6 -5
  37. package/dist/account-layer/use-deallocate.d.ts.map +1 -1
  38. package/dist/account-layer/use-deallocate.js +33 -20
  39. package/dist/account-layer/use-deallocate.js.map +1 -1
  40. package/dist/account-layer/use-delete-sub-account.d.ts +2 -2
  41. package/dist/account-layer/use-delete-sub-account.d.ts.map +1 -1
  42. package/dist/account-layer/use-delete-sub-account.js +30 -19
  43. package/dist/account-layer/use-delete-sub-account.js.map +1 -1
  44. package/dist/account-layer/use-execute-account-calls.d.ts +7 -0
  45. package/dist/account-layer/use-execute-account-calls.d.ts.map +1 -0
  46. package/dist/account-layer/use-execute-account-calls.js +54 -0
  47. package/dist/account-layer/use-execute-account-calls.js.map +1 -0
  48. package/dist/account-layer/use-protected-function.d.ts +22 -0
  49. package/dist/account-layer/use-protected-function.d.ts.map +1 -0
  50. package/dist/account-layer/use-protected-function.js +68 -0
  51. package/dist/account-layer/use-protected-function.js.map +1 -0
  52. package/dist/account-layer/use-remove-margin.d.ts +2 -2
  53. package/dist/account-layer/use-remove-margin.d.ts.map +1 -1
  54. package/dist/account-layer/use-remove-margin.js +31 -20
  55. package/dist/account-layer/use-remove-margin.js.map +1 -1
  56. package/dist/account-layer/use-timelock-policy.d.ts +21 -0
  57. package/dist/account-layer/use-timelock-policy.d.ts.map +1 -0
  58. package/dist/account-layer/use-timelock-policy.js +112 -0
  59. package/dist/account-layer/use-timelock-policy.js.map +1 -0
  60. package/dist/account-layer/use-timelock-route.d.ts +75 -0
  61. package/dist/account-layer/use-timelock-route.d.ts.map +1 -0
  62. package/dist/account-layer/use-timelock-route.js +177 -0
  63. package/dist/account-layer/use-timelock-route.js.map +1 -0
  64. package/dist/account-layer/use-timelock.d.ts +102 -0
  65. package/dist/account-layer/use-timelock.d.ts.map +1 -0
  66. package/dist/account-layer/use-timelock.js +177 -0
  67. package/dist/account-layer/use-timelock.js.map +1 -0
  68. package/dist/account-layer/use-virtual-accounts-count-of-sub-account.d.ts +24 -0
  69. package/dist/account-layer/use-virtual-accounts-count-of-sub-account.d.ts.map +1 -0
  70. package/dist/account-layer/use-virtual-accounts-count-of-sub-account.js +27 -0
  71. package/dist/account-layer/use-virtual-accounts-count-of-sub-account.js.map +1 -0
  72. package/dist/account-layer/use-virtual-accounts-of-sub-account.d.ts +25 -0
  73. package/dist/account-layer/use-virtual-accounts-of-sub-account.d.ts.map +1 -0
  74. package/dist/account-layer/use-virtual-accounts-of-sub-account.js +27 -0
  75. package/dist/account-layer/use-virtual-accounts-of-sub-account.js.map +1 -0
  76. package/dist/errors/normalize-protected-write-error.d.ts +5 -0
  77. package/dist/errors/normalize-protected-write-error.d.ts.map +1 -0
  78. package/dist/errors/normalize-protected-write-error.js +43 -0
  79. package/dist/errors/normalize-protected-write-error.js.map +1 -0
  80. package/dist/errors/normalize-symm-error.d.ts.map +1 -1
  81. package/dist/errors/normalize-symm-error.js +56 -43
  82. package/dist/errors/normalize-symm-error.js.map +1 -1
  83. package/dist/errors/symmio-request-error.d.ts +5 -0
  84. package/dist/errors/symmio-request-error.d.ts.map +1 -1
  85. package/dist/errors/symmio-request-error.js +2 -1
  86. package/dist/errors/symmio-request-error.js.map +1 -1
  87. package/dist/gasless/index.d.ts +1 -0
  88. package/dist/gasless/index.d.ts.map +1 -1
  89. package/dist/gasless/index.js +20 -19
  90. package/dist/gasless/invalidate-relay-reads.d.ts +3 -1
  91. package/dist/gasless/invalidate-relay-reads.d.ts.map +1 -1
  92. package/dist/gasless/invalidate-relay-reads.js +115 -60
  93. package/dist/gasless/invalidate-relay-reads.js.map +1 -1
  94. package/dist/gasless/use-approve-operational-fee-allowance.d.ts +37 -0
  95. package/dist/gasless/use-approve-operational-fee-allowance.d.ts.map +1 -0
  96. package/dist/gasless/use-approve-operational-fee-allowance.js +48 -0
  97. package/dist/gasless/use-approve-operational-fee-allowance.js.map +1 -0
  98. package/dist/gasless/use-approve-operational-fee.d.ts +2 -2
  99. package/dist/gasless/use-approve-operational-fee.d.ts.map +1 -1
  100. package/dist/gasless/use-approve-operational-fee.js +28 -17
  101. package/dist/gasless/use-approve-operational-fee.js.map +1 -1
  102. package/dist/gasless/use-relay-gasless-batch.d.ts +5 -4
  103. package/dist/gasless/use-relay-gasless-batch.d.ts.map +1 -1
  104. package/dist/gasless/use-relay-gasless-batch.js.map +1 -1
  105. package/dist/index.d.ts +13 -7
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +271 -256
  108. package/dist/instant-layer/index.d.ts +2 -0
  109. package/dist/instant-layer/index.d.ts.map +1 -1
  110. package/dist/instant-layer/index.js +25 -23
  111. package/dist/instant-layer/invalidate-delegation-grant.d.ts +17 -0
  112. package/dist/instant-layer/invalidate-delegation-grant.d.ts.map +1 -0
  113. package/dist/instant-layer/invalidate-delegation-grant.js +26 -0
  114. package/dist/instant-layer/invalidate-delegation-grant.js.map +1 -0
  115. package/dist/instant-layer/use-grant-delegation.d.ts +3 -1
  116. package/dist/instant-layer/use-grant-delegation.d.ts.map +1 -1
  117. package/dist/instant-layer/use-grant-delegation.js +19 -28
  118. package/dist/instant-layer/use-grant-delegation.js.map +1 -1
  119. package/dist/instant-layer/use-grant-delegations.d.ts +44 -0
  120. package/dist/instant-layer/use-grant-delegations.d.ts.map +1 -0
  121. package/dist/instant-layer/use-grant-delegations.js +36 -0
  122. package/dist/instant-layer/use-grant-delegations.js.map +1 -0
  123. package/dist/instant-layer/use-instant-close-fees.js +8 -8
  124. package/dist/instant-layer/use-instant-open-inputs.d.ts +1 -0
  125. package/dist/instant-layer/use-instant-open-inputs.d.ts.map +1 -1
  126. package/dist/instant-layer/use-instant-open-inputs.js +81 -80
  127. package/dist/instant-layer/use-instant-open-inputs.js.map +1 -1
  128. package/dist/instant-layer/use-prepare-instant-open-params.d.ts +6 -0
  129. package/dist/instant-layer/use-prepare-instant-open-params.d.ts.map +1 -1
  130. package/dist/instant-layer/use-prepare-instant-open-params.js +1 -0
  131. package/dist/instant-layer/use-prepare-instant-open-params.js.map +1 -1
  132. package/dist/instant-layer/use-session-key-selectors.d.ts +5 -2
  133. package/dist/instant-layer/use-session-key-selectors.d.ts.map +1 -1
  134. package/dist/instant-layer/use-session-key-selectors.js +9 -5
  135. package/dist/instant-layer/use-session-key-selectors.js.map +1 -1
  136. package/dist/instant-layer/use-simulate-grant-delegations.d.ts +25 -0
  137. package/dist/instant-layer/use-simulate-grant-delegations.d.ts.map +1 -0
  138. package/dist/instant-layer/use-simulate-grant-delegations.js +29 -0
  139. package/dist/instant-layer/use-simulate-grant-delegations.js.map +1 -0
  140. package/dist/price-service/use-enigma-prices.d.ts +4 -0
  141. package/dist/price-service/use-enigma-prices.d.ts.map +1 -1
  142. package/dist/price-service/use-enigma-prices.js +60 -24
  143. package/dist/price-service/use-enigma-prices.js.map +1 -1
  144. package/dist/provider/symmio-provider.d.ts +31 -4
  145. package/dist/provider/symmio-provider.d.ts.map +1 -1
  146. package/dist/provider/symmio-provider.js +12 -11
  147. package/dist/provider/symmio-provider.js.map +1 -1
  148. package/dist/solvers/timelock-capability-cache.d.ts +9 -0
  149. package/dist/solvers/timelock-capability-cache.d.ts.map +1 -0
  150. package/dist/solvers/timelock-capability-cache.js +79 -0
  151. package/dist/solvers/timelock-capability-cache.js.map +1 -0
  152. package/dist/solvers/use-solver-info.d.ts +5 -2
  153. package/dist/solvers/use-solver-info.d.ts.map +1 -1
  154. package/dist/solvers/use-solver-info.js +35 -11
  155. package/dist/solvers/use-solver-info.js.map +1 -1
  156. package/dist/transactions/write-types.d.ts +13 -1
  157. package/dist/transactions/write-types.d.ts.map +1 -1
  158. package/dist/withdraw/index.d.ts +3 -0
  159. package/dist/withdraw/index.d.ts.map +1 -1
  160. package/dist/withdraw/use-deallocate-debounce-time.d.ts +29 -0
  161. package/dist/withdraw/use-deallocate-debounce-time.d.ts.map +1 -0
  162. package/dist/withdraw/use-deallocate-debounce-time.js +27 -0
  163. package/dist/withdraw/use-deallocate-debounce-time.js.map +1 -0
  164. package/dist/withdraw/use-finalize-withdraw-request.d.ts.map +1 -1
  165. package/dist/withdraw/use-finalize-withdraw-request.js +13 -12
  166. package/dist/withdraw/use-finalize-withdraw-request.js.map +1 -1
  167. package/dist/withdraw/use-initiate-withdraw.d.ts +2 -2
  168. package/dist/withdraw/use-initiate-withdraw.d.ts.map +1 -1
  169. package/dist/withdraw/use-initiate-withdraw.js +29 -17
  170. package/dist/withdraw/use-initiate-withdraw.js.map +1 -1
  171. package/dist/withdraw/use-pending-withdraw-requests-batch.d.ts +19 -0
  172. package/dist/withdraw/use-pending-withdraw-requests-batch.d.ts.map +1 -0
  173. package/dist/withdraw/use-pending-withdraw-requests-batch.js +27 -0
  174. package/dist/withdraw/use-pending-withdraw-requests-batch.js.map +1 -0
  175. package/dist/withdraw/use-request-cancel-withdraw.d.ts.map +1 -1
  176. package/dist/withdraw/use-request-cancel-withdraw.js +14 -13
  177. package/dist/withdraw/use-request-cancel-withdraw.js.map +1 -1
  178. package/dist/withdraw/use-withdraw-cooldown-of.d.ts +33 -0
  179. package/dist/withdraw/use-withdraw-cooldown-of.d.ts.map +1 -0
  180. package/dist/withdraw/use-withdraw-cooldown-of.js +27 -0
  181. package/dist/withdraw/use-withdraw-cooldown-of.js.map +1 -0
  182. package/dist/withdraw/use-withdraw.d.ts +3 -3
  183. package/dist/withdraw/use-withdraw.d.ts.map +1 -1
  184. package/dist/withdraw/use-withdraw.js +57 -31
  185. package/dist/withdraw/use-withdraw.js.map +1 -1
  186. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"use-withdraw.js","names":[],"sources":["../../src/withdraw/use-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getAccountBalanceInfoQueryKey,\n getAccountBalanceOfQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getWithdrawableTimeQueryKey,\n SymmError,\n withdrawAutoMutationOptions,\n type WithdrawAutoParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport type { Address } from \"viem\";\nimport { useSubAccount } from \"../account-layer/use-sub-account\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type WriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useWithdraw}. `account` (the subaccount) and `chainId` are\n * read at hook time so the hook can resolve the subaccount's isolation type via\n * {@link useSubAccount}; the per-withdraw inputs (`amount`, `receiver`, …) are the\n * mutation variables.\n */\nexport type UseWithdrawParameters = WriteParameters & {\n /** The subaccount to withdraw from. The connected wallet must be its on-chain owner. */\n account?: Address;\n /** Target chain id. Defaults to the connected chain. */\n chainId?: number;\n};\n\n/**\n * Variables for the {@link useWithdraw} mutation — the per-withdraw inputs, with\n * `amount` in the **collateral token's decimals**. `account`, `chainId`, and\n * `isolationType` are supplied by the hook, so the caller never passes them (nor\n * `parts`). `upnlSig` is optional; on the `CUSTOM` path a fresh Muon uPnL signature\n * is fetched for the deallocate leg when omitted.\n */\nexport type UseWithdrawVariables = Omit<WithdrawAutoParameters, \"account\" | \"isolationType\" | \"chainId\">;\n\n/** Result returned by the {@link useWithdraw} mutation. */\nexport type WithdrawResult = WriteResult;\n\n/** Return type of {@link useWithdraw}. */\nexport type UseWithdrawReturnType = UseMutationResult<WithdrawResult, SymmioRequestError, UseWithdrawVariables>;\n\n/**\n * Withdraw from a subaccount from a **minimal, collateral-decimals input** — the\n * high-level entry point that hides isolation, parts, and amount scaling.\n *\n * Pass the `account` (and optional `chainId`) to the hook; call `mutate` with just\n * `{ amount, receiver }`. The hook reads the subaccount's `isolationType` with\n * {@link useSubAccount} (deduped with any other `useSubAccount` on the same key —\n * e.g. one already driving a balance display) and hands it to the SDK, so the core\n * action skips a redundant on-chain read and picks the path: a `CUSTOM`\n * (cross-margin) subaccount deallocates then initiates in one atomic transaction; a\n * `MARKET` / `MARKET_DIRECTION` (VA / lowcap) subaccount only initiates the withdraw\n * request. On a cache miss the core action resolves `isolationType` itself.\n *\n * `amount` is in the **collateral token's decimals** (e.g. 6 for USDC). The hook\n * builds the classic same-chain withdraw part from it and, on the `CUSTOM` path,\n * scales it to the 18-decimal amount the deallocate leg needs — the caller does not\n * scale anything.\n *\n * On success, the subaccount's balance reads (`balanceInfo`, `balanceOf`) and its\n * pending-requests / withdrawable-time reads are invalidated.\n *\n * @remarks\n * On the `CUSTOM` path the SDK fetches a fresh Muon uPnL signature for the\n * deallocate leg unless you pass one as `upnlSig`; that leg is subject to the\n * on-chain deallocate debounce. Failures surface as a normalized\n * {@link SymmioRequestError}. Reach for `useDeallocateAndInitiateWithdraw` /\n * `useInitiateWithdraw` when you already know the isolation and want to drive one\n * specific path, or need custom (multi-part / cross-chain) withdraw parts.\n *\n * @example\n * ```tsx\n * const { mutate } = useWithdraw({ account: \"0xsub…\" });\n * // amount in the collateral token's decimals (6-dec USDC → 1 USDC):\n * mutate({ amount: 1_000000n, receiver: \"0xabc…\" });\n * ```\n */\nexport function useWithdraw(parameters: UseWithdrawParameters = {}): UseWithdrawReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const resolvedChainId = parameters.chainId ?? chainId;\n\n // Resolve the subaccount's isolation type via the standard hook (deduped by\n // react-query with any other useSubAccount on the same key), so the core action\n // skips a redundant getSubAccount RPC.\n const { data: subAccount } = useSubAccount({\n account: parameters.account,\n chainId: parameters.chainId,\n config: parameters.config,\n });\n const isolationType = subAccount?.isolationType;\n\n const base = withdrawAutoMutationOptions(config);\n\n return useMutation<WithdrawResult, SymmioRequestError, UseWithdrawVariables>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n const account = parameters.account;\n if (!account) {\n throw new SymmError(\"validation\", \"MISSING_ACCOUNT\", \"useWithdraw: `account` must be set on the hook.\");\n }\n const hash = await base.mutationFn({ ...variables, account, chainId: resolvedChainId, isolationType });\n return resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: () => {\n const account = parameters.account;\n if (!account) return;\n\n const balancePartial = { account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceInfoQueryKey, balancePartial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceOfQueryKey, balancePartial) });\n\n const withdrawPartial = { user: account };\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsQueryKey, withdrawPartial),\n });\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getWithdrawableTimeQueryKey, withdrawPartial),\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;AAqFA,SAAgB,EAAY,IAAoC,CAAC,GAA0B;CACzF,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAkB,EAAW,WAAW,GAKxC,EAAE,MAAM,MAAe,EAAc;EACzC,SAAS,EAAW;EACpB,SAAS,EAAW;EACpB,QAAQ,EAAW;CACrB,CAAC,GACK,IAAgB,GAAY,eAE5B,IAAO,EAA4B,CAAM;CAE/C,OAAO,EAAsE;EAC3E,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,IAAM,IAAU,EAAW;IAC3B,IAAI,CAAC,GACH,MAAM,IAAI,EAAU,cAAc,mBAAmB,iDAAiD;IAGxG,OAAO,EAAmB,GAAQ,MADf,EAAK,WAAW;KAAE,GAAG;KAAW;KAAS,SAAS;KAAiB;IAAc,CAAC,GAC7D;KACtC,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CAAC;GACH,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,iBAAiB;GACf,IAAM,IAAU,EAAW;GAC3B,IAAI,CAAC,GAAS;GAEd,IAAM,IAAiB,EAAE,WAAQ;GAEjC,AADA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA+B,CAAc,EAAE,CAAC,GAC/G,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA6B,CAAc,EAAE,CAAC;GAE7G,IAAM,IAAkB,EAAE,MAAM,EAAQ;GAIxC,AAHA,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAoC,CAAe,EAC/E,CAAC,GACD,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAA6B,CAAe,EACxE,CAAC;EACH;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"use-withdraw.js","names":[],"sources":["../../src/withdraw/use-withdraw.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getAccountBalanceInfoQueryKey,\n getAccountBalanceOfQueryKey,\n getPendingWithdrawRequestsBatchQueryKey,\n getPendingWithdrawRequestsQueryKey,\n getSubAccountQueryOptions,\n getWithdrawableTimeQueryKey,\n getWithdrawCooldownOfQueryKey,\n SubAccountIsolationType,\n SymmError,\n withdrawAutoMutationOptions,\n type WithdrawAutoParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport type { Address } from \"viem\";\nimport { useAutomaticTimelock } from \"../account-layer/use-automatic-timelock\";\nimport { useSubAccount } from \"../account-layer/use-sub-account\";\nimport { normalizeProtectedWriteError } from \"../errors/normalize-protected-write-error\";\nimport { normalizeSymmError } from \"../errors/normalize-symm-error\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useSymmioChainId } from \"../provider/use-symmio-chain-id\";\nimport { useSymmioConfig } from \"../provider/use-symmio-config\";\nimport { resolveWriteResult, type AutomaticTimelockWriteParameters, type WriteResult } from \"../transactions\";\nimport { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useWithdraw}. `account` (the subaccount) and `chainId` are\n * read at hook time so the hook can resolve the subaccount's isolation type via\n * {@link useSubAccount}; the per-withdraw inputs (`amount`, `receiver`, …) are the\n * mutation variables.\n */\nexport type UseWithdrawParameters = AutomaticTimelockWriteParameters & {\n /** The subaccount to withdraw from. The connected wallet must be its on-chain owner. */\n account?: Address;\n /** Target chain id. Defaults to the connected chain. */\n chainId?: number;\n};\n\n/**\n * Variables for the {@link useWithdraw} mutation — the per-withdraw inputs, with\n * `amount` in the **collateral token's decimals**. `account`, `chainId`, and\n * `isolationType` are supplied by the hook, so the caller never passes them (nor\n * `parts`). `upnlSig` is optional; on the `CUSTOM` path a fresh Muon uPnL signature\n * is fetched for the deallocate leg when omitted.\n */\nexport type UseWithdrawVariables = Omit<WithdrawAutoParameters, \"account\" | \"isolationType\" | \"chainId\">;\n\n/** Result returned by the {@link useWithdraw} mutation. */\nexport type WithdrawResult = WriteResult;\n\n/** Return type of {@link useWithdraw}. */\nexport type UseWithdrawReturnType = UseMutationResult<WithdrawResult, SymmioRequestError, UseWithdrawVariables>;\n\n/**\n * Withdraw from a subaccount from a **minimal, collateral-decimals input** — the\n * high-level entry point that hides isolation, parts, and amount scaling.\n *\n * Pass the `account` (and optional `chainId`) to the hook; call `mutate` with just\n * `{ amount, receiver }`. The hook reads the subaccount's `isolationType` with\n * {@link useSubAccount} (deduped with any other `useSubAccount` on the same key —\n * e.g. one already driving a balance display) and hands it to the SDK, so the core\n * action skips a redundant on-chain read and picks the path: a `CUSTOM`\n * (cross-margin) subaccount deallocates then initiates in one atomic transaction; a\n * `MARKET` / `MARKET_DIRECTION` (VA / lowcap) subaccount only initiates the withdraw\n * request. On a cache miss the core action resolves `isolationType` itself.\n *\n * `amount` is in the **collateral token's decimals** (e.g. 6 for USDC). The hook\n * builds the classic same-chain withdraw part from it and, on the `CUSTOM` path,\n * scales it to the 18-decimal amount the deallocate leg needs — the caller does not\n * scale anything.\n *\n * On success, the subaccount's balance reads (`balanceInfo`, `balanceOf`) and its\n * pending-requests / withdrawable-time / withdraw-cooldown reads are invalidated.\n *\n * @remarks\n * On the `CUSTOM` path the SDK fetches a fresh Muon uPnL signature for the\n * deallocate leg unless you pass one as `upnlSig`; that leg is subject to the\n * on-chain deallocate debounce. Failures surface as a normalized\n * {@link SymmioRequestError}. Reach for `useDeallocateAndInitiateWithdraw` /\n * `useInitiateWithdraw` when you already know the isolation and want to drive one\n * specific path, or need custom (multi-part / cross-chain) withdraw parts.\n *\n * @example\n * ```tsx\n * const { mutate } = useWithdraw({ account: \"0xsub…\" });\n * // amount in the collateral token's decimals (6-dec USDC → 1 USDC):\n * mutate({ amount: 1_000000n, receiver: \"0xabc…\" });\n * ```\n */\nexport function useWithdraw(parameters: UseWithdrawParameters = {}): UseWithdrawReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const automaticTimelock = useAutomaticTimelock(config, parameters.automaticTimelock, parameters.account);\n const resolvedChainId = parameters.chainId ?? chainId;\n\n // Resolve the subaccount's isolation type via the standard hook (deduped by\n // react-query with any other useSubAccount on the same key), so the core action\n // skips a redundant getSubAccount RPC.\n const { data: subAccount } = useSubAccount({\n account: parameters.account,\n chainId: parameters.chainId,\n config: parameters.config,\n });\n const isolationType = subAccount?.isolationType;\n\n const base = withdrawAutoMutationOptions(config);\n\n return useMutation<WithdrawResult, SymmioRequestError, UseWithdrawVariables>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n let authorization = variables.timelock;\n try {\n const account = parameters.account;\n if (!account) {\n throw new SymmError(\"validation\", \"MISSING_ACCOUNT\", \"useWithdraw: `account` must be set on the hook.\");\n }\n if (!authorization && parameters.automaticTimelock !== false)\n await automaticTimelock.guard(variables, { account, chainId: resolvedChainId });\n let actualIsolation = isolationType;\n const solver = config.getSolver({ chainId: resolvedChainId });\n const shouldDiscover =\n parameters.automaticTimelock !== false &&\n config.getChainConfig(resolvedChainId).timelockSupported !== false &&\n solver.capabilities?.timelockApproval !== false &&\n (typeof parameters.automaticTimelock === \"object\" ||\n solver.id === \"enigma\" ||\n solver.capabilities?.timelockApproval === true);\n if (!authorization && shouldDiscover) {\n actualIsolation ??= (\n await queryClient.fetchQuery({\n ...getSubAccountQueryOptions(config, { account, chainId: resolvedChainId }),\n retry: false,\n })\n ).isolationType;\n authorization =\n actualIsolation === SubAccountIsolationType.CUSTOM\n ? await automaticTimelock.batch(variables, {\n account,\n chainId: resolvedChainId,\n functionNames: [\"deallocate\", \"initiateWithdraw\"],\n })\n : await automaticTimelock(variables, {\n account,\n chainId: resolvedChainId,\n functionName: \"initiateWithdraw\",\n });\n }\n const hash = await base.mutationFn({\n ...variables,\n account,\n chainId: resolvedChainId,\n isolationType: actualIsolation,\n ...(authorization ? { timelock: authorization } : {}),\n });\n const result = resolveWriteResult(config, hash, {\n chainId: resolvedChainId,\n waitForReceipt: parameters.waitForReceipt,\n confirmations: parameters.confirmations,\n });\n const settled = await result;\n automaticTimelock.finish(variables, settled);\n return settled;\n } catch (err) {\n automaticTimelock.fail(variables, err);\n throw authorization ? normalizeProtectedWriteError(err, authorization) : normalizeSymmError(err);\n }\n },\n onSuccess: (result) => {\n /** Broadcast-only callers own confirmation and the later batch refresh. */\n if (result.receipt) {\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsBatchQueryKey, {\n configKey: config.getChainConfigKey(resolvedChainId),\n }),\n });\n }\n const account = parameters.account;\n if (!account) return;\n\n const balancePartial = { account };\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceInfoQueryKey, balancePartial) });\n void queryClient.invalidateQueries({ predicate: predicateMatch(getAccountBalanceOfQueryKey, balancePartial) });\n\n const withdrawPartial = { user: account };\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getPendingWithdrawRequestsQueryKey, withdrawPartial),\n });\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getWithdrawableTimeQueryKey, withdrawPartial),\n });\n /** The `CUSTOM` path deallocates first, which stamps the cooldown timestamp. */\n void queryClient.invalidateQueries({\n predicate: predicateMatch(getWithdrawCooldownOfQueryKey, withdrawPartial),\n });\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;AA2FA,SAAgB,EAAY,IAAoC,CAAC,GAA0B;CACzF,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAoB,EAAqB,GAAQ,EAAW,mBAAmB,EAAW,OAAO,GACjG,IAAkB,EAAW,WAAW,GAKxC,EAAE,MAAM,MAAe,EAAc;EACzC,SAAS,EAAW;EACpB,SAAS,EAAW;EACpB,QAAQ,EAAW;CACrB,CAAC,GACK,IAAgB,GAAY,eAE5B,IAAO,EAA4B,CAAM;CAE/C,OAAO,EAAsE;EAC3E,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI,IAAgB,EAAU;GAC9B,IAAI;IACF,IAAM,IAAU,EAAW;IAC3B,IAAI,CAAC,GACH,MAAM,IAAI,EAAU,cAAc,mBAAmB,iDAAiD;IAExG,AAAI,CAAC,KAAiB,EAAW,sBAAsB,MACrD,MAAM,EAAkB,MAAM,GAAW;KAAE;KAAS,SAAS;IAAgB,CAAC;IAChF,IAAI,IAAkB,GAChB,IAAS,EAAO,UAAU,EAAE,SAAS,EAAgB,CAAC,GACtD,IACJ,EAAW,sBAAsB,MACjC,EAAO,eAAe,CAAe,EAAE,sBAAsB,MAC7D,EAAO,cAAc,qBAAqB,OACzC,OAAO,EAAW,qBAAsB,YACvC,EAAO,OAAO,YACd,EAAO,cAAc,qBAAqB;IAC9C,AAAI,CAAC,KAAiB,MACpB,OACE,MAAM,EAAY,WAAW;KAC3B,GAAG,EAA0B,GAAQ;MAAE;MAAS,SAAS;KAAgB,CAAC;KAC1E,OAAO;IACT,CAAC,GACD,eACF,IACE,MAAoB,EAAwB,SACxC,MAAM,EAAkB,MAAM,GAAW;KACvC;KACA,SAAS;KACT,eAAe,CAAC,cAAc,kBAAkB;IAClD,CAAC,IACD,MAAM,EAAkB,GAAW;KACjC;KACA,SAAS;KACT,cAAc;IAChB,CAAC;IAcT,IAAM,IAAU,MALD,EAAmB,GAAQ,MAPvB,EAAK,WAAW;KACjC,GAAG;KACH;KACA,SAAS;KACT,eAAe;KACf,GAAI,IAAgB,EAAE,UAAU,EAAc,IAAI,CAAC;IACrD,CAAC,GAC+C;KAC9C,SAAS;KACT,gBAAgB,EAAW;KAC3B,eAAe,EAAW;IAC5B,CACsB;IAEtB,OADA,EAAkB,OAAO,GAAW,CAAO,GACpC;GACT,SAAS,GAAK;IAEZ,MADA,EAAkB,KAAK,GAAW,CAAG,GAC/B,IAAgB,EAA6B,GAAK,CAAa,IAAI,EAAmB,CAAG;GACjG;EACF;EACA,YAAY,MAAW;GAErB,AAAI,EAAO,WACT,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAyC,EACjE,WAAW,EAAO,kBAAkB,CAAe,EACrD,CAAC,EACH,CAAC;GAEH,IAAM,IAAU,EAAW;GAC3B,IAAI,CAAC,GAAS;GAEd,IAAM,IAAiB,EAAE,WAAQ;GAEjC,AADA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA+B,CAAc,EAAE,CAAC,GAC/G,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA6B,CAAc,EAAE,CAAC;GAE7G,IAAM,IAAkB,EAAE,MAAM,EAAQ;GAQxC,AAPA,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAAoC,CAAe,EAC/E,CAAC,GACD,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAA6B,CAAe,EACxE,CAAC,GAED,EAAiB,kBAAkB,EACjC,WAAW,EAAe,GAA+B,CAAe,EAC1E,CAAC;EACH;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symmio/trading-react",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "React adapter for the SYMMIO SDK. Hooks, providers, and React-bound ergonomics on top of @symmio/trading-core.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/SYMM-IO/Trading-SDK/tree/main/packages/trading-react#readme",
@@ -91,7 +91,7 @@
91
91
  "@tanstack/react-query": "^5.100.0",
92
92
  "decimal.js": "^10.4.3",
93
93
  "zustand": "^5.0.0",
94
- "@symmio/trading-core": "^4.2.1"
94
+ "@symmio/trading-core": "^4.4.0"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "react": "^19.0.0",