@haven-fi/solauto-sdk 1.0.695 → 1.0.696
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.
@@ -17,9 +17,9 @@ export declare class RebalanceSwapManager {
|
|
17
17
|
constructor(client: SolautoClient, values: RebalanceValues, flRequirements?: FlashLoanRequirements | undefined, targetLiqUtilizationRateBps?: number | undefined, priceType?: PriceType | undefined);
|
18
18
|
private isBoost;
|
19
19
|
private usdToSwap;
|
20
|
+
private swapDetails;
|
20
21
|
private postRebalanceLiqUtilizationRateBps;
|
21
22
|
private findSufficientQuote;
|
22
|
-
private swapDetails;
|
23
23
|
private bigIntWithIncrement;
|
24
24
|
setSwapParams(attemptNum: number): Promise<void>;
|
25
25
|
getSwapTxData(): Promise<{
|
@@ -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;AAS3E,qBAAa,oBAAoB;IAQ7B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,SAAS,CAAC;IAXb,UAAU,EAAG,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,cAAc,CAAkB;gBAG9B,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;IAK/B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,WAAW;IA2BnB,OAAO,CAAC,kCAAkC;YA4B5B,mBAAmB;IAoCjC,OAAO,CAAC,mBAAmB;IAIrB,aAAa,CAAC,UAAU,EAAE,MAAM;IAyEhC,aAAa;;;;;;CAWpB"}
|
@@ -20,16 +20,33 @@ class RebalanceSwapManager {
|
|
20
20
|
usdToSwap() {
|
21
21
|
return Math.abs(this.values.debtAdjustmentUsd);
|
22
22
|
}
|
23
|
+
swapDetails() {
|
24
|
+
const input = this.isBoost()
|
25
|
+
? this.client.pos.state.debt
|
26
|
+
: this.client.pos.state.supply;
|
27
|
+
const output = this.isBoost()
|
28
|
+
? this.client.pos.state.supply
|
29
|
+
: this.client.pos.state.debt;
|
30
|
+
const supplyPrice = this.client.pos.supplyPrice(this.priceType);
|
31
|
+
const debtPrice = this.client.pos.debtPrice(this.priceType);
|
32
|
+
const inputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
33
|
+
const outputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
34
|
+
let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() / inputPrice, input.decimals);
|
35
|
+
return {
|
36
|
+
inputAmount,
|
37
|
+
input,
|
38
|
+
inputPrice,
|
39
|
+
output,
|
40
|
+
outputPrice,
|
41
|
+
};
|
42
|
+
}
|
23
43
|
postRebalanceLiqUtilizationRateBps(swapOutputAmount) {
|
24
44
|
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
25
45
|
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
26
46
|
// TODO: add token balance change
|
27
|
-
const
|
28
|
-
? this.client.pos.supplyMint
|
29
|
-
: this.client.pos.debtMint;
|
47
|
+
const { output, outputPrice } = this.swapDetails();
|
30
48
|
const swapOutputUsd = swapOutputAmount
|
31
|
-
? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)(
|
32
|
-
(0, utils_1.safeGetPrice)(outputToken, this.priceType)
|
49
|
+
? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint)).decimals) * outputPrice
|
33
50
|
: this.usdToSwap();
|
34
51
|
supplyUsd = this.isBoost()
|
35
52
|
? supplyUsd + swapOutputUsd
|
@@ -62,32 +79,18 @@ class RebalanceSwapManager {
|
|
62
79
|
}
|
63
80
|
return swapQuote;
|
64
81
|
}
|
65
|
-
swapDetails() {
|
66
|
-
const input = this.isBoost()
|
67
|
-
? this.client.pos.state.debt
|
68
|
-
: this.client.pos.state.supply;
|
69
|
-
const output = this.isBoost()
|
70
|
-
? this.client.pos.state.supply
|
71
|
-
: this.client.pos.state.debt;
|
72
|
-
let inputAmount = (0, utils_1.toBaseUnit)(this.usdToSwap() / (0, utils_1.safeGetPrice)(input.mint, this.priceType), input.decimals);
|
73
|
-
return {
|
74
|
-
input,
|
75
|
-
output,
|
76
|
-
inputAmount,
|
77
|
-
};
|
78
|
-
}
|
79
82
|
bigIntWithIncrement(num, inc) {
|
80
83
|
return num + BigInt(Math.round(Number(num) * inc));
|
81
84
|
}
|
82
85
|
async setSwapParams(attemptNum) {
|
83
86
|
const rebalanceToZero = this.targetLiqUtilizationRateBps === 0;
|
84
|
-
let { input, output, inputAmount } = this.swapDetails();
|
87
|
+
let { input, output, outputPrice, inputAmount } = this.swapDetails();
|
85
88
|
let outputAmount = rebalanceToZero
|
86
89
|
? output.amountUsed.baseUnit +
|
87
90
|
BigInt(Math.round(Number(output.amountUsed.baseUnit) *
|
88
91
|
// Add this small percentage to account for the APR on the debt between now and the transaction
|
89
92
|
0.0001))
|
90
|
-
: (0, utils_1.toBaseUnit)(this.usdToSwap() /
|
93
|
+
: (0, utils_1.toBaseUnit)(this.usdToSwap() / outputPrice, output.decimals);
|
91
94
|
const flashLoanRepayFromDebt = !this.isBoost() &&
|
92
95
|
this.flRequirements &&
|
93
96
|
this.flRequirements.liquiditySource === generated_1.TokenType.Debt;
|
package/package.json
CHANGED
@@ -9,7 +9,6 @@ import {
|
|
9
9
|
consoleLog,
|
10
10
|
fromBaseUnit,
|
11
11
|
getLiqUtilzationRateBps,
|
12
|
-
safeGetPrice,
|
13
12
|
toBaseUnit,
|
14
13
|
tokenInfo,
|
15
14
|
} from "../../utils";
|
@@ -39,17 +38,45 @@ export class RebalanceSwapManager {
|
|
39
38
|
return Math.abs(this.values.debtAdjustmentUsd);
|
40
39
|
}
|
41
40
|
|
41
|
+
private swapDetails() {
|
42
|
+
const input = this.isBoost()
|
43
|
+
? this.client.pos.state.debt
|
44
|
+
: this.client.pos.state.supply;
|
45
|
+
const output = this.isBoost()
|
46
|
+
? this.client.pos.state.supply
|
47
|
+
: this.client.pos.state.debt;
|
48
|
+
|
49
|
+
const supplyPrice = this.client.pos.supplyPrice(this.priceType)!;
|
50
|
+
const debtPrice = this.client.pos.debtPrice(this.priceType)!;
|
51
|
+
const inputPrice = this.isBoost() ? debtPrice : supplyPrice;
|
52
|
+
const outputPrice = this.isBoost() ? supplyPrice : debtPrice;
|
53
|
+
|
54
|
+
let inputAmount = toBaseUnit(
|
55
|
+
this.usdToSwap() / inputPrice!,
|
56
|
+
input.decimals
|
57
|
+
);
|
58
|
+
|
59
|
+
return {
|
60
|
+
inputAmount,
|
61
|
+
input,
|
62
|
+
inputPrice,
|
63
|
+
output,
|
64
|
+
outputPrice,
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
42
68
|
private postRebalanceLiqUtilizationRateBps(swapOutputAmount?: bigint) {
|
43
69
|
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
44
70
|
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
45
71
|
// TODO: add token balance change
|
46
72
|
|
47
|
-
const
|
48
|
-
|
49
|
-
: this.client.pos.debtMint;
|
73
|
+
const { output, outputPrice } = this.swapDetails();
|
74
|
+
|
50
75
|
const swapOutputUsd = swapOutputAmount
|
51
|
-
? fromBaseUnit(
|
52
|
-
|
76
|
+
? fromBaseUnit(
|
77
|
+
swapOutputAmount,
|
78
|
+
tokenInfo(toWeb3JsPublicKey(output.mint)).decimals
|
79
|
+
) * outputPrice
|
53
80
|
: this.usdToSwap();
|
54
81
|
|
55
82
|
supplyUsd = this.isBoost()
|
@@ -102,33 +129,13 @@ export class RebalanceSwapManager {
|
|
102
129
|
return swapQuote!;
|
103
130
|
}
|
104
131
|
|
105
|
-
private swapDetails() {
|
106
|
-
const input = this.isBoost()
|
107
|
-
? this.client.pos.state.debt
|
108
|
-
: this.client.pos.state.supply;
|
109
|
-
const output = this.isBoost()
|
110
|
-
? this.client.pos.state.supply
|
111
|
-
: this.client.pos.state.debt;
|
112
|
-
|
113
|
-
let inputAmount = toBaseUnit(
|
114
|
-
this.usdToSwap() / safeGetPrice(input.mint, this.priceType)!,
|
115
|
-
input.decimals
|
116
|
-
);
|
117
|
-
|
118
|
-
return {
|
119
|
-
input,
|
120
|
-
output,
|
121
|
-
inputAmount,
|
122
|
-
};
|
123
|
-
}
|
124
|
-
|
125
132
|
private bigIntWithIncrement(num: bigint, inc: number) {
|
126
133
|
return num + BigInt(Math.round(Number(num) * inc));
|
127
134
|
}
|
128
135
|
|
129
136
|
async setSwapParams(attemptNum: number) {
|
130
137
|
const rebalanceToZero = this.targetLiqUtilizationRateBps === 0;
|
131
|
-
let { input, output, inputAmount } = this.swapDetails();
|
138
|
+
let { input, output, outputPrice, inputAmount } = this.swapDetails();
|
132
139
|
|
133
140
|
let outputAmount = rebalanceToZero
|
134
141
|
? output.amountUsed.baseUnit +
|
@@ -139,10 +146,7 @@ export class RebalanceSwapManager {
|
|
139
146
|
0.0001
|
140
147
|
)
|
141
148
|
)
|
142
|
-
: toBaseUnit(
|
143
|
-
this.usdToSwap() / safeGetPrice(output.mint, this.priceType)!,
|
144
|
-
output.decimals
|
145
|
-
);
|
149
|
+
: toBaseUnit(this.usdToSwap() / outputPrice, output.decimals);
|
146
150
|
|
147
151
|
const flashLoanRepayFromDebt =
|
148
152
|
!this.isBoost() &&
|