@t2000/sdk 0.15.2 → 0.15.3
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.cjs +13 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3054,9 +3054,12 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3054
3054
|
}
|
|
3055
3055
|
async balance() {
|
|
3056
3056
|
const bal = await queryBalance(this.client, this._address);
|
|
3057
|
+
const earningAssets = new Set(
|
|
3058
|
+
this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
|
|
3059
|
+
);
|
|
3057
3060
|
try {
|
|
3058
3061
|
const positions = await this.positions();
|
|
3059
|
-
const savings = positions.positions.filter((p) => p.type === "save").reduce((sum, p) => sum + p.amount, 0);
|
|
3062
|
+
const savings = positions.positions.filter((p) => p.type === "save").filter((p) => !earningAssets.has(p.asset)).reduce((sum, p) => sum + p.amount, 0);
|
|
3060
3063
|
const debt = positions.positions.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.amount, 0);
|
|
3061
3064
|
bal.savings = savings;
|
|
3062
3065
|
bal.debt = debt;
|
|
@@ -3084,7 +3087,14 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3084
3087
|
for (const pos of portfolioPositions) {
|
|
3085
3088
|
if (!(pos.asset in INVESTMENT_ASSETS)) continue;
|
|
3086
3089
|
const price = assetPrices[pos.asset] ?? 0;
|
|
3087
|
-
if (pos.
|
|
3090
|
+
if (pos.earning) {
|
|
3091
|
+
investmentValue += pos.totalAmount * price;
|
|
3092
|
+
investmentCostBasis += pos.costBasis;
|
|
3093
|
+
if (pos.asset === "SUI") {
|
|
3094
|
+
const gasSui = Math.max(0, bal.gasReserve.sui);
|
|
3095
|
+
bal.gasReserve = { sui: gasSui, usdEquiv: gasSui * price };
|
|
3096
|
+
}
|
|
3097
|
+
} else if (pos.asset === "SUI") {
|
|
3088
3098
|
const actualHeld = Math.min(pos.totalAmount, bal.gasReserve.sui);
|
|
3089
3099
|
investmentValue += actualHeld * price;
|
|
3090
3100
|
if (actualHeld < pos.totalAmount && pos.totalAmount > 0) {
|
|
@@ -4017,7 +4027,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4017
4027
|
const currentPrice = prices[pos.asset] ?? 0;
|
|
4018
4028
|
let totalAmount = pos.totalAmount;
|
|
4019
4029
|
let costBasis = pos.costBasis;
|
|
4020
|
-
if (pos.asset in INVESTMENT_ASSETS) {
|
|
4030
|
+
if (pos.asset in INVESTMENT_ASSETS && !pos.earning) {
|
|
4021
4031
|
try {
|
|
4022
4032
|
const assetInfo = SUPPORTED_ASSETS[pos.asset];
|
|
4023
4033
|
const bal = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
|