@haven-fi/solauto-sdk 1.0.171 → 1.0.172
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA+IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,
|
1
|
+
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA+IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CAoEjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,EACvB,cAAc,EAAE,MAAM,GACrB,gBAAgB,GAAG,SAAS,CA0D9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAyChB"}
|
@@ -120,16 +120,11 @@ function getFlashLoanDetails(client, values, jupQuote, priceImpactBps) {
|
|
120
120
|
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) +
|
121
121
|
(values.dcaTokenType === generated_1.TokenType.Supply ? values.amountUsdToDcaIn : 0);
|
122
122
|
let debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
123
|
-
const
|
124
|
-
Math.abs(values.debtAdjustmentUsd) * (0, numberUtils_1.fromBps)(priceImpactBps);
|
123
|
+
const debtAdjustmentUsd = Math.abs(values.debtAdjustmentUsd);
|
125
124
|
supplyUsd =
|
126
|
-
values.debtAdjustmentUsd < 0
|
127
|
-
? supplyUsd - debtAdjustmentWithSlippage
|
128
|
-
: supplyUsd;
|
125
|
+
values.debtAdjustmentUsd < 0 ? supplyUsd - debtAdjustmentUsd : supplyUsd;
|
129
126
|
debtUsd =
|
130
|
-
values.debtAdjustmentUsd > 0
|
131
|
-
? debtUsd + debtAdjustmentWithSlippage
|
132
|
-
: debtUsd;
|
127
|
+
values.debtAdjustmentUsd > 0 ? debtUsd + debtAdjustmentUsd : debtUsd;
|
133
128
|
const tempLiqUtilizationRateBps = (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, client.solautoPositionState.liqThresholdBps);
|
134
129
|
const requiresFlashLoan = supplyUsd <= 0 ||
|
135
130
|
tempLiqUtilizationRateBps >
|
@@ -151,7 +146,7 @@ function getFlashLoanDetails(client, values, jupQuote, priceImpactBps) {
|
|
151
146
|
? {
|
152
147
|
baseUnitAmount: exactAmountBaseUnit
|
153
148
|
? exactAmountBaseUnit
|
154
|
-
: (0, numberUtils_1.toBaseUnit)(
|
149
|
+
: (0, numberUtils_1.toBaseUnit)(debtAdjustmentUsd / flashLoanTokenPrice, flashLoanToken.decimals),
|
155
150
|
mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(flashLoanToken.mint),
|
156
151
|
}
|
157
152
|
: undefined;
|
@@ -166,7 +161,12 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
166
161
|
const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
|
167
162
|
(values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
|
168
163
|
const inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, generalUtils_2.safeGetPrice)(input.mint), input.decimals);
|
169
|
-
const outputAmount =
|
164
|
+
const outputAmount = targetLiqUtilizationRateBps === 0
|
165
|
+
? output.amountUsed.baseUnit +
|
166
|
+
BigInt(Math.round(Number(output.amountUsed.baseUnit) *
|
167
|
+
// Add this small percentage to account for the APR on the debt between now and the transaction
|
168
|
+
0.0001))
|
169
|
+
: (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, generalUtils_2.safeGetPrice)(output.mint), output.decimals);
|
170
170
|
const exactOut = targetLiqUtilizationRateBps === 0 || values.repayingCloseToMaxLtv;
|
171
171
|
const exactIn = !exactOut;
|
172
172
|
return {
|
@@ -174,14 +174,7 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
174
174
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
|
175
175
|
destinationWallet: client.solautoPosition,
|
176
176
|
slippageIncFactor: 0.5 + (attemptNum ?? 0) * 0.2,
|
177
|
-
amount: exactOut
|
178
|
-
? outputAmount +
|
179
|
-
(targetLiqUtilizationRateBps === 0
|
180
|
-
? BigInt(Math.round(Number(outputAmount) *
|
181
|
-
// Add this small percentage to account for the APR on the debt between now and the transaction
|
182
|
-
0.0001))
|
183
|
-
: BigInt(0))
|
184
|
-
: inputAmount,
|
177
|
+
amount: exactOut ? outputAmount : inputAmount,
|
185
178
|
exactIn: exactIn,
|
186
179
|
exactOut: exactOut,
|
187
180
|
};
|
package/package.json
CHANGED
@@ -237,7 +237,8 @@ export function getRebalanceValues(
|
|
237
237
|
return {
|
238
238
|
increasingLeverage,
|
239
239
|
debtAdjustmentUsd,
|
240
|
-
repayingCloseToMaxLtv:
|
240
|
+
repayingCloseToMaxLtv:
|
241
|
+
state.liqUtilizationRateBps > maxRepayTo && targetRateBps >= maxRepayTo,
|
241
242
|
amountToDcaIn: amountToDcaIn ?? 0,
|
242
243
|
amountUsdToDcaIn,
|
243
244
|
dcaTokenType: dca?.tokenType,
|
@@ -266,17 +267,11 @@ export function getFlashLoanDetails(
|
|
266
267
|
USD_DECIMALS
|
267
268
|
);
|
268
269
|
|
269
|
-
const
|
270
|
-
Math.abs(values.debtAdjustmentUsd) +
|
271
|
-
Math.abs(values.debtAdjustmentUsd) * fromBps(priceImpactBps);
|
270
|
+
const debtAdjustmentUsd = Math.abs(values.debtAdjustmentUsd);
|
272
271
|
supplyUsd =
|
273
|
-
values.debtAdjustmentUsd < 0
|
274
|
-
? supplyUsd - debtAdjustmentWithSlippage
|
275
|
-
: supplyUsd;
|
272
|
+
values.debtAdjustmentUsd < 0 ? supplyUsd - debtAdjustmentUsd : supplyUsd;
|
276
273
|
debtUsd =
|
277
|
-
values.debtAdjustmentUsd > 0
|
278
|
-
? debtUsd + debtAdjustmentWithSlippage
|
279
|
-
: debtUsd;
|
274
|
+
values.debtAdjustmentUsd > 0 ? debtUsd + debtAdjustmentUsd : debtUsd;
|
280
275
|
|
281
276
|
const tempLiqUtilizationRateBps = getLiqUtilzationRateBps(
|
282
277
|
supplyUsd,
|
@@ -312,7 +307,7 @@ export function getFlashLoanDetails(
|
|
312
307
|
baseUnitAmount: exactAmountBaseUnit
|
313
308
|
? exactAmountBaseUnit
|
314
309
|
: toBaseUnit(
|
315
|
-
|
310
|
+
debtAdjustmentUsd / flashLoanTokenPrice,
|
316
311
|
flashLoanToken.decimals
|
317
312
|
),
|
318
313
|
mint: toWeb3JsPublicKey(flashLoanToken.mint),
|
@@ -341,12 +336,20 @@ export function getJupSwapRebalanceDetails(
|
|
341
336
|
usdToSwap / safeGetPrice(input.mint)!,
|
342
337
|
input.decimals
|
343
338
|
);
|
344
|
-
const outputAmount =
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
339
|
+
const outputAmount =
|
340
|
+
targetLiqUtilizationRateBps === 0
|
341
|
+
? output.amountUsed.baseUnit +
|
342
|
+
BigInt(
|
343
|
+
Math.round(
|
344
|
+
Number(output.amountUsed.baseUnit) *
|
345
|
+
// Add this small percentage to account for the APR on the debt between now and the transaction
|
346
|
+
0.0001
|
347
|
+
)
|
348
|
+
)
|
349
|
+
: toBaseUnit(usdToSwap / safeGetPrice(output.mint)!, output.decimals);
|
350
|
+
|
351
|
+
const exactOut =
|
352
|
+
targetLiqUtilizationRateBps === 0 || values.repayingCloseToMaxLtv;
|
350
353
|
const exactIn = !exactOut;
|
351
354
|
|
352
355
|
return {
|
@@ -354,18 +357,7 @@ export function getJupSwapRebalanceDetails(
|
|
354
357
|
outputMint: toWeb3JsPublicKey(output.mint),
|
355
358
|
destinationWallet: client.solautoPosition,
|
356
359
|
slippageIncFactor: 0.5 + (attemptNum ?? 0) * 0.2,
|
357
|
-
amount: exactOut
|
358
|
-
? outputAmount +
|
359
|
-
(targetLiqUtilizationRateBps === 0
|
360
|
-
? BigInt(
|
361
|
-
Math.round(
|
362
|
-
Number(outputAmount) *
|
363
|
-
// Add this small percentage to account for the APR on the debt between now and the transaction
|
364
|
-
0.0001
|
365
|
-
)
|
366
|
-
)
|
367
|
-
: BigInt(0))
|
368
|
-
: inputAmount,
|
360
|
+
amount: exactOut ? outputAmount : inputAmount,
|
369
361
|
exactIn: exactIn,
|
370
362
|
exactOut: exactOut,
|
371
363
|
};
|