@drift-labs/sdk 0.1.34-master.3 → 0.1.34-master.4

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.
@@ -28,6 +28,7 @@ function calculateAllEstimatedFundingRate(market, oraclePriceData, periodAdjustm
28
28
  // 24 * 365.25: annualized
29
29
  const secondsInHour = new anchor_1.BN(3600);
30
30
  const hoursInDay = new anchor_1.BN(24);
31
+ const ONE = new anchor_1.BN(1);
31
32
  if (!market.initialized) {
32
33
  return [numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO];
33
34
  }
@@ -51,7 +52,7 @@ function calculateAllEstimatedFundingRate(market, oraclePriceData, periodAdjustm
51
52
  const lastOraclePriceTwapTs = market.amm.lastOraclePriceTwapTs;
52
53
  const oracleInvalidDuration = anchor_1.BN.max(numericConstants_1.ZERO, lastMarkPriceTwapTs.sub(lastOraclePriceTwapTs));
53
54
  const timeSinceLastOracleTwapUpdate = now.sub(lastOraclePriceTwapTs);
54
- const oracleTwapTimeSinceLastUpdate = anchor_1.BN.min(secondsInHour, anchor_1.BN.max(numericConstants_1.ZERO, secondsInHour.sub(timeSinceLastOracleTwapUpdate)));
55
+ const oracleTwapTimeSinceLastUpdate = anchor_1.BN.max(ONE, anchor_1.BN.min(secondsInHour, anchor_1.BN.max(ONE, secondsInHour.sub(timeSinceLastOracleTwapUpdate))));
55
56
  let oracleTwapWithMantissa = lastOracleTwapWithMantissa;
56
57
  // if passing live oracle data, improve predicted calc estimate
57
58
  if (oraclePriceData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.34-master.3",
3
+ "version": "0.1.34-master.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -27,6 +27,7 @@ export async function calculateAllEstimatedFundingRate(
27
27
  // 24 * 365.25: annualized
28
28
  const secondsInHour = new BN(3600);
29
29
  const hoursInDay = new BN(24);
30
+ const ONE = new BN(1);
30
31
 
31
32
  if (!market.initialized) {
32
33
  return [ZERO, ZERO, ZERO, ZERO, ZERO];
@@ -65,9 +66,12 @@ export async function calculateAllEstimatedFundingRate(
65
66
  );
66
67
 
67
68
  const timeSinceLastOracleTwapUpdate = now.sub(lastOraclePriceTwapTs);
68
- const oracleTwapTimeSinceLastUpdate = BN.min(
69
- secondsInHour,
70
- BN.max(ZERO, secondsInHour.sub(timeSinceLastOracleTwapUpdate))
69
+ const oracleTwapTimeSinceLastUpdate = BN.max(
70
+ ONE,
71
+ BN.min(
72
+ secondsInHour,
73
+ BN.max(ONE, secondsInHour.sub(timeSinceLastOracleTwapUpdate))
74
+ )
71
75
  );
72
76
  let oracleTwapWithMantissa = lastOracleTwapWithMantissa;
73
77