@t2000/sdk 0.7.0 → 0.7.2
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 +48 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1376,7 +1376,7 @@ var LENDING_MARKET_ID = "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc
|
|
|
1376
1376
|
var LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL";
|
|
1377
1377
|
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1378
1378
|
var UPGRADE_CAP_ID = "0x3d4ef1859c3ee9fc72858f588b56a09da5466e64f8cc4e90a7b3b909fba8a7ae";
|
|
1379
|
-
var FALLBACK_PUBLISHED_AT = "
|
|
1379
|
+
var FALLBACK_PUBLISHED_AT = "0x3d4353f3bd3565329655e6b77bc2abfd31e558b86662ebd078ae453d416bc10f";
|
|
1380
1380
|
var descriptor4 = {
|
|
1381
1381
|
id: "suilend",
|
|
1382
1382
|
name: "Suilend",
|
|
@@ -2164,6 +2164,10 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2164
2164
|
}
|
|
2165
2165
|
} else {
|
|
2166
2166
|
amount = params.amount;
|
|
2167
|
+
const bal = await queryBalance(this.client, this._address);
|
|
2168
|
+
if (amount > bal.available) {
|
|
2169
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient USDC. Available: $${bal.available.toFixed(2)}, requested: $${amount.toFixed(2)}`);
|
|
2170
|
+
}
|
|
2167
2171
|
}
|
|
2168
2172
|
const fee = calculateFee("save", amount);
|
|
2169
2173
|
const saveAmount = amount;
|
|
@@ -2197,6 +2201,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2197
2201
|
if (asset !== "USDC") {
|
|
2198
2202
|
throw new T2000Error("ASSET_NOT_SUPPORTED", `Only USDC is supported for withdraw. Got: ${asset}`);
|
|
2199
2203
|
}
|
|
2204
|
+
if (params.amount === "all" && !params.protocol) {
|
|
2205
|
+
return this.withdrawAllProtocols(asset);
|
|
2206
|
+
}
|
|
2200
2207
|
const adapter = await this.resolveLending(params.protocol, asset, "withdraw");
|
|
2201
2208
|
let amount;
|
|
2202
2209
|
if (params.amount === "all") {
|
|
@@ -2239,6 +2246,46 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2239
2246
|
gasMethod: gasResult.gasMethod
|
|
2240
2247
|
};
|
|
2241
2248
|
}
|
|
2249
|
+
async withdrawAllProtocols(asset) {
|
|
2250
|
+
const allPositions = await this.registry.allPositions(this._address);
|
|
2251
|
+
const withSupply = allPositions.filter(
|
|
2252
|
+
(p) => p.positions.supplies.some((s) => s.asset === asset && s.amount > 1e-3)
|
|
2253
|
+
);
|
|
2254
|
+
if (withSupply.length === 0) {
|
|
2255
|
+
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
2256
|
+
}
|
|
2257
|
+
let totalWithdrawn = 0;
|
|
2258
|
+
let lastDigest = "";
|
|
2259
|
+
let totalGasCost = 0;
|
|
2260
|
+
let lastGasMethod = "self-funded";
|
|
2261
|
+
for (const pos of withSupply) {
|
|
2262
|
+
const adapter = this.registry.getLending(pos.protocolId);
|
|
2263
|
+
if (!adapter) continue;
|
|
2264
|
+
const maxResult = await adapter.maxWithdraw(this._address, asset);
|
|
2265
|
+
if (maxResult.maxAmount <= 1e-3) continue;
|
|
2266
|
+
let effectiveAmount = maxResult.maxAmount;
|
|
2267
|
+
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
2268
|
+
const built = await adapter.buildWithdrawTx(this._address, maxResult.maxAmount, asset);
|
|
2269
|
+
effectiveAmount = built.effectiveAmount;
|
|
2270
|
+
return built.tx;
|
|
2271
|
+
});
|
|
2272
|
+
totalWithdrawn += effectiveAmount;
|
|
2273
|
+
lastDigest = gasResult.digest;
|
|
2274
|
+
totalGasCost += gasResult.gasCostSui;
|
|
2275
|
+
lastGasMethod = gasResult.gasMethod;
|
|
2276
|
+
this.emitBalanceChange("USDC", effectiveAmount, "withdraw", gasResult.digest);
|
|
2277
|
+
}
|
|
2278
|
+
if (totalWithdrawn <= 0) {
|
|
2279
|
+
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
2280
|
+
}
|
|
2281
|
+
return {
|
|
2282
|
+
success: true,
|
|
2283
|
+
tx: lastDigest,
|
|
2284
|
+
amount: totalWithdrawn,
|
|
2285
|
+
gasCost: totalGasCost,
|
|
2286
|
+
gasMethod: lastGasMethod
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2242
2289
|
async maxWithdraw() {
|
|
2243
2290
|
const adapter = await this.resolveLending(void 0, "USDC", "withdraw");
|
|
2244
2291
|
return adapter.maxWithdraw(this._address, "USDC");
|