@haven-fi/solauto-sdk 1.0.51 → 1.0.52

Sign up to get free protection for your applications and to get access to all the features.
@@ -321,7 +321,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
321
321
  client.solautoPositionState = await client.getFreshPositionState();
322
322
  if (client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) ||
323
323
  (targetLiqUtilizationRateBps === undefined &&
324
- !(0, generalUtils_2.eligibileForRebalance)(client.solautoPositionState, client.livePositionUpdates.settings ??
324
+ !(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.livePositionUpdates.settings ??
325
325
  client.solautoPositionData?.position.settingParams, client.livePositionUpdates.activeDca ??
326
326
  client.solautoPositionData?.position.dca))) {
327
327
  client.log("Not eligible for a rebalance");
@@ -13,4 +13,5 @@ export declare enum PriorityFeeSetting {
13
13
  Default = "Medium",
14
14
  High = "High"
15
15
  }
16
+ export type RebalanceAction = "boost" | "repay" | "dca";
16
17
  //# sourceMappingURL=solauto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,OAAO,WAAW;IAClB,IAAI,SAAS;CACd"}
1
+ {"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,OAAO,WAAW;IAClB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { Umi } from "@metaplex-foundation/umi";
3
3
  import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, LendingPlatform, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
4
- import { SolautoPositionDetails } from "../../types/solauto";
4
+ import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
5
5
  export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
6
6
  export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings): boolean;
7
7
  export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
@@ -11,7 +11,7 @@ export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType)
11
11
  referrer: number;
12
12
  total: number;
13
13
  };
14
- export declare function eligibileForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): boolean;
14
+ export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): RebalanceAction | undefined;
15
15
  export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters): boolean;
16
16
  export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<SolautoPositionDetails[]>;
17
17
  export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,GAC7B,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,kBAAkB,EAAE,MAAM,GACzB,yBAAyB,CAgB3B;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,OAAO,GACf;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAYA;AAED,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,yBAAyB,EAC3C,WAAW,EAAE,WAAW,GACvB,OAAO,CAmCT;AAED,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,aAAa,EAC5B,gB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AW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LivePositionUpdates = exports.positionStateWithLatestPrices = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibileForRebalance = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
3
+ exports.LivePositionUpdates = exports.positionStateWithLatestPrices = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibleForRebalance = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
4
4
  const umi_1 = require("@metaplex-foundation/umi");
5
5
  const generated_1 = require("../../generated");
6
6
  const generalUtils_1 = require("../generalUtils");
@@ -58,13 +58,13 @@ function getSolautoFeesBps(isReferred, feeType) {
58
58
  };
59
59
  }
60
60
  exports.getSolautoFeesBps = getSolautoFeesBps;
61
- function eligibileForRebalance(positionState, positionSettings, positionDca) {
61
+ function eligibleForRebalance(positionState, positionSettings, positionDca) {
62
62
  if (positionDca.automation.targetPeriods > 0 &&
63
63
  eligibleForNextAutomationPeriod(positionDca.automation)) {
64
- return true;
64
+ return 'dca';
65
65
  }
66
66
  if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
67
- return false;
67
+ return undefined;
68
68
  }
69
69
  const boostToBps = eligibleForRefresh(positionState, positionSettings) &&
70
70
  positionSettings.automation.targetPeriods > 0
@@ -73,15 +73,14 @@ function eligibileForRebalance(positionState, positionSettings, positionDca) {
73
73
  const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
74
74
  const boostFrom = boostToBps - positionSettings.boostGap;
75
75
  if (positionState.liqUtilizationRateBps <= boostFrom) {
76
- return true;
76
+ return 'boost';
77
77
  }
78
78
  else if (positionState.liqUtilizationRateBps >= repayFrom) {
79
- console.log(`Requires repay ${positionState.liqUtilizationRateBps} > ${repayFrom}`);
80
- return true;
79
+ return 'repay';
81
80
  }
82
- return false;
81
+ return undefined;
83
82
  }
84
- exports.eligibileForRebalance = eligibileForRebalance;
83
+ exports.eligibleForRebalance = eligibleForRebalance;
85
84
  function eligibleForRefresh(positionState, positionSettings) {
86
85
  if (positionSettings.automation.targetPeriods > 0) {
87
86
  return eligibleForNextAutomationPeriod(positionSettings.automation);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
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",
@@ -46,7 +46,7 @@ import {
46
46
  getMaxLiqUtilizationRate,
47
47
  uint8ArrayToBigInt,
48
48
  } from "../utils/numberUtils";
49
- import { eligibileForRebalance } from "../utils/solauto/generalUtils";
49
+ import { eligibleForRebalance } from "../utils/solauto/generalUtils";
50
50
  import { getTokenAccount } from "../utils/accountUtils";
51
51
  import {
52
52
  getLendingAccountBorrowInstructionDataSerializer,
@@ -563,7 +563,7 @@ export async function buildSolautoRebalanceTransaction(
563
563
  if (
564
564
  client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) ||
565
565
  (targetLiqUtilizationRateBps === undefined &&
566
- !eligibileForRebalance(
566
+ !eligibleForRebalance(
567
567
  client.solautoPositionState!,
568
568
  client.livePositionUpdates.settings ??
569
569
  client.solautoPositionData?.position.settingParams!,
@@ -14,4 +14,6 @@ export interface SolautoPositionDetails {
14
14
  export enum PriorityFeeSetting {
15
15
  Default = "Medium",
16
16
  High = "High"
17
- }
17
+ }
18
+
19
+ export type RebalanceAction = "boost" | "repay" | "dca";
@@ -27,7 +27,7 @@ import {
27
27
  getAllMarginfiAccountsByAuthority,
28
28
  getMarginfiAccountPositionState,
29
29
  } from "../marginfiUtils";
30
- import { SolautoPositionDetails } from "../../types/solauto";
30
+ import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
31
31
 
32
32
  function newPeriodsPassed(
33
33
  automation: AutomationSettings,
@@ -118,20 +118,20 @@ export function getSolautoFeesBps(
118
118
  };
119
119
  }
120
120
 
121
- export function eligibileForRebalance(
121
+ export function eligibleForRebalance(
122
122
  positionState: PositionState,
123
123
  positionSettings: SolautoSettingsParameters,
124
124
  positionDca: DCASettings
125
- ): boolean {
125
+ ): RebalanceAction | undefined {
126
126
  if (
127
127
  positionDca.automation.targetPeriods > 0 &&
128
128
  eligibleForNextAutomationPeriod(positionDca.automation)
129
129
  ) {
130
- return true;
130
+ return 'dca';
131
131
  }
132
132
 
133
133
  if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
134
- return false;
134
+ return undefined;
135
135
  }
136
136
 
137
137
  const boostToBps =
@@ -148,15 +148,14 @@ export function eligibileForRebalance(
148
148
  const boostFrom = boostToBps - positionSettings.boostGap;
149
149
 
150
150
  if (positionState.liqUtilizationRateBps <= boostFrom) {
151
- return true;
151
+ return 'boost';
152
152
  } else if (
153
153
  positionState.liqUtilizationRateBps >= repayFrom
154
154
  ) {
155
- console.log(`Requires repay ${positionState.liqUtilizationRateBps} > ${repayFrom}`);
156
- return true;
155
+ return 'repay';
157
156
  }
158
157
 
159
- return false;
158
+ return undefined;
160
159
  }
161
160
 
162
161
  export function eligibleForRefresh(