flash-sdk 1.0.134 → 2.0.1

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.
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import { Assets, FeesStats, Custody, Fees, PricingParams, TradeStats, Permissions, BorrowRateParams, OracleParams, VolumeStats, PositionStats, BorrowRateState, Side } from "./types";
3
- import { PositionAccount } from "./PositionAccount";
2
+ import { Assets, FeesStats, Custody, Fees, PricingParams, Permissions, BorrowRateParams, OracleParams, BorrowRateState } from "./types";
3
+ import BN from "bn.js";
4
4
  export declare class CustodyAccount implements Custody {
5
5
  publicKey: PublicKey;
6
6
  pool: PublicKey;
@@ -8,23 +8,21 @@ export declare class CustodyAccount implements Custody {
8
8
  tokenAccount: PublicKey;
9
9
  decimals: number;
10
10
  isStable: boolean;
11
+ depegAdjustment: boolean;
11
12
  isVirtual: boolean;
13
+ distributeRewards: boolean;
12
14
  oracle: OracleParams;
13
15
  pricing: PricingParams;
14
16
  permissions: Permissions;
15
17
  fees: Fees;
16
18
  borrowRate: BorrowRateParams;
19
+ rewardThreshold: BN;
17
20
  assets: Assets;
18
- collectedFees: FeesStats;
19
- volumeStats: VolumeStats;
20
- tradeStats: TradeStats;
21
- longPositions: PositionStats;
22
- shortPositions: PositionStats;
21
+ feesStats: FeesStats;
23
22
  borrowRateState: BorrowRateState;
24
23
  bump: number;
25
24
  tokenAccountBump: number;
26
25
  constructor(publicKey: PublicKey, parseData: Custody);
27
26
  static from(publicKey: PublicKey, parseData: Custody): CustodyAccount;
28
27
  updateCustodyData(custody: Custody): void;
29
- getCollectivePosition(side: Side): PositionAccount;
30
28
  }
@@ -12,10 +12,6 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.CustodyAccount = void 0;
15
- var web3_js_1 = require("@solana/web3.js");
16
- var types_1 = require("./types");
17
- var PositionAccount_1 = require("./PositionAccount");
18
- var constants_1 = require("./constants");
19
15
  var CustodyAccount = (function () {
20
16
  function CustodyAccount(publicKey, parseData) {
21
17
  this.publicKey = publicKey;
@@ -27,23 +23,6 @@ var CustodyAccount = (function () {
27
23
  CustodyAccount.prototype.updateCustodyData = function (custody) {
28
24
  Object.assign(this, __assign({}, custody));
29
25
  };
30
- CustodyAccount.prototype.getCollectivePosition = function (side) {
31
- var stats;
32
- if ((0, types_1.isVariant)(side, 'long')) {
33
- stats = this.longPositions;
34
- }
35
- else {
36
- stats = this.shortPositions;
37
- }
38
- ;
39
- if (stats.openPositions.gt(constants_1.BN_ZERO)) {
40
- var obj = __assign({ side: side, price: stats.averagePrice.div(stats.totalQuantity), sizeUsd: stats.sizeUsd, collateralUsd: stats.collateralUsd, unrealizedLossUsd: stats.cumulativeInterestUsd, cumulativeInterestSnapshot: stats.cumulativeInterestSnapshot, lockedAmount: stats.lockedAmount }, types_1.DEFAULT_POSITION);
41
- return new PositionAccount_1.PositionAccount(web3_js_1.PublicKey.default, obj);
42
- }
43
- else {
44
- return new PositionAccount_1.PositionAccount(web3_js_1.PublicKey.default, types_1.DEFAULT_POSITION);
45
- }
46
- };
47
26
  return CustodyAccount;
48
27
  }());
49
28
  exports.CustodyAccount = CustodyAccount;
@@ -0,0 +1,23 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { Market, MarketPermissions, PositionStats, Side } from "./types";
3
+ import BN from "bn.js";
4
+ import { PositionAccount } from "./PositionAccount";
5
+ export declare class MarketAccount implements Market {
6
+ publicKey: PublicKey;
7
+ pool: PublicKey;
8
+ targetCustody: PublicKey;
9
+ collateralCustody: PublicKey;
10
+ side: Side;
11
+ correlation: boolean;
12
+ maxPayoffBps: BN;
13
+ permissions: MarketPermissions;
14
+ openInterest: BN;
15
+ collectivePosition: PositionStats;
16
+ targetCustodyId: BN;
17
+ collateralCustodyId: BN;
18
+ bump: number;
19
+ constructor(publicKey: PublicKey, parseData: Market);
20
+ static from(publicKey: PublicKey, parseData: Market): MarketAccount;
21
+ updateMarketData(market: Market): void;
22
+ getCollectivePosition(): PositionAccount;
23
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.MarketAccount = void 0;
15
+ var web3_js_1 = require("@solana/web3.js");
16
+ var types_1 = require("./types");
17
+ var PositionAccount_1 = require("./PositionAccount");
18
+ var constants_1 = require("./constants");
19
+ var MarketAccount = (function () {
20
+ function MarketAccount(publicKey, parseData) {
21
+ this.publicKey = publicKey;
22
+ Object.assign(this, parseData);
23
+ }
24
+ MarketAccount.from = function (publicKey, parseData) {
25
+ return new MarketAccount(publicKey, parseData);
26
+ };
27
+ MarketAccount.prototype.updateMarketData = function (market) {
28
+ Object.assign(this, __assign({}, market));
29
+ };
30
+ MarketAccount.prototype.getCollectivePosition = function () {
31
+ var stats;
32
+ if (stats.openPositions.gt(constants_1.BN_ZERO)) {
33
+ var obj = __assign({ entryPrice: stats.averageEntryPrice, sizeAmount: stats.sizeAmount, sizeUsd: stats.sizeUsd, collateralAmount: stats.collateralAmount, collateralUsd: stats.collateralUsd, lockedAmount: stats.lockedAmount, lockedUsd: stats.lockedUsd, unsettledFeesUsd: stats.unsettledFeeUsd, cumulativeLockFeeSnapshot: stats.cumulativeLockFeeSnapshot }, types_1.DEFAULT_POSITION);
34
+ return new PositionAccount_1.PositionAccount(web3_js_1.PublicKey.default, obj);
35
+ }
36
+ else {
37
+ return new PositionAccount_1.PositionAccount(web3_js_1.PublicKey.default, types_1.DEFAULT_POSITION);
38
+ }
39
+ };
40
+ return MarketAccount;
41
+ }());
42
+ exports.MarketAccount = MarketAccount;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { BN } from "@coral-xyz/anchor";
3
+ import { ContractOraclePrice } from "./types";
3
4
  export declare class OraclePrice {
4
5
  price: BN;
5
6
  exponent: BN;
@@ -17,6 +18,7 @@ export declare class OraclePrice {
17
18
  confidence: BN;
18
19
  timestamp: BN;
19
20
  }): OraclePrice;
21
+ toContractOraclePrice(): ContractOraclePrice;
20
22
  cmp(other: OraclePrice): -1 | 0 | 1;
21
23
  getDeviationFactor(other: OraclePrice): BN;
22
24
  scale_to_exponent(target_exponent: BN): OraclePrice;
@@ -11,6 +11,12 @@ var OraclePrice = (function () {
11
11
  OraclePrice.from = function (parseData) {
12
12
  return new OraclePrice(parseData);
13
13
  };
14
+ OraclePrice.prototype.toContractOraclePrice = function () {
15
+ return {
16
+ price: this.price,
17
+ exponent: this.exponent.toNumber()
18
+ };
19
+ };
14
20
  OraclePrice.prototype.cmp = function (other) {
15
21
  var lhs, rhs;
16
22
  if (this.exponent.eq(other.exponent)) {
@@ -32,14 +38,16 @@ var OraclePrice = (function () {
32
38
  };
33
39
  OraclePrice.prototype.getDeviationFactor = function (other) {
34
40
  if (!this.exponent.eq(other.exponent)) {
35
- throw "Exponents mistmatch";
41
+ throw "Exponents mistmatch ".concat(this.exponent.toNumber(), " != ").concat(other.exponent.toNumber());
36
42
  }
37
- if (this.price.cmp(other.price) == 1) {
38
- return ((this.price.sub(other.price)).muln(constants_1.BPS_POWER).div(this.price));
43
+ var factor;
44
+ if (this.price.gt(other.price)) {
45
+ factor = OraclePrice.from({ price: (this.price.sub(other.price).div(other.price)), exponent: this.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
39
46
  }
40
47
  else {
41
- return ((other.price.sub(this.price)).muln(constants_1.BPS_POWER).div(this.price));
48
+ factor = OraclePrice.from({ price: (other.price.sub(this.price).div(other.price)), exponent: this.exponent, confidence: constants_1.BN_ZERO, timestamp: constants_1.BN_ZERO });
42
49
  }
50
+ return (factor.scale_to_exponent(new anchor_1.BN(-1 * constants_1.BPS_DECIMALS)).price);
43
51
  };
44
52
  OraclePrice.prototype.scale_to_exponent = function (target_exponent) {
45
53
  if (!target_exponent.isNeg()) {