@haven-fi/solauto-sdk 1.0.502 → 1.0.503
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 +0 -1
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +1 -10
- package/dist/transactions/transactionUtils.d.ts +1 -2
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +3 -4
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +0 -2
- package/dist/utils/jupiterUtils.d.ts +1 -0
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +4 -22
- package/dist/utils/priceUtils.d.ts +4 -0
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +15 -0
- package/dist/utils/solauto/rebalanceUtils.d.ts +1 -2
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +16 -19
- package/package.json +1 -1
- package/src/constants/solautoConstants.ts +1 -11
- package/src/transactions/transactionUtils.ts +4 -8
- package/src/transactions/transactionsManager.ts +0 -2
- package/src/utils/jupiterUtils.ts +7 -28
- package/src/utils/priceUtils.ts +28 -1
- package/src/utils/solauto/rebalanceUtils.ts +24 -39
- package/tests/transactions/solautoMarginfi.ts +22 -40
@@ -15,5 +15,4 @@ 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[];
|
19
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,11 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
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
6
|
const generalAccounts_1 = require("./generalAccounts");
|
7
7
|
const jupiter_sdk_1 = require("../jupiter-sdk");
|
8
|
-
const tokenConstants_1 = require("./tokenConstants");
|
9
8
|
exports.SOLAUTO_PROD_PROGRAM = new web3_js_1.PublicKey("AutoyKBRaHSBHy9RsmXCZMy6nNFAg5FYijrvZyQcNLV");
|
10
9
|
exports.SOLAUTO_TEST_PROGRAM = new web3_js_1.PublicKey("TesTjfQ6TbXv96Tv6fqr95XTZ1LYPxtkafmShN9PjBp");
|
11
10
|
globalThis.LOCAL_TEST = false;
|
@@ -30,11 +29,3 @@ exports.STANDARD_LUT_ACCOUNTS = [
|
|
30
29
|
jupiter_sdk_1.JUPITER_PROGRAM_ID,
|
31
30
|
].map((x) => x.toString());
|
32
31
|
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,12 +1,11 @@
|
|
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";
|
5
4
|
import { ReferralStateManager } from "../clients";
|
6
5
|
import { TransactionItemInputs } from "../types";
|
7
6
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
8
7
|
export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
|
9
|
-
export declare function requiresRefreshBeforeRebalance(client: SolautoClient
|
8
|
+
export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
|
10
9
|
export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<TransactionItemInputs | undefined>;
|
11
10
|
export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
12
11
|
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;
|
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,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) {
|
333
333
|
const neverRefreshedBefore = client.solautoPositionData &&
|
334
334
|
client.solautoPositionData.state.supply.amountCanBeUsed.baseUnit ===
|
335
335
|
BigInt(0) &&
|
@@ -373,12 +373,11 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
373
373
|
}
|
374
374
|
const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), supplyPrice, debtPrice, targetLiqUtilizationRateBps);
|
375
375
|
client.log("Rebalance values: ", values);
|
376
|
-
const swapDetails = (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
|
376
|
+
const swapDetails = await (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
|
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
|
-
|
381
|
-
if (await requiresRefreshBeforeRebalance(client, values)) {
|
380
|
+
if (await requiresRefreshBeforeRebalance(client)) {
|
382
381
|
tx = tx.add(client.refresh());
|
383
382
|
}
|
384
383
|
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,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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BAAuB;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;
|
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,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;AA0FD,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,0BA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,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YAkCxB,6BAA6B;YAsI7B,qBAAqB;YAoDrB,eAAe;YA0Df,eAAe;CA4D9B"}
|
@@ -271,7 +271,6 @@ class TransactionsManager {
|
|
271
271
|
for (const item of items) {
|
272
272
|
await item.initialize();
|
273
273
|
}
|
274
|
-
// TODO: need better fix here
|
275
274
|
const allAccounts = items.flatMap((item) => {
|
276
275
|
return (item.tx
|
277
276
|
?.getInstructions()
|
@@ -290,7 +289,6 @@ class TransactionsManager {
|
|
290
289
|
.stale;
|
291
290
|
if (stale) {
|
292
291
|
this.txHandler.log("Requires oracle update...");
|
293
|
-
console.log(mint);
|
294
292
|
const swbTx = new TransactionItem(async () => (0, utils_1.buildSwbSubmitResponseTx)(client.connection, client.signer, mint), this.updateOracleTxName);
|
295
293
|
await swbTx.initialize();
|
296
294
|
items.unshift(swbTx);
|
@@ -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;
|
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;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;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,CAwG7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GA0B5E"}
|
@@ -25,13 +25,8 @@ function createTransactionInstruction(instruction) {
|
|
25
25
|
async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
26
26
|
const memecoinSwap = constants_1.TOKEN_INFO[swapDetails.inputMint.toString()].isMeme ||
|
27
27
|
constants_1.TOKEN_INFO[swapDetails.outputMint.toString()].isMeme;
|
28
|
-
const
|
29
|
-
|
30
|
-
const useLowAccounts = tokensWithLowAccounts.find((x) => swapDetails.inputMint.equals(new web3_js_1.PublicKey(x))) ||
|
31
|
-
tokensWithLowAccounts.find((x) => swapDetails.outputMint.equals(new web3_js_1.PublicKey(x)));
|
32
|
-
let quoteResponse;
|
33
|
-
try {
|
34
|
-
quoteResponse = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.quoteGet({
|
28
|
+
const quoteResponse = swapDetails.jupQuote ??
|
29
|
+
(await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.quoteGet({
|
35
30
|
amount: Number(swapDetails.amount),
|
36
31
|
inputMint: swapDetails.inputMint.toString(),
|
37
32
|
outputMint: swapDetails.outputMint.toString(),
|
@@ -41,21 +36,8 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
41
36
|
? "ExactIn"
|
42
37
|
: undefined,
|
43
38
|
slippageBps: memecoinSwap ? 500 : 200,
|
44
|
-
maxAccounts: !swapDetails.exactOut
|
45
|
-
|
46
|
-
? 15
|
47
|
-
: 40
|
48
|
-
: undefined,
|
49
|
-
}), 4, 200);
|
50
|
-
}
|
51
|
-
catch (e) {
|
52
|
-
if (swapDetails.exactOut) {
|
53
|
-
// Failed to find exact out route, try exact in
|
54
|
-
swapDetails.exactIn = true;
|
55
|
-
return await getJupSwapTransaction(signer, swapDetails, attemptNum);
|
56
|
-
}
|
57
|
-
throw e;
|
58
|
-
}
|
39
|
+
maxAccounts: !swapDetails.exactOut ? 40 : undefined,
|
40
|
+
}), 4, 200));
|
59
41
|
const priceImpactBps = Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1;
|
60
42
|
const finalPriceSlippageBps = Math.round(Math.max(50, quoteResponse.slippageBps, priceImpactBps) *
|
61
43
|
(1 + (swapDetails.slippageIncFactor ?? 0)));
|
@@ -5,4 +5,8 @@ export declare function getPythPrices(mints: PublicKey[]): Promise<number[]>;
|
|
5
5
|
export declare function getSwitchboardPrices(mints: PublicKey[]): Promise<number[]>;
|
6
6
|
export declare function getJupTokenPrices(mints: PublicKey[]): Promise<number[]>;
|
7
7
|
export declare function safeGetPrice(mint: PublicKey | UmiPublicKey | undefined): number | undefined;
|
8
|
+
export declare function getPriceImpact(inputMint: PublicKey, inputAmount: bigint, outputMint: PublicKey): Promise<{
|
9
|
+
priceImpact: number;
|
10
|
+
quote: import("@jup-ag/api").QuoteResponse;
|
11
|
+
}>;
|
8
12
|
//# 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,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
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"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -28,6 +28,7 @@ exports.getPythPrices = getPythPrices;
|
|
28
28
|
exports.getSwitchboardPrices = getSwitchboardPrices;
|
29
29
|
exports.getJupTokenPrices = getJupTokenPrices;
|
30
30
|
exports.safeGetPrice = safeGetPrice;
|
31
|
+
exports.getPriceImpact = getPriceImpact;
|
31
32
|
const pythConstants_1 = require("../constants/pythConstants");
|
32
33
|
const numberUtils_1 = require("./numberUtils");
|
33
34
|
const solautoConstants_1 = require("../constants/solautoConstants");
|
@@ -35,6 +36,7 @@ const switchboardConstants_1 = require("../constants/switchboardConstants");
|
|
35
36
|
const generalUtils_1 = require("./generalUtils");
|
36
37
|
const OnDemand = __importStar(require("@switchboard-xyz/on-demand"));
|
37
38
|
const jupiterUtils_1 = require("./jupiterUtils");
|
39
|
+
const api_1 = require("@jup-ag/api");
|
38
40
|
async function fetchTokenPrices(mints) {
|
39
41
|
const currentTime = (0, generalUtils_1.currentUnixSeconds)();
|
40
42
|
if (!mints.some((mint) => !(mint.toString() in solautoConstants_1.PRICES) ||
|
@@ -128,3 +130,16 @@ function safeGetPrice(mint) {
|
|
128
130
|
}
|
129
131
|
return undefined;
|
130
132
|
}
|
133
|
+
async function getPriceImpact(inputMint, inputAmount, outputMint) {
|
134
|
+
const jupApi = (0, api_1.createJupiterApiClient)();
|
135
|
+
const quoteResponse = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.quoteGet({
|
136
|
+
amount: Number(inputAmount),
|
137
|
+
inputMint: inputMint.toString(),
|
138
|
+
outputMint: outputMint.toString(),
|
139
|
+
swapMode: "ExactIn",
|
140
|
+
}), 4, 200);
|
141
|
+
return {
|
142
|
+
priceImpact: parseFloat(quoteResponse.priceImpactPct),
|
143
|
+
quote: quoteResponse,
|
144
|
+
};
|
145
|
+
}
|
@@ -13,7 +13,6 @@ export interface RebalanceValues {
|
|
13
13
|
rebalanceAction: RebalanceAction;
|
14
14
|
rebalanceDirection: RebalanceDirection;
|
15
15
|
feesUsd: number;
|
16
|
-
targetRateBps: number;
|
17
16
|
}
|
18
17
|
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): RebalanceValues;
|
19
18
|
export declare function rebalanceRequiresFlashLoan(client: SolautoClient, values: RebalanceValues): {
|
@@ -26,5 +25,5 @@ export interface FlashLoanDetails {
|
|
26
25
|
useDebtLiquidity: boolean;
|
27
26
|
}
|
28
27
|
export declare function getFlashLoanDetails(client: SolautoClient, values: RebalanceValues, jupQuote: QuoteResponse): FlashLoanDetails | undefined;
|
29
|
-
export declare function getJupSwapRebalanceDetails(client: SolautoClient, values: RebalanceValues, targetLiqUtilizationRateBps?: number, attemptNum?: number): JupSwapDetails
|
28
|
+
export declare function getJupSwapRebalanceDetails(client: SolautoClient, values: RebalanceValues, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<JupSwapDetails>;
|
30
29
|
//# sourceMappingURL=rebalanceUtils.d.ts.map
|
@@ -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;
|
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,E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,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,cAAc,CAAC,CA2EzB"}
|
@@ -4,7 +4,6 @@ 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");
|
8
7
|
const generated_1 = require("../../generated");
|
9
8
|
const generalUtils_1 = require("./generalUtils");
|
10
9
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
@@ -12,7 +11,6 @@ const generalUtils_2 = require("../generalUtils");
|
|
12
11
|
const numberUtils_1 = require("../numberUtils");
|
13
12
|
const generalAccounts_1 = require("../../constants/generalAccounts");
|
14
13
|
const priceUtils_1 = require("../priceUtils");
|
15
|
-
const constants_1 = require("../../constants");
|
16
14
|
function getAdditionalAmountToDcaIn(dca) {
|
17
15
|
if (dca.dcaInBaseUnit === BigInt(0)) {
|
18
16
|
return 0;
|
@@ -84,18 +82,7 @@ function getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, target
|
|
84
82
|
}
|
85
83
|
}
|
86
84
|
function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
|
87
|
-
|
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
|
-
}
|
85
|
+
const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, targetLiqUtilizationRateBps);
|
99
86
|
const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
|
100
87
|
(dca?.tokenType === generated_1.TokenType.Debt ? debtPrice : supplyPrice);
|
101
88
|
const rebalanceDirection = amountUsdToDcaIn > 0 || state.liqUtilizationRateBps <= targetRateBps
|
@@ -106,7 +93,6 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
106
93
|
amountUsdToDcaIn;
|
107
94
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(state.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
108
95
|
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));
|
110
96
|
const maxRepayTo = (0, numberUtils_1.maxRepayToBps)(state.maxLtvBps, state.liqThresholdBps);
|
111
97
|
return {
|
112
98
|
debtAdjustmentUsd,
|
@@ -121,7 +107,6 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
121
107
|
: "repay",
|
122
108
|
rebalanceDirection,
|
123
109
|
feesUsd: Math.abs(debtAdjustmentUsd * (0, numberUtils_1.fromBps)(adjustmentFeeBps)),
|
124
|
-
targetRateBps,
|
125
110
|
};
|
126
111
|
}
|
127
112
|
function rebalanceRequiresFlashLoan(client, values) {
|
@@ -173,7 +158,7 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
173
158
|
}
|
174
159
|
: undefined;
|
175
160
|
}
|
176
|
-
function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps, attemptNum) {
|
161
|
+
async function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps, attemptNum) {
|
177
162
|
const input = values.rebalanceDirection === generated_1.RebalanceDirection.Boost
|
178
163
|
? client.solautoPositionState.debt
|
179
164
|
: client.solautoPositionState.supply;
|
@@ -192,9 +177,20 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
192
177
|
const repaying = values.rebalanceDirection === generated_1.RebalanceDirection.Repay;
|
193
178
|
const { requiresFlashLoan, useDebtLiquidity } = rebalanceRequiresFlashLoan(client, values);
|
194
179
|
const flashLoanRepayFromDebt = repaying && requiresFlashLoan && useDebtLiquidity;
|
195
|
-
const exactOut =
|
196
|
-
|
180
|
+
const exactOut =
|
181
|
+
// targetLiqUtilizationRateBps === 0 ||
|
182
|
+
// values.repayingCloseToMaxLtv ||
|
183
|
+
flashLoanRepayFromDebt;
|
197
184
|
const exactIn = !exactOut;
|
185
|
+
let jupQuote = undefined;
|
186
|
+
if (targetLiqUtilizationRateBps === 0) {
|
187
|
+
let priceImpact = 0;
|
188
|
+
do {
|
189
|
+
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));
|
190
|
+
priceImpact = res.priceImpact;
|
191
|
+
jupQuote = res.quote;
|
192
|
+
} while (parseInt(jupQuote.outAmount) < outputAmount);
|
193
|
+
}
|
198
194
|
const addPadding = exactOut;
|
199
195
|
return {
|
200
196
|
inputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint),
|
@@ -207,5 +203,6 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
207
203
|
exactIn,
|
208
204
|
exactOut,
|
209
205
|
addPadding,
|
206
|
+
jupQuote,
|
210
207
|
};
|
211
208
|
}
|
package/package.json
CHANGED
@@ -11,7 +11,6 @@ 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";
|
15
14
|
|
16
15
|
export const SOLAUTO_PROD_PROGRAM = new PublicKey(
|
17
16
|
"AutoyKBRaHSBHy9RsmXCZMy6nNFAg5FYijrvZyQcNLV"
|
@@ -46,13 +45,4 @@ export const STANDARD_LUT_ACCOUNTS = [
|
|
46
45
|
JUPITER_PROGRAM_ID,
|
47
46
|
].map((x) => x.toString());
|
48
47
|
|
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
|
-
]
|
48
|
+
export const JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
|
@@ -39,7 +39,6 @@ import {
|
|
39
39
|
getFlashLoanDetails,
|
40
40
|
getJupSwapRebalanceDetails,
|
41
41
|
getRebalanceValues,
|
42
|
-
RebalanceValues,
|
43
42
|
} from "../utils/solauto/rebalanceUtils";
|
44
43
|
import {
|
45
44
|
consoleLog,
|
@@ -72,11 +71,10 @@ import {
|
|
72
71
|
getJupiterErrorFromCode,
|
73
72
|
JUPITER_PROGRAM_ID,
|
74
73
|
} from "../jupiter-sdk";
|
75
|
-
import {
|
74
|
+
import { PRICES } from "../constants";
|
76
75
|
import { TransactionItemInputs } from "../types";
|
77
76
|
import { safeGetPrice } from "../utils";
|
78
77
|
import { BundleSimulationError } from "../types/transactions";
|
79
|
-
import { getPackedSettings } from "http2";
|
80
78
|
|
81
79
|
interface wSolTokenUsage {
|
82
80
|
wSolTokenAccount: PublicKey;
|
@@ -600,7 +598,7 @@ export async function getTransactionChores(
|
|
600
598
|
return [choresBefore, choresAfter];
|
601
599
|
}
|
602
600
|
|
603
|
-
export async function requiresRefreshBeforeRebalance(client: SolautoClient
|
601
|
+
export async function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
604
602
|
const neverRefreshedBefore =
|
605
603
|
client.solautoPositionData &&
|
606
604
|
client.solautoPositionData.state.supply.amountCanBeUsed.baseUnit ===
|
@@ -692,7 +690,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
692
690
|
);
|
693
691
|
client.log("Rebalance values: ", values);
|
694
692
|
|
695
|
-
const swapDetails = getJupSwapRebalanceDetails(
|
693
|
+
const swapDetails = await getJupSwapRebalanceDetails(
|
696
694
|
client,
|
697
695
|
values,
|
698
696
|
targetLiqUtilizationRateBps,
|
@@ -705,13 +703,11 @@ export async function buildSolautoRebalanceTransaction(
|
|
705
703
|
tokenLedgerIx,
|
706
704
|
swapIx,
|
707
705
|
} = await getJupSwapTransaction(client.signer, swapDetails, attemptNum);
|
708
|
-
|
709
706
|
const flashLoan = getFlashLoanDetails(client, values, jupQuote);
|
710
707
|
|
711
708
|
let tx = transactionBuilder();
|
712
709
|
|
713
|
-
|
714
|
-
if (await requiresRefreshBeforeRebalance(client, values)) {
|
710
|
+
if (await requiresRefreshBeforeRebalance(client)) {
|
715
711
|
tx = tx.add(client.refresh());
|
716
712
|
}
|
717
713
|
|
@@ -435,7 +435,6 @@ export class TransactionsManager {
|
|
435
435
|
await item.initialize();
|
436
436
|
}
|
437
437
|
|
438
|
-
// TODO: need better fix here
|
439
438
|
const allAccounts = items.flatMap((item) => {
|
440
439
|
return (
|
441
440
|
item.tx
|
@@ -466,7 +465,6 @@ export class TransactionsManager {
|
|
466
465
|
|
467
466
|
if (stale) {
|
468
467
|
this.txHandler.log("Requires oracle update...");
|
469
|
-
console.log(mint);
|
470
468
|
const swbTx = new TransactionItem(
|
471
469
|
async () =>
|
472
470
|
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 {
|
16
|
+
import { TOKEN_INFO } from "../constants";
|
17
17
|
|
18
18
|
const jupApi = createJupiterApiClient();
|
19
19
|
|
@@ -26,6 +26,7 @@ export interface JupSwapDetails {
|
|
26
26
|
exactOut?: boolean;
|
27
27
|
exactIn?: boolean;
|
28
28
|
addPadding?: boolean;
|
29
|
+
jupQuote?: QuoteResponse;
|
29
30
|
}
|
30
31
|
|
31
32
|
function createTransactionInstruction(
|
@@ -60,19 +61,9 @@ export async function getJupSwapTransaction(
|
|
60
61
|
TOKEN_INFO[swapDetails.inputMint.toString()].isMeme ||
|
61
62
|
TOKEN_INFO[swapDetails.outputMint.toString()].isMeme;
|
62
63
|
|
63
|
-
const
|
64
|
-
|
65
|
-
|
66
|
-
tokensWithLowAccounts.find((x) =>
|
67
|
-
swapDetails.inputMint.equals(new PublicKey(x))
|
68
|
-
) ||
|
69
|
-
tokensWithLowAccounts.find((x) =>
|
70
|
-
swapDetails.outputMint.equals(new PublicKey(x))
|
71
|
-
);
|
72
|
-
|
73
|
-
let quoteResponse: QuoteResponse;
|
74
|
-
try {
|
75
|
-
quoteResponse = await retryWithExponentialBackoff(
|
64
|
+
const quoteResponse =
|
65
|
+
swapDetails.jupQuote ??
|
66
|
+
(await retryWithExponentialBackoff(
|
76
67
|
async () =>
|
77
68
|
await jupApi.quoteGet({
|
78
69
|
amount: Number(swapDetails.amount),
|
@@ -84,23 +75,11 @@ export async function getJupSwapTransaction(
|
|
84
75
|
? "ExactIn"
|
85
76
|
: undefined,
|
86
77
|
slippageBps: memecoinSwap ? 500 : 200,
|
87
|
-
maxAccounts: !swapDetails.exactOut
|
88
|
-
? useLowAccounts
|
89
|
-
? 15
|
90
|
-
: 40
|
91
|
-
: undefined,
|
78
|
+
maxAccounts: !swapDetails.exactOut ? 40 : undefined,
|
92
79
|
}),
|
93
80
|
4,
|
94
81
|
200
|
95
|
-
);
|
96
|
-
} catch (e) {
|
97
|
-
if (swapDetails.exactOut) {
|
98
|
-
// Failed to find exact out route, try exact in
|
99
|
-
swapDetails.exactIn = true;
|
100
|
-
return await getJupSwapTransaction(signer, swapDetails, attemptNum);
|
101
|
-
}
|
102
|
-
throw e;
|
103
|
-
}
|
82
|
+
));
|
104
83
|
|
105
84
|
const priceImpactBps =
|
106
85
|
Math.round(toBps(parseFloat(quoteResponse.priceImpactPct))) + 1;
|
package/src/utils/priceUtils.ts
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { PublicKey as UmiPublicKey } from "@metaplex-foundation/umi";
|
3
3
|
import { PYTH_PRICE_FEED_IDS } from "../constants/pythConstants";
|
4
|
-
import { fromBaseUnit, toBaseUnit } from "./numberUtils";
|
4
|
+
import { fromBaseUnit, toBaseUnit, toBps } from "./numberUtils";
|
5
5
|
import { PRICES } from "../constants/solautoConstants";
|
6
6
|
import { SWITCHBOARD_PRICE_FEED_IDS } from "../constants/switchboardConstants";
|
7
7
|
import {
|
8
8
|
consoleLog,
|
9
9
|
currentUnixSeconds,
|
10
10
|
retryWithExponentialBackoff,
|
11
|
+
tokenInfo,
|
11
12
|
zip,
|
12
13
|
} from "./generalUtils";
|
13
14
|
import * as OnDemand from "@switchboard-xyz/on-demand";
|
14
15
|
import { getJupPriceData } from "./jupiterUtils";
|
16
|
+
import { createJupiterApiClient } from "@jup-ag/api";
|
15
17
|
|
16
18
|
export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
|
17
19
|
const currentTime = currentUnixSeconds();
|
@@ -164,3 +166,28 @@ export function safeGetPrice(
|
|
164
166
|
}
|
165
167
|
return undefined;
|
166
168
|
}
|
169
|
+
|
170
|
+
export async function getPriceImpact(
|
171
|
+
inputMint: PublicKey,
|
172
|
+
inputAmount: bigint,
|
173
|
+
outputMint: PublicKey
|
174
|
+
) {
|
175
|
+
const jupApi = createJupiterApiClient();
|
176
|
+
|
177
|
+
const quoteResponse = await retryWithExponentialBackoff(
|
178
|
+
async () =>
|
179
|
+
await jupApi.quoteGet({
|
180
|
+
amount: Number(inputAmount),
|
181
|
+
inputMint: inputMint.toString(),
|
182
|
+
outputMint: outputMint.toString(),
|
183
|
+
swapMode: "ExactIn",
|
184
|
+
}),
|
185
|
+
4,
|
186
|
+
200
|
187
|
+
);
|
188
|
+
|
189
|
+
return {
|
190
|
+
priceImpact: parseFloat(quoteResponse.priceImpactPct),
|
191
|
+
quote: quoteResponse,
|
192
|
+
};
|
193
|
+
}
|
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
17
17
|
import { QuoteResponse } from "@jup-ag/api";
|
18
18
|
import { JupSwapDetails } from "../jupiterUtils";
|
19
|
-
import { consoleLog, currentUnixSeconds
|
19
|
+
import { consoleLog, currentUnixSeconds } from "../generalUtils";
|
20
20
|
import {
|
21
21
|
fromBaseUnit,
|
22
22
|
fromBps,
|
@@ -24,22 +24,13 @@ import {
|
|
24
24
|
getLiqUtilzationRateBps,
|
25
25
|
getMaxLiqUtilizationRateBps,
|
26
26
|
getSolautoFeesBps,
|
27
|
-
maxBoostToBps,
|
28
27
|
maxRepayToBps,
|
29
28
|
toBaseUnit,
|
30
29
|
} from "../numberUtils";
|
31
30
|
import { USD_DECIMALS } from "../../constants/generalAccounts";
|
32
31
|
import { RebalanceAction } from "../../types";
|
33
|
-
import { safeGetPrice } from "../priceUtils";
|
34
|
-
import {
|
35
|
-
BONK,
|
36
|
-
BROKEN_TOKENS,
|
37
|
-
JUP,
|
38
|
-
TOKEN_INFO,
|
39
|
-
USDC,
|
40
|
-
USDT,
|
41
|
-
WETH,
|
42
|
-
} from "../../constants";
|
32
|
+
import { getPriceImpact, safeGetPrice } from "../priceUtils";
|
33
|
+
import { TOKEN_INFO } from "../../constants";
|
43
34
|
|
44
35
|
function getAdditionalAmountToDcaIn(dca: DCASettings): number {
|
45
36
|
if (dca.dcaInBaseUnit === BigInt(0)) {
|
@@ -178,7 +169,6 @@ export interface RebalanceValues {
|
|
178
169
|
rebalanceAction: RebalanceAction;
|
179
170
|
rebalanceDirection: RebalanceDirection;
|
180
171
|
feesUsd: number;
|
181
|
-
targetRateBps: number;
|
182
172
|
}
|
183
173
|
|
184
174
|
export function getRebalanceValues(
|
@@ -190,7 +180,7 @@ export function getRebalanceValues(
|
|
190
180
|
debtPrice: number,
|
191
181
|
targetLiqUtilizationRateBps?: number
|
192
182
|
): RebalanceValues {
|
193
|
-
|
183
|
+
const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(
|
194
184
|
state,
|
195
185
|
settings,
|
196
186
|
dca,
|
@@ -198,20 +188,6 @@ export function getRebalanceValues(
|
|
198
188
|
targetLiqUtilizationRateBps
|
199
189
|
);
|
200
190
|
|
201
|
-
// REVERT ME AND GET TO THE ROOT OF THIS ISSUE
|
202
|
-
const supplyMint = toWeb3JsPublicKey(state.supply.mint);
|
203
|
-
if (
|
204
|
-
BROKEN_TOKENS.includes(supplyMint.toString()) &&
|
205
|
-
(toWeb3JsPublicKey(state.debt.mint).equals(new PublicKey(USDC)) ||
|
206
|
-
toWeb3JsPublicKey(state.debt.mint).equals(new PublicKey(USDT))) &&
|
207
|
-
settings &&
|
208
|
-
settings.boostToBps ===
|
209
|
-
maxBoostToBps(state.maxLtvBps, state.liqThresholdBps) &&
|
210
|
-
targetRateBps === settings.boostToBps
|
211
|
-
) {
|
212
|
-
targetRateBps = 6500;
|
213
|
-
}
|
214
|
-
|
215
191
|
const amountUsdToDcaIn =
|
216
192
|
fromBaseUnit(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
|
217
193
|
(dca?.tokenType === TokenType.Debt ? debtPrice : supplyPrice);
|
@@ -242,12 +218,6 @@ export function getRebalanceValues(
|
|
242
218
|
adjustmentFeeBps
|
243
219
|
);
|
244
220
|
|
245
|
-
consoleLog(
|
246
|
-
"Target rate:",
|
247
|
-
targetRateBps,
|
248
|
-
maxBoostToBps(state.maxLtvBps, state.liqThresholdBps)
|
249
|
-
);
|
250
|
-
|
251
221
|
const maxRepayTo = maxRepayToBps(state.maxLtvBps, state.liqThresholdBps);
|
252
222
|
return {
|
253
223
|
debtAdjustmentUsd,
|
@@ -264,7 +234,6 @@ export function getRebalanceValues(
|
|
264
234
|
: "repay",
|
265
235
|
rebalanceDirection,
|
266
236
|
feesUsd: Math.abs(debtAdjustmentUsd * fromBps(adjustmentFeeBps)),
|
267
|
-
targetRateBps,
|
268
237
|
};
|
269
238
|
}
|
270
239
|
|
@@ -370,12 +339,12 @@ export function getFlashLoanDetails(
|
|
370
339
|
: undefined;
|
371
340
|
}
|
372
341
|
|
373
|
-
export function getJupSwapRebalanceDetails(
|
342
|
+
export async function getJupSwapRebalanceDetails(
|
374
343
|
client: SolautoClient,
|
375
344
|
values: RebalanceValues,
|
376
345
|
targetLiqUtilizationRateBps?: number,
|
377
346
|
attemptNum?: number
|
378
|
-
): JupSwapDetails {
|
347
|
+
): Promise<JupSwapDetails> {
|
379
348
|
const input =
|
380
349
|
values.rebalanceDirection === RebalanceDirection.Boost
|
381
350
|
? client.solautoPositionState!.debt
|
@@ -393,7 +362,6 @@ export function getJupSwapRebalanceDetails(
|
|
393
362
|
usdToSwap / safeGetPrice(input.mint)!,
|
394
363
|
input.decimals
|
395
364
|
);
|
396
|
-
|
397
365
|
const outputAmount =
|
398
366
|
targetLiqUtilizationRateBps === 0
|
399
367
|
? output.amountUsed.baseUnit +
|
@@ -416,10 +384,26 @@ export function getJupSwapRebalanceDetails(
|
|
416
384
|
repaying && requiresFlashLoan && useDebtLiquidity;
|
417
385
|
|
418
386
|
const exactOut =
|
419
|
-
targetLiqUtilizationRateBps === 0 ||
|
387
|
+
// targetLiqUtilizationRateBps === 0 ||
|
388
|
+
// values.repayingCloseToMaxLtv ||
|
420
389
|
flashLoanRepayFromDebt;
|
421
390
|
const exactIn = !exactOut;
|
422
391
|
|
392
|
+
let jupQuote: QuoteResponse | undefined = undefined;
|
393
|
+
if (targetLiqUtilizationRateBps === 0) {
|
394
|
+
let priceImpact: number = 0;
|
395
|
+
|
396
|
+
do {
|
397
|
+
const res = await getPriceImpact(
|
398
|
+
toWeb3JsPublicKey(input.mint),
|
399
|
+
inputAmount + BigInt(Math.round(Number(inputAmount) * priceImpact)),
|
400
|
+
toWeb3JsPublicKey(output.mint)
|
401
|
+
);
|
402
|
+
priceImpact = res.priceImpact;
|
403
|
+
jupQuote = res.quote;
|
404
|
+
} while (parseInt(jupQuote.outAmount) < outputAmount);
|
405
|
+
}
|
406
|
+
|
423
407
|
const addPadding = exactOut;
|
424
408
|
|
425
409
|
return {
|
@@ -433,5 +417,6 @@ export function getJupSwapRebalanceDetails(
|
|
433
417
|
exactIn,
|
434
418
|
exactOut,
|
435
419
|
addPadding,
|
420
|
+
jupQuote,
|
436
421
|
};
|
437
422
|
}
|
@@ -3,16 +3,12 @@ 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,
|
7
6
|
safeFetchSolautoPosition,
|
8
7
|
solautoAction,
|
9
8
|
SolautoSettingsParametersInpArgs,
|
10
9
|
} from "../../src/generated";
|
11
10
|
import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
|
12
11
|
import {
|
13
|
-
bytesToI80F48,
|
14
|
-
getLiqUtilzationRateBps,
|
15
|
-
getMaxLiqUtilizationRateBps,
|
16
12
|
maxBoostToBps,
|
17
13
|
maxRepayFromBps,
|
18
14
|
maxRepayToBps,
|
@@ -25,20 +21,17 @@ import {
|
|
25
21
|
} from "../../src/transactions/transactionsManager";
|
26
22
|
import { PublicKey } from "@solana/web3.js";
|
27
23
|
import {
|
28
|
-
|
29
|
-
MARGINFI_ACCOUNTS,
|
24
|
+
INF,
|
30
25
|
SOLAUTO_PROD_PROGRAM,
|
31
26
|
SOLAUTO_TEST_PROGRAM,
|
32
27
|
USDC,
|
33
|
-
USDT,
|
34
28
|
} from "../../src/constants";
|
35
29
|
import {
|
36
30
|
buildHeliusApiUrl,
|
37
|
-
|
31
|
+
fetchTokenPrices,
|
32
|
+
getJupPriceData,
|
38
33
|
getQnComputeUnitPriceEstimate,
|
39
34
|
getSolautoManagedPositions,
|
40
|
-
getSolautoPositionAccount,
|
41
|
-
retryWithExponentialBackoff,
|
42
35
|
} from "../../src/utils";
|
43
36
|
import { PriorityFeeSetting } from "../../src/types";
|
44
37
|
import { buildIronforgeApiUrl } from "../../dist";
|
@@ -63,18 +56,23 @@ describe("Solauto Marginfi tests", async () => {
|
|
63
56
|
const supplyDecimals = 6;
|
64
57
|
const debtDecimals = 6;
|
65
58
|
|
66
|
-
await client.initialize({
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
});
|
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;
|
78
76
|
|
79
77
|
// console.log(
|
80
78
|
// JSON.stringify(
|
@@ -104,15 +102,6 @@ describe("Solauto Marginfi tests", async () => {
|
|
104
102
|
// targetBoostToBps: none(),
|
105
103
|
// };
|
106
104
|
|
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
|
-
|
116
105
|
// if (client.solautoPositionData === null) {
|
117
106
|
// transactionItems.push(
|
118
107
|
// new TransactionItem(async () => {
|
@@ -158,22 +147,15 @@ describe("Solauto Marginfi tests", async () => {
|
|
158
147
|
transactionItems.push(
|
159
148
|
new TransactionItem(
|
160
149
|
async (attemptNum) =>
|
161
|
-
await buildSolautoRebalanceTransaction(client,
|
150
|
+
await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
162
151
|
"rebalance"
|
163
152
|
)
|
164
153
|
);
|
165
154
|
|
166
|
-
// transactionItems.push(
|
167
|
-
// new TransactionItem(
|
168
|
-
// async () => ({ tx: client.refresh() }),
|
169
|
-
// "refresh"
|
170
|
-
// )
|
171
|
-
// );
|
172
|
-
|
173
155
|
// transactionItems.push(
|
174
156
|
// new TransactionItem(
|
175
157
|
// async (attemptNum) =>
|
176
|
-
// await buildSolautoRebalanceTransaction(client,
|
158
|
+
// await buildSolautoRebalanceTransaction(client, settingParams.boostToBps, attemptNum),
|
177
159
|
// "rebalance"
|
178
160
|
// )
|
179
161
|
// );
|