@haven-fi/solauto-sdk 1.0.493 → 1.0.495
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.
@@ -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,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAcjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA4I9C,MAAM,WAAW,eAAe;IAC9B,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;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB;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,GACnC,eAAe,CA6EjB;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe;;;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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,GACnC,eAAe,CA6EjB;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe;;;EAsDxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CAgC9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAqEhB"}
|
@@ -183,20 +183,23 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
183
183
|
const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
|
184
184
|
(values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
|
185
185
|
const inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(input.mint), input.decimals);
|
186
|
+
const highLiquidity = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS) > 10000;
|
187
|
+
const usingMajor = (0, generalUtils_2.tokenInfo)(client.supplyMint).isMajor || (0, generalUtils_2.tokenInfo)(client.debtMint).isMajor;
|
188
|
+
const debtPadding = !usingMajor && highLiquidity ? 0.001 : 0.0001;
|
186
189
|
const outputAmount = targetLiqUtilizationRateBps === 0
|
187
190
|
? output.amountUsed.baseUnit +
|
188
191
|
BigInt(Math.round(Number(output.amountUsed.baseUnit) *
|
189
192
|
// Add this small percentage to account for the APR on the debt between now and the transaction
|
190
|
-
|
193
|
+
debtPadding))
|
191
194
|
: (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(output.mint), output.decimals);
|
192
195
|
const repaying = values.rebalanceDirection === generated_1.RebalanceDirection.Repay;
|
193
196
|
const { requiresFlashLoan, useDebtLiquidity } = rebalanceRequiresFlashLoan(client, values);
|
194
197
|
const flashLoanRepayFromDebt = repaying && requiresFlashLoan && useDebtLiquidity;
|
195
|
-
const exactOut = targetLiqUtilizationRateBps === 0 ||
|
198
|
+
const exactOut = (targetLiqUtilizationRateBps === 0 && highLiquidity && usingMajor) ||
|
196
199
|
// values.repayingCloseToMaxLtv ||
|
197
200
|
flashLoanRepayFromDebt;
|
198
201
|
const exactIn = !exactOut;
|
199
|
-
const addPadding = exactOut;
|
202
|
+
const addPadding = exactOut || targetLiqUtilizationRateBps === 0;
|
200
203
|
return {
|
201
204
|
inputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint),
|
202
205
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
|
package/package.json
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
17
17
|
import { QuoteResponse } from "@jup-ag/api";
|
18
18
|
import { JupSwapDetails } from "../jupiterUtils";
|
19
|
-
import { consoleLog, currentUnixSeconds } from "../generalUtils";
|
19
|
+
import { consoleLog, currentUnixSeconds, tokenInfo } from "../generalUtils";
|
20
20
|
import {
|
21
21
|
fromBaseUnit,
|
22
22
|
fromBps,
|
@@ -393,6 +393,15 @@ export function getJupSwapRebalanceDetails(
|
|
393
393
|
usdToSwap / safeGetPrice(input.mint)!,
|
394
394
|
input.decimals
|
395
395
|
);
|
396
|
+
|
397
|
+
const highLiquidity =
|
398
|
+
fromBaseUnit(
|
399
|
+
client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
|
400
|
+
USD_DECIMALS
|
401
|
+
) > 10_000;
|
402
|
+
const usingMajor =
|
403
|
+
tokenInfo(client.supplyMint).isMajor || tokenInfo(client.debtMint).isMajor;
|
404
|
+
const debtPadding = !usingMajor && highLiquidity ? 0.001 : 0.0001;
|
396
405
|
const outputAmount =
|
397
406
|
targetLiqUtilizationRateBps === 0
|
398
407
|
? output.amountUsed.baseUnit +
|
@@ -400,7 +409,7 @@ export function getJupSwapRebalanceDetails(
|
|
400
409
|
Math.round(
|
401
410
|
Number(output.amountUsed.baseUnit) *
|
402
411
|
// Add this small percentage to account for the APR on the debt between now and the transaction
|
403
|
-
|
412
|
+
debtPadding
|
404
413
|
)
|
405
414
|
)
|
406
415
|
: toBaseUnit(usdToSwap / safeGetPrice(output.mint)!, output.decimals);
|
@@ -414,13 +423,14 @@ export function getJupSwapRebalanceDetails(
|
|
414
423
|
const flashLoanRepayFromDebt =
|
415
424
|
repaying && requiresFlashLoan && useDebtLiquidity;
|
416
425
|
|
426
|
+
|
417
427
|
const exactOut =
|
418
|
-
targetLiqUtilizationRateBps === 0 ||
|
428
|
+
(targetLiqUtilizationRateBps === 0 && highLiquidity && usingMajor) ||
|
419
429
|
// values.repayingCloseToMaxLtv ||
|
420
430
|
flashLoanRepayFromDebt;
|
421
431
|
const exactIn = !exactOut;
|
422
432
|
|
423
|
-
const addPadding = exactOut;
|
433
|
+
const addPadding = exactOut || targetLiqUtilizationRateBps === 0;
|
424
434
|
|
425
435
|
return {
|
426
436
|
inputMint: toWeb3JsPublicKey(input.mint),
|
@@ -45,7 +45,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
45
45
|
// const signer = setupTest();
|
46
46
|
const signer = setupTest("solauto-manager");
|
47
47
|
|
48
|
-
const payForTransactions =
|
48
|
+
const payForTransactions = false;
|
49
49
|
const testProgram = false;
|
50
50
|
const positionId = 1;
|
51
51
|
|
@@ -63,7 +63,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
63
63
|
await client.initialize({
|
64
64
|
signer,
|
65
65
|
positionId,
|
66
|
-
authority: new PublicKey("
|
66
|
+
authority: new PublicKey("9j53Z6bejUaAxJCEC64BbxozLPuvsuAFsr6iqWKKDvaw"),
|
67
67
|
// new: true,
|
68
68
|
// marginfiAccount: new PublicKey(
|
69
69
|
// ""
|
@@ -152,48 +152,48 @@ describe("Solauto Marginfi tests", async () => {
|
|
152
152
|
// )
|
153
153
|
// );
|
154
154
|
|
155
|
-
transactionItems.push(
|
156
|
-
new TransactionItem(
|
157
|
-
async (attemptNum) =>
|
158
|
-
await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
159
|
-
"rebalance"
|
160
|
-
)
|
161
|
-
);
|
162
|
-
|
163
|
-
// transactionItems.push(
|
164
|
-
// new TransactionItem(
|
165
|
-
// async () => ({ tx: client.refresh() }),
|
166
|
-
// "refresh"
|
167
|
-
// )
|
168
|
-
// );
|
169
|
-
|
170
155
|
// transactionItems.push(
|
171
156
|
// new TransactionItem(
|
172
157
|
// async (attemptNum) =>
|
173
|
-
// await buildSolautoRebalanceTransaction(client,
|
158
|
+
// await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
174
159
|
// "rebalance"
|
175
160
|
// )
|
176
161
|
// );
|
177
162
|
|
178
163
|
// transactionItems.push(
|
179
164
|
// new TransactionItem(
|
180
|
-
// async () => ({
|
181
|
-
//
|
182
|
-
// solautoAction("Withdraw", [{ __kind: "All" }])
|
183
|
-
// ),
|
184
|
-
// }),
|
185
|
-
// "withdraw"
|
165
|
+
// async () => ({ tx: client.refresh() }),
|
166
|
+
// "refresh"
|
186
167
|
// )
|
187
168
|
// );
|
188
169
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
170
|
+
transactionItems.push(
|
171
|
+
new TransactionItem(
|
172
|
+
async (attemptNum) =>
|
173
|
+
await buildSolautoRebalanceTransaction(client, 0, attemptNum),
|
174
|
+
"rebalance"
|
175
|
+
)
|
176
|
+
);
|
177
|
+
|
178
|
+
transactionItems.push(
|
179
|
+
new TransactionItem(
|
180
|
+
async () => ({
|
181
|
+
tx: client.protocolInteraction(
|
182
|
+
solautoAction("Withdraw", [{ __kind: "All" }])
|
183
|
+
),
|
184
|
+
}),
|
185
|
+
"withdraw"
|
186
|
+
)
|
187
|
+
);
|
188
|
+
|
189
|
+
transactionItems.push(
|
190
|
+
new TransactionItem(
|
191
|
+
async () => ({
|
192
|
+
tx: client.closePositionIx(),
|
193
|
+
}),
|
194
|
+
"close position"
|
195
|
+
)
|
196
|
+
);
|
197
197
|
|
198
198
|
const statuses = await new TransactionsManager(
|
199
199
|
client,
|