@symmio/trading-core 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/tpsl/assert-tpsl-acceptance.d.ts +3 -0
  2. package/dist/tpsl/assert-tpsl-acceptance.d.ts.map +1 -0
  3. package/dist/tpsl/assert-tpsl-acceptance.js +14 -0
  4. package/dist/tpsl/assert-tpsl-acceptance.js.map +1 -0
  5. package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.d.ts +4 -3
  6. package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.d.ts.map +1 -1
  7. package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.js +9 -11
  8. package/dist/tpsl/delete-quote-tpsl/delete-quote-tpsl.js.map +1 -1
  9. package/dist/tpsl/delete-quote-tpsl/query.d.ts +4 -0
  10. package/dist/tpsl/delete-quote-tpsl/query.d.ts.map +1 -1
  11. package/dist/tpsl/delete-quote-tpsl/query.js +1 -0
  12. package/dist/tpsl/delete-quote-tpsl/query.js.map +1 -1
  13. package/dist/tpsl/search-tpsl-orders/search-tpsl-orders.d.ts.map +1 -1
  14. package/dist/tpsl/search-tpsl-orders/search-tpsl-orders.js +31 -28
  15. package/dist/tpsl/search-tpsl-orders/search-tpsl-orders.js.map +1 -1
  16. package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.d.ts +1 -1
  17. package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.d.ts.map +1 -1
  18. package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.js +9 -7
  19. package/dist/tpsl/set-quote-tpsl/build-conditional-order-leg.js.map +1 -1
  20. package/dist/tpsl/set-quote-tpsl/query.d.ts +4 -0
  21. package/dist/tpsl/set-quote-tpsl/query.d.ts.map +1 -1
  22. package/dist/tpsl/set-quote-tpsl/query.js +1 -0
  23. package/dist/tpsl/set-quote-tpsl/query.js.map +1 -1
  24. package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.d.ts +3 -3
  25. package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.d.ts.map +1 -1
  26. package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.js +42 -40
  27. package/dist/tpsl/set-quote-tpsl/set-quote-tpsl.js.map +1 -1
  28. package/package.json +1 -1
