@pear-protocol/symmio-client 0.3.19 → 0.3.21

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.
@@ -627,7 +627,7 @@ var symmKeys = {
627
627
  tradeHistory: (params) => ["symm", "tradeHistory", params],
628
628
  tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
629
629
  tpslOrdersList: (params) => ["symm", "tpslOrders", params],
630
- twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
630
+ twapOrders: (params) => ["symm", "twapOrders", params],
631
631
  triggerOrders: (params) => ["symm", "triggerOrders", params],
632
632
  triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
633
633
  markets: (chainId, search, pageSize) => ["symm", "markets", chainId, search, pageSize],
@@ -2553,10 +2553,9 @@ function useSymmCloseOrder(options) {
2553
2553
  if (!symmCoreClient) {
2554
2554
  throw new Error("symm-core client not available");
2555
2555
  }
2556
- const typedRequest = request;
2557
2556
  const authToken = await resolveAuthToken(
2558
- typedRequest.authToken,
2559
- typedRequest.accountAddress
2557
+ request.authToken,
2558
+ request.accountAddress
2560
2559
  );
2561
2560
  if (!authToken) {
2562
2561
  throw new Error("auth token is required to close an order");
@@ -25229,17 +25228,29 @@ function normalizeSignParams(raw) {
25229
25228
  return raw ?? {};
25230
25229
  }
25231
25230
  function unwrapMuonResult(result) {
25232
- const data = result["result"];
25233
- if (!data) {
25231
+ const envelope = result["result"];
25232
+ if (!envelope) {
25234
25233
  throw new SymmioSDKError("Invalid Muon response: missing result", "MUON_PARSE_ERROR");
25235
25234
  }
25236
- const sigData = data["data"];
25235
+ const meta = envelope["data"] ?? {};
25237
25236
  return {
25238
- signParams: normalizeSignParams(sigData?.["signParams"] ?? data["signParams"]),
25239
- signatures: sigData?.["signatures"] ?? data["signatures"] ?? [],
25240
- init: sigData?.["init"] ?? data["init"]
25237
+ envelope,
25238
+ meta,
25239
+ computed: meta["result"] ?? {},
25240
+ signParams: normalizeSignParams(meta["signParams"] ?? envelope["signParams"]),
25241
+ signatures: meta["signatures"] ?? envelope["signatures"] ?? [],
25242
+ init: meta["init"] ?? envelope["init"]
25241
25243
  };
25242
25244
  }
25245
+ function requireBigInt(value, field) {
25246
+ if (value === void 0 || value === null || value === "") {
25247
+ throw new SymmioSDKError(
25248
+ `Invalid Muon response: missing "${field}"`,
25249
+ "MUON_PARSE_ERROR"
25250
+ );
25251
+ }
25252
+ return BigInt(value);
25253
+ }
25243
25254
  function extractSchnorrSign(signParams, signatures, init) {
25244
25255
  const inline = signParams["sigs"];
25245
25256
  if (inline?.signature !== void 0) {
@@ -25269,41 +25280,43 @@ function extractSchnorrSign(signParams, signatures, init) {
25269
25280
  nonce: nonceAddress
25270
25281
  };
25271
25282
  }
25272
- function gatewaySigOf(signatures) {
25283
+ function gatewaySigOf(envelope, signatures) {
25284
+ const shield = envelope["shieldSignature"] ?? envelope["nodeSignature"] ?? envelope["gatewaySignature"];
25285
+ if (typeof shield === "string" && shield.length > 0) return shield;
25273
25286
  return signatures?.[0]?.["signature"] ?? "0x";
25274
25287
  }
25275
25288
  function parseSingleUpnlSig(result) {
25276
- const { signParams, signatures, init } = unwrapMuonResult(result);
25289
+ const { signParams, signatures, init, envelope, meta, computed } = unwrapMuonResult(result);
25277
25290
  return {
25278
- reqId: signParams["reqId"],
25279
- timestamp: BigInt(signParams["timestamp"]),
25280
- upnl: BigInt(signParams["upnl"]),
25281
- gatewaySignature: gatewaySigOf(signatures),
25291
+ reqId: signParams["reqId"] ?? envelope["reqId"],
25292
+ timestamp: requireBigInt(signParams["timestamp"] ?? meta["timestamp"], "timestamp"),
25293
+ upnl: requireBigInt(signParams["upnl"] ?? computed["uPnl"], "upnl"),
25294
+ gatewaySignature: gatewaySigOf(envelope, signatures),
25282
25295
  sigs: extractSchnorrSign(signParams, signatures, init)
25283
25296
  };
25284
25297
  }
25285
25298
  function parseSingleUpnlAndPriceSig(result) {
25286
- const { signParams, signatures, init } = unwrapMuonResult(result);
25299
+ const { signParams, signatures, init, envelope, meta, computed } = unwrapMuonResult(result);
25287
25300
  return {
25288
- reqId: signParams["reqId"],
25289
- timestamp: BigInt(signParams["timestamp"]),
25290
- upnl: BigInt(signParams["upnl"]),
25291
- price: BigInt(signParams["price"]),
25292
- gatewaySignature: gatewaySigOf(signatures),
25301
+ reqId: signParams["reqId"] ?? envelope["reqId"],
25302
+ timestamp: requireBigInt(signParams["timestamp"] ?? meta["timestamp"], "timestamp"),
25303
+ upnl: requireBigInt(signParams["upnl"] ?? computed["uPnl"], "upnl"),
25304
+ price: requireBigInt(signParams["price"] ?? computed["price"], "price"),
25305
+ gatewaySignature: gatewaySigOf(envelope, signatures),
25293
25306
  sigs: extractSchnorrSign(signParams, signatures, init)
25294
25307
  };
25295
25308
  }
25296
25309
  function parseBatchSig(result) {
25297
- const { signParams, signatures, init } = unwrapMuonResult(result);
25298
- const prices = signParams["prices"];
25299
- const symbolIds = signParams["symbolIds"];
25310
+ const { signParams, signatures, init, envelope, meta, computed } = unwrapMuonResult(result);
25311
+ const prices = signParams["prices"] ?? computed["prices"];
25312
+ const symbolIds = signParams["symbolIds"] ?? computed["symbolIds"];
25300
25313
  return {
25301
- reqId: signParams["reqId"],
25302
- timestamp: BigInt(signParams["timestamp"]),
25303
- upnl: BigInt(signParams["upnl"]),
25314
+ reqId: signParams["reqId"] ?? envelope["reqId"],
25315
+ timestamp: requireBigInt(signParams["timestamp"] ?? meta["timestamp"], "timestamp"),
25316
+ upnl: requireBigInt(signParams["upnl"] ?? computed["uPnl"], "upnl"),
25304
25317
  prices: (prices ?? []).map((p) => BigInt(p)),
25305
25318
  symbolIds: (symbolIds ?? []).map((s) => BigInt(s)),
25306
- gatewaySignature: gatewaySigOf(signatures),
25319
+ gatewaySignature: gatewaySigOf(envelope, signatures),
25307
25320
  sigs: extractSchnorrSign(signParams, signatures, init)
25308
25321
  };
25309
25322
  }
@@ -26451,23 +26464,64 @@ function useSymmUpdatePositionMutation(paramsOrOptions, maybeOptions) {
26451
26464
  }
26452
26465
  });
26453
26466
  }
26467
+
26468
+ // src/react/hooks/order-status.ts
26469
+ var ACTIVE_ORDER_STATUS = "active";
26470
+ function normalizeOrderStatus(status) {
26471
+ return status.toLowerCase();
26472
+ }
26473
+ function isMatchingOrderStatus(orderStatus, requestedStatus) {
26474
+ if (!orderStatus) {
26475
+ return false;
26476
+ }
26477
+ const normalizedOrderStatus = normalizeOrderStatus(orderStatus);
26478
+ const normalizedRequestedStatus = normalizeOrderStatus(requestedStatus);
26479
+ return normalizedOrderStatus === normalizedRequestedStatus;
26480
+ }
26481
+ function filterOrdersByStatus(response, status) {
26482
+ const orders = response.data?.orders;
26483
+ if (!orders) {
26484
+ return response;
26485
+ }
26486
+ const filteredOrders = orders.filter((order) => isMatchingOrderStatus(order.status, status));
26487
+ return {
26488
+ ...response,
26489
+ data: {
26490
+ ...response.data,
26491
+ orders: filteredOrders
26492
+ }
26493
+ };
26494
+ }
26495
+
26496
+ // src/react/hooks/use-symm-open-orders.ts
26454
26497
  function useSymmOpenOrders(params) {
26455
26498
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
26456
- const { accountAddress, address } = params;
26499
+ const { accountAddress, address, kind, limit, offset } = params;
26500
+ const status = ACTIVE_ORDER_STATUS;
26457
26501
  const resolvedAddress = accountAddress ? void 0 : address;
26458
26502
  const chainId = params.chainId ?? ctxChainId;
26459
26503
  const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
26504
+ const request = {
26505
+ accountAddress,
26506
+ address: resolvedAddress,
26507
+ chainId,
26508
+ status,
26509
+ kind,
26510
+ limit,
26511
+ offset
26512
+ };
26460
26513
  return useQuery({
26461
26514
  ...params.query,
26462
26515
  queryKey: symmKeys.openOrders({
26463
26516
  accountAddress,
26464
26517
  address: resolvedAddress,
26465
- chainId
26466
- }),
26467
- queryFn: () => symmCoreClient.orders.list({
26468
- address: accountAddress ?? resolvedAddress,
26469
- chainId
26518
+ chainId,
26519
+ status,
26520
+ kind,
26521
+ limit,
26522
+ offset
26470
26523
  }),
26524
+ queryFn: async () => filterOrdersByStatus(await symmCoreClient.orders.list(request), status),
26471
26525
  enabled: internalEnabled && (params.query?.enabled ?? true)
26472
26526
  });
26473
26527
  }
@@ -26529,12 +26583,14 @@ function useSymmCancelTpslMutation(options) {
26529
26583
  }
26530
26584
  function useSymmTpslOrders(params) {
26531
26585
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
26532
- const { accountAddress, address, positionId, type, status } = params;
26586
+ const { accountAddress, address, positionId, type } = params;
26587
+ const status = params.status ?? ACTIVE_ORDER_STATUS;
26533
26588
  const resolvedAddress = accountAddress ? void 0 : address;
26534
26589
  const chainId = params.chainId ?? ctxChainId;
26535
- const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress || positionId);
26590
+ const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
26536
26591
  const request = {
26537
- address: accountAddress ?? resolvedAddress,
26592
+ accountAddress,
26593
+ address: resolvedAddress,
26538
26594
  positionId,
26539
26595
  type,
26540
26596
  status,
@@ -26550,27 +26606,58 @@ function useSymmTpslOrders(params) {
26550
26606
  status,
26551
26607
  chainId
26552
26608
  }),
26553
- queryFn: () => symmCoreClient.orders.getTpslOrders(request),
26609
+ queryFn: async () => filterOrdersByStatus(await symmCoreClient.orders.getTpslOrders(request), status),
26554
26610
  enabled: internalEnabled && (params.query?.enabled ?? true)
26555
26611
  });
26556
26612
  }
