flash-sdk 1.0.25 → 1.0.26
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/dist/CustodyAccount.js +1 -6
- package/dist/OraclePrice.d.ts +0 -3
- package/dist/OraclePrice.js +1 -22
- package/dist/PerpetualsClient.js +194 -288
- package/dist/PoolAccount.js +4 -58
- package/dist/PoolConfig.js +1 -4
- package/dist/PoolDataClient.js +5 -24
- package/dist/PositionAccount.js +5 -5
- package/dist/Token.js +0 -1
- package/dist/constants/index.js +2 -2
- package/dist/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.js +4 -22
- package/dist/utils/index.js +4 -47
- package/dist/utils/rpc.js +18 -49
- package/package.json +1 -1
package/dist/CustodyAccount.js
CHANGED
@@ -21,7 +21,7 @@ var PositionAccount_1 = require("./PositionAccount");
|
|
21
21
|
var bn_js_1 = __importDefault(require("bn.js"));
|
22
22
|
var constants_1 = require("./constants");
|
23
23
|
var utils_1 = require("./utils");
|
24
|
-
var CustodyAccount =
|
24
|
+
var CustodyAccount = (function () {
|
25
25
|
function CustodyAccount(publicKey, parseData) {
|
26
26
|
this.publicKey = publicKey;
|
27
27
|
Object.assign(this, parseData);
|
@@ -46,7 +46,6 @@ var CustodyAccount = /** @class */ (function () {
|
|
46
46
|
return constants_1.BN_ZERO;
|
47
47
|
}
|
48
48
|
var cumulative_interest = this.getCumulativeInterest(curtime);
|
49
|
-
// console.log("cumulative_interest:",cumulative_interest.toString())
|
50
49
|
var position_interest;
|
51
50
|
if (cumulative_interest.gt(position.cumulativeInterestSnapshot)) {
|
52
51
|
position_interest = cumulative_interest.sub(position.cumulativeInterestSnapshot);
|
@@ -55,10 +54,6 @@ var CustodyAccount = /** @class */ (function () {
|
|
55
54
|
position_interest = constants_1.BN_ZERO;
|
56
55
|
}
|
57
56
|
;
|
58
|
-
// math::checked_as_u64(math::checked_div(
|
59
|
-
// math::checked_mul(position_interest, position.size_usd as u128)?,
|
60
|
-
// Perpetuals::RATE_POWER,
|
61
|
-
// )?)
|
62
57
|
return (position_interest.mul(position.sizeUsd))
|
63
58
|
.div(new bn_js_1.default(constants_1.RATE_POWER));
|
64
59
|
};
|
package/dist/OraclePrice.d.ts
CHANGED
@@ -11,9 +11,6 @@ export declare class OraclePrice {
|
|
11
11
|
price: BN;
|
12
12
|
exponent: BN;
|
13
13
|
}): OraclePrice;
|
14
|
-
/**
|
15
|
-
* @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
|
16
|
-
*/
|
17
14
|
cmp(other: OraclePrice): -1 | 0 | 1;
|
18
15
|
scale_to_exponent(target_exponent: BN): OraclePrice;
|
19
16
|
getTokenAmount(asset_amount_usd: BN, token_decimals: number): BN;
|
package/dist/OraclePrice.js
CHANGED
@@ -4,31 +4,20 @@ exports.OraclePrice = void 0;
|
|
4
4
|
var anchor_1 = require("@coral-xyz/anchor");
|
5
5
|
var constants_1 = require("./constants");
|
6
6
|
var utils_1 = require("./utils");
|
7
|
-
|
8
|
-
var OraclePrice = /** @class */ (function () {
|
7
|
+
var OraclePrice = (function () {
|
9
8
|
function OraclePrice(parseData) {
|
10
9
|
Object.assign(this, parseData);
|
11
10
|
}
|
12
11
|
OraclePrice.from = function (parseData) {
|
13
12
|
return new OraclePrice(parseData);
|
14
13
|
};
|
15
|
-
/**
|
16
|
-
* @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
|
17
|
-
*/
|
18
14
|
OraclePrice.prototype.cmp = function (other) {
|
19
|
-
// TODO make sure this works when they're diff signs or 0
|
20
|
-
// return this.data.cmp(x.getData());
|
21
15
|
var lhs, rhs;
|
22
16
|
if (this.exponent.eq(other.exponent)) {
|
23
17
|
lhs = this.price;
|
24
18
|
rhs = other.price;
|
25
19
|
}
|
26
20
|
else if (this.exponent.lt(other.exponent)) {
|
27
|
-
// if let Ok(scaled_price) = other.scale_to_exponent(this.exponent) {
|
28
|
-
// (this.price, scaled_price.price)
|
29
|
-
// } else {
|
30
|
-
// return None;
|
31
|
-
// }
|
32
21
|
var scaled_price = other.scale_to_exponent(this.exponent);
|
33
22
|
lhs = this.price;
|
34
23
|
rhs = scaled_price.price;
|
@@ -47,34 +36,24 @@ var OraclePrice = /** @class */ (function () {
|
|
47
36
|
}
|
48
37
|
var delta = target_exponent.sub(this.exponent);
|
49
38
|
if (delta.gt(constants_1.BN_ZERO)) {
|
50
|
-
// Ok(OraclePrice {
|
51
|
-
// price: math::checked_div(self.price, math::checked_pow(10, delta as usize)?)?,
|
52
|
-
// exponent: target_exponent,
|
53
|
-
// })
|
54
39
|
return new OraclePrice({
|
55
40
|
price: this.price.div(new anchor_1.BN(10).pow(delta)),
|
56
41
|
exponent: target_exponent
|
57
42
|
});
|
58
43
|
}
|
59
44
|
else {
|
60
|
-
// Ok(OraclePrice {
|
61
|
-
// price: math::checked_mul(self.price, math::checked_pow(10, (-delta) as usize)?)?,
|
62
|
-
// exponent: target_exponent,
|
63
|
-
// })
|
64
45
|
return new OraclePrice({
|
65
46
|
price: this.price.mul(new anchor_1.BN(10).pow(delta.mul(new anchor_1.BN(-1)))),
|
66
47
|
exponent: target_exponent
|
67
48
|
});
|
68
49
|
}
|
69
50
|
};
|
70
|
-
// Converts USD amount with implied USD_DECIMALS decimals to token amount
|
71
51
|
OraclePrice.prototype.getTokenAmount = function (asset_amount_usd, token_decimals) {
|
72
52
|
if (asset_amount_usd.isZero() || this.price.isZero()) {
|
73
53
|
return constants_1.BN_ZERO;
|
74
54
|
}
|
75
55
|
return (0, utils_1.checkedDecimalDiv)(asset_amount_usd, new anchor_1.BN(-1 * constants_1.USD_DECIMALS), this.price, this.exponent, new anchor_1.BN(-1 * token_decimals));
|
76
56
|
};
|
77
|
-
// Converts token amount to USD with implied USD_DECIMALS decimals using oracle price
|
78
57
|
OraclePrice.prototype.getAssetAmountUsd = function (token_amount, token_decimals) {
|
79
58
|
if (token_amount.isZero() || this.price.isZero()) {
|
80
59
|
return constants_1.BN_ZERO;
|