@haven-fi/solauto-sdk 1.0.505 → 1.0.507

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.
@@ -15,4 +15,5 @@ export declare const PRICES: {
15
15
  export declare const SOLAUTO_LUT = "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
16
16
  export declare const STANDARD_LUT_ACCOUNTS: string[];
17
17
  export declare const JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
18
+ export declare const BROKEN_TOKENS: string[];
18
19
  //# sourceMappingURL=solautoConstants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAE7E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC;AAE3B,eAAO,MAAM,iBAAiB,0CAA0C,CAAC"}
1
+ {"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AASzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAE7E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC;AAE3B,eAAO,MAAM,iBAAiB,0CAA0C,CAAC;AAEzE,eAAO,MAAM,aAAa,UAOzB,CAAA"}
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JITO_BLOCK_ENGINE = exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.BASIS_POINTS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
3
+ exports.BROKEN_TOKENS = exports.JITO_BLOCK_ENGINE = exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.BASIS_POINTS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  const spl_token_1 = require("@solana/spl-token");
6
6
  const generalAccounts_1 = require("./generalAccounts");
7
7
  const jupiter_sdk_1 = require("../jupiter-sdk");
8
+ const tokenConstants_1 = require("./tokenConstants");
8
9
  exports.SOLAUTO_PROD_PROGRAM = new web3_js_1.PublicKey("AutoyKBRaHSBHy9RsmXCZMy6nNFAg5FYijrvZyQcNLV");
9
10
  exports.SOLAUTO_TEST_PROGRAM = new web3_js_1.PublicKey("TesTjfQ6TbXv96Tv6fqr95XTZ1LYPxtkafmShN9PjBp");
10
11
  globalThis.LOCAL_TEST = false;
@@ -29,3 +30,11 @@ exports.STANDARD_LUT_ACCOUNTS = [
29
30
  jupiter_sdk_1.JUPITER_PROGRAM_ID,
30
31
  ].map((x) => x.toString());
31
32
  exports.JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
33
+ exports.BROKEN_TOKENS = [
34
+ tokenConstants_1.JUP,
35
+ tokenConstants_1.JLP,
36
+ tokenConstants_1.WETH,
37
+ tokenConstants_1.HNT,
38
+ tokenConstants_1.JTO,
39
+ tokenConstants_1.PYTH
40
+ ];
@@ -1,11 +1,12 @@
1
1
  import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  import { SolautoClient } from "../clients/solautoClient";
4
+ import { RebalanceValues } from "../utils/solauto/rebalanceUtils";
4
5
  import { ReferralStateManager } from "../clients";
5
6
  import { TransactionItemInputs } from "../types";
6
7
  export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
7
8
  export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
8
- export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
9
+ export declare function requiresRefreshBeforeRebalance(client: SolautoClient, values: RebalanceValues): Promise<boolean>;
9
10
  export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<TransactionItemInputs | undefined>;
10
11
  export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<TransactionItemInputs | undefined>;
11
12
  export declare function getErrorInfo(umi: Umi, txs: TransactionBuilder[], error: Error, simulationSuccessful?: boolean): {
@@ -1 +1 @@
1
- {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAoBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAOlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA4LjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAoH7B;AA2LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBAqDzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAoI5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,w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;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO;;;;EAoG/B"}
@@ -329,7 +329,7 @@ async function getTransactionChores(client, tx) {
329
329
  choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.livePositionUpdates.cancellingDca));
330
330
  return [choresBefore, choresAfter];
331
331
  }
332
- async function requiresRefreshBeforeRebalance(client) {
332
+ async function requiresRefreshBeforeRebalance(client, values) {
333
333
  const neverRefreshedBefore = client.solautoPositionData &&
334
334
  client.solautoPositionData.state.supply.amountCanBeUsed.baseUnit ===
335
335
  BigInt(0) &&
@@ -377,7 +377,8 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
377
377
  const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
378
378
  const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
379
379
  let tx = (0, umi_1.transactionBuilder)();
380
- if (await requiresRefreshBeforeRebalance(client)) {
380
+ // REVERT ME
381
+ if (await requiresRefreshBeforeRebalance(client, values)) {
381
382
  tx = tx.add(client.refresh());
382
383
  }
383
384
  if (flashLoan) {
@@ -1 +1 @@
1
- {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EAEL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAc7D,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,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,UAAU,CAAS;IAE3B,kBAAkB,SAAmB;gBAG3B,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAC/C,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,MAAM,CAAC,EAAE,kBAAkB,YAAA,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,UAAU,GAAE,OAAe,EAC3B,aAAa,CAAC,EAAE,aAAa,YAAA,EACrC,WAAW,CAAC,EAAE,WAAW;YAab,uBAAuB;IAwCrC,OAAO,CAAC,YAAY;YA6CN,aAAa;IAoB3B,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,mBAAmB;YAoBb,SAAS;IAiBV,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,GAC9B,OAAO,CAAC,0BAA0B,CAAC;IA2GzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YAkCxB,6BAA6B;YAsI7B,qBAAqB;YAoDrB,eAAe;YA0Df,eAAe;CA4D9B"}
@@ -289,6 +289,7 @@ class TransactionsManager {
289
289
  .stale;
290
290
  if (stale) {
291
291
  this.txHandler.log("Requires oracle update...");
292
+ console.log(mint);
292
293
  const swbTx = new TransactionItem(async () => (0, utils_1.buildSwbSubmitResponseTx)(client.connection, client.signer, mint), this.updateOracleTxName);
293
294
  await swbTx.initialize();
294
295
  items.unshift(swbTx);
@@ -12,6 +12,7 @@ export interface JupSwapDetails {
12
12
  addPadding?: boolean;
13
13
  jupQuote?: QuoteResponse;
14
14
  }
15
+ export declare function accountsLimit(inputMint: PublicKey, outputMint: PublicKey): 15 | 40;
15
16
  export interface JupSwapTransaction {
16
17
  jupQuote: QuoteResponse;
17
18
  priceImpactBps: number;
@@ -1 +1 @@
1
- {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings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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;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAgBD,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,WAOxE;AAED,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,CA0G7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GA0B5E"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.accountsLimit = accountsLimit;
3
4
  exports.getJupSwapTransaction = getJupSwapTransaction;
4
5
  exports.getJupPriceData = getJupPriceData;
5
6
  const umi_1 = require("@metaplex-foundation/umi");
@@ -22,6 +23,13 @@ function createTransactionInstruction(instruction) {
22
23
  data: Buffer.from(instruction.data, "base64"),
23
24
  });
24
25
  }
26
+ function accountsLimit(inputMint, outputMint) {
27
+ const tokensWithLowAccounts = [constants_1.PYTH, constants_1.INF];
28
+ // TEMP REVERT ME
29
+ const useLowAccounts = tokensWithLowAccounts.find((x) => inputMint.equals(new web3_js_1.PublicKey(x))) ||
30
+ tokensWithLowAccounts.find((x) => outputMint.equals(new web3_js_1.PublicKey(x)));
31
+ return useLowAccounts ? 15 : 40;
32
+ }
25
33
  async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
26
34
  const memecoinSwap = constants_1.TOKEN_INFO[swapDetails.inputMint.toString()].isMeme ||
27
35
  constants_1.TOKEN_INFO[swapDetails.outputMint.toString()].isMeme;
@@ -36,7 +44,9 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
36
44
  ? "ExactIn"
37
45
  : undefined,
38
46
  slippageBps: memecoinSwap ? 500 : 200,
39
- maxAccounts: !swapDetails.exactOut ? 40 : undefined,
47
+ maxAccounts: !swapDetails.exactOut
48
+ ? accountsLimit(swapDetails.inputMint, swapDetails.outputMint)
49
+ : undefined,
40
50
  }), 4, 200));
41
51
  const priceImpactBps = Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1;
42
52
  const finalPriceSlippageBps = Math.round(Math.max(50, quoteResponse.slippageBps, priceImpactBps) *
@@ -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;AAgBrE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAgDnB;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,qBAQzD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAsB,cAAc,CAClC,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,SAAS;;;GAoBtB"}
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;AAgBrE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAgDnB;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,qBAQzD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAsB,cAAc,CAClC,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,SAAS;;;GAqBtB"}
@@ -137,6 +137,7 @@ async function getPriceImpact(inputMint, inputAmount, outputMint) {
137
137
  inputMint: inputMint.toString(),
138
138
  outputMint: outputMint.toString(),
139
139
  swapMode: "ExactIn",
140
+ maxAccounts: (0, jupiterUtils_1.accountsLimit)(inputMint, outputMint),
140
141
  }), 4, 200);
141
142
  return {
142
143
  priceImpact: parseFloat(quoteResponse.priceImpactPct),
@@ -13,6 +13,7 @@ export interface RebalanceValues {
13
13
  rebalanceAction: RebalanceAction;
14
14
  rebalanceDirection: RebalanceDirection;
15
15
  feesUsd: number;
16
+ targetRateBps: number;
16
17
  }
17
18
  export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): RebalanceValues;
18
19
  export declare function rebalanceRequiresFlashLoan(client: SolautoClient, values: RebalanceValues): {
@@ -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;AAajD,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,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,C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,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,CA4EjB;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,CAkFzB"}
@@ -4,6 +4,7 @@ exports.getRebalanceValues = getRebalanceValues;
4
4
  exports.rebalanceRequiresFlashLoan = rebalanceRequiresFlashLoan;
5
5
  exports.getFlashLoanDetails = getFlashLoanDetails;
6
6
  exports.getJupSwapRebalanceDetails = getJupSwapRebalanceDetails;
7
+ const web3_js_1 = require("@solana/web3.js");
7
8
  const generated_1 = require("../../generated");
8
9
  const generalUtils_1 = require("./generalUtils");
9
10
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
@@ -11,6 +12,7 @@ const generalUtils_2 = require("../generalUtils");
11
12
  const numberUtils_1 = require("../numberUtils");
12
13
  const generalAccounts_1 = require("../../constants/generalAccounts");
13
14
  const priceUtils_1 = require("../priceUtils");
15
+ const constants_1 = require("../../constants");
14
16
  function getAdditionalAmountToDcaIn(dca) {
15
17
  if (dca.dcaInBaseUnit === BigInt(0)) {
16
18
  return 0;
@@ -82,7 +84,18 @@ function getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, target
82
84
  }
83
85
  }
84
86
  function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
85
- const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, targetLiqUtilizationRateBps);
87
+ let { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, targetLiqUtilizationRateBps);
88
+ // REVERT ME AND GET TO THE ROOT OF THIS ISSUE
89
+ const supplyMint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint);
90
+ if (constants_1.BROKEN_TOKENS.includes(supplyMint.toString()) &&
91
+ ((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint).equals(new web3_js_1.PublicKey(constants_1.USDC)) ||
92
+ (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint).equals(new web3_js_1.PublicKey(constants_1.USDT))) &&
93
+ settings &&
94
+ settings.boostToBps ===
95
+ (0, numberUtils_1.maxBoostToBps)(state.maxLtvBps, state.liqThresholdBps) &&
96
+ targetRateBps === settings.boostToBps) {
97
+ targetRateBps = 6500;
98
+ }
86
99
  const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
87
100
  (dca?.tokenType === generated_1.TokenType.Debt ? debtPrice : supplyPrice);
88
101
  const rebalanceDirection = amountUsdToDcaIn > 0 || state.liqUtilizationRateBps <= targetRateBps
@@ -93,6 +106,7 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
93
106
  amountUsdToDcaIn;
94
107
  const debtUsd = (0, numberUtils_1.fromBaseUnit)(state.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
95
108
  let debtAdjustmentUsd = (0, numberUtils_1.getDebtAdjustmentUsd)(state.liqThresholdBps, supplyUsd, debtUsd, targetRateBps, adjustmentFeeBps);
109
+ (0, generalUtils_2.consoleLog)("Target rate:", targetRateBps, (0, numberUtils_1.maxBoostToBps)(state.maxLtvBps, state.liqThresholdBps));
96
110
  const maxRepayTo = (0, numberUtils_1.maxRepayToBps)(state.maxLtvBps, state.liqThresholdBps);
97
111
  return {
98
112
  debtAdjustmentUsd,
@@ -107,6 +121,7 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
107
121
  : "repay",
108
122
  rebalanceDirection,
109
123
  feesUsd: Math.abs(debtAdjustmentUsd * (0, numberUtils_1.fromBps)(adjustmentFeeBps)),
124
+ targetRateBps,
110
125
  };
111
126
  }
112
127
  function rebalanceRequiresFlashLoan(client, values) {
@@ -190,8 +205,11 @@ async function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRa
190
205
  const res = await (0, priceUtils_1.getPriceImpact)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint), inputAmount + BigInt(Math.round(Number(inputAmount) * priceImpact)), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint));
