@haven-fi/solauto-sdk 1.0.699 → 1.0.701
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 +1 -0
- package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +36 -20
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +5 -0
- package/dist/services/solauto/solautoClient.d.ts +1 -1
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.d.ts +1 -1
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +1 -1
- package/dist/services/swap/jupSwapManager.js +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +2 -2
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +1 -1
- package/dist/utils/solanaUtils.js +1 -1
- package/local/txSandbox.ts +46 -6
- package/package.json +1 -1
- package/src/services/rebalance/rebalanceSwapManager.ts +57 -20
- package/src/services/rebalance/rebalanceTxBuilder.ts +9 -0
- package/src/services/solauto/solautoClient.ts +1 -1
- package/src/services/solauto/solautoMarginfiClient.ts +2 -2
- package/src/services/swap/jupSwapManager.ts +1 -1
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +2 -2
- package/src/utils/jitoUtils.ts +1 -1
- package/src/utils/solanaUtils.ts +1 -1
@@ -14,6 +14,7 @@ export declare class RebalanceSwapManager {
|
|
14
14
|
swapQuote?: QuoteResponse;
|
15
15
|
flBorrowAmount?: bigint;
|
16
16
|
private jupSwapManager;
|
17
|
+
private solautoFeeBps;
|
17
18
|
constructor(client: SolautoClient, values: RebalanceValues, flRequirements?: FlashLoanRequirements | undefined, targetLiqUtilizationRateBps?: number | undefined, priceType?: PriceType | undefined);
|
18
19
|
private isBoost;
|
19
20
|
private usdToSwap;
|
@@ -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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAiC,MAAM,iBAAiB,CAAC;
|
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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,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;YAsC5B,mBAAmB;IA2CjC,OAAO,CAAC,mBAAmB;IAIrB,aAAa,CAAC,UAAU,EAAE,MAAM;IAyEhC,aAAa;;;;;;CAWpB"}
|
@@ -5,6 +5,7 @@ const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters"
|
|
5
5
|
const swap_1 = require("../swap");
|
6
6
|
const generated_1 = require("../../generated");
|
7
7
|
const utils_1 = require("../../utils");
|
8
|
+
const solautoFees_1 = require("./solautoFees");
|
8
9
|
class RebalanceSwapManager {
|
9
10
|
constructor(client, values, flRequirements, targetLiqUtilizationRateBps, priceType) {
|
10
11
|
this.client = client;
|
@@ -13,6 +14,7 @@ class RebalanceSwapManager {
|
|
13
14
|
this.targetLiqUtilizationRateBps = targetLiqUtilizationRateBps;
|
14
15
|
this.priceType = priceType;
|
15
16
|
this.jupSwapManager = new swap_1.JupSwapManager(client.signer);
|
17
|
+
this.solautoFeeBps = solautoFees_1.SolautoFeesBps.create(this.client.isReferred, this.targetLiqUtilizationRateBps, this.client.pos.netWorthUsd(this.priceType)).getSolautoFeesBps(values.rebalanceDirection).total;
|
16
18
|
}
|
17
19
|
isBoost() {
|
18
20
|
return this.values.rebalanceDirection === generated_1.RebalanceDirection.Boost;
|
@@ -27,53 +29,67 @@ class RebalanceSwapManager {
|
|
27
29
|
const output = this.isBoost()
|
28
30
|
? this.client.pos.state.supply
|
29
31
|
: this.client.pos.state.debt;
|
30
|
-
// const
|
31
|
-
//
|
32
|
-
//
|
33
|
-
//
|
34
|
-
const
|
35
|
-
|
32
|
+
// const inputPrice = safeGetPrice(
|
33
|
+
// toWeb3JsPublicKey(input.mint),
|
34
|
+
// this.priceType
|
35
|
+
// )!;
|
36
|
+
// const outputPrice = safeGetPrice(
|
37
|
+
// toWeb3JsPublicKey(output.mint),
|
38
|
+
// this.priceType
|
39
|
+
// )!;
|
40
|
+
const supplyPrice = this.client.pos.supplyPrice(this.priceType);
|
41
|
+
const debtPrice = this.client.pos.debtPrice(this.priceType);
|
42
|
+
const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
43
|
+
const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
44
|
+
const inputPrice = biasedInputPrice;
|
45
|
+
const outputPrice = biasedOutputPrice;
|
36
46
|
let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() / inputPrice, input.decimals);
|
37
47
|
return {
|
38
48
|
inputAmount,
|
39
49
|
input,
|
40
50
|
inputPrice,
|
51
|
+
biasedInputPrice,
|
41
52
|
output,
|
42
53
|
outputPrice,
|
54
|
+
biasedOutputPrice,
|
43
55
|
};
|
44
56
|
}
|
45
|
-
postRebalanceLiqUtilizationRateBps(swapOutputAmount) {
|
57
|
+
postRebalanceLiqUtilizationRateBps(swapOutputAmount, swapInputAmount) {
|
46
58
|
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
47
59
|
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
48
60
|
// TODO: add token balance change
|
49
|
-
const { output,
|
50
|
-
const
|
51
|
-
? (0, utils_1.fromBaseUnit)(
|
61
|
+
const { input, biasedInputPrice, output, biasedOutputPrice } = this.swapDetails();
|
62
|
+
const swapInputUsd = swapInputAmount
|
63
|
+
? (0, utils_1.fromBaseUnit)(swapInputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint)).decimals) * biasedInputPrice
|
52
64
|
: this.usdToSwap();
|
65
|
+
let swapOutputUsd = swapOutputAmount
|
66
|
+
? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint)).decimals) * biasedOutputPrice
|
67
|
+
: this.usdToSwap();
|
68
|
+
swapOutputUsd = swapOutputUsd - swapOutputUsd * (0, utils_1.fromBps)(this.solautoFeeBps);
|
53
69
|
supplyUsd = this.isBoost()
|
54
70
|
? supplyUsd + swapOutputUsd
|
55
|
-
: supplyUsd -
|
56
|
-
debtUsd = this.isBoost()
|
57
|
-
? debtUsd + this.usdToSwap()
|
58
|
-
: debtUsd - swapOutputUsd;
|
71
|
+
: supplyUsd - swapInputUsd;
|
72
|
+
debtUsd = this.isBoost() ? debtUsd + swapInputUsd : debtUsd - swapOutputUsd;
|
59
73
|
return (0, utils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, this.client.pos.state.liqThresholdBps ?? 0);
|
60
74
|
}
|
61
75
|
async findSufficientQuote(swapInput, criteria) {
|
62
76
|
let swapQuote;
|
63
77
|
let insufficient = false;
|
64
|
-
for (let i = 0; i <
|
78
|
+
for (let i = 0; i < 20; i++) {
|
65
79
|
(0, utils_1.consoleLog)("Finding sufficient quote...");
|
66
80
|
swapQuote = await this.jupSwapManager.getQuote(swapInput);
|
67
81
|
const outputAmount = parseInt(swapQuote.outAmount);
|
68
|
-
const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(BigInt(outputAmount));
|
82
|
+
const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(BigInt(outputAmount), BigInt(parseInt(swapQuote.inAmount)));
|
69
83
|
insufficient = criteria.minOutputAmount
|
70
84
|
? outputAmount < Number(criteria.minOutputAmount)
|
71
85
|
: criteria.minLiqUtilizationRateBps
|
72
86
|
? postRebalanceRate < criteria.minLiqUtilizationRateBps
|
73
87
|
: postRebalanceRate > criteria.maxLiqUtilizationRateBps;
|
88
|
+
(0, utils_1.consoleLog)(postRebalanceRate, criteria.maxLiqUtilizationRateBps);
|
74
89
|
if (insufficient) {
|
75
90
|
(0, utils_1.consoleLog)("Insufficient swap quote:", swapQuote);
|
76
|
-
|
91
|
+
const increment = 0.01 + i * 0.001;
|
92
|
+
swapInput.amount = this.bigIntWithIncrement(swapInput.amount, this.isBoost() ? increment * -1 : increment);
|
77
93
|
}
|
78
94
|
else {
|
79
95
|
break;
|
@@ -116,11 +132,11 @@ class RebalanceSwapManager {
|
|
116
132
|
amount: swapAmount,
|
117
133
|
};
|
118
134
|
(0, utils_1.consoleLog)("Swap input:", swapInput);
|
119
|
-
if (exactIn
|
135
|
+
if (exactIn) {
|
120
136
|
this.swapQuote = await this.findSufficientQuote(swapInput, {
|
121
137
|
minOutputAmount: rebalanceToZero ? outputAmount : undefined,
|
122
|
-
maxLiqUtilizationRateBps:
|
123
|
-
? this.client.pos.
|
138
|
+
maxLiqUtilizationRateBps: !rebalanceToZero
|
139
|
+
? this.client.pos.maxBoostToBps
|
124
140
|
: undefined,
|
125
141
|
});
|
126
142
|
}
|
@@ -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;
|
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;IA8EpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
|
@@ -200,6 +200,11 @@ class RebalanceTxBuilder {
|
|
200
200
|
};
|
201
201
|
(0, utils_1.consoleLog)("Rebalance details:", rebalanceDetails);
|
202
202
|
(0, utils_1.consoleLog)("Prices:", this.client.pos.supplyPrice(this.priceType), this.client.pos.debtPrice(this.priceType));
|
203
|
+
if ((0, utils_1.isMarginfiPosition)(this.client.pos)) {
|
204
|
+
const supply = this.values.endResult.supplyUsd * (0, utils_1.bytesToI80F48)(this.client.pos.supplyBank.config.assetWeightInit.value);
|
205
|
+
const debt = this.values.endResult.debtUsd * (0, utils_1.bytesToI80F48)(this.client.pos.debtBank.config.liabilityWeightInit.value);
|
206
|
+
(0, utils_1.consoleLog)("Weighted values", supply, debt);
|
207
|
+
}
|
203
208
|
const firstRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PreSwap, rebalanceDetails);
|
204
209
|
const lastRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PostSwap, rebalanceDetails);
|
205
210
|
if (!flashLoanDetails) {
|
@@ -58,7 +58,7 @@ export declare abstract class SolautoClient extends ReferralStateManager {
|
|
58
58
|
updatePositionIx(args: UpdatePositionDataArgs): TransactionBuilder;
|
59
59
|
abstract closePositionIx(): TransactionBuilder;
|
60
60
|
cancelDCAIx(): TransactionBuilder;
|
61
|
-
abstract refreshIx(priceType
|
61
|
+
abstract refreshIx(priceType?: PriceType): TransactionBuilder;
|
62
62
|
protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder;
|
63
63
|
abstract rebalanceIx(rebalanceStep: RebalanceStep, data: RebalanceDetails): TransactionBuilder;
|
64
64
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,gCAAgC,EAEhC,sBAAsB,EAGvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAKL,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,iBAAkB,SAAQ,wBAAwB;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAChD,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,CACtC,GACC,OAAO,CAAC,IAAI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AAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CACtB"}
|
@@ -22,7 +22,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
22
22
|
openPositionIx(settings?: SolautoSettingsParametersInpArgs, dca?: DCASettingsInpArgs): TransactionBuilder;
|
23
23
|
private marginfiOpenPositionIx;
|
24
24
|
closePositionIx(): TransactionBuilder;
|
25
|
-
refreshIx(priceType
|
25
|
+
refreshIx(priceType?: PriceType): TransactionBuilder;
|
26
26
|
protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder;
|
27
27
|
private marginfiProtocolInteractionIx;
|
28
28
|
private marginfiSolautoProtocolInteractionIx;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoMarginfiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,MAAM,EACN,kBAAkB,EAIlB,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAuB,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,eAAe,EAEf,SAAS,EAET,aAAa,EACb,iBAAiB,EAEjB,gCAAgC,EAOjC,MAAM,iBAAiB,CAAC;AAmBzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMnE,qBAAa,qBAAsB,SAAQ,aAAa;IAC/C,eAAe,kBAA4B;IAE3C,WAAW,EAAG,uBAAuB,CAAC;IAEtC,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,4BAA4B,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7C,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,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C;IAC7C,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,EAAG,qBAAqB,CAAC;IAC/C,oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAE7B,UAAU,CAAC,IAAI,EAAE,iBAAiB;IA6ExC,mBAAmB,IAAI,MAAM,EAAE;IAO/B,gBAAgB,IAAI,SAAS,EAAE;IAI/B,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAAG,kBAAkB;IAStE,cAAc,CACZ,QAAQ,CAAC,EAAE,gCAAgC,EAC3C,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA0C9B,eAAe,IAAI,kBAAkB;IAYrC,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAepD,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUlE,OAAO,CAAC,6BAA6B;IAkFrC,OAAO,CAAC,oCAAoC;IA0D5C,WAAW,CACT,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CA4EtB"}
|
@@ -140,7 +140,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
140
140
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
|
141
141
|
debtPriceOracle: (0, umi_1.publicKey)(this.debtPriceOracle),
|
142
142
|
solautoPosition: (0, umi_1.publicKey)(this.pos.publicKey),
|
143
|
-
priceType,
|
143
|
+
priceType: priceType ?? generated_1.PriceType.Realtime,
|
144
144
|
});
|
145
145
|
}
|
146
146
|
protocolInteractionIx(args) {
|
@@ -24,7 +24,7 @@ class JupSwapManager {
|
|
24
24
|
? "ExactIn"
|
25
25
|
: undefined,
|
26
26
|
slippageBps,
|
27
|
-
maxAccounts: !data.exactOut ? 15 + attemptNum * 5 : undefined,
|
27
|
+
maxAccounts: !data.exactOut ? (memeSwap ? 25 : 15) + attemptNum * 5 : undefined,
|
28
28
|
}), 4, 150);
|
29
29
|
}
|
30
30
|
async getJupInstructions(data) {
|
@@ -5,8 +5,8 @@ import { LendingPlatform, PriceType } from "../generated";
|
|
5
5
|
export declare class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
6
6
|
lendingPlatform: LendingPlatform;
|
7
7
|
maxLtvPriceType: PriceType;
|
8
|
-
|
9
|
-
|
8
|
+
supplyBank: Bank | null;
|
9
|
+
debtBank: Bank | null;
|
10
10
|
supplyPrice(priceType?: PriceType): number | undefined;
|
11
11
|
debtPrice(priceType?: PriceType): number | undefined;
|
12
12
|
private getBankAccounts;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAepE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;
|
1
|
+
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAepE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;IAEzB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;IAC/B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAQ;IAEpC,WAAW,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAItD,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD,OAAO,CAAC,eAAe;IAMjB,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAW3B,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IASpC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAa3D,OAAO,CAAC,6BAA6B;IAwBrC,gCAAgC,CAAC,KAAK,EAAE,IAAI,EAAE;IAK9C,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE;IAQ1C,IAAI,eAAe,cAElB;IAED,IAAI,aAAa,cAEhB;IAED,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BjE"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -265,7 +265,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, prior
|
|
265
265
|
const blockhash = await connection.getLatestBlockhash("confirmed");
|
266
266
|
let cuLimit = undefined;
|
267
267
|
if (txType !== "skip-simulation") {
|
268
|
-
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(umi, connection, assembleFinalTransaction(umi, tx, undefined, 1400000).setBlockhash(blockhash)),
|
268
|
+
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(umi, connection, assembleFinalTransaction(umi, tx, undefined, 1400000).setBlockhash(blockhash)), 2);
|
269
269
|
cuLimit = Math.round(simulationResult.value.unitsConsumed * 1.15);
|
270
270
|
(0, generalUtils_1.consoleLog)("Compute unit limit: ", cuLimit);
|
271
271
|
}
|
package/local/txSandbox.ts
CHANGED
@@ -3,22 +3,30 @@ import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
5
|
ClientTransactionsManager,
|
6
|
+
closeSolautoPosition,
|
6
7
|
consoleLog,
|
8
|
+
deposit,
|
7
9
|
getBatches,
|
8
10
|
getClient,
|
11
|
+
getMaxLiqUtilizationRateBps,
|
9
12
|
getPositionExBulk,
|
10
13
|
getSolanaRpcConnection,
|
11
14
|
getSolautoManagedPositions,
|
12
15
|
LendingPlatform,
|
13
16
|
LOCAL_IRONFORGE_API_URL,
|
17
|
+
openSolautoPosition,
|
14
18
|
PriceType,
|
15
19
|
PriorityFeeSetting,
|
16
20
|
ProgramEnv,
|
17
21
|
rebalance,
|
22
|
+
RETARDIO,
|
18
23
|
SOLAUTO_PROD_PROGRAM,
|
19
24
|
SOLAUTO_TEST_PROGRAM,
|
20
25
|
SolautoClient,
|
26
|
+
toBaseUnit,
|
21
27
|
TransactionItem,
|
28
|
+
USDC,
|
29
|
+
withdraw,
|
22
30
|
} from "../src";
|
23
31
|
import { getSecretKey } from "./shared";
|
24
32
|
|
@@ -34,7 +42,7 @@ let [, umi] = getSolanaRpcConnection(
|
|
34
42
|
|
35
43
|
const signer = createSignerFromKeypair(
|
36
44
|
umi,
|
37
|
-
fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey(
|
45
|
+
fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey()))
|
38
46
|
);
|
39
47
|
|
40
48
|
export async function main() {
|
@@ -47,20 +55,52 @@ export async function main() {
|
|
47
55
|
});
|
48
56
|
|
49
57
|
await client.initializeExistingSolautoPosition({
|
50
|
-
positionId:
|
51
|
-
authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
|
58
|
+
positionId: 3,
|
59
|
+
// authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
|
52
60
|
// lpUserAccount: new PublicKey(
|
53
61
|
// "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
54
62
|
// ),
|
63
|
+
// lpPoolAccount: new PublicKey(
|
64
|
+
// "EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm"
|
65
|
+
// ),
|
66
|
+
// supplyMint: new PublicKey(USDC),
|
67
|
+
// debtMint: new PublicKey(RETARDIO),
|
55
68
|
});
|
56
69
|
|
57
|
-
|
70
|
+
await client.pos.refreshPositionState();
|
71
|
+
|
72
|
+
// const transactionItems = [
|
73
|
+
// openSolautoPosition(client, {
|
74
|
+
// boostGap: 100,
|
75
|
+
// boostToBps: client.pos.maxBoostToBps,
|
76
|
+
// repayGap: 100,
|
77
|
+
// repayToBps: client.pos.maxRepayToBps,
|
78
|
+
// }),
|
79
|
+
// ];
|
80
|
+
const transactionItems = [
|
81
|
+
// openSolautoPosition(client, {
|
82
|
+
// boostGap: 100,
|
83
|
+
// boostToBps: client.pos.maxBoostToBps,
|
84
|
+
// repayGap: 100,
|
85
|
+
// repayToBps: client.pos.maxRepayToBps,
|
86
|
+
// }),
|
87
|
+
deposit(client, toBaseUnit(50, client.pos.supplyMintInfo.decimals)),
|
88
|
+
rebalance(client, client.pos.maxBoostToBps),
|
89
|
+
// withdraw(client, "All"),
|
90
|
+
// closeSolautoPosition(client)
|
91
|
+
// new TransactionItem(
|
92
|
+
// async () => ({ tx: client.refreshIx() }),
|
93
|
+
// `refresh`,
|
94
|
+
// true
|
95
|
+
// ),
|
96
|
+
];
|
58
97
|
|
59
98
|
const txManager = new ClientTransactionsManager({
|
60
99
|
txHandler: client,
|
61
100
|
txRunType: payForTransaction ? "normal" : "only-simulate",
|
62
101
|
priorityFeeSetting: PriorityFeeSetting.Default,
|
63
|
-
retryConfig: { totalRetries:
|
102
|
+
retryConfig: { totalRetries: 0 },
|
103
|
+
// atomically: false,
|
64
104
|
});
|
65
105
|
const statuses = await txManager.send(transactionItems);
|
66
106
|
consoleLog(statuses);
|
@@ -105,7 +145,7 @@ async function refreshAll() {
|
|
105
145
|
txHandler: client!,
|
106
146
|
txRunType: payForTransaction ? "normal" : "only-simulate",
|
107
147
|
priorityFeeSetting: PriorityFeeSetting.Default,
|
108
|
-
retryConfig: { totalRetries:
|
148
|
+
retryConfig: { totalRetries: 2 },
|
109
149
|
});
|
110
150
|
const statuses = await txManager.send(batch);
|
111
151
|
consoleLog(statuses);
|
package/package.json
CHANGED
@@ -8,11 +8,13 @@ import { PriceType, RebalanceDirection, TokenType } from "../../generated";
|
|
8
8
|
import {
|
9
9
|
consoleLog,
|
10
10
|
fromBaseUnit,
|
11
|
+
fromBps,
|
11
12
|
getLiqUtilzationRateBps,
|
12
13
|
safeGetPrice,
|
13
14
|
toBaseUnit,
|
14
15
|
tokenInfo,
|
15
16
|
} from "../../utils";
|
17
|
+
import { SolautoFeesBps } from "./solautoFees";
|
16
18
|
|
17
19
|
export class RebalanceSwapManager {
|
18
20
|
public swapParams!: SwapParams;
|
@@ -20,6 +22,7 @@ export class RebalanceSwapManager {
|
|
20
22
|
public flBorrowAmount?: bigint;
|
21
23
|
|
22
24
|
private jupSwapManager!: JupSwapManager;
|
25
|
+
private solautoFeeBps!: number;
|
23
26
|
|
24
27
|
constructor(
|
25
28
|
private client: SolautoClient,
|
@@ -29,6 +32,11 @@ export class RebalanceSwapManager {
|
|
29
32
|
private priceType?: PriceType
|
30
33
|
) {
|
31
34
|
this.jupSwapManager = new JupSwapManager(client.signer);
|
35
|
+
this.solautoFeeBps = SolautoFeesBps.create(
|
36
|
+
this.client.isReferred,
|
37
|
+
this.targetLiqUtilizationRateBps,
|
38
|
+
this.client.pos.netWorthUsd(this.priceType)
|
39
|
+
).getSolautoFeesBps(values.rebalanceDirection).total;
|
32
40
|
}
|
33
41
|
|
34
42
|
private isBoost() {
|
@@ -47,12 +55,22 @@ export class RebalanceSwapManager {
|
|
47
55
|
? this.client.pos.state.supply
|
48
56
|
: this.client.pos.state.debt;
|
49
57
|
|
50
|
-
// const
|
51
|
-
//
|
52
|
-
//
|
53
|
-
//
|
54
|
-
const
|
55
|
-
|
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
|
+
|
67
|
+
const supplyPrice = this.client.pos.supplyPrice(this.priceType)!;
|
68
|
+
const debtPrice = this.client.pos.debtPrice(this.priceType)!;
|
69
|
+
const biasedInputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
70
|
+
const biasedOutputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
71
|
+
|
72
|
+
const inputPrice = biasedInputPrice;
|
73
|
+
const outputPrice = biasedOutputPrice;
|
56
74
|
|
57
75
|
let inputAmount = toBaseUnit(
|
58
76
|
this.usdToSwap() / inputPrice!,
|
@@ -63,31 +81,43 @@ export class RebalanceSwapManager {
|
|
63
81
|
inputAmount,
|
64
82
|
input,
|
65
83
|
inputPrice,
|
84
|
+
biasedInputPrice,
|
66
85
|
output,
|
67
86
|
outputPrice,
|
87
|
+
biasedOutputPrice,
|
68
88
|
};
|
69
89
|
}
|
70
90
|
|
71
|
-
private postRebalanceLiqUtilizationRateBps(
|
91
|
+
private postRebalanceLiqUtilizationRateBps(
|
92
|
+
swapOutputAmount?: bigint,
|
93
|
+
swapInputAmount?: bigint
|
94
|
+
) {
|
72
95
|
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
73
96
|
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
74
97
|
// TODO: add token balance change
|
75
98
|
|
76
|
-
const { output,
|
99
|
+
const { input, biasedInputPrice, output, biasedOutputPrice } =
|
100
|
+
this.swapDetails();
|
101
|
+
|
102
|
+
const swapInputUsd = swapInputAmount
|
103
|
+
? fromBaseUnit(
|
104
|
+
swapInputAmount,
|
105
|
+
tokenInfo(toWeb3JsPublicKey(input.mint)).decimals
|
106
|
+
) * biasedInputPrice
|
107
|
+
: this.usdToSwap();
|
77
108
|
|
78
|
-
|
109
|
+
let swapOutputUsd = swapOutputAmount
|
79
110
|
? fromBaseUnit(
|
80
111
|
swapOutputAmount,
|
81
112
|
tokenInfo(toWeb3JsPublicKey(output.mint)).decimals
|
82
|
-
) *
|
113
|
+
) * biasedOutputPrice
|
83
114
|
: this.usdToSwap();
|
115
|
+
swapOutputUsd = swapOutputUsd - swapOutputUsd * fromBps(this.solautoFeeBps);
|
84
116
|
|
85
117
|
supplyUsd = this.isBoost()
|
86
118
|
? supplyUsd + swapOutputUsd
|
87
|
-
: supplyUsd -
|
88
|
-
debtUsd = this.isBoost()
|
89
|
-
? debtUsd + this.usdToSwap()
|
90
|
-
: debtUsd - swapOutputUsd;
|
119
|
+
: supplyUsd - swapInputUsd;
|
120
|
+
debtUsd = this.isBoost() ? debtUsd + swapInputUsd : debtUsd - swapOutputUsd;
|
91
121
|
|
92
122
|
return getLiqUtilzationRateBps(
|
93
123
|
supplyUsd,
|
@@ -107,13 +137,14 @@ export class RebalanceSwapManager {
|
|
107
137
|
let swapQuote: QuoteResponse;
|
108
138
|
let insufficient: boolean = false;
|
109
139
|
|
110
|
-
for (let i = 0; i <
|
140
|
+
for (let i = 0; i < 20; i++) {
|
111
141
|
consoleLog("Finding sufficient quote...");
|
112
142
|
swapQuote = await this.jupSwapManager.getQuote(swapInput);
|
113
143
|
|
114
144
|
const outputAmount = parseInt(swapQuote.outAmount);
|
115
145
|
const postRebalanceRate = this.postRebalanceLiqUtilizationRateBps(
|
116
|
-
BigInt(outputAmount)
|
146
|
+
BigInt(outputAmount),
|
147
|
+
BigInt(parseInt(swapQuote.inAmount))
|
117
148
|
);
|
118
149
|
insufficient = criteria.minOutputAmount
|
119
150
|
? outputAmount < Number(criteria.minOutputAmount)
|
@@ -121,9 +152,15 @@ export class RebalanceSwapManager {
|
|
121
152
|
? postRebalanceRate < criteria.minLiqUtilizationRateBps
|
122
153
|
: postRebalanceRate > criteria.maxLiqUtilizationRateBps!;
|
123
154
|
|
155
|
+
consoleLog(postRebalanceRate, criteria.maxLiqUtilizationRateBps);
|
124
156
|
if (insufficient) {
|
125
157
|
consoleLog("Insufficient swap quote:", swapQuote);
|
126
|
-
|
158
|
+
|
159
|
+
const increment = 0.01 + i * 0.001;
|
160
|
+
swapInput.amount = this.bigIntWithIncrement(
|
161
|
+
swapInput.amount,
|
162
|
+
this.isBoost() ? increment * -1 : increment
|
163
|
+
);
|
127
164
|
} else {
|
128
165
|
break;
|
129
166
|
}
|
@@ -183,11 +220,11 @@ export class RebalanceSwapManager {
|
|
183
220
|
};
|
184
221
|
consoleLog("Swap input:", swapInput);
|
185
222
|
|
186
|
-
if (exactIn
|
223
|
+
if (exactIn) {
|
187
224
|
this.swapQuote = await this.findSufficientQuote(swapInput, {
|
188
225
|
minOutputAmount: rebalanceToZero ? outputAmount : undefined,
|
189
|
-
maxLiqUtilizationRateBps:
|
190
|
-
? this.client.pos.
|
226
|
+
maxLiqUtilizationRateBps: !rebalanceToZero
|
227
|
+
? this.client.pos.maxBoostToBps
|
191
228
|
: undefined,
|
192
229
|
});
|
193
230
|
}
|
@@ -8,13 +8,16 @@ import {
|
|
8
8
|
TransactionItemInputs,
|
9
9
|
} from "../../types";
|
10
10
|
import {
|
11
|
+
bytesToI80F48,
|
11
12
|
consoleLog,
|
12
13
|
fromBaseUnit,
|
13
14
|
fromBps,
|
15
|
+
getLiqUtilzationRateBps,
|
14
16
|
getMaxLiqUtilizationRateBps,
|
15
17
|
getTokenAccount,
|
16
18
|
hasFirstRebalance,
|
17
19
|
hasLastRebalance,
|
20
|
+
isMarginfiPosition,
|
18
21
|
safeGetPrice,
|
19
22
|
tokenInfo,
|
20
23
|
} from "../../utils";
|
@@ -346,6 +349,12 @@ export class RebalanceTxBuilder {
|
|
346
349
|
this.client.pos.debtPrice(this.priceType)
|
347
350
|
);
|
348
351
|
|
352
|
+
if (isMarginfiPosition(this.client.pos)) {
|
353
|
+
const supply = this.values.endResult.supplyUsd * bytesToI80F48(this.client.pos.supplyBank!.config.assetWeightInit.value);
|
354
|
+
const debt = this.values.endResult.debtUsd * bytesToI80F48(this.client.pos.debtBank!.config.liabilityWeightInit.value);
|
355
|
+
consoleLog("Weighted values", supply, debt);
|
356
|
+
}
|
357
|
+
|
349
358
|
const firstRebalance = this.client.rebalanceIx(
|
350
359
|
RebalanceStep.PreSwap,
|
351
360
|
rebalanceDetails
|
@@ -437,7 +437,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
437
437
|
});
|
438
438
|
}
|
439
439
|
|
440
|
-
abstract refreshIx(priceType
|
440
|
+
abstract refreshIx(priceType?: PriceType): TransactionBuilder;
|
441
441
|
|
442
442
|
protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder {
|
443
443
|
let tx = transactionBuilder();
|
@@ -230,7 +230,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
230
230
|
});
|
231
231
|
}
|
232
232
|
|
233
|
-
refreshIx(priceType
|
233
|
+
refreshIx(priceType?: PriceType): TransactionBuilder {
|
234
234
|
return marginfiRefreshData(this.umi, {
|
235
235
|
signer: this.signer,
|
236
236
|
marginfiProgram: publicKey(this.mfiAccounts.program),
|
@@ -241,7 +241,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
241
241
|
debtBank: publicKey(this.marginfiDebtAccounts.bank),
|
242
242
|
debtPriceOracle: publicKey(this.debtPriceOracle),
|
243
243
|
solautoPosition: publicKey(this.pos.publicKey),
|
244
|
-
priceType,
|
244
|
+
priceType: priceType ?? PriceType.Realtime,
|
245
245
|
});
|
246
246
|
}
|
247
247
|
|
@@ -21,8 +21,8 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
21
21
|
lendingPlatform = LendingPlatform.Marginfi;
|
22
22
|
maxLtvPriceType = PriceType.Ema;
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
public supplyBank: Bank | null = null;
|
25
|
+
public debtBank: Bank | null = null;
|
26
26
|
|
27
27
|
supplyPrice(priceType?: PriceType): number | undefined {
|
28
28
|
return this._supplyPrice ?? safeGetPrice(this.supplyMint, priceType, PriceBias.Low);
|
package/src/utils/jitoUtils.ts
CHANGED
package/src/utils/solanaUtils.ts
CHANGED