@t2000/sdk 0.18.6 → 0.18.8
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 +36 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3854,48 +3854,45 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3854
3854
|
}
|
|
3855
3855
|
async balance() {
|
|
3856
3856
|
const bal = await queryBalance(this.client, this._address);
|
|
3857
|
+
const portfolioPositions = this.portfolio.getPositions();
|
|
3857
3858
|
const earningAssets = new Set(
|
|
3858
|
-
|
|
3859
|
+
portfolioPositions.filter((p) => p.earning).map((p) => p.asset)
|
|
3859
3860
|
);
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
const portfolioPositions = this.portfolio.getPositions();
|
|
3870
|
-
const suiPrice = bal.gasReserve.sui > 0 ? bal.gasReserve.usdEquiv / bal.gasReserve.sui : 0;
|
|
3871
|
-
const assetPrices = { SUI: suiPrice };
|
|
3872
|
-
const swapAdapter = this.registry.listSwap()[0];
|
|
3873
|
-
const investedAssets = /* @__PURE__ */ new Set();
|
|
3874
|
-
for (const pos of portfolioPositions) {
|
|
3875
|
-
if (pos.asset in INVESTMENT_ASSETS) investedAssets.add(pos.asset);
|
|
3876
|
-
}
|
|
3877
|
-
for (const key of this.portfolio.getAllStrategyKeys()) {
|
|
3878
|
-
for (const sp of this.portfolio.getStrategyPositions(key)) {
|
|
3879
|
-
if (sp.asset in INVESTMENT_ASSETS) investedAssets.add(sp.asset);
|
|
3861
|
+
const suiPrice = bal.gasReserve.sui > 0 ? bal.gasReserve.usdEquiv / bal.gasReserve.sui : 0;
|
|
3862
|
+
const assetPrices = { SUI: suiPrice };
|
|
3863
|
+
const swapAdapter = this.registry.listSwap()[0];
|
|
3864
|
+
for (const asset of Object.keys(INVESTMENT_ASSETS)) {
|
|
3865
|
+
if (asset === "SUI") continue;
|
|
3866
|
+
try {
|
|
3867
|
+
if (swapAdapter) {
|
|
3868
|
+
const quote = await swapAdapter.getQuote("USDC", asset, 1);
|
|
3869
|
+
assetPrices[asset] = quote.expectedOutput > 0 ? 1 / quote.expectedOutput : 0;
|
|
3880
3870
|
}
|
|
3871
|
+
} catch {
|
|
3872
|
+
assetPrices[asset] = 0;
|
|
3881
3873
|
}
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3874
|
+
}
|
|
3875
|
+
let chainTotal = bal.available + bal.gasReserve.usdEquiv;
|
|
3876
|
+
for (const asset of Object.keys(INVESTMENT_ASSETS)) {
|
|
3877
|
+
if (asset === "SUI") continue;
|
|
3878
|
+
chainTotal += (bal.assets[asset] ?? 0) * (assetPrices[asset] ?? 0);
|
|
3879
|
+
}
|
|
3880
|
+
try {
|
|
3881
|
+
const positions = await this.positions();
|
|
3882
|
+
for (const pos of positions.positions) {
|
|
3883
|
+
if (pos.type === "save") {
|
|
3884
|
+
chainTotal += pos.amount;
|
|
3885
|
+
if (!earningAssets.has(pos.asset)) {
|
|
3886
|
+
bal.savings += pos.amount;
|
|
3891
3887
|
}
|
|
3892
|
-
}
|
|
3893
|
-
|
|
3888
|
+
} else if (pos.type === "borrow") {
|
|
3889
|
+
chainTotal -= pos.amount;
|
|
3890
|
+
bal.debt += pos.amount;
|
|
3894
3891
|
}
|
|
3895
3892
|
}
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3893
|
+
} catch {
|
|
3894
|
+
}
|
|
3895
|
+
try {
|
|
3899
3896
|
const trackedAmounts = {};
|
|
3900
3897
|
const trackedCostBasis = {};
|
|
3901
3898
|
const earningAssetSet = /* @__PURE__ */ new Set();
|
|
@@ -3912,6 +3909,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3912
3909
|
trackedCostBasis[sp.asset] = (trackedCostBasis[sp.asset] ?? 0) + sp.costBasis;
|
|
3913
3910
|
}
|
|
3914
3911
|
}
|
|
3912
|
+
let investmentValue = 0;
|
|
3913
|
+
let investmentCostBasis = 0;
|
|
3914
|
+
let trackedValue = 0;
|
|
3915
3915
|
for (const asset of Object.keys(INVESTMENT_ASSETS)) {
|
|
3916
3916
|
const price = assetPrices[asset] ?? 0;
|
|
3917
3917
|
const tracked = trackedAmounts[asset] ?? 0;
|
|
@@ -3949,7 +3949,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3949
3949
|
} catch {
|
|
3950
3950
|
bal.pendingRewards = 0;
|
|
3951
3951
|
}
|
|
3952
|
-
bal.total =
|
|
3952
|
+
bal.total = chainTotal;
|
|
3953
3953
|
return bal;
|
|
3954
3954
|
}
|
|
3955
3955
|
async history(params) {
|