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