@pear-protocol/symmio-client 0.3.14 → 0.3.15
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/index.d.mts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +182 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +127 -36
- package/dist/react/index.d.ts +127 -36
- package/dist/react/index.js +431 -58
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +426 -60
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +24 -10
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +24 -10
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -24739,6 +24739,19 @@ function readTimestamp(source) {
|
|
|
24739
24739
|
const parsed = Number(timestamp);
|
|
24740
24740
|
return Number.isFinite(parsed) ? parsed : void 0;
|
|
24741
24741
|
}
|
|
24742
|
+
function getSymmAccountData(response) {
|
|
24743
|
+
if (!isRecord(response)) {
|
|
24744
|
+
return void 0;
|
|
24745
|
+
}
|
|
24746
|
+
const data = response.data;
|
|
24747
|
+
if (isRecord(data)) {
|
|
24748
|
+
return data;
|
|
24749
|
+
}
|
|
24750
|
+
if ("equity" in response || "maintenanceMargin" in response || "availableForOrder" in response || "totalLocked" in response) {
|
|
24751
|
+
return response;
|
|
24752
|
+
}
|
|
24753
|
+
return void 0;
|
|
24754
|
+
}
|
|
24742
24755
|
function getBalanceInfoContainer(response) {
|
|
24743
24756
|
if (!isRecord(response)) {
|
|
24744
24757
|
return void 0;
|
|
@@ -24854,6 +24867,38 @@ function computeSymmAccountOverview({
|
|
|
24854
24867
|
timestamp: readTimestamp(balanceInfo)
|
|
24855
24868
|
};
|
|
24856
24869
|
}
|
|
24870
|
+
function computeSymmAccountOverviewFromData({
|
|
24871
|
+
accountData,
|
|
24872
|
+
upnl,
|
|
24873
|
+
netDeposited
|
|
24874
|
+
}) {
|
|
24875
|
+
const equity = readNumber(accountData, ["equity"]);
|
|
24876
|
+
const maintenanceMargin = readNumber(accountData, [
|
|
24877
|
+
"maintenanceMargin",
|
|
24878
|
+
"maintenance_margin"
|
|
24879
|
+
]);
|
|
24880
|
+
const availableForOrder = readNumber(accountData, [
|
|
24881
|
+
"availableForOrder",
|
|
24882
|
+
"available_for_order"
|
|
24883
|
+
]);
|
|
24884
|
+
const totalLocked = readNumber(accountData, ["totalLocked", "total_locked"]);
|
|
24885
|
+
return {
|
|
24886
|
+
allocatedBalance: "0",
|
|
24887
|
+
upnl: toDisplayString(toNumber(upnl)),
|
|
24888
|
+
equity: toDisplayString(equity),
|
|
24889
|
+
totalAccountValue: toDisplayString(equity),
|
|
24890
|
+
maintenanceMargin: toDisplayString(maintenanceMargin),
|
|
24891
|
+
accountHealthData: accountData.accountHealthData,
|
|
24892
|
+
totalLocked: toDisplayString(totalLocked),
|
|
24893
|
+
marginUsed: toDisplayString(totalLocked),
|
|
24894
|
+
totalPendingLocked: "0",
|
|
24895
|
+
availableForOrder: toDisplayString(availableForOrder),
|
|
24896
|
+
availableMargin: toDisplayString(availableForOrder),
|
|
24897
|
+
availableBalance: toDisplayString(availableForOrder),
|
|
24898
|
+
netDeposited: toDisplayString(toNumber(netDeposited)),
|
|
24899
|
+
notional: "0"
|
|
24900
|
+
};
|
|
24901
|
+
}
|
|
24857
24902
|
function computeSymmNetDeposited(totals, decimals = 6) {
|
|
24858
24903
|
if (!totals) {
|
|
24859
24904
|
return "0";
|
|
@@ -24889,6 +24934,138 @@ function parseRawCollateralUnits(value) {
|
|
|
24889
24934
|
return BigInt(value);
|
|
24890
24935
|
}
|
|
24891
24936
|
|
|
24892
|
-
|
|
24937
|
+
// src/utils/account-pnl.ts
|
|
24938
|
+
function toNumber2(value) {
|
|
24939
|
+
if (value === null || value === void 0 || value === "") {
|
|
24940
|
+
return 0;
|
|
24941
|
+
}
|
|
24942
|
+
const parsed = Number(value);
|
|
24943
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
24944
|
+
}
|
|
24945
|
+
function readOpenedPrice(leg) {
|
|
24946
|
+
return toNumber2(leg.openedPrice ?? leg.opened_price);
|
|
24947
|
+
}
|
|
24948
|
+
function readCurrentPrice(leg) {
|
|
24949
|
+
const parsed = Number(leg.currentPrice ?? leg.current_price);
|
|
24950
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
24951
|
+
}
|
|
24952
|
+
function readMarkPrice(leg, markPrices) {
|
|
24953
|
+
const symbol = leg.symbol?.trim().toUpperCase();
|
|
24954
|
+
if (symbol) {
|
|
24955
|
+
const markPrice = Number(markPrices[symbol]);
|
|
24956
|
+
if (Number.isFinite(markPrice)) {
|
|
24957
|
+
return markPrice;
|
|
24958
|
+
}
|
|
24959
|
+
}
|
|
24960
|
+
return readCurrentPrice(leg);
|
|
24961
|
+
}
|
|
24962
|
+
function getSymbol(leg) {
|
|
24963
|
+
return leg.symbol?.trim().toUpperCase() || void 0;
|
|
24964
|
+
}
|
|
24965
|
+
function computeLegUpnl(leg, side, markPrices) {
|
|
24966
|
+
const markPrice = readMarkPrice(leg, markPrices);
|
|
24967
|
+
if (markPrice === void 0) {
|
|
24968
|
+
return { upnl: 0, missingSymbol: getSymbol(leg) };
|
|
24969
|
+
}
|
|
24970
|
+
const quantity = toNumber2(leg.quantity);
|
|
24971
|
+
const openedPrice = readOpenedPrice(leg);
|
|
24972
|
+
const direction = side === "short" ? -1 : 1;
|
|
24973
|
+
return {
|
|
24974
|
+
upnl: quantity * (markPrice - openedPrice) * direction
|
|
24975
|
+
};
|
|
24976
|
+
}
|
|
24977
|
+
function computeSymmPositionUpnl(position, markPrices = {}) {
|
|
24978
|
+
const missingSymbols = /* @__PURE__ */ new Set();
|
|
24979
|
+
let upnl = 0;
|
|
24980
|
+
let legsCount = 0;
|
|
24981
|
+
for (const leg of position.longAssets ?? []) {
|
|
24982
|
+
legsCount += 1;
|
|
24983
|
+
const result = computeLegUpnl(leg, "long", markPrices);
|
|
24984
|
+
upnl += result.upnl;
|
|
24985
|
+
if (result.missingSymbol) missingSymbols.add(result.missingSymbol);
|
|
24986
|
+
}
|
|
24987
|
+
for (const leg of position.shortAssets ?? []) {
|
|
24988
|
+
legsCount += 1;
|
|
24989
|
+
const result = computeLegUpnl(leg, "short", markPrices);
|
|
24990
|
+
upnl += result.upnl;
|
|
24991
|
+
if (result.missingSymbol) missingSymbols.add(result.missingSymbol);
|
|
24992
|
+
}
|
|
24993
|
+
if (legsCount === 0) {
|
|
24994
|
+
return {
|
|
24995
|
+
upnl: toNumber2(position.unrealizedPnl ?? position.unrealized_pnl),
|
|
24996
|
+
missingSymbols: [],
|
|
24997
|
+
positionsCount: 1,
|
|
24998
|
+
legsCount,
|
|
24999
|
+
usedFallbackPositions: 1
|
|
25000
|
+
};
|
|
25001
|
+
}
|
|
25002
|
+
return {
|
|
25003
|
+
upnl,
|
|
25004
|
+
missingSymbols: Array.from(missingSymbols),
|
|
25005
|
+
positionsCount: 1,
|
|
25006
|
+
legsCount,
|
|
25007
|
+
usedFallbackPositions: 0
|
|
25008
|
+
};
|
|
25009
|
+
}
|
|
25010
|
+
function computeSymmPositionsUpnl(positions = [], markPrices = {}) {
|
|
25011
|
+
const missingSymbols = /* @__PURE__ */ new Set();
|
|
25012
|
+
let upnl = 0;
|
|
25013
|
+
let legsCount = 0;
|
|
25014
|
+
let usedFallbackPositions = 0;
|
|
25015
|
+
for (const position of positions) {
|
|
25016
|
+
const result = computeSymmPositionUpnl(position, markPrices);
|
|
25017
|
+
upnl += result.upnl;
|
|
25018
|
+
legsCount += result.legsCount;
|
|
25019
|
+
usedFallbackPositions += result.usedFallbackPositions;
|
|
25020
|
+
result.missingSymbols.forEach((symbol) => missingSymbols.add(symbol));
|
|
25021
|
+
}
|
|
25022
|
+
return {
|
|
25023
|
+
upnl,
|
|
25024
|
+
missingSymbols: Array.from(missingSymbols),
|
|
25025
|
+
positionsCount: positions.length,
|
|
25026
|
+
legsCount,
|
|
25027
|
+
usedFallbackPositions
|
|
25028
|
+
};
|
|
25029
|
+
}
|
|
25030
|
+
function readMessageNumber(message, keys) {
|
|
25031
|
+
for (const key of keys) {
|
|
25032
|
+
if (key in message) {
|
|
25033
|
+
return toNumber2(message[key]);
|
|
25034
|
+
}
|
|
25035
|
+
}
|
|
25036
|
+
return 0;
|
|
25037
|
+
}
|
|
25038
|
+
function normalizeSymmUpnlWebSocketMessage(raw) {
|
|
25039
|
+
if (typeof raw !== "object" || raw === null) {
|
|
25040
|
+
return void 0;
|
|
25041
|
+
}
|
|
25042
|
+
const message = raw;
|
|
25043
|
+
const timestamp = readMessageNumber(message, ["timestamp"]);
|
|
25044
|
+
return {
|
|
25045
|
+
upnl: readMessageNumber(message, ["upnl"]),
|
|
25046
|
+
timestamp: timestamp || void 0,
|
|
25047
|
+
availableBalance: readMessageNumber(message, [
|
|
25048
|
+
"availableBalance",
|
|
25049
|
+
"available_balance"
|
|
25050
|
+
]),
|
|
25051
|
+
allocatedBalance: readMessageNumber(message, [
|
|
25052
|
+
"allocatedBalance",
|
|
25053
|
+
"allocated_balance"
|
|
25054
|
+
]),
|
|
25055
|
+
cva: readMessageNumber(message, ["cva"]),
|
|
25056
|
+
lf: readMessageNumber(message, ["lf"]),
|
|
25057
|
+
partyAmm: readMessageNumber(message, ["partyAmm", "party_a_mm", "mm"]),
|
|
25058
|
+
pendingPartyAmm: readMessageNumber(message, [
|
|
25059
|
+
"pendingPartyAmm",
|
|
25060
|
+
"pending_party_a_mm",
|
|
25061
|
+
"pending_mm"
|
|
25062
|
+
]),
|
|
25063
|
+
pendingCva: readMessageNumber(message, ["pendingCva", "pending_cva"]),
|
|
25064
|
+
pendingLf: readMessageNumber(message, ["pendingLf", "pending_lf"]),
|
|
25065
|
+
raw
|
|
25066
|
+
};
|
|
25067
|
+
}
|
|
25068
|
+
|
|
25069
|
+
export { ALL_TRADING_SELECTORS, AffiliateFeeLevel, ApprovalState, CHAIN_NAMES, CLEARING_HOUSE_ADDRESS, CLOSE_QUOTE_SELECTOR, COLLATERAL_ADDRESS, COLLATERAL_DECIMALS, ClearingHouseABI, ClearingHouseLiquidationStatus, DEFAULT_PARTY_B_ADDRESS, DEFAULT_PRECISION, ERC20ABI, FALLBACK_CHAIN_ID, InstantCloseStatus, LIMIT_ORDER_DEADLINE, LiquidationStatus, MARKET_ORDER_DEADLINE, MARKET_PRICE_COEFFICIENT, MAX_LEVERAGE, MULTI_ACCOUNT_ADDRESS, MUON_APP_NAME, MUON_BASE_URLS, MultiAccountABI, MuonClient, MuonVerifierABI, OrderType, PositionType, QuoteStatus, SEND_QUOTE_WITH_AFFILIATE_SELECTOR, SIGNATURE_STORE_ADDRESS, STANDARD_WITHDRAW_COOLDOWN, SYMMIO_DIAMOND_ADDRESS, SignatureStoreABI, SoftLiquidationLevel, SupportedChainId, SymmioDiamondABI, SymmioSDKError, V3_CHAIN_IDS, account_exports as accountActions, admin_exports as adminActions, allocate_exports as allocateActions, applySlippage, approval_exports as approvalActions, calculateGasMargin, cancel_exports as cancelActions, close_exports as closeActions, computeSymmAccountOverview, computeSymmAccountOverviewFromData, computeSymmNetDeposited, computeSymmPositionUpnl, computeSymmPositionsUpnl, delegation_exports as delegationActions, deposit_exports as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, getSymmAccountData, instant_exports as instantActions, normalizeSymmUpnlWebSocketMessage, signature_exports as signatureActions, stats_exports as statsActions, toWei, trade_exports as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw_exports as withdrawActions, wrapInProxyCall };
|
|
24893
25070
|
//# sourceMappingURL=index.mjs.map
|
|
24894
25071
|
//# sourceMappingURL=index.mjs.map
|