flash-sdk 1.0.21 → 1.0.23
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 → dist}/PerpetualsClient.d.ts +4 -0
- package/{lib → dist}/PerpetualsClient.js +121 -0
- package/{lib → dist}/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -4
- package/src/CustodyAccount.ts +0 -125
- package/src/OraclePrice.ts +0 -111
- package/src/PerpetualsClient.ts +0 -1961
- package/src/PoolAccount.ts +0 -491
- package/src/PoolConfig.json +0 -322
- package/src/PoolConfig.ts +0 -182
- package/src/PoolDataClient.ts +0 -173
- package/src/PositionAccount.ts +0 -58
- package/src/Token.ts +0 -1
- package/src/constants/index.ts +0 -21
- package/src/idl/perpetuals.ts +0 -7561
- package/src/index.ts +0 -19
- package/src/type-rules.md +0 -4
- package/src/types/index.ts +0 -290
- package/src/utils/index.ts +0 -234
- package/src/utils/rpc.ts +0 -162
- package/tsconfig.json +0 -23
- /package/{lib → dist}/CustodyAccount.d.ts +0 -0
- /package/{lib → dist}/CustodyAccount.js +0 -0
- /package/{lib → dist}/OraclePrice.d.ts +0 -0
- /package/{lib → dist}/OraclePrice.js +0 -0
- /package/{lib → dist}/PoolAccount.d.ts +0 -0
- /package/{lib → dist}/PoolAccount.js +0 -0
- /package/{lib → dist}/PoolConfig.d.ts +0 -0
- /package/{lib → dist}/PoolConfig.js +0 -0
- /package/{lib → dist}/PoolConfig.json +0 -0
- /package/{lib → dist}/PoolDataClient.d.ts +0 -0
- /package/{lib → dist}/PoolDataClient.js +0 -0
- /package/{lib → dist}/PositionAccount.d.ts +0 -0
- /package/{lib → dist}/PositionAccount.js +0 -0
- /package/{lib → dist}/Token.d.ts +0 -0
- /package/{lib → dist}/Token.js +0 -0
- /package/{lib → dist}/constants/index.d.ts +0 -0
- /package/{lib → dist}/constants/index.js +0 -0
- /package/{lib → dist}/idl/perpetuals.d.ts +0 -0
- /package/{lib → dist}/idl/perpetuals.js +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/index.js +0 -0
- /package/{lib → dist}/types/index.d.ts +0 -0
- /package/{lib → dist}/types/index.js +0 -0
- /package/{lib → dist}/utils/index.d.ts +0 -0
- /package/{lib → dist}/utils/index.js +0 -0
- /package/{lib → dist}/utils/rpc.d.ts +0 -0
- /package/{lib → dist}/utils/rpc.js +0 -0
package/src/OraclePrice.ts
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
import { BN } from "@coral-xyz/anchor";
|
2
|
-
import { Connection, PublicKey } from "@solana/web3.js";
|
3
|
-
import { isVariant, Position, Side } from "./types";
|
4
|
-
import { BN_ZERO, USD_DECIMALS } from "./constants";
|
5
|
-
import { checkedDecimalDiv, checkedDecimalMul } from "./utils";
|
6
|
-
|
7
|
-
// use something similar to mango v3 FixedNum I80F48 type : https://github.com/blockworks-foundation/mango-client-v3/blob/e81ac7cf127f4acbf5585dd2b1c0cabef1d6c437/src/utils/fixednum.ts#L8
|
8
|
-
|
9
|
-
|
10
|
-
export class OraclePrice {
|
11
|
-
|
12
|
-
price: BN;
|
13
|
-
exponent: BN;
|
14
|
-
|
15
|
-
constructor( parseData : { price : BN, exponent: BN}) {
|
16
|
-
Object.assign(this, parseData);
|
17
|
-
}
|
18
|
-
|
19
|
-
static from(parseData : { price : BN, exponent: BN}): OraclePrice {
|
20
|
-
return new OraclePrice(parseData);
|
21
|
-
}
|
22
|
-
|
23
|
-
/**
|
24
|
-
* @description lhs.cmp(rhs) === (lhs > rhs) compare numbers and return `-1 (a < b)`, `0 (a == b)`, or `1 (a > b)` depending on the comparison result
|
25
|
-
*/
|
26
|
-
cmp(other: OraclePrice): -1 | 0 | 1 {
|
27
|
-
// TODO make sure this works when they're diff signs or 0
|
28
|
-
// return this.data.cmp(x.getData());
|
29
|
-
let lhs:BN, rhs:BN;
|
30
|
-
if (this.exponent.eq(other.exponent)) {
|
31
|
-
lhs =this.price;
|
32
|
-
rhs = other.price;
|
33
|
-
} else if (this.exponent.lt(other.exponent)) {
|
34
|
-
// if let Ok(scaled_price) = other.scale_to_exponent(this.exponent) {
|
35
|
-
// (this.price, scaled_price.price)
|
36
|
-
// } else {
|
37
|
-
// return None;
|
38
|
-
// }
|
39
|
-
let scaled_price = other.scale_to_exponent(this.exponent);
|
40
|
-
lhs =this.price;
|
41
|
-
rhs = scaled_price.price;
|
42
|
-
|
43
|
-
} else {
|
44
|
-
let scaled_price = this.scale_to_exponent(other.exponent);
|
45
|
-
lhs =scaled_price.price;
|
46
|
-
rhs = other.price;
|
47
|
-
};
|
48
|
-
return lhs.cmp(rhs);
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
scale_to_exponent( target_exponent: BN) : OraclePrice {
|
53
|
-
if (target_exponent.eq(this.exponent)) {
|
54
|
-
return this;
|
55
|
-
}
|
56
|
-
let delta = target_exponent.sub(this.exponent);
|
57
|
-
if (delta.gt(BN_ZERO)) {
|
58
|
-
// Ok(OraclePrice {
|
59
|
-
// price: math::checked_div(self.price, math::checked_pow(10, delta as usize)?)?,
|
60
|
-
// exponent: target_exponent,
|
61
|
-
// })
|
62
|
-
return new OraclePrice({
|
63
|
-
price : this.price.div(new BN(10).pow(delta)),
|
64
|
-
exponent : target_exponent
|
65
|
-
})
|
66
|
-
|
67
|
-
} else {
|
68
|
-
// Ok(OraclePrice {
|
69
|
-
// price: math::checked_mul(self.price, math::checked_pow(10, (-delta) as usize)?)?,
|
70
|
-
// exponent: target_exponent,
|
71
|
-
// })
|
72
|
-
return new OraclePrice({
|
73
|
-
price : this.price.mul(new BN(10).pow(delta.mul(new BN(-1)))),
|
74
|
-
exponent : target_exponent
|
75
|
-
})
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
// Converts USD amount with implied USD_DECIMALS decimals to token amount
|
80
|
-
getTokenAmount( asset_amount_usd: BN, token_decimals: number) : BN {
|
81
|
-
if (asset_amount_usd.isZero() || this.price.isZero()) {
|
82
|
-
return BN_ZERO;
|
83
|
-
}
|
84
|
-
return checkedDecimalDiv(
|
85
|
-
asset_amount_usd,
|
86
|
-
new BN(-1* USD_DECIMALS),
|
87
|
-
this.price,
|
88
|
-
this.exponent,
|
89
|
-
new BN(-1 * token_decimals),
|
90
|
-
)
|
91
|
-
}
|
92
|
-
|
93
|
-
// Converts token amount to USD with implied USD_DECIMALS decimals using oracle price
|
94
|
-
getAssetAmountUsd( token_amount: BN, token_decimals: number) : BN {
|
95
|
-
if (token_amount.isZero() || this.price.isZero()) {
|
96
|
-
return BN_ZERO;
|
97
|
-
}
|
98
|
-
return checkedDecimalMul(
|
99
|
-
token_amount,
|
100
|
-
new BN(-1 * token_decimals),
|
101
|
-
this.price,
|
102
|
-
this.exponent,
|
103
|
-
new BN(-1 * USD_DECIMALS),
|
104
|
-
)
|
105
|
-
}
|
106
|
-
|
107
|
-
toUiPrice(precision: number): number {
|
108
|
-
const x: BN = this.price.div(new BN(10).pow(new BN((this.exponent.toNumber()*-1) - precision)))
|
109
|
-
return x.toNumber()/10**precision
|
110
|
-
}
|
111
|
-
}
|