@haven-fi/solauto-sdk 1.0.499 → 1.0.501

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":"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;AAOrB,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;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;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,CAoH7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GA0B5E"}
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;AAOrB,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;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;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,CAiI7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GA0B5E"}
@@ -29,22 +29,32 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
29
29
  // TEMP REVERT ME
30
30
  const useLowAccounts = tokensWithLowAccounts.find((x) => swapDetails.inputMint.equals(new web3_js_1.PublicKey(x))) ||
31
31
  tokensWithLowAccounts.find((x) => swapDetails.outputMint.equals(new web3_js_1.PublicKey(x)));
32
- const quoteResponse = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.quoteGet({
33
- amount: Number(swapDetails.amount),
34
- inputMint: swapDetails.inputMint.toString(),
35
- outputMint: swapDetails.outputMint.toString(),
36
- swapMode: swapDetails.exactOut
37
- ? "ExactOut"
38
- : swapDetails.exactIn
39
- ? "ExactIn"
32
+ let quoteResponse;
33
+ try {
34
+ quoteResponse = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.quoteGet({
35
+ amount: Number(swapDetails.amount),
36
+ inputMint: swapDetails.inputMint.toString(),
37
+ outputMint: swapDetails.outputMint.toString(),
38
+ swapMode: swapDetails.exactOut
39
+ ? "ExactOut"
40
+ : swapDetails.exactIn
41
+ ? "ExactIn"
42
+ : undefined,
43
+ slippageBps: memecoinSwap ? 500 : 200,
44
+ maxAccounts: !swapDetails.exactOut
45
+ ? useLowAccounts
46
+ ? 15
47
+ : 40
40
48
  : undefined,
41
- slippageBps: memecoinSwap ? 500 : 200,
42
- maxAccounts: !swapDetails.exactOut
43
- ? useLowAccounts
44
- ? 15
45
- : 40
46
- : undefined,
47
- }), 4, 200);
49
+ }), 4, 200);
50
+ }
51
+ catch (e) {
52
+ if (swapDetails.exactOut) {
53
+ // Failed to find exact out route, try exact in
54
+ return await getJupSwapTransaction(signer, { ...swapDetails, exactIn: true }, attemptNum);
55
+ }
56
+ throw e;
57
+ }
48
58
  const priceImpactBps = Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1;
49
59
  const finalPriceSlippageBps = Math.round(Math.max(50, quoteResponse.slippageBps, priceImpactBps) *
50
60
  (1 + (swapDetails.slippageIncFactor ?? 0)));
@@ -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,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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,CA2DhB"}
@@ -183,20 +183,6 @@ 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
  let inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(input.mint), input.decimals);
186
- // const highLiquidity =
187
- // fromBaseUnit(
188
- // client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
189
- // USD_DECIMALS
190
- // ) > 10_000;
191
- // const usingMajor =
192
- // tokenInfo(client.supplyMint).isMajor || tokenInfo(client.debtMint).isMajor;
193
- const inputPadding = targetLiqUtilizationRateBps === 0
194
- // && !usingMajor && highLiquidity
195
- ? 0.1
196
- : 0;
197
- if (inputPadding) {
198
- inputAmount += BigInt(Math.round(Number(inputAmount) * inputPadding));
199
- }
200
186
  const outputAmount = targetLiqUtilizationRateBps === 0
201
187
  ? output.amountUsed.baseUnit +
