@t2000/sdk 0.18.4 → 0.18.5
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 +10 -2
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +10 -2
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +19 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1129,11 +1129,19 @@ async function getRates(client) {
|
|
|
1129
1129
|
}
|
|
1130
1130
|
async function getPositions(client, addressOrKeypair) {
|
|
1131
1131
|
const address = typeof addressOrKeypair === "string" ? addressOrKeypair : addressOrKeypair.getPublicKey().toSuiAddress();
|
|
1132
|
-
const [states,
|
|
1132
|
+
const [states, cachedPools] = await Promise.all([getUserState(client, address), getPools()]);
|
|
1133
|
+
let pools = cachedPools;
|
|
1134
|
+
const unmatchedIds = states.filter((s) => !pools.find((p) => p.id === s.assetId)).map((s) => s.assetId);
|
|
1135
|
+
if (unmatchedIds.length > 0) {
|
|
1136
|
+
pools = await getPools(true);
|
|
1137
|
+
}
|
|
1133
1138
|
const positions = [];
|
|
1134
1139
|
for (const state of states) {
|
|
1135
1140
|
const pool = pools.find((p) => p.id === state.assetId);
|
|
1136
|
-
if (!pool)
|
|
1141
|
+
if (!pool) {
|
|
1142
|
+
console.warn(`[NAVI] No pool found for assetId=${state.assetId} (supply=${state.supplyBalance}, borrow=${state.borrowBalance}) \u2014 funds may be invisible`);
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1137
1145
|
const symbol = resolvePoolSymbol(pool);
|
|
1138
1146
|
const supplyBal = compoundBalance(state.supplyBalance, pool.currentSupplyIndex, pool);
|
|
1139
1147
|
const borrowBal = compoundBalance(state.borrowBalance, pool.currentBorrowIndex, pool);
|
|
@@ -3851,7 +3859,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3851
3859
|
);
|
|
3852
3860
|
try {
|
|
3853
3861
|
const positions = await this.positions();
|
|
3854
|
-
const savings = positions.positions.filter((p) => p.type === "save").filter((p) => !earningAssets.has(p.asset)).
|
|
3862
|
+
const savings = positions.positions.filter((p) => p.type === "save").filter((p) => !earningAssets.has(p.asset)).reduce((sum, p) => sum + p.amount, 0);
|
|
3855
3863
|
const debt = positions.positions.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.amount, 0);
|
|
3856
3864
|
bal.savings = savings;
|
|
3857
3865
|
bal.debt = debt;
|
|
@@ -3871,6 +3879,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3871
3879
|
if (sp.asset in INVESTMENT_ASSETS) investedAssets.add(sp.asset);
|
|
3872
3880
|
}
|
|
3873
3881
|
}
|
|
3882
|
+
for (const asset of Object.keys(INVESTMENT_ASSETS)) {
|
|
3883
|
+
if ((bal.assets[asset] ?? 0) > 0) investedAssets.add(asset);
|
|
3884
|
+
}
|
|
3874
3885
|
for (const asset of investedAssets) {
|
|
3875
3886
|
if (asset === "SUI" || asset in assetPrices) continue;
|
|
3876
3887
|
try {
|
|
@@ -4072,11 +4083,14 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
4072
4083
|
return this.withdrawAllProtocols();
|
|
4073
4084
|
}
|
|
4074
4085
|
const allPositions = await this.registry.allPositions(this._address);
|
|
4086
|
+
const earningAssets = new Set(
|
|
4087
|
+
this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
|
|
4088
|
+
);
|
|
4075
4089
|
const supplies = [];
|
|
4076
4090
|
for (const pos of allPositions) {
|
|
4077
4091
|
if (params.protocol && pos.protocolId !== params.protocol) continue;
|
|
4078
4092
|
for (const s of pos.positions.supplies) {
|
|
4079
|
-
if (s.amount > 1e-3 && !(s.asset
|
|
4093
|
+
if (s.amount > 1e-3 && !earningAssets.has(s.asset)) {
|
|
4080
4094
|
supplies.push({ protocolId: pos.protocolId, asset: s.asset, amount: s.amount, apy: s.apy });
|
|
4081
4095
|
}
|
|
4082
4096
|
}
|
|
@@ -4160,7 +4174,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
4160
4174
|
const withdrawable = [];
|
|
4161
4175
|
for (const pos of allPositions) {
|
|
4162
4176
|
for (const supply of pos.positions.supplies) {
|
|
4163
|
-
if (supply.amount > 0.01 && !earningAssets.has(supply.asset)
|
|
4177
|
+
if (supply.amount > 0.01 && !earningAssets.has(supply.asset)) {
|
|
4164
4178
|
withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
|
|
4165
4179
|
}
|
|
4166
4180
|
}
|