26557
26613
  function useResolvedTwapParams(params) {
26558
26614
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
26559
- const { accountAddress, address } = params;
26615
+ const { accountAddress, address, limit, offset } = params;
26616
+ const status = params.status ?? ACTIVE_ORDER_STATUS;
26560
26617
  const resolvedAddress = accountAddress ? void 0 : address;
26561
26618
  const chainId = params.chainId ?? ctxChainId;
26562
- return { symmCoreClient, accountAddress, resolvedAddress, chainId, query: params.query };
26619
+ return {
26620
+ symmCoreClient,
26621
+ accountAddress,
26622
+ resolvedAddress,
26623
+ chainId,
26624
+ status,
26625
+ limit,
26626
+ offset,
26627
+ query: params.query
26628
+ };
26563
26629
  }
26564
26630
  function useSymmTwapOrdersQuery(params) {
26565
- const { symmCoreClient, accountAddress, resolvedAddress, chainId, query } = useResolvedTwapParams(params);
26631
+ const {
26632
+ symmCoreClient,
26633
+ accountAddress,
26634
+ resolvedAddress,
26635
+ chainId,
26636
+ status,
26637
+ limit,
26638
+ offset,
26639
+ query
26640
+ } = useResolvedTwapParams(params);
26566
26641
  const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
26642
+ const request = {
26643
+ accountAddress,
26644
+ address: resolvedAddress,
26645
+ chainId,
26646
+ status,
26647
+ limit,
26648
+ offset
26649
+ };
26567
26650
  return useQuery({
26568
26651
  ...query,
26569
- queryKey: symmKeys.twapOrders(accountAddress ?? resolvedAddress, chainId),
26570
- queryFn: () => symmCoreClient.orders.getTwapOrders({
26571
- address: accountAddress ?? resolvedAddress,
26572
- chainId
26652
+ queryKey: symmKeys.twapOrders({
26653
+ accountAddress,
26654
+ address: resolvedAddress,
26655
+ chainId,
26656
+ status,
26657
+ limit,
26658
+ offset
26573
26659
  }),
26660
+ queryFn: async () => filterOrdersByStatus(await symmCoreClient.orders.getTwapOrders(request), status),
26574
26661
  enabled: internalEnabled && (query?.enabled ?? true)
26575
26662
  });
26576
26663
  }
@@ -26644,12 +26731,14 @@ function useSymmClearTriggerConfigMutation(params, options) {
26644
26731
  }
26645
26732
  function useSymmTriggerOrders(params) {
26646
26733
  const { symmCoreClient, chainId: ctxChainId } = useSymmContext();
26647
- const { accountAddress, address, status, limit, offset } = params;
26734
+ const { accountAddress, address, limit, offset } = params;
26735
+ const status = params.status ?? ACTIVE_ORDER_STATUS;
26648
26736
  const resolvedAddress = accountAddress ? void 0 : address;
26649
26737
  const chainId = params.chainId ?? ctxChainId;
26650
26738
  const internalEnabled = !!symmCoreClient && !!(accountAddress || resolvedAddress);
26651
26739
  const request = {
26652
- address: accountAddress ?? resolvedAddress,
26740
+ accountAddress,
26741
+ address: resolvedAddress,
26653
26742
  chainId,
26654
26743
  status,
26655
26744
  limit,
@@ -26665,7 +26754,7 @@ function useSymmTriggerOrders(params) {
26665
26754
  limit,
26666
26755
  offset
26667
26756
  }),
26668
- queryFn: () => symmCoreClient.orders.listTriggerOrders(request),
26757
+ queryFn: async () => filterOrdersByStatus(await symmCoreClient.orders.listTriggerOrders(request), status),
26669
26758
  enabled: internalEnabled && (params.query?.enabled ?? true)
26670
26759
  });
26671
26760
  }
@@ -26846,6 +26935,11 @@ async function fetch24hrTickers() {
26846
26935
 
26847
26936
  // src/react/hooks/use-symm-token-selection-markets.ts
26848
26937
  var EMPTY_MARKETS = [];
26938
+ function toSortedSymbolsKey(symbols) {
26939
+ const sortedSymbols = Array.from(symbols);
26940
+ sortedSymbols.sort();
26941
+ return sortedSymbols.join(",");
26942
+ }
26849
26943
  function useSymmTokenSelectionMarkets(params) {
26850
26944
  const query = useSymmHedgerMarkets(params);
26851
26945
  const baseMarkets = query.data?.filteredMarkets ?? query.data?.markets ?? EMPTY_MARKETS;
@@ -26858,7 +26952,7 @@ function useSymmTokenSelectionMarkets(params) {
26858
26952
  [baseMarkets]
26859
26953
  );
26860
26954
  const symbolsKey = useMemo(
26861
- () => [...marketSymbols].sort().join(","),
26955
+ () => toSortedSymbolsKey(marketSymbols),
26862
26956
  [marketSymbols]
26863
26957
  );
26864
26958
  const liveMarkPrices = useBinanceMarkPriceStore((state) => state.markPrices);