@t2000/sdk 0.8.4 → 0.8.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/index.cjs +16 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2795,6 +2795,22 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2795
2795
|
const current = savePositions.reduce(
|
|
2796
2796
|
(worst, p) => p.apy < worst.apy ? p : worst
|
|
2797
2797
|
);
|
|
2798
|
+
const withdrawAdapter = this.registry.getLending(current.protocolId);
|
|
2799
|
+
if (withdrawAdapter) {
|
|
2800
|
+
try {
|
|
2801
|
+
const maxResult = await withdrawAdapter.maxWithdraw(this._address, current.asset);
|
|
2802
|
+
if (maxResult.maxAmount < current.amount) {
|
|
2803
|
+
current.amount = Math.max(0, maxResult.maxAmount - 0.01);
|
|
2804
|
+
}
|
|
2805
|
+
} catch {
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
if (current.amount <= 0.01) {
|
|
2809
|
+
throw new T2000Error(
|
|
2810
|
+
"HEALTH_FACTOR_TOO_LOW",
|
|
2811
|
+
"Cannot rebalance \u2014 active borrows prevent safe withdrawal. Repay some debt first."
|
|
2812
|
+
);
|
|
2813
|
+
}
|
|
2798
2814
|
const apyDiff = bestRate.rates.saveApy - current.apy;
|
|
2799
2815
|
const isSameProtocol = current.protocolId === bestRate.protocolId;
|
|
2800
2816
|
const isSameAsset = current.asset === bestRate.asset;
|
|
@@ -2906,7 +2922,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2906
2922
|
}
|
|
2907
2923
|
const txDigests = [];
|
|
2908
2924
|
let totalGasCost = 0;
|
|
2909
|
-
const withdrawAdapter = this.registry.getLending(current.protocolId);
|
|
2910
2925
|
if (!withdrawAdapter) throw new T2000Error("PROTOCOL_UNAVAILABLE", `Protocol ${current.protocolId} not found`);
|
|
2911
2926
|
const withdrawResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
2912
2927
|
const built = await withdrawAdapter.buildWithdrawTx(this._address, current.amount, current.asset);
|