@pear-protocol/symmio-client 0.3.27 → 0.3.28
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/react/index.d.mts +5 -4
- package/dist/react/index.d.ts +5 -4
- package/dist/react/index.js +27 -11
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +28 -12
- package/dist/react/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/react/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { createContext, useContext, useMemo, useCallback, useState, useEffect, useRef } from 'react';
|
|
3
|
-
import { createSymmSDK, TpslStatus, isAuthExpiredError, isNetworkError, isInsufficientMarginError, isRateLimitedError, isTimeoutError } from '@pear-protocol/symm-core';
|
|
3
|
+
import { createSymmSDK, TpslStatus, HedgerClient, isAuthExpiredError, isNetworkError, isInsufficientMarginError, isRateLimitedError, isTimeoutError } from '@pear-protocol/symm-core';
|
|
4
4
|
import { create } from 'zustand';
|
|
5
5
|
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -27106,6 +27106,24 @@ function useSymmBalances(params) {
|
|
|
27106
27106
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
27107
27107
|
});
|
|
27108
27108
|
}
|
|
27109
|
+
function normalizeSideWeights(legs) {
|
|
27110
|
+
if (!legs?.length) return legs;
|
|
27111
|
+
const allWeighted = legs.every(
|
|
27112
|
+
(leg) => typeof leg.weight === "number" && Number.isFinite(leg.weight) && leg.weight > 0
|
|
27113
|
+
);
|
|
27114
|
+
if (!allWeighted) return legs;
|
|
27115
|
+
const total = legs.reduce((sum, leg) => sum + (leg.weight ?? 0), 0);
|
|
27116
|
+
if (total <= 0) return legs;
|
|
27117
|
+
if (Math.abs(total - 1) < 1e-9) return legs;
|
|
27118
|
+
return legs.map((leg) => ({ ...leg, weight: (leg.weight ?? 0) / total }));
|
|
27119
|
+
}
|
|
27120
|
+
function normalizeBasketWeights(request) {
|
|
27121
|
+
return {
|
|
27122
|
+
...request,
|
|
27123
|
+
longPositions: normalizeSideWeights(request.longPositions),
|
|
27124
|
+
shortPositions: normalizeSideWeights(request.shortPositions)
|
|
27125
|
+
};
|
|
27126
|
+
}
|
|
27109
27127
|
function useSymmOpenBasketMutation(options) {
|
|
27110
27128
|
const { symmCoreClient } = useSymmContext();
|
|
27111
27129
|
const queryClient = useQueryClient();
|
|
@@ -27126,10 +27144,12 @@ function useSymmOpenBasketMutation(options) {
|
|
|
27126
27144
|
if (!authToken) {
|
|
27127
27145
|
throw new Error("auth token is required to open a position");
|
|
27128
27146
|
}
|
|
27129
|
-
return symmCoreClient.positions.openBasket(
|
|
27130
|
-
|
|
27131
|
-
|
|
27132
|
-
|
|
27147
|
+
return symmCoreClient.positions.openBasket(
|
|
27148
|
+
normalizeBasketWeights({
|
|
27149
|
+
...request,
|
|
27150
|
+
authToken
|
|
27151
|
+
})
|
|
27152
|
+
);
|
|
27133
27153
|
}
|
|
27134
27154
|
});
|
|
27135
27155
|
}
|
|
@@ -27601,18 +27621,14 @@ function useSymmHedgerMarketBySymbol(params) {
|
|
|
27601
27621
|
});
|
|
27602
27622
|
}
|
|
27603
27623
|
function useSymmLockedParams(params) {
|
|
27604
|
-
const {
|
|
27624
|
+
const { chainId: ctxChainId } = useSymmContext();
|
|
27605
27625
|
const { marketName, leverage } = params;
|
|
27606
27626
|
const chainId = params.chainId ?? ctxChainId;
|
|
27607
|
-
const internalEnabled = !!
|
|
27627
|
+
const internalEnabled = !!marketName && leverage != null && typeof chainId === "number";
|
|
27608
27628
|
return useQuery({
|
|
27609
27629
|
...params.query,
|
|
27610
27630
|
queryKey: symmKeys.lockedParams(marketName, leverage, chainId),
|
|
27611
|
-
queryFn: () =>
|
|
27612
|
-
marketName,
|
|
27613
|
-
leverage,
|
|
27614
|
-
chainId
|
|
27615
|
-
}),
|
|
27631
|
+
queryFn: () => HedgerClient.getLockedParams(chainId, marketName, leverage),
|
|
27616
27632
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
27617
27633
|
});
|
|
27618
27634
|
}
|