@haven-fi/solauto-sdk 1.0.217 → 1.0.218

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ export declare function toBps(value: number): number;
6
6
  export declare function bytesToI80F48(bytes: number[]): number;
7
7
  export declare function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint;
8
8
  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): {
9
+ export declare function getSolautoFeesBps(isReferred: boolean, targetLiqUtilizationRateBps: number | undefined, positionNetWorthUsd: number, rebalanceDirection: "boost" | "repay"): {
10
10
  solauto: number;
11
11
  referrer: number;
12
12
  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,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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U,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,OAAO,GAAG,OAAO,GACpC;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"}
@@ -66,14 +66,14 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
66
66
  (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
67
67
  return debtAdjustmentUsd;
68
68
  }
69
- function getSolautoFeesBps(isReferred, targetLiqUtilizationRateBps, positionNetWorthUsd) {
69
+ function getSolautoFeesBps(isReferred, targetLiqUtilizationRateBps, positionNetWorthUsd, rebalanceDirection) {
70
70
  const minSize = 10000; // Minimum position size
71
71
  const maxSize = 500000; // Maximum position size
72
72
  const maxFeeBps = 200; // Fee in basis points for minSize (2%)
73
73
  const minFeeBps = 50; // Fee in basis points for maxSize (0.5%)
74
74
  const k = 1.5;
75
75
  let feeBps = 0;
76
- if (targetLiqUtilizationRateBps !== undefined) {
76
+ if (targetLiqUtilizationRateBps !== undefined || rebalanceDirection === "repay") {
77
77
  feeBps = 25;
78
78
  }
79
79
  else if (positionNetWorthUsd <= minSize) {
@@ -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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,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,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"}
@@ -84,10 +84,7 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
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
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
- }
87
+ const adjustmentFeeBps = (0, numberUtils_1.getSolautoFeesBps)(false, targetLiqUtilizationRateBps, (0, numberUtils_1.fromBaseUnit)(state.netWorth.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS), increasingLeverage ? "boost" : "repay").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);
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.218",
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",
@@ -89,7 +89,8 @@ export function getDebtAdjustmentUsd(
89
89
  export function getSolautoFeesBps(
90
90
  isReferred: boolean,
91
91
  targetLiqUtilizationRateBps: number | undefined,
92
- positionNetWorthUsd: number
92
+ positionNetWorthUsd: number,
93
+ rebalanceDirection: "boost" | "repay"
93
94
  ): {
94
95
  solauto: number;
95
96
  referrer: number;
@@ -103,7 +104,7 @@ export function getSolautoFeesBps(
103
104
 
104
105
  let feeBps: number = 0;
105
106
 
106
- if (targetLiqUtilizationRateBps !== undefined) {
107
+ if (targetLiqUtilizationRateBps !== undefined || rebalanceDirection === "repay") {
107
108
  feeBps = 25;
108
109
  } else if (positionNetWorthUsd <= minSize) {
109
110
  feeBps = maxFeeBps;
@@ -190,14 +190,12 @@ export function getRebalanceValues(
190
190
 
191
191
  const increasingLeverage =
192
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
- }
193
+ const adjustmentFeeBps = getSolautoFeesBps(
194
+ false,
195
+ targetLiqUtilizationRateBps,
196
+ fromBaseUnit(state.netWorth.baseAmountUsdValue, USD_DECIMALS),
197
+ increasingLeverage ? "boost" : "repay"
198
+ ).total;
201
199
 
202
200
  const supplyUsd =
203
201
  fromBaseUnit(state.supply.amountUsed.baseAmountUsdValue, USD_DECIMALS) +
@@ -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,
@@ -64,7 +65,8 @@ function assertAccurateRebalance(
64
65
  fromBaseUnit(
65
66
  client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
66
67
  USD_DECIMALS
67
- )
68
+ ),
69
+ increasingLeverage ? "boost" : "repay"
68
70
  ).total;
69
71
  }
70
72
 
@@ -174,7 +176,7 @@ async function getFakePosition(
174
176
  state: client.solautoPositionState!,
175
177
  rebalance: {
176
178
  rebalanceType: SolautoRebalanceType.Regular,
177
- targetLiqUtilizationRateBps: 0,
179
+ rebalanceDirection: RebalanceDirection.Boost,
178
180
  flashLoanAmount: BigInt(0),
179
181
  padding1: [],
180
182
  padding2: [],