@haven-fi/solauto-sdk 1.0.700 → 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 +5 -2
- package/local/txSandbox.ts +2 -1
- package/package.json +1 -1
- package/src/services/rebalance/rebalanceSwapManager.ts +11 -2
@@ -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;
|
@@ -60,9 +62,10 @@ class RebalanceSwapManager {
|
|
60
62
|
const swapInputUsd = swapInputAmount
|
61
63
|
? (0, utils_1.fromBaseUnit)(swapInputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint)).decimals) * biasedInputPrice
|
62
64
|
: this.usdToSwap();
|
63
|
-
|
65
|
+
let swapOutputUsd = swapOutputAmount
|
64
66
|
? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint)).decimals) * biasedOutputPrice
|
65
67
|
: this.usdToSwap();
|
68
|
+
swapOutputUsd = swapOutputUsd - swapOutputUsd * (0, utils_1.fromBps)(this.solautoFeeBps);
|
66
69
|
supplyUsd = this.isBoost()
|
67
70
|
? supplyUsd + swapOutputUsd
|
68
71
|
: supplyUsd - swapInputUsd;
|
@@ -85,7 +88,7 @@ class RebalanceSwapManager {
|
|
85
88
|
(0, utils_1.consoleLog)(postRebalanceRate, criteria.maxLiqUtilizationRateBps);
|
86
89
|
if (insufficient) {
|
87
90
|
(0, utils_1.consoleLog)("Insufficient swap quote:", swapQuote);
|
88
|
-
const increment = 0.01 + i * 0.
|
91
|
+
const increment = 0.01 + i * 0.001;
|
89
92
|
swapInput.amount = this.bigIntWithIncrement(swapInput.amount, this.isBoost() ? increment * -1 : increment);
|
90
93
|
}
|
91
94
|
else {
|
package/local/txSandbox.ts
CHANGED
@@ -8,6 +8,7 @@ import {
|
|
8
8
|
deposit,
|
9
9
|
getBatches,
|
10
10
|
getClient,
|
11
|
+
getMaxLiqUtilizationRateBps,
|
11
12
|
getPositionExBulk,
|
12
13
|
getSolanaRpcConnection,
|
13
14
|
getSolautoManagedPositions,
|
@@ -83,7 +84,7 @@ export async function main() {
|
|
83
84
|
// repayGap: 100,
|
84
85
|
// repayToBps: client.pos.maxRepayToBps,
|
85
86
|
// }),
|
86
|
-
deposit(client, toBaseUnit(
|
87
|
+
deposit(client, toBaseUnit(50, client.pos.supplyMintInfo.decimals)),
|
87
88
|
rebalance(client, client.pos.maxBoostToBps),
|
88
89
|
// withdraw(client, "All"),
|
89
90
|
// closeSolautoPosition(client)
|
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() {
|
@@ -98,12 +106,13 @@ export class RebalanceSwapManager {
|
|
98
106
|
) * biasedInputPrice
|
99
107
|
: this.usdToSwap();
|
100
108
|
|
101
|
-
|
109
|
+
let swapOutputUsd = swapOutputAmount
|
102
110
|
? fromBaseUnit(
|
103
111
|
swapOutputAmount,
|
104
112
|
tokenInfo(toWeb3JsPublicKey(output.mint)).decimals
|
105
113
|
) * biasedOutputPrice
|
106
114
|
: this.usdToSwap();
|
115
|
+
swapOutputUsd = swapOutputUsd - swapOutputUsd * fromBps(this.solautoFeeBps);
|
107
116
|
|
108
117
|
supplyUsd = this.isBoost()
|
109
118
|
? supplyUsd + swapOutputUsd
|
@@ -147,7 +156,7 @@ export class RebalanceSwapManager {
|
|
147
156
|
if (insufficient) {
|
148
157
|
consoleLog("Insufficient swap quote:", swapQuote);
|
149
158
|
|
150
|
-
const increment = 0.01 + i * 0.
|
159
|
+
const increment = 0.01 + i * 0.001;
|
151
160
|
swapInput.amount = this.bigIntWithIncrement(
|
152
161
|
swapInput.amount,
|
153
162
|
this.isBoost() ? increment * -1 : increment
|