flash-sdk 1.0.0 → 1.0.2

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,13 @@ export class Side {
28
28
  static Short = { short: {} };
29
29
  }
30
30
 
31
+ export class AumCalcMode {
32
+ static Min = { min: {} };
33
+ static Max = { max: {}};
34
+ static Last = {last : {}};
35
+ static EMA = {ema : {}};
36
+ }
37
+
31
38
  // =======================================================
32
39
  // ================== POSITION ====================
33
40
  // =======================================================
@@ -125,8 +132,8 @@ export interface PositionStats {
125
132
  collateralUsd: BN,
126
133
  sizeUsd: BN,
127
134
  lockedAmount: BN,
128
- weightedLeverage: BN,
129
- totalLeverage: BN,
135
+ weightedLeverage: BN, // weighted_price
136
+ totalLeverage: BN, // total_quantity
130
137
  cumulativeInterestUsd: BN,
131
138
  cumulativeInterestSnapshot: BN,
132
139
  }
@@ -5,6 +5,57 @@ export const getUnixTs = () => {
5
5
  return new Date().getTime() / 1000;
6
6
  };
7
7
 
8
+ // 99999.123456
9
+ // 99999.123
10
+ export function toUiDecimals(
11
+ nativeAmount: BN | number | string,
12
+ decimals: number,
13
+ precision = 3,
14
+ commaSeperated = false
15
+ ): string {
16
+ // TODO: remove BN and upgrade to bigint https://github.com/solana-labs/solana/issues/27440
17
+
18
+ if(precision> decimals){
19
+ throw "not allowed precision> decimals"
20
+ }
21
+ let r = '';
22
+
23
+ if (nativeAmount instanceof BN) {
24
+ const nativeAmountString = nativeAmount.toString();
25
+ // get decimals
26
+ const d = nativeAmountString.slice((decimals) * -1);
27
+ const p = d.slice(0 ,precision);
28
+ const nativeAmountWithoutDecimalsStr = nativeAmount.div(new BN( 10 ** decimals)).toString();
29
+
30
+ r = nativeAmountWithoutDecimalsStr + "." + p;
31
+ }
32
+ else if (typeof nativeAmount === "string") {
33
+ if( isNaN(Number(nativeAmount))){
34
+ throw "String No valid "
35
+ }
36
+ const d = nativeAmount.slice((decimals) * -1);
37
+ const p = d.slice(0 ,precision);
38
+ const nativeAmountWithoutDecimalsStr = (new BN(nativeAmount)).div(new BN( 10 ** decimals)).toString();
39
+
40
+ r = nativeAmountWithoutDecimalsStr + "." + p;
41
+ }
42
+ else if (typeof nativeAmount === "number") {
43
+ const d = nativeAmount.toString().slice((decimals) * -1);
44
+ const p = d.slice(0 ,precision);
45
+ const nativeAmountWithoutDecimalsStr = (new BN(nativeAmount)).div(new BN( 10 ** decimals)).toString();
46
+ r = nativeAmountWithoutDecimalsStr + "." + p;
47
+ }
48
+ else {
49
+ return 'type unknown'
50
+ }
51
+
52
+ if(commaSeperated){
53
+ return Number(r).toLocaleString();
54
+ } else {
55
+ return r;
56
+ }
57
+
58
+ }
8
59
 
9
60
  // recheck ?? logic
10
61
  export const scaleToExponent = (arg: BN, exponent: BN, target_exponent: BN) : BN => {
package/tsconfig.json CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  // "declarationMap": true,
16
16
  // "noImplicitAny": false,
17
- // "resolveJsonModule": true,
17
+ "resolveJsonModule": true,
18
18
  // "sourceMap": true,
19
19
 
20
20
  },