@symmio/trading-react 4.2.0 → 4.3.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/dist/instant-layer/use-instant-open-with-tpsl.d.ts +14 -7
- package/dist/instant-layer/use-instant-open-with-tpsl.d.ts.map +1 -1
- package/dist/instant-layer/use-instant-open-with-tpsl.js +49 -35
- package/dist/instant-layer/use-instant-open-with-tpsl.js.map +1 -1
- package/dist/tpsl/use-delete-quote-tpsl.js +1 -1
- package/dist/tpsl/use-delete-quote-tpsl.js.map +1 -1
- package/dist/tpsl/use-set-quote-tpsl.js +1 -1
- package/dist/tpsl/use-set-quote-tpsl.js.map +1 -1
- package/package.json +4 -4
|
@@ -10,24 +10,31 @@ import { SymmioRequestError } from '../errors/symmio-request-error.js';
|
|
|
10
10
|
* exactly like {@link useInstantOpenAuto}. When present, the SDK dispatches
|
|
11
11
|
* `setQuoteTpSl` immediately after the hedger returns a `tempQuoteId` — the
|
|
12
12
|
* message is signed against the (predicted) VA the caller supplies, so no
|
|
13
|
-
* on-chain reconciliation wait is needed.
|
|
14
|
-
*
|
|
13
|
+
* on-chain reconciliation wait is needed. Acceptance is separate from observed
|
|
14
|
+
* order state. Consumers can use the SDK store or own REST reconciliation.
|
|
15
15
|
*/
|
|
16
16
|
export interface UseInstantOpenWithTpSlVariables extends PrepareInstantOpenParameters {
|
|
17
17
|
tpsl?: Omit<SetQuoteTpSlParameters, "quoteId" | "chainId">;
|
|
18
|
+
/** Use the exact submitted size for attachment, or retain the provided quantity (default). */
|
|
19
|
+
tpslQuantityMode?: "provided" | "prepared";
|
|
18
20
|
}
|
|
19
21
|
/** Aggregated success payload from {@link useInstantOpenWithTpSl}. */
|
|
20
22
|
export interface UseInstantOpenWithTpSlData {
|
|
21
23
|
instantOpen: InstantOpenReturnType;
|
|
22
24
|
/** Set when the TP/SL leg was attempted and succeeded. */
|
|
23
25
|
tpsl?: SetQuoteTpSlReturnType;
|
|
24
|
-
/** Set when
|
|
26
|
+
/** Set when TP/SL attachment could not be submitted or failed — instant open still landed. */
|
|
25
27
|
tpslError?: SymmioRequestError;
|
|
28
|
+
/** Resolved attachment inputs, including on failure. Contains no signature. */
|
|
29
|
+
tpslParameters?: SetQuoteTpSlParameters;
|
|
26
30
|
}
|
|
27
31
|
/** Which leg the orchestrator is currently on. */
|
|
28
32
|
export type UseInstantOpenWithTpSlPhase = "idle" | "opening" | "attaching-tpsl" | "success" | "error";
|
|
29
33
|
/** Parameters for {@link useInstantOpenWithTpSl}. */
|
|
30
|
-
export type UseInstantOpenWithTpSlParameters = ConfigParameter
|
|
34
|
+
export type UseInstantOpenWithTpSlParameters = ConfigParameter & {
|
|
35
|
+
/** "external" leaves TP/SL optimism/reconciliation to the consumer. Defaults to "sdk". */
|
|
36
|
+
tpslState?: "sdk" | "external";
|
|
37
|
+
};
|
|
31
38
|
/** Return type of {@link useInstantOpenWithTpSl}. */
|
|
32
39
|
export type UseInstantOpenWithTpSlReturnType = UseMutationResult<UseInstantOpenWithTpSlData, SymmioRequestError, UseInstantOpenWithTpSlVariables> & {
|
|
33
40
|
/** Current orchestration phase. Handy for phased status UI. */
|
|
@@ -37,13 +44,13 @@ export type UseInstantOpenWithTpSlReturnType = UseMutationResult<UseInstantOpenW
|
|
|
37
44
|
* One-shot orchestrator: post an instant open and — if the caller pre-filled
|
|
38
45
|
* a TP/SL block — immediately submit `setQuoteTpSl` using the hedger's returned
|
|
39
46
|
* `tempQuoteId`. Web layer just wires inputs; all mutation logic (both legs +
|
|
40
|
-
*
|
|
47
|
+
* open/balance invalidation and optional confirming-slot write) lives in the SDK.
|
|
41
48
|
*
|
|
42
49
|
* Funding follows the `PrepareInstantOpenParameters` one-of: a typed
|
|
43
50
|
* `initialMargin`, or `fund: { mode: "full-balance", balance }` (lowcap only)
|
|
44
51
|
* to deploy the whole balance. In full-balance mode the submitted quantity is
|
|
45
|
-
* the SDK-rescaled one
|
|
46
|
-
*
|
|
52
|
+
* the SDK-rescaled one. Select `tpslQuantityMode: "prepared"` to use that exact
|
|
53
|
+
* submitted quantity, even when a prior preview differs.
|
|
47
54
|
*
|
|
48
55
|
* @example
|
|
49
56
|
* ```tsx
|
|
@@ -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,
|
|
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,EAOL,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;AAI5F,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;IAC3D,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;CAC5C;AAED,sEAAsE;AACtE,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,qBAAqB,CAAC;IACnC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,sBAAsB,CAAC;IAC9B,8FAA8F;IAC9F,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,+EAA+E;IAC/E,cAAc,CAAC,EAAE,sBAAsB,CAAC;CACzC;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,GAAG;IAC/D,0FAA0F;IAC1F,SAAS,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC;CAChC,CAAC;AAEF,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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,GAAE,gCAAqC,GAChD,gCAAgC,CA0GlC"}
|
|
@@ -5,63 +5,77 @@ import { normalizeSymmError as n } from "../errors/normalize-symm-error.js";
|
|
|
5
5
|
import { predicateMatch as r } from "../utils/predicate-match.js";
|
|
6
6
|
import { invalidateAccountBalances as i } from "../utils/invalidate-account-balances.js";
|
|
7
7
|
import { useTpSlStore as a } from "../tpsl/tpsl-store.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { SymmError as o, getInstantOpensQueryKey as s, instantOpen as c, instantOpenAutoMutationOptions as l, prepareInstantOpenParams as u, setQuoteTpSlMutationOptions as d } from "@symmio/trading-core";
|
|
9
|
+
import { formatUnits as f } from "viem";
|
|
10
|
+
import { useState as p } from "react";
|
|
11
|
+
import { useMutation as m, useQueryClient as h } from "@tanstack/react-query";
|
|
11
12
|
//#region src/instant-layer/use-instant-open-with-tpsl.ts
|
|
12
|
-
function
|
|
13
|
-
let
|
|
13
|
+
function g(g = {}) {
|
|
14
|
+
let _ = t(g), v = e(), y = h(), b = l(_), x = d(_), S = a((e) => e.markConfirming), [C, w] = p("idle"), T = m({
|
|
14
15
|
mutationKey: ["useInstantOpenWithTpSl"],
|
|
16
|
+
retry: !1,
|
|
15
17
|
mutationFn: async (e) => {
|
|
16
|
-
let t = e.chainId ??
|
|
17
|
-
|
|
18
|
-
let a;
|
|
18
|
+
let t = e.chainId ?? v;
|
|
19
|
+
w("opening");
|
|
20
|
+
let a, l = e.tpsl?.quantity;
|
|
19
21
|
try {
|
|
20
|
-
|
|
22
|
+
if (e.tpslQuantityMode === "prepared" && e.tpsl) {
|
|
23
|
+
let n = await u(_, {
|
|
24
|
+
...e,
|
|
25
|
+
chainId: t
|
|
26
|
+
});
|
|
27
|
+
l = f(n.order.quantity, 18), a = await c(_, n);
|
|
28
|
+
} else a = await b.mutationFn({
|
|
21
29
|
...e,
|
|
22
30
|
chainId: t
|
|
23
31
|
});
|
|
24
32
|
} catch (e) {
|
|
25
|
-
throw
|
|
33
|
+
throw w("error"), n(e);
|
|
26
34
|
}
|
|
27
|
-
let
|
|
28
|
-
if (
|
|
29
|
-
let
|
|
30
|
-
if (!Number.
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
let d = _.getChainConfigKey(t);
|
|
36
|
+
if (y.invalidateQueries({ predicate: r(s, { configKey: d }) }), i(y, { configKey: d }), !(e.tpsl && (e.tpsl.tp || e.tpsl.sl))) return w("success"), { instantOpen: a };
|
|
37
|
+
let p = a.tempQuoteId, m = typeof p == "string" && /^-?\d+$/.test(p) ? Number(p) : NaN;
|
|
38
|
+
if (!Number.isSafeInteger(m) || m === 0) return w("success"), {
|
|
39
|
+
instantOpen: a,
|
|
40
|
+
tpslError: n(new o("validation", "INSTANT_OPEN_TPSL_INVALID_ID", "Open accepted but attachment quote ID is missing or unsafe."))
|
|
41
|
+
};
|
|
42
|
+
w("attaching-tpsl");
|
|
43
|
+
let h = BigInt(m), C = {
|
|
44
|
+
...e.tpsl,
|
|
45
|
+
quantity: l,
|
|
46
|
+
chainId: t,
|
|
47
|
+
quoteId: h
|
|
48
|
+
};
|
|
33
49
|
try {
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
let t = await x.mutationFn(C), n = e.tpsl.tp, r = e.tpsl.sl;
|
|
51
|
+
return n && g.tpslState !== "external" && S(h, "tp", {
|
|
52
|
+
price: n.triggerPrice,
|
|
53
|
+
pricePrecision: e.tpsl.pricePrecision,
|
|
54
|
+
priceType: n.priceType,
|
|
55
|
+
cohQuoteId: t.cohQuoteId
|
|
56
|
+
}), r && g.tpslState !== "external" && S(h, "sl", {
|
|
40
57
|
price: r.triggerPrice,
|
|
41
58
|
pricePrecision: e.tpsl.pricePrecision,
|
|
42
59
|
priceType: r.priceType,
|
|
43
|
-
cohQuoteId:
|
|
44
|
-
}),
|
|
45
|
-
price: i.triggerPrice,
|
|
46
|
-
pricePrecision: e.tpsl.pricePrecision,
|
|
47
|
-
priceType: i.priceType,
|
|
48
|
-
cohQuoteId: n.cohQuoteId
|
|
49
|
-
}), b("success"), {
|
|
60
|
+
cohQuoteId: t.cohQuoteId
|
|
61
|
+
}), w("success"), {
|
|
50
62
|
instantOpen: a,
|
|
51
|
-
tpsl:
|
|
63
|
+
tpsl: t,
|
|
64
|
+
tpslParameters: C
|
|
52
65
|
};
|
|
53
66
|
} catch (e) {
|
|
54
|
-
return
|
|
67
|
+
return w("success"), {
|
|
55
68
|
instantOpen: a,
|
|
56
|
-
tpslError: n(e)
|
|
69
|
+
tpslError: n(e),
|
|
70
|
+
tpslParameters: C
|
|
57
71
|
};
|
|
58
72
|
}
|
|
59
73
|
},
|
|
60
|
-
onError: () =>
|
|
74
|
+
onError: () => w("error")
|
|
61
75
|
});
|
|
62
|
-
return Object.assign(
|
|
76
|
+
return Object.assign(T, { phase: C });
|
|
63
77
|
}
|
|
64
78
|
//#endregion
|
|
65
|
-
export {
|
|
79
|
+
export { g as useInstantOpenWithTpSl };
|
|
66
80
|
|
|
67
81
|
//# sourceMappingURL=use-instant-open-with-tpsl.js.map
|
|
@@ -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 { invalidateAccountBalances, 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 * Funding follows the `PrepareInstantOpenParameters` one-of: a typed\n * `initialMargin`, or `fund: { mode: \"full-balance\", balance }` (lowcap only)\n * to deploy the whole balance. In full-balance mode the submitted quantity is\n * the SDK-rescaled one — take the TP/SL `quantity` from `useInstantOpenFees`\n * (its `quantity` field) rather than re-deriving it from the typed margin.\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 /** The open locks margin and charges a fee — every balance read on this chain is now suspect. */\n invalidateAccountBalances(queryClient, { 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 pricePrecision: variables.tpsl!.pricePrecision,\n priceType: tp.priceType,\n cohQuoteId: tpslResult.cohQuoteId,\n });\n }\n if (sl) {\n markConfirming(quoteId, \"sl\", {\n price: sl.triggerPrice,\n pricePrecision: variables.tpsl!.pricePrecision,\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":";;;;;;;;;;;AAsFA,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;GAM1D,IALA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAyB,EAAE,aAAU,CAAC,EAAE,CAAC,GAExG,EAA0B,GAAa,EAAE,aAAU,CAAC,GAGhD,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;IAkB3B,OAjBI,KACF,EAAe,GAAS,MAAM;KAC5B,OAAO,EAAG;KACV,gBAAgB,EAAU,KAAM;KAChC,WAAW,EAAG;KACd,YAAY,EAAW;IACzB,CAAC,GAEC,KACF,EAAe,GAAS,MAAM;KAC5B,OAAO,EAAG;KACV,gBAAgB,EAAU,KAAM;KAChC,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"}
|
|
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 instantOpen,\n instantOpenAutoMutationOptions,\n prepareInstantOpenParams,\n setQuoteTpSlMutationOptions,\n SymmError,\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 { formatUnits } from \"viem\";\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 { invalidateAccountBalances, 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. Acceptance is separate from observed\n * order state. Consumers can use the SDK store or own REST reconciliation.\n */\nexport interface UseInstantOpenWithTpSlVariables extends PrepareInstantOpenParameters {\n tpsl?: Omit<SetQuoteTpSlParameters, \"quoteId\" | \"chainId\">;\n /** Use the exact submitted size for attachment, or retain the provided quantity (default). */\n tpslQuantityMode?: \"provided\" | \"prepared\";\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 TP/SL attachment could not be submitted or failed — instant open still landed. */\n tpslError?: SymmioRequestError;\n /** Resolved attachment inputs, including on failure. Contains no signature. */\n tpslParameters?: SetQuoteTpSlParameters;\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 /** \"external\" leaves TP/SL optimism/reconciliation to the consumer. Defaults to \"sdk\". */\n tpslState?: \"sdk\" | \"external\";\n};\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 * open/balance invalidation and optional confirming-slot write) lives in the SDK.\n *\n * Funding follows the `PrepareInstantOpenParameters` one-of: a typed\n * `initialMargin`, or `fund: { mode: \"full-balance\", balance }` (lowcap only)\n * to deploy the whole balance. In full-balance mode the submitted quantity is\n * the SDK-rescaled one. Select `tpslQuantityMode: \"prepared\"` to use that exact\n * submitted quantity, even when a prior preview differs.\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 retry: false,\n mutationFn: async (variables) => {\n const resolvedChainId = variables.chainId ?? chainId;\n setPhase(\"opening\");\n let openResult: InstantOpenReturnType;\n let quantity = variables.tpsl?.quantity;\n try {\n if (variables.tpslQuantityMode === \"prepared\" && variables.tpsl) {\n const prepared = await prepareInstantOpenParams(config, { ...variables, chainId: resolvedChainId });\n quantity = formatUnits(prepared.order.quantity, 18);\n openResult = await instantOpen(config, prepared);\n } else {\n openResult = await openBase.mutationFn({ ...variables, chainId: resolvedChainId });\n }\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 /** The open locks margin and charges a fee — every balance read on this chain is now suspect. */\n invalidateAccountBalances(queryClient, { configKey });\n\n const wantsTpSl = Boolean(variables.tpsl && (variables.tpsl.tp || variables.tpsl.sl));\n if (!wantsTpSl) {\n setPhase(\"success\");\n return { instantOpen: openResult };\n }\n\n // Check the original decimal integer syntax before Number can round a fractional ID.\n const tempId = openResult.tempQuoteId;\n const tempIdNumber = typeof tempId === \"string\" && /^-?\\d+$/.test(tempId) ? Number(tempId) : NaN;\n if (!Number.isSafeInteger(tempIdNumber) || tempIdNumber === 0) {\n setPhase(\"success\");\n return {\n instantOpen: openResult,\n tpslError: normalizeSymmError(\n new SymmError(\n \"validation\",\n \"INSTANT_OPEN_TPSL_INVALID_ID\",\n \"Open accepted but attachment quote ID is missing or unsafe.\",\n ),\n ),\n };\n }\n\n setPhase(\"attaching-tpsl\");\n const quoteId = BigInt(tempIdNumber);\n const tpslParameters: SetQuoteTpSlParameters = {\n ...variables.tpsl!,\n quantity: quantity!,\n chainId: resolvedChainId,\n quoteId,\n };\n try {\n const tpslResult = await tpslBase.mutationFn(tpslParameters);\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 && parameters.tpslState !== \"external\") {\n markConfirming(quoteId, \"tp\", {\n price: tp.triggerPrice,\n pricePrecision: variables.tpsl!.pricePrecision,\n priceType: tp.priceType,\n cohQuoteId: tpslResult.cohQuoteId,\n });\n }\n if (sl && parameters.tpslState !== \"external\") {\n markConfirming(quoteId, \"sl\", {\n price: sl.triggerPrice,\n pricePrecision: variables.tpsl!.pricePrecision,\n priceType: sl.priceType,\n cohQuoteId: tpslResult.cohQuoteId,\n });\n }\n setPhase(\"success\");\n return { instantOpen: openResult, tpsl: tpslResult, tpslParameters };\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), tpslParameters };\n }\n },\n onError: () => setPhase(\"error\"),\n }) as UseMutationResult<UseInstantOpenWithTpSlData, SymmioRequestError, UseInstantOpenWithTpSlVariables>;\n\n return Object.assign(mutation, { phase });\n}\n"],"mappings":";;;;;;;;;;;;AAiGA,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,OAAO;EACP,YAAY,OAAO,MAAc;GAC/B,IAAM,IAAkB,EAAU,WAAW;GAC7C,EAAS,SAAS;GAClB,IAAI,GACA,IAAW,EAAU,MAAM;GAC/B,IAAI;IACF,IAAI,EAAU,qBAAqB,cAAc,EAAU,MAAM;KAC/D,IAAM,IAAW,MAAM,EAAyB,GAAQ;MAAE,GAAG;MAAW,SAAS;KAAgB,CAAC;KAElG,AADA,IAAW,EAAY,EAAS,MAAM,UAAU,EAAE,GAClD,IAAa,MAAM,EAAY,GAAQ,CAAQ;IACjD,OACE,IAAa,MAAM,EAAS,WAAW;KAAE,GAAG;KAAW,SAAS;IAAgB,CAAC;GAErF,SAAS,GAAK;IAEZ,MADA,EAAS,OAAO,GACV,EAAmB,CAAG;GAC9B;GAGA,IAAM,IAAY,EAAO,kBAAkB,CAAe;GAM1D,IALA,EAAiB,kBAAkB,EAAE,WAAW,EAAe,GAAyB,EAAE,aAAU,CAAC,EAAE,CAAC,GAExG,EAA0B,GAAa,EAAE,aAAU,CAAC,GAGhD,EADsB,EAAU,SAAS,EAAU,KAAK,MAAM,EAAU,KAAK,MAG/E,OADA,EAAS,SAAS,GACX,EAAE,aAAa,EAAW;GAInC,IAAM,IAAS,EAAW,aACpB,IAAe,OAAO,KAAW,YAAY,UAAU,KAAK,CAAM,IAAI,OAAO,CAAM,IAAI;GAC7F,IAAI,CAAC,OAAO,cAAc,CAAY,KAAK,MAAiB,GAE1D,OADA,EAAS,SAAS,GACX;IACL,aAAa;IACb,WAAW,EACT,IAAI,EACF,cACA,gCACA,6DACF,CACF;GACF;GAGF,EAAS,gBAAgB;GACzB,IAAM,IAAU,OAAO,CAAY,GAC7B,IAAyC;IAC7C,GAAG,EAAU;IACH;IACV,SAAS;IACT;GACF;GACA,IAAI;IACF,IAAM,IAAa,MAAM,EAAS,WAAW,CAAc,GAKrD,IAAK,EAAU,KAAM,IACrB,IAAK,EAAU,KAAM;IAkB3B,OAjBI,KAAM,EAAW,cAAc,cACjC,EAAe,GAAS,MAAM;KAC5B,OAAO,EAAG;KACV,gBAAgB,EAAU,KAAM;KAChC,WAAW,EAAG;KACd,YAAY,EAAW;IACzB,CAAC,GAEC,KAAM,EAAW,cAAc,cACjC,EAAe,GAAS,MAAM;KAC5B,OAAO,EAAG;KACV,gBAAgB,EAAU,KAAM;KAChC,WAAW,EAAG;KACd,YAAY,EAAW;IACzB,CAAC,GAEH,EAAS,SAAS,GACX;KAAE,aAAa;KAAY,MAAM;KAAY;IAAe;GACrE,SAAS,GAAK;IAKZ,OADA,EAAS,SAAS,GACX;KAAE,aAAa;KAAY,WAAW,EAAmB,CAAG;KAAG;IAAe;GACvF;EACF;EACA,eAAe,EAAS,OAAO;CACjC,CAAC;CAED,OAAO,OAAO,OAAO,GAAU,EAAE,SAAM,CAAC;AAC1C"}
|
|
@@ -10,7 +10,7 @@ import { useMutation as o, useQueryClient as s } from "@tanstack/react-query";
|
|
|
10
10
|
function c(c = {}) {
|
|
11
11
|
let l = t(c), u = e(), d = s(), f = a(l), p = r((e) => e.markConfirming);
|
|
12
12
|
return o({
|
|
13
|
-
|
|
13
|
+
...f,
|
|
14
14
|
mutationFn: async (e) => {
|
|
15
15
|
try {
|
|
16
16
|
return await f.mutationFn({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-delete-quote-tpsl.js","names":[],"sources":["../../src/tpsl/use-delete-quote-tpsl.ts"],"sourcesContent":["\"use client\";\n\nimport {\n deleteQuoteTpSlMutationOptions,\n type ConfigParameter,\n type DeleteQuoteTpSlParameters,\n type DeleteQuoteTpSlReturnType,\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 { invalidateTpSlReads } from \"./invalidate-tpsl\";\nimport { useTpSlStore } from \"./tpsl-store\";\n\n/** Parameters for {@link useDeleteQuoteTpSl}. */\nexport type UseDeleteQuoteTpSlParameters = ConfigParameter;\n\n/** Return type of {@link useDeleteQuoteTpSl}. */\nexport type UseDeleteQuoteTpSlReturnType = UseMutationResult<\n DeleteQuoteTpSlReturnType,\n SymmioRequestError,\n DeleteQuoteTpSlParameters\n>;\n\n/**\n * Cancel a live TP or SL by its `cohQuoteId`. Signs an EIP-712 delete message\n * with the session-key wallet and calls `DELETE /api/v5/`. On 200 the target\n * side is marked `\"confirming\"` in the shared TP/SL store; the WS `cancel`\n * report flips it to `\"canceled\"` via `applyNotification`.\n */\nexport function useDeleteQuoteTpSl(parameters: UseDeleteQuoteTpSlParameters = {}): UseDeleteQuoteTpSlReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const base = deleteQuoteTpSlMutationOptions(config);\n const markConfirming = useTpSlStore((state) => state.markConfirming);\n\n return useMutation<DeleteQuoteTpSlReturnType, SymmioRequestError, DeleteQuoteTpSlParameters>({\n
|
|
1
|
+
{"version":3,"file":"use-delete-quote-tpsl.js","names":[],"sources":["../../src/tpsl/use-delete-quote-tpsl.ts"],"sourcesContent":["\"use client\";\n\nimport {\n deleteQuoteTpSlMutationOptions,\n type ConfigParameter,\n type DeleteQuoteTpSlParameters,\n type DeleteQuoteTpSlReturnType,\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 { invalidateTpSlReads } from \"./invalidate-tpsl\";\nimport { useTpSlStore } from \"./tpsl-store\";\n\n/** Parameters for {@link useDeleteQuoteTpSl}. */\nexport type UseDeleteQuoteTpSlParameters = ConfigParameter;\n\n/** Return type of {@link useDeleteQuoteTpSl}. */\nexport type UseDeleteQuoteTpSlReturnType = UseMutationResult<\n DeleteQuoteTpSlReturnType,\n SymmioRequestError,\n DeleteQuoteTpSlParameters\n>;\n\n/**\n * Cancel a live TP or SL by its `cohQuoteId`. Signs an EIP-712 delete message\n * with the session-key wallet and calls `DELETE /api/v5/`. On 200 the target\n * side is marked `\"confirming\"` in the shared TP/SL store; the WS `cancel`\n * report flips it to `\"canceled\"` via `applyNotification`.\n */\nexport function useDeleteQuoteTpSl(parameters: UseDeleteQuoteTpSlParameters = {}): UseDeleteQuoteTpSlReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const base = deleteQuoteTpSlMutationOptions(config);\n const markConfirming = useTpSlStore((state) => state.markConfirming);\n\n return useMutation<DeleteQuoteTpSlReturnType, SymmioRequestError, DeleteQuoteTpSlParameters>({\n ...base,\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 // `intent: \"cancel\"` — this side is waiting to disappear, so an empty\n // refetch confirms it instead of being held off as a pending write.\n if (variables.conditionalOrderType === \"take_profit\") {\n markConfirming(variables.quoteId, \"tp\", { intent: \"cancel\" });\n }\n if (variables.conditionalOrderType === \"stop_loss\") {\n markConfirming(variables.quoteId, \"sl\", { intent: \"cancel\" });\n }\n void invalidateTpSlReads(queryClient, [variables.quoteId]);\n },\n });\n}\n"],"mappings":";;;;;;;;;AAgCA,SAAgB,EAAmB,IAA2C,CAAC,GAAiC;CAC9G,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAO,EAA+B,CAAM,GAC5C,IAAiB,GAAc,MAAU,EAAM,cAAc;CAEnE,OAAO,EAAsF;EAC3F,GAAG;EACH,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;GASjC,AANI,EAAU,yBAAyB,iBACrC,EAAe,EAAU,SAAS,MAAM,EAAE,QAAQ,SAAS,CAAC,GAE1D,EAAU,yBAAyB,eACrC,EAAe,EAAU,SAAS,MAAM,EAAE,QAAQ,SAAS,CAAC,GAE9D,EAAyB,GAAa,CAAC,EAAU,OAAO,CAAC;EAC3D;CACF,CAAC;AACH"}
|
|
@@ -10,7 +10,7 @@ import { useMutation as o, useQueryClient as s } from "@tanstack/react-query";
|
|
|
10
10
|
function c(c = {}) {
|
|
11
11
|
let l = t(c), u = e(), d = s(), f = a(l), p = r((e) => e.markConfirming);
|
|
12
12
|
return o({
|
|
13
|
-
|
|
13
|
+
...f,
|
|
14
14
|
mutationFn: async (e) => {
|
|
15
15
|
try {
|
|
16
16
|
return await f.mutationFn({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-set-quote-tpsl.js","names":[],"sources":["../../src/tpsl/use-set-quote-tpsl.ts"],"sourcesContent":["\"use client\";\n\nimport {\n setQuoteTpSlMutationOptions,\n type ConfigParameter,\n type SetQuoteTpSlParameters,\n type SetQuoteTpSlReturnType,\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 { invalidateTpSlReads } from \"./invalidate-tpsl\";\nimport { useTpSlStore } from \"./tpsl-store\";\n\n/** Parameters for {@link useSetQuoteTpSl}. */\nexport type UseSetQuoteTpSlParameters = ConfigParameter;\n\n/** Return type of {@link useSetQuoteTpSl}. */\nexport type UseSetQuoteTpSlReturnType = UseMutationResult<\n SetQuoteTpSlReturnType,\n SymmioRequestError,\n SetQuoteTpSlParameters\n>;\n\n/**\n * Submit a TP/SL order for one quote. Signs an EIP-712 message with the\n * session-key wallet and POSTs to the handler.\n *\n * State machine (per side):\n * 1. `pending` — POST in flight (`mutation.isPending`).\n * 2. `confirming` — POST returned 200; the store's `markConfirming` sets\n * `tp/slState` to `\"confirming\"` and seeds the target trigger price so\n * the UI can render it immediately.\n * 3. `new` — Confirmed. The handler's live `report` (`applyNotification`)\n * resolves the side first when the socket is connected; a refetch of the\n * quote's TP/SL read on success is the authoritative backstop, so the box\n * resolves out of `confirming` even when that frame is missed.\n */\nexport function useSetQuoteTpSl(parameters: UseSetQuoteTpSlParameters = {}): UseSetQuoteTpSlReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const base = setQuoteTpSlMutationOptions(config);\n const markConfirming = useTpSlStore((state) => state.markConfirming);\n\n return useMutation<SetQuoteTpSlReturnType, SymmioRequestError, SetQuoteTpSlParameters>({\n
|
|
1
|
+
{"version":3,"file":"use-set-quote-tpsl.js","names":[],"sources":["../../src/tpsl/use-set-quote-tpsl.ts"],"sourcesContent":["\"use client\";\n\nimport {\n setQuoteTpSlMutationOptions,\n type ConfigParameter,\n type SetQuoteTpSlParameters,\n type SetQuoteTpSlReturnType,\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 { invalidateTpSlReads } from \"./invalidate-tpsl\";\nimport { useTpSlStore } from \"./tpsl-store\";\n\n/** Parameters for {@link useSetQuoteTpSl}. */\nexport type UseSetQuoteTpSlParameters = ConfigParameter;\n\n/** Return type of {@link useSetQuoteTpSl}. */\nexport type UseSetQuoteTpSlReturnType = UseMutationResult<\n SetQuoteTpSlReturnType,\n SymmioRequestError,\n SetQuoteTpSlParameters\n>;\n\n/**\n * Submit a TP/SL order for one quote. Signs an EIP-712 message with the\n * session-key wallet and POSTs to the handler.\n *\n * State machine (per side):\n * 1. `pending` — POST in flight (`mutation.isPending`).\n * 2. `confirming` — POST returned 200; the store's `markConfirming` sets\n * `tp/slState` to `\"confirming\"` and seeds the target trigger price so\n * the UI can render it immediately.\n * 3. `new` — Confirmed. The handler's live `report` (`applyNotification`)\n * resolves the side first when the socket is connected; a refetch of the\n * quote's TP/SL read on success is the authoritative backstop, so the box\n * resolves out of `confirming` even when that frame is missed.\n */\nexport function useSetQuoteTpSl(parameters: UseSetQuoteTpSlParameters = {}): UseSetQuoteTpSlReturnType {\n const config = useSymmioConfig(parameters);\n const chainId = useSymmioChainId();\n const queryClient = useQueryClient();\n const base = setQuoteTpSlMutationOptions(config);\n const markConfirming = useTpSlStore((state) => state.markConfirming);\n\n return useMutation<SetQuoteTpSlReturnType, SymmioRequestError, SetQuoteTpSlParameters>({\n ...base,\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 if (variables.tp) {\n markConfirming(variables.quoteId, \"tp\", {\n price: variables.tp.triggerPrice,\n pricePrecision: variables.pricePrecision,\n priceType: variables.tp.priceType,\n cohQuoteId: result.cohQuoteId,\n });\n }\n if (variables.sl) {\n markConfirming(variables.quoteId, \"sl\", {\n price: variables.sl.triggerPrice,\n pricePrecision: variables.pricePrecision,\n priceType: variables.sl.priceType,\n cohQuoteId: result.cohQuoteId,\n });\n }\n void invalidateTpSlReads(queryClient, [variables.quoteId]);\n },\n });\n}\n"],"mappings":";;;;;;;;;AAwCA,SAAgB,EAAgB,IAAwC,CAAC,GAA8B;CACrG,IAAM,IAAS,EAAgB,CAAU,GACnC,IAAU,EAAiB,GAC3B,IAAc,EAAe,GAC7B,IAAO,EAA4B,CAAM,GACzC,IAAiB,GAAc,MAAU,EAAM,cAAc;CAEnE,OAAO,EAAgF;EACrF,GAAG;EACH,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,GAAQ,MAAc;GAiBhC,AAhBI,EAAU,MACZ,EAAe,EAAU,SAAS,MAAM;IACtC,OAAO,EAAU,GAAG;IACpB,gBAAgB,EAAU;IAC1B,WAAW,EAAU,GAAG;IACxB,YAAY,EAAO;GACrB,CAAC,GAEC,EAAU,MACZ,EAAe,EAAU,SAAS,MAAM;IACtC,OAAO,EAAU,GAAG;IACpB,gBAAgB,EAAU;IAC1B,WAAW,EAAU,GAAG;IACxB,YAAY,EAAO;GACrB,CAAC,GAEH,EAAyB,GAAa,CAAC,EAAU,OAAO,CAAC;EAC3D;CACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symmio/trading-react",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "React adapter for the SYMMIO SDK. Hooks, providers, and React-bound ergonomics on top of @symmio/trading-core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/SYMM-IO/Trading-SDK/tree/main/packages/trading-react#readme",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@tanstack/react-query": "^5.100.0",
|
|
92
92
|
"decimal.js": "^10.4.3",
|
|
93
93
|
"zustand": "^5.0.0",
|
|
94
|
-
"@symmio/trading-core": "^4.2.
|
|
94
|
+
"@symmio/trading-core": "^4.2.1"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"react": "^19.0.0",
|
|
@@ -117,8 +117,8 @@
|
|
|
117
117
|
"vite-plugin-dts": "^5.0.0",
|
|
118
118
|
"vitest": "^4.1.10",
|
|
119
119
|
"wagmi": "^3.4.2",
|
|
120
|
-
"@symmio/
|
|
121
|
-
"@symmio/
|
|
120
|
+
"@symmio/eslint-config": "^1.0.0",
|
|
121
|
+
"@symmio/typescript-config": "^1.0.0"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|
|
124
124
|
"build": "vite build && node ../../scripts/fix-dts-extensions.mjs dist",
|