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