@haven-fi/solauto-sdk 1.0.66 → 1.0.68

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,10 +82,10 @@ function eligibleForRebalance(positionState, positionSettings, positionDca, curr
82
82
  : positionSettings.boostToBps;
83
83
  const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
84
84
  const boostFrom = boostToBps - positionSettings.boostGap;
85
- if (positionState.liqUtilizationRateBps <= boostFrom) {
85
+ if (positionState.liqUtilizationRateBps < boostFrom) {
86
86
  return "boost";
87
87
  }
88
- else if (positionState.liqUtilizationRateBps >= repayFrom) {
88
+ else if (positionState.liqUtilizationRateBps > repayFrom) {
89
89
  return "repay";
90
90
  }
91
91
  return undefined;
@@ -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,OAAO,EACP,aAAa,EAEb,yBAAyB,EAC1B,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAkJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,OAAO,EAAE,OAAO,EAChB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,M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,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CAsEjB;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,SAAS,CAkE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAkChB"}
@@ -19,21 +19,20 @@ function getAdditionalAmountToDcaIn(dca) {
19
19
  }
20
20
  function getStandardTargetLiqUtilizationRateBps(state, settings) {
21
21
  const adjustedSettings = (0, generalUtils_1.getAdjustedSettingsFromAutomation)(settings, (0, generalUtils_2.currentUnixSeconds)());
22
- const repayFrom = adjustedSettings.repayToBps - adjustedSettings.repayGap;
23
- const boostFrom = adjustedSettings.boostToBps + adjustedSettings.boostGap;
22
+ const repayFrom = adjustedSettings.repayToBps + adjustedSettings.repayGap;
23
+ const boostFrom = adjustedSettings.boostToBps - adjustedSettings.boostGap;
24
24
  if (state.liqUtilizationRateBps < boostFrom) {
25
25
  return adjustedSettings.boostToBps;
26
26
  }
27
- else if (state.liqUtilizationRateBps > repayFrom ||
28
- repayFrom - state.liqUtilizationRateBps < repayFrom * 0.015) {
27
+ else if (state.liqUtilizationRateBps > repayFrom) {
29
28
  return adjustedSettings.repayToBps;
30
29
  }
31
30
  else {
32
31
  throw new Error("Invalid rebalance condition");
33
32
  }
34
33
  }
35
- function targetLiqUtilizationRateBpsFromDCA(state, settings, dca) {
36
- const adjustedSettings = (0, generalUtils_1.getAdjustedSettingsFromAutomation)(settings, (0, generalUtils_2.currentUnixSeconds)());
34
+ function targetLiqUtilizationRateBpsFromDCA(state, settings, dca, currentUnixTime) {
35
+ const adjustedSettings = (0, generalUtils_1.getAdjustedSettingsFromAutomation)(settings, currentUnixTime);
37
36
  let targetRateBps = 0;
38
37
  if (dca.debtToAddBaseUnit > BigInt(0)) {
39
38
  targetRateBps = Math.max(state.liqUtilizationRateBps, adjustedSettings.boostToBps);
@@ -47,7 +46,7 @@ function isDcaRebalance(state, settings, dca, currentUnixTime) {
47
46
  if (dca === undefined || dca.automation.targetPeriods === 0) {
48
47
  return false;
49
48
  }
50
- const adjustedSettings = (0, generalUtils_1.getAdjustedSettingsFromAutomation)(settings, (0, generalUtils_2.currentUnixSeconds)());
49
+ const adjustedSettings = (0, generalUtils_1.getAdjustedSettingsFromAutomation)(settings, currentUnixTime);
51
50
  if (state.liqUtilizationRateBps >
52
51
  adjustedSettings.repayToBps + adjustedSettings.repayGap) {
53
52
  return false;
@@ -68,7 +67,7 @@ function getTargetRateAndDcaAmount(state, settings, dca, currentUnixTime, target
68
67
  }
69
68
  if (isDcaRebalance(state, settings, dca, currentUnixTime)) {
70
69
  const amountToDcaIn = getAdditionalAmountToDcaIn(dca);
71
- const targetLiqUtilizationRateBps = targetLiqUtilizationRateBpsFromDCA(state, settings, dca);
70
+ const targetLiqUtilizationRateBps = targetLiqUtilizationRateBpsFromDCA(state, settings, dca, currentUnixTime);
72
71
  return {
73
72
  targetRateBps: targetLiqUtilizationRateBps,
74
73
  amountToDcaIn,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
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",
@@ -154,9 +154,9 @@ export function eligibleForRebalance(
154
154
  const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
155
155
  const boostFrom = boostToBps - positionSettings.boostGap;
156
156
 
157
- if (positionState.liqUtilizationRateBps <= boostFrom) {
157
+ if (positionState.liqUtilizationRateBps < boostFrom) {
158
158
  return "boost";
159
- } else if (positionState.liqUtilizationRateBps >= repayFrom) {
159
+ } else if (positionState.liqUtilizationRateBps > repayFrom) {
160
160
  return "repay";
161
161
  }
162
162
 
@@ -57,15 +57,12 @@ function getStandardTargetLiqUtilizationRateBps(
57
57
  currentUnixSeconds()
58
58
  );
59
59
 
60
- const repayFrom = adjustedSettings.repayToBps - adjustedSettings.repayGap;
61
- const boostFrom = adjustedSettings.boostToBps + adjustedSettings.boostGap;
60
+ const repayFrom = adjustedSettings.repayToBps + adjustedSettings.repayGap;
61
+ const boostFrom = adjustedSettings.boostToBps - adjustedSettings.boostGap;
62
62
 
63
63
  if (state.liqUtilizationRateBps < boostFrom) {
64
64
  return adjustedSettings.boostToBps;
65
- } else if (
66
- state.liqUtilizationRateBps > repayFrom ||
67
- repayFrom - state.liqUtilizationRateBps < repayFrom * 0.015
68
- ) {
65
+ } else if (state.liqUtilizationRateBps > repayFrom) {
69
66
  return adjustedSettings.repayToBps;
70
67
  } else {
71
68
  throw new Error("Invalid rebalance condition");
@@ -75,11 +72,12 @@ function getStandardTargetLiqUtilizationRateBps(
75
72
  function targetLiqUtilizationRateBpsFromDCA(
76
73
  state: PositionState,
77
74
  settings: SolautoSettingsParameters,
78
- dca: DCASettings
75
+ dca: DCASettings,
76
+ currentUnixTime: number
79
77
  ) {
80
78
  const adjustedSettings = getAdjustedSettingsFromAutomation(
81
79
  settings,
82
- currentUnixSeconds()
80
+ currentUnixTime
83
81
  );
84
82
 
85
83
  let targetRateBps = 0;
@@ -106,7 +104,7 @@ function isDcaRebalance(
106
104
 
107
105
  const adjustedSettings = getAdjustedSettingsFromAutomation(
108
106
  settings,
109
- currentUnixSeconds()
107
+ currentUnixTime
110
108
  );
111
109
 
112
110
  if (
@@ -147,7 +145,8 @@ function getTargetRateAndDcaAmount(
147
145
  const targetLiqUtilizationRateBps = targetLiqUtilizationRateBpsFromDCA(
148
146
  state,
149
147
  settings,
150
- dca!
148
+ dca!,
149
+ currentUnixTime
151
150
  );
152
151
 
153
152
  return {
@@ -194,12 +194,6 @@ async function getFakePosition(
194
194
 
195
195
  client.solautoPositionState!.lastUpdated = BigInt(currentUnixSeconds());
196
196
 
197
- assert(
198
- fakeLiqUtilizationRateBps ===
199
- client.solautoPositionState!.liqUtilizationRateBps,
200
- "Fake position not set up correctly"
201
- );
202
-
203
197
  return client;
204
198
  }
205
199
 
@@ -291,28 +285,28 @@ describe("Rebalance tests", async () => {
291
285
  ]);
292
286
  });
293
287
 
294
- it("Standard rebalance with target rate", async () => {
295
- const client = await getFakePosition(supplyPrice, debtPrice, 3450, {
296
- boostToBps: 500,
297
- boostGap: 100,
298
- repayToBps: 7000,
299
- repayGap: 250,
300
- automation: {
301
- targetPeriods: 0,
302
- periodsPassed: 0,
303
- unixStartDate: BigInt(0),
304
- intervalSeconds: BigInt(0),
305
- padding1: [],
306
- padding: new Uint8Array([]),
307
- },
308
- targetBoostToBps: 0,
309
- padding1: [],
310
- padding: new Uint8Array([]),
311
- });
288
+ // it("Standard rebalance with target rate", async () => {
289
+ // const client = await getFakePosition(supplyPrice, debtPrice, 3450, {
290
+ // boostToBps: 500,
291
+ // boostGap: 100,
292
+ // repayToBps: 7000,
293
+ // repayGap: 250,
294
+ // automation: {
295
+ // targetPeriods: 0,
296
+ // periodsPassed: 0,
297
+ // unixStartDate: BigInt(0),
298
+ // intervalSeconds: BigInt(0),
299
+ // padding1: [],
300
+ // padding: new Uint8Array([]),
301
+ // },
302
+ // targetBoostToBps: 0,
303
+ // padding1: [],
304
+ // padding: new Uint8Array([]),
305
+ // });
312
306
 
313
- assertAccurateRebalance(client, 5000, 5000);
314
- assertAccurateRebalance(client, 1000, 1000);
315
- });
307
+ // assertAccurateRebalance(client, 5000, 5000);
308
+ // assertAccurateRebalance(client, 1000, 1000);
309
+ // });
316
310
 
317
311
  it("Standard boost or repay", async () => {
318
312
  const settings: SolautoSettingsParameters = {