flash-sdk 2.43.1 → 2.44.1-alpha.0

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.
@@ -588,27 +588,34 @@ var PerpetualsClient = (function () {
588
588
  }
589
589
  });
590
590
  }); };
591
- this.removeCustody = function (poolName, tokenMint, ratios) { return __awaiter(_this, void 0, void 0, function () {
591
+ this.removeCustody = function (poolName, tokenMint, ratios, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
592
+ var custodyConfig, userReceivingTokenAccount;
592
593
  return __generator(this, function (_a) {
593
594
  switch (_a.label) {
594
- case 0: return [4, this.program.methods
595
- .removeCustody({ ratios: ratios })
596
- .accounts({
597
- admin: this.admin,
598
- multisig: this.multisig.publicKey,
599
- transferAuthority: this.authority.publicKey,
600
- perpetuals: this.perpetuals.publicKey,
601
- pool: this.getPoolKey(poolName),
602
- custody: this.getCustodyKey(poolName, tokenMint),
603
- custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
604
- systemProgram: web3_js_1.SystemProgram.programId,
605
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
606
- })
607
- .rpc()
608
- .catch(function (err) {
609
- console.error(err);
610
- throw err;
611
- })];
595
+ case 0:
596
+ custodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(tokenMint); });
597
+ userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, this.admin, true);
598
+ return [4, this.program.methods
599
+ .removeCustody({ ratios: ratios })
600
+ .accounts({
601
+ admin: this.admin,
602
+ receivingAccount: userReceivingTokenAccount,
603
+ multisig: this.multisig.publicKey,
604
+ transferAuthority: this.authority.publicKey,
605
+ perpetuals: this.perpetuals.publicKey,
606
+ pool: this.getPoolKey(poolName),
607
+ custody: this.getCustodyKey(poolName, tokenMint),
608
+ custodyTokenAccount: this.getCustodyTokenAccountKey(poolName, tokenMint),
609
+ custodyOracleAccount: this.useExtOracleAccount ? custodyConfig.extOracleAccount : custodyConfig.intOracleAccount,
610
+ systemProgram: web3_js_1.SystemProgram.programId,
611
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
612
+ ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
613
+ })
614
+ .rpc()
615
+ .catch(function (err) {
616
+ console.error(err);
617
+ throw err;
618
+ })];
612
619
  case 1:
613
620
  _a.sent();
614
621
  return [2];
@@ -1234,8 +1241,9 @@ var PerpetualsClient = (function () {
1234
1241
  }
1235
1242
  return collateralInInputToken;
1236
1243
  };
1237
- this.getDecreaseSizeCollateralAndFeeSync = function (positionAccount, marketCorrelation, sizeDeltaUsd, keepLevSame, targetPrice, targetEmaPrice, marketConfig, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, side, poolConfig, discountBps) {
1244
+ this.getDecreaseSizeCollateralAndFeeSync = function (positionAccount, marketCorrelation, sizeDeltaUsd, keepLevSame, targetPrice, targetEmaPrice, marketConfig, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, side, poolConfig, discountBps, debugLogs) {
1238
1245
  if (discountBps === void 0) { discountBps = constants_1.BN_ZERO; }
1246
+ if (debugLogs === void 0) { debugLogs = false; }
1239
1247
  if (!marketConfig.marketAccount.equals(positionAccount.market)) {
1240
1248
  throw new Error("marketCustodyAccount mismatch");
1241
1249
  }
@@ -1272,6 +1280,9 @@ var PerpetualsClient = (function () {
1272
1280
  var liabilityUsd = newPnl.lossUsd.add(totalFeesUsd);
1273
1281
  var assetsUsd = newPnl.profitUsd.add(currentCollateralUsd);
1274
1282
  var closeAmount, feesAmount;
1283
+ if (debugLogs) {
1284
+ console.log("assetsUsd.sub(liabilityUsd):", collateralCustodyAccount.decimals, assetsUsd.toString(), liabilityUsd.toString(), assetsUsd.sub(liabilityUsd).toString());
1285
+ }
1275
1286
  if (assetsUsd.gte(liabilityUsd)) {
1276
1287
  closeAmount = collateralMinMaxPrice.max.getTokenAmount(assetsUsd.sub(liabilityUsd), collateralCustodyAccount.decimals);
1277
1288
  feesAmount = collateralMinMaxPrice.min.getTokenAmount(totalFeesUsd, collateralCustodyAccount.decimals);
@@ -1306,11 +1317,18 @@ var PerpetualsClient = (function () {
1306
1317
  var collateralAmountReceived = closeAmount;
1307
1318
  var collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(collateralAmountReceived, collateralCustodyAccount.decimals);
1308
1319
  var maxWithdrawableAmount = _this.getMaxWithdrawableAmountSyncInternal(newPosition, targetPrice, targetEmaPrice, targetCustodyAccount, collateralPrice, collateralEmaPrice, collateralCustodyAccount, currentTimestamp, poolConfig, closeAmount);
1320
+ if (debugLogs) {
1321
+ console.log("maxWithdrawableAmount ", maxWithdrawableAmount.toString(), keepLevSame);
1322
+ console.log("collateralAmountReceived ", collateralAmountReceived.toString(), keepLevSame);
1323
+ }
1309
1324
  if (collateralAmountReceived.lt(constants_1.BN_ZERO)) {
1310
1325
  collateralAmountReceived = constants_1.BN_ZERO;
1311
1326
  collateralAmountRecievedUsd = constants_1.BN_ZERO;
1312
1327
  }
1313
1328
  else if (collateralAmountReceived.gt(maxWithdrawableAmount)) {
1329
+ if (debugLogs) {
1330
+ console.log("exceeding to redicing maxWithdrawableAmount ", maxWithdrawableAmount.toString(), collateralAmountReceived.toString());
1331
+ }
1314
1332
  collateralAmountReceived = maxWithdrawableAmount;
1315
1333
  collateralAmountRecievedUsd = collateralMinMaxPrice.min.getAssetAmountUsd(maxWithdrawableAmount, collateralCustodyAccount.decimals);
1316
1334
  }
@@ -1998,8 +2016,8 @@ var PerpetualsClient = (function () {
1998
2016
  throw Error("incorrect markets");
1999
2017
  }
2000
2018
  var position = markets[index].getCollectivePosition();
2001
- var collectivePnl = _this.getPnlSync(position, tokenPrices[markets[index].targetCustodyId.toNumber()], tokenEmaPrices[markets[index].targetCustodyId.toNumber()], custodies[markets[index].targetCustodyId.toNumber()], tokenPrices[markets[index].collateralCustodyId.toNumber()], tokenEmaPrices[markets[index].collateralCustodyId.toNumber()], custodies[markets[index].collateralCustodyId.toNumber()], currentTime, custodies[markets[index].targetCustodyId.toNumber()].pricing.delaySeconds, poolConfig);
2002
- var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(tokenPrices[markets[index].collateralCustodyId.toNumber()], tokenEmaPrices[markets[index].collateralCustodyId.toNumber()], custodies[markets[index].collateralCustodyId.toNumber()]);
2019
+ var collectivePnl = _this.getPnlSync(position, tokenPrices[markets[index].targetCustodyUid], tokenEmaPrices[markets[index].targetCustodyUid], custodies[markets[index].targetCustodyUid], tokenPrices[markets[index].collateralCustodyUid], tokenEmaPrices[markets[index].collateralCustodyUid], custodies[markets[index].collateralCustodyUid], currentTime, custodies[markets[index].targetCustodyUid].pricing.delaySeconds, poolConfig);
2020
+ var collateralMinMaxPrice = _this.getMinAndMaxOraclePriceSync(tokenPrices[markets[index].collateralCustodyUid], tokenEmaPrices[markets[index].collateralCustodyUid], custodies[markets[index].collateralCustodyUid]);
2003
2021
  var collectiveCollateralUsd = collateralMinMaxPrice.min.getAssetAmountUsd(position.collateralAmount, position.collateralDecimals);
2004
2022
  var collectiveLossUsd = anchor_1.BN.min(collectivePnl.lossUsd, collectiveCollateralUsd);
2005
2023
  poolEquityUsd = (poolEquityUsd.add(collectiveLossUsd)).sub(collectivePnl.profitUsd);
@@ -6049,11 +6067,11 @@ var PerpetualsClient = (function () {
6049
6067
  });
6050
6068
  });
6051
6069
  };
6052
- this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, receiveCustodyId, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
6070
+ this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
6053
6071
  if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
6054
6072
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6055
6073
  return __awaiter(_this, void 0, void 0, function () {
6056
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_40;
6074
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_40;
6057
6075
  return __generator(this, function (_c) {
6058
6076
  switch (_c.label) {
6059
6077
  case 0:
@@ -6061,6 +6079,7 @@ var PerpetualsClient = (function () {
6061
6079
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
6062
6080
  reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
6063
6081
  collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
6082
+ receiveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
6064
6083
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
6065
6084
  return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey)];
6066
6085
  case 1:
@@ -6128,8 +6147,7 @@ var PerpetualsClient = (function () {
6128
6147
  reserveAmount: reserveAmount,
6129
6148
  sizeAmount: sizeAmount,
6130
6149
  stopLossPrice: stopLossPrice,
6131
- takeProfitPrice: takeProfitPrice,
6132
- receiveCustodyId: receiveCustodyId
6150
+ takeProfitPrice: takeProfitPrice
6133
6151
  })
6134
6152
  .accounts({
6135
6153
  owner: publicKey,
@@ -6145,6 +6163,7 @@ var PerpetualsClient = (function () {
6145
6163
  reserveCustody: reserveCustodyConfig.custodyAccount,
6146
6164
  reserveOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
6147
6165
  reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
6166
+ receiveCustody: receiveCustodyConfig.custodyAccount,
6148
6167
  systemProgram: web3_js_1.SystemProgram.programId,
6149
6168
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6150
6169
  eventAuthority: this.eventAuthority.publicKey,
@@ -6168,11 +6187,11 @@ var PerpetualsClient = (function () {
6168
6187
  });
6169
6188
  });
6170
6189
  };
6171
- this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, receiveCustodyId, poolConfig, createUserATA, ephemeralSignerPubkey) {
6190
+ this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
6172
6191
  if (createUserATA === void 0) { createUserATA = true; }
6173
6192
  if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
6174
6193
  return __awaiter(_this, void 0, void 0, function () {
6175
- var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_41;
6194
+ var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_41;
6176
6195
  return __generator(this, function (_b) {
6177
6196
  switch (_b.label) {
6178
6197
  case 0:
@@ -6180,6 +6199,7 @@ var PerpetualsClient = (function () {
6180
6199
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
6181
6200
  reserveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey); });
6182
6201
  collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
6202
+ receiveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
6183
6203
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
6184
6204
  preInstructions = [];
6185
6205
  instructions = [];
@@ -6230,12 +6250,12 @@ var PerpetualsClient = (function () {
6230
6250
  limitPrice: limitPrice,
6231
6251
  sizeAmount: sizeAmount,
6232
6252
  stopLossPrice: stopLossPrice,
6233
- takeProfitPrice: takeProfitPrice,
6234
- receiveCustodyId: receiveCustodyId
6253
+ takeProfitPrice: takeProfitPrice
6235
6254
  })
6236
6255
  .accounts({
6237
6256
  owner: publicKey,
6238
6257
  feePayer: publicKey,
6258
+ receivingAccount: reserveSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
6239
6259
  transferAuthority: poolConfig.transferAuthority,
6240
6260
  perpetuals: poolConfig.perpetuals,
6241
6261
  pool: poolConfig.poolAddress,
@@ -6247,7 +6267,7 @@ var PerpetualsClient = (function () {
6247
6267
  reserveCustody: reserveCustodyConfig.custodyAccount,
6248
6268
  reserveOracleAccount: this.useExtOracleAccount ? reserveCustodyConfig.extOracleAccount : reserveCustodyConfig.intOracleAccount,
6249
6269
  reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
6250
- receivingAccount: reserveSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userReceivingTokenAccount,
6270
+ receiveCustody: receiveCustodyConfig.custodyAccount,
6251
6271
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
6252
6272
  eventAuthority: this.eventAuthority.publicKey,
6253
6273
  program: this.programId,
@@ -6403,14 +6423,15 @@ var PerpetualsClient = (function () {
6403
6423
  });
6404
6424
  });
6405
6425
  };
6406
- this.placeTriggerOrder = function (targetSymbol, collateralSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, receiveCustodyId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6407
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_44;
6426
+ this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6427
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_44;
6408
6428
  return __generator(this, function (_a) {
6409
6429
  switch (_a.label) {
6410
6430
  case 0:
6411
6431
  publicKey = this.provider.wallet.publicKey;
6412
6432
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
6413
6433
  collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
6434
+ receivingCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
6414
6435
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
6415
6436
  preInstructions = [];
6416
6437
  instructions = [];
@@ -6425,8 +6446,7 @@ var PerpetualsClient = (function () {
6425
6446
  .placeTriggerOrder({
6426
6447
  triggerPrice: triggerPrice,
6427
6448
  deltaSizeAmount: deltaSizeAmount,
6428
- isStopLoss: isStopLoss,
6429
- receiveCustodyId: receiveCustodyId
6449
+ isStopLoss: isStopLoss
6430
6450
  })
6431
6451
  .accounts({
6432
6452
  owner: publicKey,
@@ -6440,6 +6460,7 @@ var PerpetualsClient = (function () {
6440
6460
  targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
6441
6461
  collateralCustody: collateralCustodyConfig.custodyAccount,
6442
6462
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
6463
+ receiveCustody: receivingCustodyConfig.custodyAccount,
6443
6464
  systemProgram: web3_js_1.SystemProgram.programId,
6444
6465
  eventAuthority: this.eventAuthority.publicKey,
6445
6466
  program: this.programId,
@@ -6461,14 +6482,15 @@ var PerpetualsClient = (function () {
6461
6482
  }
6462
6483
  });
6463
6484
  }); };
6464
- this.editTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6465
- var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_45;
6485
+ this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
6486
+ var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_45;
6466
6487
  return __generator(this, function (_a) {
6467
6488
  switch (_a.label) {
6468
6489
  case 0:
6469
6490
  publicKey = this.provider.wallet.publicKey;
6470
6491
  targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
6471
6492
  collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
6493
+ receivingCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
6472
6494
  marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
6473
6495
  preInstructions = [];
6474
6496
  instructions = [];
@@ -6497,6 +6519,7 @@ var PerpetualsClient = (function () {
6497
6519
  targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
6498
6520
  collateralCustody: collateralCustodyConfig.custodyAccount,
6499
6521
  collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
6522
+ receiveCustody: receivingCustodyConfig.custodyAccount,
6500
6523
  eventAuthority: this.eventAuthority.publicKey,
6501
6524
  program: this.programId,
6502
6525
  ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
@@ -22,6 +22,7 @@ export declare class PoolAccount implements Pool {
22
22
  lpMintBump: number;
23
23
  stakedLpVaultBump: number;
24
24
  vpVolumeFactor: number;
25
+ uniqueCustodyCount: number;
25
26
  padding: number[];
26
27
  stakingFeeBoostBps: BN[];
27
28
  compoundingMint: PublicKey;