@t2000/sdk 0.16.24 → 0.16.25
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/adapters/index.cjs +1 -1
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +9 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -404,6 +404,7 @@ async function buildSendTx({
|
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
// src/wallet/balance.ts
|
|
407
|
+
var SUI_PRICE_FALLBACK = 1;
|
|
407
408
|
var _cachedSuiPrice = 0;
|
|
408
409
|
var _priceLastFetched = 0;
|
|
409
410
|
var PRICE_CACHE_TTL_MS = 6e4;
|
|
@@ -433,15 +434,15 @@ async function fetchSuiPrice(client) {
|
|
|
433
434
|
}
|
|
434
435
|
} catch {
|
|
435
436
|
}
|
|
436
|
-
return _cachedSuiPrice;
|
|
437
|
+
return _cachedSuiPrice || SUI_PRICE_FALLBACK;
|
|
437
438
|
}
|
|
438
439
|
async function queryBalance(client, address) {
|
|
439
440
|
const stableBalancePromises = STABLE_ASSETS.map(
|
|
440
|
-
(asset) => client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS[asset].type }).then((b) => ({ asset, amount: Number(b.totalBalance) / 10 ** SUPPORTED_ASSETS[asset].decimals }))
|
|
441
|
+
(asset) => client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS[asset].type }).then((b) => ({ asset, amount: Number(b.totalBalance) / 10 ** SUPPORTED_ASSETS[asset].decimals })).catch(() => ({ asset, amount: 0 }))
|
|
441
442
|
);
|
|
442
443
|
const nonSuiInvestmentAssets = Object.keys(INVESTMENT_ASSETS).filter((a) => a !== "SUI");
|
|
443
444
|
const investBalancePromises = nonSuiInvestmentAssets.map(
|
|
444
|
-
(asset) => client.getBalance({ owner: address, coinType: INVESTMENT_ASSETS[asset].type }).then((b) => ({ asset, amount: Number(b.totalBalance) / 10 ** INVESTMENT_ASSETS[asset].decimals }))
|
|
445
|
+
(asset) => client.getBalance({ owner: address, coinType: INVESTMENT_ASSETS[asset].type }).then((b) => ({ asset, amount: Number(b.totalBalance) / 10 ** INVESTMENT_ASSETS[asset].decimals })).catch(() => ({ asset, amount: 0 }))
|
|
445
446
|
);
|
|
446
447
|
const [suiBalance, suiPriceUsd, ...rest] = await Promise.all([
|
|
447
448
|
client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS.SUI.type }),
|
|
@@ -1136,7 +1137,7 @@ async function maxWithdrawAmount(client, addressOrKeypair) {
|
|
|
1136
1137
|
maxAmount = Math.max(0, hf.supplied - hf.borrowed * MIN_HEALTH_FACTOR / ltv);
|
|
1137
1138
|
}
|
|
1138
1139
|
const remainingSupply = hf.supplied - maxAmount;
|
|
1139
|
-
const hfAfter = hf.borrowed > 0 ? remainingSupply / hf.borrowed : Infinity;
|
|
1140
|
+
const hfAfter = hf.borrowed > 0 ? remainingSupply * ltv / hf.borrowed : Infinity;
|
|
1140
1141
|
return { maxAmount, healthFactorAfter: hfAfter, currentHF: hf.healthFactor };
|
|
1141
1142
|
}
|
|
1142
1143
|
async function maxBorrowAmount(client, addressOrKeypair) {
|
|
@@ -2935,8 +2936,9 @@ var PortfolioManager = class {
|
|
|
2935
2936
|
throw new T2000Error("INSUFFICIENT_INVESTMENT", `No ${trade.asset} position to sell`);
|
|
2936
2937
|
}
|
|
2937
2938
|
const sellAmount = Math.min(trade.amount, pos.totalAmount);
|
|
2939
|
+
const effectiveUsdValue = trade.amount > 0 && sellAmount < trade.amount ? trade.usdValue * (sellAmount / trade.amount) : trade.usdValue;
|
|
2938
2940
|
const costOfSold = pos.avgPrice * sellAmount;
|
|
2939
|
-
const realizedPnL =
|
|
2941
|
+
const realizedPnL = effectiveUsdValue - costOfSold;
|
|
2940
2942
|
pos.totalAmount -= sellAmount;
|
|
2941
2943
|
pos.costBasis -= costOfSold;
|
|
2942
2944
|
if (pos.totalAmount < 1e-6) {
|
|
@@ -3034,8 +3036,9 @@ var PortfolioManager = class {
|
|
|
3034
3036
|
throw new T2000Error("INSUFFICIENT_INVESTMENT", `No ${trade.asset} position in strategy '${strategyKey}'`);
|
|
3035
3037
|
}
|
|
3036
3038
|
const sellAmount = Math.min(trade.amount, pos.totalAmount);
|
|
3039
|
+
const effectiveUsdValue = trade.amount > 0 && sellAmount < trade.amount ? trade.usdValue * (sellAmount / trade.amount) : trade.usdValue;
|
|
3037
3040
|
const costOfSold = pos.avgPrice * sellAmount;
|
|
3038
|
-
const realizedPnL =
|
|
3041
|
+
const realizedPnL = effectiveUsdValue - costOfSold;
|
|
3039
3042
|
pos.totalAmount -= sellAmount;
|
|
3040
3043
|
pos.costBasis -= costOfSold;
|
|
3041
3044
|
if (pos.totalAmount < 1e-6) {
|