@symmio/trading-react 0.2.0 → 1.0.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 (46) hide show
  1. package/README.md +2 -2
  2. package/dist/account-layer/use-account-balance-info.d.ts +15 -4
  3. package/dist/account-layer/use-account-balance-info.d.ts.map +1 -1
  4. package/dist/account-layer/use-account-balance-info.js +21 -9
  5. package/dist/account-layer/use-account-balance-info.js.map +1 -1
  6. package/dist/account-layer/use-account-balance-of.d.ts +15 -4
  7. package/dist/account-layer/use-account-balance-of.d.ts.map +1 -1
  8. package/dist/account-layer/use-account-balance-of.js +20 -9
  9. package/dist/account-layer/use-account-balance-of.js.map +1 -1
  10. package/dist/account-layer/use-deposit.d.ts +3 -1
  11. package/dist/account-layer/use-deposit.d.ts.map +1 -1
  12. package/dist/account-layer/use-deposit.js +17 -15
  13. package/dist/account-layer/use-deposit.js.map +1 -1
  14. package/dist/estimated-price/index.d.ts +2 -0
  15. package/dist/estimated-price/index.d.ts.map +1 -0
  16. package/dist/estimated-price/use-debounced-value.d.ts +9 -0
  17. package/dist/estimated-price/use-debounced-value.d.ts.map +1 -0
  18. package/dist/estimated-price/use-debounced-value.js +18 -0
  19. package/dist/estimated-price/use-debounced-value.js.map +1 -0
  20. package/dist/estimated-price/use-estimated-price.d.ts +46 -0
  21. package/dist/estimated-price/use-estimated-price.d.ts.map +1 -0
  22. package/dist/estimated-price/use-estimated-price.js +31 -0
  23. package/dist/estimated-price/use-estimated-price.js.map +1 -0
  24. package/dist/index.d.ts +6 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +106 -104
  27. package/dist/instant-layer/use-instant-open-with-tpsl.d.ts.map +1 -1
  28. package/dist/instant-layer/use-instant-open-with-tpsl.js +10 -2
  29. package/dist/instant-layer/use-instant-open-with-tpsl.js.map +1 -1
  30. package/dist/margin/index.d.ts +2 -0
  31. package/dist/margin/index.d.ts.map +1 -0
  32. package/dist/margin/use-available-instant-open-margin.d.ts +51 -0
  33. package/dist/margin/use-available-instant-open-margin.d.ts.map +1 -0
  34. package/dist/margin/use-available-instant-open-margin.js +66 -0
  35. package/dist/margin/use-available-instant-open-margin.js.map +1 -0
  36. package/dist/provider/symmio-provider.d.ts +14 -5
  37. package/dist/provider/symmio-provider.d.ts.map +1 -1
  38. package/dist/provider/symmio-provider.js +2 -2
  39. package/dist/provider/symmio-provider.js.map +1 -1
  40. package/dist/quotes/use-managed-quotes.js +16 -16
  41. package/dist/quotes/use-managed-quotes.js.map +1 -1
  42. package/dist/websocket/is-settle-notification.d.ts +15 -0
  43. package/dist/websocket/is-settle-notification.d.ts.map +1 -0
  44. package/dist/websocket/is-settle-notification.js +15 -0
  45. package/dist/websocket/is-settle-notification.js.map +1 -0
  46. package/package.json +7 -8
package/dist/index.js CHANGED
@@ -7,74 +7,74 @@ import { useConnectWallet as a } from "./wallet/use-connect-wallet.js";
7
7
  import { useDisconnectWallet as o } from "./wallet/use-disconnect-wallet.js";
8
8
  import { useSwitchToSymmioChain as s } from "./wallet/use-switch-to-symmio-chain.js";
9
9
  import { useWalletAccount as c } from "./wallet/use-wallet-account.js";
10
- import { useAccountBalanceInfo as l } from "./account-layer/use-account-balance-info.js";
11
- import { useAccountBalanceOf as u } from "./account-layer/use-account-balance-of.js";
12
- import { useTransactionsStore as d } from "./transactions/use-transactions-store.js";
13
- import { predicateMatch as f } from "./utils/predicate-match.js";
14
- import { useAddMargin as p } from "./account-layer/use-add-margin.js";
15
- import { useAllocate as m } from "./account-layer/use-allocate.js";
16
- import { useCreateSubAccounts as h } from "./account-layer/use-create-sub-accounts.js";
17
- import { useDeallocate as g } from "./account-layer/use-deallocate.js";
18
- import { useDeleteSubAccount as _ } from "./account-layer/use-delete-sub-account.js";
19
- import { useDeposit as v } from "./account-layer/use-deposit.js";
20
- import { useDepositAndAllocate as y } from "./account-layer/use-deposit-and-allocate.js";
21
- import { useEditAccountName as b } from "./account-layer/use-edit-account-name.js";
22
- import { usePredictedNextVirtualAccount as x } from "./account-layer/use-predicted-next-virtual-account.js";
23
- import { useRemoveMargin as S } from "./account-layer/use-remove-margin.js";
24
- import { useSimulateAddMargin as C } from "./account-layer/use-simulate-add-margin.js";
25
- import { useSimulateAllocate as w } from "./account-layer/use-simulate-allocate.js";
26
- import { useSimulateCreateSubAccounts as T } from "./account-layer/use-simulate-create-sub-accounts.js";
27
- import { useSimulateDeallocate as E } from "./account-layer/use-simulate-deallocate.js";
28
- import { useSimulateDeleteSubAccount as D } from "./account-layer/use-simulate-delete-sub-account.js";
29
- import { useSimulateDeposit as O } from "./account-layer/use-simulate-deposit.js";
30
- import { useSimulateDepositAndAllocate as k } from "./account-layer/use-simulate-deposit-and-allocate.js";
31
- import { useSimulateEditAccountName as A } from "./account-layer/use-simulate-edit-account-name.js";
32
- import { useSimulateRemoveMargin as j } from "./account-layer/use-simulate-remove-margin.js";
33
- import { useSubAccount as M } from "./account-layer/use-sub-account.js";
34
- import { useSubAccountVirtualNonce as N } from "./account-layer/use-sub-account-virtual-nonce.js";
35
- import { useSubAccountsCountOfUser as P } from "./account-layer/use-sub-accounts-count-of-user.js";
36
- import { useUserSubAccounts as F } from "./account-layer/use-user-sub-accounts.js";
37
- import { useUserSubAccountsAddresses as I } from "./account-layer/use-user-sub-accounts-addresses.js";
38
- import { useVirtualAccount as L } from "./account-layer/use-virtual-account.js";
39
- import { useVirtualAccountsAddressesOfSubAccount as R } from "./account-layer/use-virtual-accounts-addresses-of-sub-account.js";
40
- import { useApproveCollateral as z } from "./collateral/use-approve-collateral.js";
41
- import { useCollateralAllowance as B } from "./collateral/use-collateral-allowance.js";
42
- import { useCollateralBalance as V } from "./collateral/use-collateral-balance.js";
43
- import { useSimulateApproveCollateral as H } from "./collateral/use-simulate-approve-collateral.js";
44
- import { useDelegationExpiry as U } from "./instant-layer/use-delegation-expiry.js";
45
- import { useGrantDelegation as W } from "./instant-layer/use-grant-delegation.js";
46
- import { useInstantClose as G } from "./instant-layer/use-instant-close.js";
47
- import { useInstantCloseAuto as K } from "./instant-layer/use-instant-close-auto.js";
48
- import { useInstantCloseBulk as q } from "./instant-layer/use-instant-close-bulk.js";
49
- import { useInstantCloseBulkAuto as J } from "./instant-layer/use-instant-close-bulk-auto.js";
50
- import { useInstantCloses as Y } from "./instant-layer/use-instant-closes.js";
51
- import { useInstantOpen as X } from "./instant-layer/use-instant-open.js";
52
- import { useInstantOpenAuto as Z } from "./instant-layer/use-instant-open-auto.js";
53
- import { useInstantOpenQuoteId as Q } from "./instant-layer/use-instant-open-quote-id.js";
54
- import { toQuoteTpSl as $ } from "./tpsl/to-quote-tpsl.js";
55
- import { useTpSlRecord as ee, useTpSlStore as te } from "./tpsl/tpsl-store.js";
56
- import { useInstantOpenWithTpSl as ne } from "./instant-layer/use-instant-open-with-tpsl.js";
57
- import { useInstantOpens as re } from "./instant-layer/use-instant-opens.js";
58
- import { useIsDelegationActive as ie } from "./instant-layer/use-is-delegation-active.js";
59
- import { useSimulateGrantDelegation as ae } from "./instant-layer/use-simulate-grant-delegation.js";
60
- import { useFinalizeWithdrawRequest as oe } from "./withdraw/use-finalize-withdraw-request.js";
61
- import { useInitiateWithdraw as se } from "./withdraw/use-initiate-withdraw.js";
62
- import { useLastWithdrawRequestId as ce } from "./withdraw/use-last-withdraw-request-id.js";
63
- import { usePendingWithdrawRequests as le } from "./withdraw/use-pending-withdraw-requests.js";
64
- import { useRequestCancelWithdraw as ue } from "./withdraw/use-request-cancel-withdraw.js";
65
- import { useSimulateFinalizeWithdrawRequest as de } from "./withdraw/use-simulate-finalize-withdraw-request.js";
66
- import { useSimulateInitiateWithdraw as fe } from "./withdraw/use-simulate-initiate-withdraw.js";
67
- import { useSimulateRequestCancelWithdraw as pe } from "./withdraw/use-simulate-request-cancel-withdraw.js";
68
- import { useWithdrawRequest as me } from "./withdraw/use-withdraw-requests.js";
69
- import { useWithdrawableTime as he } from "./withdraw/use-withdrawable-time.js";
70
- import { useMarkets as ge } from "./markets/use-markets.js";
71
- import { useOnchainContractMarkets as _e } from "./markets/use-onchain-contract-markets.js";
72
- import { useSolverErrorCodes as ve } from "./error-codes/use-solver-error-codes.js";
73
- import { useSolverErrorMessage as ye } from "./error-codes/use-solver-error-message.js";
74
- import { useOptimisticQuotesStore as be } from "./quotes/optimistic-quotes-store.js";
75
- import { usePartyAOpenPositions as xe } from "./quotes/use-party-a-open-positions.js";
76
- import { useAccountLiquidationPrice as Se } from "./quotes/use-account-liquidation-price.js";
77
- import { useNotifications as Ce } from "./websocket/use-notifications.js";
10
+ import { useNotifications as l } from "./websocket/use-notifications.js";
11
+ import { useAccountBalanceInfo as u } from "./account-layer/use-account-balance-info.js";
12
+ import { useAccountBalanceOf as d } from "./account-layer/use-account-balance-of.js";
13
+ import { useTransactionsStore as f } from "./transactions/use-transactions-store.js";
14
+ import { predicateMatch as p } from "./utils/predicate-match.js";
15
+ import { useAddMargin as m } from "./account-layer/use-add-margin.js";
16
+ import { useAllocate as h } from "./account-layer/use-allocate.js";
17
+ import { useCreateSubAccounts as g } from "./account-layer/use-create-sub-accounts.js";
18
+ import { useDeallocate as _ } from "./account-layer/use-deallocate.js";
19
+ import { useDeleteSubAccount as v } from "./account-layer/use-delete-sub-account.js";
20
+ import { useDeposit as y } from "./account-layer/use-deposit.js";
21
+ import { useDepositAndAllocate as b } from "./account-layer/use-deposit-and-allocate.js";
22
+ import { useEditAccountName as x } from "./account-layer/use-edit-account-name.js";
23
+ import { usePredictedNextVirtualAccount as S } from "./account-layer/use-predicted-next-virtual-account.js";
24
+ import { useRemoveMargin as C } from "./account-layer/use-remove-margin.js";
25
+ import { useSimulateAddMargin as w } from "./account-layer/use-simulate-add-margin.js";
26
+ import { useSimulateAllocate as T } from "./account-layer/use-simulate-allocate.js";
27
+ import { useSimulateCreateSubAccounts as E } from "./account-layer/use-simulate-create-sub-accounts.js";
28
+ import { useSimulateDeallocate as D } from "./account-layer/use-simulate-deallocate.js";
29
+ import { useSimulateDeleteSubAccount as O } from "./account-layer/use-simulate-delete-sub-account.js";
30
+ import { useSimulateDeposit as k } from "./account-layer/use-simulate-deposit.js";
31
+ import { useSimulateDepositAndAllocate as A } from "./account-layer/use-simulate-deposit-and-allocate.js";
32
+ import { useSimulateEditAccountName as j } from "./account-layer/use-simulate-edit-account-name.js";
33
+ import { useSimulateRemoveMargin as M } from "./account-layer/use-simulate-remove-margin.js";
34
+ import { useSubAccount as N } from "./account-layer/use-sub-account.js";
35
+ import { useSubAccountVirtualNonce as P } from "./account-layer/use-sub-account-virtual-nonce.js";
36
+ import { useSubAccountsCountOfUser as F } from "./account-layer/use-sub-accounts-count-of-user.js";
37
+ import { useUserSubAccounts as I } from "./account-layer/use-user-sub-accounts.js";
38
+ import { useUserSubAccountsAddresses as L } from "./account-layer/use-user-sub-accounts-addresses.js";
39
+ import { useVirtualAccount as R } from "./account-layer/use-virtual-account.js";
40
+ import { useVirtualAccountsAddressesOfSubAccount as z } from "./account-layer/use-virtual-accounts-addresses-of-sub-account.js";
41
+ import { useApproveCollateral as B } from "./collateral/use-approve-collateral.js";
42
+ import { useCollateralAllowance as V } from "./collateral/use-collateral-allowance.js";
43
+ import { useCollateralBalance as H } from "./collateral/use-collateral-balance.js";
44
+ import { useSimulateApproveCollateral as U } from "./collateral/use-simulate-approve-collateral.js";
45
+ import { useDelegationExpiry as W } from "./instant-layer/use-delegation-expiry.js";
46
+ import { useGrantDelegation as G } from "./instant-layer/use-grant-delegation.js";
47
+ import { useInstantClose as K } from "./instant-layer/use-instant-close.js";
48
+ import { useInstantCloseAuto as q } from "./instant-layer/use-instant-close-auto.js";
49
+ import { useInstantCloseBulk as J } from "./instant-layer/use-instant-close-bulk.js";
50
+ import { useInstantCloseBulkAuto as Y } from "./instant-layer/use-instant-close-bulk-auto.js";
51
+ import { useInstantCloses as X } from "./instant-layer/use-instant-closes.js";
52
+ import { useInstantOpen as Z } from "./instant-layer/use-instant-open.js";
53
+ import { useInstantOpenAuto as Q } from "./instant-layer/use-instant-open-auto.js";
54
+ import { useInstantOpenQuoteId as $ } from "./instant-layer/use-instant-open-quote-id.js";
55
+ import { toQuoteTpSl as ee } from "./tpsl/to-quote-tpsl.js";
56
+ import { useTpSlRecord as te, useTpSlStore as ne } from "./tpsl/tpsl-store.js";
57
+ import { useInstantOpenWithTpSl as re } from "./instant-layer/use-instant-open-with-tpsl.js";
58
+ import { useInstantOpens as ie } from "./instant-layer/use-instant-opens.js";
59
+ import { useIsDelegationActive as ae } from "./instant-layer/use-is-delegation-active.js";
60
+ import { useSimulateGrantDelegation as oe } from "./instant-layer/use-simulate-grant-delegation.js";
61
+ import { useFinalizeWithdrawRequest as se } from "./withdraw/use-finalize-withdraw-request.js";
62
+ import { useInitiateWithdraw as ce } from "./withdraw/use-initiate-withdraw.js";
63
+ import { useLastWithdrawRequestId as le } from "./withdraw/use-last-withdraw-request-id.js";
64
+ import { usePendingWithdrawRequests as ue } from "./withdraw/use-pending-withdraw-requests.js";
65
+ import { useRequestCancelWithdraw as de } from "./withdraw/use-request-cancel-withdraw.js";
66
+ import { useSimulateFinalizeWithdrawRequest as fe } from "./withdraw/use-simulate-finalize-withdraw-request.js";
67
+ import { useSimulateInitiateWithdraw as pe } from "./withdraw/use-simulate-initiate-withdraw.js";
68
+ import { useSimulateRequestCancelWithdraw as me } from "./withdraw/use-simulate-request-cancel-withdraw.js";
69
+ import { useWithdrawRequest as he } from "./withdraw/use-withdraw-requests.js";
70
+ import { useWithdrawableTime as ge } from "./withdraw/use-withdrawable-time.js";
71
+ import { useMarkets as _e } from "./markets/use-markets.js";
72
+ import { useOnchainContractMarkets as ve } from "./markets/use-onchain-contract-markets.js";
73
+ import { useSolverErrorCodes as ye } from "./error-codes/use-solver-error-codes.js";
74
+ import { useSolverErrorMessage as be } from "./error-codes/use-solver-error-message.js";
75
+ import { useOptimisticQuotesStore as xe } from "./quotes/optimistic-quotes-store.js";
76
+ import { usePartyAOpenPositions as Se } from "./quotes/use-party-a-open-positions.js";
77
+ import { useAccountLiquidationPrice as Ce } from "./quotes/use-account-liquidation-price.js";
78
78
  import { useManagedQuotes as we } from "./quotes/use-managed-quotes.js";
