@haven-fi/solauto-sdk 1.0.508 → 1.0.510

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.
@@ -36,7 +36,7 @@ async function getJupQuote(swapDetails) {
36
36
  : undefined,
37
37
  slippageBps: memecoinSwap ? 500 : 200,
38
38
  maxAccounts: !swapDetails.exactOut ? 40 : undefined,
39
- }), 4, 200);
39
+ }), 2, 200);
40
40
  }
41
41
  async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
42
42
  const quoteResponse = swapDetails.jupQuote ?? (await getJupQuote(swapDetails));
@@ -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,EAAgB,MAAM,iBAAiB,CAAC;AAa5E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAoI9C,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;CACjB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,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C;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;CACjB;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,CAwDjB;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,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,CA6FzB"}
@@ -170,12 +170,10 @@ async function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRa
170
170
  const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
171
171
  (values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
172
172
  let inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(input.mint), input.decimals);
173
- const outputAmount = rebalanceToZero
174
- ? output.amountUsed.baseUnit +
175
- BigInt(Math.round(Number(output.amountUsed.baseUnit) *
176
- // Add this small percentage to account for the APR on the debt between now and the transaction
177
- 0.0001))
178
- : (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(output.mint), output.decimals);
173
+ const outputAmount = output.amountUsed.baseUnit +
174
+ BigInt(Math.round(Number(output.amountUsed.baseUnit) *
175
+ // Add this small percentage to account for the APR on the debt between now and the transaction
176
+ 0.0001));
179
177
  const repaying = values.rebalanceDirection === generated_1.RebalanceDirection.Repay;
180
178
  const { requiresFlashLoan, useDebtLiquidity } = rebalanceRequiresFlashLoan(client, values);
181
179
  const flashLoanRepayFromDebt = repaying && requiresFlashLoan && useDebtLiquidity;
@@ -188,6 +186,8 @@ async function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRa
188
186
  exactOut,
189
187
  amount: exactOut ? outputAmount : inputAmount,
190
188
  };
189
+ (0, generalUtils_2.consoleLog)(targetLiqUtilizationRateBps, rebalanceToZero);
190
+ (0, generalUtils_2.consoleLog)(jupSwapInput);
191
191
  let jupQuote = undefined;
192
192
  if (rebalanceToZero) {
193
193
  try {
@@ -195,14 +195,18 @@ async function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRa
195
195
  }
196
196
  catch {
197
197
  let priceImpact = 0;
198
- inputAmount += BigInt(Math.round(Number(inputAmount) * 0.001));
198
+ jupSwapInput.exactIn = true;
199
+ jupSwapInput.exactOut = false;
200
+ jupSwapInput.amount =
201
+ inputAmount + BigInt(Math.round(Number(inputAmount) * 0.001));
199
202
  do {
200
- const res = await (0, priceUtils_1.getPriceImpact)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint), inputAmount + BigInt(Math.round(Number(inputAmount) * priceImpact)), "ExactIn");
203
+ const res = await (0, priceUtils_1.getPriceImpact)(jupSwapInput.inputMint, jupSwapInput.outputMint, jupSwapInput.amount +
204
+ BigInt(Math.round(Number(jupSwapInput.amount) * priceImpact)), "ExactIn");
201
205
  priceImpact = res.priceImpact;
202
206
  jupQuote = res.quote;
203
- inputAmount =
207
+ jupSwapInput.amount =
204
208
  BigInt(parseInt(res.quote.inAmount)) +
205
- BigInt(Math.round(Number(inputAmount) * 0.001));
209
+ BigInt(Math.round(Number(jupSwapInput.amount) * 0.001));
206
210
  } while (parseInt(jupQuote.outAmount) < outputAmount &&
207
211
  priceImpact > 0.001);
208
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.508",
3
+ "version": "1.0.510",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -69,7 +69,7 @@ export async function getJupQuote(swapDetails: JupSwapInput) {
69
69
  slippageBps: memecoinSwap ? 500 : 200,
70
70
  maxAccounts: !swapDetails.exactOut ? 40 : undefined,
71
71
  }),
72
- 4,
72
+ 2,
73
73
  200
74
74
  );
75
75
  }
@@ -363,16 +363,15 @@ export async function getJupSwapRebalanceDetails(
363
363
  usdToSwap / safeGetPrice(input.mint)!,
364
364
  input.decimals
365
365
  );
366
- const outputAmount = rebalanceToZero
367
- ? output.amountUsed.baseUnit +
368
- BigInt(
369
- Math.round(
370
- Number(output.amountUsed.baseUnit) *
371
- // Add this small percentage to account for the APR on the debt between now and the transaction
372
- 0.0001
373
- )
366
+ const outputAmount =
367
+ output.amountUsed.baseUnit +
368
+ BigInt(
369
+ Math.round(
370
+ Number(output.amountUsed.baseUnit) *
371
+ // Add this small percentage to account for the APR on the debt between now and the transaction
372
+ 0.0001
374
373
  )
375
- : toBaseUnit(usdToSwap / safeGetPrice(output.mint)!, output.decimals);
374
+ );
376
375
 
377
376
  const repaying = values.rebalanceDirection === RebalanceDirection.Repay;
378
377
 
@@ -393,6 +392,8 @@ export async function getJupSwapRebalanceDetails(
393
392
  exactOut,
394
393
  amount: exactOut ? outputAmount : inputAmount,
395
394
  };
395
+ consoleLog(targetLiqUtilizationRateBps, rebalanceToZero);
396
+ consoleLog(jupSwapInput);
396
397
 
397
398
  let jupQuote: QuoteResponse | undefined = undefined;
398
399
  if (rebalanceToZero) {
@@ -400,20 +401,24 @@ export async function getJupSwapRebalanceDetails(
400
401
  jupQuote = await getJupQuote(jupSwapInput);
401
402
  } catch {
402
403
  let priceImpact: number = 0;
403
- inputAmount += BigInt(Math.round(Number(inputAmount) * 0.001));
404
+ jupSwapInput.exactIn = true;
405
+ jupSwapInput.exactOut = false;
406
+ jupSwapInput.amount =
407
+ inputAmount + BigInt(Math.round(Number(inputAmount) * 0.001));
404
408
 
405
409
  do {
406
410
  const res = await getPriceImpact(
407
- toWeb3JsPublicKey(input.mint),
408
- toWeb3JsPublicKey(output.mint),
409
- inputAmount + BigInt(Math.round(Number(inputAmount) * priceImpact)),
411
+ jupSwapInput.inputMint,
412
+ jupSwapInput.outputMint,
413
+ jupSwapInput.amount +
414
+ BigInt(Math.round(Number(jupSwapInput.amount) * priceImpact)),
410
415
  "ExactIn"
411
416
  );
412
417
  priceImpact = res.priceImpact;
413
418
  jupQuote = res.quote;
414
- inputAmount =
419
+ jupSwapInput.amount =
415
420
  BigInt(parseInt(res.quote.inAmount)) +
416
- BigInt(Math.round(Number(inputAmount) * 0.001));
421
+ BigInt(Math.round(Number(jupSwapInput.amount) * 0.001));
417
422
  } while (
418
423
  parseInt(jupQuote.outAmount) < outputAmount &&
419
424
  priceImpact > 0.001