@haven-fi/solauto-sdk 1.0.536 → 1.0.537

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":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAarE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0C5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAoDnB;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,SAAS,EAAE,EAClB,oBAAoB,CAAC,EAAE,OAAO,qBAa/B;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAsB,cAAc,CAClC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,oBAAoB;;;GAc/B"}
1
+ {"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAarE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAyC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAoDnB;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,SAAS,EAAE,EAClB,oBAAoB,CAAC,EAAE,OAAO,qBAa/B;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAsB,cAAc,CAClC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,oBAAoB;;;GAc/B"}
@@ -45,7 +45,6 @@ async function fetchTokenPrices(mints) {
45
45
  const pythMints = mints.filter((x) => x.toString() in pythConstants_1.PYTH_PRICE_FEED_IDS);
46
46
  const switchboardMints = mints.filter((x) => x.toString() in switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS);
47
47
  const otherMints = mints.filter((x) => !pythMints.includes(x) && !switchboardMints.includes(x));
48
- console.log(mints.length, otherMints.length);
49
48
  const [pythData, switchboardData, jupData] = await Promise.all([
50
49
  (0, generalUtils_1.zip)(pythMints, await getPythPrices(pythMints)),
51
50
  (0, generalUtils_1.zip)(switchboardMints, await getSwitchboardPrices(switchboardMints)),
@@ -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,MAA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MAAM,GACnC,eAAe,CA4EjB;AAoDD,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAoG5C;AAED,MAAM,WAAW,gBAAiB,SAAQ,qBAAqB;IAC7D,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,cAAc,EAAE,qBAAqB,EACrC,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CA2B9B;AA4CD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,cAAc,CAAC,EAAE,qBAAqB,EACtC,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,CA4EzB"}
@@ -179,7 +179,9 @@ async function getFlashLoanRequirements(client, values, attemptNum) {
179
179
  signerFlashLoan =
180
180
  sufficientSignerSupplyLiquidity || sufficientSignerDebtLiquidity;
181
181
  if (signerFlashLoan) {
182
- useDebtLiquidity = !sufficientSignerSupplyLiquidity;
182
+ useDebtLiquidity =
183
+ values.rebalanceDirection === generated_1.RebalanceDirection.Boost ||
184
+ !sufficientSignerSupplyLiquidity;
183
185
  }
184
186
  else {
185
187
  throw new Error(`Need at least ${values.debtAdjustmentUsd / debtPrice} ${(0, generalUtils_2.tokenInfo)(client.debtMint).ticker} or ${values.debtAdjustmentUsd / supplyPrice} ${(0, generalUtils_2.tokenInfo)(client.supplyMint).ticker} to perform the transaction`);
@@ -249,7 +251,7 @@ async function getJupSwapRebalanceDetails(client, values, flRequirements, target
249
251
  const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
250
252
  (values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
251
253
  let inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / (0, priceUtils_1.safeGetPrice)(input.mint), input.decimals);
252
- const outputAmount = rebalanceToZero
254
+ let outputAmount = rebalanceToZero
253
255
  ? output.amountUsed.baseUnit +
254
256
  BigInt(Math.round(Number(output.amountUsed.baseUnit) *
255
257
  // Add this small percentage to account for the APR on the debt between now and the transaction
@@ -260,7 +262,7 @@ async function getJupSwapRebalanceDetails(client, values, flRequirements, target
260
262
  const exactOut = flashLoanRepayFromDebt && !rebalanceToZero;
261
263
  // || rebalanceToZero
262
264
  const exactIn = !exactOut;
263
- if (exactIn && rebalanceToZero) {
265
+ if (exactIn && (rebalanceToZero || values.repayingCloseToMaxLtv)) {
264
266
  inputAmount = inputAmount + BigInt(Math.round(Number(inputAmount) * 0.005));
265
267
  }
266
268
  const jupSwapInput = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.536",
3
+ "version": "1.0.537",
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",
@@ -33,7 +33,6 @@ export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
33
33
  const otherMints = mints.filter(
34
34
  (x) => !pythMints.includes(x) && !switchboardMints.includes(x)
35
35
  );
36
- console.log(mints.length, otherMints.length);
37
36
 
38
37
  const [pythData, switchboardData, jupData] = await Promise.all([
39
38
  zip(pythMints, await getPythPrices(pythMints)),
@@ -397,7 +397,9 @@ export async function getFlashLoanRequirements(
397
397
  signerFlashLoan =
398
398
  sufficientSignerSupplyLiquidity || sufficientSignerDebtLiquidity;
399
399
  if (signerFlashLoan) {
400
- useDebtLiquidity = !sufficientSignerSupplyLiquidity;
400
+ useDebtLiquidity =
401
+ values.rebalanceDirection === RebalanceDirection.Boost ||
402
+ !sufficientSignerSupplyLiquidity;
401
403
  } else {
402
404
  throw new Error(
403
405
  `Need at least ${values.debtAdjustmentUsd / debtPrice} ${tokenInfo(client.debtMint).ticker} or ${values.debtAdjustmentUsd / supplyPrice} ${tokenInfo(client.supplyMint).ticker} to perform the transaction`
@@ -525,7 +527,7 @@ export async function getJupSwapRebalanceDetails(
525
527
  usdToSwap / safeGetPrice(input.mint)!,
526
528
  input.decimals
527
529
  );
528
- const outputAmount = rebalanceToZero
530
+ let outputAmount = rebalanceToZero
529
531
  ? output.amountUsed.baseUnit +
530
532
  BigInt(
531
533
  Math.round(
@@ -545,9 +547,10 @@ export async function getJupSwapRebalanceDetails(
545
547
  // || rebalanceToZero
546
548
  const exactIn = !exactOut;
547
549
 
548
- if (exactIn && rebalanceToZero) {
550
+ if (exactIn && (rebalanceToZero || values.repayingCloseToMaxLtv)) {
549
551
  inputAmount = inputAmount + BigInt(Math.round(Number(inputAmount) * 0.005));
550
552
  }
553
+
551
554
  const jupSwapInput: JupSwapInput = {
552
555
  inputMint: toWeb3JsPublicKey(input.mint),
553
556
  outputMint: toWeb3JsPublicKey(output.mint),
@@ -18,7 +18,7 @@ import {
18
18
  maxRepayToBps,
19
19
  toBaseUnit,
20
20
  } from "../../src/utils/numberUtils";
21
- import { NATIVE_MINT, TOKEN_PROGRAM_ID } from "@solana/spl-token";
21
+ import { NATIVE_MINT } from "@solana/spl-token";
22
22
  import {
23
23
  TransactionItem,
24
24
  TransactionsManager,
@@ -34,34 +34,22 @@ import {
34
34
  } from "../../src/constants";
35
35
  import {
36
36
  buildHeliusApiUrl,
37
- fetchTokenPrices,
38
37
  getAllPositionsByAuthority,
39
38
  getQnComputeUnitPriceEstimate,
40
39
  getSolautoManagedPositions,
41
40
  getSolautoPositionAccount,
42
- getTokenAccount,
43
41
  retryWithExponentialBackoff,
44
42
  } from "../../src/utils";
45
43
  import { PriorityFeeSetting } from "../../src/types";
46
- import {
47
- ALL_SUPPORTED_TOKENS,
48
- buildIronforgeApiUrl,
49
- fromBaseUnit,
50
- tokenInfo,
51
- USD_DECIMALS,
52
- } from "../../dist";
53
- import {
54
- RawAccount as TokenAccountData,
55
- AccountLayout as SplTokenAccountLayout,
56
- } from "@solana/spl-token";
44
+ import { buildIronforgeApiUrl, fromBaseUnit, tokenInfo, USD_DECIMALS } from "../../dist";
57
45
 
58
46
  describe("Solauto Marginfi tests", async () => {
59
- const signer = setupTest();
60
- // const signer = setupTest("solauto-manager");
47
+ // const signer = setupTest();
48
+ const signer = setupTest("solauto-manager");
61
49
 
62
- const payForTransactions = false;
63
- const testProgram = true;
64
- const positionId = 1;
50
+ const payForTransactions = true;
51
+ const testProgram = false;
52
+ const positionId = 3;
65
53
 
66
54
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
67
55
  const client = new SolautoMarginfiClient(
@@ -74,38 +62,18 @@ describe("Solauto Marginfi tests", async () => {
74
62
  const supplyDecimals = 6;
75
63
  const debtDecimals = 6;
76
64
 
77
- // await client.initialize({
78
- // signer,
79
- // positionId,
80
- // // authority: new PublicKey("FKYQs7KgRvaKQHxXwb8HKfoBcFdSxLL3JvHWpPdVQ16v"),
81
- // // new: true,
82
- // // marginfiAccount: new PublicKey(
83
- // // ""
84
- // // ),
85
- // // marginfiGroup: new PublicKey(""),
86
- // // supplyMint: new PublicKey(""),
87
- // // debtMint: new PublicKey(USDC),
88
- // });
89
-
90
- const tokenAccounts = (
91
- await client.connection.getTokenAccountsByOwner(
92
- new PublicKey("He4ka5Q3N1UvZikZvykdi47xyk5PoVP2tcQL5sVp31Sz"),
93
- { programId: TOKEN_PROGRAM_ID },
94
- { commitment: "confirmed" }
95
- )
96
- ).value;
97
-
98
- const tokenAccountsData = tokenAccounts
99
- .map(
100
- (x) => SplTokenAccountLayout.decode(x.account.data) as TokenAccountData
101
- )
102
- .filter((x) => Boolean(x));
103
-
104
- console.log(tokenAccountsData);
105
- console.log(tokenAccountsData.length);
106
-
107
- console.log(await fetchTokenPrices(tokenAccountsData.map((x) => x.mint)));
108
- return;
65
+ await client.initialize({
66
+ signer,
67
+ positionId,
68
+ authority: new PublicKey("FKYQs7KgRvaKQHxXwb8HKfoBcFdSxLL3JvHWpPdVQ16v"),
69
+ // new: true,
70
+ // marginfiAccount: new PublicKey(
71
+ // ""
72
+ // ),
73
+ // marginfiGroup: new PublicKey(""),
74
+ // supplyMint: new PublicKey(""),
75
+ // debtMint: new PublicKey(USDC),
76
+ });
109
77
 
110
78
  const transactionItems: TransactionItem[] = [];
111
79
  // const settingParams: SolautoSettingsParametersInpArgs = {
@@ -177,7 +145,7 @@ describe("Solauto Marginfi tests", async () => {
177
145
  transactionItems.push(
178
146
  new TransactionItem(
179
147
  async (attemptNum) =>
180
- await buildSolautoRebalanceTransaction(client, 2000, attemptNum),
148
+ await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
181
149
  "rebalance"
182
150
  )
183
151
  );