flash-sdk 1.0.25 → 1.0.27

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.
@@ -6,7 +6,7 @@ var anchor_1 = require("@coral-xyz/anchor");
6
6
  var types_1 = require("./types");
7
7
  var OraclePrice_1 = require("./OraclePrice");
8
8
  var utils_1 = require("./utils");
9
- var PoolAccount = /** @class */ (function () {
9
+ var PoolAccount = (function () {
10
10
  function PoolAccount(publicKey, parseData) {
11
11
  this.publicKey = publicKey;
12
12
  Object.assign(this, parseData);
@@ -23,22 +23,10 @@ var PoolAccount = /** @class */ (function () {
23
23
  PoolAccount.prototype.getAddLiquidityFee = function (tokenId, amount, custody, tokenPrice) {
24
24
  return this.getFee(tokenId, custody.fees.addLiquidity, amount, new anchor_1.BN(0), custody, tokenPrice);
25
25
  };
26
- // TODO
27
26
  PoolAccount.prototype.getFee = function (tokenId, baseFee, amountAdd, amountRemove, custody, tokenPrice) {
28
27
  if (custody.fees.mode === types_1.FeesMode.Fixed) {
29
- // return Self::get_fee_amount(base_fee, std::cmp::max(amount_add, amount_remove));
30
28
  return this.getFeeAmount(baseFee, anchor_1.BN.max(amountAdd, amountRemove));
31
29
  }
32
- // === NOW FEE MODE IS FeesMode.Linear
33
- // if token ratio is improved:
34
- // fee = base_fee / ratio_fee
35
- // otherwise:
36
- // fee = base_fee * ratio_fee
37
- // where:
38
- // if new_ratio < ratios.target:
39
- // ratio_fee = 1 + custody.fees.ratio_mult * (ratios.target - new_ratio) / (ratios.target - ratios.min);
40
- // otherwise:
41
- // ratio_fee = 1 + custody.fees.ratio_mult * (new_ratio - ratios.target) / (ratios.max - ratios.target);
42
30
  var ratios = this.ratios[tokenId];
43
31
  var current_ratio = this.getCurrentRatio(custody, tokenPrice);
44
32
  throw Error("TODODO");
@@ -60,14 +48,6 @@ var PoolAccount = /** @class */ (function () {
60
48
  if (this.aumUsd.isZero()) {
61
49
  return new anchor_1.BN(0);
62
50
  }
63
- // let ratio = math::checked_as_u64(math::checked_div(
64
- // math::checked_mul(
65
- // token_price.get_asset_amount_usd(custody.assets.owned, custody.decimals)? as u128,
66
- // Perpetuals::BPS_POWER,
67
- // )?,
68
- // self.aum_usd,
69
- // )?)?;
70
- // Ok(std::cmp::min(ratio, Perpetuals::BPS_POWER as u64))
71
51
  };
72
52
  PoolAccount.getEntryPrice = function (token_price, token_ema_price, side, custody) {
73
53
  var price = PoolAccount.getPrice(token_price, token_ema_price, ((0, types_1.isVariant)(side, 'long')) ? types_1.Side.Long : types_1.Side.Short, ((0, types_1.isVariant)(side, 'long')) ? custody.pricing.tradeSpreadLong : custody.pricing.tradeSpreadShort);
@@ -80,10 +60,7 @@ var PoolAccount = /** @class */ (function () {
80
60
  PoolAccount.getPriceAfterSlippage = function (isEntry, slippageBps, token_price, token_ema_price, side, custody) {
81
61
  if (isEntry) {
82
62
  var current_price = this.getEntryPrice(token_price, token_ema_price, side, custody);
83
- // console.log("getEntryPrice current_price:",current_price.toString())
84
- // TODO:: checked USE
85
63
  var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS), slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS));
86
- // console.log("getPriceAfterSlippage spread_i:",spread_i.toString());
87
64
  if ((0, types_1.isVariant)(side, 'long')) {
88
65
  return current_price.add(spread_i);
89
66
  }
@@ -98,12 +75,8 @@ var PoolAccount = /** @class */ (function () {
98
75
  }
99
76
  }
100
77
  else {
101
- // Opp in during close
102
78
  var current_price = this.getExitPrice(token_price, token_ema_price, side, custody);
103
- // console.log("getExitPrice current_price:",current_price.toString())
104
- // TODO:: checked USE
105
79
  var spread_i = (0, utils_1.checkedDecimalCeilMul)(current_price, new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS), slippageBps, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS));
106
- // console.log("spread_i:",spread_i);
107
80
  if ((0, types_1.isVariant)(side, 'long')) {
108
81
  if (spread_i.lt(current_price)) {
109
82
  return current_price.sub(spread_i);
@@ -120,7 +93,6 @@ var PoolAccount = /** @class */ (function () {
120
93
  };
121
94
  PoolAccount.getPrice = function (token_price, token_ema_price, side, spread) {
122
95
  if ((0, types_1.isVariant)(side, 'long')) {
123
- // console.log("inside long")
124
96
  var max_price = void 0;
125
97
  if (token_price.cmp(token_ema_price)) {
126
98
  max_price = token_price;
@@ -130,14 +102,12 @@ var PoolAccount = /** @class */ (function () {
130
102
  }
131
103
  ;
132
104
  var spread_i = (0, utils_1.checkedDecimalCeilMul)(max_price.price, max_price.exponent, spread, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), max_price.exponent);
133
- // console.log("getPrice spread_i:",spread_i.toString());
134
105
  return new OraclePrice_1.OraclePrice({
135
106
  price: max_price.price.add(spread_i),
136
107
  exponent: max_price.exponent,
137
108
  });
138
109
  }
139
110
  else {
140
- // console.log("inside short ")
141
111
  var min_price = void 0;
142
112
  if (token_price.cmp(token_ema_price)) {
143
113
  min_price = token_ema_price;
@@ -147,7 +117,6 @@ var PoolAccount = /** @class */ (function () {
147
117
  }
148
118
  ;
149
119
  var spread_i = (0, utils_1.checkedDecimalMul)(min_price.price, min_price.exponent, spread, new anchor_1.BN(-1 * constants_1.BPS_DECIMALS), min_price.exponent);
150
- // console.log("spread_i:",spread_i.toString())
151
120
  var price = void 0;
152
121
  if (spread_i.lt(min_price.price)) {
153
122
  price = min_price.price.sub(spread_i);
@@ -179,9 +148,7 @@ var PoolAccount = /** @class */ (function () {
179
148
  }
180
149
  ;
181
150
  var exit_price = PoolAccount.getExitPrice(token_price, token_ema_price, position.side, custody);
182
- // console.log("exit_price:",exit_price, exit_price?.toString())
183
151
  var size = token_ema_price.getTokenAmount(position.sizeUsd, custody.decimals);
184
- // console.log("size:",size, size?.toString())
185
152
  var exit_fee;
186
153
  if (liquidation) {
187
154
  exit_fee = this.getLiquidationFee(size, custody);
@@ -190,13 +157,9 @@ var PoolAccount = /** @class */ (function () {
190
157
  exit_fee = this.getExitFee(size, custody);
191
158
  }
192
159
  ;
193
- // console.log("exit_fee:",exit_fee.toString())
194
160
  var exit_fee_usd = token_ema_price.getAssetAmountUsd(exit_fee, custody.decimals);
195
- // console.log("exit_fee_usd:",exit_fee_usd.toString())
196
161
  var interest_usd = custody.getInterestAmountUsd(position, curtime);
197
- // console.log("interest_usd:",interest_usd.toString())
198
162
  var unrealized_loss_usd = (exit_fee_usd.add(interest_usd)).add(position.unrealizedLossUsd);
199
- // console.log("unrealized_loss_usd:",unrealized_loss_usd.toString())
200
163
  var price_diff_profit, price_diff_loss;
201
164
  if ((0, types_1.isVariant)(position.side, 'long')) {
202
165
  if (exit_price.gt(position.price)) {
@@ -217,19 +180,13 @@ var PoolAccount = /** @class */ (function () {
217
180
  price_diff_loss = exit_price.sub(position.price);
218
181
  }
219
182
  ;
220
- // console.log("1 price_diff_profit:",price_diff_profit.toString())
221
- // console.log("2 price_diff_loss:",price_diff_loss.toString())
222
183
  var position_price = (0, utils_1.scaleToExponent)(position.price, new anchor_1.BN(-1 * constants_1.PRICE_DECIMALS), new anchor_1.BN(-1 * constants_1.USD_DECIMALS));
223
- // console.log("position_price:",position_price.toString())
224
184
  if (price_diff_profit.gt(constants_1.BN_ZERO)) {
225
185
  var potential_profit_usd = (position.sizeUsd.mul(price_diff_profit)).div(position_price);
226
186
  potential_profit_usd = potential_profit_usd.add(position.unrealizedProfitUsd);
227
- // console.log("potential_profit_usd:",potential_profit_usd.toString())
228
187
  if (potential_profit_usd.gte(unrealized_loss_usd)) {
229
188
  var cur_profit_usd = potential_profit_usd.sub(unrealized_loss_usd);
230
189
  var max_profit_usd = min_price.getAssetAmountUsd(position.lockedAmount, custody.decimals);
231
- // console.log("cur_profit_usd:",cur_profit_usd.toString())
232
- // console.log("max_profit_usd:",max_profit_usd.toString())
233
190
  return {
234
191
  profit: anchor_1.BN.min(max_profit_usd, cur_profit_usd),
235
192
  loss: constants_1.BN_ZERO,
@@ -237,8 +194,6 @@ var PoolAccount = /** @class */ (function () {
237
194
  };
238
195
  }
239
196
  else {
240
- // console.log(" -- unrealized_loss_usd:",unrealized_loss_usd.toString())
241
- // console.log(" -- potential_profit_usd:",potential_profit_usd.toString())
242
197
  return {
243
198
  profit: constants_1.BN_ZERO,
244
199
  loss: unrealized_loss_usd.sub(potential_profit_usd),
@@ -249,9 +204,7 @@ var PoolAccount = /** @class */ (function () {
249
204
  else {
250
205
  var potential_loss_usd = (0, utils_1.checkedCeilDiv)(position.sizeUsd.mul(price_diff_loss), position_price);
251
206
  potential_loss_usd = potential_loss_usd.add(unrealized_loss_usd);
252
- // console.log("potential_loss_usd:",potential_loss_usd.toString())
253
207
  if (potential_loss_usd.gte(position.unrealizedProfitUsd)) {
254
- // console.log("position.unrealizedProfitUsd:",position.unrealizedProfitUsd.toString())
255
208
  return {
256
209
  profit: constants_1.BN_ZERO,
257
210
  loss: potential_loss_usd.sub(position.unrealizedProfitUsd),
@@ -261,8 +214,6 @@ var PoolAccount = /** @class */ (function () {
261
214
  else {
262
215
  var cur_profit_usd = position.unrealizedProfitUsd.sub(potential_loss_usd);
263
216
  var max_profit_usd = min_price.getAssetAmountUsd(position.lockedAmount, custody.decimals);
264
- // console.log("cur_profit_usd:",cur_profit_usd.toString())
265
- // console.log("max_profit_usd:",max_profit_usd.toString())
266
217
  return {
267
218
  profit: anchor_1.BN.min(max_profit_usd, cur_profit_usd),
268
219
  loss: constants_1.BN_ZERO,
@@ -270,7 +221,7 @@ var PoolAccount = /** @class */ (function () {
270
221
  };
271
222
  }
272
223
  }
273
- }; //getPnlUsd
224
+ };
274
225
  PoolAccount.prototype.getAssetsUnderManagementUsd = function (token_prices, token_ema_prices, custodyAccounts, aum_calc_mode, currentTime) {
275
226
  var pool_amount_usd = constants_1.BN_ZERO;
276
227
  for (var index = 0; index < custodyAccounts.length; index++) {
@@ -278,7 +229,6 @@ var PoolAccount = /** @class */ (function () {
278
229
  throw Error("token prices length incorrect");
279
230
  }
280
231
  var aum_token_price = void 0;
281
- // switch unable to match enum
282
232
  if ((0, types_1.isVariant)(aum_calc_mode, "last")) {
283
233
  aum_token_price = token_prices[index];
284
234
  }
@@ -304,20 +254,16 @@ var PoolAccount = /** @class */ (function () {
304
254
  var token_amount_usd = aum_token_price.getAssetAmountUsd(custodyAccounts[index].assets.owned, custodyAccounts[index].decimals);
305
255
  pool_amount_usd = pool_amount_usd.add(token_amount_usd);
306
256
  if (custodyAccounts[index].pricing.useUnrealizedPnlInAum) {
307
- // compute aggregate unrealized pnl
308
- // console.log("long_pos:",custodyAccounts[index].longPositions)
309
257
  var _a = this.getPnlUsd(custodyAccounts[index].getCollectivePosition(types_1.Side.Long), token_prices[index], token_ema_prices[index], custodyAccounts[index], currentTime, false), long_profit = _a.profit, long_loss = _a.loss;
310
- // console.log("long_pos:",custodyAccounts[index].shortPositions)
311
258
  var _b = this.getPnlUsd(custodyAccounts[index].getCollectivePosition(types_1.Side.Short), token_prices[index], token_ema_prices[index], custodyAccounts[index], currentTime, false), short_profit = _b.profit, short_loss = _b.loss;
312
- // adjust pool amount by collective profit/loss
313
259
  pool_amount_usd = pool_amount_usd.add(long_profit);
314
260
  pool_amount_usd = pool_amount_usd.add(short_profit);
315
- pool_amount_usd = pool_amount_usd.sub(long_loss); // check overflow - saturating_sub
261
+ pool_amount_usd = pool_amount_usd.sub(long_loss);
316
262
  pool_amount_usd = pool_amount_usd.sub(short_loss);
317
263
  }
318
264
  }
319
265
  return pool_amount_usd;
320
266
  };
321
267
  return PoolAccount;
322
- }()); // Pool
268
+ }());
323
269
  exports.PoolAccount = PoolAccount;
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.PoolConfig = void 0;
18
18
  var web3_js_1 = require("@solana/web3.js");
19
19
  var PoolConfig_json_1 = __importDefault(require("./PoolConfig.json"));
20
- var PoolConfig = /** @class */ (function () {
20
+ var PoolConfig = (function () {
21
21
  function PoolConfig(programId, cluster, poolName, poolAddress, lpTokenMint, lpDecimals, perpetuals, transferAuthority, multisig, tokens, custodies) {
22
22
  var _this = this;
23
23
  this.programId = programId;
@@ -57,9 +57,6 @@ var PoolConfig = /** @class */ (function () {
57
57
  .filter(function (custody) { return !custody.isStable; })
58
58
  .map(function (custody) { return new web3_js_1.PublicKey(custody.custodyAccount); }));
59
59
  };
60
- // static getAllPoolConfigs(cluster: Cluster): PoolConfig[] {
61
- // return poolConfigs.pools.map(p => this.fromIdsByName(p.poolName, cluster))
62
- // }
63
60
  PoolConfig.getCustodyConfig = function (custodyAccountPk, poolName, cluster) {
64
61
  return this.fromIdsByName(poolName, cluster).custodies.find(function (f) { return f.custodyAccount.toBase58() === custodyAccountPk.toString(); });
65
62
  };
@@ -6,6 +6,96 @@
6
6
  "testnet": "http://api.testnet.rpcpool.com"
7
7
  },
8
8
  "pools": [
9
+ {
10
+ "programId": "FT9LNjBwCwt4C7A1UiKUHTW7Ds4gJxGBEbqUfJiupSHr",
11
+ "cluster": "devnet",
12
+ "poolName": "devnet.1",
13
+ "poolAddress": "6ScKsHUbEgaidWTBNpo2WzBRwXx4gbvWXitYUNqUFv6p",
14
+ "lpTokenMint": "HNnh2dWBt5PKVUCrer85caHqmivPndk6Po5y7XnzcBrg",
15
+ "lpDecimals": 6,
16
+ "perpetuals": "8iou5Rt7J89uhPwL5kkEcRdwLWwy5AzrWHxRnFqfFkL3",
17
+ "transferAuthority": "45McQhLvcCTqKs9ua1c4SauiTWFB4KRfobbwh2h74etc",
18
+ "multisig": "3Uj5gn8NA8swzRz6J8LGorhCxPA4eRa6XhnJeeADV3CZ",
19
+ "tokens": [
20
+ {
21
+ "symbol": "USDC",
22
+ "mintKey": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr",
23
+ "decimals": 6,
24
+ "isStable": true,
25
+ "pythTicker": "Crypto.USDC/USD"
26
+ },
27
+ {
28
+ "symbol": "SOL",
29
+ "mintKey": "So11111111111111111111111111111111111111112",
30
+ "decimals": 9,
31
+ "isStable": false,
32
+ "pythTicker": "Crypto.SOL/USD"
33
+ },
34
+ {
35
+ "symbol": "WSOL",
36
+ "mintKey": "So11111111111111111111111111111111111111112",
37
+ "decimals": 9,
38
+ "isStable": false,
39
+ "pythTicker": "Crypto.SOL/USD"
40
+ },
41
+ {
42
+ "symbol": "BTC",
43
+ "mintKey": "B8DYqbh57aEPRbUq7reyueY6jaYoN75js5YsiM84tFfP",
44
+ "decimals": 6,
45
+ "isStable": false,
46
+ "pythTicker": "Crypto.BTC/USD"
47
+ },
48
+ {
49
+ "symbol": "ETH",
50
+ "mintKey": "BA17bkYW78GvnirtgRHcceQxZdwkhpzbvrwDU6voUXRz",
51
+ "decimals": 6,
52
+ "isStable": false,
53
+ "pythTicker": "Crypto.ETH/USD"
54
+ }
55
+ ],
56
+ "custodies": [
57
+ {
58
+ "custodyId": 0,
59
+ "custodyAccount": "5Yy4UN3BiG2XGpdnAaZzZiHrLP74v2DPrrR7pseQm34e",
60
+ "tokenAccount": "GwBjqN7tuRsJhqZJPXLHRXFadToNf4xHqFAnaJUV3C14",
61
+ "symbol": "USDC",
62
+ "mintKey": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr",
63
+ "decimals": 6,
64
+ "isStable": true,
65
+ "oracleAddress": "5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7"
66
+ },
67
+ {
68
+ "custodyId": 1,
69
+ "custodyAccount": "EDM5BrduPuHyzTaJS3rSYDR5ZSJGFKfSQ5hcsf5Ybjof",
70
+ "tokenAccount": "VdcLYqXk9mCZ4jPknTWijpeofLx7s55S5r5PmwbA8id",
71
+ "symbol": "SOL",
72
+ "mintKey": "So11111111111111111111111111111111111111112",
73
+ "decimals": 9,
74
+ "isStable": false,
75
+ "oracleAddress": "J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"
76
+ },
77
+ {
78
+ "custodyId": 2,
79
+ "custodyAccount": "",
80
+ "tokenAccount": "",
81
+ "symbol": "BTC",
82
+ "mintKey": "B8DYqbh57aEPRbUq7reyueY6jaYoN75js5YsiM84tFfP",
83
+ "decimals": 6,
84
+ "isStable": false,
85
+ "oracleAddress": "HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J"
86
+ },
87
+ {
88
+ "custodyId": 3,
89
+ "custodyAccount": "EbaGMJApw6hRu3Hnzm2CbhZjtHJLNJDdP2vn7s5SQH6M",
90
+ "tokenAccount": "GEcw5RUT6dA31NwaoMkndXk8hCuUMUZ5yJuXJ5DE6mp3",
91
+ "symbol": "ETH",
92
+ "mintKey": "BA17bkYW78GvnirtgRHcceQxZdwkhpzbvrwDU6voUXRz",
93
+ "decimals": 6,
94
+ "isStable": false,
95
+ "oracleAddress": "EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw"
96
+ }
97
+ ]
98
+ },
9
99
  {
10
100
  "programId": "BPkaJkzjqZ3u3sMnK7oHup5GGV5EHp4hYthz9Yodvydj",
11
101
  "cluster": "devnet",
@@ -4,13 +4,13 @@ exports.PoolDataClient = void 0;
4
4
  var constants_1 = require("./constants");
5
5
  var anchor_1 = require("@coral-xyz/anchor");
6
6
  var utils_1 = require("./utils");
7
- var PoolDataClient = /** @class */ (function () {
7
+ var PoolDataClient = (function () {
8
8
  function PoolDataClient(poolConfig, pool, lpTokenInfo, custodies) {
9
9
  this.poolConfig = poolConfig;
10
10
  this.pool = pool;
11
11
  this.lpTokenInfo = lpTokenInfo;
12
12
  this.custodies = custodies;
13
- this.totalPoolValueUsd = new anchor_1.BN(-1); // -1 meaning unset
13
+ this.totalPoolValueUsd = new anchor_1.BN(-1);
14
14
  }
15
15
  PoolDataClient.prototype.loadCustodies = function (custodies) {
16
16
  this.custodies = custodies;
@@ -21,8 +21,6 @@ var PoolDataClient = /** @class */ (function () {
21
21
  PoolDataClient.prototype.loadLpData = function (lpTokenInfo) {
22
22
  this.lpTokenInfo = lpTokenInfo;
23
23
  };
24
- // TODO :: replace this with PoolAccount.getAssetsUnderManagementUsd()
25
- // should take pnl's into account
26
24
  PoolDataClient.prototype.getLpStats = function (prices) {
27
25
  var stableCoinAmount = new anchor_1.BN(0);
28
26
  var totalPoolValueUsd = new anchor_1.BN(0);
@@ -32,7 +30,7 @@ var PoolDataClient = /** @class */ (function () {
32
30
  if (custodyData.isStable) {
33
31
  stableCoinAmount = stableCoinAmount.add(custodyData.assets.owned);
34
32
  }
35
- var priceBN = new anchor_1.BN(prices.get(custody.symbol) * Math.pow(10, constants_1.PRICE_DECIMALS)); // so always keep prices with 6 decimals
33
+ var priceBN = new anchor_1.BN(prices.get(custody.symbol) * Math.pow(10, constants_1.PRICE_DECIMALS));
36
34
  var custodyValue = priceBN.mul(custodyData.assets.owned).div(new anchor_1.BN(Math.pow(10, custody.decimals)));
37
35
  totalPoolValueUsd = totalPoolValueUsd.add(custodyValue);
38
36
  }
@@ -42,12 +40,6 @@ var PoolDataClient = /** @class */ (function () {
42
40
  var custody = _a[_i];
43
41
  _loop_1(custody);
44
42
  }
45
- // console.log("totalPoolValueUsd.toNumber():",totalPoolValueUsd.toString())
46
- // console.log("stableCoinAmount.toNumber():",stableCoinAmount.toString())
47
- // if(this.lpTokenInfo.supply.toString() =='0' || totalPoolValueUsd.toString()=='0'){
48
- // console.error("supply or amt cannot be zero")
49
- // throw "supply or amt cannot be zero";
50
- // }
51
43
  this.totalPoolValueUsd = totalPoolValueUsd;
52
44
  var lpPrice = totalPoolValueUsd.div(new anchor_1.BN(this.lpTokenInfo.supply.toString() === '0' ? 1 : this.lpTokenInfo.supply.toString()));
53
45
  return {
@@ -57,7 +49,6 @@ var PoolDataClient = /** @class */ (function () {
57
49
  price: lpPrice,
58
50
  stableCoinPercentage: totalPoolValueUsd.toNumber() != 0 ? stableCoinAmount.mul(new anchor_1.BN(constants_1.PERCENTAGE_DECIMALS)).div(totalPoolValueUsd) : new anchor_1.BN(1),
59
51
  marketCap: lpPrice.mul(new anchor_1.BN(this.lpTokenInfo.supply.toString())),
60
- // totalStaked : BN,
61
52
  };
62
53
  };
63
54
  PoolDataClient.prototype.getOiLongUI = function () {
@@ -74,27 +65,19 @@ var PoolDataClient = /** @class */ (function () {
74
65
  });
75
66
  return totalAmount;
76
67
  };
77
- // handle decimal and this should accept a list of prices probs map or object
78
68
  PoolDataClient.prototype.getCustodyDetails = function (prices) {
79
69
  var custodyDetails = [];
80
70
  var _loop_2 = function (i) {
81
71
  var custody = this_2.poolConfig.custodies[i];
82
72
  if (!custody)
83
73
  return "continue";
84
- // console.log('this.pool :>> ', this.pool);
85
- // const token = this.pool.tokens.find(t => t.custody.toBase58() === custody.custodyAccount.toBase58());
86
74
  var tokenRatio = this_2.pool.ratios[i];
87
75
  var custodyData = this_2.custodies.find(function (t) { return t.mint.toBase58() === custody.mintKey.toBase58(); });
88
- var priceBN = new anchor_1.BN(prices.get(custody.symbol) * Math.pow(10, 6)); // so always keep prices with 6 decimals
76
+ var priceBN = new anchor_1.BN(prices.get(custody.symbol) * Math.pow(10, 6));
89
77
  if (this_2.totalPoolValueUsd.toString() == "-1") {
90
78
  console.error("call getLpStats first");
91
79
  throw "call getLpStats first";
92
80
  }
93
- // if(this.totalPoolValueUsd.toString()=='0'){
94
- // console.error("call getLpStats first , totalPoolValueUsd ZERO")
95
- // return defaultData.custodyDetails;
96
- // }
97
- // console.log("this.totalPoolValueUsd:",this.totalPoolValueUsd.toString())
98
81
  if (custodyData && tokenRatio) {
99
82
  custodyDetails.push({
100
83
  symbol: custody.symbol,
@@ -106,9 +89,7 @@ var PoolDataClient = /** @class */ (function () {
106
89
  utilization: custodyData.assets.owned.toNumber() ?
107
90
  (0, utils_1.toUiDecimals)(custodyData.assets.locked.mul(new anchor_1.BN(Math.pow(10, constants_1.PERCENTAGE_DECIMALS))).div(custodyData.assets.owned), constants_1.PERCENTAGE_DECIMALS, 2)
108
91
  : '0',
109
- // assetsAmountUi : (custodyData.assets.owned.toNumber() / 10**(custody.decimals)).toFixed(4),
110
92
  assetsAmountUi: (0, utils_1.toUiDecimals)(custodyData.assets.owned, custody.decimals, 4, true),
111
- // totalUsdAmountUi : ((custodyData.assets.owned.mul(priceBN)).div(new BN(10**(custody.decimals))).toNumber() / 10**6).toFixed(4),
112
93
  totalUsdAmountUi: (0, utils_1.toUiDecimals)((custodyData.assets.owned.mul(priceBN)), custody.decimals + constants_1.PRICE_DECIMALS, 2, true),
113
94
  });
114
95
  }
@@ -148,5 +129,5 @@ var PoolDataClient = /** @class */ (function () {
148
129
  };
149
130
  };
150
131
  return PoolDataClient;
151
- }()); // PoolDisplayData
132
+ }());
152
133
  exports.PoolDataClient = PoolDataClient;
@@ -49,7 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.PositionAccount = void 0;
51
51
  var anchor_1 = require("@coral-xyz/anchor");
52
- var PositionAccount = /** @class */ (function () {
52
+ var PositionAccount = (function () {
53
53
  function PositionAccount(publicKey, parseData) {
54
54
  this.publicKey = publicKey;
55
55
  Object.assign(this, parseData);
@@ -66,9 +66,9 @@ var PositionAccount = /** @class */ (function () {
66
66
  try {
67
67
  }
68
68
  catch (error) {
69
- return [2 /*return*/, new anchor_1.BN(0)];
69
+ return [2, new anchor_1.BN(0)];
70
70
  }
71
- return [2 /*return*/];
71
+ return [2];
72
72
  });
73
73
  });
74
74
  };
@@ -78,9 +78,9 @@ var PositionAccount = /** @class */ (function () {
78
78
  try {
79
79
  }
80
80
  catch (error) {
81
- return [2 /*return*/, new anchor_1.BN(0)];
81
+ return [2, new anchor_1.BN(0)];
82
82
  }
83
- return [2 /*return*/];
83
+ return [2];
84
84
  });
85
85
  });
86
86
  };
package/dist/Token.js CHANGED
@@ -1 +0,0 @@
1
- // later inport from UI
@@ -4,13 +4,13 @@ exports.BN_ONE = exports.BN_ZERO = exports.RATE_POWER = exports.RATE_DECIMALS =
4
4
  var bn_js_1 = require("bn.js");
5
5
  exports.DEFAULT_CLUSTER = 'devnet';
6
6
  exports.DEFAULT_POOL = 'pool1';
7
- exports.PERCENTAGE_DECIMALS = 4; // stableCoinPercentage
7
+ exports.PERCENTAGE_DECIMALS = 4;
8
8
  exports.PRICE_DECIMALS = 6;
9
9
  exports.USD_DECIMALS = 6;
10
10
  exports.BPS_DECIMALS = 4;
11
11
  exports.BPS_POWER = Math.pow(10, (exports.BPS_DECIMALS));
12
12
  exports.LP_DECIMALS = exports.USD_DECIMALS;
13
- exports.RATE_DECIMALS = 9; // borow rate
13
+ exports.RATE_DECIMALS = 9;
14
14
  exports.RATE_POWER = Math.pow(10, (exports.RATE_DECIMALS));
15
15
  exports.BN_ZERO = new bn_js_1.BN(0);
16
16
  exports.BN_ONE = new bn_js_1.BN(1);
package/dist/index.js CHANGED
@@ -28,4 +28,3 @@ __exportStar(require("./PoolDataClient"), exports);
28
28
  var perpetuals_1 = require("./idl/perpetuals");
29
29
  Object.defineProperty(exports, "IDL", { enumerable: true, get: function () { return perpetuals_1.IDL; } });
30
30
  __exportStar(require("./utils/rpc"), exports);
31
- // export { default as PoolConfigJson } from "./PoolConfig.json";