79
79
  import { useGroupedQuotes as Te } from "./quotes/use-grouped-quotes.js";
80
80
  import { usePartyAPendingQuotes as Ee } from "./quotes/use-party-a-pending-quotes.js";
@@ -89,39 +89,41 @@ import { useEnigmaPriceByName as Pe } from "./price-service/use-enigma-price-by-
89
89
  import { useEnigmaPriceByMarketId as Fe } from "./price-service/use-enigma-price-by-market-id.js";
90
90
  import { useQuoteUpnlAndPnl as Ie } from "./quotes/use-quote-upnl-and-pnl.js";
91
91
  import { useSubgraphQuery as Le } from "./quotes/use-subgraph-query.js";
92
- import { useBalanceHistory as Re } from "./balance-history/use-balance-history.js";
93
- import { useDepositHistory as ze } from "./balance-history/use-deposit-history.js";
94
- import { useWithdrawHistory as Be } from "./balance-history/use-withdraw-history.js";
95
- import { useTransferHistory as Ve } from "./transfers/use-transfer-history.js";
96
- import { useLockedParams as He } from "./locked-params/use-locked-params.js";
97
- import { DEFAULT_NOTIONAL_CAP_POLLING_MS as Ue, useNotionalCapBySymbolId as We } from "./notional-cap/use-notional-cap-by-symbol-id.js";
98
- import { useNotionalCapAll as Ge } from "./notional-cap/use-notional-cap-all.js";
99
- import { useOpenInterestBySymbolId as Ke } from "./notional-cap/use-open-interest-by-symbol-id.js";
100
- import { useFundingInfo as qe } from "./funding-info/use-funding-info.js";
101
- import { useMarketInfo as Je } from "./market-info/use-market-info.js";
102
- import { useFeeForUser as Ye } from "./fees/use-fee-for-user.js";
103
- import { useEnigmaPriceServiceHealth as Xe } from "./price-service/use-enigma-price-service-health.js";
104
- import { useEnigmaPriceServiceMetadata as Ze } from "./price-service/use-enigma-price-service-metadata.js";
105
- import { useEnigmaPriceServicePricesByAddresses as Qe } from "./price-service/use-enigma-price-service-prices-by-addresses.js";
106
- import { useEnigmaPriceServicePricesByNames as $e } from "./price-service/use-enigma-price-service-prices-by-names.js";
107
- import { useEnigmaPriceServiceSymbolsInfo as et } from "./price-service/use-enigma-price-service-symbols-info.js";
108
- import { useEnigmaPrices as tt } from "./price-service/use-enigma-prices.js";
109
- import { useSearchNotifications as nt } from "./notifications/use-search-notifications.js";
110
- import { useDeallocateUpnlSig as rt } from "./muon/use-deallocate-upnl-sig.js";
111
- import { useMuonPartyAOverview as it } from "./muon/use-muon-party-a-overview.js";
112
- import { useMuonPrice as at } from "./muon/use-muon-price.js";
113
- import { useMuonPriceRange as ot } from "./muon/use-muon-price-range.js";
114
- import { useMuonSettleUpnl as st } from "./muon/use-muon-settle-upnl.js";
115
- import { useMuonUpnl as ct } from "./muon/use-muon-upnl.js";
116
- import { useMuonUpnlA as lt } from "./muon/use-muon-upnl-a.js";
117
- import { useMuonUpnlAWithSymbolPrice as ut } from "./muon/use-muon-upnl-a-with-symbol-price.js";
118
- import { useMuonUpnlB as dt } from "./muon/use-muon-upnl-b.js";
119
- import { useMuonUpnlWithSymbolPrice as ft } from "./muon/use-muon-upnl-with-symbol-price.js";
120
- import { useDeleteQuoteTpSl as pt } from "./tpsl/use-delete-quote-tpsl.js";
121
- import { useWatchTpSlNotifications as mt } from "./tpsl/use-watch-tpsl-notifications.js";
122
- import { useQuoteTpSl as ht } from "./tpsl/use-quote-tpsl.js";
123
- import { useSetQuoteTpSl as gt } from "./tpsl/use-set-quote-tpsl.js";
124
- import { useTpSlConfig as _t } from "./tpsl/use-tpsl-config.js";
125
- import { useTpSlSigningSpec as vt } from "./tpsl/use-tpsl-signing-spec.js";
126
- import { ADD_MARGIN_TO_NEXT_VA_SELECTOR as yt, DEFAULT_TPSL_SLIPPAGE_LOWCAPS as bt, INSTANT_TRADE_REQUIRED_SELECTORS as xt, NotificationType as St, OrderType as Ct, PositionType as wt, QuoteStatus as Tt, REQUEST_TO_CLOSE_POSITION_SELECTOR as Et, SEND_QUOTE_WITH_AFFILIATE_AND_DATA_SELECTOR as Dt, SubAccountIsolationType as Ot, SymmApiError as kt, SymmError as At, VIRTUAL_ACCOUNT_ISOLATION_TYPE as jt, ZERO_LEG as Mt, buildConditionalOrderLeg as Nt, buildConditionalOrderMessage as Pt, buildTpSlDeleteMessage as Ft, calculateClosePrice as It, calculateTradeParams as Lt, clampClosePrecision as Rt, deleteQuoteTpSl as zt, deleteQuoteTpSlMutationOptions as Bt, generateTpSlSalt as Vt, getPartyAOpenPositionsQueryKey as Ht, getPartyAOpenPositionsQueryOptions as Ut, isolationTypeForSide as Wt, parseTpSlFrame as Gt, priceSlippageCalculation as Kt, signTpSlRequest as qt, toSignableTpSlMessage as Jt, validateInstantCloseAgainstMarket as Yt, validateInstantOpenAgainstMarket as Xt, validateTpSl as Zt, watchTpSlNotifications as Qt } from "@symmio/trading-core";
127
- export { yt as ADD_MARGIN_TO_NEXT_VA_SELECTOR, Ue as DEFAULT_NOTIONAL_CAP_POLLING_MS, bt as DEFAULT_TPSL_SLIPPAGE_LOWCAPS, xt as INSTANT_TRADE_REQUIRED_SELECTORS, St as NotificationType, Ct as OrderType, wt as PositionType, Tt as QuoteStatus, Et as REQUEST_TO_CLOSE_POSITION_SELECTOR, Dt as SEND_QUOTE_WITH_AFFILIATE_AND_DATA_SELECTOR, Ot as SubAccountIsolationType, kt as SymmApiError, At as SymmError, e as SymmioProvider, r as SymmioRequestError, jt as VIRTUAL_ACCOUNT_ISOLATION_TYPE, Mt as ZERO_LEG, Nt as buildConditionalOrderLeg, Pt as buildConditionalOrderMessage, Ft as buildTpSlDeleteMessage, It as calculateClosePrice, Lt as calculateTradeParams, Rt as clampClosePrecision, zt as deleteQuoteTpSl, Bt as deleteQuoteTpSlMutationOptions, Vt as generateTpSlSalt, Ht as getPartyAOpenPositionsQueryKey, Ut as getPartyAOpenPositionsQueryOptions, Wt as isolationTypeForSide, i as normalizeSymmError, Gt as parseTpSlFrame, f as predicateMatch, Kt as priceSlippageCalculation, qt as signTpSlRequest, $ as toQuoteTpSl, Jt as toSignableTpSlMessage, l as useAccountBalanceInfo, u as useAccountBalanceOf, Se as useAccountLiquidationPrice, p as useAddMargin, m as useAllocate, z as useApproveCollateral, Re as useBalanceHistory, B as useCollateralAllowance, V as useCollateralBalance, a as useConnectWallet, h as useCreateSubAccounts, g as useDeallocate, rt as useDeallocateUpnlSig, U as useDelegationExpiry, pt as useDeleteQuoteTpSl, _ as useDeleteSubAccount, v as useDeposit, y as useDepositAndAllocate, ze as useDepositHistory, o as useDisconnectWallet, b as useEditAccountName, Fe as useEnigmaPriceByMarketId, Pe as useEnigmaPriceByName, Xe as useEnigmaPriceServiceHealth, Ze as useEnigmaPriceServiceMetadata, Qe as useEnigmaPriceServicePricesByAddresses, $e as useEnigmaPriceServicePricesByNames, et as useEnigmaPriceServiceSymbolsInfo, tt as useEnigmaPrices, Ye as useFeeForUser, oe as useFinalizeWithdrawRequest, qe as useFundingInfo, W as useGrantDelegation, Te as useGroupedQuotes, se as useInitiateWithdraw, G as useInstantClose, K as useInstantCloseAuto, q as useInstantCloseBulk, J as useInstantCloseBulkAuto, Y as useInstantCloses, X as useInstantOpen, Z as useInstantOpenAuto, Q as useInstantOpenQuoteId, ne as useInstantOpenWithTpSl, re as useInstantOpens, ie as useIsDelegationActive, ce as useLastWithdrawRequestId, He as useLockedParams, we as useManagedQuotes, Je as useMarketInfo, ge as useMarkets, it as useMuonPartyAOverview, at as useMuonPrice, ot as useMuonPriceRange, st as useMuonSettleUpnl, ct as useMuonUpnl, lt as useMuonUpnlA, ut as useMuonUpnlAWithSymbolPrice, dt as useMuonUpnlB, ft as useMuonUpnlWithSymbolPrice, Ce as useNotifications, Ge as useNotionalCapAll, We as useNotionalCapBySymbolId, _e as useOnchainContractMarkets, Ke as useOpenInterestBySymbolId, be as useOptimisticQuotesStore, xe as usePartyAOpenPositions, Ee as usePartyAPendingQuotes, le as usePendingWithdrawRequests, x as usePredictedNextVirtualAccount, De as useQuote, Oe as useQuoteEventsByType, Ae as useQuoteFunding, je as useQuoteHistory, Me as useQuotePlatformFee, Ne as useQuotePriceHistory, ht as useQuoteTpSl, Ie as useQuoteUpnlAndPnl, ke as useQuotesFunding, S as useRemoveMargin, ue as useRequestCancelWithdraw, nt as useSearchNotifications, gt as useSetQuoteTpSl, C as useSimulateAddMargin, w as useSimulateAllocate, H as useSimulateApproveCollateral, T as useSimulateCreateSubAccounts, E as useSimulateDeallocate, D as useSimulateDeleteSubAccount, O as useSimulateDeposit, k as useSimulateDepositAndAllocate, A as useSimulateEditAccountName, de as useSimulateFinalizeWithdrawRequest, ae as useSimulateGrantDelegation, fe as useSimulateInitiateWithdraw, j as useSimulateRemoveMargin, pe as useSimulateRequestCancelWithdraw, ve as useSolverErrorCodes, ye as useSolverErrorMessage, M as useSubAccount, N as useSubAccountVirtualNonce, P as useSubAccountsCountOfUser, Le as useSubgraphQuery, s as useSwitchToSymmioChain, t as useSymmioChainId, n as useSymmioConfig, _t as useTpSlConfig, ee as useTpSlRecord, vt as useTpSlSigningSpec, te as useTpSlStore, d as useTransactionsStore, Ve as useTransferHistory, F as useUserSubAccounts, I as useUserSubAccountsAddresses, L as useVirtualAccount, R as useVirtualAccountsAddressesOfSubAccount, c as useWalletAccount, mt as useWatchTpSlNotifications, Be as useWithdrawHistory, me as useWithdrawRequest, he as useWithdrawableTime, Yt as validateInstantCloseAgainstMarket, Xt as validateInstantOpenAgainstMarket, Zt as validateTpSl, Qt as watchTpSlNotifications };
92
+ import { useFeeForUser as Re } from "./fees/use-fee-for-user.js";
93
+ import { useAvailableInstantOpenMargin as ze } from "./margin/use-available-instant-open-margin.js";
94
+ import { useBalanceHistory as Be } from "./balance-history/use-balance-history.js";
95
+ import { useDepositHistory as Ve } from "./balance-history/use-deposit-history.js";
96
+ import { useWithdrawHistory as He } from "./balance-history/use-withdraw-history.js";
97
+ import { useTransferHistory as Ue } from "./transfers/use-transfer-history.js";
98
+ import { useLockedParams as We } from "./locked-params/use-locked-params.js";
99
+ import { DEFAULT_NOTIONAL_CAP_POLLING_MS as Ge, useNotionalCapBySymbolId as Ke } from "./notional-cap/use-notional-cap-by-symbol-id.js";
100
+ import { useNotionalCapAll as qe } from "./notional-cap/use-notional-cap-all.js";
101
+ import { useOpenInterestBySymbolId as Je } from "./notional-cap/use-open-interest-by-symbol-id.js";
102
+ import { useEstimatedPrice as Ye } from "./estimated-price/use-estimated-price.js";
103
+ import { useFundingInfo as Xe } from "./funding-info/use-funding-info.js";
104
+ import { useMarketInfo as Ze } from "./market-info/use-market-info.js";
105
+ import { useEnigmaPriceServiceHealth as Qe } from "./price-service/use-enigma-price-service-health.js";
106
+ import { useEnigmaPriceServiceMetadata as $e } from "./price-service/use-enigma-price-service-metadata.js";
107
+ import { useEnigmaPriceServicePricesByAddresses as et } from "./price-service/use-enigma-price-service-prices-by-addresses.js";
108
+ import { useEnigmaPriceServicePricesByNames as tt } from "./price-service/use-enigma-price-service-prices-by-names.js";
109
+ import { useEnigmaPriceServiceSymbolsInfo as nt } from "./price-service/use-enigma-price-service-symbols-info.js";
110
+ import { useEnigmaPrices as rt } from "./price-service/use-enigma-prices.js";
111
+ import { useSearchNotifications as it } from "./notifications/use-search-notifications.js";
112
+ import { useDeallocateUpnlSig as at } from "./muon/use-deallocate-upnl-sig.js";
113
+ import { useMuonPartyAOverview as ot } from "./muon/use-muon-party-a-overview.js";
114
+ import { useMuonPrice as st } from "./muon/use-muon-price.js";
115
+ import { useMuonPriceRange as ct } from "./muon/use-muon-price-range.js";
116
+ import { useMuonSettleUpnl as lt } from "./muon/use-muon-settle-upnl.js";
117
+ import { useMuonUpnl as ut } from "./muon/use-muon-upnl.js";
118
+ import { useMuonUpnlA as dt } from "./muon/use-muon-upnl-a.js";
119
+ import { useMuonUpnlAWithSymbolPrice as ft } from "./muon/use-muon-upnl-a-with-symbol-price.js";
120
+ import { useMuonUpnlB as pt } from "./muon/use-muon-upnl-b.js";
121
+ import { useMuonUpnlWithSymbolPrice as mt } from "./muon/use-muon-upnl-with-symbol-price.js";
122
+ import { useDeleteQuoteTpSl as ht } from "./tpsl/use-delete-quote-tpsl.js";
123
+ import { useWatchTpSlNotifications as gt } from "./tpsl/use-watch-tpsl-notifications.js";
124
+ import { useQuoteTpSl as _t } from "./tpsl/use-quote-tpsl.js";
125
+ import { useSetQuoteTpSl as vt } from "./tpsl/use-set-quote-tpsl.js";
126
+ import { useTpSlConfig as yt } from "./tpsl/use-tpsl-config.js";
127
+ import { useTpSlSigningSpec as bt } from "./tpsl/use-tpsl-signing-spec.js";
128
+ import { ADD_MARGIN_TO_NEXT_VA_SELECTOR as xt, DEFAULT_TPSL_SLIPPAGE_LOWCAPS as St, INSTANT_TRADE_REQUIRED_SELECTORS as Ct, NotificationType as wt, OrderType as Tt, PositionType as Et, QuoteStatus as Dt, REQUEST_TO_CLOSE_POSITION_SELECTOR as Ot, SEND_QUOTE_WITH_AFFILIATE_AND_DATA_SELECTOR as kt, SubAccountIsolationType as At, SymmApiError as jt, SymmError as Mt, VIRTUAL_ACCOUNT_ISOLATION_TYPE as Nt, ZERO_LEG as Pt, buildConditionalOrderLeg as Ft, buildConditionalOrderMessage as It, buildTpSlDeleteMessage as Lt, calculateAvailableInstantOpenMargin as Rt, calculateClosePrice as zt, calculatePriceImpact as Bt, calculateQuotePnl as Vt, calculateTradeParams as Ht, clampClosePrecision as Ut, deleteQuoteTpSl as Wt, deleteQuoteTpSlMutationOptions as Gt, generateTpSlSalt as Kt, getPartyAOpenPositionsQueryKey as qt, getPartyAOpenPositionsQueryOptions as Jt, isolationTypeForSide as Yt, parseTpSlFrame as Xt, priceSlippageCalculation as Zt, signTpSlRequest as Qt, toSignableTpSlMessage as $t, validateInstantCloseAgainstMarket as en, validateInstantOpenAgainstMarket as tn, validateTpSl as nn, watchTpSlNotifications as rn } from "@symmio/trading-core";
129
+ export { xt as ADD_MARGIN_TO_NEXT_VA_SELECTOR, Ge as DEFAULT_NOTIONAL_CAP_POLLING_MS, St as DEFAULT_TPSL_SLIPPAGE_LOWCAPS, Ct as INSTANT_TRADE_REQUIRED_SELECTORS, wt as NotificationType, Tt as OrderType, Et as PositionType, Dt as QuoteStatus, Ot as REQUEST_TO_CLOSE_POSITION_SELECTOR, kt as SEND_QUOTE_WITH_AFFILIATE_AND_DATA_SELECTOR, At as SubAccountIsolationType, jt as SymmApiError, Mt as SymmError, e as SymmioProvider, r as SymmioRequestError, Nt as VIRTUAL_ACCOUNT_ISOLATION_TYPE, Pt as ZERO_LEG, Ft as buildConditionalOrderLeg, It as buildConditionalOrderMessage, Lt as buildTpSlDeleteMessage, Rt as calculateAvailableInstantOpenMargin, zt as calculateClosePrice, Bt as calculatePriceImpact, Vt as calculateQuotePnl, Ht as calculateTradeParams, Ut as clampClosePrecision, Wt as deleteQuoteTpSl, Gt as deleteQuoteTpSlMutationOptions, Kt as generateTpSlSalt, qt as getPartyAOpenPositionsQueryKey, Jt as getPartyAOpenPositionsQueryOptions, Yt as isolationTypeForSide, i as normalizeSymmError, Xt as parseTpSlFrame, p as predicateMatch, Zt as priceSlippageCalculation, Qt as signTpSlRequest, ee as toQuoteTpSl, $t as toSignableTpSlMessage, u as useAccountBalanceInfo, d as useAccountBalanceOf, Ce as useAccountLiquidationPrice, m as useAddMargin, h as useAllocate, B as useApproveCollateral, ze as useAvailableInstantOpenMargin, Be as useBalanceHistory, V as useCollateralAllowance, H as useCollateralBalance, a as useConnectWallet, g as useCreateSubAccounts, _ as useDeallocate, at as useDeallocateUpnlSig, W as useDelegationExpiry, ht as useDeleteQuoteTpSl, v as useDeleteSubAccount, y as useDeposit, b as useDepositAndAllocate, Ve as useDepositHistory, o as useDisconnectWallet, x as useEditAccountName, Fe as useEnigmaPriceByMarketId, Pe as useEnigmaPriceByName, Qe as useEnigmaPriceServiceHealth, $e as useEnigmaPriceServiceMetadata, et as useEnigmaPriceServicePricesByAddresses, tt as useEnigmaPriceServicePricesByNames, nt as useEnigmaPriceServiceSymbolsInfo, rt as useEnigmaPrices, Ye as useEstimatedPrice, Re as useFeeForUser, se as useFinalizeWithdrawRequest, Xe as useFundingInfo, G as useGrantDelegation, Te as useGroupedQuotes, ce as useInitiateWithdraw, K as useInstantClose, q as useInstantCloseAuto, J as useInstantCloseBulk, Y as useInstantCloseBulkAuto, X as useInstantCloses, Z as useInstantOpen, Q as useInstantOpenAuto, $ as useInstantOpenQuoteId, re as useInstantOpenWithTpSl, ie as useInstantOpens, ae as useIsDelegationActive, le as useLastWithdrawRequestId, We as useLockedParams, we as useManagedQuotes, Ze as useMarketInfo, _e as useMarkets, ot as useMuonPartyAOverview, st as useMuonPrice, ct as useMuonPriceRange, lt as useMuonSettleUpnl, ut as useMuonUpnl, dt as useMuonUpnlA, ft as useMuonUpnlAWithSymbolPrice, pt as useMuonUpnlB, mt as useMuonUpnlWithSymbolPrice, l as useNotifications, qe as useNotionalCapAll, Ke as useNotionalCapBySymbolId, ve as useOnchainContractMarkets, Je as useOpenInterestBySymbolId, xe as useOptimisticQuotesStore, Se as usePartyAOpenPositions, Ee as usePartyAPendingQuotes, ue as usePendingWithdrawRequests, S as usePredictedNextVirtualAccount, De as useQuote, Oe as useQuoteEventsByType, Ae as useQuoteFunding, je as useQuoteHistory, Me as useQuotePlatformFee, Ne as useQuotePriceHistory, _t as useQuoteTpSl, Ie as useQuoteUpnlAndPnl, ke as useQuotesFunding, C as useRemoveMargin, de as useRequestCancelWithdraw, it as useSearchNotifications, vt as useSetQuoteTpSl, w as useSimulateAddMargin, T as useSimulateAllocate, U as useSimulateApproveCollateral, E as useSimulateCreateSubAccounts, D as useSimulateDeallocate, O as useSimulateDeleteSubAccount, k as useSimulateDeposit, A as useSimulateDepositAndAllocate, j as useSimulateEditAccountName, fe as useSimulateFinalizeWithdrawRequest, oe as useSimulateGrantDelegation, pe as useSimulateInitiateWithdraw, M as useSimulateRemoveMargin, me as useSimulateRequestCancelWithdraw, ye as useSolverErrorCodes, be as useSolverErrorMessage, N as useSubAccount, P as useSubAccountVirtualNonce, F as useSubAccountsCountOfUser, Le as useSubgraphQuery, s as useSwitchToSymmioChain, t as useSymmioChainId, n as useSymmioConfig, yt as useTpSlConfig, te as useTpSlRecord, bt as useTpSlSigningSpec, ne as useTpSlStore, f as useTransactionsStore, Ue as useTransferHistory, I as useUserSubAccounts, L as useUserSubAccountsAddresses, R as useVirtualAccount, z as useVirtualAccountsAddressesOfSubAccount, c as useWalletAccount, gt as useWatchTpSlNotifications, He as useWithdrawHistory, he as useWithdrawRequest, ge as useWithdrawableTime, en as validateInstantCloseAgainstMarket, tn as validateInstantOpenAgainstMarket, nn as validateTpSl, rn as watchTpSlNotifications };
@@ -1 +1 @@
1
- {"version":3,"file":"use-instant-open-with-tpsl.d.ts","sourceRoot":"","sources":["../../src/instant-layer/use-instant-open-with-tpsl.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAMzE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,+BAAgC,SAAQ,4BAA4B;IACnF,IAAI,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;CAC5D;AAED,sEAAsE;AACtE,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,qBAAqB,CAAC;IACnC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAC9B,mFAAmF;IACnF,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC;AAED,kDAAkD;AAClD,MAAM,MAAM,2BAA2B,GAAG,MAAM,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,GAAG,OAAO,CAAC;AAEtG,qDAAqD;AACrD,MAAM,MAAM,gCAAgC,GAAG,eAAe,CAAC;AAE/D,qDAAqD;AACrD,MAAM,MAAM,gCAAgC,GAAG,iBAAiB,CAC9D,0BAA0B,EAC1B,kBAAkB,EAClB,+BAA+B,CAChC,GAAG;IACF,+DAA+D;IAC/D,KAAK,EAAE,2BAA2B,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,GAAE,gCAAqC,GAChD,gCAAgC,CAiElC"}
1
+ {"version":3,"file":"use-instant-open-with-tpsl.d.ts","sourceRoot":"","sources":["../../src/instant-layer/use-instant-open-with-tpsl.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAMzE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,+BAAgC,SAAQ,4BAA4B;IACnF,IAAI,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;CAC5D;AAED,sEAAsE;AACtE,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,qBAAqB,CAAC;IACnC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAC9B,mFAAmF;IACnF,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC;AAED,kDAAkD;AAClD,MAAM,MAAM,2BAA2B,GAAG,MAAM,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,GAAG,OAAO,CAAC;AAEtG,qDAAqD;AACrD,MAAM,MAAM,gCAAgC,GAAG,eAAe,CAAC;AAE/D,qDAAqD;AACrD,MAAM,MAAM,gCAAgC,GAAG,iBAAiB,CAC9D,0BAA0B,EAC1B,kBAAkB,EAClB,+BAA+B,CAChC,GAAG;IACF,+DAA+D;IAC/D,KAAK,EAAE,2BAA2B,CAAC;CACpC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,GAAE,gCAAqC,GAChD,gCAAgC,CAiFlC"}
@@ -34,8 +34,16 @@ function d(d = {}) {
34
34
  ...e.tpsl,
35
35
  chainId: t,
36
36
  quoteId: c
37
- });
38
- return e.tpsl.tp && _(c, "tp"), e.tpsl.sl && _(c, "sl"), y("success"), {
37
+ }), r = e.tpsl.tp, a = e.tpsl.sl;
38
+ return r && _(c, "tp", {
39
+ price: r.triggerPrice,
40
+ priceType: r.priceType,
41
+ cohQuoteId: n.cohQuoteId
42
+ }), a && _(c, "sl", {
43
+ price: a.triggerPrice,
44
+ priceType: a.priceType,
45
+ cohQuoteId: n.cohQuoteId
46
+ }), y("success"), {
39
47
  instantOpen: i,
40
48
  tpsl: n
41
49
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-instant-open-with-tpsl.js","names":[],"sources":["../../src/instant-layer/use-instant-open-with-tpsl.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getInstantOpensQueryKey,\n instantOpenAutoMutationOptions,\n setQuoteTpSlMutationOptions,\n type ConfigParameter,\n type InstantOpenReturnType,\n type PrepareInstantOpenParameters,\n type SetQuoteTpSlParameters,\n type SetQuoteTpSlReturnType,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useState } from \"react\";\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 { useTpSlStore } from \"../tpsl/tpsl-store\";\nimport { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useInstantOpenWithTpSl}: the standard instant-open\n * inputs, plus an optional `tpsl` block that mirrors {@link SetQuoteTpSlParameters}\n * minus `quoteId` (derived from the hedger response) and `chainId` (defaulted).\n *\n * When `tpsl` is omitted (or both `tp` and `sl` are empty), the hook behaves\n * exactly like {@link useInstantOpenAuto}. When present, the SDK dispatches\n * `setQuoteTpSl` immediately after the hedger returns a `tempQuoteId` — the\n * message is signed against the (predicted) VA the caller supplies, so no\n * on-chain reconciliation wait is needed. Confirmation still comes through the\n * TP/SL WebSocket picked up by {@link useQuoteTpSl}.\n */\nexport interface UseInstantOpenWithTpSlVariables extends PrepareInstantOpenParameters {\n tpsl?: Omit<SetQuoteTpSlParameters, \"quoteId\" | \"chainId\">;\n}\n\n/** Aggregated success payload from {@link useInstantOpenWithTpSl}. */\nexport interface UseInstantOpenWithTpSlData {\n instantOpen: InstantOpenReturnType;\n /** Set when the TP/SL leg was attempted and succeeded. */\n tpsl?: SetQuoteTpSlReturnType;\n /** Set when the TP/SL leg was attempted and failed — instant open still landed. */\n tpslError?: SymmioRequestError;\n}\n\n/** Which leg the orchestrator is currently on. */\nexport type UseInstantOpenWithTpSlPhase = \"idle\" | \"opening\" | \"attaching-tpsl\" | \"success\" | \"error\";\n\n/** Parameters for {@link useInstantOpenWithTpSl}. */\nexport type UseInstantOpenWithTpSlParameters = ConfigParameter;\n\n/** Return type of {@link useInstantOpenWithTpSl}. */\nexport type UseInstantOpenWithTpSlReturnType = UseMutationResult<\n UseInstantOpenWithTpSlData,\n SymmioRequestError,\n UseInstantOpenWithTpSlVariables\n> & {\n /** Current orchestration phase. Handy for phased status UI. */\n phase: UseInstantOpenWithTpSlPhase;\n};\n\n/**\n * One-shot orchestrator: post an instant open and — if the caller pre-filled\n * a TP/SL block — immediately submit `setQuoteTpSl` using the hedger's returned\n * `tempQuoteId`. Web layer just wires inputs; all mutation logic (both legs +\n * cache invalidation + confirming-slot write) lives in the SDK.\n *\n * @example\n * ```tsx\n * const open = useInstantOpenWithTpSl();\n * open.mutate({\n * ...instantOpenParams,\n * tpsl: hasTpOrSl\n * ? { from: sessionKey, virtualAccount: predictedVa, subAccount,\n * symbolId, positionType, quantity, pricePrecision, tp, sl }\n * : undefined,\n * });\n * ```\n */\nexport function useInstantOpenWithTpSl(\n parameters: UseInstantOpenWithTpSlParameters = {},\n): UseInstantOpenWithTpSlReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const openBase = instantOpenAutoMutationOptions(config);\n const tpslBase = setQuoteTpSlMutationOptions(config);\n const markConfirming = useTpSlStore((state) => state.markConfirming);\n\n const [phase, setPhase] = useState<UseInstantOpenWithTpSlPhase>(\"idle\");\n\n const mutation = useMutation<UseInstantOpenWithTpSlData, SymmioRequestError, UseInstantOpenWithTpSlVariables>({\n mutationKey: [\"useInstantOpenWithTpSl\"] as const,\n mutationFn: async (variables) => {\n const resolvedChainId = variables.chainId ?? chainId;\n setPhase(\"opening\");\n let openResult: InstantOpenReturnType;\n try {\n openResult = await openBase.mutationFn({ ...variables, chainId: resolvedChainId });\n } catch (err) {\n setPhase(\"error\");\n throw normalizeSymmError(err);\n }\n\n // Refresh the instant-opens feed the moment the hedger accepts.\n const configKey = config.getChainConfigKey(resolvedChainId);\n void queryClient.invalidateQueries({ predicate: predicateMatch(getInstantOpensQueryKey, { configKey }) });\n\n const wantsTpSl = Boolean(variables.tpsl && (variables.tpsl.tp || variables.tpsl.sl));\n if (!wantsTpSl || !openResult.tempQuoteId) {\n setPhase(\"success\");\n return { instantOpen: openResult };\n }\n\n const tempIdNumber = Number(openResult.tempQuoteId);\n if (!Number.isFinite(tempIdNumber)) {\n setPhase(\"success\");\n return { instantOpen: openResult };\n }\n\n setPhase(\"attaching-tpsl\");\n const quoteId = BigInt(tempIdNumber);\n try {\n const tpslResult = await tpslBase.mutationFn({\n ...(variables.tpsl as Omit<SetQuoteTpSlParameters, \"quoteId\" | \"chainId\">),\n chainId: resolvedChainId,\n quoteId,\n });\n // Mirror useSetQuoteTpSl.onSuccess: mark confirming for the sides we\n // submitted so useQuoteTpSl overlays \"Processing…\" until the WS report.\n if (variables.tpsl!.tp) markConfirming(quoteId, \"tp\");\n if (variables.tpsl!.sl) markConfirming(quoteId, \"sl\");\n setPhase(\"success\");\n return { instantOpen: openResult, tpsl: tpslResult };\n } catch (err) {\n // Instant open landed; only the TP/SL leg failed. Surface it on the\n // return payload rather than throwing, so callers can render a partial\n // success state without losing the trade.\n setPhase(\"success\");\n return { instantOpen: openResult, tpslError: normalizeSymmError(err) };\n }\n },\n onError: () => setPhase(\"error\"),\n }) as UseMutationResult<UseInstantOpenWithTpSlData, SymmioRequestError, UseInstantOpenWithTpSlVariables>;\n\n return Object.assign(mutation, { phase });\n}\n"],"mappings":";;;;;;;;;;AAgFA,SAAgB,EACd,IAA+C,CAAC,GACd;CAClC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAW,EAA+B,CAAM,GAChD,IAAW,EAA4B,CAAM,GAC7C,IAAiB,GAAc,MAAU,EAAM,cAAc,GAE7D,CAAC,GAAO,KAAY,EAAsC,MAAM,GAEhE,IAAW,EAA6F;EAC5G,aAAa,CAAC,wBAAwB;EACtC,YAAY,OAAO,MAAc;GAC/B,IAAM,IAAkB,EAAU,WAAW;GAC7C,EAAS,SAAS;GAClB,IAAI;GACJ,IAAI;IACF,IAAa,MAAM,EAAS,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC;GACnF,SAAS,GAAK;IAEZ,MADA,EAAS,OAAO,GACV,EAAmB,CAAG;GAC9B;GAGA,IAAM,IAAY,EAAO,kBAAkB,CAAe;GAI1D,IAHA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAyB,EAAE,aAAU,CAAC,EAAE,CAAC,GAGpG,EADsB,EAAU,SAAS,EAAU,KAAK,MAAM,EAAU,KAAK,QAC/D,CAAC,EAAW,aAE5B,OADA,EAAS,SAAS,GACX,EAAE,aAAa,EAAW;GAGnC,IAAM,IAAe,OAAO,EAAW,WAAW;GAClD,IAAI,CAAC,OAAO,SAAS,CAAY,GAE/B,OADA,EAAS,SAAS,GACX,EAAE,aAAa,EAAW;GAGnC,EAAS,gBAAgB;GACzB,IAAM,IAAU,OAAO,CAAY;GACnC,IAAI;IACF,IAAM,IAAa,MAAM,EAAS,WAAW;KAC3C,GAAI,EAAU;KACd,SAAS;KACT;IACF,CAAC;IAMD,OAHI,EAAU,KAAM,MAAI,EAAe,GAAS,IAAI,GAChD,EAAU,KAAM,MAAI,EAAe,GAAS,IAAI,GACpD,EAAS,SAAS,GACX;KAAE,aAAa;KAAY,MAAM;IAAW;GACrD,SAAS,GAAK;IAKZ,OADA,EAAS,SAAS,GACX;KAAE,aAAa;KAAY,WAAW,EAAmB,CAAG;IAAE;GACvE;EACF;EACA,eAAe,EAAS,OAAO;CACjC,CAAC;CAED,OAAO,OAAO,OAAO,GAAU,EAAE,SAAM,CAAC;AAC1C"}
1
+ {"version":3,"file":"use-instant-open-with-tpsl.js","names":[],"sources":["../../src/instant-layer/use-instant-open-with-tpsl.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getInstantOpensQueryKey,\n instantOpenAutoMutationOptions,\n setQuoteTpSlMutationOptions,\n type ConfigParameter,\n type InstantOpenReturnType,\n type PrepareInstantOpenParameters,\n type SetQuoteTpSlParameters,\n type SetQuoteTpSlReturnType,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\nimport { useState } from \"react\";\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 { useTpSlStore } from \"../tpsl/tpsl-store\";\nimport { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useInstantOpenWithTpSl}: the standard instant-open\n * inputs, plus an optional `tpsl` block that mirrors {@link SetQuoteTpSlParameters}\n * minus `quoteId` (derived from the hedger response) and `chainId` (defaulted).\n *\n * When `tpsl` is omitted (or both `tp` and `sl` are empty), the hook behaves\n * exactly like {@link useInstantOpenAuto}. When present, the SDK dispatches\n * `setQuoteTpSl` immediately after the hedger returns a `tempQuoteId` — the\n * message is signed against the (predicted) VA the caller supplies, so no\n * on-chain reconciliation wait is needed. Confirmation still comes through the\n * TP/SL WebSocket picked up by {@link useQuoteTpSl}.\n */\nexport interface UseInstantOpenWithTpSlVariables extends PrepareInstantOpenParameters {\n tpsl?: Omit<SetQuoteTpSlParameters, \"quoteId\" | \"chainId\">;\n}\n\n/** Aggregated success payload from {@link useInstantOpenWithTpSl}. */\nexport interface UseInstantOpenWithTpSlData {\n instantOpen: InstantOpenReturnType;\n /** Set when the TP/SL leg was attempted and succeeded. */\n tpsl?: SetQuoteTpSlReturnType;\n /** Set when the TP/SL leg was attempted and failed — instant open still landed. */\n tpslError?: SymmioRequestError;\n}\n\n/** Which leg the orchestrator is currently on. */\nexport type UseInstantOpenWithTpSlPhase = \"idle\" | \"opening\" | \"attaching-tpsl\" | \"success\" | \"error\";\n\n/** Parameters for {@link useInstantOpenWithTpSl}. */\nexport type UseInstantOpenWithTpSlParameters = ConfigParameter;\n\n/** Return type of {@link useInstantOpenWithTpSl}. */\nexport type UseInstantOpenWithTpSlReturnType = UseMutationResult<\n UseInstantOpenWithTpSlData,\n SymmioRequestError,\n UseInstantOpenWithTpSlVariables\n> & {\n /** Current orchestration phase. Handy for phased status UI. */\n phase: UseInstantOpenWithTpSlPhase;\n};\n\n/**\n * One-shot orchestrator: post an instant open and — if the caller pre-filled\n * a TP/SL block — immediately submit `setQuoteTpSl` using the hedger's returned\n * `tempQuoteId`. Web layer just wires inputs; all mutation logic (both legs +\n * cache invalidation + confirming-slot write) lives in the SDK.\n *\n * @example\n * ```tsx\n * const open = useInstantOpenWithTpSl();\n * open.mutate({\n * ...instantOpenParams,\n * tpsl: hasTpOrSl\n * ? { from: sessionKey, virtualAccount: predictedVa, subAccount,\n * symbolId, positionType, quantity, pricePrecision, tp, sl }\n * : undefined,\n * });\n * ```\n */\nexport function useInstantOpenWithTpSl(\n parameters: UseInstantOpenWithTpSlParameters = {},\n): UseInstantOpenWithTpSlReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const openBase = instantOpenAutoMutationOptions(config);\n const tpslBase = setQuoteTpSlMutationOptions(config);\n const markConfirming = useTpSlStore((state) => state.markConfirming);\n\n const [phase, setPhase] = useState<UseInstantOpenWithTpSlPhase>(\"idle\");\n\n const mutation = useMutation<UseInstantOpenWithTpSlData, SymmioRequestError, UseInstantOpenWithTpSlVariables>({\n mutationKey: [\"useInstantOpenWithTpSl\"] as const,\n mutationFn: async (variables) => {\n const resolvedChainId = variables.chainId ?? chainId;\n setPhase(\"opening\");\n let openResult: InstantOpenReturnType;\n try {\n openResult = await openBase.mutationFn({ ...variables, chainId: resolvedChainId });\n } catch (err) {\n setPhase(\"error\");\n throw normalizeSymmError(err);\n }\n\n // Refresh the instant-opens feed the moment the hedger accepts.\n const configKey = config.getChainConfigKey(resolvedChainId);\n void queryClient.invalidateQueries({ predicate: predicateMatch(getInstantOpensQueryKey, { configKey }) });\n\n const wantsTpSl = Boolean(variables.tpsl && (variables.tpsl.tp || variables.tpsl.sl));\n if (!wantsTpSl || !openResult.tempQuoteId) {\n setPhase(\"success\");\n return { instantOpen: openResult };\n }\n\n const tempIdNumber = Number(openResult.tempQuoteId);\n if (!Number.isFinite(tempIdNumber)) {\n setPhase(\"success\");\n return { instantOpen: openResult };\n }\n\n setPhase(\"attaching-tpsl\");\n const quoteId = BigInt(tempIdNumber);\n try {\n const tpslResult = await tpslBase.mutationFn({\n ...(variables.tpsl as Omit<SetQuoteTpSlParameters, \"quoteId\" | \"chainId\">),\n chainId: resolvedChainId,\n quoteId,\n });\n // Mirror useSetQuoteTpSl.onSuccess: seed the confirming slot with the\n // target trigger price/type (not just the state) so useQuoteTpSl renders\n // the levels immediately — e.g. inline on the freshly-opened position row,\n // keyed by the tempQuoteId — instead of blank until the WS report lands.\n const tp = variables.tpsl!.tp;\n const sl = variables.tpsl!.sl;\n if (tp) {\n markConfirming(quoteId, \"tp\", {\n price: tp.triggerPrice,\n priceType: tp.priceType,\n cohQuoteId: tpslResult.cohQuoteId,\n });\n }\n if (sl) {\n markConfirming(quoteId, \"sl\", {\n price: sl.triggerPrice,\n priceType: sl.priceType,\n cohQuoteId: tpslResult.cohQuoteId,\n });\n }\n setPhase(\"success\");\n return { instantOpen: openResult, tpsl: tpslResult };\n } catch (err) {\n // Instant open landed; only the TP/SL leg failed. Surface it on the\n // return payload rather than throwing, so callers can render a partial\n // success state without losing the trade.\n setPhase(\"success\");\n return { instantOpen: openResult, tpslError: normalizeSymmError(err) };\n }\n },\n onError: () => setPhase(\"error\"),\n }) as UseMutationResult<UseInstantOpenWithTpSlData, SymmioRequestError, UseInstantOpenWithTpSlVariables>;\n\n return Object.assign(mutation, { phase });\n}\n"],"mappings":";;;;;;;;;;AAgFA,SAAgB,EACd,IAA+C,CAAC,GACd;CAClC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAW,EAA+B,CAAM,GAChD,IAAW,EAA4B,CAAM,GAC7C,IAAiB,GAAc,MAAU,EAAM,cAAc,GAE7D,CAAC,GAAO,KAAY,EAAsC,MAAM,GAEhE,IAAW,EAA6F;EAC5G,aAAa,CAAC,wBAAwB;EACtC,YAAY,OAAO,MAAc;GAC/B,IAAM,IAAkB,EAAU,WAAW;GAC7C,EAAS,SAAS;GAClB,IAAI;GACJ,IAAI;IACF,IAAa,MAAM,EAAS,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC;GACnF,SAAS,GAAK;IAEZ,MADA,EAAS,OAAO,GACV,EAAmB,CAAG;GAC9B;GAGA,IAAM,IAAY,EAAO,kBAAkB,CAAe;GAI1D,IAHA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAyB,EAAE,aAAU,CAAC,EAAE,CAAC,GAGpG,EADsB,EAAU,SAAS,EAAU,KAAK,MAAM,EAAU,KAAK,QAC/D,CAAC,EAAW,aAE5B,OADA,EAAS,SAAS,GACX,EAAE,aAAa,EAAW;GAGnC,IAAM,IAAe,OAAO,EAAW,WAAW;GAClD,IAAI,CAAC,OAAO,SAAS,CAAY,GAE/B,OADA,EAAS,SAAS,GACX,EAAE,aAAa,EAAW;GAGnC,EAAS,gBAAgB;GACzB,IAAM,IAAU,OAAO,CAAY;GACnC,IAAI;IACF,IAAM,IAAa,MAAM,EAAS,WAAW;KAC3C,GAAI,EAAU;KACd,SAAS;KACT;IACF,CAAC,GAKK,IAAK,EAAU,KAAM,IACrB,IAAK,EAAU,KAAM;IAgB3B,OAfI,KACF,EAAe,GAAS,MAAM;KAC5B,OAAO,EAAG;KACV,WAAW,EAAG;KACd,YAAY,EAAW;IACzB,CAAC,GAEC,KACF,EAAe,GAAS,MAAM;KAC5B,OAAO,EAAG;KACV,WAAW,EAAG;KACd,YAAY,EAAW;IACzB,CAAC,GAEH,EAAS,SAAS,GACX;KAAE,aAAa;KAAY,MAAM;IAAW;GACrD,SAAS,GAAK;IAKZ,OADA,EAAS,SAAS,GACX;KAAE,aAAa;KAAY,WAAW,EAAmB,CAAG;IAAE;GACvE;EACF;EACA,eAAe,EAAS,OAAO;CACjC,CAAC;CAED,OAAO,OAAO,OAAO,GAAU,EAAE,SAAM,CAAC;AAC1C"}
@@ -0,0 +1,2 @@
1
+ export * from './use-available-instant-open-margin.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/margin/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { PositionType, ConfigParameter } from '@symmio/trading-core';
2
+ import { Address } from 'viem';
3
+ import { SymmioRequestError } from '../errors/symmio-request-error.js';
4
+ /** Parameters for {@link useAvailableInstantOpenMargin}. */
5
+ export interface UseAvailableInstantOpenMarginParameters extends ConfigParameter {
6
+ /** SubAccount to spend margin from. The hook is idle until it is set. */
7
+ account?: Address;
8
+ /** Market symbol id, for the fee lookup. Idle until it is set. */
9
+ symbolId?: bigint | number;
10
+ /** Requested leverage (integer ≥ 1). */
11
+ leverage: number;
12
+ /** LONG skips the slippage cap; SHORT applies it. */
13
+ positionType: PositionType;
14
+ /** Slippage percent, e.g. `5`. */
15
+ slippage: number;
16
+ /** Optional chain override; defaults to the connected chain. */
17
+ chainId?: number;
18
+ }
19
+ /** Return type of {@link useAvailableInstantOpenMargin}. */
20
+ export interface UseAvailableInstantOpenMarginReturnType {
21
+ /** Spendable margin in 18-decimal wei; `undefined` until balance + fees load. */
22
+ availableMarginWei: bigint | undefined;
23
+ /** {@link UseAvailableInstantOpenMarginReturnType.availableMarginWei} as a decimal string; `"0"` when unavailable. */
24
+ availableMargin: string;
25
+ /** `true` while the underlying balance / fee reads are loading. */
26
+ isLoading: boolean;
27
+ /** First error from the balance / fee reads, if any. */
28
+ error: SymmioRequestError | null;
29
+ /** Refetch the underlying balance + fee reads (e.g. after an open/close settles). */
30
+ refetch: () => Promise<void>;
31
+ }
32
+ /**
33
+ * Maximum initial margin an instant open can spend for `account` on a market,
34
+ * shaved for fees and — SHORT only — a worst-case slippage fill. Composes
35
+ * {@link useAccountBalanceOf} + {@link useFeeForUser} and feeds them to
36
+ * `calculateAvailableInstantOpenMargin`. Wire the result to the trade form's
37
+ * `Max` chip and gate submit on it.
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * const { availableMargin, availableMarginWei } = useAvailableInstantOpenMargin({
42
+ * account: subAccount,
43
+ * symbolId: market.symbol_id,
44
+ * leverage,
45
+ * positionType,
46
+ * slippage,
47
+ * });
48
+ * ```
49
+ */
50
+ export declare function useAvailableInstantOpenMargin(parameters: UseAvailableInstantOpenMarginParameters): UseAvailableInstantOpenMarginReturnType;
51
+ //# sourceMappingURL=use-available-instant-open-margin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-available-instant-open-margin.d.ts","sourceRoot":"","sources":["../../src/margin/use-available-instant-open-margin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuC,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE/G,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAQzE,4DAA4D;AAC5D,MAAM,WAAW,uCAAwC,SAAQ,eAAe;IAC9E,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,YAAY,EAAE,YAAY,CAAC;IAC3B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,4DAA4D;AAC5D,MAAM,WAAW,uCAAuC;IACtD,iFAAiF;IACjF,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,sHAAsH;IACtH,eAAe,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACjC,qFAAqF;IACrF,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,uCAAuC,GAClD,uCAAuC,CAwCzC"}
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { useAccountBalanceOf as e } from "../account-layer/use-account-balance-of.js";
3
+ import { useFeeForUser as t } from "../fees/use-fee-for-user.js";
4
+ import { calculateAvailableInstantOpenMargin as n } from "@symmio/trading-core";
5
+ import { useCallback as r, useMemo as i } from "react";
6
+ import { formatUnits as a, zeroAddress as o } from "viem";
7
+ //#region src/margin/use-available-instant-open-margin.ts
8
+ function s(e) {
9
+ return BigInt(Math.round(e * 0x2386f26fc10000));
10
+ }
11
+ function c(c) {
12
+ let { account: l, symbolId: u, leverage: d, positionType: f, slippage: p, chainId: m, config: h } = c, g = e({
13
+ account: l,
14
+ chainId: m,
15
+ config: h,
16
+ live: !0
17
+ }), _ = t({
18
+ user: l ?? o,
19
+ symbolId: u ?? 0,
20
+ chainId: m,
21
+ config: h,
22
+ query: { enabled: !!(l && u !== void 0) }
23
+ }), { data: v, isLoading: y, error: b, refetch: x } = g, { data: S, isLoading: C, error: w, refetch: T } = _, E = r(async () => {
24
+ await Promise.all([x(), T()]);
25
+ }, [x, T]);
26
+ return i(() => {
27
+ let e = y || C, t = b ?? w ?? null;
28
+ if (v === void 0 || S === void 0) return {
29
+ availableMarginWei: void 0,
30
+ availableMargin: "0",
31
+ isLoading: e,
32
+ error: t,
33
+ refetch: E
34
+ };
35
+ let r = n({
36
+ balance: v,
37
+ openFee: S.openFee,
38
+ closeFee: S.closeFee,
39
+ slippageFractionWei: s(p),
40
+ leverage: d,
41
+ positionType: f
42
+ });
43
+ return {
44
+ availableMarginWei: r,
45
+ availableMargin: a(r, 18),
46
+ isLoading: e,
47
+ error: t,
48
+ refetch: E
49
+ };
50
+ }, [
51
+ v,
52
+ y,
53
+ b,
54
+ S,
55
+ C,
56
+ w,
57
+ p,
58
+ d,
59
+ f,
60
+ E
61
+ ]);
62
+ }
63
+ //#endregion
64
+ export { c as useAvailableInstantOpenMargin };
65
+
66
+ //# sourceMappingURL=use-available-instant-open-margin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-available-instant-open-margin.js","names":[],"sources":["../../src/margin/use-available-instant-open-margin.ts"],"sourcesContent":["\"use client\";\n\nimport { calculateAvailableInstantOpenMargin, PositionType, type ConfigParameter } from \"@symmio/trading-core\";\nimport { useCallback, useMemo } from \"react\";\nimport { formatUnits, zeroAddress, type Address } from \"viem\";\nimport { useAccountBalanceOf } from \"../account-layer/use-account-balance-of\";\nimport type { SymmioRequestError } from \"../errors/symmio-request-error\";\nimport { useFeeForUser } from \"../fees/use-fee-for-user\";\n\n/** Convert a slippage percent (e.g. `5`) to an 18-decimal fraction (`5e16`). */\nfunction slippagePercentToFractionWei(slippage: number): bigint {\n return BigInt(Math.round(slippage * 1e16));\n}\n\n/** Parameters for {@link useAvailableInstantOpenMargin}. */\nexport interface UseAvailableInstantOpenMarginParameters extends ConfigParameter {\n /** SubAccount to spend margin from. The hook is idle until it is set. */\n account?: Address;\n /** Market symbol id, for the fee lookup. Idle until it is set. */\n symbolId?: bigint | number;\n /** Requested leverage (integer ≥ 1). */\n leverage: number;\n /** LONG skips the slippage cap; SHORT applies it. */\n positionType: PositionType;\n /** Slippage percent, e.g. `5`. */\n slippage: number;\n /** Optional chain override; defaults to the connected chain. */\n chainId?: number;\n}\n\n/** Return type of {@link useAvailableInstantOpenMargin}. */\nexport interface UseAvailableInstantOpenMarginReturnType {\n /** Spendable margin in 18-decimal wei; `undefined` until balance + fees load. */\n availableMarginWei: bigint | undefined;\n /** {@link UseAvailableInstantOpenMarginReturnType.availableMarginWei} as a decimal string; `\"0\"` when unavailable. */\n availableMargin: string;\n /** `true` while the underlying balance / fee reads are loading. */\n isLoading: boolean;\n /** First error from the balance / fee reads, if any. */\n error: SymmioRequestError | null;\n /** Refetch the underlying balance + fee reads (e.g. after an open/close settles). */\n refetch: () => Promise<void>;\n}\n\n/**\n * Maximum initial margin an instant open can spend for `account` on a market,\n * shaved for fees and — SHORT only — a worst-case slippage fill. Composes\n * {@link useAccountBalanceOf} + {@link useFeeForUser} and feeds them to\n * `calculateAvailableInstantOpenMargin`. Wire the result to the trade form's\n * `Max` chip and gate submit on it.\n *\n * @example\n * ```tsx\n * const { availableMargin, availableMarginWei } = useAvailableInstantOpenMargin({\n * account: subAccount,\n * symbolId: market.symbol_id,\n * leverage,\n * positionType,\n * slippage,\n * });\n * ```\n */\nexport function useAvailableInstantOpenMargin(\n parameters: UseAvailableInstantOpenMarginParameters,\n): UseAvailableInstantOpenMarginReturnType {\n const { account, symbolId, leverage, positionType, slippage, chainId, config } = parameters;\n\n // `live` keeps the shaved margin fresh: the balance refetches when an\n // open/close settles on-chain, so the Max chip drops without a manual refresh.\n const balanceQuery = useAccountBalanceOf({ account, chainId, config, live: true });\n const feeQuery = useFeeForUser({\n user: account ?? zeroAddress,\n symbolId: symbolId ?? 0,\n chainId,\n config,\n query: { enabled: Boolean(account && symbolId !== undefined) },\n });\n\n const { data: balance, isLoading: balanceLoading, error: balanceError, refetch: refetchBalance } = balanceQuery;\n const { data: fees, isLoading: feeLoading, error: feeError, refetch: refetchFees } = feeQuery;\n\n const refetch = useCallback(async () => {\n await Promise.all([refetchBalance(), refetchFees()]);\n }, [refetchBalance, refetchFees]);\n\n return useMemo<UseAvailableInstantOpenMarginReturnType>(() => {\n const isLoading = balanceLoading || feeLoading;\n const error = balanceError ?? feeError ?? null;\n\n if (balance === undefined || fees === undefined) {\n return { availableMarginWei: undefined, availableMargin: \"0\", isLoading, error, refetch };\n }\n\n const availableMarginWei = calculateAvailableInstantOpenMargin({\n balance,\n openFee: fees.openFee,\n closeFee: fees.closeFee,\n slippageFractionWei: slippagePercentToFractionWei(slippage),\n leverage,\n positionType,\n });\n\n return { availableMarginWei, availableMargin: formatUnits(availableMarginWei, 18), isLoading, error, refetch };\n }, [balance, balanceLoading, balanceError, fees, feeLoading, feeError, slippage, leverage, positionType, refetch]);\n}\n"],"mappings":";;;;;;;AAUA,SAAS,EAA6B,GAA0B;CAC9D,OAAO,OAAO,KAAK,MAAM,IAAW,gBAAI,CAAC;AAC3C;AAkDA,SAAgB,EACd,GACyC;CACzC,IAAM,EAAE,YAAS,aAAU,aAAU,iBAAc,aAAU,YAAS,cAAW,GAI3E,IAAe,EAAoB;EAAE;EAAS;EAAS;EAAQ,MAAM;CAAK,CAAC,GAC3E,IAAW,EAAc;EAC7B,MAAM,KAAW;EACjB,UAAU,KAAY;EACtB;EACA;EACA,OAAO,EAAE,SAAS,GAAQ,KAAW,MAAa,KAAA,GAAW;CAC/D,CAAC,GAEK,EAAE,MAAM,GAAS,WAAW,GAAgB,OAAO,GAAc,SAAS,MAAmB,GAC7F,EAAE,MAAM,GAAM,WAAW,GAAY,OAAO,GAAU,SAAS,MAAgB,GAE/E,IAAU,EAAY,YAAY;EACtC,MAAM,QAAQ,IAAI,CAAC,EAAe,GAAG,EAAY,CAAC,CAAC;CACrD,GAAG,CAAC,GAAgB,CAAW,CAAC;CAEhC,OAAO,QAAuD;EAC5D,IAAM,IAAY,KAAkB,GAC9B,IAAQ,KAAgB,KAAY;EAE1C,IAAI,MAAY,KAAA,KAAa,MAAS,KAAA,GACpC,OAAO;GAAE,oBAAoB,KAAA;GAAW,iBAAiB;GAAK;GAAW;GAAO;EAAQ;EAG1F,IAAM,IAAqB,EAAoC;GAC7D;GACA,SAAS,EAAK;GACd,UAAU,EAAK;GACf,qBAAqB,EAA6B,CAAQ;GAC1D;GACA;EACF,CAAC;EAED,OAAO;GAAE;GAAoB,iBAAiB,EAAY,GAAoB,EAAE;GAAG;GAAW;GAAO;EAAQ;CAC/G,GAAG;EAAC;EAAS;EAAgB;EAAc;EAAM;EAAY;EAAU;EAAU;EAAU;EAAc;CAAO,CAAC;AACnH"}
@@ -7,10 +7,19 @@ export interface SymmioProviderProps {
7
7
  /** React subtree that may use SYMMIO SDK hooks. */
8
8
  children: ReactNode;
9
9
  /**
10
- * Per-chain Symmio overrides (addresses, subgraphs, solver) deep-merged onto
11
- * the SDK's built-in defaults, keyed by chain id. Omit to use defaults.
10
+ * Per-chain SYMMIO configuration, keyed by chain id — deep-merged onto the
11
+ * SDK's built-in defaults (addresses, subgraphs, solver, …).
12
+ *
13
+ * **Required.** Every supported chain must set a non-zero
14
+ * `addresses.affiliatesAddress` — your frontend's on-chain affiliate (your
15
+ * identity in SYMMIO on that chain), attached to every quote so the protocol
16
+ * attributes the trade to you and routes your fee share. Affiliate addresses
17
+ * are per chain (a registration on one chain is not valid on another). The
18
+ * provider throws `AFFILIATE_ADDRESS_REQUIRED` (via `createConfig`) for any
19
+ * supported chain missing it, so trades can never silently fall back to the
20
+ * built-in default affiliate and lose attribution.
12
21
  */
13
- chainOverrides?: CreateConfigParameters["chainOverrides"];
22
+ symmioConfig: CreateConfigParameters["symmioConfig"];
14
23
  /** Chain used when a hook or action omits `chainId`. Defaults to the first supported chain. */
15
24
  defaultChainId?: number;
16
25
  /**
@@ -35,7 +44,7 @@ export interface SymmioProviderProps {
35
44
  * ```tsx
36
45
  * <WagmiProvider config={wagmiConfig}>
37
46
  * <QueryClientProvider client={queryClient}>
38
- * <SymmioProvider>
47
+ * <SymmioProvider symmioConfig={{ [SymmioSupportedChainId.HYPER_EVM]: { addresses: { affiliatesAddress: "0x…" } } }}>
39
48
  * <App />
40
49
  * </SymmioProvider>
41
50
  * </QueryClientProvider>
@@ -45,5 +54,5 @@ export interface SymmioProviderProps {
45
54
  * The SDK never mounts wagmi or a `QueryClient` for the host — those (which
46
55
  * connectors, which RPC URLs, which shared `QueryClient`) belong to the host.
47
56
  */
48
- export declare function SymmioProvider({ children, chainOverrides, defaultChainId, getWalletClient: getWalletClientProp, }: SymmioProviderProps): import("react").JSX.Element;
57
+ export declare function SymmioProvider({ children, symmioConfig, defaultChainId, getWalletClient: getWalletClientProp, }: SymmioProviderProps): import("react").JSX.Element;
49
58
  //# sourceMappingURL=symmio-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"symmio-provider.d.ts","sourceRoot":"","sources":["../../src/provider/symmio-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,EAAE,SAAS,CAAC;IACpB;;;OAGG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,+FAA+F;IAC/F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,cAAc,EACd,cAAc,EACd,eAAe,EAAE,mBAAmB,GACrC,EAAE,mBAAmB,+BAsCrB"}
1
+ {"version":3,"file":"symmio-provider.d.ts","sourceRoot":"","sources":["../../src/provider/symmio-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;;;;;;;;;OAYG;IACH,YAAY,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;IACrD,+FAA+F;IAC/F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,eAAe,EAAE,mBAAmB,GACrC,EAAE,mBAAmB,+BAsCrB"}
@@ -6,9 +6,9 @@ import { useConfig as i } from "wagmi";
6
6
  import { getPublicClient as a, getWalletClient as o } from "wagmi/actions";
7
7
  import { jsx as s } from "react/jsx-runtime";
8
8
  //#region src/provider/symmio-provider.tsx
9
- function c({ children: c, chainOverrides: l, defaultChainId: u, getWalletClient: d }) {
9
+ function c({ children: c, symmioConfig: l, defaultChainId: u, getWalletClient: d }) {
10
10
  let f = i(), p = r(() => n({
11
- chainOverrides: l,
11
+ symmioConfig: l,
12
12
  defaultChainId: u,
13
13
  getClient: ({ chainId: e } = {}) => {
14
14
  let n = a(f, { chainId: e });
@@ -1 +1 @@
1
- {"version":3,"file":"symmio-provider.js","names":[],"sources":["../../src/provider/symmio-provider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createConfig,\n SymmError,\n type Config,\n type CreateConfigParameters,\n type GetWalletClientFn,\n} from \"@symmio/trading-core\";\nimport { useMemo, type ReactNode } from \"react\";\nimport type { PublicClient } from \"viem\";\nimport { useConfig } from \"wagmi\";\nimport { getPublicClient, getWalletClient } from \"wagmi/actions\";\nimport { SymmioConfigContext } from \"./symmio-config-context\";\n\n/**\n * Props for {@link SymmioProvider}.\n */\nexport interface SymmioProviderProps {\n /** React subtree that may use SYMMIO SDK hooks. */\n children: ReactNode;\n /**\n * Per-chain Symmio overrides (addresses, subgraphs, solver) deep-merged onto\n * the SDK's built-in defaults, keyed by chain id. Omit to use defaults.\n */\n chainOverrides?: CreateConfigParameters[\"chainOverrides\"];\n /** Chain used when a hook or action omits `chainId`. Defaults to the first supported chain. */\n defaultChainId?: number;\n /**\n * Custom wallet-client resolver. Receives `{ chainId, from? }` from the SDK\n * and returns the wallet client to sign with. Use this to plug in\n * session-key, multi-signer, or any non-wagmi flow — the resolver decides.\n *\n * When omitted, the provider falls back to wagmi's connected wallet (ignores\n * `from`).\n */\n getWalletClient?: GetWalletClientFn;\n}\n\n/**\n * Provides the SYMMIO {@link Config} to descendant hooks. The config's viem\n * clients are resolved from the host's wagmi config, so this is the only place\n * the SDK touches wagmi.\n *\n * **Mount order matters**: this reads wagmi context and (transitively) the\n * host's `@tanstack/react-query` `QueryClient`. Both must be mounted **outside**\n * `SymmioProvider`:\n *\n * ```tsx\n * <WagmiProvider config={wagmiConfig}>\n * <QueryClientProvider client={queryClient}>\n * <SymmioProvider>\n * <App />\n * </SymmioProvider>\n * </QueryClientProvider>\n * </WagmiProvider>\n * ```\n *\n * The SDK never mounts wagmi or a `QueryClient` for the host — those (which\n * connectors, which RPC URLs, which shared `QueryClient`) belong to the host.\n */\nexport function SymmioProvider({\n children,\n chainOverrides,\n defaultChainId,\n getWalletClient: getWalletClientProp,\n}: SymmioProviderProps) {\n const wagmiConfig = useConfig();\n\n const config = useMemo<Config>(\n () =>\n createConfig({\n chainOverrides,\n defaultChainId,\n getClient: ({ chainId } = {}): PublicClient => {\n const client = getPublicClient(wagmiConfig, { chainId });\n\n if (!client)\n throw new SymmError(\n \"config\",\n \"NO_PUBLIC_CLIENT\",\n `No public client available for chain ${chainId ?? \"(default)\"}.`,\n );\n return client;\n },\n getWalletClient:\n getWalletClientProp ??\n (async ({ chainId }) => {\n try {\n return await getWalletClient(wagmiConfig, { chainId });\n } catch (err) {\n throw new SymmError(\n \"config\",\n \"NO_WALLET_CONNECTED\",\n \"No connected wallet. Connect a wallet before sending transactions.\",\n { cause: err instanceof Error ? err : undefined },\n );\n }\n }),\n }),\n [chainOverrides, defaultChainId, getWalletClientProp, wagmiConfig],\n );\n\n return <SymmioConfigContext.Provider value={config}>{children}</SymmioConfigContext.Provider>;\n}\n"],"mappings":";;;;;;;;AA6DA,SAAgB,EAAe,EAC7B,aACA,mBACA,mBACA,iBAAiB,KACK;CACtB,IAAM,IAAc,EAAU,GAExB,IAAS,QAEX,EAAa;EACX;EACA;EACA,YAAY,EAAE,eAAY,CAAC,MAAoB;GAC7C,IAAM,IAAS,EAAgB,GAAa,EAAE,WAAQ,CAAC;GAEvD,IAAI,CAAC,GACH,MAAM,IAAI,EACR,UACA,oBACA,wCAAwC,KAAW,YAAY,EACjE;GACF,OAAO;EACT;EACA,iBACE,MACC,OAAO,EAAE,iBAAc;GACtB,IAAI;IACF,OAAO,MAAM,EAAgB,GAAa,EAAE,WAAQ,CAAC;GACvD,SAAS,GAAK;IACZ,MAAM,IAAI,EACR,UACA,uBACA,sEACA,EAAE,OAAO,aAAe,QAAQ,IAAM,KAAA,EAAU,CAClD;GACF;EACF;CACJ,CAAC,GACH;EAAC;EAAgB;EAAgB;EAAqB;CAAW,CACnE;CAEA,OAAO,kBAAC,EAAoB,UAArB;EAA8B,OAAO;EAAS;CAAuC,CAAA;AAC9F"}
1
+ {"version":3,"file":"symmio-provider.js","names":[],"sources":["../../src/provider/symmio-provider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createConfig,\n SymmError,\n type Config,\n type CreateConfigParameters,\n type GetWalletClientFn,\n} from \"@symmio/trading-core\";\nimport { useMemo, type ReactNode } from \"react\";\nimport type { PublicClient } from \"viem\";\nimport { useConfig } from \"wagmi\";\nimport { getPublicClient, getWalletClient } from \"wagmi/actions\";\nimport { SymmioConfigContext } from \"./symmio-config-context\";\n\n/**\n * Props for {@link SymmioProvider}.\n */\nexport interface SymmioProviderProps {\n /** React subtree that may use SYMMIO SDK hooks. */\n children: ReactNode;\n /**\n * Per-chain SYMMIO configuration, keyed by chain id — deep-merged onto the\n * SDK's built-in defaults (addresses, subgraphs, solver, …).\n *\n * **Required.** Every supported chain must set a non-zero\n * `addresses.affiliatesAddress` — your frontend's on-chain affiliate (your\n * identity in SYMMIO on that chain), attached to every quote so the protocol\n * attributes the trade to you and routes your fee share. Affiliate addresses\n * are per chain (a registration on one chain is not valid on another). The\n * provider throws `AFFILIATE_ADDRESS_REQUIRED` (via `createConfig`) for any\n * supported chain missing it, so trades can never silently fall back to the\n * built-in default affiliate and lose attribution.\n */\n symmioConfig: CreateConfigParameters[\"symmioConfig\"];\n /** Chain used when a hook or action omits `chainId`. Defaults to the first supported chain. */\n defaultChainId?: number;\n /**\n * Custom wallet-client resolver. Receives `{ chainId, from? }` from the SDK\n * and returns the wallet client to sign with. Use this to plug in\n * session-key, multi-signer, or any non-wagmi flow — the resolver decides.\n *\n * When omitted, the provider falls back to wagmi's connected wallet (ignores\n * `from`).\n */\n getWalletClient?: GetWalletClientFn;\n}\n\n/**\n * Provides the SYMMIO {@link Config} to descendant hooks. The config's viem\n * clients are resolved from the host's wagmi config, so this is the only place\n * the SDK touches wagmi.\n *\n * **Mount order matters**: this reads wagmi context and (transitively) the\n * host's `@tanstack/react-query` `QueryClient`. Both must be mounted **outside**\n * `SymmioProvider`:\n *\n * ```tsx\n * <WagmiProvider config={wagmiConfig}>\n * <QueryClientProvider client={queryClient}>\n * <SymmioProvider symmioConfig={{ [SymmioSupportedChainId.HYPER_EVM]: { addresses: { affiliatesAddress: \"0x…\" } } }}>\n * <App />\n * </SymmioProvider>\n * </QueryClientProvider>\n * </WagmiProvider>\n * ```\n *\n * The SDK never mounts wagmi or a `QueryClient` for the host — those (which\n * connectors, which RPC URLs, which shared `QueryClient`) belong to the host.\n */\nexport function SymmioProvider({\n children,\n symmioConfig,\n defaultChainId,\n getWalletClient: getWalletClientProp,\n}: SymmioProviderProps) {\n const wagmiConfig = useConfig();\n\n const config = useMemo<Config>(\n () =>\n createConfig({\n symmioConfig,\n defaultChainId,\n getClient: ({ chainId } = {}): PublicClient => {\n const client = getPublicClient(wagmiConfig, { chainId });\n\n if (!client)\n throw new SymmError(\n \"config\",\n \"NO_PUBLIC_CLIENT\",\n `No public client available for chain ${chainId ?? \"(default)\"}.`,\n );\n return client;\n },\n getWalletClient:\n getWalletClientProp ??\n (async ({ chainId }) => {\n try {\n return await getWalletClient(wagmiConfig, { chainId });\n } catch (err) {\n throw new SymmError(\n \"config\",\n \"NO_WALLET_CONNECTED\",\n \"No connected wallet. Connect a wallet before sending transactions.\",\n { cause: err instanceof Error ? err : undefined },\n );\n }\n }),\n }),\n [symmioConfig, defaultChainId, getWalletClientProp, wagmiConfig],\n );\n\n return <SymmioConfigContext.Provider value={config}>{children}</SymmioConfigContext.Provider>;\n}\n"],"mappings":";;;;;;;;AAsEA,SAAgB,EAAe,EAC7B,aACA,iBACA,mBACA,iBAAiB,KACK;CACtB,IAAM,IAAc,EAAU,GAExB,IAAS,QAEX,EAAa;EACX;EACA;EACA,YAAY,EAAE,eAAY,CAAC,MAAoB;GAC7C,IAAM,IAAS,EAAgB,GAAa,EAAE,WAAQ,CAAC;GAEvD,IAAI,CAAC,GACH,MAAM,IAAI,EACR,UACA,oBACA,wCAAwC,KAAW,YAAY,EACjE;GACF,OAAO;EACT;EACA,iBACE,MACC,OAAO,EAAE,iBAAc;GACtB,IAAI;IACF,OAAO,MAAM,EAAgB,GAAa,EAAE,WAAQ,CAAC;GACvD,SAAS,GAAK;IACZ,MAAM,IAAI,EACR,UACA,uBACA,sEACA,EAAE,OAAO,aAAe,QAAQ,IAAM,KAAA,EAAU,CAClD;GACF;EACF;CACJ,CAAC,GACH;EAAC;EAAc;EAAgB;EAAqB;CAAW,CACjE;CAEA,OAAO,kBAAC,EAAoB,UAArB;EAA8B,OAAO;EAAS;CAAuC,CAAA;AAC9F"}