@@ -0,0 +1,3 @@
1
+ /** Shared acknowledgment validation; acceptance does not establish completion. */
2
+ export declare function assertTpSlAcceptance(body: unknown, operation: "SET" | "DELETE"): void;
3
+ //# sourceMappingURL=assert-tpsl-acceptance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-tpsl-acceptance.d.ts","sourceRoot":"","sources":["../../src/tpsl/assert-tpsl-acceptance.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,QAAQ,GAAG,IAAI,CA2BrF"}
@@ -0,0 +1,14 @@
1
+ import { SymmError as e } from "../shared/errors/symm-error.js";
2
+ //#region src/tpsl/assert-tpsl-acceptance.ts
3
+ function t(t, n) {
4
+ let r = t && typeof t == "object" ? t : {};
5
+ if (r.successful === !1 || r.successful === "false") {
6
+ let t = typeof r.message == "string" ? r.message : r.error_message;
7
+ throw new e("api", `${n}_TPSL_REJECTED`, typeof t == "string" ? t : n === "SET" ? "Handler rejected TP/SL submission." : "Handler rejected TP/SL delete.");
8
+ }
9
+ if (r.successful !== !0 && r.successful !== "true") throw new e("api", `${n}_TPSL_INVALID_RESPONSE`, n === "SET" ? "Handler did not explicitly acknowledge TP/SL submission; outcome is unknown." : "Handler did not explicitly acknowledge TP/SL removal; outcome is unknown.");
10
+ }
11
+ //#endregion
12
+ export { t as assertTpSlAcceptance };
13
+
14
+ //# sourceMappingURL=assert-tpsl-acceptance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-tpsl-acceptance.js","names":[],"sources":["../../src/tpsl/assert-tpsl-acceptance.ts"],"sourcesContent":["import { SymmError } from \"../shared/errors/symm-error\";\n\n/** Shared acknowledgment validation; acceptance does not establish completion. */\nexport function assertTpSlAcceptance(body: unknown, operation: \"SET\" | \"DELETE\"): void {\n const response = (body && typeof body === \"object\" ? body : {}) as {\n successful?: unknown;\n message?: unknown;\n error_message?: unknown;\n };\n if (response.successful === false || response.successful === \"false\") {\n const message = typeof response.message === \"string\" ? response.message : response.error_message;\n throw new SymmError(\n \"api\",\n `${operation}_TPSL_REJECTED`,\n typeof message === \"string\"\n ? message\n : operation === \"SET\"\n ? \"Handler rejected TP/SL submission.\"\n : \"Handler rejected TP/SL delete.\",\n );\n }\n if (response.successful !== true && response.successful !== \"true\") {\n throw new SymmError(\n \"api\",\n `${operation}_TPSL_INVALID_RESPONSE`,\n operation === \"SET\"\n ? \"Handler did not explicitly acknowledge TP/SL submission; outcome is unknown.\"\n : \"Handler did not explicitly acknowledge TP/SL removal; outcome is unknown.\",\n );\n }\n}\n"],"mappings":";;AAGA,SAAgB,EAAqB,GAAe,GAAmC;CACrF,IAAM,IAAY,KAAQ,OAAO,KAAS,WAAW,IAAO,CAAC;CAK7D,IAAI,EAAS,eAAe,MAAS,EAAS,eAAe,SAAS;EACpE,IAAM,IAAU,OAAO,EAAS,WAAY,WAAW,EAAS,UAAU,EAAS;EACnF,MAAM,IAAI,EACR,OACA,GAAG,EAAU,iBACb,OAAO,KAAY,WACf,IACA,MAAc,QACZ,uCACA,gCACR;CACF;CACA,IAAI,EAAS,eAAe,MAAQ,EAAS,eAAe,QAC1D,MAAM,IAAI,EACR,OACA,GAAG,EAAU,yBACb,MAAc,QACV,iFACA,2EACN;AAEJ"}
@@ -26,9 +26,10 @@ export interface DeleteQuoteTpSlReturnType {
26
26
  * 3. Sign with the session-key wallet.
27
27
  * 4. DELETE `/api/v5/` with `{ typedData, signature, signer }`.
28
28
  *
29
- * The handler returns 200 on accept — the cancel is only fully "confirmed"
30
- * once the WebSocket reports `state: "cancel"` (or `canceled` / `cancelled`).
31
- * Callers should subscribe via `watchTpSlNotifications` and reconcile.
29
+ * An explicit successful response acknowledges submission, not completion.
30
+ * Notifications are refresh signals; reconcile with a complete live-order read
31
+ * before treating the requested order as removed. Notifications do not identify
32
+ * a particular mutation or carry an order version.
32
33
  *
33
34
  * @throws {SymmError} when the chain has no `tpsl` config or signing fails.
34
35
  * @throws {SymmApiError} when the handler request fails.
@@ -1 +1 @@
1
- {"version":3,"file":"delete-quote-tpsl.d.ts","sourceRoot":"","sources":["../../../src/tpsl/delete-quote-tpsl/delete-quote-tpsl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAMnF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAGzD,8CAA8C;AAC9C,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAC7C,oBAAoB,GAAG;IACrB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,cAAc,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,oBAAoB,EAAE,wBAAwB,CAAC;CAChD,CACF,CAAC;AAEF,8CAA8C;AAC9C,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,IAAI,CAAC;CACf;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC,yBAAyB,CAAC,CA2BpC"}
1
+ {"version":3,"file":"delete-quote-tpsl.d.ts","sourceRoot":"","sources":["../../../src/tpsl/delete-quote-tpsl/delete-quote-tpsl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAOnF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAGzD,8CAA8C;AAC9C,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAC7C,oBAAoB,GAAG;IACrB,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,cAAc,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,oBAAoB,EAAE,wBAAwB,CAAC;CAChD,CACF,CAAC;AAEF,8CAA8C;AAC9C,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,IAAI,CAAC;CACf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC,yBAAyB,CAAC,CAwBpC"}
@@ -1,13 +1,13 @@
1
- import { SymmError as e } from "../../shared/errors/symm-error.js";
2
- import { rethrowTpSlError as t } from "../internal/axios.js";
3
- import { resolveTpSlConfig as n } from "../internal/resolve-tpsl-config.js";
4
- import { deleteConditionalOrderV5ApiV5Delete as r } from "../types/generated/tpsl-handler.js";
1
+ import { rethrowTpSlError as e } from "../internal/axios.js";
2
+ import { resolveTpSlConfig as t } from "../internal/resolve-tpsl-config.js";
3
+ import { deleteConditionalOrderV5ApiV5Delete as n } from "../types/generated/tpsl-handler.js";
4
+ import { assertTpSlAcceptance as r } from "../assert-tpsl-acceptance.js";
5
5
  import { buildTpSlDeleteMessage as i } from "../set-quote-tpsl/build-conditional-order-message.js";
6
6
  import { signTpSlRequest as a } from "../set-quote-tpsl/sign-tpsl-request.js";
7
7
  import { getTpSlDeleteSigningSpec as o } from "../signing-spec/get-tpsl-delete-signing-spec.js";
8
8
  //#region src/tpsl/delete-quote-tpsl/delete-quote-tpsl.ts
9
9
  async function s(s, c) {
10
- let l = n(s, c.chainId), u = await a({
10
+ let l = t(s, c.chainId), u = await a({
11
11
  signingSpec: await o(s, { chainId: c.chainId }),
12
12
  message: i({
13
13
  virtualAccount: c.virtualAccount,
@@ -20,18 +20,16 @@ async function s(s, c) {
20
20
  })
21
21
  });
22
22
  try {
23
- let t = (await r(u, {
23
+ return r((await n(u, {
24
24
  baseURL: l.url,
25
25
  headers: {
26
26
  "App-Name": l.appName,
27
27
  "Content-Type": "application/json",
28
28
  Accept: "application/json"
29
29
  }
30
- })).data ?? {};
31
- if (!(typeof t.successful == "string" ? t.successful !== "false" : t.successful !== !1)) throw new e("api", "DELETE_TPSL_REJECTED", t.message ?? "Handler rejected TP/SL delete.");
32
- return { success: !0 };
33
- } catch (e) {
34
- return t(e, {
30
+ })).data ?? {}, "DELETE"), { success: !0 };
31
+ } catch (t) {
32
+ return e(t, {
35
33
  code: "DELETE_TPSL_FAILED",
36
34
  baseURL: l.url
37
35
  });
@@ -1 +1 @@
1
- {"version":3,"file":"delete-quote-tpsl.js","names":[],"sources":["../../../src/tpsl/delete-quote-tpsl/delete-quote-tpsl.ts"],"sourcesContent":["import type { Address } from \"viem\";\nimport type { Config } from \"../../core/config\";\nimport { SymmError } from \"../../shared/errors/symm-error\";\nimport type { Compute, WriteSolverParameter } from \"../../shared/types/properties\";\nimport { rethrowTpSlError } from \"../internal/axios\";\nimport { resolveTpSlConfig } from \"../internal/resolve-tpsl-config\";\nimport { buildTpSlDeleteMessage } from \"../set-quote-tpsl/build-conditional-order-message\";\nimport { signTpSlRequest } from \"../set-quote-tpsl/sign-tpsl-request\";\nimport { getTpSlDeleteSigningSpec } from \"../signing-spec/get-tpsl-delete-signing-spec\";\nimport type { TpSlConditionalOrderType } from \"../types\";\nimport { deleteConditionalOrderV5ApiV5Delete, type ConditionalOrderOperationV5 } from \"../types/generated/tpsl-handler\";\n\n/** Parameters for {@link deleteQuoteTpSl}. */\nexport type DeleteQuoteTpSlParameters = Compute<\n WriteSolverParameter & {\n /** On-chain quote id the order belongs to (used for cache invalidation). */\n quoteId: bigint;\n /** PartyA (the VA address) that owns the quote. */\n virtualAccount: Address;\n /** Handler-issued conditional-order id targeted by the delete. */\n cohQuoteId: string;\n /** Which side is being canceled. */\n conditionalOrderType: TpSlConditionalOrderType;\n }\n>;\n\n/** Return type of {@link deleteQuoteTpSl}. */\nexport interface DeleteQuoteTpSlReturnType {\n success: true;\n}\n\n/**\n * Cancel a live TP or SL order by its handler-issued `cohQuoteId`.\n *\n * Steps:\n * 1. Resolve the TP/SL handler URL + DELETE signing spec.\n * 2. Build a {@link TpSlDeleteMessage} bound to the target cohQuoteId + side.\n * 3. Sign with the session-key wallet.\n * 4. DELETE `/api/v5/` with `{ typedData, signature, signer }`.\n *\n * The handler returns 200 on accept — the cancel is only fully \"confirmed\"\n * once the WebSocket reports `state: \"cancel\"` (or `canceled` / `cancelled`).\n * Callers should subscribe via `watchTpSlNotifications` and reconcile.\n *\n * @throws {SymmError} when the chain has no `tpsl` config or signing fails.\n * @throws {SymmApiError} when the handler request fails.\n */\nexport async function deleteQuoteTpSl(\n config: Config,\n parameters: DeleteQuoteTpSlParameters,\n): Promise<DeleteQuoteTpSlReturnType> {\n const tpsl = resolveTpSlConfig(config, parameters.chainId);\n const signingSpec = await getTpSlDeleteSigningSpec(config, { chainId: parameters.chainId });\n\n const message = buildTpSlDeleteMessage({\n virtualAccount: parameters.virtualAccount,\n cohQuoteId: parameters.cohQuoteId,\n conditionalOrderType: parameters.conditionalOrderType,\n });\n\n const walletClient = await config.getWalletClient({ chainId: parameters.chainId, from: parameters.from });\n const signed = await signTpSlRequest({ signingSpec, message, walletClient });\n\n try {\n const response = await deleteConditionalOrderV5ApiV5Delete(signed as unknown as ConditionalOrderOperationV5, {\n baseURL: tpsl.url,\n headers: { \"App-Name\": tpsl.appName, \"Content-Type\": \"application/json\", Accept: \"application/json\" },\n });\n const body = response.data ?? {};\n const successful = typeof body.successful === \"string\" ? body.successful !== \"false\" : body.successful !== false;\n if (!successful) {\n throw new SymmError(\"api\", \"DELETE_TPSL_REJECTED\", body.message ?? \"Handler rejected TP/SL delete.\");\n }\n return { success: true };\n } catch (err) {\n return rethrowTpSlError(err, { code: \"DELETE_TPSL_FAILED\", baseURL: tpsl.url });\n }\n}\n"],"mappings":";;;;;;;;AA+CA,eAAsB,EACpB,GACA,GACoC;CACpC,IAAM,IAAO,EAAkB,GAAQ,EAAW,OAAO,GAUnD,IAAS,MAAM,EAAgB;EAAE,aAAA,MATb,EAAyB,GAAQ,EAAE,SAAS,EAAW,QAAQ,CAAC;EAStC,SAPpC,EAAuB;GACrC,gBAAgB,EAAW;GAC3B,YAAY,EAAW;GACvB,sBAAsB,EAAW;EACnC,CAGoD;EAAS,cAAA,MADlC,EAAO,gBAAgB;GAAE,SAAS,EAAW;GAAS,MAAM,EAAW;EAAK,CAAC;CAC9B,CAAC;CAE3E,IAAI;EAKF,IAAM,KAAO,MAJU,EAAoC,GAAkD;GAC3G,SAAS,EAAK;GACd,SAAS;IAAE,YAAY,EAAK;IAAS,gBAAgB;IAAoB,QAAQ;GAAmB;EACtG,CAAC,GACqB,QAAQ,CAAC;EAE/B,IAAI,EADe,OAAO,EAAK,cAAe,WAAW,EAAK,eAAe,UAAU,EAAK,eAAe,KAEzG,MAAM,IAAI,EAAU,OAAO,wBAAwB,EAAK,WAAW,gCAAgC;EAErG,OAAO,EAAE,SAAS,GAAK;CACzB,SAAS,GAAK;EACZ,OAAO,EAAiB,GAAK;GAAE,MAAM;GAAsB,SAAS,EAAK;EAAI,CAAC;CAChF;AACF"}
1
+ {"version":3,"file":"delete-quote-tpsl.js","names":[],"sources":["../../../src/tpsl/delete-quote-tpsl/delete-quote-tpsl.ts"],"sourcesContent":["import type { Address } from \"viem\";\nimport type { Config } from \"../../core/config\";\nimport type { Compute, WriteSolverParameter } from \"../../shared/types/properties\";\nimport { assertTpSlAcceptance } from \"../assert-tpsl-acceptance\";\nimport { rethrowTpSlError } from \"../internal/axios\";\nimport { resolveTpSlConfig } from \"../internal/resolve-tpsl-config\";\nimport { buildTpSlDeleteMessage } from \"../set-quote-tpsl/build-conditional-order-message\";\nimport { signTpSlRequest } from \"../set-quote-tpsl/sign-tpsl-request\";\nimport { getTpSlDeleteSigningSpec } from \"../signing-spec/get-tpsl-delete-signing-spec\";\nimport type { TpSlConditionalOrderType } from \"../types\";\nimport { deleteConditionalOrderV5ApiV5Delete, type ConditionalOrderOperationV5 } from \"../types/generated/tpsl-handler\";\n\n/** Parameters for {@link deleteQuoteTpSl}. */\nexport type DeleteQuoteTpSlParameters = Compute<\n WriteSolverParameter & {\n /** On-chain quote id the order belongs to (used for cache invalidation). */\n quoteId: bigint;\n /** PartyA (the VA address) that owns the quote. */\n virtualAccount: Address;\n /** Handler-issued conditional-order id targeted by the delete. */\n cohQuoteId: string;\n /** Which side is being canceled. */\n conditionalOrderType: TpSlConditionalOrderType;\n }\n>;\n\n/** Return type of {@link deleteQuoteTpSl}. */\nexport interface DeleteQuoteTpSlReturnType {\n success: true;\n}\n\n/**\n * Cancel a live TP or SL order by its handler-issued `cohQuoteId`.\n *\n * Steps:\n * 1. Resolve the TP/SL handler URL + DELETE signing spec.\n * 2. Build a {@link TpSlDeleteMessage} bound to the target cohQuoteId + side.\n * 3. Sign with the session-key wallet.\n * 4. DELETE `/api/v5/` with `{ typedData, signature, signer }`.\n *\n * An explicit successful response acknowledges submission, not completion.\n * Notifications are refresh signals; reconcile with a complete live-order read\n * before treating the requested order as removed. Notifications do not identify\n * a particular mutation or carry an order version.\n *\n * @throws {SymmError} when the chain has no `tpsl` config or signing fails.\n * @throws {SymmApiError} when the handler request fails.\n */\nexport async function deleteQuoteTpSl(\n config: Config,\n parameters: DeleteQuoteTpSlParameters,\n): Promise<DeleteQuoteTpSlReturnType> {\n const tpsl = resolveTpSlConfig(config, parameters.chainId);\n const signingSpec = await getTpSlDeleteSigningSpec(config, { chainId: parameters.chainId });\n\n const message = buildTpSlDeleteMessage({\n virtualAccount: parameters.virtualAccount,\n cohQuoteId: parameters.cohQuoteId,\n conditionalOrderType: parameters.conditionalOrderType,\n });\n\n const walletClient = await config.getWalletClient({ chainId: parameters.chainId, from: parameters.from });\n const signed = await signTpSlRequest({ signingSpec, message, walletClient });\n\n try {\n const response = await deleteConditionalOrderV5ApiV5Delete(signed as unknown as ConditionalOrderOperationV5, {\n baseURL: tpsl.url,\n headers: { \"App-Name\": tpsl.appName, \"Content-Type\": \"application/json\", Accept: \"application/json\" },\n });\n const body = response.data ?? {};\n assertTpSlAcceptance(body, \"DELETE\");\n return { success: true };\n } catch (err) {\n return rethrowTpSlError(err, { code: \"DELETE_TPSL_FAILED\", baseURL: tpsl.url });\n }\n}\n"],"mappings":";;;;;;;;AAgDA,eAAsB,EACpB,GACA,GACoC;CACpC,IAAM,IAAO,EAAkB,GAAQ,EAAW,OAAO,GAUnD,IAAS,MAAM,EAAgB;EAAE,aAAA,MATb,EAAyB,GAAQ,EAAE,SAAS,EAAW,QAAQ,CAAC;EAStC,SAPpC,EAAuB;GACrC,gBAAgB,EAAW;GAC3B,YAAY,EAAW;GACvB,sBAAsB,EAAW;EACnC,CAGoD;EAAS,cAAA,MADlC,EAAO,gBAAgB;GAAE,SAAS,EAAW;GAAS,MAAM,EAAW;EAAK,CAAC;CAC9B,CAAC;CAE3E,IAAI;EAOF,OADA,GADa,MAJU,EAAoC,GAAkD;GAC3G,SAAS,EAAK;GACd,SAAS;IAAE,YAAY,EAAK;IAAS,gBAAgB;IAAoB,QAAQ;GAAmB;EACtG,CAAC,GACqB,QAAQ,CAAC,GACJ,QAAQ,GAC5B,EAAE,SAAS,GAAK;CACzB,SAAS,GAAK;EACZ,OAAO,EAAiB,GAAK;GAAE,MAAM;GAAsB,SAAS,EAAK;EAAI,CAAC;CAChF;AACF"}
@@ -3,12 +3,16 @@ import { DeleteQuoteTpSlParameters } from './delete-quote-tpsl.js';
3
3
  /**
4
4
  * Build TanStack Mutation options for {@link deleteQuoteTpSl}.
5
5
  *
6
+ * Automatic retries are disabled: a failed response may follow an accepted write.
7
+ * Reconcile state before explicitly submitting again.
8
+ *
6
9
  * @example
7
10
  * ```ts
8
11
  * useMutation(deleteQuoteTpSlMutationOptions(config));
9
12
  * ```
10
13
  */
11
14
  export declare function deleteQuoteTpSlMutationOptions(config: Config): {
15
+ retry: boolean;
12
16
  mutationKey: readonly ["deleteQuoteTpSl"];
13
17
  mutationFn: (variables: DeleteQuoteTpSlParameters) => Promise<import('./delete-quote-tpsl.js').DeleteQuoteTpSlReturnType>;
14
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/tpsl/delete-quote-tpsl/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAmB,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAEtF;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM;;4BAGjC,yBAAyB;EAEpD"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/tpsl/delete-quote-tpsl/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAmB,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAEtF;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM;;;4BAIjC,yBAAyB;EAEpD"}
@@ -2,6 +2,7 @@ import { deleteQuoteTpSl as e } from "./delete-quote-tpsl.js";
2
2
  //#region src/tpsl/delete-quote-tpsl/query.ts
3
3
  function t(t) {
4
4
  return {
5
+ retry: !1,
5
6
  mutationKey: ["deleteQuoteTpSl"],
6
7
  mutationFn: (n) => e(t, n)
7
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","names":[],"sources":["../../../src/tpsl/delete-quote-tpsl/query.ts"],"sourcesContent":["import type { Config } from \"../../core/config\";\nimport { deleteQuoteTpSl, type DeleteQuoteTpSlParameters } from \"./delete-quote-tpsl\";\n\n/**\n * Build TanStack Mutation options for {@link deleteQuoteTpSl}.\n *\n * @example\n * ```ts\n * useMutation(deleteQuoteTpSlMutationOptions(config));\n * ```\n */\nexport function deleteQuoteTpSlMutationOptions(config: Config) {\n return {\n mutationKey: [\"deleteQuoteTpSl\"] as const,\n mutationFn: (variables: DeleteQuoteTpSlParameters) => deleteQuoteTpSl(config, variables),\n };\n}\n"],"mappings":";;AAWA,SAAgB,EAA+B,GAAgB;CAC7D,OAAO;EACL,aAAa,CAAC,iBAAiB;EAC/B,aAAa,MAAyC,EAAgB,GAAQ,CAAS;CACzF;AACF"}
1
+ {"version":3,"file":"query.js","names":[],"sources":["../../../src/tpsl/delete-quote-tpsl/query.ts"],"sourcesContent":["import type { Config } from \"../../core/config\";\nimport { deleteQuoteTpSl, type DeleteQuoteTpSlParameters } from \"./delete-quote-tpsl\";\n\n/**\n * Build TanStack Mutation options for {@link deleteQuoteTpSl}.\n *\n * Automatic retries are disabled: a failed response may follow an accepted write.\n * Reconcile state before explicitly submitting again.\n *\n * @example\n * ```ts\n * useMutation(deleteQuoteTpSlMutationOptions(config));\n * ```\n */\nexport function deleteQuoteTpSlMutationOptions(config: Config) {\n return {\n retry: false,\n mutationKey: [\"deleteQuoteTpSl\"] as const,\n mutationFn: (variables: DeleteQuoteTpSlParameters) => deleteQuoteTpSl(config, variables),\n };\n}\n"],"mappings":";;AAcA,SAAgB,EAA+B,GAAgB;CAC7D,OAAO;EACL,OAAO;EACP,aAAa,CAAC,iBAAiB;EAC/B,aAAa,MAAyC,EAAgB,GAAQ,CAAS;CACzF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"search-tpsl-orders.d.ts","sourceRoot":"","sources":["../../../src/tpsl/search-tpsl-or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EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CACF,CAAC;AAEF,6CAA6C;AAC7C,KAAK,uBAAuB,GAAG,qCAAqC,CAAC,OAAO,CAAC,SACzE,CAAC,MAAM,MAAM,CAAC,EAAE,GAChB,IAAI,GACJ,SAAS,GACT,MAAM,GACN,KAAK,CAAC;AAEV,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B;IACzC,yCAAyC;IACzC,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;OAQG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,0BAA0B,GACrC,OAAO,CAAC,0BAA0B,CAAC,CA8BrC"}
@@ -1,47 +1,50 @@
1
- import { rethrowTpSlError as e } from "../internal/axios.js";
2
- import { resolveTpSlConfig as t } from "../internal/resolve-tpsl-config.js";
3
- import { ConditionalOrdersState as n, searchConditionalOrdersV5ApiV5SearchPost as r } from "../types/generated/tpsl-handler.js";
1
+ import { SymmError as e } from "../../shared/errors/symm-error.js";
2
+ import { rethrowTpSlError as t } from "../internal/axios.js";
3
+ import { resolveTpSlConfig as n } from "../internal/resolve-tpsl-config.js";
4
+ import { ConditionalOrdersState as r, searchConditionalOrdersV5ApiV5SearchPost as i } from "../types/generated/tpsl-handler.js";
4
5
  //#region src/tpsl/search-tpsl-orders/search-tpsl-orders.ts
5
- var i = [
6
- n.pending,
7
- n.new,
8
- n.triggered,
9
- n.triggered_pending
10
- ], a = 200;
11
- async function o(n, o) {
12
- let c = t(n, o.chainId), l = o.size ?? a, u = {
13
- ...o.account === void 0 ? {} : { party_a_address: o.account },
14
- state: [...o.state ?? i],
15
- start: o.start ?? 0,
6
+ var a = [
7
+ r.pending,
8
+ r.new,
9
+ r.triggered,
10
+ r.triggered_pending
11
+ ], o = 200;
12
+ async function s(e, r) {
13
+ let s = n(e, r.chainId), l = r.size ?? o, u = {
14
+ ...r.account === void 0 ? {} : { party_a_address: r.account },
15
+ state: [...r.state ?? a],
16
+ start: r.start ?? 0,
16
17
  size: l
17
18
  };
18
- o.symbolId !== void 0 && (u.symbol_id = o.symbolId), o.conditionalOrderType !== void 0 && (u.conditional_order_type = o.conditionalOrderType), o.conditionalPriceType !== void 0 && (u.conditional_price_type = o.conditionalPriceType);
19
+ r.symbolId !== void 0 && (u.symbol_id = r.symbolId), r.conditionalOrderType !== void 0 && (u.conditional_order_type = r.conditionalOrderType), r.conditionalPriceType !== void 0 && (u.conditional_price_type = r.conditionalPriceType);
19
20
  try {
20
- return s((await r(u, {
21
- baseURL: c.url,
21
+ return c((await i(u, {
22
+ baseURL: s.url,
22
23
  headers: {
23
- "App-Name": c.appName,
24
+ "App-Name": s.appName,
24
25
  "Content-Type": "application/json",
25
26
  Accept: "application/json"
26
27
  },
27
- ...o.timeoutMs === void 0 ? {} : { timeout: o.timeoutMs }
28
+ ...r.timeoutMs === void 0 ? {} : { timeout: r.timeoutMs }
28
29
  })).data, l);
29
- } catch (t) {
30
- return e(t, {
30
+ } catch (e) {
31
+ return t(e, {
31
32
  code: "SEARCH_TPSL_FAILED",
32
- baseURL: c.url
33
+ baseURL: s.url
33
34
  });
34
35
  }
35
36
  }
36
- function s(e, t) {
37
- let n = Array.isArray(e) ? e : e?.data ?? [], r = Array.isArray(e) ? void 0 : e?.count;
37
+ function c(t, n) {
38
+ let r = Array.isArray(t) ? t : t?.data;
39
+ if (!Array.isArray(r)) throw new e("api", "SEARCH_TPSL_INVALID_RESPONSE", "Handler returned an invalid conditional-order page.");
40
+ let i = r, a = Array.isArray(t) ? void 0 : t?.count;
38
41
  return {
39
- orders: n,
40
- count: typeof r == "number" ? r : n.length,
41
- isComplete: n.length < t
42
+ orders: i,
43
+ count: typeof a == "number" ? a : i.length,
44
+ isComplete: i.length < n
42
45
  };
43
46
  }
44
47
  //#endregion
45
- export { i as TPSL_LIVE_ORDER_STATES, o as searchTpSlOrders };
48
+ export { a as TPSL_LIVE_ORDER_STATES, s as searchTpSlOrders };
46
49
 
47
50
  //# sourceMappingURL=search-tpsl-orders.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"search-tpsl-orders.js","names":[],"sources":["../../../src/tpsl/search-tpsl-orders/search-tpsl-orders.ts"],"sourcesContent":["import type { Address } from \"viem\";\nimport type { Config } from \"../../core/config\";\nimport type { ChainIdParameter, Compute } from \"../../shared/types/properties\";\nimport type { QuoteTpSlRow } from \"../get-quote-tpsl\";\nimport { rethrowTpSlError } from \"../internal/axios\";\nimport { resolveTpSlConfig } from \"../internal/resolve-tpsl-config\";\nimport { TpSlSearchOrderType } from \"../types\";\nimport {\n ConditionalOrdersState,\n searchConditionalOrdersV5ApiV5SearchPost,\n type ConditionalOrderSearchRequestSchemaV3,\n type ConditionalOrderType,\n type PriceActionType,\n} from \"../types/generated/tpsl-handler\";\n\n/**\n * The row states that represent an order the handler still holds.\n *\n * Exactly the set {@link QuoteTpSlRow} consumers treat as actionable —\n * `canceled` and `killed` are terminal and carry no live order. Passing this as\n * the search filter keeps \"absent from the result\" equivalent to \"no live\n * order\", which is what makes a cancel confirmable from a search response.\n */\nexport const TPSL_LIVE_ORDER_STATES = [\n ConditionalOrdersState.pending,\n ConditionalOrdersState.new,\n ConditionalOrdersState.triggered,\n ConditionalOrdersState.triggered_pending,\n] as const;\n\n/** Default page size. The handler's own default is 100; a position's legs fit well inside this. */\nconst DEFAULT_SEARCH_SIZE = 200;\n\n/** Parameters for {@link searchTpSlOrders}. */\nexport type SearchTpSlOrdersParameters = Compute<\n ChainIdParameter & {\n /**\n * Account whose conditional orders to search — the Virtual Account that\n * owns them, which is what the handler stores as `party_a_address`.\n *\n * **Omit to search across every account.** The handler treats the field as\n * an optional filter, so leaving it out returns all matching orders — which\n * is how a pool's own order book is read (`symbolId` + `conditionalOrderType`,\n * no account). Verified against the live handler.\n */\n account?: Address;\n /** Row states to include. Defaults to {@link TPSL_LIVE_ORDER_STATES}. */\n state?: readonly QuoteTpSlRowStateFilter[];\n /** Restrict to one market. */\n symbolId?: number;\n /** Restrict to one side. */\n conditionalOrderType?: TpSlSearchOrderType;\n /** Restrict to one trigger-price source. */\n conditionalPriceType?: PriceActionType;\n /** Page offset. Defaults to `0`. */\n start?: number;\n /** Page size. Defaults to `200`. */\n size?: number;\n /**\n * Abort the request after this many milliseconds. Unset means axios's\n * default of \"wait forever\" — pass one when the call is on a repeating\n * schedule, so a stalled connection fails the attempt instead of hanging it.\n */\n timeoutMs?: number;\n }\n>;\n\n/** A state accepted by the search filter. */\ntype QuoteTpSlRowStateFilter = ConditionalOrderSearchRequestSchemaV3[\"state\"] extends\n | (infer TState)[]\n | null\n | undefined\n ? TState\n : never;\n\n/** Return type of {@link searchTpSlOrders}. */\nexport interface SearchTpSlOrdersReturnType {\n /** The page's rows, in handler order. */\n orders: QuoteTpSlRow[];\n /** The handler's reported total for the filter. Advisory — see `isComplete`. */\n count: number;\n /**\n * `true` when this page provably exhausted the filtered result set, i.e.\n * fewer rows came back than were asked for.\n *\n * Derived from the page length rather than from `count`, whose meaning on\n * this endpoint is unverified and whose sibling `GET` already contradicts its\n * own spec. A caller may only read \"this order is absent, therefore it is\n * gone\" from a complete page; on an incomplete one, absence means nothing.\n */\n isComplete: boolean;\n}\n\n/**\n * Search conditional orders at the TP/SL handler.\n *\n * Hits `POST /api/v5/search/`. Unlike {@link getQuoteTpSl}, which reads one\n * quote, this returns every matching order in a single request — so a merged\n * position's legs cost one call rather than one call per leg.\n *\n * Every filter is optional, including `account`. Pass one to read a single\n * account's orders; omit it to read **across accounts**, which is how a pool's\n * order book is read — filter by `symbolId` and\n * `conditionalOrderType: \"send_quote\"` and the rows come back for every trader\n * on that market.\n *\n * Returns the raw rows; framework layers fold them into UI-facing snapshots.\n *\n * @param config - The SDK config.\n * @param parameters - Optional account, filters and paging.\n * @returns The page's rows, the handler's count, and whether the page is complete.\n *\n * @throws {SymmError} when the chain has no `tpsl` config.\n * @throws {SymmApiError} when the HTTP request fails.\n *\n * @example\n * ```ts\n * // One account's live legs.\n * const { orders } = await searchTpSlOrders(config, { account: virtualAccount });\n *\n * // A pool's pending trigger-to-open orders, across every trader.\n * const book = await searchTpSlOrders(config, {\n * symbolId,\n * conditionalOrderType: TpSlSearchOrderType.SEND_QUOTE,\n * });\n * ```\n */\nexport async function searchTpSlOrders(\n config: Config,\n parameters: SearchTpSlOrdersParameters,\n): Promise<SearchTpSlOrdersReturnType> {\n const tpsl = resolveTpSlConfig(config, parameters.chainId);\n const size = parameters.size ?? DEFAULT_SEARCH_SIZE;\n const body: ConditionalOrderSearchRequestSchemaV3 = {\n /**\n * Omitted entirely when absent rather than sent as `undefined`: the handler\n * treats a present-but-empty filter differently from a missing one.\n */\n ...(parameters.account === undefined ? {} : { party_a_address: parameters.account }),\n state: [...(parameters.state ?? TPSL_LIVE_ORDER_STATES)],\n start: parameters.start ?? 0,\n size,\n };\n if (parameters.symbolId !== undefined) body.symbol_id = parameters.symbolId;\n if (parameters.conditionalOrderType !== undefined) {\n /** Same string values as the generated enum; cast at the wire boundary so the generated type stays internal. */\n body.conditional_order_type = parameters.conditionalOrderType as unknown as ConditionalOrderType;\n }\n if (parameters.conditionalPriceType !== undefined) body.conditional_price_type = parameters.conditionalPriceType;\n\n try {\n const response = await searchConditionalOrdersV5ApiV5SearchPost(body, {\n baseURL: tpsl.url,\n headers: { \"App-Name\": tpsl.appName, \"Content-Type\": \"application/json\", Accept: \"application/json\" },\n ...(parameters.timeoutMs === undefined ? {} : { timeout: parameters.timeoutMs }),\n });\n return toSearchResult(response.data, size);\n } catch (err) {\n return rethrowTpSlError(err, { code: \"SEARCH_TPSL_FAILED\", baseURL: tpsl.url });\n }\n}\n\n/**\n * Normalize the response body.\n *\n * The live endpoint answers `{ data, count }`, but its sibling `GET` returns a\n * bare array against the same spec, so both shapes are accepted rather than\n * assumed — reading the wrong one would silently yield an empty page, which a\n * caller cannot distinguish from \"this account has no orders\".\n */\nfunction toSearchResult(body: unknown, size: number): SearchTpSlOrdersReturnType {\n const orders = (Array.isArray(body) ? body : ((body as { data?: unknown })?.data ?? [])) as QuoteTpSlRow[];\n const reported = Array.isArray(body) ? undefined : (body as { count?: unknown })?.count;\n return {\n orders,\n count: typeof reported === \"number\" ? reported : orders.length,\n isComplete: orders.length < size,\n };\n}\n"],"mappings":";;;;AAuBA,IAAa,IAAyB;CACpC,EAAuB;CACvB,EAAuB;CACvB,EAAuB;CACvB,EAAuB;AACzB,GAGM,IAAsB;AAgG5B,eAAsB,EACpB,GACA,GACqC;CACrC,IAAM,IAAO,EAAkB,GAAQ,EAAW,OAAO,GACnD,IAAO,EAAW,QAAQ,GAC1B,IAA8C;EAKlD,GAAI,EAAW,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB,EAAW,QAAQ;EAClF,OAAO,CAAC,GAAI,EAAW,SAAS,CAAuB;EACvD,OAAO,EAAW,SAAS;EAC3B;CACF;CAMA,AALI,EAAW,aAAa,KAAA,MAAW,EAAK,YAAY,EAAW,WAC/D,EAAW,yBAAyB,KAAA,MAEtC,EAAK,yBAAyB,EAAW,uBAEvC,EAAW,yBAAyB,KAAA,MAAW,EAAK,yBAAyB,EAAW;CAE5F,IAAI;EAMF,OAAO,GAAe,MALC,EAAyC,GAAM;GACpE,SAAS,EAAK;GACd,SAAS;IAAE,YAAY,EAAK;IAAS,gBAAgB;IAAoB,QAAQ;GAAmB;GACpG,GAAI,EAAW,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,EAAW,UAAU;EAChF,CAAC,GAC8B,MAAM,CAAI;CAC3C,SAAS,GAAK;EACZ,OAAO,EAAiB,GAAK;GAAE,MAAM;GAAsB,SAAS,EAAK;EAAI,CAAC;CAChF;AACF;AAUA,SAAS,EAAe,GAAe,GAA0C;CAC/E,IAAM,IAAU,MAAM,QAAQ,CAAI,IAAI,IAAS,GAA6B,QAAQ,CAAC,GAC/E,IAAW,MAAM,QAAQ,CAAI,IAAI,KAAA,IAAa,GAA8B;CAClF,OAAO;EACL;EACA,OAAO,OAAO,KAAa,WAAW,IAAW,EAAO;EACxD,YAAY,EAAO,SAAS;CAC9B;AACF"}
1
+ {"version":3,"file":"search-tpsl-orders.js","names":[],"sources":["../../../src/tpsl/search-tpsl-orders/search-tpsl-orders.ts"],"sourcesContent":["import type { Address } from \"viem\";\nimport type { Config } from \"../../core/config\";\nimport { SymmError } from \"../../shared/errors/symm-error\";\nimport type { ChainIdParameter, Compute } from \"../../shared/types/properties\";\nimport type { QuoteTpSlRow } from \"../get-quote-tpsl\";\nimport { rethrowTpSlError } from \"../internal/axios\";\nimport { resolveTpSlConfig } from \"../internal/resolve-tpsl-config\";\nimport { TpSlSearchOrderType } from \"../types\";\nimport {\n ConditionalOrdersState,\n searchConditionalOrdersV5ApiV5SearchPost,\n type ConditionalOrderSearchRequestSchemaV3,\n type ConditionalOrderType,\n type PriceActionType,\n} from \"../types/generated/tpsl-handler\";\n\n/**\n * The row states that represent an order the handler still holds.\n *\n * Exactly the set {@link QuoteTpSlRow} consumers treat as actionable —\n * `canceled` and `killed` are terminal and carry no live order. Passing this as\n * the search filter keeps \"absent from the result\" equivalent to \"no live\n * order\", which is what makes a cancel confirmable from a search response.\n */\nexport const TPSL_LIVE_ORDER_STATES = [\n ConditionalOrdersState.pending,\n ConditionalOrdersState.new,\n ConditionalOrdersState.triggered,\n ConditionalOrdersState.triggered_pending,\n] as const;\n\n/** Default page size. The handler's own default is 100; a position's legs fit well inside this. */\nconst DEFAULT_SEARCH_SIZE = 200;\n\n/** Parameters for {@link searchTpSlOrders}. */\nexport type SearchTpSlOrdersParameters = Compute<\n ChainIdParameter & {\n /**\n * Account whose conditional orders to search — the Virtual Account that\n * owns them, which is what the handler stores as `party_a_address`.\n *\n * **Omit to search across every account.** The handler treats the field as\n * an optional filter, so leaving it out returns all matching orders — which\n * is how a pool's own order book is read (`symbolId` + `conditionalOrderType`,\n * no account). Verified against the live handler.\n */\n account?: Address;\n /** Row states to include. Defaults to {@link TPSL_LIVE_ORDER_STATES}. */\n state?: readonly QuoteTpSlRowStateFilter[];\n /** Restrict to one market. */\n symbolId?: number;\n /** Restrict to one side. */\n conditionalOrderType?: TpSlSearchOrderType;\n /** Restrict to one trigger-price source. */\n conditionalPriceType?: PriceActionType;\n /** Page offset. Defaults to `0`. */\n start?: number;\n /** Page size. Defaults to `200`. */\n size?: number;\n /**\n * Abort the request after this many milliseconds. Unset means axios's\n * default of \"wait forever\" — pass one when the call is on a repeating\n * schedule, so a stalled connection fails the attempt instead of hanging it.\n */\n timeoutMs?: number;\n }\n>;\n\n/** A state accepted by the search filter. */\ntype QuoteTpSlRowStateFilter = ConditionalOrderSearchRequestSchemaV3[\"state\"] extends\n | (infer TState)[]\n | null\n | undefined\n ? TState\n : never;\n\n/** Return type of {@link searchTpSlOrders}. */\nexport interface SearchTpSlOrdersReturnType {\n /** The page's rows, in handler order. */\n orders: QuoteTpSlRow[];\n /** The handler's reported total for the filter. Advisory — see `isComplete`. */\n count: number;\n /**\n * `true` when this page provably exhausted the filtered result set, i.e.\n * fewer rows came back than were asked for.\n *\n * Derived from the page length rather than from `count`, whose meaning on\n * this endpoint is unverified and whose sibling `GET` already contradicts its\n * own spec. A caller may only read \"this order is absent, therefore it is\n * gone\" from a complete page; on an incomplete one, absence means nothing.\n */\n isComplete: boolean;\n}\n\n/**\n * Search conditional orders at the TP/SL handler.\n *\n * Hits `POST /api/v5/search/`. Unlike {@link getQuoteTpSl}, which reads one\n * quote, this returns every matching order in a single request — so a merged\n * position's legs cost one call rather than one call per leg.\n *\n * Every filter is optional, including `account`. Pass one to read a single\n * account's orders; omit it to read **across accounts**, which is how a pool's\n * order book is read — filter by `symbolId` and\n * `conditionalOrderType: \"send_quote\"` and the rows come back for every trader\n * on that market.\n *\n * Returns the raw rows; framework layers fold them into UI-facing snapshots.\n *\n * @param config - The SDK config.\n * @param parameters - Optional account, filters and paging.\n * @returns The page's rows, the handler's count, and whether the page is complete.\n *\n * @throws {SymmError} when the chain has no `tpsl` config.\n * @throws {SymmApiError} when the HTTP request fails.\n *\n * @example\n * ```ts\n * // One account's live legs.\n * const { orders } = await searchTpSlOrders(config, { account: virtualAccount });\n *\n * // A pool's pending trigger-to-open orders, across every trader.\n * const book = await searchTpSlOrders(config, {\n * symbolId,\n * conditionalOrderType: TpSlSearchOrderType.SEND_QUOTE,\n * });\n * ```\n */\nexport async function searchTpSlOrders(\n config: Config,\n parameters: SearchTpSlOrdersParameters,\n): Promise<SearchTpSlOrdersReturnType> {\n const tpsl = resolveTpSlConfig(config, parameters.chainId);\n const size = parameters.size ?? DEFAULT_SEARCH_SIZE;\n const body: ConditionalOrderSearchRequestSchemaV3 = {\n /**\n * Omitted entirely when absent rather than sent as `undefined`: the handler\n * treats a present-but-empty filter differently from a missing one.\n */\n ...(parameters.account === undefined ? {} : { party_a_address: parameters.account }),\n state: [...(parameters.state ?? TPSL_LIVE_ORDER_STATES)],\n start: parameters.start ?? 0,\n size,\n };\n if (parameters.symbolId !== undefined) body.symbol_id = parameters.symbolId;\n if (parameters.conditionalOrderType !== undefined) {\n /** Same string values as the generated enum; cast at the wire boundary so the generated type stays internal. */\n body.conditional_order_type = parameters.conditionalOrderType as unknown as ConditionalOrderType;\n }\n if (parameters.conditionalPriceType !== undefined) body.conditional_price_type = parameters.conditionalPriceType;\n\n try {\n const response = await searchConditionalOrdersV5ApiV5SearchPost(body, {\n baseURL: tpsl.url,\n headers: { \"App-Name\": tpsl.appName, \"Content-Type\": \"application/json\", Accept: \"application/json\" },\n ...(parameters.timeoutMs === undefined ? {} : { timeout: parameters.timeoutMs }),\n });\n return toSearchResult(response.data, size);\n } catch (err) {\n return rethrowTpSlError(err, { code: \"SEARCH_TPSL_FAILED\", baseURL: tpsl.url });\n }\n}\n\n/**\n * Normalize the response body.\n *\n * The live endpoint answers `{ data, count }`, but its sibling `GET` returns a\n * bare array against the same spec, so both shapes are accepted rather than\n * assumed — reading the wrong one would silently yield an empty page, which a\n * caller cannot distinguish from \"this account has no orders\".\n */\nfunction toSearchResult(body: unknown, size: number): SearchTpSlOrdersReturnType {\n const rows: unknown = Array.isArray(body) ? body : (body as { data?: unknown })?.data;\n if (!Array.isArray(rows)) {\n throw new SymmError(\"api\", \"SEARCH_TPSL_INVALID_RESPONSE\", \"Handler returned an invalid conditional-order page.\");\n }\n const orders = rows as QuoteTpSlRow[];\n const reported = Array.isArray(body) ? undefined : (body as { count?: unknown })?.count;\n return {\n orders,\n count: typeof reported === \"number\" ? reported : orders.length,\n isComplete: orders.length < size,\n };\n}\n"],"mappings":";;;;;AAwBA,IAAa,IAAyB;CACpC,EAAuB;CACvB,EAAuB;CACvB,EAAuB;CACvB,EAAuB;AACzB,GAGM,IAAsB;AAgG5B,eAAsB,EACpB,GACA,GACqC;CACrC,IAAM,IAAO,EAAkB,GAAQ,EAAW,OAAO,GACnD,IAAO,EAAW,QAAQ,GAC1B,IAA8C;EAKlD,GAAI,EAAW,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB,EAAW,QAAQ;EAClF,OAAO,CAAC,GAAI,EAAW,SAAS,CAAuB;EACvD,OAAO,EAAW,SAAS;EAC3B;CACF;CAMA,AALI,EAAW,aAAa,KAAA,MAAW,EAAK,YAAY,EAAW,WAC/D,EAAW,yBAAyB,KAAA,MAEtC,EAAK,yBAAyB,EAAW,uBAEvC,EAAW,yBAAyB,KAAA,MAAW,EAAK,yBAAyB,EAAW;CAE5F,IAAI;EAMF,OAAO,GAAe,MALC,EAAyC,GAAM;GACpE,SAAS,EAAK;GACd,SAAS;IAAE,YAAY,EAAK;IAAS,gBAAgB;IAAoB,QAAQ;GAAmB;GACpG,GAAI,EAAW,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,EAAW,UAAU;EAChF,CAAC,GAC8B,MAAM,CAAI;CAC3C,SAAS,GAAK;EACZ,OAAO,EAAiB,GAAK;GAAE,MAAM;GAAsB,SAAS,EAAK;EAAI,CAAC;CAChF;AACF;AAUA,SAAS,EAAe,GAAe,GAA0C;CAC/E,IAAM,IAAgB,MAAM,QAAQ,CAAI,IAAI,IAAQ,GAA6B;CACjF,IAAI,CAAC,MAAM,QAAQ,CAAI,GACrB,MAAM,IAAI,EAAU,OAAO,gCAAgC,qDAAqD;CAElH,IAAM,IAAS,GACT,IAAW,MAAM,QAAQ,CAAI,IAAI,KAAA,IAAa,GAA8B;CAClF,OAAO;EACL;EACA,OAAO,OAAO,KAAa,WAAW,IAAW,EAAO;EACxD,YAAY,EAAO,SAAS;CAC9B;AACF"}
@@ -14,7 +14,7 @@ export declare function buildConditionalOrderLeg(parameters: {
14
14
  /** Trigger price (decimal string, rounded to market precision). */
15
15
  conditionalPrice: string;
16
16
  priceType: TpSlPriceType;
17
- /** Defaults to `TPSL_LEG_ORDER_TYPE_MARKET`. */
17
+ /** Defaults to `OrderType.MARKET_BEST_EFFORT` (2), a close-only order type. */
18
18
  orderType?: number;
19
19
  }): TpSlConditionalOrderLeg;
20
20
  //# sourceMappingURL=build-conditional-order-leg.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-conditional-order-leg.d.ts","sourceRoot":"","sources":["../../../src/tpsl/set-quote-tpsl/build-conditional-order-leg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvE,yCAAyC;AACzC,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE;IACnD,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,aAAa,CAAC;IACzB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,uBAAuB,CAQ1B"}
1
+ {"version":3,"file":"build-conditional-order-leg.d.ts","sourceRoot":"","sources":["../../../src/tpsl/set-quote-tpsl/build-conditional-order-leg.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvE,yCAAyC;AACzC,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE;IACnD,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,aAAa,CAAC;IACzB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,uBAAuB,CAQ1B"}
@@ -1,13 +1,15 @@
1
- function e(e) {
1
+ import { OrderType as e } from "../../symmio-contracts/symmio/types.js";
2
+ //#region src/tpsl/set-quote-tpsl/build-conditional-order-leg.ts
3
+ function t(t) {
2
4
  return {
3
- quantity: e.quantity,
4
- price: e.price,
5
- orderType: e.orderType ?? 1,
6
- conditionalPrice: e.conditionalPrice,
7
- conditionalPriceType: e.priceType === "lastPrice" ? "last_close" : "market"
5
+ quantity: t.quantity,
6
+ price: t.price,
7
+ orderType: t.orderType ?? e.MARKET_BEST_EFFORT,
8
+ conditionalPrice: t.conditionalPrice,
9
+ conditionalPriceType: t.priceType === "lastPrice" ? "last_close" : "market"
8
10
  };
9
11
  }
10
12
  //#endregion
11
- export { e as buildConditionalOrderLeg };
13
+ export { t as buildConditionalOrderLeg };
12
14
 
13
15
  //# sourceMappingURL=build-conditional-order-leg.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-conditional-order-leg.js","names":[],"sources":["../../../src/tpsl/set-quote-tpsl/build-conditional-order-leg.ts"],"sourcesContent":["import type { TpSlConditionalOrderLeg, TpSlPriceType } from \"../types\";\n\n/** `order_type` field — `1` = market. */\nexport const TPSL_LEG_ORDER_TYPE_MARKET = 1;\n\n/**\n * Build one conditional-order leg (TP or SL). Mirrors the reference frontend's\n * `buildConditionalOrderLeg` exactly so the signed payload matches what the\n * handler expects.\n */\nexport function buildConditionalOrderLeg(parameters: {\n /** Quote quantity (decimal string). */\n quantity: string;\n /** Slippage-shifted \"opened\" price (decimal string, rounded to market precision). */\n price: string;\n /** Trigger price (decimal string, rounded to market precision). */\n conditionalPrice: string;\n priceType: TpSlPriceType;\n /** Defaults to `TPSL_LEG_ORDER_TYPE_MARKET`. */\n orderType?: number;\n}): TpSlConditionalOrderLeg {\n return {\n quantity: parameters.quantity,\n price: parameters.price,\n orderType: parameters.orderType ?? TPSL_LEG_ORDER_TYPE_MARKET,\n conditionalPrice: parameters.conditionalPrice,\n conditionalPriceType: parameters.priceType === \"lastPrice\" ? \"last_close\" : \"market\",\n };\n}\n"],"mappings":"AAUA,SAAgB,EAAyB,GAUb;CAC1B,OAAO;EACL,UAAU,EAAW;EACrB,OAAO,EAAW;EAClB,WAAW,EAAW,aAAA;EACtB,kBAAkB,EAAW;EAC7B,sBAAsB,EAAW,cAAc,cAAc,eAAe;CAC9E;AACF"}
1
+ {"version":3,"file":"build-conditional-order-leg.js","names":[],"sources":["../../../src/tpsl/set-quote-tpsl/build-conditional-order-leg.ts"],"sourcesContent":["import { OrderType } from \"../../symmio-contracts/symmio/types\";\nimport type { TpSlConditionalOrderLeg, TpSlPriceType } from \"../types\";\n\n/** `order_type` field — `1` = market. */\nexport const TPSL_LEG_ORDER_TYPE_MARKET = 1;\n\n/**\n * Build one conditional-order leg (TP or SL). Mirrors the reference frontend's\n * `buildConditionalOrderLeg` exactly so the signed payload matches what the\n * handler expects.\n */\nexport function buildConditionalOrderLeg(parameters: {\n /** Quote quantity (decimal string). */\n quantity: string;\n /** Slippage-shifted \"opened\" price (decimal string, rounded to market precision). */\n price: string;\n /** Trigger price (decimal string, rounded to market precision). */\n conditionalPrice: string;\n priceType: TpSlPriceType;\n /** Defaults to `OrderType.MARKET_BEST_EFFORT` (2), a close-only order type. */\n orderType?: number;\n}): TpSlConditionalOrderLeg {\n return {\n quantity: parameters.quantity,\n price: parameters.price,\n orderType: parameters.orderType ?? OrderType.MARKET_BEST_EFFORT,\n conditionalPrice: parameters.conditionalPrice,\n conditionalPriceType: parameters.priceType === \"lastPrice\" ? \"last_close\" : \"market\",\n };\n}\n"],"mappings":";;AAWA,SAAgB,EAAyB,GAUb;CAC1B,OAAO;EACL,UAAU,EAAW;EACrB,OAAO,EAAW;EAClB,WAAW,EAAW,aAAa,EAAU;EAC7C,kBAAkB,EAAW;EAC7B,sBAAsB,EAAW,cAAc,cAAc,eAAe;CAC9E;AACF"}
@@ -3,12 +3,16 @@ import { SetQuoteTpSlParameters } from './set-quote-tpsl.js';
3
3
  /**
4
4
  * Build TanStack Mutation options for {@link setQuoteTpSl}.
5
5
  *
6
+ * Automatic retries are disabled: a failed response may follow an accepted write.
7
+ * Reconcile state before explicitly submitting again.
8
+ *
6
9
  * @example
7
10
  * ```ts
8
11
  * useMutation(setQuoteTpSlMutationOptions(config));
9
12
  * ```
10
13
  */
11
14
  export declare function setQuoteTpSlMutationOptions(config: Config): {
15
+ retry: boolean;
12
16
  mutationKey: readonly ["setQuoteTpSl"];
13
17
  mutationFn: (variables: SetQuoteTpSlParameters) => Promise<import('./set-quote-tpsl.js').SetQuoteTpSlReturnType>;
14
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/tpsl/set-quote-tpsl/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAgB,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM;;4BAG9B,sBAAsB;EAEjD"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/tpsl/set-quote-tpsl/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAgB,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM;;;4BAI9B,sBAAsB;EAEjD"}
@@ -2,6 +2,7 @@ import { setQuoteTpSl as e } from "./set-quote-tpsl.js";
2
2
  //#region src/tpsl/set-quote-tpsl/query.ts
3
3
  function t(t) {
4
4
  return {
5
+ retry: !1,
5
6
  mutationKey: ["setQuoteTpSl"],
6
7
  mutationFn: (n) => e(t, n)
7
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","names":[],"sources":["../../../src/tpsl/set-quote-tpsl/query.ts"],"sourcesContent":["import type { Config } from \"../../core/config\";\nimport { setQuoteTpSl, type SetQuoteTpSlParameters } from \"./set-quote-tpsl\";\n\n/**\n * Build TanStack Mutation options for {@link setQuoteTpSl}.\n *\n * @example\n * ```ts\n * useMutation(setQuoteTpSlMutationOptions(config));\n * ```\n */\nexport function setQuoteTpSlMutationOptions(config: Config) {\n return {\n mutationKey: [\"setQuoteTpSl\"] as const,\n mutationFn: (variables: SetQuoteTpSlParameters) => setQuoteTpSl(config, variables),\n };\n}\n"],"mappings":";;AAWA,SAAgB,EAA4B,GAAgB;CAC1D,OAAO;EACL,aAAa,CAAC,cAAc;EAC5B,aAAa,MAAsC,EAAa,GAAQ,CAAS;CACnF;AACF"}
1
+ {"version":3,"file":"query.js","names":[],"sources":["../../../src/tpsl/set-quote-tpsl/query.ts"],"sourcesContent":["import type { Config } from \"../../core/config\";\nimport { setQuoteTpSl, type SetQuoteTpSlParameters } from \"./set-quote-tpsl\";\n\n/**\n * Build TanStack Mutation options for {@link setQuoteTpSl}.\n *\n * Automatic retries are disabled: a failed response may follow an accepted write.\n * Reconcile state before explicitly submitting again.\n *\n * @example\n * ```ts\n * useMutation(setQuoteTpSlMutationOptions(config));\n * ```\n */\nexport function setQuoteTpSlMutationOptions(config: Config) {\n return {\n retry: false,\n mutationKey: [\"setQuoteTpSl\"] as const,\n mutationFn: (variables: SetQuoteTpSlParameters) => setQuoteTpSl(config, variables),\n };\n}\n"],"mappings":";;AAcA,SAAgB,EAA4B,GAAgB;CAC1D,OAAO;EACL,OAAO;EACP,aAAa,CAAC,cAAc;EAC5B,aAAa,MAAsC,EAAa,GAAQ,CAAS;CACnF;AACF"}
@@ -62,9 +62,9 @@ export interface SetQuoteTpSlReturnType {
62
62
  * 4. Sign it with the session-key wallet client (`config.getWalletClient`).
63
63
  * 5. POST `{ typedData, signature, signer }` to the handler.
64
64
  *
65
- * The handler returns 200 on accept but the order is only "confirmed" once
66
- * the WebSocket reports `state: "new"`; callers should subscribe via
67
- * `watchTpSlNotifications` and reconcile.
65
+ * An explicit successful response establishes acceptance. Subscribe with
66
+ * `watchTpSlNotifications` for refresh hints and reconcile live order state;
67
+ * notifications do not correlate successive mutations or supply order versions.
68
68
  *
69
69
  * @throws {SymmError} when the chain has no `tpsl` config, both `tp` and `sl`
70
70
  * are omitted, or signing fails.
@@ -1 +1 @@
1
- {"version":3,"file":"set-quote-tpsl.d.ts","sourceRoot":"","sources":["../../../src/tpsl/set-quote-tpsl/set-quote-tpsl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAKnE,OAAO,KAAK,EAA2B,aAAa,EAAE,MAAM,UAAU,CAAC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racts/symmio/types.js";
3
3
  import { rethrowTpSlError as n } from "../internal/axios.js";
4
4
  import { resolveTpSlConfig as r } from "../internal/resolve-tpsl-config.js";
5
5
  import { conditionalOrderRequestV5ApiV5Post as i } from "../types/generated/tpsl-handler.js";
6
- import { buildConditionalOrderMessage as a } from "./build-conditional-order-message.js";
7
- import { signTpSlRequest as o } from "./sign-tpsl-request.js";
8
- import { buildConditionalOrderLeg as s } from "./build-conditional-order-leg.js";
9
- import { getTpSlSigningSpec as c } from "../signing-spec/get-tpsl-signing-spec.js";
10
- import { priceSlippageCalculation as l } from "../slippage.js";
11
- import { toDecimal as u } from "@symmio/utils/decimal";
6
+ import { assertTpSlAcceptance as a } from "../assert-tpsl-acceptance.js";
7
+ import { buildConditionalOrderMessage as o } from "./build-conditional-order-message.js";
8
+ import { signTpSlRequest as s } from "./sign-tpsl-request.js";
9
+ import { buildConditionalOrderLeg as c } from "./build-conditional-order-leg.js";
10
+ import { getTpSlSigningSpec as l } from "../signing-spec/get-tpsl-signing-spec.js";
11
+ import { priceSlippageCalculation as u } from "../slippage.js";
12
+ import { toDecimal as d } from "@symmio/utils/decimal";
12
13
  //#region src/tpsl/set-quote-tpsl/set-quote-tpsl.ts
13
- async function d(d, f) {
14
- if (!f.tp && !f.sl) throw new e("validation", "SET_TPSL_NOTHING_TO_SUBMIT", "setQuoteTpSl: at least one of `tp` or `sl` must be provided.");
15
- let p = d.getChainConfig(f.chainId), m = r(d, f.chainId), h = f.affiliate ?? p.addresses.affiliatesAddress, g = f.slippage ?? 90, _ = await c(d, { chainId: f.chainId }), v = f.tp ? s({
16
- quantity: f.quantity,
17
- price: l(f.tp.triggerPrice, g, f.positionType, f.pricePrecision),
18
- conditionalPrice: u(f.tp.triggerPrice).toFixed(f.pricePrecision),
19
- priceType: f.tp.priceType
20
- }) : null, y = f.sl ? s({
21
- quantity: f.quantity,
22
- price: l(f.sl.triggerPrice, g, f.positionType, f.pricePrecision),
23
- conditionalPrice: u(f.sl.triggerPrice).toFixed(f.pricePrecision),
24
- priceType: f.sl.priceType
25
- }) : null, b = await o({
26
- signingSpec: _,
27
- message: a({
28
- virtualAccount: f.virtualAccount,
29
- subAccount: f.subAccount,
30
- quoteId: Number(f.quoteId),
31
- symbolId: Number(f.symbolId),
32
- positionType: f.positionType === t.LONG ? 0 : 1,
33
- affiliate: h,
34
- takeProfit: v,
35
- stopLoss: y
14
+ async function f(f, p) {
15
+ if (!p.tp && !p.sl) throw new e("validation", "SET_TPSL_NOTHING_TO_SUBMIT", "setQuoteTpSl: at least one of `tp` or `sl` must be provided.");
16
+ if (!Number.isSafeInteger(Number(p.quoteId)) || p.quoteId === 0n || !Number.isSafeInteger(Number(p.symbolId)) || p.symbolId <= 0n) throw new e("validation", "SET_TPSL_INVALID_ID", "TP/SL quote and symbol IDs must be safe nonzero integers.");
17
+ let m = f.getChainConfig(p.chainId), h = r(f, p.chainId), g = p.affiliate ?? m.addresses.affiliatesAddress, _ = p.slippage ?? 90, v = await l(f, { chainId: p.chainId }), y = p.tp ? c({
18
+ quantity: p.quantity,
19
+ price: u(p.tp.triggerPrice, _, p.positionType, p.pricePrecision),
20
+ conditionalPrice: d(p.tp.triggerPrice).toFixed(p.pricePrecision),
21
+ priceType: p.tp.priceType
22
+ }) : null, b = p.sl ? c({
23
+ quantity: p.quantity,
24
+ price: u(p.sl.triggerPrice, _, p.positionType, p.pricePrecision),
25
+ conditionalPrice: d(p.sl.triggerPrice).toFixed(p.pricePrecision),
26
+ priceType: p.sl.priceType
27
+ }) : null, x = await s({
28
+ signingSpec: v,
29
+ message: o({
30
+ virtualAccount: p.virtualAccount,
31
+ subAccount: p.subAccount,
32
+ quoteId: Number(p.quoteId),
33
+ symbolId: Number(p.symbolId),
34
+ positionType: p.positionType === t.LONG ? 0 : 1,
35
+ affiliate: g,
36
+ takeProfit: y,
37
+ stopLoss: b
36
38
  }),
37
- walletClient: await d.getWalletClient({
38
- chainId: f.chainId,
39
- from: f.from
39
+ walletClient: await f.getWalletClient({
40
+ chainId: p.chainId,
41
+ from: p.from
40
42
  })
41
43
  });
42
44
  try {
43
- let t = (await i(b, {
44
- baseURL: m.url,
45
+ let e = (await i(x, {
46
+ baseURL: h.url,
45
47
  headers: {
46
- "App-Name": m.appName,
48
+ "App-Name": h.appName,
47
49
  "Content-Type": "application/json",
48
50
  Accept: "application/json"
49
51
  }
50
52
  })).data ?? {};
51
- if (!(typeof t.successful == "string" ? t.successful !== "false" : t.successful !== !1)) throw new e("api", "SET_TPSL_REJECTED", t.message ?? "Handler rejected TP/SL submission.");
52
- let n = t;
53
+ a(e, "SET");
54
+ let t = e;
53
55
  return {
54
56
  success: !0,
55
- cohQuoteId: n.coh_quote_id ?? n.cohQuoteId
57
+ cohQuoteId: t.coh_quote_id ?? t.cohQuoteId
56
58
  };
57
59
  } catch (e) {
58
60
  return n(e, {
59
61
  code: "SET_TPSL_FAILED",
60
- baseURL: m.url
62
+ baseURL: h.url
61
63
  });
62
64
  }
63
65
  }
64
66
  //#endregion
65
- export { d as setQuoteTpSl };
67
+ export { f as setQuoteTpSl };
66
68
 
67
69
  //# sourceMappingURL=set-quote-tpsl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-quote-tpsl.js","names":[],"sources":["../../../src/tpsl/set-quote-tpsl/set-quote-tpsl.ts"],"sourcesContent":["import { toDecimal } from \"@symmio/utils/decimal\";\nimport type { Address } from \"viem\";\nimport type { Config } from \"../../core/config\";\nimport { SymmError } from \"../../shared/errors/symm-error\";\nimport type { Compute, WriteSolverParameter } from \"../../shared/types/properties\";\nimport { PositionType } from \"../../symmio-contracts/symmio/types\";\nimport { rethrowTpSlError } from \"../internal/axios\";\nimport { resolveTpSlConfig } from \"../internal/resolve-tpsl-config\";\nimport { getTpSlSigningSpec } from \"../signing-spec/get-tpsl-signing-spec\";\nimport { DEFAULT_TPSL_SLIPPAGE_LOWCAPS, priceSlippageCalculation } from \"../slippage\";\nimport type { TpSlConditionalOrderLeg, TpSlPriceType } from \"../types\";\nimport { conditionalOrderRequestV5ApiV5Post, type ConditionalOrderOperationV5 } from \"../types/generated/tpsl-handler\";\nimport { buildConditionalOrderLeg } from \"./build-conditional-order-leg\";\nimport { buildConditionalOrderMessage } from \"./build-conditional-order-message\";\nimport { signTpSlRequest } from \"./sign-tpsl-request\";\n\n/**\n * One side (TP or SL) of a {@link setQuoteTpSl} call.\n */\nexport interface SetTpSlSide {\n /** Trigger price (decimal string). */\n triggerPrice: string;\n /** Mark vs last-close. */\n priceType: TpSlPriceType;\n}\n\n/**\n * Parameters for {@link setQuoteTpSl}.\n */\nexport type SetQuoteTpSlParameters = Compute<\n WriteSolverParameter & {\n /** On-chain quote id. */\n quoteId: bigint;\n /** PartyA (the VA address) that owns the quote. */\n virtualAccount: Address;\n /** SubAccount that owns the VA. */\n subAccount: Address;\n /** Solver market id. */\n symbolId: bigint;\n /** Quote direction. */\n positionType: PositionType;\n /** Quote quantity (decimal string). */\n quantity: string;\n /** Market price precision (rounds prices to N decimals). */\n pricePrecision: number;\n /**\n * Affiliate to bind to the order. Defaults to\n * `chainConfig.addresses.affiliatesAddress`.\n */\n affiliate?: Address;\n /**\n * Slippage percent applied when deriving each leg's `price`. Defaults to\n * {@link DEFAULT_TPSL_SLIPPAGE_LOWCAPS}.\n */\n slippage?: number;\n /** Take-profit side. Omit to skip TP. */\n tp?: SetTpSlSide;\n /** Stop-loss side. Omit to skip SL. */\n sl?: SetTpSlSide;\n }\n>;\n\n/** Return type of {@link setQuoteTpSl}. */\nexport interface SetQuoteTpSlReturnType {\n success: true;\n /** Handler-issued conditional-order id (when reported on the response). */\n cohQuoteId?: string;\n}\n\n/**\n * Submit a TP and/or SL order to the handler.\n *\n * Steps:\n * 1. Resolve the TP/SL handler URL + signing spec for the chain.\n * 2. Round trigger prices and compute slippage-shifted \"opened\" prices via\n * {@link priceSlippageCalculation}.\n * 3. Build a {@link TpSlConditionalOrderMessage} with non-null legs only.\n * 4. Sign it with the session-key wallet client (`config.getWalletClient`).\n * 5. POST `{ typedData, signature, signer }` to the handler.\n *\n * The handler returns 200 on accept but the order is only \"confirmed\" once\n * the WebSocket reports `state: \"new\"`; callers should subscribe via\n * `watchTpSlNotifications` and reconcile.\n *\n * @throws {SymmError} when the chain has no `tpsl` config, both `tp` and `sl`\n * are omitted, or signing fails.\n * @throws {SymmApiError} when the handler request fails.\n */\nexport async function setQuoteTpSl(\n config: Config,\n parameters: SetQuoteTpSlParameters,\n): Promise<SetQuoteTpSlReturnType> {\n if (!parameters.tp && !parameters.sl) {\n throw new SymmError(\n \"validation\",\n \"SET_TPSL_NOTHING_TO_SUBMIT\",\n \"setQuoteTpSl: at least one of `tp` or `sl` must be provided.\",\n );\n }\n\n const chainConfig = config.getChainConfig(parameters.chainId);\n const tpsl = resolveTpSlConfig(config, parameters.chainId);\n const affiliate = parameters.affiliate ?? chainConfig.addresses.affiliatesAddress;\n const slippage = parameters.slippage ?? DEFAULT_TPSL_SLIPPAGE_LOWCAPS;\n\n const signingSpec = await getTpSlSigningSpec(config, { chainId: parameters.chainId });\n\n const tpLeg: TpSlConditionalOrderLeg | null = parameters.tp\n ? buildConditionalOrderLeg({\n quantity: parameters.quantity,\n price: priceSlippageCalculation(\n parameters.tp.triggerPrice,\n slippage,\n parameters.positionType,\n parameters.pricePrecision,\n ),\n conditionalPrice: toDecimal(parameters.tp.triggerPrice).toFixed(parameters.pricePrecision),\n priceType: parameters.tp.priceType,\n })\n : null;\n\n const slLeg: TpSlConditionalOrderLeg | null = parameters.sl\n ? buildConditionalOrderLeg({\n quantity: parameters.quantity,\n price: priceSlippageCalculation(\n parameters.sl.triggerPrice,\n slippage,\n parameters.positionType,\n parameters.pricePrecision,\n ),\n conditionalPrice: toDecimal(parameters.sl.triggerPrice).toFixed(parameters.pricePrecision),\n priceType: parameters.sl.priceType,\n })\n : null;\n\n const message = buildConditionalOrderMessage({\n virtualAccount: parameters.virtualAccount,\n subAccount: parameters.subAccount,\n quoteId: Number(parameters.quoteId),\n symbolId: Number(parameters.symbolId),\n positionType: parameters.positionType === PositionType.LONG ? 0 : 1,\n affiliate,\n takeProfit: tpLeg,\n stopLoss: slLeg,\n });\n\n const walletClient = await config.getWalletClient({ chainId: parameters.chainId, from: parameters.from });\n const signed = await signTpSlRequest({ signingSpec, message, walletClient });\n\n try {\n const response = await conditionalOrderRequestV5ApiV5Post(signed as unknown as ConditionalOrderOperationV5, {\n baseURL: tpsl.url,\n headers: { \"App-Name\": tpsl.appName, \"Content-Type\": \"application/json\", Accept: \"application/json\" },\n });\n const body = response.data ?? {};\n const successful = typeof body.successful === \"string\" ? body.successful !== \"false\" : body.successful !== false;\n if (!successful) {\n throw new SymmError(\"api\", \"SET_TPSL_REJECTED\", body.message ?? \"Handler rejected TP/SL submission.\");\n }\n const extra = body as { coh_quote_id?: string; cohQuoteId?: string };\n return { success: true, cohQuoteId: extra.coh_quote_id ?? extra.cohQuoteId };\n } catch (err) {\n return rethrowTpSlError(err, { code: \"SET_TPSL_FAILED\", baseURL: tpsl.url });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAwFA,eAAsB,EACpB,GACA,GACiC;CACjC,IAAI,CAAC,EAAW,MAAM,CAAC,EAAW,IAChC,MAAM,IAAI,EACR,cACA,8BACA,8DACF;CAGF,IAAM,IAAc,EAAO,eAAe,EAAW,OAAO,GACtD,IAAO,EAAkB,GAAQ,EAAW,OAAO,GACnD,IAAY,EAAW,aAAa,EAAY,UAAU,mBAC1D,IAAW,EAAW,YAAA,IAEtB,IAAc,MAAM,EAAmB,GAAQ,EAAE,SAAS,EAAW,QAAQ,CAAC,GAE9E,IAAwC,EAAW,KACrD,EAAyB;EACvB,UAAU,EAAW;EACrB,OAAO,EACL,EAAW,GAAG,cACd,GACA,EAAW,cACX,EAAW,cACb;EACA,kBAAkB,EAAU,EAAW,GAAG,YAAY,EAAE,QAAQ,EAAW,cAAc;EACzF,WAAW,EAAW,GAAG;CAC3B,CAAC,IACD,MAEE,IAAwC,EAAW,KACrD,EAAyB;EACvB,UAAU,EAAW;EACrB,OAAO,EACL,EAAW,GAAG,cACd,GACA,EAAW,cACX,EAAW,cACb;EACA,kBAAkB,EAAU,EAAW,GAAG,YAAY,EAAE,QAAQ,EAAW,cAAc;EACzF,WAAW,EAAW,GAAG;CAC3B,CAAC,IACD,MAcE,IAAS,MAAM,EAAgB;EAAE;EAAa,SAZpC,EAA6B;GAC3C,gBAAgB,EAAW;GAC3B,YAAY,EAAW;GACvB,SAAS,OAAO,EAAW,OAAO;GAClC,UAAU,OAAO,EAAW,QAAQ;GACpC,cAAc,EAAW,iBAAiB,EAAa,OAAO,IAAI;GAClE;GACA,YAAY;GACZ,UAAU;EACZ,CAGoD;EAAS,cAAA,MADlC,EAAO,gBAAgB;GAAE,SAAS,EAAW;GAAS,MAAM,EAAW;EAAK,CAAC;CAC9B,CAAC;CAE3E,IAAI;EAKF,IAAM,KAAO,MAJU,EAAmC,GAAkD;GAC1G,SAAS,EAAK;GACd,SAAS;IAAE,YAAY,EAAK;IAAS,gBAAgB;IAAoB,QAAQ;GAAmB;EACtG,CAAC,GACqB,QAAQ,CAAC;EAE/B,IAAI,EADe,OAAO,EAAK,cAAe,WAAW,EAAK,eAAe,UAAU,EAAK,eAAe,KAEzG,MAAM,IAAI,EAAU,OAAO,qBAAqB,EAAK,WAAW,oCAAoC;EAEtG,IAAM,IAAQ;EACd,OAAO;GAAE,SAAS;GAAM,YAAY,EAAM,gBAAgB,EAAM;EAAW;CAC7E,SAAS,GAAK;EACZ,OAAO,EAAiB,GAAK;GAAE,MAAM;GAAmB,SAAS,EAAK;EAAI,CAAC;CAC7E;AACF"}
1
+ {"version":3,"file":"set-quote-tpsl.js","names":[],"sources":["../../../src/tpsl/set-quote-tpsl/set-quote-tpsl.ts"],"sourcesContent":["import { toDecimal } from \"@symmio/utils/decimal\";\nimport type { Address } from \"viem\";\nimport type { Config } from \"../../core/config\";\nimport { SymmError } from \"../../shared/errors/symm-error\";\nimport type { Compute, WriteSolverParameter } from \"../../shared/types/properties\";\nimport { PositionType } from \"../../symmio-contracts/symmio/types\";\nimport { assertTpSlAcceptance } from \"../assert-tpsl-acceptance\";\nimport { rethrowTpSlError } from \"../internal/axios\";\nimport { resolveTpSlConfig } from \"../internal/resolve-tpsl-config\";\nimport { getTpSlSigningSpec } from \"../signing-spec/get-tpsl-signing-spec\";\nimport { DEFAULT_TPSL_SLIPPAGE_LOWCAPS, priceSlippageCalculation } from \"../slippage\";\nimport type { TpSlConditionalOrderLeg, TpSlPriceType } from \"../types\";\nimport { conditionalOrderRequestV5ApiV5Post, type ConditionalOrderOperationV5 } from \"../types/generated/tpsl-handler\";\nimport { buildConditionalOrderLeg } from \"./build-conditional-order-leg\";\nimport { buildConditionalOrderMessage } from \"./build-conditional-order-message\";\nimport { signTpSlRequest } from \"./sign-tpsl-request\";\n\n/**\n * One side (TP or SL) of a {@link setQuoteTpSl} call.\n */\nexport interface SetTpSlSide {\n /** Trigger price (decimal string). */\n triggerPrice: string;\n /** Mark vs last-close. */\n priceType: TpSlPriceType;\n}\n\n/**\n * Parameters for {@link setQuoteTpSl}.\n */\nexport type SetQuoteTpSlParameters = Compute<\n WriteSolverParameter & {\n /** On-chain quote id. */\n quoteId: bigint;\n /** PartyA (the VA address) that owns the quote. */\n virtualAccount: Address;\n /** SubAccount that owns the VA. */\n subAccount: Address;\n /** Solver market id. */\n symbolId: bigint;\n /** Quote direction. */\n positionType: PositionType;\n /** Quote quantity (decimal string). */\n quantity: string;\n /** Market price precision (rounds prices to N decimals). */\n pricePrecision: number;\n /**\n * Affiliate to bind to the order. Defaults to\n * `chainConfig.addresses.affiliatesAddress`.\n */\n affiliate?: Address;\n /**\n * Slippage percent applied when deriving each leg's `price`. Defaults to\n * {@link DEFAULT_TPSL_SLIPPAGE_LOWCAPS}.\n */\n slippage?: number;\n /** Take-profit side. Omit to skip TP. */\n tp?: SetTpSlSide;\n /** Stop-loss side. Omit to skip SL. */\n sl?: SetTpSlSide;\n }\n>;\n\n/** Return type of {@link setQuoteTpSl}. */\nexport interface SetQuoteTpSlReturnType {\n success: true;\n /** Handler-issued conditional-order id (when reported on the response). */\n cohQuoteId?: string;\n}\n\n/**\n * Submit a TP and/or SL order to the handler.\n *\n * Steps:\n * 1. Resolve the TP/SL handler URL + signing spec for the chain.\n * 2. Round trigger prices and compute slippage-shifted \"opened\" prices via\n * {@link priceSlippageCalculation}.\n * 3. Build a {@link TpSlConditionalOrderMessage} with non-null legs only.\n * 4. Sign it with the session-key wallet client (`config.getWalletClient`).\n * 5. POST `{ typedData, signature, signer }` to the handler.\n *\n * An explicit successful response establishes acceptance. Subscribe with\n * `watchTpSlNotifications` for refresh hints and reconcile live order state;\n * notifications do not correlate successive mutations or supply order versions.\n *\n * @throws {SymmError} when the chain has no `tpsl` config, both `tp` and `sl`\n * are omitted, or signing fails.\n * @throws {SymmApiError} when the handler request fails.\n */\nexport async function setQuoteTpSl(\n config: Config,\n parameters: SetQuoteTpSlParameters,\n): Promise<SetQuoteTpSlReturnType> {\n if (!parameters.tp && !parameters.sl) {\n throw new SymmError(\n \"validation\",\n \"SET_TPSL_NOTHING_TO_SUBMIT\",\n \"setQuoteTpSl: at least one of `tp` or `sl` must be provided.\",\n );\n }\n\n if (\n !Number.isSafeInteger(Number(parameters.quoteId)) ||\n parameters.quoteId === 0n ||\n !Number.isSafeInteger(Number(parameters.symbolId)) ||\n parameters.symbolId <= 0n\n ) {\n throw new SymmError(\n \"validation\",\n \"SET_TPSL_INVALID_ID\",\n \"TP/SL quote and symbol IDs must be safe nonzero integers.\",\n );\n }\n\n const chainConfig = config.getChainConfig(parameters.chainId);\n const tpsl = resolveTpSlConfig(config, parameters.chainId);\n const affiliate = parameters.affiliate ?? chainConfig.addresses.affiliatesAddress;\n const slippage = parameters.slippage ?? DEFAULT_TPSL_SLIPPAGE_LOWCAPS;\n\n const signingSpec = await getTpSlSigningSpec(config, { chainId: parameters.chainId });\n\n const tpLeg: TpSlConditionalOrderLeg | null = parameters.tp\n ? buildConditionalOrderLeg({\n quantity: parameters.quantity,\n price: priceSlippageCalculation(\n parameters.tp.triggerPrice,\n slippage,\n parameters.positionType,\n parameters.pricePrecision,\n ),\n conditionalPrice: toDecimal(parameters.tp.triggerPrice).toFixed(parameters.pricePrecision),\n priceType: parameters.tp.priceType,\n })\n : null;\n\n const slLeg: TpSlConditionalOrderLeg | null = parameters.sl\n ? buildConditionalOrderLeg({\n quantity: parameters.quantity,\n price: priceSlippageCalculation(\n parameters.sl.triggerPrice,\n slippage,\n parameters.positionType,\n parameters.pricePrecision,\n ),\n conditionalPrice: toDecimal(parameters.sl.triggerPrice).toFixed(parameters.pricePrecision),\n priceType: parameters.sl.priceType,\n })\n : null;\n\n const message = buildConditionalOrderMessage({\n virtualAccount: parameters.virtualAccount,\n subAccount: parameters.subAccount,\n quoteId: Number(parameters.quoteId),\n symbolId: Number(parameters.symbolId),\n positionType: parameters.positionType === PositionType.LONG ? 0 : 1,\n affiliate,\n takeProfit: tpLeg,\n stopLoss: slLeg,\n });\n\n const walletClient = await config.getWalletClient({ chainId: parameters.chainId, from: parameters.from });\n const signed = await signTpSlRequest({ signingSpec, message, walletClient });\n\n try {\n const response = await conditionalOrderRequestV5ApiV5Post(signed as unknown as ConditionalOrderOperationV5, {\n baseURL: tpsl.url,\n headers: { \"App-Name\": tpsl.appName, \"Content-Type\": \"application/json\", Accept: \"application/json\" },\n });\n const body = response.data ?? {};\n assertTpSlAcceptance(body, \"SET\");\n const extra = body as { coh_quote_id?: string; cohQuoteId?: string };\n return { success: true, cohQuoteId: extra.coh_quote_id ?? extra.cohQuoteId };\n } catch (err) {\n return rethrowTpSlError(err, { code: \"SET_TPSL_FAILED\", baseURL: tpsl.url });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAyFA,eAAsB,EACpB,GACA,GACiC;CACjC,IAAI,CAAC,EAAW,MAAM,CAAC,EAAW,IAChC,MAAM,IAAI,EACR,cACA,8BACA,8DACF;CAGF,IACE,CAAC,OAAO,cAAc,OAAO,EAAW,OAAO,CAAC,KAChD,EAAW,YAAY,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ACqB,QAAQ,CAAC;EAC/B,EAAqB,GAAM,KAAK;EAChC,IAAM,IAAQ;EACd,OAAO;GAAE,SAAS;GAAM,YAAY,EAAM,gBAAgB,EAAM;EAAW;CAC7E,SAAS,GAAK;EACZ,OAAO,EAAiB,GAAK;GAAE,MAAM;GAAmB,SAAS,EAAK;EAAI,CAAC;CAC7E;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symmio/trading-core",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Framework-agnostic SYMMIO SDK. Contract calls, calculations, and transformations with no framework assumptions.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/SYMM-IO/Trading-SDK/tree/main/packages/trading-core#readme",