191
206
  priceImpact = res.priceImpact;
192
207
  jupQuote = res.quote;
193
- inputAmount = BigInt(parseInt(res.quote.inAmount)) + BigInt(Math.round(Number(inputAmount) * 0.001));
194
- } while (parseInt(jupQuote.outAmount) < outputAmount && priceImpact > 0.001);
208
+ inputAmount =
209
+ BigInt(parseInt(res.quote.inAmount)) +
210
+ BigInt(Math.round(Number(inputAmount) * 0.001));
211
+ } while (parseInt(jupQuote.outAmount) < outputAmount &&
212
+ priceImpact > 0.001);
195
213
  }
196
214
  const addPadding = exactOut;
197
215
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.505",
3
+ "version": "1.0.507",
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",
@@ -11,6 +11,7 @@ import {
11
11
  } from "@solana/spl-token";
12
12
  import { SOLAUTO_MANAGER } from "./generalAccounts";
13
13
  import { JUPITER_PROGRAM_ID } from "../jupiter-sdk";
14
+ import { HNT, JLP, JTO, JUP, PYTH, WETH } from "./tokenConstants";
14
15
 
15
16
  export const SOLAUTO_PROD_PROGRAM = new PublicKey(
16
17
  "AutoyKBRaHSBHy9RsmXCZMy6nNFAg5FYijrvZyQcNLV"
@@ -45,4 +46,13 @@ export const STANDARD_LUT_ACCOUNTS = [
45
46
  JUPITER_PROGRAM_ID,
46
47
  ].map((x) => x.toString());
47
48
 
48
- export const JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
49
+ export const JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
50
+
51
+ export const BROKEN_TOKENS = [
52
+ JUP,
53
+ JLP,
54
+ WETH,
55
+ HNT,
56
+ JTO,
57
+ PYTH
58
+ ]
@@ -39,6 +39,7 @@ import {
39
39
  getFlashLoanDetails,
40
40
  getJupSwapRebalanceDetails,
41
41
  getRebalanceValues,
42
+ RebalanceValues,
42
43
  } from "../utils/solauto/rebalanceUtils";
43
44
  import {
44
45
  consoleLog,
@@ -71,10 +72,11 @@ import {
71
72
  getJupiterErrorFromCode,
72
73
  JUPITER_PROGRAM_ID,
73
74
  } from "../jupiter-sdk";
74
- import { PRICES } from "../constants";
75
+ import { JUP, PRICES, USDC } from "../constants";
75
76
  import { TransactionItemInputs } from "../types";
76
77
  import { safeGetPrice } from "../utils";
77
78
  import { BundleSimulationError } from "../types/transactions";
79
+ import { getPackedSettings } from "http2";
78
80
 
79
81
  interface wSolTokenUsage {
80
82
  wSolTokenAccount: PublicKey;
@@ -598,7 +600,7 @@ export async function getTransactionChores(
598
600
  return [choresBefore, choresAfter];
599
601
  }
600
602
 
601
- export async function requiresRefreshBeforeRebalance(client: SolautoClient) {
603
+ export async function requiresRefreshBeforeRebalance(client: SolautoClient, values: RebalanceValues) {
602
604
  const neverRefreshedBefore =
603
605
  client.solautoPositionData &&
604
606
  client.solautoPositionData.state.supply.amountCanBeUsed.baseUnit ===
@@ -703,11 +705,13 @@ export async function buildSolautoRebalanceTransaction(
703
705
  tokenLedgerIx,
704
706
  swapIx,
705
707
  } = await getJupSwapTransaction(client.signer, swapDetails, attemptNum);
708
+
706
709
  const flashLoan = getFlashLoanDetails(client, values, jupQuote);
707
710
 
708
711
  let tx = transactionBuilder();
709
712
 
710
- if (await requiresRefreshBeforeRebalance(client)) {
713
+ // REVERT ME
714
+ if (await requiresRefreshBeforeRebalance(client, values)) {
711
715
  tx = tx.add(client.refresh());
712
716
  }
713
717
 
@@ -465,6 +465,7 @@ export class TransactionsManager {
465
465
 
466
466
  if (stale) {
467
467
  this.txHandler.log("Requires oracle update...");
468
+ console.log(mint);
468
469
  const swbTx = new TransactionItem(
469
470
  async () =>
470
471
  buildSwbSubmitResponseTx(client.connection, client.signer, mint),
@@ -13,7 +13,7 @@ import {
13
13
  } from "@jup-ag/api";
14
14
  import { getTokenAccount } from "./accountUtils";
15
15
  import { consoleLog, retryWithExponentialBackoff } from "./generalUtils";
16
- import { TOKEN_INFO } from "../constants";
16
+ import { INF, PYTH, TOKEN_INFO } from "../constants";
17
17
 
18
18
  const jupApi = createJupiterApiClient();
19
19
 
@@ -43,6 +43,15 @@ function createTransactionInstruction(
43
43
  });
44
44
  }
45
45
 
46
+ export function accountsLimit(inputMint: PublicKey, outputMint: PublicKey) {
47
+ const tokensWithLowAccounts = [PYTH, INF];
48
+ // TEMP REVERT ME
49
+ const useLowAccounts =
50
+ tokensWithLowAccounts.find((x) => inputMint.equals(new PublicKey(x))) ||
51
+ tokensWithLowAccounts.find((x) => outputMint.equals(new PublicKey(x)));
52
+ return useLowAccounts ? 15 : 40;
53
+ }
54
+
46
55
  export interface JupSwapTransaction {
47
56
  jupQuote: QuoteResponse;
48
57
  priceImpactBps: number;
@@ -75,7 +84,9 @@ export async function getJupSwapTransaction(
75
84
  ? "ExactIn"
76
85
  : undefined,
77
86
  slippageBps: memecoinSwap ? 500 : 200,
78
- maxAccounts: !swapDetails.exactOut ? 40 : undefined,
87
+ maxAccounts: !swapDetails.exactOut
88
+ ? accountsLimit(swapDetails.inputMint, swapDetails.outputMint)
89
+ : undefined,
79
90
  }),
80
91
  4,
81
92
  200
@@ -12,7 +12,7 @@ import {
12
12
  zip,
13
13
  } from "./generalUtils";
14
14
  import * as OnDemand from "@switchboard-xyz/on-demand";
15
- import { getJupPriceData } from "./jupiterUtils";
15
+ import { accountsLimit, getJupPriceData } from "./jupiterUtils";
16
16
  import { createJupiterApiClient } from "@jup-ag/api";
17
17
 
18
18
  export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
@@ -181,6 +181,7 @@ export async function getPriceImpact(
181
181
  inputMint: inputMint.toString(),
182
182
  outputMint: outputMint.toString(),
183
183
  swapMode: "ExactIn",
184
+ maxAccounts: accountsLimit(inputMint, outputMint),
184
185
  }),
185
186
  4,
186
187
  200
@@ -24,13 +24,14 @@ import {
24
24
  getLiqUtilzationRateBps,
25
25
  getMaxLiqUtilizationRateBps,
26
26
  getSolautoFeesBps,
27
+ maxBoostToBps,
27
28
  maxRepayToBps,
28
29
  toBaseUnit,
29
30
  } from "../numberUtils";
30
31
  import { USD_DECIMALS } from "../../constants/generalAccounts";
31
32
  import { RebalanceAction } from "../../types";
32
33
  import { getPriceImpact, safeGetPrice } from "../priceUtils";
33
- import { TOKEN_INFO } from "../../constants";
34
+ import { BROKEN_TOKENS, USDC, USDT } from "../../constants";
34
35
 
35
36
  function getAdditionalAmountToDcaIn(dca: DCASettings): number {
36
37
  if (dca.dcaInBaseUnit === BigInt(0)) {
@@ -169,6 +170,7 @@ export interface RebalanceValues {
169
170
  rebalanceAction: RebalanceAction;
170
171
  rebalanceDirection: RebalanceDirection;
171
172
  feesUsd: number;
173
+ targetRateBps: number;
172
174
  }
173
175
 
174
176
  export function getRebalanceValues(
@@ -180,7 +182,7 @@ export function getRebalanceValues(
180
182
  debtPrice: number,
181
183
  targetLiqUtilizationRateBps?: number
182
184
  ): RebalanceValues {
183
- const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(
185
+ let { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(
184
186
  state,
185
187
  settings,
186
188
  dca,
@@ -188,6 +190,20 @@ export function getRebalanceValues(
188
190
  targetLiqUtilizationRateBps
189
191
  );
190
192
 
193
+ // REVERT ME AND GET TO THE ROOT OF THIS ISSUE
194
+ const supplyMint = toWeb3JsPublicKey(state.supply.mint);
195
+ if (
196
+ BROKEN_TOKENS.includes(supplyMint.toString()) &&
197
+ (toWeb3JsPublicKey(state.debt.mint).equals(new PublicKey(USDC)) ||
198
+ toWeb3JsPublicKey(state.debt.mint).equals(new PublicKey(USDT))) &&
199
+ settings &&
200
+ settings.boostToBps ===
201
+ maxBoostToBps(state.maxLtvBps, state.liqThresholdBps) &&
202
+ targetRateBps === settings.boostToBps
203
+ ) {
204
+ targetRateBps = 6500;
205
+ }
206
+
191
207
  const amountUsdToDcaIn =
192
208
  fromBaseUnit(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
193
209
  (dca?.tokenType === TokenType.Debt ? debtPrice : supplyPrice);
@@ -218,6 +234,11 @@ export function getRebalanceValues(
218
234
  adjustmentFeeBps
219
235
  );
220
236
 
237
+ consoleLog(
238
+ "Target rate:",
239
+ targetRateBps,
240
+ maxBoostToBps(state.maxLtvBps, state.liqThresholdBps)
241
+ );
221
242
  const maxRepayTo = maxRepayToBps(state.maxLtvBps, state.liqThresholdBps);
222
243
  return {
223
244
  debtAdjustmentUsd,
@@ -234,6 +255,7 @@ export function getRebalanceValues(
234
255
  : "repay",
235
256
  rebalanceDirection,
236
257
  feesUsd: Math.abs(debtAdjustmentUsd * fromBps(adjustmentFeeBps)),
258
+ targetRateBps,
237
259
  };
238
260
  }
239
261
 
@@ -402,8 +424,13 @@ export async function getJupSwapRebalanceDetails(
402
424
  );
403
425
  priceImpact = res.priceImpact;
404
426
  jupQuote = res.quote;
405
- inputAmount = BigInt(parseInt(res.quote.inAmount)) + BigInt(Math.round(Number(inputAmount) * 0.001));
406
- } while (parseInt(jupQuote.outAmount) < outputAmount && priceImpact > 0.001);
427
+ inputAmount =
428
+ BigInt(parseInt(res.quote.inAmount)) +
429
+ BigInt(Math.round(Number(inputAmount) * 0.001));
430
+ } while (
431
+ parseInt(jupQuote.outAmount) < outputAmount &&
432
+ priceImpact > 0.001
433
+ );
407
434
  }
408
435
 
409
436
  const addPadding = exactOut;
@@ -3,12 +3,16 @@ 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,
9
10
  } from "../../src/generated";
10
11
  import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
11
12
  import {
13
+ bytesToI80F48,
14
+ getLiqUtilzationRateBps,
15
+ getMaxLiqUtilizationRateBps,
12
16
  maxBoostToBps,
13
17
  maxRepayFromBps,
14
18
  maxRepayToBps,
@@ -21,17 +25,20 @@ import {
21
25
  } from "../../src/transactions/transactionsManager";
22
26
  import { PublicKey } from "@solana/web3.js";
23
27
  import {
24
- INF,
28
+ DEFAULT_MARGINFI_GROUP,
29
+ MARGINFI_ACCOUNTS,
25
30
  SOLAUTO_PROD_PROGRAM,
26
31
  SOLAUTO_TEST_PROGRAM,
27
32
  USDC,
33
+ USDT,
28
34
  } from "../../src/constants";
29
35
  import {
30
36
  buildHeliusApiUrl,
31
- fetchTokenPrices,
32
- getJupPriceData,
37
+ getAllPositionsByAuthority,
33
38
  getQnComputeUnitPriceEstimate,
34
39
  getSolautoManagedPositions,
40
+ getSolautoPositionAccount,
41
+ retryWithExponentialBackoff,
35
42
  } from "../../src/utils";
36
43
  import { PriorityFeeSetting } from "../../src/types";
37
44
  import { buildIronforgeApiUrl } from "../../dist";
@@ -56,23 +63,18 @@ describe("Solauto Marginfi tests", async () => {
56
63
  const supplyDecimals = 6;
57
64
  const debtDecimals = 6;
58
65
 
59
- // await client.initialize({
60
- // signer,
61
- // positionId,
62
- // authority: new PublicKey("He4ka5Q3N1UvZikZvykdi47xyk5PoVP2tcQL5sVp31Sz"),
63
- // // new: true,
64
- // // marginfiAccount: new PublicKey(
65
- // // ""
66
- // // ),
67
- // // marginfiGroup: new PublicKey(""),
68
- // // supplyMint: new PublicKey(""),
69
- // // debtMint: new PublicKey(USDC),
70
- // });
71
-
72
- console.log(
73
- JSON.stringify(await getJupPriceData([new PublicKey(INF)], true), null, 2)
74
- );
75
- return;
66
+ await client.initialize({
67
+ signer,
68
+ positionId,
69
+ authority: new PublicKey("7F6v4HWZsyFP6yVFq92HQWygUgoYm5khUX8pXWGLoqUN"),
70
+ // new: true,
71
+ // marginfiAccount: new PublicKey(
72
+ // ""
73
+ // ),
74
+ // marginfiGroup: new PublicKey(""),
75
+ // supplyMint: new PublicKey(""),
76
+ // debtMint: new PublicKey(USDC),
77
+ });
76
78
 
77
79
  // console.log(
78
80
  // JSON.stringify(
@@ -102,6 +104,15 @@ describe("Solauto Marginfi tests", async () => {
102
104
  // targetBoostToBps: none(),
103
105
  // };
104
106
 
107
+ const settingParams: SolautoSettingsParametersInpArgs = {
108
+ boostToBps: client.solautoPositionSettings().boostToBps - 150,
109
+ boostGap: 50,
110
+ repayToBps: client.solautoPositionSettings().repayToBps - 150,
111
+ repayGap: 50,
112
+ automation: none(),
113
+ targetBoostToBps: none(),
114
+ };
115
+
105
116
  // if (client.solautoPositionData === null) {
106
117
  // transactionItems.push(
107
118
  // new TransactionItem(async () => {
@@ -152,10 +163,17 @@ describe("Solauto Marginfi tests", async () => {
152
163
  )
153
164
  );
154
165
 
166
+ // transactionItems.push(
167
+ // new TransactionItem(
168
+ // async () => ({ tx: client.refresh() }),
169
+ // "refresh"
170
+ // )
171
+ // );
172
+
155
173
  // transactionItems.push(
156
174
  // new TransactionItem(
157
175
  // async (attemptNum) =>
158
- // await buildSolautoRebalanceTransaction(client, settingParams.boostToBps, attemptNum),
176
+ // await buildSolautoRebalanceTransaction(client, 0, attemptNum),
159
177
  // "rebalance"
160
178
  // )
161
179
  // );