@haven-fi/solauto-sdk 1.0.701 → 1.0.703
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/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +19 -20
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +6 -4
- package/dist/services/rebalance/rebalanceValues.d.ts +4 -1
- package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceValues.js +9 -5
- package/dist/services/transactions/manager/transactionsManager.d.ts.map +1 -1
- package/dist/services/transactions/manager/transactionsManager.js +5 -3
- package/dist/services/transactions/transactionUtils.d.ts +3 -2
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +6 -2
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +2 -1
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +2 -1
- package/package.json +1 -1
- package/src/services/rebalance/rebalanceSwapManager.ts +31 -22
- package/src/services/rebalance/rebalanceTxBuilder.ts +11 -3
- package/src/services/rebalance/rebalanceValues.ts +10 -5
- package/src/services/transactions/manager/transactionsManager.ts +7 -3
- package/src/services/transactions/transactionUtils.ts +8 -3
- package/src/utils/jitoUtils.ts +2 -1
- package/src/utils/solanaUtils.ts +2 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceSwapManager.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceSwapManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAkB,UAAU,EAAa,MAAM,SAAS,CAAC;AAChE,OAAO,
|
1
|
+
{"version":3,"file":"rebalanceSwapManager.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceSwapManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAkB,UAAU,EAAa,MAAM,SAAS,CAAC;AAChE,OAAO,EAA0B,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAiC,MAAM,iBAAiB,CAAC;AAY3E,qBAAa,oBAAoB;IAS7B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,SAAS,CAAC;IAZb,UAAU,EAAG,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,aAAa,CAAU;gBAGrB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,cAAc,CAAC,EAAE,qBAAqB,YAAA,EACtC,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,SAAS,CAAC,EAAE,SAAS,YAAA;IAU/B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IAyCnB,OAAO,CAAC,kCAAkC;YA+C5B,mBAAmB;IA2CjC,OAAO,CAAC,mBAAmB;IAIrB,aAAa,CAAC,UAAU,EAAE,MAAM;IAyEhC,aAAa;;;;;;CAWpB"}
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RebalanceSwapManager = void 0;
|
4
4
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
5
5
|
const swap_1 = require("../swap");
|
6
|
+
const rebalanceValues_1 = require("./rebalanceValues");
|
6
7
|
const generated_1 = require("../../generated");
|
7
8
|
const utils_1 = require("../../utils");
|
8
9
|
const solautoFees_1 = require("./solautoFees");
|
@@ -29,21 +30,15 @@ class RebalanceSwapManager {
|
|
29
30
|
const output = this.isBoost()
|
30
31
|
? this.client.pos.state.supply
|
31
32
|
: this.client.pos.state.debt;
|
32
|
-
|
33
|
-
|
34
|
-
// this.priceType
|
35
|
-
// )!;
|
36
|
-
// const outputPrice = safeGetPrice(
|
37
|
-
// toWeb3JsPublicKey(output.mint),
|
38
|
-
// this.priceType
|
39
|
-
// )!;
|
33
|
+
const inputPrice = (0, utils_1.safeGetPrice)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint), this.priceType);
|
34
|
+
const outputPrice = (0, utils_1.safeGetPrice)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint), this.priceType);
|
40
35
|
const supplyPrice = this.client.pos.supplyPrice(this.priceType);
|
41
36
|
const debtPrice = this.client.pos.debtPrice(this.priceType);
|
42
37
|
const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
43
38
|
const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
44
|
-
const
|
45
|
-
const
|
46
|
-
let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() /
|
39
|
+
// const biasedInputPrice = inputPrice;
|
40
|
+
// const biasedOutputPrice = outputPrice;
|
41
|
+
let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() / biasedInputPrice, input.decimals);
|
47
42
|
return {
|
48
43
|
inputAmount,
|
49
44
|
input,
|
@@ -62,15 +57,19 @@ class RebalanceSwapManager {
|
|
62
57
|
const swapInputUsd = swapInputAmount
|
63
58
|
? (0, utils_1.fromBaseUnit)(swapInputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint)).decimals) * biasedInputPrice
|
64
59
|
: this.usdToSwap();
|
65
|
-
|
60
|
+
const swapOutputUsd = swapOutputAmount
|
66
61
|
? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint)).decimals) * biasedOutputPrice
|
67
62
|
: this.usdToSwap();
|
68
|
-
|
69
|
-
|
70
|
-
?
|
71
|
-
:
|
72
|
-
|
73
|
-
|
63
|
+
console.log(swapInputUsd, swapOutputUsd);
|
64
|
+
const res = (0, rebalanceValues_1.applyDebtAdjustmentUsd)({
|
65
|
+
debtAdjustmentUsd: this.isBoost() ? swapInputUsd : swapInputUsd * -1,
|
66
|
+
debtAdjustmentUsdOutput: swapOutputUsd,
|
67
|
+
}, { supplyUsd, debtUsd }, (0, utils_1.fromBps)(this.client.pos.state.liqThresholdBps), {
|
68
|
+
solauto: this.solautoFeeBps,
|
69
|
+
flashLoan: this.flRequirements?.flFeeBps ?? 0,
|
70
|
+
lpBorrow: this.client.pos.state.debt.borrowFeeBps,
|
71
|
+
});
|
72
|
+
return (0, utils_1.getLiqUtilzationRateBps)(res.newPos.supplyUsd, res.newPos.debtUsd, this.client.pos.state.liqThresholdBps ?? 0);
|
74
73
|
}
|
75
74
|
async findSufficientQuote(swapInput, criteria) {
|
76
75
|
let swapQuote;
|
@@ -102,13 +101,13 @@ class RebalanceSwapManager {
|
|
102
101
|
}
|
103
102
|
async setSwapParams(attemptNum) {
|
104
103
|
const rebalanceToZero = this.targetLiqUtilizationRateBps === 0;
|
105
|
-
let { input, output,
|
104
|
+
let { input, output, biasedOutputPrice, inputAmount } = this.swapDetails();
|
106
105
|
let outputAmount = rebalanceToZero
|
107
106
|
? output.amountUsed.baseUnit +
|
108
107
|
BigInt(Math.round(Number(output.amountUsed.baseUnit) *
|
109
108
|
// Add this small percentage to account for the APR on the debt between now and the transaction
|
110
109
|
0.0001))
|
111
|
-
: (0, utils_1.toBaseUnit)(this.usdToSwap() /
|
110
|
+
: (0, utils_1.toBaseUnit)(this.usdToSwap() / biasedOutputPrice, output.decimals);
|
112
111
|
const flashLoanRepayFromDebt = !this.isBoost() &&
|
113
112
|
this.flRequirements &&
|
114
113
|
this.flRequirements.liquiditySource === generated_1.TokenType.Debt;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAiCrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC;IATvB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,YAAY,CAAC,EAAE,OAAO,YAAA;IAGhC,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;
|
1
|
+
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAiCrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC;IATvB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,YAAY,CAAC,EAAE,OAAO,YAAA;IAGhC,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;IAsFpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
|
@@ -52,7 +52,7 @@ class RebalanceTxBuilder {
|
|
52
52
|
return this.values.intermediaryLiqUtilizationRateBps;
|
53
53
|
}
|
54
54
|
const fees = new solautoFees_1.SolautoFeesBps(this.client.isReferred, this.targetLiqUtilizationRateBps, this.client.pos.netWorthUsd(generated_1.PriceType.Realtime));
|
55
|
-
const { intermediaryLiqUtilizationRateBps } = (0, rebalanceValues_1.applyDebtAdjustmentUsd)(this.values.debtAdjustmentUsd, {
|
55
|
+
const { intermediaryLiqUtilizationRateBps } = (0, rebalanceValues_1.applyDebtAdjustmentUsd)({ debtAdjustmentUsd: this.values.debtAdjustmentUsd }, {
|
56
56
|
supplyUsd: this.client.pos.supplyUsd(generated_1.PriceType.Ema),
|
57
57
|
debtUsd: this.client.pos.debtUsd(generated_1.PriceType.Ema),
|
58
58
|
}, (0, utils_1.fromBps)(this.client.pos.state.liqThresholdBps), {
|
@@ -199,10 +199,12 @@ class RebalanceTxBuilder {
|
|
199
199
|
priceType: this.priceType,
|
200
200
|
};
|
201
201
|
(0, utils_1.consoleLog)("Rebalance details:", rebalanceDetails);
|
202
|
-
(0, utils_1.consoleLog)("Prices:", this.client.pos.supplyPrice(this.priceType), this.client.pos.debtPrice(this.priceType));
|
202
|
+
(0, utils_1.consoleLog)("Prices:", (0, utils_1.safeGetPrice)(this.client.pos.supplyMint, this.priceType), this.client.pos.supplyPrice(this.priceType), (0, utils_1.safeGetPrice)(this.client.pos.debtMint, this.priceType), this.client.pos.debtPrice(this.priceType));
|
203
203
|
if ((0, utils_1.isMarginfiPosition)(this.client.pos)) {
|
204
|
-
const supply = this.values.endResult.supplyUsd *
|
205
|
-
|
204
|
+
const supply = this.values.endResult.supplyUsd *
|
205
|
+
(0, utils_1.bytesToI80F48)(this.client.pos.supplyBank.config.assetWeightInit.value);
|
206
|
+
const debt = this.values.endResult.debtUsd *
|
207
|
+
(0, utils_1.bytesToI80F48)(this.client.pos.debtBank.config.liabilityWeightInit.value);
|
206
208
|
(0, utils_1.consoleLog)("Weighted values", supply, debt);
|
207
209
|
}
|
208
210
|
const firstRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PreSwap, rebalanceDetails);
|
@@ -19,7 +19,10 @@ interface ApplyDebtAdjustmentResult {
|
|
19
19
|
newPos: PositionValues;
|
20
20
|
intermediaryLiqUtilizationRateBps: number;
|
21
21
|
}
|
22
|
-
export declare function applyDebtAdjustmentUsd(
|
22
|
+
export declare function applyDebtAdjustmentUsd(adjustment: {
|
23
|
+
debtAdjustmentUsd: number;
|
24
|
+
debtAdjustmentUsdOutput?: number;
|
25
|
+
}, pos: PositionValues, liqThreshold: number, fees?: RebalanceFeesBps): ApplyDebtAdjustmentResult;
|
23
26
|
export declare function getDebtAdjustment(liqThresholdBps: number, pos: PositionValues, targetLiqUtilizationRateBps: number, fees?: RebalanceFeesBps): DebtAdjustment;
|
24
27
|
export interface RebalanceValues extends DebtAdjustment {
|
25
28
|
rebalanceDirection: RebalanceDirection;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceValues.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,cAAc,CAAC;IAC1B,iCAAiC,EAAE,MAAM,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,yBAAyB;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,iCAAiC,EAAE,MAAM,CAAC;CAC3C;AAED,wBAAgB,sBAAsB,CACpC,iBAAiB,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"rebalanceValues.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,W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ues;
|
6
6
|
const generated_1 = require("../../generated");
|
7
7
|
const utils_1 = require("../../utils");
|
8
|
-
function applyDebtAdjustmentUsd(
|
8
|
+
function applyDebtAdjustmentUsd(adjustment, pos, liqThreshold, fees) {
|
9
9
|
const newPos = { ...pos };
|
10
|
-
const isBoost = debtAdjustmentUsd > 0;
|
11
|
-
|
12
|
-
|
10
|
+
const isBoost = adjustment.debtAdjustmentUsd > 0;
|
11
|
+
if (!adjustment.debtAdjustmentUsdOutput) {
|
12
|
+
adjustment.debtAdjustmentUsdOutput = adjustment.debtAdjustmentUsd;
|
13
|
+
}
|
14
|
+
const daMinusSolautoFees = adjustment.debtAdjustmentUsdOutput -
|
15
|
+
adjustment.debtAdjustmentUsdOutput * (0, utils_1.fromBps)(fees?.solauto ?? 0);
|
16
|
+
const daWithFlashLoan = adjustment.debtAdjustmentUsd * (1.0 + (0, utils_1.fromBps)(fees?.flashLoan ?? 0));
|
13
17
|
let intermediaryLiqUtilizationRateBps = 0;
|
14
18
|
if (isBoost) {
|
15
19
|
newPos.debtUsd +=
|
@@ -40,7 +44,7 @@ function getDebtAdjustment(liqThresholdBps, pos, targetLiqUtilizationRateBps, fe
|
|
40
44
|
targetUtilizationRate * actualizedFee * liqThreshold)
|
41
45
|
: (targetUtilizationRate * liqThreshold * pos.supplyUsd - pos.debtUsd) /
|
42
46
|
(actualizedFee - targetUtilizationRate * liqThreshold * (1.0 + flFee));
|
43
|
-
const newPos = applyDebtAdjustmentUsd(debtAdjustmentUsd, pos, liqThreshold, fees);
|
47
|
+
const newPos = applyDebtAdjustmentUsd({ debtAdjustmentUsd }, pos, liqThreshold, fees);
|
44
48
|
return {
|
45
49
|
debtAdjustmentUsd,
|
46
50
|
endResult: newPos.newPos,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/transactionsManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0B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AE,CAAC,CAAC;IACvB,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAC1E,SAAS,CAAC,SAAS,CAAC,EAAE,kBAAkB,CAAC;IACzC,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IACjD,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC;IAC9B,SAAS,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACxC,SAAS,CAAC,QAAQ,EAAE,0BAA0B,CAAM;IACpD,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC;IACrC,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAE7B,kBAAkB,SAAmB;gBAEzB,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC;YAmB9B,uBAAuB;IA0CrC,OAAO,CAAC,YAAY;YA6CN,aAAa;IAoB3B,SAAS,CAAC,4BAA4B,CACpC,SAAS,EAAE,KAAK,GAAG,SAAS,EAC5B,UAAU,EAAE,MAAM;IAcpB,OAAO,CAAC,mBAAmB;IAoBd,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA8BxB,6BAA6B;
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/transactionsManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAElB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,aAAa,EAId,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAkB,MAAM,UAAU,CAAC;AAEzE,qBAAa,w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C,aAAa,CAAC,EAAE,aAAa,CAAC;IACxC,SAAS,CAAC,QAAQ,EAAE,0BAA0B,CAAM;IACpD,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC;IACrC,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAE7B,kBAAkB,SAAmB;gBAEzB,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC;YAmB9B,uBAAuB;IA0CrC,OAAO,CAAC,YAAY;YA6CN,aAAa;IAoB3B,SAAS,CAAC,4BAA4B,CACpC,SAAS,EAAE,KAAK,GAAG,SAAS,EAC5B,UAAU,EAAE,MAAM;IAcpB,OAAO,CAAC,mBAAmB;IAoBd,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA8BxB,6BAA6B;YAiJ7B,qBAAqB;YAiDrB,eAAe;cA2Db,eAAe,CAC7B,EAAE,EAAE,kBAAkB,EACtB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,kBAAkB,EACvC,SAAS,CAAC,EAAE,kBAAkB;CAyDjC"}
|
@@ -167,6 +167,7 @@ class TransactionsManager {
|
|
167
167
|
}
|
168
168
|
async processTransactionsAtomically(itemSets) {
|
169
169
|
let num = 0;
|
170
|
+
let priorityFeeSetting;
|
170
171
|
let transactions = [];
|
171
172
|
await (0, utils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
|
172
173
|
if (prevError &&
|
@@ -175,6 +176,7 @@ class TransactionsManager {
|
|
175
176
|
throw prevError;
|
176
177
|
}
|
177
178
|
num = attemptNum;
|
179
|
+
priorityFeeSetting = this.getUpdatedPriorityFeeSetting(prevError, attemptNum);
|
178
180
|
if (attemptNum > 0) {
|
179
181
|
const refreshedSets = await this.refreshItemSets(itemSets, attemptNum, prevError);
|
180
182
|
if (!refreshedSets || !refreshedSets.length) {
|
@@ -200,7 +202,7 @@ class TransactionsManager {
|
|
200
202
|
let txSigs;
|
201
203
|
let error;
|
202
204
|
try {
|
203
|
-
txSigs = await (0, utils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, this.txHandler.otherSigners, transactions, this.txRunType,
|
205
|
+
txSigs = await (0, utils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, this.txHandler.otherSigners, transactions, this.txRunType, priorityFeeSetting, () => this.updateStatusForSets(itemSets, TransactionStatus.Processing, attemptNum, undefined, true));
|
204
206
|
}
|
205
207
|
catch (e) {
|
206
208
|
error = e;
|
@@ -214,7 +216,7 @@ class TransactionsManager {
|
|
214
216
|
this.updateStatusForSets(itemSets, TransactionStatus.Successful, attemptNum, txSigs);
|
215
217
|
}, this.totalRetries, this.retryDelay, this.errorsToThrow).catch((e) => {
|
216
218
|
this.txHandler.log("Capturing error info...");
|
217
|
-
const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, transactions, e, itemSets.filter((x) => this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful).length === itemSets.length);
|
219
|
+
const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, transactions, e, itemSets.filter((x) => this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful).length === itemSets.length, priorityFeeSetting);
|
218
220
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
219
221
|
const errorInfo = errorDetails.errorName || errorDetails.errorInfo
|
220
222
|
? errorString
|
@@ -295,7 +297,7 @@ class TransactionsManager {
|
|
295
297
|
}
|
296
298
|
catch (e) {
|
297
299
|
this.txHandler.log("Capturing error info...");
|
298
|
-
const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, [tx], e, this.statuses.find((x) => x.name === txName)?.simulationSuccessful);
|
300
|
+
const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, [tx], e, this.statuses.find((x) => x.name === txName)?.simulationSuccessful, priorityFeeSetting);
|
299
301
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
300
302
|
const errorInfo = errorDetails.errorName || errorDetails.errorInfo
|
301
303
|
? errorString
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { SolautoClient, ReferralStateManager } from "../solauto";
|
4
|
-
import { TransactionItemInputs } from "../../types";
|
4
|
+
import { TransactionItemInputs, PriorityFeeSetting } from "../../types";
|
5
5
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
6
6
|
export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
|
7
7
|
export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
8
|
-
export declare function getErrorInfo(umi: Umi, txs: TransactionBuilder[], error: Error, simulationSuccessful?: boolean): {
|
8
|
+
export declare function getErrorInfo(umi: Umi, txs: TransactionBuilder[], error: Error, simulationSuccessful?: boolean, priorityFeeSetting?: PriorityFeeSetting): {
|
9
9
|
errorName: string | undefined;
|
10
10
|
errorInfo: string | undefined;
|
11
11
|
canBeIgnored: boolean;
|
12
12
|
};
|
13
|
+
export declare function usePriorityFee(priorityFeeSetting?: PriorityFeeSetting): priorityFeeSetting is PriorityFeeSetting.Min | PriorityFeeSetting.Low | PriorityFeeSetting.Default | PriorityFeeSetting.High | PriorityFeeSetting.VeryHigh;
|
13
14
|
//# sourceMappingURL=transactionUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAiBlC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4BjE,OAAO,EAAE,qBAAqB,EAAyB,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAiBlC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4BjE,OAAO,EAAE,qBAAqB,EAAyB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAwL/F,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAyF7B;AA+LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAuC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO,EAC9B,kBAAkB,CAAC,EAAE,kBAAkB;;;;EAuHxC;AAED,wBAAgB,cAAc,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,8JAErE"}
|
@@ -4,6 +4,7 @@ exports.rebalanceChoresBefore = rebalanceChoresBefore;
|
|
4
4
|
exports.getTransactionChores = getTransactionChores;
|
5
5
|
exports.convertReferralFeesToDestination = convertReferralFeesToDestination;
|
6
6
|
exports.getErrorInfo = getErrorInfo;
|
7
|
+
exports.usePriorityFee = usePriorityFee;
|
7
8
|
const web3_js_1 = require("@solana/web3.js");
|
8
9
|
const spl_token_1 = require("@solana/spl-token");
|
9
10
|
const umi_1 = require("@metaplex-foundation/umi");
|
@@ -339,7 +340,7 @@ async function convertReferralFeesToDestination(referralManager, tokenAccount, d
|
|
339
340
|
.add(swapIx);
|
340
341
|
return { tx, lookupTableAddresses };
|
341
342
|
}
|
342
|
-
function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
343
|
+
function getErrorInfo(umi, txs, error, simulationSuccessful, priorityFeeSetting) {
|
343
344
|
let canBeIgnored = false;
|
344
345
|
let errorName = undefined;
|
345
346
|
let errorInfo = undefined;
|
@@ -348,7 +349,7 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
348
349
|
let errCode;
|
349
350
|
let errName;
|
350
351
|
// sub ixs to account for computeUnitLimit and computeUnitPrice that get added
|
351
|
-
const getComputeIxs = (txIdx) => (0, utils_1.addTxOptimizations)(umi, txs[txIdx], 1, simulationSuccessful ? 1 : undefined).getInstructions().length - txs[txIdx].getInstructions().length;
|
352
|
+
const getComputeIxs = (txIdx) => (0, utils_1.addTxOptimizations)(umi, txs[txIdx], usePriorityFee(priorityFeeSetting) ? 1 : undefined, simulationSuccessful ? 1 : undefined).getInstructions().length - txs[txIdx].getInstructions().length;
|
352
353
|
try {
|
353
354
|
if (error instanceof types_1.BundleSimulationError) {
|
354
355
|
errTxIdx = error.details.transactionIdx;
|
@@ -423,3 +424,6 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
423
424
|
(0, utils_1.consoleLog)(errData);
|
424
425
|
return errData;
|
425
426
|
}
|
427
|
+
function usePriorityFee(priorityFeeSetting) {
|
428
|
+
return priorityFeeSetting !== undefined && priorityFeeSetting !== types_1.PriorityFeeSetting.None;
|
429
|
+
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAgBlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AAkGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB/D;AAwHD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CA+F/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -14,6 +14,7 @@ const types_2 = require("../types");
|
|
14
14
|
const solanaUtils_1 = require("./solanaUtils");
|
15
15
|
const generalUtils_1 = require("./generalUtils");
|
16
16
|
const bs58_1 = __importDefault(require("bs58"));
|
17
|
+
const services_1 = require("../services");
|
17
18
|
function getRandomTipAccount() {
|
18
19
|
const randomInt = Math.floor(Math.random() * constants_1.JITO_TIP_ACCOUNTS.length);
|
19
20
|
return new web3_js_1.PublicKey(constants_1.JITO_TIP_ACCOUNTS[randomInt]);
|
@@ -190,7 +191,7 @@ async function sendJitoBundledTransactions(umi, connection, userSigner, otherSig
|
|
190
191
|
(0, generalUtils_1.consoleLog)(txs.map((tx) => tx.getInstructions().map((x) => x.programId.toString())));
|
191
192
|
(0, generalUtils_1.consoleLog)("Transaction sizes: ", txs.map((x) => x.getTransactionSize(umi)));
|
192
193
|
txs[0] = txs[0].prepend(getTipInstruction(userSigner, 150000));
|
193
|
-
const feeEstimates =
|
194
|
+
const feeEstimates = (0, services_1.usePriorityFee)(priorityFeeSetting)
|
194
195
|
? await Promise.all(txs.map(async (x) => (await (0, solanaUtils_1.getComputeUnitPriceEstimate)(umi, x, priorityFeeSetting, true)) ?? 1000000))
|
195
196
|
: undefined;
|
196
197
|
const latestBlockhash = (await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })).blockhash;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACV,SAAS,EAKT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;
|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C1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CA4DjC"}
|
@@ -31,6 +31,7 @@ const accountUtils_1 = require("./accountUtils");
|
|
31
31
|
const generalUtils_1 = require("./generalUtils");
|
32
32
|
const solautoUtils_1 = require("./solautoUtils");
|
33
33
|
const marginfi_1 = require("./marginfi");
|
34
|
+
const services_1 = require("../services");
|
34
35
|
function getSolanaRpcConnection(rpcUrl, programId, lpEnv) {
|
35
36
|
const connection = new web3_js_1.Connection(rpcUrl, {
|
36
37
|
commitment: "confirmed",
|
@@ -270,7 +271,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, prior
|
|
270
271
|
(0, generalUtils_1.consoleLog)("Compute unit limit: ", cuLimit);
|
271
272
|
}
|
272
273
|
let cuPrice;
|
273
|
-
if (
|
274
|
+
if ((0, services_1.usePriorityFee)(prioritySetting)) {
|
274
275
|
cuPrice = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
|
275
276
|
cuPrice = Math.min(cuPrice ?? 0, 100000000);
|
276
277
|
(0, generalUtils_1.consoleLog)("Compute unit price: ", cuPrice);
|
package/package.json
CHANGED
@@ -3,7 +3,7 @@ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
|
3
3
|
import { FlashLoanRequirements } from "../../types";
|
4
4
|
import { SolautoClient } from "../solauto";
|
5
5
|
import { JupSwapManager, SwapParams, SwapInput } from "../swap";
|
6
|
-
import { RebalanceValues } from "./rebalanceValues";
|
6
|
+
import { applyDebtAdjustmentUsd, RebalanceValues } from "./rebalanceValues";
|
7
7
|
import { PriceType, RebalanceDirection, TokenType } from "../../generated";
|
8
8
|
import {
|
9
9
|
consoleLog,
|
@@ -55,25 +55,25 @@ export class RebalanceSwapManager {
|
|
55
55
|
? this.client.pos.state.supply
|
56
56
|
: this.client.pos.state.debt;
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
const inputPrice = safeGetPrice(
|
59
|
+
toWeb3JsPublicKey(input.mint),
|
60
|
+
this.priceType
|
61
|
+
)!;
|
62
|
+
const outputPrice = safeGetPrice(
|
63
|
+
toWeb3JsPublicKey(output.mint),
|
64
|
+
this.priceType
|
65
|
+
)!;
|
66
66
|
|
67
67
|
const supplyPrice = this.client.pos.supplyPrice(this.priceType)!;
|
68
68
|
const debtPrice = this.client.pos.debtPrice(this.priceType)!;
|
69
69
|
const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
70
70
|
const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
71
71
|
|
72
|
-
const
|
73
|
-
const
|
72
|
+
// const biasedInputPrice = inputPrice;
|
73
|
+
// const biasedOutputPrice = outputPrice;
|
74
74
|
|
75
75
|
let inputAmount = toBaseUnit(
|
76
|
-
this.usdToSwap() /
|
76
|
+
this.usdToSwap() / biasedInputPrice!,
|
77
77
|
input.decimals
|
78
78
|
);
|
79
79
|
|
@@ -106,22 +106,31 @@ export class RebalanceSwapManager {
|
|
106
106
|
) * biasedInputPrice
|
107
107
|
: this.usdToSwap();
|
108
108
|
|
109
|
-
|
109
|
+
const swapOutputUsd = swapOutputAmount
|
110
110
|
? fromBaseUnit(
|
111
111
|
swapOutputAmount,
|
112
112
|
tokenInfo(toWeb3JsPublicKey(output.mint)).decimals
|
113
113
|
) * biasedOutputPrice
|
114
114
|
: this.usdToSwap();
|
115
|
-
swapOutputUsd = swapOutputUsd - swapOutputUsd * fromBps(this.solautoFeeBps);
|
116
115
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
console.log(swapInputUsd, swapOutputUsd);
|
117
|
+
const res = applyDebtAdjustmentUsd(
|
118
|
+
{
|
119
|
+
debtAdjustmentUsd: this.isBoost() ? swapInputUsd : swapInputUsd * -1,
|
120
|
+
debtAdjustmentUsdOutput: swapOutputUsd,
|
121
|
+
},
|
122
|
+
{ supplyUsd, debtUsd },
|
123
|
+
fromBps(this.client.pos.state.liqThresholdBps),
|
124
|
+
{
|
125
|
+
solauto: this.solautoFeeBps,
|
126
|
+
flashLoan: this.flRequirements?.flFeeBps ?? 0,
|
127
|
+
lpBorrow: this.client.pos.state.debt.borrowFeeBps,
|
128
|
+
}
|
129
|
+
);
|
121
130
|
|
122
131
|
return getLiqUtilzationRateBps(
|
123
|
-
supplyUsd,
|
124
|
-
debtUsd,
|
132
|
+
res.newPos.supplyUsd,
|
133
|
+
res.newPos.debtUsd,
|
125
134
|
this.client.pos.state.liqThresholdBps ?? 0
|
126
135
|
);
|
127
136
|
}
|
@@ -175,7 +184,7 @@ export class RebalanceSwapManager {
|
|
175
184
|
|
176
185
|
async setSwapParams(attemptNum: number) {
|
177
186
|
const rebalanceToZero = this.targetLiqUtilizationRateBps === 0;
|
178
|
-
let { input, output,
|
187
|
+
let { input, output, biasedOutputPrice, inputAmount } = this.swapDetails();
|
179
188
|
|
180
189
|
let outputAmount = rebalanceToZero
|
181
190
|
? output.amountUsed.baseUnit +
|
@@ -186,7 +195,7 @@ export class RebalanceSwapManager {
|
|
186
195
|
0.0001
|
187
196
|
)
|
188
197
|
)
|
189
|
-
: toBaseUnit(this.usdToSwap() /
|
198
|
+
: toBaseUnit(this.usdToSwap() / biasedOutputPrice, output.decimals);
|
190
199
|
|
191
200
|
const flashLoanRepayFromDebt =
|
192
201
|
!this.isBoost() &&
|
@@ -136,7 +136,7 @@ export class RebalanceTxBuilder {
|
|
136
136
|
);
|
137
137
|
|
138
138
|
const { intermediaryLiqUtilizationRateBps } = applyDebtAdjustmentUsd(
|
139
|
-
this.values.debtAdjustmentUsd,
|
139
|
+
{ debtAdjustmentUsd: this.values.debtAdjustmentUsd },
|
140
140
|
{
|
141
141
|
supplyUsd: this.client.pos.supplyUsd(PriceType.Ema),
|
142
142
|
debtUsd: this.client.pos.debtUsd(PriceType.Ema),
|
@@ -345,13 +345,21 @@ export class RebalanceTxBuilder {
|
|
345
345
|
consoleLog("Rebalance details:", rebalanceDetails);
|
346
346
|
consoleLog(
|
347
347
|
"Prices:",
|
348
|
+
safeGetPrice(this.client.pos.supplyMint, this.priceType),
|
348
349
|
this.client.pos.supplyPrice(this.priceType),
|
350
|
+
safeGetPrice(this.client.pos.debtMint, this.priceType),
|
349
351
|
this.client.pos.debtPrice(this.priceType)
|
350
352
|
);
|
351
353
|
|
352
354
|
if (isMarginfiPosition(this.client.pos)) {
|
353
|
-
const supply =
|
354
|
-
|
355
|
+
const supply =
|
356
|
+
this.values.endResult.supplyUsd *
|
357
|
+
bytesToI80F48(this.client.pos.supplyBank!.config.assetWeightInit.value);
|
358
|
+
const debt =
|
359
|
+
this.values.endResult.debtUsd *
|
360
|
+
bytesToI80F48(
|
361
|
+
this.client.pos.debtBank!.config.liabilityWeightInit.value
|
362
|
+
);
|
355
363
|
consoleLog("Weighted values", supply, debt);
|
356
364
|
}
|
357
365
|
|
@@ -38,18 +38,23 @@ interface ApplyDebtAdjustmentResult {
|
|
38
38
|
}
|
39
39
|
|
40
40
|
export function applyDebtAdjustmentUsd(
|
41
|
-
debtAdjustmentUsd: number,
|
41
|
+
adjustment: { debtAdjustmentUsd: number; debtAdjustmentUsdOutput?: number },
|
42
42
|
pos: PositionValues,
|
43
43
|
liqThreshold: number,
|
44
44
|
fees?: RebalanceFeesBps
|
45
45
|
): ApplyDebtAdjustmentResult {
|
46
46
|
const newPos = { ...pos };
|
47
|
-
const isBoost = debtAdjustmentUsd > 0;
|
47
|
+
const isBoost = adjustment.debtAdjustmentUsd > 0;
|
48
48
|
|
49
|
+
if (!adjustment.debtAdjustmentUsdOutput) {
|
50
|
+
adjustment.debtAdjustmentUsdOutput = adjustment.debtAdjustmentUsd;
|
51
|
+
}
|
49
52
|
const daMinusSolautoFees =
|
50
|
-
|
53
|
+
adjustment.debtAdjustmentUsdOutput -
|
54
|
+
adjustment.debtAdjustmentUsdOutput * fromBps(fees?.solauto ?? 0);
|
55
|
+
|
51
56
|
const daWithFlashLoan =
|
52
|
-
debtAdjustmentUsd * (1.0 + fromBps(fees?.flashLoan ?? 0));
|
57
|
+
adjustment.debtAdjustmentUsd * (1.0 + fromBps(fees?.flashLoan ?? 0));
|
53
58
|
|
54
59
|
let intermediaryLiqUtilizationRateBps = 0;
|
55
60
|
if (isBoost) {
|
@@ -100,7 +105,7 @@ export function getDebtAdjustment(
|
|
100
105
|
(actualizedFee - targetUtilizationRate * liqThreshold * (1.0 + flFee));
|
101
106
|
|
102
107
|
const newPos = applyDebtAdjustmentUsd(
|
103
|
-
debtAdjustmentUsd,
|
108
|
+
{ debtAdjustmentUsd },
|
104
109
|
pos,
|
105
110
|
liqThreshold,
|
106
111
|
fees
|
@@ -269,6 +269,7 @@ export class TransactionsManager<T extends TxHandler> {
|
|
269
269
|
|
270
270
|
private async processTransactionsAtomically(itemSets: TransactionSet[]) {
|
271
271
|
let num = 0;
|
272
|
+
let priorityFeeSetting: PriorityFeeSetting;
|
272
273
|
let transactions: TransactionBuilder[] = [];
|
273
274
|
|
274
275
|
await retryWithExponentialBackoff(
|
@@ -282,6 +283,7 @@ export class TransactionsManager<T extends TxHandler> {
|
|
282
283
|
}
|
283
284
|
|
284
285
|
num = attemptNum;
|
286
|
+
priorityFeeSetting = this.getUpdatedPriorityFeeSetting(prevError, attemptNum);
|
285
287
|
|
286
288
|
if (attemptNum > 0) {
|
287
289
|
const refreshedSets = await this.refreshItemSets(
|
@@ -334,7 +336,7 @@ export class TransactionsManager<T extends TxHandler> {
|
|
334
336
|
this.txHandler.otherSigners,
|
335
337
|
transactions,
|
336
338
|
this.txRunType,
|
337
|
-
|
339
|
+
priorityFeeSetting,
|
338
340
|
() =>
|
339
341
|
this.updateStatusForSets(
|
340
342
|
itemSets,
|
@@ -383,7 +385,8 @@ export class TransactionsManager<T extends TxHandler> {
|
|
383
385
|
itemSets.filter(
|
384
386
|
(x) =>
|
385
387
|
this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful
|
386
|
-
).length === itemSets.length
|
388
|
+
).length === itemSets.length,
|
389
|
+
priorityFeeSetting
|
387
390
|
);
|
388
391
|
|
389
392
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
@@ -553,7 +556,8 @@ export class TransactionsManager<T extends TxHandler> {
|
|
553
556
|
this.txHandler.umi,
|
554
557
|
[tx],
|
555
558
|
e,
|
556
|
-
this.statuses.find((x) => x.name === txName)?.simulationSuccessful
|
559
|
+
this.statuses.find((x) => x.name === txName)?.simulationSuccessful,
|
560
|
+
priorityFeeSetting
|
557
561
|
);
|
558
562
|
|
559
563
|
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
|
@@ -56,7 +56,7 @@ import {
|
|
56
56
|
getJupiterErrorFromCode,
|
57
57
|
JUPITER_PROGRAM_ID,
|
58
58
|
} from "../../jupiter-sdk";
|
59
|
-
import { TransactionItemInputs, BundleSimulationError } from "../../types";
|
59
|
+
import { TransactionItemInputs, BundleSimulationError, PriorityFeeSetting } from "../../types";
|
60
60
|
import { isMarginfiProgram } from "../../constants";
|
61
61
|
|
62
62
|
interface wSolTokenUsage {
|
@@ -604,7 +604,8 @@ export function getErrorInfo(
|
|
604
604
|
umi: Umi,
|
605
605
|
txs: TransactionBuilder[],
|
606
606
|
error: Error,
|
607
|
-
simulationSuccessful?: boolean
|
607
|
+
simulationSuccessful?: boolean,
|
608
|
+
priorityFeeSetting?: PriorityFeeSetting
|
608
609
|
) {
|
609
610
|
let canBeIgnored = false;
|
610
611
|
let errorName: string | undefined = undefined;
|
@@ -620,7 +621,7 @@ export function getErrorInfo(
|
|
620
621
|
addTxOptimizations(
|
621
622
|
umi,
|
622
623
|
txs[txIdx],
|
623
|
-
1,
|
624
|
+
usePriorityFee(priorityFeeSetting) ? 1 : undefined,
|
624
625
|
simulationSuccessful ? 1 : undefined
|
625
626
|
).getInstructions().length - txs[txIdx].getInstructions().length;
|
626
627
|
|
@@ -724,3 +725,7 @@ export function getErrorInfo(
|
|
724
725
|
|
725
726
|
return errData;
|
726
727
|
}
|
728
|
+
|
729
|
+
export function usePriorityFee(priorityFeeSetting?: PriorityFeeSetting) {
|
730
|
+
return priorityFeeSetting !== undefined && priorityFeeSetting !== PriorityFeeSetting.None;
|
731
|
+
}
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -28,6 +28,7 @@ import {
|
|
28
28
|
retryWithExponentialBackoff,
|
29
29
|
} from "./generalUtils";
|
30
30
|
import base58 from "bs58";
|
31
|
+
import { usePriorityFee } from "../services";
|
31
32
|
|
32
33
|
export function getRandomTipAccount(): PublicKey {
|
33
34
|
const randomInt = Math.floor(Math.random() * JITO_TIP_ACCOUNTS.length);
|
@@ -303,7 +304,7 @@ export async function sendJitoBundledTransactions(
|
|
303
304
|
txs[0] = txs[0].prepend(getTipInstruction(userSigner, 150_000));
|
304
305
|
|
305
306
|
const feeEstimates =
|
306
|
-
priorityFeeSetting
|
307
|
+
usePriorityFee(priorityFeeSetting)
|
307
308
|
? await Promise.all(
|
308
309
|
txs.map(
|
309
310
|
async (x) =>
|
package/src/utils/solanaUtils.ts
CHANGED
@@ -48,6 +48,7 @@ import {
|
|
48
48
|
} from "./generalUtils";
|
49
49
|
import { createDynamicSolautoProgram } from "./solautoUtils";
|
50
50
|
import { createDynamicMarginfiProgram } from "./marginfi";
|
51
|
+
import { usePriorityFee } from "../services";
|
51
52
|
|
52
53
|
export function getSolanaRpcConnection(
|
53
54
|
rpcUrl: string,
|
@@ -469,7 +470,7 @@ export async function sendSingleOptimizedTransaction(
|
|
469
470
|
}
|
470
471
|
|
471
472
|
let cuPrice: number | undefined;
|
472
|
-
if (prioritySetting
|
473
|
+
if (usePriorityFee(prioritySetting)) {
|
473
474
|
cuPrice = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
|
474
475
|
cuPrice = Math.min(cuPrice ?? 0, 100_000_000);
|
475
476
|
consoleLog("Compute unit price: ", cuPrice);
|