@pear-protocol/symmio-client 0.3.12 → 0.3.14
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 +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +207 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +205 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +232 -2
- package/dist/react/index.d.ts +232 -2
- package/dist/react/index.js +430 -137
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +427 -138
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +189 -136
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +189 -136
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -24685,6 +24685,210 @@ function applySlippage(price, slippagePercent, isLong) {
|
|
|
24685
24685
|
return price - price * bps / 10000n;
|
|
24686
24686
|
}
|
|
24687
24687
|
|
|
24688
|
-
|
|
24688
|
+
// src/utils/account-overview.ts
|
|
24689
|
+
var BALANCE_INFO_KEYS = [
|
|
24690
|
+
"allocatedBalance",
|
|
24691
|
+
"allocated_balance",
|
|
24692
|
+
"cva",
|
|
24693
|
+
"lf",
|
|
24694
|
+
"partyAmm",
|
|
24695
|
+
"partyAMM",
|
|
24696
|
+
"party_a_mm",
|
|
24697
|
+
"mm",
|
|
24698
|
+
"lockedPartyAMM",
|
|
24699
|
+
"upnl"
|
|
24700
|
+
];
|
|
24701
|
+
function isRecord(value) {
|
|
24702
|
+
return typeof value === "object" && value !== null;
|
|
24703
|
+
}
|
|
24704
|
+
function hasBalanceInfoShape(value) {
|
|
24705
|
+
return isRecord(value) && BALANCE_INFO_KEYS.some((key) => key in value);
|
|
24706
|
+
}
|
|
24707
|
+
function readValue(source, keys) {
|
|
24708
|
+
for (const key of keys) {
|
|
24709
|
+
if (key in source) {
|
|
24710
|
+
return source[key];
|
|
24711
|
+
}
|
|
24712
|
+
}
|
|
24713
|
+
return void 0;
|
|
24714
|
+
}
|
|
24715
|
+
function toNumber(value) {
|
|
24716
|
+
if (value === null || value === void 0 || value === "") {
|
|
24717
|
+
return 0;
|
|
24718
|
+
}
|
|
24719
|
+
if (typeof value === "bigint") {
|
|
24720
|
+
return Number(value);
|
|
24721
|
+
}
|
|
24722
|
+
const parsed = Number(value);
|
|
24723
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
24724
|
+
}
|
|
24725
|
+
function toDisplayString(value) {
|
|
24726
|
+
if (Object.is(value, -0) || Math.abs(value) < Number.EPSILON) {
|
|
24727
|
+
return "0";
|
|
24728
|
+
}
|
|
24729
|
+
return String(value);
|
|
24730
|
+
}
|
|
24731
|
+
function readNumber(source, keys) {
|
|
24732
|
+
return toNumber(readValue(source, keys));
|
|
24733
|
+
}
|
|
24734
|
+
function readTimestamp(source) {
|
|
24735
|
+
const timestamp = readValue(source, ["timestamp"]);
|
|
24736
|
+
if (timestamp === void 0 || timestamp === null) {
|
|
24737
|
+
return void 0;
|
|
24738
|
+
}
|
|
24739
|
+
const parsed = Number(timestamp);
|
|
24740
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
24741
|
+
}
|
|
24742
|
+
function getBalanceInfoContainer(response) {
|
|
24743
|
+
if (!isRecord(response)) {
|
|
24744
|
+
return void 0;
|
|
24745
|
+
}
|
|
24746
|
+
if (hasBalanceInfoShape(response)) {
|
|
24747
|
+
return response;
|
|
24748
|
+
}
|
|
24749
|
+
const data = response.data;
|
|
24750
|
+
if (isRecord(data)) {
|
|
24751
|
+
return data;
|
|
24752
|
+
}
|
|
24753
|
+
return response;
|
|
24754
|
+
}
|
|
24755
|
+
function getSymmAccountBalanceInfo(response, accountAddress) {
|
|
24756
|
+
const container = getBalanceInfoContainer(response);
|
|
24757
|
+
if (!container) {
|
|
24758
|
+
return void 0;
|
|
24759
|
+
}
|
|
24760
|
+
if (hasBalanceInfoShape(container)) {
|
|
24761
|
+
return container;
|
|
24762
|
+
}
|
|
24763
|
+
if (accountAddress) {
|
|
24764
|
+
const normalizedAddress = accountAddress.toLowerCase();
|
|
24765
|
+
const direct = container[accountAddress] ?? container[normalizedAddress];
|
|
24766
|
+
if (isRecord(direct) && hasBalanceInfoShape(direct)) {
|
|
24767
|
+
return direct;
|
|
24768
|
+
}
|
|
24769
|
+
const matchingEntry = Object.entries(container).find(
|
|
24770
|
+
([key]) => key.toLowerCase() === normalizedAddress
|
|
24771
|
+
);
|
|
24772
|
+
if (isRecord(matchingEntry?.[1]) && hasBalanceInfoShape(matchingEntry[1])) {
|
|
24773
|
+
return matchingEntry[1];
|
|
24774
|
+
}
|
|
24775
|
+
}
|
|
24776
|
+
const values = Object.values(container);
|
|
24777
|
+
if (values.length === 1 && isRecord(values[0]) && hasBalanceInfoShape(values[0])) {
|
|
24778
|
+
return values[0];
|
|
24779
|
+
}
|
|
24780
|
+
return void 0;
|
|
24781
|
+
}
|
|
24782
|
+
function computeSymmAccountOverview({
|
|
24783
|
+
balanceInfo,
|
|
24784
|
+
upnl: upnlOverride,
|
|
24785
|
+
netDeposited
|
|
24786
|
+
}) {
|
|
24787
|
+
const allocatedBalance = readNumber(balanceInfo, [
|
|
24788
|
+
"allocatedBalance",
|
|
24789
|
+
"allocated_balance"
|
|
24790
|
+
]);
|
|
24791
|
+
const cva = readNumber(balanceInfo, ["cva", "lockedCVA", "locked_cva"]);
|
|
24792
|
+
const lf = readNumber(balanceInfo, ["lf", "lockedLF", "locked_lf"]);
|
|
24793
|
+
const partyAmm = readNumber(balanceInfo, [
|
|
24794
|
+
"partyAmm",
|
|
24795
|
+
"partyAMM",
|
|
24796
|
+
"party_a_mm",
|
|
24797
|
+
"mm",
|
|
24798
|
+
"lockedPartyAMM",
|
|
24799
|
+
"locked_party_a_mm"
|
|
24800
|
+
]);
|
|
24801
|
+
const pendingCva = readNumber(balanceInfo, [
|
|
24802
|
+
"pendingCva",
|
|
24803
|
+
"pending_cva",
|
|
24804
|
+
"pendingLockedCVA",
|
|
24805
|
+
"pending_locked_cva"
|
|
24806
|
+
]);
|
|
24807
|
+
const pendingLf = readNumber(balanceInfo, [
|
|
24808
|
+
"pendingLf",
|
|
24809
|
+
"pending_lf",
|
|
24810
|
+
"pendingLockedLF",
|
|
24811
|
+
"pending_locked_lf"
|
|
24812
|
+
]);
|
|
24813
|
+
const pendingPartyAmm = readNumber(balanceInfo, [
|
|
24814
|
+
"pendingPartyAmm",
|
|
24815
|
+
"pendingPartyAMM",
|
|
24816
|
+
"pending_party_a_mm",
|
|
24817
|
+
"pendingMm",
|
|
24818
|
+
"pending_mm",
|
|
24819
|
+
"pendingLockedPartyAMM",
|
|
24820
|
+
"pending_locked_party_a_mm"
|
|
24821
|
+
]);
|
|
24822
|
+
const upnl = upnlOverride === void 0 ? readNumber(balanceInfo, ["upnl"]) : toNumber(upnlOverride);
|
|
24823
|
+
const computedTotalLocked = cva + lf + partyAmm;
|
|
24824
|
+
const totalLocked = readValue(
|
|
24825
|
+
balanceInfo,
|
|
24826
|
+
["totalLocked", "total_locked"]
|
|
24827
|
+
) === void 0 ? computedTotalLocked : readNumber(balanceInfo, ["totalLocked", "total_locked"]);
|
|
24828
|
+
const totalPendingLocked = readValue(balanceInfo, [
|
|
24829
|
+
"totalPendingLocked",
|
|
24830
|
+
"total_pending_locked"
|
|
24831
|
+
]) === void 0 ? pendingCva + pendingLf + pendingPartyAmm : readNumber(balanceInfo, ["totalPendingLocked", "total_pending_locked"]);
|
|
24832
|
+
const maintenanceMargin = cva + lf;
|
|
24833
|
+
const equity = allocatedBalance + upnl;
|
|
24834
|
+
const availableForOrder = upnl >= 0 ? allocatedBalance + upnl - totalLocked - totalPendingLocked : allocatedBalance - cva - lf - totalPendingLocked - Math.max(Math.abs(upnl), partyAmm);
|
|
24835
|
+
const availableBalance = readNumber(balanceInfo, [
|
|
24836
|
+
"availableBalance",
|
|
24837
|
+
"available_balance"
|
|
24838
|
+
]);
|
|
24839
|
+
const notional = readNumber(balanceInfo, ["notional"]);
|
|
24840
|
+
return {
|
|
24841
|
+
allocatedBalance: toDisplayString(allocatedBalance),
|
|
24842
|
+
upnl: toDisplayString(upnl),
|
|
24843
|
+
equity: toDisplayString(equity),
|
|
24844
|
+
totalAccountValue: toDisplayString(equity),
|
|
24845
|
+
maintenanceMargin: toDisplayString(maintenanceMargin),
|
|
24846
|
+
totalLocked: toDisplayString(totalLocked),
|
|
24847
|
+
marginUsed: toDisplayString(computedTotalLocked),
|
|
24848
|
+
totalPendingLocked: toDisplayString(totalPendingLocked),
|
|
24849
|
+
availableForOrder: toDisplayString(availableForOrder),
|
|
24850
|
+
availableMargin: toDisplayString(availableForOrder),
|
|
24851
|
+
availableBalance: toDisplayString(availableBalance),
|
|
24852
|
+
netDeposited: toDisplayString(toNumber(netDeposited)),
|
|
24853
|
+
notional: toDisplayString(notional),
|
|
24854
|
+
timestamp: readTimestamp(balanceInfo)
|
|
24855
|
+
};
|
|
24856
|
+
}
|
|
24857
|
+
function computeSymmNetDeposited(totals, decimals = 6) {
|
|
24858
|
+
if (!totals) {
|
|
24859
|
+
return "0";
|
|
24860
|
+
}
|
|
24861
|
+
const deposit2 = parseRawCollateralUnits(totals.deposit);
|
|
24862
|
+
const withdraw2 = parseRawCollateralUnits(totals.withdraw);
|
|
24863
|
+
const value = deposit2 - withdraw2;
|
|
24864
|
+
const negative = value < 0n;
|
|
24865
|
+
const absolute = negative ? -value : value;
|
|
24866
|
+
const scale = 10n ** BigInt(decimals);
|
|
24867
|
+
const whole = absolute / scale;
|
|
24868
|
+
const fraction = absolute % scale;
|
|
24869
|
+
const fractionText = fraction.toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
24870
|
+
const amount = fractionText ? `${whole}.${fractionText}` : whole.toString();
|
|
24871
|
+
return negative ? `-${amount}` : amount;
|
|
24872
|
+
}
|
|
24873
|
+
function parseRawCollateralUnits(value) {
|
|
24874
|
+
if (value === null || value === void 0 || value === "") {
|
|
24875
|
+
return 0n;
|
|
24876
|
+
}
|
|
24877
|
+
if (typeof value === "bigint") {
|
|
24878
|
+
return value;
|
|
24879
|
+
}
|
|
24880
|
+
if (typeof value === "number") {
|
|
24881
|
+
if (!Number.isSafeInteger(value)) {
|
|
24882
|
+
throw new Error("Raw collateral unit numbers must be safe integers");
|
|
24883
|
+
}
|
|
24884
|
+
return BigInt(value);
|
|
24885
|
+
}
|
|
24886
|
+
if (!/^-?\d+$/.test(value)) {
|
|
24887
|
+
throw new Error("Raw collateral unit strings must be base-10 integers");
|
|
24888
|
+
}
|
|
24889
|
+
return BigInt(value);
|
|
24890
|
+
}
|
|
24891
|
+
|
|
24892
|
+
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, computeSymmNetDeposited, delegation_exports as delegationActions, deposit_exports as depositActions, encodeCall, formatPrice, fromWei, getAddress, getSymmAccountBalanceInfo, instant_exports as instantActions, signature_exports as signatureActions, stats_exports as statsActions, toWei, trade_exports as tradeActions, validateAddress, validateAmount, validateChainId, validateDeadline, validateQuantity, withdraw_exports as withdrawActions, wrapInProxyCall };
|
|
24689
24893
|
//# sourceMappingURL=index.mjs.map
|
|
24690
24894
|
//# sourceMappingURL=index.mjs.map
|