@haven-fi/solauto-sdk 1.0.217 → 1.0.219

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ import { RebalanceDirection } from "../generated";
1
2
  export declare function getLiqUtilzationRateBps(supplyUsd: number, debtUsd: number, liqThresholdBps: number): number;
2
3
  export declare function toBaseUnit(value: number, decimals: number): bigint;
3
4
  export declare function fromBaseUnit(value: bigint, decimals: number): number;
@@ -6,7 +7,7 @@ export declare function toBps(value: number): number;
6
7
  export declare function bytesToI80F48(bytes: number[]): number;
7
8
  export declare function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint;
8
9
  export declare function getDebtAdjustmentUsd(liqThresholdBps: number, supplyUsd: number, debtUsd: number, targetLiqUtilizationRateBps: number, adjustmentFeeBps?: number): number;
9
- export declare function getSolautoFeesBps(isReferred: boolean, targetLiqUtilizationRateBps: number | undefined, positionNetWorthUsd: number): {
10
+ export declare function getSolautoFeesBps(isReferred: boolean, targetLiqUtilizationRateBps: number | undefined, positionNetWorthUsd: number, rebalanceDirection: RebalanceDirection): {
10
11
  solauto: number;
11
12
  referrer: number;
12
13
  total: number;
@@ -1 +1 @@
1
- {"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,GACtB,MAAM,CAMR;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,M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AED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAejE;AAED,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,2BAA2B,EAAE,MAAM,EACnC,gBAAgB,CAAC,EAAE,MAAM,UAW1B;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,2BAA2B,EAAE,MAAM,GAAG,SAAS,EAC/C,mBAAmB,EAAE,MAAM,EAC3B,kBAAkB,EAAE,kBAAkB,GACrC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAgCA;AAED,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAER;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKzE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKvE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKvE"}
@@ -14,6 +14,7 @@ exports.maxRepayFromBps = maxRepayFromBps;
14
14
  exports.maxRepayToBps = maxRepayToBps;
15
15
  exports.maxBoostToBps = maxBoostToBps;
16
16
  const constants_1 = require("../constants");
17
+ const generated_1 = require("../generated");
17
18
  function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
18
19
  if (supplyUsd === 0) {
19
20
  return 0;
@@ -66,14 +67,14 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
66
67
  (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
67
68
  return debtAdjustmentUsd;
68
69
  }
69
- function getSolautoFeesBps(isReferred, targetLiqUtilizationRateBps, positionNetWorthUsd) {
70
+ function getSolautoFeesBps(isReferred, targetLiqUtilizationRateBps, positionNetWorthUsd, rebalanceDirection) {
70
71
  const minSize = 10000; // Minimum position size
71
72
  const maxSize = 500000; // Maximum position size
72
73
  const maxFeeBps = 200; // Fee in basis points for minSize (2%)
73
74
  const minFeeBps = 50; // Fee in basis points for maxSize (0.5%)
74
75
  const k = 1.5;
75
76
  let feeBps = 0;
76
- if (targetLiqUtilizationRateBps !== undefined) {
77
+ if (targetLiqUtilizationRateBps !== undefined || rebalanceDirection === generated_1.RebalanceDirection.Repay) {
77
78
  feeBps = 25;
78
79
  }
79
80
  else if (positionNetWorthUsd <= minSize) {
@@ -1,17 +1,17 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { SolautoClient } from "../../clients/solautoClient";
3
- import { DCASettings, PositionState, SolautoSettingsParameters, TokenType } from "../../generated";
3
+ import { DCASettings, PositionState, RebalanceDirection, SolautoSettingsParameters, TokenType } from "../../generated";
4
4
  import { QuoteResponse } from "@jup-ag/api";
5
5
  import { JupSwapDetails } from "../jupiterUtils";
6
6
  import { RebalanceAction } from "../../types";
7
7
  export interface RebalanceValues {
8
- increasingLeverage: boolean;
9
8
  debtAdjustmentUsd: number;
10
9
  repayingCloseToMaxLtv: boolean;
11
10
  amountToDcaIn: number;
12
11
  amountUsdToDcaIn: number;
13
12
  dcaTokenType?: TokenType;
14
13
  rebalanceAction: RebalanceAction;
14
+ rebalanceDirection: RebalanceDirection;
15
15
  }
16
16
  export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): RebalanceValues;
17
17
  export interface FlashLoanDetails {
@@ -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,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAkI9C,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,GACnC,eAAe,CAmDjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG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B,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CA0D9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAyChB"}
@@ -83,24 +83,21 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
83
83
  const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, targetLiqUtilizationRateBps);
84
84
  const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
85
85
  (dca?.tokenType === generated_1.TokenType.Debt ? debtPrice : supplyPrice);
86
- const increasingLeverage = amountUsdToDcaIn > 0 || state.liqUtilizationRateBps < targetRateBps;
87
- let adjustmentFeeBps = 0;
88
- if (increasingLeverage) {
89
- adjustmentFeeBps = (0, numberUtils_1.getSolautoFeesBps)(false, targetLiqUtilizationRateBps, (0, numberUtils_1.fromBaseUnit)(state.netWorth.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS)).total;
90
- }
86
+ const rebalanceDirection = amountUsdToDcaIn > 0 || state.liqUtilizationRateBps < targetRateBps ? generated_1.RebalanceDirection.Boost : generated_1.RebalanceDirection.Repay;
87
+ const adjustmentFeeBps = (0, numberUtils_1.getSolautoFeesBps)(false, targetLiqUtilizationRateBps, (0, numberUtils_1.fromBaseUnit)(state.netWorth.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS), rebalanceDirection).total;
91
88
  const supplyUsd = (0, numberUtils_1.fromBaseUnit)(state.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) +
92
89
  amountUsdToDcaIn;
93
90
  const debtUsd = (0, numberUtils_1.fromBaseUnit)(state.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
94
91
  let debtAdjustmentUsd = (0, numberUtils_1.getDebtAdjustmentUsd)(state.liqThresholdBps, supplyUsd, debtUsd, targetRateBps, adjustmentFeeBps);
95
92
  const maxRepayTo = (0, numberUtils_1.maxRepayToBps)(state.maxLtvBps, state.liqThresholdBps);
96
93
  return {
97
- increasingLeverage,
98
94
  debtAdjustmentUsd,
99
95
  repayingCloseToMaxLtv: state.liqUtilizationRateBps > maxRepayTo && targetRateBps >= maxRepayTo,
100
96
  amountToDcaIn: amountToDcaIn ?? 0,
101
97
  amountUsdToDcaIn,
102
98
  dcaTokenType: dca?.tokenType,
103
- rebalanceAction: (amountToDcaIn ?? 0) > 0 ? "dca" : increasingLeverage ? "boost" : "repay",
99
+ rebalanceAction: (amountToDcaIn ?? 0) > 0 ? "dca" : rebalanceDirection === generated_1.RebalanceDirection.Boost ? "boost" : "repay",
100
+ rebalanceDirection,
104
101
  };
105
102
  }
106
103
  function getFlashLoanDetails(client, values, jupQuote) {
@@ -118,7 +115,7 @@ function getFlashLoanDetails(client, values, jupQuote) {
118
115
  (0, numberUtils_1.getMaxLiqUtilizationRateBps)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps, 0.01);
119
116
  let flashLoanToken = undefined;
120
117
  let flashLoanTokenPrice = 0;
121
- if (values.increasingLeverage) {
118
+ if (values.rebalanceDirection === generated_1.RebalanceDirection.Boost) {
122
119
  flashLoanToken = client.solautoPositionState.debt;
123
120
  flashLoanTokenPrice = (0, generalUtils_2.safeGetPrice)(client.debtMint);
124
121
  }
@@ -139,10 +136,10 @@ function getFlashLoanDetails(client, values, jupQuote) {
139
136
  : undefined;
140
137
  }
141
138
  function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps, attemptNum) {
142
- const input = values.increasingLeverage
139
+ const input = values.rebalanceDirection === generated_1.RebalanceDirection.Boost
143
140
  ? client.solautoPositionState.debt
144
141
  : client.solautoPositionState.supply;
145
- const output = values.increasingLeverage
142
+ const output = values.rebalanceDirection === generated_1.RebalanceDirection.Boost
146
143
  ? client.solautoPositionState.supply
147
144
  : client.solautoPositionState.debt;
148
145
  const usdToSwap = Math.abs(values.debtAdjustmentUsd) +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.217",
3
+ "version": "1.0.219",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -1,4 +1,5 @@
1
1
  import { BASIS_POINTS, MIN_REPAY_GAP_BPS } from "../constants";
2
+ import { RebalanceDirection } from "../generated";
2
3
 
3
4
  export function getLiqUtilzationRateBps(
4
5
  supplyUsd: number,
@@ -89,7 +90,8 @@ export function getDebtAdjustmentUsd(
89
90
  export function getSolautoFeesBps(
90
91
  isReferred: boolean,
91
92
  targetLiqUtilizationRateBps: number | undefined,
92
- positionNetWorthUsd: number
93
+ positionNetWorthUsd: number,
94
+ rebalanceDirection: RebalanceDirection
93
95
  ): {
94
96
  solauto: number;
95
97
  referrer: number;
@@ -103,7 +105,7 @@ export function getSolautoFeesBps(
103
105
 
104
106
  let feeBps: number = 0;
105
107
 
106
- if (targetLiqUtilizationRateBps !== undefined) {
108
+ if (targetLiqUtilizationRateBps !== undefined || rebalanceDirection === RebalanceDirection.Repay) {
107
109
  feeBps = 25;
108
110
  } else if (positionNetWorthUsd <= minSize) {
109
111
  feeBps = maxFeeBps;
@@ -4,6 +4,7 @@ import {
4
4
  DCASettings,
5
5
  PositionState,
6
6
  PositionTokenUsage,
7
+ RebalanceDirection,
7
8
  SolautoSettingsParameters,
8
9
  TokenType,
9
10
  } from "../../generated";
@@ -158,13 +159,13 @@ function getTargetRateAndDcaAmount(
158
159
  }
159
160
 
160
161
  export interface RebalanceValues {
161
- increasingLeverage: boolean;
162
162
  debtAdjustmentUsd: number;
163
163
  repayingCloseToMaxLtv: boolean;
164
164
  amountToDcaIn: number;
165
165
  amountUsdToDcaIn: number;
166
166
  dcaTokenType?: TokenType;
167
167
  rebalanceAction: RebalanceAction;
168
+ rebalanceDirection: RebalanceDirection
168
169
  }
169
170
 
170
171
  export function getRebalanceValues(
@@ -188,16 +189,13 @@ export function getRebalanceValues(
188
189
  fromBaseUnit(BigInt(Math.round(amountToDcaIn ?? 0)), state.debt.decimals) *
189
190
  (dca?.tokenType === TokenType.Debt ? debtPrice : supplyPrice);
190
191
 
191
- const increasingLeverage =
192
- amountUsdToDcaIn > 0 || state.liqUtilizationRateBps < targetRateBps;
193
- let adjustmentFeeBps = 0;
194
- if (increasingLeverage) {
195
- adjustmentFeeBps = getSolautoFeesBps(
196
- false,
197
- targetLiqUtilizationRateBps,
198
- fromBaseUnit(state.netWorth.baseAmountUsdValue, USD_DECIMALS)
199
- ).total;
200
- }
192
+ const rebalanceDirection = amountUsdToDcaIn > 0 || state.liqUtilizationRateBps < targetRateBps ? RebalanceDirection.Boost : RebalanceDirection.Repay;
193
+ const adjustmentFeeBps = getSolautoFeesBps(
194
+ false,
195
+ targetLiqUtilizationRateBps,
196
+ fromBaseUnit(state.netWorth.baseAmountUsdValue, USD_DECIMALS),
197
+ rebalanceDirection
198
+ ).total;
201
199
 
202
200
  const supplyUsd =
203
201
  fromBaseUnit(state.supply.amountUsed.baseAmountUsdValue, USD_DECIMALS) +
@@ -216,7 +214,6 @@ export function getRebalanceValues(
216
214
 
217
215
  const maxRepayTo = maxRepayToBps(state.maxLtvBps, state.liqThresholdBps);
218
216
  return {
219
- increasingLeverage,
220
217
  debtAdjustmentUsd,
221
218
  repayingCloseToMaxLtv:
222
219
  state.liqUtilizationRateBps > maxRepayTo && targetRateBps >= maxRepayTo,
@@ -224,7 +221,8 @@ export function getRebalanceValues(
224
221
  amountUsdToDcaIn,
225
222
  dcaTokenType: dca?.tokenType,
226
223
  rebalanceAction:
227
- (amountToDcaIn ?? 0) > 0 ? "dca" : increasingLeverage ? "boost" : "repay",
224
+ (amountToDcaIn ?? 0) > 0 ? "dca" : rebalanceDirection === RebalanceDirection.Boost ? "boost" : "repay",
225
+ rebalanceDirection,
228
226
  };
229
227
  }
230
228
 
@@ -271,7 +269,7 @@ export function getFlashLoanDetails(
271
269
 
272
270
  let flashLoanToken: PositionTokenUsage | undefined = undefined;
273
271
  let flashLoanTokenPrice = 0;
274
- if (values.increasingLeverage) {
272
+ if (values.rebalanceDirection === RebalanceDirection.Boost) {
275
273
  flashLoanToken = client.solautoPositionState!.debt;
276
274
  flashLoanTokenPrice = safeGetPrice(client.debtMint)!;
277
275
  } else {
@@ -303,10 +301,10 @@ export function getJupSwapRebalanceDetails(
303
301
  targetLiqUtilizationRateBps?: number,
304
302
  attemptNum?: number
305
303
  ): JupSwapDetails {
306
- const input = values.increasingLeverage
304
+ const input = values.rebalanceDirection === RebalanceDirection.Boost
307
305
  ? client.solautoPositionState!.debt
308
306
  : client.solautoPositionState!.supply;
309
- const output = values.increasingLeverage
307
+ const output = values.rebalanceDirection === RebalanceDirection.Boost
310
308
  ? client.solautoPositionState!.supply
311
309
  : client.solautoPositionState!.debt;
312
310
 
@@ -11,6 +11,7 @@ import {
11
11
  DCASettings,
12
12
  LendingPlatform,
13
13
  PositionType,
14
+ RebalanceDirection,
14
15
  SolautoRebalanceType,
15
16
  SolautoSettingsParameters,
16
17
  TokenType,
@@ -45,7 +46,7 @@ function assertAccurateRebalance(
45
46
  targetLiqUtilizationRateBps?: number,
46
47
  expectedUsdToDcaIn?: number
47
48
  ) {
48
- const { increasingLeverage, debtAdjustmentUsd, amountUsdToDcaIn } =
49
+ const { rebalanceDirection, debtAdjustmentUsd, amountUsdToDcaIn } =
49
50
  getRebalanceValues(
50
51
  client.solautoPositionState!,
51
52
  client.solautoPositionSettings(),
@@ -57,16 +58,15 @@ function assertAccurateRebalance(
57
58
  );
58
59
 
59
60
  let adjustmentFeeBps = 0;
60
- if (increasingLeverage) {
61
- adjustmentFeeBps = getSolautoFeesBps(
62
- client.referredBy !== undefined,
63
- targetLiqUtilizationRateBps,
64
- fromBaseUnit(
65
- client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
66
- USD_DECIMALS
67
- )
68
- ).total;
69
- }
61
+ adjustmentFeeBps = getSolautoFeesBps(
62
+ client.referredBy !== undefined,
63
+ targetLiqUtilizationRateBps,
64
+ fromBaseUnit(
65
+ client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
66
+ USD_DECIMALS
67
+ ),
68
+ rebalanceDirection
69
+ ).total;
70
70
 
71
71
  assert(
72
72
  Math.round(amountUsdToDcaIn) === Math.round(expectedUsdToDcaIn ?? 0),
@@ -174,7 +174,7 @@ async function getFakePosition(
174
174
  state: client.solautoPositionState!,
175
175
  rebalance: {
176
176
  rebalanceType: SolautoRebalanceType.Regular,
177
- targetLiqUtilizationRateBps: 0,
177
+ rebalanceDirection: RebalanceDirection.Boost,
178
178
  flashLoanAmount: BigInt(0),
179
179
  padding1: [],
180
180
  padding2: [],