@haven-fi/solauto-sdk 1.0.66 → 1.0.67
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.
|
@@ -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;
|
|
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;AAiJjD,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,MAAM,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
|
|
23
|
-
const boostFrom = adjustedSettings.boostToBps
|
|
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,
|
|
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,
|
|
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
|
@@ -57,15 +57,12 @@ function getStandardTargetLiqUtilizationRateBps(
|
|
|
57
57
|
currentUnixSeconds()
|
|
58
58
|
);
|
|
59
59
|
|
|
60
|
-
const repayFrom = adjustedSettings.repayToBps
|
|
61
|
-
const boostFrom = adjustedSettings.boostToBps
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|