@symmio/trading-react 0.2.0 → 1.1.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.
- package/README.md +2 -2
- package/dist/account-layer/index.d.ts +4 -0
- package/dist/account-layer/index.d.ts.map +1 -1
- package/dist/account-layer/index.js +30 -26
- package/dist/account-layer/use-account-balance-info.d.ts +15 -4
- package/dist/account-layer/use-account-balance-info.d.ts.map +1 -1
- package/dist/account-layer/use-account-balance-info.js +21 -9
- package/dist/account-layer/use-account-balance-info.js.map +1 -1
- package/dist/account-layer/use-account-balance-of.d.ts +15 -4
- package/dist/account-layer/use-account-balance-of.d.ts.map +1 -1
- package/dist/account-layer/use-account-balance-of.js +20 -9
- package/dist/account-layer/use-account-balance-of.js.map +1 -1
- package/dist/account-layer/use-affiliate-state.d.ts +26 -0
- package/dist/account-layer/use-affiliate-state.d.ts.map +1 -0
- package/dist/account-layer/use-affiliate-state.js +27 -0
- package/dist/account-layer/use-affiliate-state.js.map +1 -0
- package/dist/account-layer/use-cancel-registration.d.ts +28 -0
- package/dist/account-layer/use-cancel-registration.d.ts.map +1 -0
- package/dist/account-layer/use-cancel-registration.js +38 -0
- package/dist/account-layer/use-cancel-registration.js.map +1 -0
- package/dist/account-layer/use-deposit-and-allocate.d.ts +7 -4
- package/dist/account-layer/use-deposit-and-allocate.d.ts.map +1 -1
- package/dist/account-layer/use-deposit-and-allocate.js.map +1 -1
- package/dist/account-layer/use-deposit.d.ts +3 -1
- package/dist/account-layer/use-deposit.d.ts.map +1 -1
- package/dist/account-layer/use-deposit.js +17 -15
- package/dist/account-layer/use-deposit.js.map +1 -1
- package/dist/account-layer/use-generated-account-manager-address.d.ts +25 -0
- package/dist/account-layer/use-generated-account-manager-address.d.ts.map +1 -0
- package/dist/account-layer/use-generated-account-manager-address.js +27 -0
- package/dist/account-layer/use-generated-account-manager-address.js.map +1 -0
- package/dist/account-layer/use-request-to-register-affiliate.d.ts +43 -0
- package/dist/account-layer/use-request-to-register-affiliate.d.ts.map +1 -0
- package/dist/account-layer/use-request-to-register-affiliate.js +38 -0
- package/dist/account-layer/use-request-to-register-affiliate.js.map +1 -0
- package/dist/estimated-price/index.d.ts +2 -0
- package/dist/estimated-price/index.d.ts.map +1 -0
- package/dist/estimated-price/use-debounced-value.d.ts +9 -0
- package/dist/estimated-price/use-debounced-value.d.ts.map +1 -0
- package/dist/estimated-price/use-debounced-value.js +18 -0
- package/dist/estimated-price/use-debounced-value.js.map +1 -0
- package/dist/estimated-price/use-estimated-price.d.ts +46 -0
- package/dist/estimated-price/use-estimated-price.d.ts.map +1 -0
- package/dist/estimated-price/use-estimated-price.js +31 -0
- package/dist/estimated-price/use-estimated-price.js.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +124 -118
- package/dist/instant-layer/use-instant-close-auto.d.ts +1 -1
- package/dist/instant-layer/use-instant-close-auto.js.map +1 -1
- package/dist/instant-layer/use-instant-close-bulk-auto.d.ts +1 -1
- package/dist/instant-layer/use-instant-close-bulk-auto.js.map +1 -1
- package/dist/instant-layer/use-instant-open-with-tpsl.d.ts.map +1 -1
- package/dist/instant-layer/use-instant-open-with-tpsl.js +10 -2
- package/dist/instant-layer/use-instant-open-with-tpsl.js.map +1 -1
- package/dist/margin/index.d.ts +2 -0
- package/dist/margin/index.d.ts.map +1 -0
- package/dist/margin/use-available-instant-open-margin.d.ts +51 -0
- package/dist/margin/use-available-instant-open-margin.d.ts.map +1 -0
- package/dist/margin/use-available-instant-open-margin.js +66 -0
- package/dist/margin/use-available-instant-open-margin.js.map +1 -0
- package/dist/provider/symmio-provider.d.ts +14 -5
- package/dist/provider/symmio-provider.d.ts.map +1 -1
- package/dist/provider/symmio-provider.js +2 -2
- package/dist/provider/symmio-provider.js.map +1 -1
- package/dist/quotes/use-managed-quotes.js +16 -16
- package/dist/quotes/use-managed-quotes.js.map +1 -1
- package/dist/websocket/is-settle-notification.d.ts +15 -0
- package/dist/websocket/is-settle-notification.d.ts.map +1 -0
- package/dist/websocket/is-settle-notification.js +15 -0
- package/dist/websocket/is-settle-notification.js.map +1 -0
- package/package.json +7 -8
package/dist/index.js
CHANGED
|
@@ -7,121 +7,127 @@ 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 {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
58
|
-
import {
|
|
59
|
-
import {
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
64
|
-
import {
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
67
|
-
import {
|
|
68
|
-
import {
|
|
69
|
-
import {
|
|
70
|
-
import {
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
75
|
-
import {
|
|
76
|
-
import {
|
|
77
|
-
import {
|
|
78
|
-
import {
|
|
79
|
-
import {
|
|
80
|
-
import {
|
|
81
|
-
import {
|
|
82
|
-
import {
|
|
83
|
-
import {
|
|
84
|
-
import {
|
|
85
|
-
import {
|
|
86
|
-
import {
|
|
87
|
-
import {
|
|
88
|
-
import {
|
|
89
|
-
import {
|
|
90
|
-
import {
|
|
91
|
-
import {
|
|
92
|
-
import {
|
|
93
|
-
import {
|
|
94
|
-
import {
|
|
95
|
-
import {
|
|
96
|
-
import {
|
|
97
|
-
import {
|
|
98
|
-
import {
|
|
99
|
-
import {
|
|
100
|
-
import {
|
|
101
|
-
import {
|
|
102
|
-
import {
|
|
103
|
-
import {
|
|
104
|
-
import {
|
|
105
|
-
import {
|
|
106
|
-
import {
|
|
107
|
-
import {
|
|
108
|
-
import {
|
|
109
|
-
import {
|
|
110
|
-
import {
|
|
111
|
-
import {
|
|
112
|
-
import {
|
|
113
|
-
import {
|
|
114
|
-
import {
|
|
115
|
-
import {
|
|
116
|
-
import {
|
|
117
|
-
import {
|
|
118
|
-
import {
|
|
119
|
-
import {
|
|
120
|
-
import {
|
|
121
|
-
import {
|
|
122
|
-
import {
|
|
123
|
-
import {
|
|
124
|
-
import {
|
|
125
|
-
import {
|
|
126
|
-
import {
|
|
127
|
-
|
|
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 { useAffiliateState as h } from "./account-layer/use-affiliate-state.js";
|
|
17
|
+
import { useAllocate as g } from "./account-layer/use-allocate.js";
|
|
18
|
+
import { useCancelRegistration as _ } from "./account-layer/use-cancel-registration.js";
|
|
19
|
+
import { useCreateSubAccounts as v } from "./account-layer/use-create-sub-accounts.js";
|
|
20
|
+
import { useDeallocate as y } from "./account-layer/use-deallocate.js";
|
|
21
|
+
import { useDeleteSubAccount as b } from "./account-layer/use-delete-sub-account.js";
|
|
22
|
+
import { useDeposit as x } from "./account-layer/use-deposit.js";
|
|
23
|
+
import { useDepositAndAllocate as S } from "./account-layer/use-deposit-and-allocate.js";
|
|
24
|
+
import { useEditAccountName as C } from "./account-layer/use-edit-account-name.js";
|
|
25
|
+
import { useGeneratedAccountManagerAddress as w } from "./account-layer/use-generated-account-manager-address.js";
|
|
26
|
+
import { usePredictedNextVirtualAccount as T } from "./account-layer/use-predicted-next-virtual-account.js";
|
|
27
|
+
import { useRemoveMargin as E } from "./account-layer/use-remove-margin.js";
|
|
28
|
+
import { useRequestToRegisterAffiliate as D } from "./account-layer/use-request-to-register-affiliate.js";
|
|
29
|
+
import { useSimulateAddMargin as O } from "./account-layer/use-simulate-add-margin.js";
|
|
30
|
+
import { useSimulateAllocate as k } from "./account-layer/use-simulate-allocate.js";
|
|
31
|
+
import { useSimulateCreateSubAccounts as A } from "./account-layer/use-simulate-create-sub-accounts.js";
|
|
32
|
+
import { useSimulateDeallocate as j } from "./account-layer/use-simulate-deallocate.js";
|
|
33
|
+
import { useSimulateDeleteSubAccount as M } from "./account-layer/use-simulate-delete-sub-account.js";
|
|
34
|
+
import { useSimulateDeposit as N } from "./account-layer/use-simulate-deposit.js";
|
|
35
|
+
import { useSimulateDepositAndAllocate as P } from "./account-layer/use-simulate-deposit-and-allocate.js";
|
|
36
|
+
import { useSimulateEditAccountName as F } from "./account-layer/use-simulate-edit-account-name.js";
|
|
37
|
+
import { useSimulateRemoveMargin as I } from "./account-layer/use-simulate-remove-margin.js";
|
|
38
|
+
import { useSubAccount as L } from "./account-layer/use-sub-account.js";
|
|
39
|
+
import { useSubAccountVirtualNonce as R } from "./account-layer/use-sub-account-virtual-nonce.js";
|
|
40
|
+
import { useSubAccountsCountOfUser as z } from "./account-layer/use-sub-accounts-count-of-user.js";
|
|
41
|
+
import { useUserSubAccounts as B } from "./account-layer/use-user-sub-accounts.js";
|
|
42
|
+
import { useUserSubAccountsAddresses as V } from "./account-layer/use-user-sub-accounts-addresses.js";
|
|
43
|
+
import { useVirtualAccount as H } from "./account-layer/use-virtual-account.js";
|
|
44
|
+
import { useVirtualAccountsAddressesOfSubAccount as U } from "./account-layer/use-virtual-accounts-addresses-of-sub-account.js";
|
|
45
|
+
import { useApproveCollateral as W } from "./collateral/use-approve-collateral.js";
|
|
46
|
+
import { useCollateralAllowance as G } from "./collateral/use-collateral-allowance.js";
|
|
47
|
+
import { useCollateralBalance as K } from "./collateral/use-collateral-balance.js";
|
|
48
|
+
import { useSimulateApproveCollateral as q } from "./collateral/use-simulate-approve-collateral.js";
|
|
49
|
+
import { useDelegationExpiry as J } from "./instant-layer/use-delegation-expiry.js";
|
|
50
|
+
import { useGrantDelegation as Y } from "./instant-layer/use-grant-delegation.js";
|
|
51
|
+
import { useInstantClose as X } from "./instant-layer/use-instant-close.js";
|
|
52
|
+
import { useInstantCloseAuto as Z } from "./instant-layer/use-instant-close-auto.js";
|
|
53
|
+
import { useInstantCloseBulk as Q } from "./instant-layer/use-instant-close-bulk.js";
|
|
54
|
+
import { useInstantCloseBulkAuto as $ } from "./instant-layer/use-instant-close-bulk-auto.js";
|
|
55
|
+
import { useInstantCloses as ee } from "./instant-layer/use-instant-closes.js";
|
|
56
|
+
import { useInstantOpen as te } from "./instant-layer/use-instant-open.js";
|
|
57
|
+
import { useInstantOpenAuto as ne } from "./instant-layer/use-instant-open-auto.js";
|
|
58
|
+
import { useInstantOpenQuoteId as re } from "./instant-layer/use-instant-open-quote-id.js";
|
|
59
|
+
import { toQuoteTpSl as ie } from "./tpsl/to-quote-tpsl.js";
|
|
60
|
+
import { useTpSlRecord as ae, useTpSlStore as oe } from "./tpsl/tpsl-store.js";
|
|
61
|
+
import { useInstantOpenWithTpSl as se } from "./instant-layer/use-instant-open-with-tpsl.js";
|
|
62
|
+
import { useInstantOpens as ce } from "./instant-layer/use-instant-opens.js";
|
|
63
|
+
import { useIsDelegationActive as le } from "./instant-layer/use-is-delegation-active.js";
|
|
64
|
+
import { useSimulateGrantDelegation as ue } from "./instant-layer/use-simulate-grant-delegation.js";
|
|
65
|
+
import { useFinalizeWithdrawRequest as de } from "./withdraw/use-finalize-withdraw-request.js";
|
|
66
|
+
import { useInitiateWithdraw as fe } from "./withdraw/use-initiate-withdraw.js";
|
|
67
|
+
import { useLastWithdrawRequestId as pe } from "./withdraw/use-last-withdraw-request-id.js";
|
|
68
|
+
import { usePendingWithdrawRequests as me } from "./withdraw/use-pending-withdraw-requests.js";
|
|
69
|
+
import { useRequestCancelWithdraw as he } from "./withdraw/use-request-cancel-withdraw.js";
|
|
70
|
+
import { useSimulateFinalizeWithdrawRequest as ge } from "./withdraw/use-simulate-finalize-withdraw-request.js";
|
|
71
|
+
import { useSimulateInitiateWithdraw as _e } from "./withdraw/use-simulate-initiate-withdraw.js";
|
|
72
|
+
import { useSimulateRequestCancelWithdraw as ve } from "./withdraw/use-simulate-request-cancel-withdraw.js";
|
|
73
|
+
import { useWithdrawRequest as ye } from "./withdraw/use-withdraw-requests.js";
|
|
74
|
+
import { useWithdrawableTime as be } from "./withdraw/use-withdrawable-time.js";
|
|
75
|
+
import { useMarkets as xe } from "./markets/use-markets.js";
|
|
76
|
+
import { useOnchainContractMarkets as Se } from "./markets/use-onchain-contract-markets.js";
|
|
77
|
+
import { useSolverErrorCodes as Ce } from "./error-codes/use-solver-error-codes.js";
|
|
78
|
+
import { useSolverErrorMessage as we } from "./error-codes/use-solver-error-message.js";
|
|
79
|
+
import { useOptimisticQuotesStore as Te } from "./quotes/optimistic-quotes-store.js";
|
|
80
|
+
import { usePartyAOpenPositions as Ee } from "./quotes/use-party-a-open-positions.js";
|
|
81
|
+
import { useAccountLiquidationPrice as De } from "./quotes/use-account-liquidation-price.js";
|
|
82
|
+
import { useManagedQuotes as Oe } from "./quotes/use-managed-quotes.js";
|
|
83
|
+
import { useGroupedQuotes as ke } from "./quotes/use-grouped-quotes.js";
|
|
84
|
+
import { usePartyAPendingQuotes as Ae } from "./quotes/use-party-a-pending-quotes.js";
|
|
85
|
+
import { useQuote as je } from "./quotes/use-quote.js";
|
|
86
|
+
import { useQuoteEventsByType as Me } from "./quotes/use-quote-events-by-type.js";
|
|
87
|
+
import { useQuotesFunding as Ne } from "./quotes/use-quotes-funding.js";
|
|
88
|
+
import { useQuoteFunding as Pe } from "./quotes/use-quote-funding.js";
|
|
89
|
+
import { useQuoteHistory as Fe } from "./quotes/use-quote-history.js";
|
|
90
|
+
import { useQuotePlatformFee as Ie } from "./quotes/use-quote-platform-fee.js";
|
|
91
|
+
import { useQuotePriceHistory as Le } from "./quotes/use-quote-price-history.js";
|
|
92
|
+
import { useEnigmaPriceByName as Re } from "./price-service/use-enigma-price-by-name.js";
|
|
93
|
+
import { useEnigmaPriceByMarketId as ze } from "./price-service/use-enigma-price-by-market-id.js";
|
|
94
|
+
import { useQuoteUpnlAndPnl as Be } from "./quotes/use-quote-upnl-and-pnl.js";
|
|
95
|
+
import { useSubgraphQuery as Ve } from "./quotes/use-subgraph-query.js";
|
|
96
|
+
import { useFeeForUser as He } from "./fees/use-fee-for-user.js";
|
|
97
|
+
import { useAvailableInstantOpenMargin as Ue } from "./margin/use-available-instant-open-margin.js";
|
|
98
|
+
import { useBalanceHistory as We } from "./balance-history/use-balance-history.js";
|
|
99
|
+
import { useDepositHistory as Ge } from "./balance-history/use-deposit-history.js";
|
|
100
|
+
import { useWithdrawHistory as Ke } from "./balance-history/use-withdraw-history.js";
|
|
101
|
+
import { useTransferHistory as qe } from "./transfers/use-transfer-history.js";
|
|
102
|
+
import { useLockedParams as Je } from "./locked-params/use-locked-params.js";
|
|
103
|
+
import { DEFAULT_NOTIONAL_CAP_POLLING_MS as Ye, useNotionalCapBySymbolId as Xe } from "./notional-cap/use-notional-cap-by-symbol-id.js";
|
|
104
|
+
import { useNotionalCapAll as Ze } from "./notional-cap/use-notional-cap-all.js";
|
|
105
|
+
import { useOpenInterestBySymbolId as Qe } from "./notional-cap/use-open-interest-by-symbol-id.js";
|
|
106
|
+
import { useEstimatedPrice as $e } from "./estimated-price/use-estimated-price.js";
|
|
107
|
+
import { useFundingInfo as et } from "./funding-info/use-funding-info.js";
|
|
108
|
+
import { useMarketInfo as tt } from "./market-info/use-market-info.js";
|
|
109
|
+
import { useEnigmaPriceServiceHealth as nt } from "./price-service/use-enigma-price-service-health.js";
|
|
110
|
+
import { useEnigmaPriceServiceMetadata as rt } from "./price-service/use-enigma-price-service-metadata.js";
|
|
111
|
+
import { useEnigmaPriceServicePricesByAddresses as it } from "./price-service/use-enigma-price-service-prices-by-addresses.js";
|
|
112
|
+
import { useEnigmaPriceServicePricesByNames as at } from "./price-service/use-enigma-price-service-prices-by-names.js";
|
|
113
|
+
import { useEnigmaPriceServiceSymbolsInfo as ot } from "./price-service/use-enigma-price-service-symbols-info.js";
|
|
114
|
+
import { useEnigmaPrices as st } from "./price-service/use-enigma-prices.js";
|
|
115
|
+
import { useSearchNotifications as ct } from "./notifications/use-search-notifications.js";
|
|
116
|
+
import { useDeallocateUpnlSig as lt } from "./muon/use-deallocate-upnl-sig.js";
|
|
117
|
+
import { useMuonPartyAOverview as ut } from "./muon/use-muon-party-a-overview.js";
|
|
118
|
+
import { useMuonPrice as dt } from "./muon/use-muon-price.js";
|
|
119
|
+
import { useMuonPriceRange as ft } from "./muon/use-muon-price-range.js";
|
|
120
|
+
import { useMuonSettleUpnl as pt } from "./muon/use-muon-settle-upnl.js";
|
|
121
|
+
import { useMuonUpnl as mt } from "./muon/use-muon-upnl.js";
|
|
122
|
+
import { useMuonUpnlA as ht } from "./muon/use-muon-upnl-a.js";
|
|
123
|
+
import { useMuonUpnlAWithSymbolPrice as gt } from "./muon/use-muon-upnl-a-with-symbol-price.js";
|
|
124
|
+
import { useMuonUpnlB as _t } from "./muon/use-muon-upnl-b.js";
|
|
125
|
+
import { useMuonUpnlWithSymbolPrice as vt } from "./muon/use-muon-upnl-with-symbol-price.js";
|
|
126
|
+
import { useDeleteQuoteTpSl as yt } from "./tpsl/use-delete-quote-tpsl.js";
|
|
127
|
+
import { useWatchTpSlNotifications as bt } from "./tpsl/use-watch-tpsl-notifications.js";
|
|
128
|
+
import { useQuoteTpSl as xt } from "./tpsl/use-quote-tpsl.js";
|
|
129
|
+
import { useSetQuoteTpSl as St } from "./tpsl/use-set-quote-tpsl.js";
|
|
130
|
+
import { useTpSlConfig as Ct } from "./tpsl/use-tpsl-config.js";
|
|
131
|
+
import { useTpSlSigningSpec as wt } from "./tpsl/use-tpsl-signing-spec.js";
|
|
132
|
+
import { ADD_MARGIN_TO_NEXT_VA_SELECTOR as Tt, DEFAULT_TPSL_SLIPPAGE_LOWCAPS as Et, INSTANT_TRADE_REQUIRED_SELECTORS as Dt, NotificationType as Ot, OrderType as kt, PositionType as At, QuoteStatus as jt, REQUEST_TO_CLOSE_POSITION_SELECTOR as Mt, SEND_QUOTE_WITH_AFFILIATE_AND_DATA_SELECTOR as Nt, SubAccountIsolationType as Pt, SymmApiError as Ft, SymmError as It, VIRTUAL_ACCOUNT_ISOLATION_TYPE as Lt, ZERO_LEG as Rt, buildConditionalOrderLeg as zt, buildConditionalOrderMessage as Bt, buildTpSlDeleteMessage as Vt, calculateAvailableInstantOpenMargin as Ht, calculateClosePrice as Ut, calculatePriceImpact as Wt, calculateQuotePnl as Gt, calculateTradeParams as Kt, clampClosePrecision as qt, deleteQuoteTpSl as Jt, deleteQuoteTpSlMutationOptions as Yt, generateTpSlSalt as Xt, getPartyAOpenPositionsQueryKey as Zt, getPartyAOpenPositionsQueryOptions as Qt, isolationTypeForSide as $t, parseTpSlFrame as en, priceSlippageCalculation as tn, signTpSlRequest as nn, toSignableTpSlMessage as rn, validateInstantCloseAgainstMarket as an, validateInstantOpenAgainstMarket as on, validateTpSl as sn, watchTpSlNotifications as cn } from "@symmio/trading-core";
|
|
133
|
+
export { Tt as ADD_MARGIN_TO_NEXT_VA_SELECTOR, Ye as DEFAULT_NOTIONAL_CAP_POLLING_MS, Et as DEFAULT_TPSL_SLIPPAGE_LOWCAPS, Dt as INSTANT_TRADE_REQUIRED_SELECTORS, Ot as NotificationType, kt as OrderType, At as PositionType, jt as QuoteStatus, Mt as REQUEST_TO_CLOSE_POSITION_SELECTOR, Nt as SEND_QUOTE_WITH_AFFILIATE_AND_DATA_SELECTOR, Pt as SubAccountIsolationType, Ft as SymmApiError, It as SymmError, e as SymmioProvider, r as SymmioRequestError, Lt as VIRTUAL_ACCOUNT_ISOLATION_TYPE, Rt as ZERO_LEG, zt as buildConditionalOrderLeg, Bt as buildConditionalOrderMessage, Vt as buildTpSlDeleteMessage, Ht as calculateAvailableInstantOpenMargin, Ut as calculateClosePrice, Wt as calculatePriceImpact, Gt as calculateQuotePnl, Kt as calculateTradeParams, qt as clampClosePrecision, Jt as deleteQuoteTpSl, Yt as deleteQuoteTpSlMutationOptions, Xt as generateTpSlSalt, Zt as getPartyAOpenPositionsQueryKey, Qt as getPartyAOpenPositionsQueryOptions, $t as isolationTypeForSide, i as normalizeSymmError, en as parseTpSlFrame, p as predicateMatch, tn as priceSlippageCalculation, nn as signTpSlRequest, ie as toQuoteTpSl, rn as toSignableTpSlMessage, u as useAccountBalanceInfo, d as useAccountBalanceOf, De as useAccountLiquidationPrice, m as useAddMargin, h as useAffiliateState, g as useAllocate, W as useApproveCollateral, Ue as useAvailableInstantOpenMargin, We as useBalanceHistory, _ as useCancelRegistration, G as useCollateralAllowance, K as useCollateralBalance, a as useConnectWallet, v as useCreateSubAccounts, y as useDeallocate, lt as useDeallocateUpnlSig, J as useDelegationExpiry, yt as useDeleteQuoteTpSl, b as useDeleteSubAccount, x as useDeposit, S as useDepositAndAllocate, Ge as useDepositHistory, o as useDisconnectWallet, C as useEditAccountName, ze as useEnigmaPriceByMarketId, Re as useEnigmaPriceByName, nt as useEnigmaPriceServiceHealth, rt as useEnigmaPriceServiceMetadata, it as useEnigmaPriceServicePricesByAddresses, at as useEnigmaPriceServicePricesByNames, ot as useEnigmaPriceServiceSymbolsInfo, st as useEnigmaPrices, $e as useEstimatedPrice, He as useFeeForUser, de as useFinalizeWithdrawRequest, et as useFundingInfo, w as useGeneratedAccountManagerAddress, Y as useGrantDelegation, ke as useGroupedQuotes, fe as useInitiateWithdraw, X as useInstantClose, Z as useInstantCloseAuto, Q as useInstantCloseBulk, $ as useInstantCloseBulkAuto, ee as useInstantCloses, te as useInstantOpen, ne as useInstantOpenAuto, re as useInstantOpenQuoteId, se as useInstantOpenWithTpSl, ce as useInstantOpens, le as useIsDelegationActive, pe as useLastWithdrawRequestId, Je as useLockedParams, Oe as useManagedQuotes, tt as useMarketInfo, xe as useMarkets, ut as useMuonPartyAOverview, dt as useMuonPrice, ft as useMuonPriceRange, pt as useMuonSettleUpnl, mt as useMuonUpnl, ht as useMuonUpnlA, gt as useMuonUpnlAWithSymbolPrice, _t as useMuonUpnlB, vt as useMuonUpnlWithSymbolPrice, l as useNotifications, Ze as useNotionalCapAll, Xe as useNotionalCapBySymbolId, Se as useOnchainContractMarkets, Qe as useOpenInterestBySymbolId, Te as useOptimisticQuotesStore, Ee as usePartyAOpenPositions, Ae as usePartyAPendingQuotes, me as usePendingWithdrawRequests, T as usePredictedNextVirtualAccount, je as useQuote, Me as useQuoteEventsByType, Pe as useQuoteFunding, Fe as useQuoteHistory, Ie as useQuotePlatformFee, Le as useQuotePriceHistory, xt as useQuoteTpSl, Be as useQuoteUpnlAndPnl, Ne as useQuotesFunding, E as useRemoveMargin, he as useRequestCancelWithdraw, D as useRequestToRegisterAffiliate, ct as useSearchNotifications, St as useSetQuoteTpSl, O as useSimulateAddMargin, k as useSimulateAllocate, q as useSimulateApproveCollateral, A as useSimulateCreateSubAccounts, j as useSimulateDeallocate, M as useSimulateDeleteSubAccount, N as useSimulateDeposit, P as useSimulateDepositAndAllocate, F as useSimulateEditAccountName, ge as useSimulateFinalizeWithdrawRequest, ue as useSimulateGrantDelegation, _e as useSimulateInitiateWithdraw, I as useSimulateRemoveMargin, ve as useSimulateRequestCancelWithdraw, Ce as useSolverErrorCodes, we as useSolverErrorMessage, L as useSubAccount, R as useSubAccountVirtualNonce, z as useSubAccountsCountOfUser, Ve as useSubgraphQuery, s as useSwitchToSymmioChain, t as useSymmioChainId, n as useSymmioConfig, Ct as useTpSlConfig, ae as useTpSlRecord, wt as useTpSlSigningSpec, oe as useTpSlStore, f as useTransactionsStore, qe as useTransferHistory, B as useUserSubAccounts, V as useUserSubAccountsAddresses, H as useVirtualAccount, U as useVirtualAccountsAddressesOfSubAccount, c as useWalletAccount, bt as useWatchTpSlNotifications, Ke as useWithdrawHistory, ye as useWithdrawRequest, be as useWithdrawableTime, an as validateInstantCloseAgainstMarket, on as validateInstantOpenAgainstMarket, sn as validateTpSl, cn as watchTpSlNotifications };
|
|
@@ -21,7 +21,7 @@ export type UseInstantCloseAutoReturnType = UseMutationResult<InstantCloseReturn
|
|
|
21
21
|
* const { mutateAsync } = useInstantCloseAuto();
|
|
22
22
|
* await mutateAsync({
|
|
23
23
|
* partyA, market: { id: 1 }, positionType: PositionType.LONG,
|
|
24
|
-
* quoteId: 42n, quantityToClose: "0.5", slippage: 1
|
|
24
|
+
* quoteId: 42n, quantityToClose: "0.5", slippage: 5, // ≥5%: source from user; 1% often fails to fill
|
|
25
25
|
* });
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-instant-close-auto.js","names":[],"sources":["../../src/instant-layer/use-instant-close-auto.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getInstantClosesQueryKey,\n instantCloseAutoMutationOptions,\n type ConfigParameter,\n type InstantCloseReturnType,\n type PrepareInstantCloseParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\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 { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useInstantCloseAuto}.\n */\nexport type UseInstantCloseAutoParameters = ConfigParameter;\n\n/** Return type of {@link useInstantCloseAuto}. */\nexport type UseInstantCloseAutoReturnType = UseMutationResult<\n InstantCloseReturnType,\n SymmioRequestError,\n PrepareInstantCloseParameters\n>;\n\n/**\n * Close (or partially close) a lowcap instant position via the wizard\n * `instantCloseAuto` action.\n *\n * Friendly default: accepts the minimal close intent and lets the SDK fetch\n * market metadata + mark price. Pre-fill `markPrice` to skip its fetch. For\n * full control — inspect / mutate resolved params between fetch and submit —\n * use {@link useInstantClose} after calling `prepareInstantCloseParams` directly.\n *\n * @example\n * ```tsx\n * const { mutateAsync } = useInstantCloseAuto();\n * await mutateAsync({\n * partyA, market: { id: 1 }, positionType: PositionType.LONG,\n * quoteId: 42n, quantityToClose: \"0.5\", slippage: 1
|
|
1
|
+
{"version":3,"file":"use-instant-close-auto.js","names":[],"sources":["../../src/instant-layer/use-instant-close-auto.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getInstantClosesQueryKey,\n instantCloseAutoMutationOptions,\n type ConfigParameter,\n type InstantCloseReturnType,\n type PrepareInstantCloseParameters,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\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 { predicateMatch } from \"../utils\";\n\n/**\n * Parameters for {@link useInstantCloseAuto}.\n */\nexport type UseInstantCloseAutoParameters = ConfigParameter;\n\n/** Return type of {@link useInstantCloseAuto}. */\nexport type UseInstantCloseAutoReturnType = UseMutationResult<\n InstantCloseReturnType,\n SymmioRequestError,\n PrepareInstantCloseParameters\n>;\n\n/**\n * Close (or partially close) a lowcap instant position via the wizard\n * `instantCloseAuto` action.\n *\n * Friendly default: accepts the minimal close intent and lets the SDK fetch\n * market metadata + mark price. Pre-fill `markPrice` to skip its fetch. For\n * full control — inspect / mutate resolved params between fetch and submit —\n * use {@link useInstantClose} after calling `prepareInstantCloseParams` directly.\n *\n * @example\n * ```tsx\n * const { mutateAsync } = useInstantCloseAuto();\n * await mutateAsync({\n * partyA, market: { id: 1 }, positionType: PositionType.LONG,\n * quoteId: 42n, quantityToClose: \"0.5\", slippage: 5, // ≥5%: source from user; 1% often fails to fill\n * });\n * ```\n */\nexport function useInstantCloseAuto(parameters: UseInstantCloseAutoParameters = {}): UseInstantCloseAutoReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const base = instantCloseAutoMutationOptions(config);\n\n return useMutation<InstantCloseReturnType, SymmioRequestError, PrepareInstantCloseParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n return await base.mutationFn({ ...variables, chainId: variables.chainId ?? chainId });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n /**\n * A freshly submitted instant-close exists on the hedger but not in any\n * cached read yet. Invalidate the instant-closes feed so it refetches and the\n * closing row appears immediately — and so the managed-quotes consumer, which\n * polls the feed only while a close is in flight, fetches it once to bootstrap.\n */\n const configKey = config.getChainConfigKey(variables.chainId ?? chainId);\n void queryClient.invalidateQueries({ predicate: predicateMatch(getInstantClosesQueryKey, { configKey }) });\n },\n });\n}\n"],"mappings":";;;;;;;;AA8CA,SAAgB,EAAoB,IAA4C,CAAC,GAAkC;CACjH,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAO,EAAgC,CAAM;CAEnD,OAAO,EAAuF;EAC5F,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,OAAO,MAAM,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS,EAAU,WAAW;IAAQ,CAAC;GACtF,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GAOjC,IAAM,IAAY,EAAO,kBAAkB,EAAU,WAAW,CAAO;GACvE,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA0B,EAAE,aAAU,CAAC,EAAE,CAAC;EAC3G;CACF,CAAC;AACH"}
|
|
@@ -17,7 +17,7 @@ export type UseInstantCloseBulkAutoReturnType = UseMutationResult<InstantCloseBu
|
|
|
17
17
|
* await mutateAsync({
|
|
18
18
|
* from: sessionKey,
|
|
19
19
|
* orders: [
|
|
20
|
-
* { partyA, market: { id: 1 }, positionType: PositionType.LONG, quoteId: 1n, quantityToClose: "0.5", slippage:
|
|
20
|
+
* { partyA, market: { id: 1 }, positionType: PositionType.LONG, quoteId: 1n, quantityToClose: "0.5", slippage: 5 },
|
|
21
21
|
* ],
|
|
22
22
|
* });
|
|
23
23
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-instant-close-bulk-auto.js","names":[],"sources":["../../src/instant-layer/use-instant-close-bulk-auto.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getInstantClosesQueryKey,\n instantCloseBulkAutoMutationOptions,\n type ConfigParameter,\n type InstantCloseBulkAutoParameters,\n type InstantCloseBulkReturnType,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\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 { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useInstantCloseBulkAuto}. */\nexport type UseInstantCloseBulkAutoParameters = ConfigParameter;\n\n/** Return type of {@link useInstantCloseBulkAuto}. */\nexport type UseInstantCloseBulkAutoReturnType = UseMutationResult<\n InstantCloseBulkReturnType,\n SymmioRequestError,\n InstantCloseBulkAutoParameters\n>;\n\n/**\n * Close multiple lowcap instant positions in one solver round-trip, deriving\n * each order's wei fields from UI-shape inputs (market id, slippage, mark\n * price, …) via `prepareInstantCloseParams`. Friendly default for \"close-all\"\n * flows.\n *\n * @example\n * ```tsx\n * const { mutateAsync } = useInstantCloseBulkAuto();\n * await mutateAsync({\n * from: sessionKey,\n * orders: [\n * { partyA, market: { id: 1 }, positionType: PositionType.LONG, quoteId: 1n, quantityToClose: \"0.5\", slippage:
|
|
1
|
+
{"version":3,"file":"use-instant-close-bulk-auto.js","names":[],"sources":["../../src/instant-layer/use-instant-close-bulk-auto.ts"],"sourcesContent":["\"use client\";\n\nimport {\n getInstantClosesQueryKey,\n instantCloseBulkAutoMutationOptions,\n type ConfigParameter,\n type InstantCloseBulkAutoParameters,\n type InstantCloseBulkReturnType,\n} from \"@symmio/trading-core\";\nimport { useMutation, useQueryClient, type UseMutationResult } from \"@tanstack/react-query\";\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 { predicateMatch } from \"../utils\";\n\n/** Parameters for {@link useInstantCloseBulkAuto}. */\nexport type UseInstantCloseBulkAutoParameters = ConfigParameter;\n\n/** Return type of {@link useInstantCloseBulkAuto}. */\nexport type UseInstantCloseBulkAutoReturnType = UseMutationResult<\n InstantCloseBulkReturnType,\n SymmioRequestError,\n InstantCloseBulkAutoParameters\n>;\n\n/**\n * Close multiple lowcap instant positions in one solver round-trip, deriving\n * each order's wei fields from UI-shape inputs (market id, slippage, mark\n * price, …) via `prepareInstantCloseParams`. Friendly default for \"close-all\"\n * flows.\n *\n * @example\n * ```tsx\n * const { mutateAsync } = useInstantCloseBulkAuto();\n * await mutateAsync({\n * from: sessionKey,\n * orders: [\n * { partyA, market: { id: 1 }, positionType: PositionType.LONG, quoteId: 1n, quantityToClose: \"0.5\", slippage: 5 },\n * ],\n * });\n * ```\n */\nexport function useInstantCloseBulkAuto(\n parameters: UseInstantCloseBulkAutoParameters = {},\n): UseInstantCloseBulkAutoReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const base = instantCloseBulkAutoMutationOptions(config);\n\n return useMutation<InstantCloseBulkReturnType, SymmioRequestError, InstantCloseBulkAutoParameters>({\n mutationKey: base.mutationKey,\n mutationFn: async (variables) => {\n try {\n return await base.mutationFn({ ...variables, chainId: variables.chainId ?? chainId });\n } catch (err) {\n throw normalizeSymmError(err);\n }\n },\n onSuccess: (_result, variables) => {\n const configKey = config.getChainConfigKey(variables.chainId ?? chainId);\n void queryClient.invalidateQueries({ predicate: predicateMatch(getInstantClosesQueryKey, { configKey }) });\n },\n });\n}\n"],"mappings":";;;;;;;;AA2CA,SAAgB,EACd,IAAgD,CAAC,GACd;CACnC,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAO,EAAoC,CAAM;CAEvD,OAAO,EAA4F;EACjG,aAAa,EAAK;EAClB,YAAY,OAAO,MAAc;GAC/B,IAAI;IACF,OAAO,MAAM,EAAK,WAAW;KAAE,GAAG;KAAW,SAAS,EAAU,WAAW;IAAQ,CAAC;GACtF,SAAS,GAAK;IACZ,MAAM,EAAmB,CAAG;GAC9B;EACF;EACA,YAAY,GAAS,MAAc;GACjC,IAAM,IAAY,EAAO,kBAAkB,EAAU,WAAW,CAAO;GACvE,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAA0B,EAAE,aAAU,CAAC,EAAE,CAAC;EAC3G;CACF,CAAC;AACH"}
|
|
@@ -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,
|
|
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
|
|
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:
|
|
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 @@
|
|
|
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"}
|