202
188
  BigInt(Math.round(Number(output.amountUsed.baseUnit) *
@@ -206,10 +192,8 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
206
192
  const repaying = values.rebalanceDirection === generated_1.RebalanceDirection.Repay;
207
193
  const { requiresFlashLoan, useDebtLiquidity } = rebalanceRequiresFlashLoan(client, values);
208
194
  const flashLoanRepayFromDebt = repaying && requiresFlashLoan && useDebtLiquidity;
209
- const exactOut =
210
- // (targetLiqUtilizationRateBps === 0 && !highLiquidity && usingMajor) ||
211
- // values.repayingCloseToMaxLtv ||
212
- flashLoanRepayFromDebt;
195
+ const exactOut = targetLiqUtilizationRateBps === 0 ||
196
+ flashLoanRepayFromDebt;
213
197
  const exactIn = !exactOut;
214
198
  const addPadding = exactOut;
215
199
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.499",
3
+ "version": "1.0.501",
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",
@@ -70,27 +70,40 @@ export async function getJupSwapTransaction(
70
70
  swapDetails.outputMint.equals(new PublicKey(x))
71
71
  );
72
72
 
73
- const quoteResponse = await retryWithExponentialBackoff(
74
- async () =>
75
- await jupApi.quoteGet({
76
- amount: Number(swapDetails.amount),
77
- inputMint: swapDetails.inputMint.toString(),
78
- outputMint: swapDetails.outputMint.toString(),
79
- swapMode: swapDetails.exactOut
80
- ? "ExactOut"
81
- : swapDetails.exactIn
82
- ? "ExactIn"
73
+ let quoteResponse: QuoteResponse;
74
+ try {
75
+ quoteResponse = await retryWithExponentialBackoff(
76
+ async () =>
77
+ await jupApi.quoteGet({
78
+ amount: Number(swapDetails.amount),
79
+ inputMint: swapDetails.inputMint.toString(),
80
+ outputMint: swapDetails.outputMint.toString(),
81
+ swapMode: swapDetails.exactOut
82
+ ? "ExactOut"
83
+ : swapDetails.exactIn
84
+ ? "ExactIn"
85
+ : undefined,
86
+ slippageBps: memecoinSwap ? 500 : 200,
87
+ maxAccounts: !swapDetails.exactOut
88
+ ? useLowAccounts
89
+ ? 15
90
+ : 40
83
91
  : undefined,
84
- slippageBps: memecoinSwap ? 500 : 200,
85
- maxAccounts: !swapDetails.exactOut
86
- ? useLowAccounts
87
- ? 15
88
- : 40
89
- : undefined,
90
- }),
91
- 4,
92
- 200
93
- );
92
+ }),
93
+ 4,
94
+ 200
95
+ );
96
+ } catch (e) {
97
+ if (swapDetails.exactOut) {
98
+ // Failed to find exact out route, try exact in
99
+ return await getJupSwapTransaction(
100
+ signer,
101
+ { ...swapDetails, exactIn: true },
102
+ attemptNum
103
+ );
104
+ }
105
+ throw e;
106
+ }
94
107
 
95
108
  const priceImpactBps =
96
109
  Math.round(toBps(parseFloat(quoteResponse.priceImpactPct))) + 1;
@@ -394,22 +394,6 @@ export function getJupSwapRebalanceDetails(
394
394
  input.decimals
395
395
  );
396
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 inputPadding =
405
- targetLiqUtilizationRateBps === 0
406
- // && !usingMajor && highLiquidity
407
- ? 0.1
408
- : 0;
409
- if (inputPadding) {
410
- inputAmount += BigInt(Math.round(Number(inputAmount) * inputPadding));
411
- }
412
-
413
397
  const outputAmount =
414
398
  targetLiqUtilizationRateBps === 0
415
399
  ? output.amountUsed.baseUnit +
@@ -432,8 +416,7 @@ export function getJupSwapRebalanceDetails(
432
416
  repaying && requiresFlashLoan && useDebtLiquidity;
433
417
 
434
418
  const exactOut =
435
- // (targetLiqUtilizationRateBps === 0 && !highLiquidity && usingMajor) ||
436
- // values.repayingCloseToMaxLtv ||
419
+ targetLiqUtilizationRateBps === 0 ||
437
420
  flashLoanRepayFromDebt;
438
421
  const exactIn = !exactOut;
439
422
 
@@ -3,6 +3,7 @@ import { none, publicKey, some } from "@metaplex-foundation/umi";
3
3
  import { setupTest } from "../shared";
4
4
  import { SolautoMarginfiClient } from "../../src/clients/solautoMarginfiClient";
5
5
  import {
6
+ PositionType,
6
7
  safeFetchSolautoPosition,
7
8
  solautoAction,
8
9
  SolautoSettingsParametersInpArgs,
@@ -33,8 +34,10 @@ import {
33
34
  } from "../../src/constants";
34
35
  import {
35
36
  buildHeliusApiUrl,
37
+ getAllPositionsByAuthority,
36
38
  getQnComputeUnitPriceEstimate,
37
39
  getSolautoManagedPositions,
40
+ getSolautoPositionAccount,
38
41
  retryWithExponentialBackoff,
39
42
  } from "../../src/utils";
40
43
  import { PriorityFeeSetting } from "../../src/types";
@@ -60,6 +63,13 @@ describe("Solauto Marginfi tests", async () => {
60
63
  const supplyDecimals = 6;
61
64
  const debtDecimals = 6;
62
65
 
66
+ console.log(
67
+ getSolautoPositionAccount(
68
+ new PublicKey("9j53Z6bejUaAxJCEC64BbxozLPuvsuAFsr6iqWKKDvaw"),
69
+ 1,
70
+ SOLAUTO_PROD_PROGRAM
71
+ )
72
+ );
63
73
  await client.initialize({
64
74
  signer,
65
75
  positionId,
@@ -73,6 +83,8 @@ describe("Solauto Marginfi tests", async () => {
73
83
  // debtMint: new PublicKey(USDC),
74
84
  });
75
85
 
86
+ return;
87
+
76
88
  // console.log(
77
89
  // JSON.stringify(
78
90
  // await getQnComputeUnitPriceEstimate(