@haven-fi/solauto-sdk 1.0.144 → 1.0.145
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +7 -7
- package/dist/utils/jupiterUtils.d.ts +2 -1
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +8 -3
- package/dist/utils/solauto/rebalanceUtils.d.ts +1 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +4 -4
- package/package.json +1 -1
- package/src/transactions/transactionUtils.ts +7 -6
- package/src/utils/jupiterUtils.ts +11 -4
- package/src/utils/solauto/rebalanceUtils.ts +5 -4
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAEL,aAAa,EAUd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAyNzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAmLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAEL,aAAa,EAUd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAyNzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAmLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CA6HA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD"}
|
@@ -333,8 +333,8 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
333
333
|
const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), (0, generalUtils_1.safeGetPrice)(client.supplyMint), (0, generalUtils_1.safeGetPrice)(client.debtMint), targetLiqUtilizationRateBps);
|
334
334
|
client.log("Rebalance values: ", values);
|
335
335
|
const swapDetails = (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
|
336
|
-
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
337
|
-
const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
|
336
|
+
const { jupQuote, priceImpactBps, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
337
|
+
const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote, priceImpactBps);
|
338
338
|
let tx = (0, umi_1.transactionBuilder)();
|
339
339
|
if (flashLoan) {
|
340
340
|
client.log("Flash loan details: ", flashLoan);
|
@@ -348,11 +348,11 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
348
348
|
client.flashBorrow(flashLoan, (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), swapDetails.inputMint)),
|
349
349
|
...(addFirstRebalance
|
350
350
|
? [
|
351
|
-
client.rebalance("A", swapDetails, rebalanceType,
|
351
|
+
client.rebalance("A", swapDetails, rebalanceType, priceImpactBps, flashLoan, targetLiqUtilizationRateBps),
|
352
352
|
]
|
353
353
|
: []),
|
354
354
|
swapIx,
|
355
|
-
client.rebalance("B", swapDetails, rebalanceType,
|
355
|
+
client.rebalance("B", swapDetails, rebalanceType, priceImpactBps, flashLoan, targetLiqUtilizationRateBps),
|
356
356
|
client.flashRepay(flashLoan),
|
357
357
|
]);
|
358
358
|
}
|
@@ -361,9 +361,9 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
361
361
|
tx = tx.add([
|
362
362
|
setupInstructions,
|
363
363
|
tokenLedgerIx,
|
364
|
-
client.rebalance("A", swapDetails, rebalanceType,
|
364
|
+
client.rebalance("A", swapDetails, rebalanceType, priceImpactBps, undefined, targetLiqUtilizationRateBps),
|
365
365
|
swapIx,
|
366
|
-
client.rebalance("B", swapDetails, rebalanceType,
|
366
|
+
client.rebalance("B", swapDetails, rebalanceType, priceImpactBps, undefined, targetLiqUtilizationRateBps),
|
367
367
|
]);
|
368
368
|
}
|
369
369
|
if (client.solautoPositionState.liqUtilizationRateBps >
|
@@ -386,7 +386,7 @@ async function convertReferralFeesToDestination(umi, referralState, tokenAccount
|
|
386
386
|
inputMint: tokenAccountData.mint,
|
387
387
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralState.destFeesMint),
|
388
388
|
exactIn: true,
|
389
|
-
|
389
|
+
slippageIncFactor: 0.15,
|
390
390
|
});
|
391
391
|
let tx = (0, umi_1.transactionBuilder)()
|
392
392
|
.add(setupInstructions)
|
@@ -6,12 +6,13 @@ export interface JupSwapDetails {
|
|
6
6
|
outputMint: PublicKey;
|
7
7
|
destinationWallet: PublicKey;
|
8
8
|
amount: bigint;
|
9
|
-
|
9
|
+
slippageIncFactor?: number;
|
10
10
|
exactOut?: boolean;
|
11
11
|
exactIn?: boolean;
|
12
12
|
}
|
13
13
|
export interface JupSwapTransaction {
|
14
14
|
jupQuote: QuoteResponse;
|
15
|
+
priceImpactBps: number;
|
15
16
|
lookupTableAddresses: string[];
|
16
17
|
setupInstructions: TransactionBuilder;
|
17
18
|
tokenLedgerIx: TransactionBuilder;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAMrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,
|
1
|
+
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAMrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CA6E7B"}
|
@@ -31,11 +31,12 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
31
31
|
: swapDetails.exactIn
|
32
32
|
? "ExactIn"
|
33
33
|
: undefined,
|
34
|
-
slippageBps:
|
34
|
+
slippageBps: 30,
|
35
35
|
maxAccounts: !swapDetails.exactOut ? 60 : undefined,
|
36
36
|
}), 3);
|
37
|
-
const
|
38
|
-
|
37
|
+
const priceImpactBps = (Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1);
|
38
|
+
const finalPriceSlippageBps = Math.round(Math.max(50, quoteResponse.slippageBps, priceImpactBps) *
|
39
|
+
(1 + (swapDetails.slippageIncFactor ?? 0)));
|
39
40
|
quoteResponse.slippageBps = finalPriceSlippageBps;
|
40
41
|
console.log(quoteResponse);
|
41
42
|
console.log("Getting jup instructions...");
|
@@ -51,8 +52,12 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
51
52
|
if (!instructions.swapInstruction) {
|
52
53
|
throw new Error("No swap instruction was returned by Jupiter");
|
53
54
|
}
|
55
|
+
console.log("Raw price impact bps:", priceImpactBps);
|
56
|
+
const finalPriceImpactBps = priceImpactBps * (1 + (swapDetails.slippageIncFactor ?? 0));
|
57
|
+
console.log("Increased price impact bps:", finalPriceImpactBps);
|
54
58
|
return {
|
55
59
|
jupQuote: quoteResponse,
|
60
|
+
priceImpactBps: finalPriceImpactBps,
|
56
61
|
lookupTableAddresses: instructions.addressLookupTableAddresses,
|
57
62
|
setupInstructions: (0, umi_1.transactionBuilder)().add(instructions.setupInstructions.map((ix) => (0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(ix)))),
|
58
63
|
tokenLedgerIx: (0, umi_1.transactionBuilder)().add(instructions.tokenLedgerInstruction !== undefined
|
@@ -15,6 +15,6 @@ export interface FlashLoanDetails {
|
|
15
15
|
baseUnitAmount: bigint;
|
16
16
|
mint: PublicKey;
|
17
17
|
}
|
18
|
-
export declare function getFlashLoanDetails(client: SolautoClient, values: RebalanceValues, jupQuote: QuoteResponse): FlashLoanDetails | undefined;
|
18
|
+
export declare function getFlashLoanDetails(client: SolautoClient, values: RebalanceValues, jupQuote: QuoteResponse, priceImpactBps: number): FlashLoanDetails | undefined;
|
19
19
|
export declare function getJupSwapRebalanceDetails(client: SolautoClient, values: RebalanceValues, targetLiqUtilizationRateBps?: number, attemptNum?: number): JupSwapDetails;
|
20
20
|
//# sourceMappingURL=rebalanceUtils.d.ts.map
|
@@ -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;AAgJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,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,CAiEjB;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,
|
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;AAgJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,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,CAiEjB;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,CAmE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAkChB"}
|
@@ -114,11 +114,11 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
114
114
|
dcaTokenType: dca?.tokenType
|
115
115
|
};
|
116
116
|
}
|
117
|
-
function getFlashLoanDetails(client, values, jupQuote) {
|
117
|
+
function getFlashLoanDetails(client, values, jupQuote, priceImpactBps) {
|
118
118
|
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) + (values.dcaTokenType === generated_1.TokenType.Supply ? values.amountUsdToDcaIn : 0);
|
119
119
|
let debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
120
120
|
const debtAdjustmentWithSlippage = Math.abs(values.debtAdjustmentUsd) +
|
121
|
-
Math.abs(values.debtAdjustmentUsd) * (0, numberUtils_1.fromBps)(
|
121
|
+
Math.abs(values.debtAdjustmentUsd) * (0, numberUtils_1.fromBps)(priceImpactBps);
|
122
122
|
supplyUsd =
|
123
123
|
values.debtAdjustmentUsd < 0
|
124
124
|
? supplyUsd - debtAdjustmentWithSlippage
|
@@ -148,7 +148,7 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
148
148
|
? {
|
149
149
|
baseUnitAmount: exactAmountBaseUnit
|
150
150
|
? exactAmountBaseUnit +
|
151
|
-
BigInt(Math.round(Number(exactAmountBaseUnit) * (0, numberUtils_1.fromBps)(
|
151
|
+
BigInt(Math.round(Number(exactAmountBaseUnit) * (0, numberUtils_1.fromBps)(priceImpactBps)))
|
152
152
|
: (0, numberUtils_1.toBaseUnit)(debtAdjustmentWithSlippage / flashLoanTokenPrice, flashLoanToken.decimals),
|
153
153
|
mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(flashLoanToken.mint),
|
154
154
|
}
|
@@ -171,7 +171,7 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
171
171
|
inputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint),
|
172
172
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
|
173
173
|
destinationWallet: client.solautoPosition,
|
174
|
-
|
174
|
+
slippageIncFactor: 0.5 + (attemptNum ?? 0) * 0.2,
|
175
175
|
amount: rebalancingToZero
|
176
176
|
? client.solautoPositionState.debt.amountUsed.baseUnit +
|
177
177
|
BigInt(Math.round(Number(client.solautoPositionState.debt.amountUsed.baseUnit) *
|
package/package.json
CHANGED
@@ -611,12 +611,13 @@ export async function buildSolautoRebalanceTransaction(
|
|
611
611
|
);
|
612
612
|
const {
|
613
613
|
jupQuote,
|
614
|
+
priceImpactBps,
|
614
615
|
lookupTableAddresses,
|
615
616
|
setupInstructions,
|
616
617
|
tokenLedgerIx,
|
617
618
|
swapIx,
|
618
619
|
} = await getJupSwapTransaction(client.signer, swapDetails, attemptNum);
|
619
|
-
const flashLoan = getFlashLoanDetails(client, values, jupQuote);
|
620
|
+
const flashLoan = getFlashLoanDetails(client, values, jupQuote, priceImpactBps);
|
620
621
|
|
621
622
|
let tx = transactionBuilder();
|
622
623
|
|
@@ -643,7 +644,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
643
644
|
"A",
|
644
645
|
swapDetails,
|
645
646
|
rebalanceType,
|
646
|
-
|
647
|
+
priceImpactBps,
|
647
648
|
flashLoan,
|
648
649
|
targetLiqUtilizationRateBps
|
649
650
|
),
|
@@ -654,7 +655,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
654
655
|
"B",
|
655
656
|
swapDetails,
|
656
657
|
rebalanceType,
|
657
|
-
|
658
|
+
priceImpactBps,
|
658
659
|
flashLoan,
|
659
660
|
targetLiqUtilizationRateBps
|
660
661
|
),
|
@@ -669,7 +670,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
669
670
|
"A",
|
670
671
|
swapDetails,
|
671
672
|
rebalanceType,
|
672
|
-
|
673
|
+
priceImpactBps,
|
673
674
|
undefined,
|
674
675
|
targetLiqUtilizationRateBps
|
675
676
|
),
|
@@ -678,7 +679,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
678
679
|
"B",
|
679
680
|
swapDetails,
|
680
681
|
rebalanceType,
|
681
|
-
|
682
|
+
priceImpactBps,
|
682
683
|
undefined,
|
683
684
|
targetLiqUtilizationRateBps
|
684
685
|
),
|
@@ -719,7 +720,7 @@ export async function convertReferralFeesToDestination(
|
|
719
720
|
inputMint: tokenAccountData.mint,
|
720
721
|
outputMint: toWeb3JsPublicKey(referralState.destFeesMint),
|
721
722
|
exactIn: true,
|
722
|
-
|
723
|
+
slippageIncFactor: 0.15,
|
723
724
|
});
|
724
725
|
|
725
726
|
let tx = transactionBuilder()
|
@@ -21,7 +21,7 @@ export interface JupSwapDetails {
|
|
21
21
|
outputMint: PublicKey;
|
22
22
|
destinationWallet: PublicKey;
|
23
23
|
amount: bigint;
|
24
|
-
|
24
|
+
slippageIncFactor?: number;
|
25
25
|
exactOut?: boolean;
|
26
26
|
exactIn?: boolean;
|
27
27
|
}
|
@@ -42,6 +42,7 @@ function createTransactionInstruction(
|
|
42
42
|
|
43
43
|
export interface JupSwapTransaction {
|
44
44
|
jupQuote: QuoteResponse;
|
45
|
+
priceImpactBps: number;
|
45
46
|
lookupTableAddresses: string[];
|
46
47
|
setupInstructions: TransactionBuilder;
|
47
48
|
tokenLedgerIx: TransactionBuilder;
|
@@ -65,19 +66,20 @@ export async function getJupSwapTransaction(
|
|
65
66
|
: swapDetails.exactIn
|
66
67
|
? "ExactIn"
|
67
68
|
: undefined,
|
68
|
-
slippageBps:
|
69
|
+
slippageBps: 30,
|
69
70
|
maxAccounts: !swapDetails.exactOut ? 60 : undefined,
|
70
71
|
}),
|
71
72
|
3
|
72
73
|
);
|
73
74
|
|
75
|
+
const priceImpactBps = (Math.round(toBps(parseFloat(quoteResponse.priceImpactPct))) + 1);
|
74
76
|
const finalPriceSlippageBps = Math.round(
|
75
77
|
Math.max(
|
76
78
|
50,
|
77
79
|
quoteResponse.slippageBps,
|
78
|
-
|
80
|
+
priceImpactBps
|
79
81
|
) *
|
80
|
-
(1 + (swapDetails.
|
82
|
+
(1 + (swapDetails.slippageIncFactor ?? 0))
|
81
83
|
);
|
82
84
|
quoteResponse.slippageBps = finalPriceSlippageBps;
|
83
85
|
console.log(quoteResponse);
|
@@ -100,8 +102,13 @@ export async function getJupSwapTransaction(
|
|
100
102
|
throw new Error("No swap instruction was returned by Jupiter");
|
101
103
|
}
|
102
104
|
|
105
|
+
console.log("Raw price impact bps:", priceImpactBps);
|
106
|
+
const finalPriceImpactBps = priceImpactBps * (1 + (swapDetails.slippageIncFactor ?? 0));
|
107
|
+
console.log("Increased price impact bps:", finalPriceImpactBps);
|
108
|
+
|
103
109
|
return {
|
104
110
|
jupQuote: quoteResponse,
|
111
|
+
priceImpactBps: finalPriceImpactBps,
|
105
112
|
lookupTableAddresses: instructions.addressLookupTableAddresses,
|
106
113
|
setupInstructions: transactionBuilder().add(
|
107
114
|
instructions.setupInstructions.map((ix) =>
|
@@ -250,7 +250,8 @@ export interface FlashLoanDetails {
|
|
250
250
|
export function getFlashLoanDetails(
|
251
251
|
client: SolautoClient,
|
252
252
|
values: RebalanceValues,
|
253
|
-
jupQuote: QuoteResponse
|
253
|
+
jupQuote: QuoteResponse,
|
254
|
+
priceImpactBps: number
|
254
255
|
): FlashLoanDetails | undefined {
|
255
256
|
let supplyUsd = fromBaseUnit(
|
256
257
|
client.solautoPositionState!.supply.amountUsed.baseAmountUsdValue,
|
@@ -263,7 +264,7 @@ export function getFlashLoanDetails(
|
|
263
264
|
|
264
265
|
const debtAdjustmentWithSlippage =
|
265
266
|
Math.abs(values.debtAdjustmentUsd) +
|
266
|
-
Math.abs(values.debtAdjustmentUsd) * fromBps(
|
267
|
+
Math.abs(values.debtAdjustmentUsd) * fromBps(priceImpactBps);
|
267
268
|
supplyUsd =
|
268
269
|
values.debtAdjustmentUsd < 0
|
269
270
|
? supplyUsd - debtAdjustmentWithSlippage
|
@@ -308,7 +309,7 @@ export function getFlashLoanDetails(
|
|
308
309
|
? exactAmountBaseUnit +
|
309
310
|
BigInt(
|
310
311
|
Math.round(
|
311
|
-
Number(exactAmountBaseUnit) * fromBps(
|
312
|
+
Number(exactAmountBaseUnit) * fromBps(priceImpactBps)
|
312
313
|
)
|
313
314
|
)
|
314
315
|
: toBaseUnit(
|
@@ -346,7 +347,7 @@ export function getJupSwapRebalanceDetails(
|
|
346
347
|
inputMint: toWeb3JsPublicKey(input.mint),
|
347
348
|
outputMint: toWeb3JsPublicKey(output.mint),
|
348
349
|
destinationWallet: client.solautoPosition,
|
349
|
-
|
350
|
+
slippageIncFactor: 0.5 + (attemptNum ?? 0) * 0.2,
|
350
351
|
amount: rebalancingToZero
|
351
352
|
? client.solautoPositionState!.debt.amountUsed.baseUnit +
|
352
353
|
BigInt(
|