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.
- package/lib/CustodyAccount.d.ts +2 -1
- package/lib/CustodyAccount.js +30 -0
- package/lib/PoolAccount.d.ts +2 -1
- package/lib/PoolAccount.js +60 -61
- package/lib/PoolConfig.d.ts +39 -0
- package/lib/PoolConfig.js +93 -0
- package/lib/PoolConfig.json +305 -0
- package/lib/PoolDisplayData.d.ts +34 -0
- package/lib/PoolDisplayData.js +152 -0
- package/lib/constants/index.d.ts +3 -0
- package/lib/constants/index.js +3 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +14 -0
- package/lib/types/index.js +11 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +45 -1
- package/package.json +1 -1
- package/src/CustodyAccount.ts +33 -1
- package/src/PoolAccount.ts +75 -67
- package/src/PoolConfig.json +307 -0
- package/src/PoolConfig.ts +158 -0
- package/src/PoolDisplayData.ts +173 -0
- package/src/constants/index.ts +4 -0
- package/src/index.ts +2 -0
- package/src/target/idl/perpetuals.json +3537 -0
- package/src/types/index.ts +9 -2
- package/src/utils/index.ts +51 -0
- package/tsconfig.json +1 -1
package/src/types/index.ts
CHANGED
@@ -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
|
}
|
package/src/utils/index.ts
CHANGED
@@ -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 => {
|