@haven-fi/solauto-sdk 1.0.310 → 1.0.312
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.
- package/dist/constants/solautoConstants.d.ts +1 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +2 -7
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +4 -2
- package/dist/transactions/transactionsManager.d.ts +3 -1
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +35 -7
- package/dist/utils/jitoUtils.d.ts +5 -0
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +98 -151
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +0 -6
- package/dist/utils/priceUtils.d.ts +1 -6
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +3 -17
- package/dist/utils/solauto/generalUtils.d.ts +1 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +10 -2
- package/dist/utils/switchboardUtils.d.ts +6 -0
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +27 -2
- package/package.json +2 -1
- package/src/constants/solautoConstants.ts +1 -6
- package/src/transactions/transactionUtils.ts +9 -3
- package/src/transactions/transactionsManager.ts +74 -7
- package/src/utils/jitoUtils.ts +166 -166
- package/src/utils/jupiterUtils.ts +0 -6
- package/src/utils/priceUtils.ts +5 -32
- package/src/utils/solauto/generalUtils.ts +23 -1
- package/src/utils/switchboardUtils.ts +58 -3
- package/tests/transactions/solautoMarginfi.ts +27 -26
@@ -14,4 +14,5 @@ export declare const PRICES: {
|
|
14
14
|
};
|
15
15
|
export declare const SOLAUTO_LUT = "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
|
16
16
|
export declare const STANDARD_LUT_ACCOUNTS: string[];
|
17
|
+
export declare const JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
|
17
18
|
//# 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;
|
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,9 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
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.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
|
-
// import { JitoRpcConnection } from "jito-ts";
|
7
6
|
const generalAccounts_1 = require("./generalAccounts");
|
8
7
|
const jupiter_sdk_1 = require("../jupiter-sdk");
|
9
8
|
exports.SOLAUTO_PROD_PROGRAM = new web3_js_1.PublicKey("AutoyKBRaHSBHy9RsmXCZMy6nNFAg5FYijrvZyQcNLV");
|
@@ -29,8 +28,4 @@ exports.STANDARD_LUT_ACCOUNTS = [
|
|
29
28
|
web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
30
29
|
jupiter_sdk_1.JUPITER_PROGRAM_ID,
|
31
30
|
].map((x) => x.toString());
|
32
|
-
|
33
|
-
// export const JITO_CONNECTION = new JitoRpcConnection(
|
34
|
-
// `https://${JITO_BLOCK_ENGINE}`,
|
35
|
-
// "finalized"
|
36
|
-
// );
|
31
|
+
exports.JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
|
@@ -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;AAmBxE,OAAO,EAAE,aAAa,EAAE,MAAM,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,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBA2CzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA4H5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EA0DxE"}
|
@@ -355,14 +355,16 @@ async function requiresRefreshBeforeRebalance(client) {
|
|
355
355
|
}
|
356
356
|
async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRateBps, attemptNum) {
|
357
357
|
client.solautoPositionState = await client.getFreshPositionState();
|
358
|
+
const supplyPrice = (0, utils_1.safeGetPrice)(client.supplyMint) ?? 0;
|
359
|
+
const debtPrice = (0, utils_1.safeGetPrice)(client.debtMint) ?? 0;
|
358
360
|
if ((client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) &&
|
359
361
|
client.livePositionUpdates.supplyAdjustment === BigInt(0)) ||
|
360
362
|
(targetLiqUtilizationRateBps === undefined &&
|
361
|
-
!(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)()))) {
|
363
|
+
!(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), supplyPrice, debtPrice, 0))) {
|
362
364
|
client.log("Not eligible for a rebalance");
|
363
365
|
return undefined;
|
364
366
|
}
|
365
|
-
const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(),
|
367
|
+
const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), supplyPrice, debtPrice, targetLiqUtilizationRateBps);
|
366
368
|
client.log("Rebalance values: ", values);
|
367
369
|
const swapDetails = (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
|
368
370
|
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
@@ -37,12 +37,13 @@ export declare class TransactionsManager {
|
|
37
37
|
private statusCallback?;
|
38
38
|
private txType?;
|
39
39
|
private priorityFeeSetting;
|
40
|
+
private atomically;
|
40
41
|
private errorsToThrow?;
|
41
42
|
private retries;
|
42
43
|
private retryDelay;
|
43
44
|
private statuses;
|
44
45
|
private lookupTables;
|
45
|
-
constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, priorityFeeSetting?: PriorityFeeSetting, errorsToThrow?: ErrorsToThrow | undefined, retries?: number, retryDelay?: number);
|
46
|
+
constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, priorityFeeSetting?: PriorityFeeSetting, atomically?: boolean, errorsToThrow?: ErrorsToThrow | undefined, retries?: number, retryDelay?: number);
|
46
47
|
private assembleTransactionSets;
|
47
48
|
private updateStatus;
|
48
49
|
private debugAccounts;
|
@@ -51,6 +52,7 @@ export declare class TransactionsManager {
|
|
51
52
|
private updateLut;
|
52
53
|
clientSend(transactions: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
53
54
|
send(items: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
55
|
+
private processTransactionsAtomically;
|
54
56
|
private processTransactionSet;
|
55
57
|
private refreshItemSet;
|
56
58
|
private sendTransaction;
|
@@ -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,EACL,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;AAW7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAMjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IARtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACjB,WAAW,EAAE,OAAO,CAAS;gBAG3B,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAKV,OAAO,CAAC,UAAU,EAAE,MAAM;IAMhC,cAAc,IAAI,MAAM,EAAE;CAY3B;AAmFD,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;
|
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,EACL,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;AAW7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAMjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IARtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACjB,WAAW,EAAE,OAAO,CAAS;gBAG3B,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UA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C,0BAA0B,CAAC;IA0FzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YAmCxB,6BAA6B;YA8D7B,qBAAqB;YAuDrB,cAAc;YAqCd,eAAe;CAmD9B"}
|
@@ -13,7 +13,7 @@ const types_1 = require("../types");
|
|
13
13
|
const web3_js_1 = require("@solana/web3.js");
|
14
14
|
const switchboardConstants_1 = require("../constants/switchboardConstants");
|
15
15
|
const utils_1 = require("../utils");
|
16
|
-
|
16
|
+
const jitoUtils_1 = require("../utils/jitoUtils");
|
17
17
|
const CHORES_TX_NAME = "account chores";
|
18
18
|
class TransactionTooLargeError extends Error {
|
19
19
|
constructor(message) {
|
@@ -139,11 +139,12 @@ var TransactionStatus;
|
|
139
139
|
TransactionStatus["Failed"] = "Failed";
|
140
140
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
141
141
|
class TransactionsManager {
|
142
|
-
constructor(txHandler, statusCallback, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, errorsToThrow, retries = 4, retryDelay = 150) {
|
142
|
+
constructor(txHandler, statusCallback, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, atomically = false, errorsToThrow, retries = 4, retryDelay = 150) {
|
143
143
|
this.txHandler = txHandler;
|
144
144
|
this.statusCallback = statusCallback;
|
145
145
|
this.txType = txType;
|
146
146
|
this.priorityFeeSetting = priorityFeeSetting;
|
147
|
+
this.atomically = atomically;
|
147
148
|
this.errorsToThrow = errorsToThrow;
|
148
149
|
this.retries = retries;
|
149
150
|
this.retryDelay = retryDelay;
|
@@ -266,7 +267,7 @@ class TransactionsManager {
|
|
266
267
|
const swbOracle = allAccounts.find((x) => Object.values(switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS).includes(x ?? ""));
|
267
268
|
if (swbOracle) {
|
268
269
|
const mint = new web3_js_1.PublicKey(Object.keys(switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS).find((x) => switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[x] === swbOracle));
|
269
|
-
const stale = (await (0, utils_1.
|
270
|
+
const stale = (await (0, utils_1.getSwitchboardFeedData)(client.connection, [mint]))[0]
|
270
271
|
.stale;
|
271
272
|
if (stale) {
|
272
273
|
const swbTx = new TransactionItem(async () => (0, utils_1.buildSwbSubmitResponseTx)(client.connection, client.signer, mint), items.length === 1 ? "Update oracle" : "");
|
@@ -316,13 +317,40 @@ class TransactionsManager {
|
|
316
317
|
this.txHandler.log("Only simulate and more than 1 transaction. Skipping...");
|
317
318
|
return [];
|
318
319
|
}
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
320
|
+
if (itemSets.length > 1 && this.atomically) {
|
321
|
+
await this.processTransactionsAtomically(itemSets);
|
322
|
+
}
|
323
|
+
else {
|
324
|
+
let currentIndex = 0;
|
325
|
+
while (currentIndex < itemSets.length) {
|
326
|
+
await this.processTransactionSet(itemSets, currentIndex);
|
327
|
+
currentIndex++;
|
328
|
+
}
|
323
329
|
}
|
324
330
|
return this.statuses;
|
325
331
|
}
|
332
|
+
async processTransactionsAtomically(itemSets) {
|
333
|
+
let num = 0;
|
334
|
+
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => {
|
335
|
+
num = attemptNum;
|
336
|
+
let transactions = [];
|
337
|
+
for (const set of itemSets) {
|
338
|
+
transactions.push(await set.getSingleTransaction());
|
339
|
+
}
|
340
|
+
itemSets.forEach((x) => this.updateStatus(x.name(), TransactionStatus.Processing, attemptNum));
|
341
|
+
const txSigs = await (0, jitoUtils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.signer, transactions, false, this.priorityFeeSetting);
|
342
|
+
if (txSigs) {
|
343
|
+
itemSets.forEach((x, i) => this.updateStatus(x.name(), TransactionStatus.Successful, attemptNum, txSigs[i]));
|
344
|
+
}
|
345
|
+
else {
|
346
|
+
itemSets.forEach((x) => this.updateStatus(x.name(), TransactionStatus.Failed, attemptNum, undefined, true));
|
347
|
+
throw new Error("Unknown error");
|
348
|
+
}
|
349
|
+
}, this.retries, this.retryDelay, this.errorsToThrow).catch((e) => {
|
350
|
+
itemSets.forEach((x) => this.updateStatus(x.name(), TransactionStatus.Failed, num, undefined, true, e.message));
|
351
|
+
throw e;
|
352
|
+
});
|
353
|
+
}
|
326
354
|
async processTransactionSet(itemSets, currentIndex) {
|
327
355
|
let itemSet = itemSets[currentIndex];
|
328
356
|
let num = 0;
|
@@ -1 +1,6 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
2
|
+
import { Signer, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
3
|
+
import { PriorityFeeSetting } from "../types";
|
4
|
+
export declare function getRandomTipAccount(): Promise<PublicKey>;
|
5
|
+
export declare function sendJitoBundledTransactions(umi: Umi, signer: Signer, txs: TransactionBuilder[], simulateOnly?: boolean, priorityFeeSetting?: PriorityFeeSetting): Promise<string[] | undefined>;
|
1
6
|
//# sourceMappingURL=jitoUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":""}
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwB,MAAM,iBAAiB,CAAC;AAGlE,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAI9C,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AA2GD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,kBAAkB,EAAE,EACzB,YAAY,CAAC,EAAE,OAAO,EACtB,kBAAkB,GAAE,kBAA2C,GAC9D,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CA0C/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -1,64 +1,35 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
// }
|
34
|
-
// export async function getRandomTipAccount(): Promise<PublicKey> {
|
35
|
-
// const tipAccounts = await getSearcherClient().getTipAccounts();
|
36
|
-
// const randomInt = Math.floor(Math.random() * tipAccounts.length);
|
37
|
-
// return new PublicKey(tipAccounts[randomInt]);
|
38
|
-
// }
|
39
|
-
// export async function waitUntilJitoNextLeader(
|
40
|
-
// distanceFromJitoSlot: number = 5
|
41
|
-
// ) {
|
42
|
-
// let searcher = getSearcherClient();
|
43
|
-
// let isLeaderSlot = false;
|
44
|
-
// while (!isLeaderSlot) {
|
45
|
-
// const nextLeader = await searcher.getNextScheduledLeader();
|
46
|
-
// const numSlots = nextLeader.nextLeaderSlot - nextLeader.currentSlot;
|
47
|
-
// isLeaderSlot = numSlots <= distanceFromJitoSlot && numSlots > 1;
|
48
|
-
// consoleLog(`Next jito leader slot in ${numSlots} slots`);
|
49
|
-
// await new Promise((r) => setTimeout(r, 500));
|
50
|
-
// }
|
51
|
-
// }
|
52
|
-
// async function getTipInstruction(
|
53
|
-
// client: SolautoClient,
|
54
|
-
// tipLamports: number
|
55
|
-
// ): Promise<WrappedInstruction> {
|
56
|
-
// return systemTransferUmiIx(
|
57
|
-
// client.signer,
|
58
|
-
// await getRandomTipAccount(),
|
59
|
-
// BigInt(tipLamports)
|
60
|
-
// );
|
61
|
-
// }
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.getRandomTipAccount = getRandomTipAccount;
|
7
|
+
exports.sendJitoBundledTransactions = sendJitoBundledTransactions;
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
9
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
10
|
+
const solautoConstants_1 = require("../constants/solautoConstants");
|
11
|
+
const solanaUtils_1 = require("./solanaUtils");
|
12
|
+
const generalUtils_1 = require("./generalUtils");
|
13
|
+
const types_1 = require("../types");
|
14
|
+
const axios_1 = __importDefault(require("axios"));
|
15
|
+
const bs58_1 = __importDefault(require("bs58"));
|
16
|
+
async function getRandomTipAccount() {
|
17
|
+
const tipAccounts = [
|
18
|
+
"96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
|
19
|
+
"HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
|
20
|
+
"Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY",
|
21
|
+
"ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49",
|
22
|
+
"DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
|
23
|
+
"ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt",
|
24
|
+
"DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL",
|
25
|
+
"3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT",
|
26
|
+
];
|
27
|
+
const randomInt = Math.floor(Math.random() * tipAccounts.length);
|
28
|
+
return new web3_js_1.PublicKey(tipAccounts[randomInt]);
|
29
|
+
}
|
30
|
+
async function getTipInstruction(signer, tipLamports) {
|
31
|
+
return (0, solanaUtils_1.systemTransferUmiIx)(signer, await getRandomTipAccount(), BigInt(tipLamports));
|
32
|
+
}
|
62
33
|
// async function simulateJitoBundle(
|
63
34
|
// txs: VersionedTransaction[]
|
64
35
|
// ): Promise<SimulatedBundleTransactionResult[]> {
|
@@ -77,94 +48,70 @@
|
|
77
48
|
// });
|
78
49
|
// return simulationResult.value.transactionResults;
|
79
50
|
// }
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
//
|
132
|
-
|
133
|
-
//
|
134
|
-
//
|
135
|
-
|
136
|
-
//
|
137
|
-
//
|
138
|
-
//
|
139
|
-
//
|
140
|
-
//
|
141
|
-
//
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
// client.signer,
|
148
|
-
// txs,
|
149
|
-
// feeEstimates,
|
150
|
-
// // Array(txs.length).fill(1_400_000)
|
151
|
-
// );
|
152
|
-
// // // TODO: Skip over this for now, and instead don't specify a compute unit limit in the final bundle transactions
|
153
|
-
// // const simulationResults = await simulateJitoBundle(builtTxs);
|
154
|
-
// if (!simulateOnly) {
|
155
|
-
// // let builtTxs = await umiToVersionedTransactions(
|
156
|
-
// // client.signer,
|
157
|
-
// // txs,
|
158
|
-
// // feeEstimates,
|
159
|
-
// // simulationResults.map((x) => x.unitsConsumed! * 1.15)
|
160
|
-
// // );
|
161
|
-
// const bundleResult = await sendJitoBundle(
|
162
|
-
// new Bundle(builtTxs, 100)
|
163
|
-
// );
|
164
|
-
// return {
|
165
|
-
// bundleResult,
|
166
|
-
// txSigs: builtTxs.map((x) => x.signatures).flat(),
|
167
|
-
// };
|
168
|
-
// }
|
169
|
-
// return undefined;
|
170
|
-
// }
|
51
|
+
async function umiToVersionedTransactions(umi, signer, txs, feeEstimates, computeUnitLimits) {
|
52
|
+
return await Promise.all(txs.map(async (tx, i) => {
|
53
|
+
const versionedTx = (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await (0, solanaUtils_1.assembleFinalTransaction)(signer, tx, feeEstimates[i], computeUnitLimits ? computeUnitLimits[i] : undefined).setLatestBlockhash(umi)).buildAndSign(umi));
|
54
|
+
return versionedTx;
|
55
|
+
}));
|
56
|
+
}
|
57
|
+
async function getBundleStatus(bundleId) {
|
58
|
+
const res = await axios_1.default.post(`${solautoConstants_1.JITO_BLOCK_ENGINE}/api/v1/bundles`, {
|
59
|
+
jsonrpc: "2.0",
|
60
|
+
id: 1,
|
61
|
+
method: "getBundleStatuses",
|
62
|
+
params: [[bundleId]],
|
63
|
+
});
|
64
|
+
if (res.data.error) {
|
65
|
+
throw new Error(`Failed to get bundle status: ${res.data.error}`);
|
66
|
+
}
|
67
|
+
return res.data.result;
|
68
|
+
}
|
69
|
+
async function pollBundleStatus(bundleId, interval = 1000, timeout = 40000) {
|
70
|
+
const endTime = Date.now() + timeout;
|
71
|
+
while (Date.now() < endTime) {
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
73
|
+
const statuses = await getBundleStatus(bundleId);
|
74
|
+
if (statuses?.value?.length > 0) {
|
75
|
+
const status = statuses.value[0].confirmation_status;
|
76
|
+
if (status === "confirmed") {
|
77
|
+
return statuses?.value[0].transactions;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
return [];
|
82
|
+
}
|
83
|
+
async function sendJitoBundle(transactions) {
|
84
|
+
(0, generalUtils_1.consoleLog)("Sending bundle...");
|
85
|
+
const resp = await axios_1.default.post(`${solautoConstants_1.JITO_BLOCK_ENGINE}/api/v1/bundles`, {
|
86
|
+
jsonrpc: "2.0",
|
87
|
+
id: 1,
|
88
|
+
method: "sendBundle",
|
89
|
+
params: [transactions],
|
90
|
+
});
|
91
|
+
const bundleId = resp.data.result;
|
92
|
+
return await pollBundleStatus(bundleId);
|
93
|
+
}
|
94
|
+
async function sendJitoBundledTransactions(umi, signer, txs, simulateOnly, priorityFeeSetting = types_1.PriorityFeeSetting.Min) {
|
95
|
+
(0, generalUtils_1.consoleLog)("Sending Jito bundle...");
|
96
|
+
(0, generalUtils_1.consoleLog)("Transactions: ", txs.length);
|
97
|
+
(0, generalUtils_1.consoleLog)("Transaction sizes: ", txs.map((x) => x.getTransactionSize(umi)));
|
98
|
+
txs[0] = txs[0].prepend(await getTipInstruction(signer, 150000));
|
99
|
+
const feeEstimates = await Promise.all(txs.map(async (x) => (await (0, solanaUtils_1.getComputeUnitPriceEstimate)(umi, x, priorityFeeSetting)) ??
|
100
|
+
1000000));
|
101
|
+
let builtTxs = await umiToVersionedTransactions(umi, signer, txs, feeEstimates
|
102
|
+
// Array(txs.length).fill(1_400_000)
|
103
|
+
);
|
104
|
+
// // TODO: Skip over this for now, and instead don't specify a compute unit limit in the final bundle transactions
|
105
|
+
// const simulationResults = await simulateJitoBundle(builtTxs);
|
106
|
+
if (!simulateOnly) {
|
107
|
+
// let builtTxs = await umiToVersionedTransactions(
|
108
|
+
// client.signer,
|
109
|
+
// txs,
|
110
|
+
// feeEstimates,
|
111
|
+
// simulationResults.map((x) => x.unitsConsumed! * 1.15)
|
112
|
+
// );
|
113
|
+
const txSigs = await sendJitoBundle(builtTxs.map((x) => bs58_1.default.encode(x.serialize())));
|
114
|
+
return txSigs.length > 0 ? txSigs : undefined;
|
115
|
+
}
|
116
|
+
return undefined;
|
117
|
+
}
|
@@ -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;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,
|
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;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,CA6F7B"}
|
@@ -45,12 +45,6 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
45
45
|
quoteResponse.inAmount = (parseInt(quoteResponse.inAmount) +
|
46
46
|
Math.ceil(parseInt(quoteResponse.inAmount) * (0, numberUtils_1.fromBps)(finalPriceSlippageBps))).toString();
|
47
47
|
}
|
48
|
-
// else {
|
49
|
-
// quoteResponse.inAmount = (
|
50
|
-
// parseInt(quoteResponse.inAmount) +
|
51
|
-
// Math.ceil(parseInt(quoteResponse.inAmount) * fromBps(priceImpactBps))
|
52
|
-
// ).toString();
|
53
|
-
// }
|
54
48
|
(0, generalUtils_1.consoleLog)("Getting jup instructions...");
|
55
49
|
const instructions = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.swapInstructionsPost({
|
56
50
|
swapRequest: {
|
@@ -1,12 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { PublicKey as UmiPublicKey } from "@metaplex-foundation/umi";
|
3
3
|
export declare function fetchTokenPrices(mints: PublicKey[]): Promise<number[]>;
|
4
4
|
export declare function getPythPrices(mints: PublicKey[]): Promise<number[]>;
|
5
|
-
export declare function getSwitchboardPrices(conn: Connection, mints: PublicKey[]): Promise<{
|
6
|
-
mint: PublicKey;
|
7
|
-
price: number;
|
8
|
-
stale: boolean;
|
9
|
-
}[]>;
|
10
5
|
export declare function safeGetPrice(mint: PublicKey | UmiPublicKey | undefined): number | undefined;
|
11
6
|
export declare function getJupTokenPrices(mints: PublicKey[]): Promise<number[]>;
|
12
7
|
//# sourceMappingURL=priceUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
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;AAYrE,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAqCnB;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAGD,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,qBAoBzD"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.fetchTokenPrices = fetchTokenPrices;
|
4
4
|
exports.getPythPrices = getPythPrices;
|
5
|
-
exports.getSwitchboardPrices = getSwitchboardPrices;
|
6
5
|
exports.safeGetPrice = safeGetPrice;
|
7
6
|
exports.getJupTokenPrices = getJupTokenPrices;
|
8
7
|
const pythConstants_1 = require("../constants/pythConstants");
|
@@ -21,7 +20,7 @@ async function fetchTokenPrices(mints) {
|
|
21
20
|
const switchboardMints = mints.filter((x) => x.toString() in switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS);
|
22
21
|
const [pythData, switchboardData] = await Promise.all([
|
23
22
|
(0, generalUtils_1.zip)(pythMints, await getPythPrices(pythMints)),
|
24
|
-
(0, generalUtils_1.zip)(switchboardMints, await
|
23
|
+
(0, generalUtils_1.zip)(switchboardMints, await (0, switchboardUtils_1.getSwitchboardPrices)(switchboardMints)),
|
25
24
|
]);
|
26
25
|
const prices = mints.map((mint) => {
|
27
26
|
const item = [...pythData, ...switchboardData].find((data) => data[0].equals(mint));
|
@@ -63,33 +62,20 @@ async function getPythPrices(mints) {
|
|
63
62
|
}, 5, 200);
|
64
63
|
return prices;
|
65
64
|
}
|
66
|
-
async function getSwitchboardPrices(conn, mints) {
|
67
|
-
if (mints.length === 0) {
|
68
|
-
return [];
|
69
|
-
}
|
70
|
-
const currSlot = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await conn.getSlot("confirmed"), 5);
|
71
|
-
const results = await Promise.all(mints.map(async (mint) => {
|
72
|
-
const feed = (0, switchboardUtils_1.getPullFeed)(conn, mint);
|
73
|
-
const result = await feed.loadData();
|
74
|
-
const price = Number(result.result.value) / Math.pow(10, 18);
|
75
|
-
const stale = currSlot > result.result.slot.toNumber() + result.maxStaleness;
|
76
|
-
return { mint, price, stale };
|
77
|
-
}));
|
78
|
-
return results;
|
79
|
-
}
|
80
65
|
function safeGetPrice(mint) {
|
81
66
|
if (mint && mint?.toString() in solautoConstants_1.PRICES) {
|
82
67
|
return solautoConstants_1.PRICES[mint.toString()].price;
|
83
68
|
}
|
84
69
|
return undefined;
|
85
70
|
}
|
71
|
+
// LEGACY, NOT USED
|
86
72
|
async function getJupTokenPrices(mints) {
|
87
73
|
if (mints.length == 0) {
|
88
74
|
return [];
|
89
75
|
}
|
90
76
|
const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
91
77
|
const res = (await fetch("https://api.jup.ag/price/v2?ids=" +
|
92
|
-
mints.map((x) => x.toString()).join(","))).json();
|
78
|
+
mints.map((x) => x.toString()).join(",") + "&showExtraInfo=true")).json();
|
93
79
|
return res;
|
94
80
|
}, 6);
|
95
81
|
const prices = Object.values(data.data).map((x) => parseFloat(x.price));
|
@@ -7,7 +7,7 @@ export declare function nextAutomationPeriodTimestamp(automation: AutomationSett
|
|
7
7
|
export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings, currentUnixTime: number): boolean;
|
8
8
|
export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
|
9
9
|
export declare function getAdjustedSettingsFromAutomation(settings: SolautoSettingsParameters, currentUnixTime: number): SolautoSettingsParameters;
|
10
|
-
export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters | undefined, positionDca: DCASettings | undefined, currentUnixTime: number, bpsDistanceThreshold?: number): RebalanceAction | undefined;
|
10
|
+
export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters | undefined, positionDca: DCASettings | undefined, currentUnixTime: number, supplyMintPrice: number, debtMintPrice: number, bpsDistanceThreshold?: number): RebalanceAction | undefined;
|
11
11
|
export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters, currentUnixTime: number): boolean;
|
12
12
|
export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey, positionTypeFilter?: PositionType): Promise<SolautoPositionDetails[]>;
|
13
13
|
export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,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,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,aAAa,CAoEf;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,gCAAgC,GACzC,yBAAyB,CA8B3B;AAED,KAAK,kBAAkB,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAA;KAAE,CAAA;CAAE,GACzE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEhD,qBAAa,mBAAmB;IACvB,gBAAgB,SAAa;IAC7B,cAAc,SAAa;IAC3B,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAC/C,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAA;KAAE,CAAa;IACpE,aAAa,EAAE,SAAS,GAAG,SAAS,CAAa;IAExD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IA6B9B,KAAK;IASL,UAAU,IAAI,OAAO;CAStB"}
|
@@ -25,6 +25,7 @@ const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters"
|
|
25
25
|
const constants_1 = require("../../constants");
|
26
26
|
const marginfiUtils_1 = require("../marginfiUtils");
|
27
27
|
const priceUtils_1 = require("../priceUtils");
|
28
|
+
const rebalanceUtils_1 = require("./rebalanceUtils");
|
28
29
|
function createDynamicSolautoProgram(programId) {
|
29
30
|
return {
|
30
31
|
name: "solauto",
|
@@ -72,7 +73,7 @@ function getAdjustedSettingsFromAutomation(settings, currentUnixTime) {
|
|
72
73
|
boostToBps,
|
73
74
|
};
|
74
75
|
}
|
75
|
-
function eligibleForRebalance(positionState, positionSettings, positionDca, currentUnixTime, bpsDistanceThreshold = 0) {
|
76
|
+
function eligibleForRebalance(positionState, positionSettings, positionDca, currentUnixTime, supplyMintPrice, debtMintPrice, bpsDistanceThreshold = 0) {
|
76
77
|
if (!positionSettings) {
|
77
78
|
return undefined;
|
78
79
|
}
|
@@ -92,7 +93,14 @@ function eligibleForRebalance(positionState, positionSettings, positionDca, curr
|
|
92
93
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
93
94
|
if (Math.max(0, positionState.liqUtilizationRateBps - boostFrom) <=
|
94
95
|
bpsDistanceThreshold) {
|
95
|
-
|
96
|
+
const values = (0, rebalanceUtils_1.getRebalanceValues)(positionState, positionSettings, positionDca, (0, generalUtils_1.currentUnixSeconds)(), supplyMintPrice, debtMintPrice);
|
97
|
+
const sufficientLiquidity = (0, numberUtils_1.fromBaseUnit)(positionState.debt.amountCanBeUsed.baseAmountUsdValue, constants_1.USD_DECIMALS) *
|
98
|
+
0.95 >
|
99
|
+
values.debtAdjustmentUsd;
|
100
|
+
if (!sufficientLiquidity) {
|
101
|
+
console.log("Insufficient debt liquidity to further boost");
|
102
|
+
}
|
103
|
+
return sufficientLiquidity ? "boost" : undefined;
|
96
104
|
}
|
97
105
|
else if (Math.max(0, repayFrom - positionState.liqUtilizationRateBps) <=
|
98
106
|
bpsDistanceThreshold) {
|
@@ -4,4 +4,10 @@ import { TransactionItemInputs } from "../types";
|
|
4
4
|
import { Signer } from "@metaplex-foundation/umi";
|
5
5
|
export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): PullFeed;
|
6
6
|
export declare function buildSwbSubmitResponseTx(conn: Connection, signer: Signer, mint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
7
|
+
export declare function getSwitchboardFeedData(conn: Connection, mints: PublicKey[]): Promise<{
|
8
|
+
mint: PublicKey;
|
9
|
+
price: number;
|
10
|
+
stale: boolean;
|
11
|
+
}[]>;
|
12
|
+
export declare function getSwitchboardPrices(mints: PublicKey[]): Promise<number[]>;
|
7
13
|
//# sourceMappingURL=switchboardUtils.d.ts.map
|