@drift-labs/sdk 2.23.0 → 2.25.0-beta.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.
Files changed (124) hide show
  1. package/README.md +1 -1
  2. package/lib/accounts/fetch.d.ts +1 -1
  3. package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -1
  4. package/lib/accounts/pollingOracleAccountSubscriber.d.ts +1 -1
  5. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +1 -1
  6. package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
  7. package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +1 -1
  8. package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
  9. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -1
  10. package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -1
  11. package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +1 -1
  12. package/lib/addresses/pda.d.ts +1 -2
  13. package/lib/addresses/pda.js +1 -1
  14. package/lib/adminClient.d.ts +3 -3
  15. package/lib/adminClient.js +16 -4
  16. package/lib/constants/numericConstants.d.ts +59 -61
  17. package/lib/constants/perpMarkets.js +21 -1
  18. package/lib/constants/spotMarkets.d.ts +0 -1
  19. package/lib/dlob/DLOB.d.ts +0 -1
  20. package/lib/dlob/DLOBNode.d.ts +0 -1
  21. package/lib/dlob/DLOBOrders.d.ts +1 -1
  22. package/lib/dlob/DLOBOrders.js +1 -1
  23. package/lib/dlob/NodeList.d.ts +0 -1
  24. package/lib/driftClient.d.ts +58 -24
  25. package/lib/driftClient.js +152 -136
  26. package/lib/events/eventSubscriber.d.ts +1 -1
  27. package/lib/events/eventSubscriber.js +3 -2
  28. package/lib/events/fetchLogs.d.ts +1 -1
  29. package/lib/events/fetchLogs.js +3 -2
  30. package/lib/examples/loadDlob.js +1 -1
  31. package/lib/examples/makeTradeExample.js +1 -1
  32. package/lib/factory/bigNum.d.ts +8 -9
  33. package/lib/factory/bigNum.js +1 -1
  34. package/lib/factory/oracleClient.js +1 -1
  35. package/lib/idl/drift.json +216 -14
  36. package/lib/index.d.ts +1 -1
  37. package/lib/index.js +1 -1
  38. package/lib/math/amm.d.ts +2 -3
  39. package/lib/math/amm.js +1 -1
  40. package/lib/math/auction.d.ts +0 -1
  41. package/lib/math/conversion.d.ts +1 -2
  42. package/lib/math/funding.d.ts +1 -2
  43. package/lib/math/funding.js +1 -1
  44. package/lib/math/insurance.d.ts +1 -1
  45. package/lib/math/insurance.js +17 -1
  46. package/lib/math/margin.d.ts +1 -2
  47. package/lib/math/margin.js +1 -1
  48. package/lib/math/market.d.ts +1 -2
  49. package/lib/math/market.js +1 -1
  50. package/lib/math/oracles.d.ts +0 -1
  51. package/lib/math/oracles.js +2 -3
  52. package/lib/math/orders.d.ts +1 -2
  53. package/lib/math/orders.js +1 -1
  54. package/lib/math/position.d.ts +0 -1
  55. package/lib/math/repeg.d.ts +1 -2
  56. package/lib/math/repeg.js +1 -1
  57. package/lib/math/spotBalance.d.ts +1 -2
  58. package/lib/math/spotBalance.js +1 -1
  59. package/lib/math/spotMarket.d.ts +1 -2
  60. package/lib/math/spotMarket.js +1 -1
  61. package/lib/math/spotPosition.d.ts +1 -2
  62. package/lib/math/trade.d.ts +1 -2
  63. package/lib/math/trade.js +1 -1
  64. package/lib/math/utils.d.ts +0 -1
  65. package/lib/oracles/pythClient.d.ts +2 -3
  66. package/lib/oracles/pythClient.js +1 -1
  67. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  68. package/lib/oracles/types.d.ts +1 -2
  69. package/lib/orderParams.d.ts +1 -2
  70. package/lib/serum/serumSubscriber.d.ts +1 -2
  71. package/lib/serum/serumSubscriber.js +1 -1
  72. package/lib/tokenFaucet.d.ts +2 -3
  73. package/lib/tokenFaucet.js +2 -2
  74. package/lib/tx/retryTxSender.d.ts +1 -1
  75. package/lib/tx/types.d.ts +1 -1
  76. package/lib/types.d.ts +9 -3
  77. package/lib/types.js +2 -1
  78. package/lib/user.d.ts +0 -1
  79. package/package.json +2 -2
  80. package/src/accounts/fetch.ts +1 -1
  81. package/src/accounts/pollingDriftClientAccountSubscriber.ts +1 -1
  82. package/src/accounts/pollingOracleAccountSubscriber.ts +1 -1
  83. package/src/accounts/pollingTokenAccountSubscriber.ts +1 -1
  84. package/src/accounts/pollingUserAccountSubscriber.ts +1 -1
  85. package/src/accounts/pollingUserStatsAccountSubscriber.ts +1 -1
  86. package/src/accounts/webSocketAccountSubscriber.ts +1 -1
  87. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +1 -1
  88. package/src/accounts/webSocketUserAccountSubscriber.ts +1 -1
  89. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +1 -1
  90. package/src/addresses/pda.ts +2 -2
  91. package/src/adminClient.ts +30 -2
  92. package/src/constants/perpMarkets.ts +21 -1
  93. package/src/dlob/DLOBOrders.ts +2 -2
  94. package/src/driftClient.ts +266 -163
  95. package/src/events/eventSubscriber.ts +7 -3
  96. package/src/events/fetchLogs.ts +7 -3
  97. package/src/examples/loadDlob.ts +1 -1
  98. package/src/examples/makeTradeExample.ts +1 -1
  99. package/src/factory/bigNum.ts +1 -1
  100. package/src/factory/oracleClient.ts +1 -1
  101. package/src/idl/drift.json +216 -14
  102. package/src/index.ts +1 -1
  103. package/src/math/amm.ts +1 -1
  104. package/src/math/funding.ts +1 -1
  105. package/src/math/insurance.ts +29 -0
  106. package/src/math/margin.ts +1 -1
  107. package/src/math/market.ts +1 -1
  108. package/src/math/oracles.ts +2 -3
  109. package/src/math/orders.ts +1 -1
  110. package/src/math/repeg.ts +1 -1
  111. package/src/math/spotBalance.ts +1 -1
  112. package/src/math/spotMarket.ts +1 -1
  113. package/src/math/spotPosition.ts +1 -1
  114. package/src/math/trade.ts +1 -1
  115. package/src/oracles/pythClient.ts +1 -1
  116. package/src/oracles/quoteAssetOracleClient.ts +1 -1
  117. package/src/oracles/types.ts +1 -1
  118. package/src/orderParams.ts +1 -1
  119. package/src/serum/serumSubscriber.ts +1 -1
  120. package/src/tokenFaucet.ts +2 -2
  121. package/src/tx/retryTxSender.ts +1 -1
  122. package/src/tx/types.ts +1 -1
  123. package/src/types.ts +8 -1
  124. package/src/userMap/userStatsMap.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.23.0",
2
+ "version": "2.25.0-beta.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -428,6 +428,72 @@
428
428
  }
429
429
  ]
430
430
  },
431
+ {
432
+ "name": "modifyOrder",
433
+ "accounts": [
434
+ {
435
+ "name": "state",
436
+ "isMut": false,
437
+ "isSigner": false
438
+ },
439
+ {
440
+ "name": "user",
441
+ "isMut": true,
442
+ "isSigner": false
443
+ },
444
+ {
445
+ "name": "authority",
446
+ "isMut": false,
447
+ "isSigner": true
448
+ }
449
+ ],
450
+ "args": [
451
+ {
452
+ "name": "orderId",
453
+ "type": {
454
+ "option": "u32"
455
+ }
456
+ },
457
+ {
458
+ "name": "modifyOrderParams",
459
+ "type": {
460
+ "defined": "ModifyOrderParams"
461
+ }
462
+ }
463
+ ]
464
+ },
465
+ {
466
+ "name": "modifyOrderByUserId",
467
+ "accounts": [
468
+ {
469
+ "name": "state",
470
+ "isMut": false,
471
+ "isSigner": false
472
+ },
473
+ {
474
+ "name": "user",
475
+ "isMut": true,
476
+ "isSigner": false
477
+ },
478
+ {
479
+ "name": "authority",
480
+ "isMut": false,
481
+ "isSigner": true
482
+ }
483
+ ],
484
+ "args": [
485
+ {
486
+ "name": "userOrderId",
487
+ "type": "u8"
488
+ },
489
+ {
490
+ "name": "modifyOrderParams",
491
+ "type": {
492
+ "defined": "ModifyOrderParams"
493
+ }
494
+ }
495
+ ]
496
+ },
431
497
  {
432
498
  "name": "placeAndTakePerpOrder",
433
499
  "accounts": [
@@ -2283,6 +2349,10 @@
2283
2349
  }
2284
2350
  ],
2285
2351
  "args": [
2352
+ {
2353
+ "name": "marketIndex",
2354
+ "type": "u16"
2355
+ },
2286
2356
  {
2287
2357
  "name": "ammBaseAssetReserve",
2288
2358
  "type": "u128"
@@ -2332,6 +2402,32 @@
2332
2402
  }
2333
2403
  ]
2334
2404
  },
2405
+ {
2406
+ "name": "deleteInitializedPerpMarket",
2407
+ "accounts": [
2408
+ {
2409
+ "name": "admin",
2410
+ "isMut": true,
2411
+ "isSigner": true
2412
+ },
2413
+ {
2414
+ "name": "state",
2415
+ "isMut": true,
2416
+ "isSigner": false
2417
+ },
2418
+ {
2419
+ "name": "perpMarket",
2420
+ "isMut": true,
2421
+ "isSigner": false
2422
+ }
2423
+ ],
2424
+ "args": [
2425
+ {
2426
+ "name": "marketIndex",
2427
+ "type": "u16"
2428
+ }
2429
+ ]
2430
+ },
2335
2431
  {
2336
2432
  "name": "moveAmmPrice",
2337
2433
  "accounts": [
@@ -4852,6 +4948,98 @@
4852
4948
  ]
4853
4949
  }
4854
4950
  },
4951
+ {
4952
+ "name": "ModifyOrderParams",
4953
+ "type": {
4954
+ "kind": "struct",
4955
+ "fields": [
4956
+ {
4957
+ "name": "direction",
4958
+ "type": {
4959
+ "option": {
4960
+ "defined": "PositionDirection"
4961
+ }
4962
+ }
4963
+ },
4964
+ {
4965
+ "name": "baseAssetAmount",
4966
+ "type": {
4967
+ "option": "u64"
4968
+ }
4969
+ },
4970
+ {
4971
+ "name": "price",
4972
+ "type": {
4973
+ "option": "u64"
4974
+ }
4975
+ },
4976
+ {
4977
+ "name": "reduceOnly",
4978
+ "type": {
4979
+ "option": "bool"
4980
+ }
4981
+ },
4982
+ {
4983
+ "name": "postOnly",
4984
+ "type": {
4985
+ "option": {
4986
+ "defined": "PostOnlyParam"
4987
+ }
4988
+ }
4989
+ },
4990
+ {
4991
+ "name": "immediateOrCancel",
4992
+ "type": {
4993
+ "option": "bool"
4994
+ }
4995
+ },
4996
+ {
4997
+ "name": "maxTs",
4998
+ "type": {
4999
+ "option": "i64"
5000
+ }
5001
+ },
5002
+ {
5003
+ "name": "triggerPrice",
5004
+ "type": {
5005
+ "option": "u64"
5006
+ }
5007
+ },
5008
+ {
5009
+ "name": "triggerCondition",
5010
+ "type": {
5011
+ "option": {
5012
+ "defined": "OrderTriggerCondition"
5013
+ }
5014
+ }
5015
+ },
5016
+ {
5017
+ "name": "oraclePriceOffset",
5018
+ "type": {
5019
+ "option": "i32"
5020
+ }
5021
+ },
5022
+ {
5023
+ "name": "auctionDuration",
5024
+ "type": {
5025
+ "option": "u8"
5026
+ }
5027
+ },
5028
+ {
5029
+ "name": "auctionStartPrice",
5030
+ "type": {
5031
+ "option": "i64"
5032
+ }
5033
+ },
5034
+ {
5035
+ "name": "auctionEndPrice",
5036
+ "type": {
5037
+ "option": "i64"
5038
+ }
5039
+ }
5040
+ ]
5041
+ }
5042
+ },
4855
5043
  {
4856
5044
  "name": "LiquidatePerpRecord",
4857
5045
  "type": {
@@ -5127,7 +5315,7 @@
5127
5315
  "fields": [
5128
5316
  {
5129
5317
  "name": "revenueWithdrawSinceLastSettle",
5130
- "type": "u64"
5318
+ "type": "i64"
5131
5319
  },
5132
5320
  {
5133
5321
  "name": "maxRevenueWithdrawPerPeriod",
@@ -5981,31 +6169,35 @@
5981
6169
  }
5982
6170
  },
5983
6171
  {
5984
- "name": "PositionDirection",
6172
+ "name": "ModifyOrderId",
5985
6173
  "type": {
5986
6174
  "kind": "enum",
5987
6175
  "variants": [
5988
6176
  {
5989
- "name": "Long"
6177
+ "name": "UserOrderId",
6178
+ "fields": [
6179
+ "u8"
6180
+ ]
5990
6181
  },
5991
6182
  {
5992
- "name": "Short"
6183
+ "name": "OrderId",
6184
+ "fields": [
6185
+ "u32"
6186
+ ]
5993
6187
  }
5994
6188
  ]
5995
6189
  }
5996
6190
  },
5997
6191
  {
5998
- "name": "FulfillmentParams",
6192
+ "name": "PositionDirection",
5999
6193
  "type": {
6000
6194
  "kind": "enum",
6001
6195
  "variants": [
6002
6196
  {
6003
- "name": "SerumFulfillmentParams",
6004
- "fields": [
6005
- {
6006
- "defined": "SerumFulfillmentParams<'a,'b>"
6007
- }
6008
- ]
6197
+ "name": "Long"
6198
+ },
6199
+ {
6200
+ "name": "Short"
6009
6201
  }
6010
6202
  ]
6011
6203
  }
@@ -6019,7 +6211,7 @@
6019
6211
  "name": "SerumV3"
6020
6212
  },
6021
6213
  {
6022
- "name": "None"
6214
+ "name": "Match"
6023
6215
  }
6024
6216
  ]
6025
6217
  }
@@ -6380,7 +6572,7 @@
6380
6572
  "kind": "enum",
6381
6573
  "variants": [
6382
6574
  {
6383
- "name": "SerumV3"
6575
+ "name": "ExternalMarket"
6384
6576
  },
6385
6577
  {
6386
6578
  "name": "Match"
@@ -8826,6 +9018,16 @@
8826
9018
  "code": 6239,
8827
9019
  "name": "RevertFill",
8828
9020
  "msg": "RevertFill"
9021
+ },
9022
+ {
9023
+ "code": 6240,
9024
+ "name": "InvalidMarketAccountforDeletion",
9025
+ "msg": "Invalid MarketAccount for Deletion"
9026
+ },
9027
+ {
9028
+ "code": 6241,
9029
+ "name": "InvalidSpotFulfillmentParams",
9030
+ "msg": "Invalid Spot Fulfillment Params"
8829
9031
  }
8830
9032
  ]
8831
9033
  }
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import pyth from '@pythnetwork/client';
4
4
  export * from './tokenFaucet';
package/lib/index.js CHANGED
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.pyth = exports.PublicKey = exports.BN = void 0;
21
- const anchor_1 = require("@project-serum/anchor");
21
+ const anchor_1 = require("@coral-xyz/anchor");
22
22
  Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return anchor_1.BN; } });
23
23
  const web3_js_1 = require("@solana/web3.js");
24
24
  Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return web3_js_1.PublicKey; } });
package/lib/math/amm.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
@@ -87,7 +86,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
87
86
  * @param market
88
87
  * @returns cost : Precision PRICE_PRECISION
89
88
  */
90
- export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
89
+ export declare function calculateTerminalPrice(market: PerpMarketAccount): any;
91
90
  export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
92
91
  export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
93
92
  export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
package/lib/math/amm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.calculateSpread = exports.calculateSpreadBN = exports.calculateVolSpreadBN = exports.calculateMaxSpread = exports.calculateEffectiveLeverage = exports.calculateInventoryScale = exports.calculateMarketOpenBidAsk = exports.calculateAmmReservesAfterSwap = exports.calculatePrice = exports.calculateBidAskPrice = exports.calculateUpdatedAMMSpreadReserves = exports.calculateUpdatedAMM = exports.calculateNewAmm = exports.calculateOptimalPegAndBudget = exports.calculatePegFromTargetPrice = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const types_1 = require("../types");
7
7
  const assert_1 = require("../assert/assert");
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { Order } from '../types';
3
2
  import { BN } from '../.';
4
3
  export declare function isAuctionComplete(order: Order, slot: number): boolean;
@@ -1,2 +1 @@
1
- import { BN } from '../';
2
- export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
1
+ export declare const convertToNumber: (bigNumber: BN, precision?: BN) => any;
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { PerpMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateFundingPool = exports.calculateLongShortFundingRateAndLiveTwaps = exports.calculateLongShortFundingRate = exports.calculateEstimatedFundingRate = exports.calculateAllEstimatedFundingRate = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const types_1 = require("../types");
7
7
  const amm_1 = require("./amm");
@@ -1,4 +1,4 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../index';
3
2
  export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
4
3
  export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
4
+ export declare function unstakeSharesToAmountWithOpenRequest(nShares: BN, withdrawRequestShares: BN, withdrawRequestAmount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unstakeSharesToAmount = exports.stakeAmountToShares = void 0;
3
+ exports.unstakeSharesToAmountWithOpenRequest = exports.unstakeSharesToAmount = exports.stakeAmountToShares = void 0;
4
4
  const numericConstants_1 = require("../constants/numericConstants");
5
5
  const index_1 = require("../index");
6
6
  function stakeAmountToShares(amount, totalIfShares, insuranceFundVaultBalance) {
@@ -25,3 +25,19 @@ function unstakeSharesToAmount(nShares, totalIfShares, insuranceFundVaultBalance
25
25
  return amount;
26
26
  }
27
27
  exports.unstakeSharesToAmount = unstakeSharesToAmount;
28
+ function unstakeSharesToAmountWithOpenRequest(nShares, withdrawRequestShares, withdrawRequestAmount, totalIfShares, insuranceFundVaultBalance) {
29
+ let stakedAmount;
30
+ if (totalIfShares.gt(numericConstants_1.ZERO)) {
31
+ stakedAmount = index_1.BN.max(numericConstants_1.ZERO, nShares
32
+ .sub(withdrawRequestShares)
33
+ .mul(insuranceFundVaultBalance)
34
+ .div(totalIfShares));
35
+ }
36
+ else {
37
+ stakedAmount = numericConstants_1.ZERO;
38
+ }
39
+ const withdrawAmount = index_1.BN.min(withdrawRequestAmount, withdrawRequestShares.mul(insuranceFundVaultBalance).div(totalIfShares));
40
+ const amount = withdrawAmount.add(stakedAmount);
41
+ return amount;
42
+ }
43
+ exports.unstakeSharesToAmountWithOpenRequest = unstakeSharesToAmountWithOpenRequest;
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { PerpMarketAccount, PerpPosition } from '..';
5
4
  export declare function calculateSizePremiumLiabilityWeight(size: BN, // AMM_RESERVE_PRECISION
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateWorstCaseBaseAssetAmount = exports.calculateBaseAssetValueWithOracle = exports.calculateOraclePriceForPerpMargin = exports.calculateSizeDiscountAssetWeight = exports.calculateSizePremiumLiabilityWeight = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
- const anchor_1 = require("@project-serum/anchor");
6
+ const anchor_1 = require("@coral-xyz/anchor");
7
7
  const types_1 = require("../types");
8
8
  const assert_1 = require("../assert/assert");
9
9
  function calculateSizePremiumLiabilityWeight(size, // AMM_RESERVE_PRECISION
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { PerpMarketAccount, PositionDirection, MarginCategory, SpotMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  import { DLOB } from '../dlob/DLOB';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateAvailablePerpLiquidity = exports.calculateNetUserPnlImbalance = exports.calculateNetUserPnl = exports.calculateMarketMaxAvailableInsurance = exports.calculateMarketAvailablePNL = exports.calculateUnrealizedAssetWeight = exports.calculateMarketMarginRatio = exports.calculateOracleSpread = exports.calculateOracleReserveSpread = exports.calculateNewMarketAfterTrade = exports.calculateAskPrice = exports.calculateBidPrice = exports.calculateReservePrice = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const types_1 = require("../types");
6
6
  const amm_1 = require("./amm");
7
7
  const margin_1 = require("./margin");
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { AMM, OracleGuardRails } from '../types';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { BN, HistoricalOracleData, PerpMarketAccount } from '../index';
@@ -21,11 +21,10 @@ function isOracleValid(amm, oraclePriceData, oracleGuardRails, slot) {
21
21
  amm.historicalOracleData.lastOraclePriceTwap
22
22
  .div(index_1.BN.max(numericConstants_1.ONE, oraclePriceData.price))
23
23
  .gt(oracleGuardRails.validity.tooVolatileRatio);
24
- const isConfidenceTooLarge = new index_1.BN(amm.baseSpread)
25
- .add(index_1.BN.max(numericConstants_1.ONE, oraclePriceData.confidence))
24
+ const isConfidenceTooLarge = index_1.BN.max(numericConstants_1.ONE, oraclePriceData.confidence)
26
25
  .mul(numericConstants_1.BID_ASK_SPREAD_PRECISION)
27
26
  .div(oraclePriceData.price)
28
- .gt(new index_1.BN(amm.maxSpread));
27
+ .gt(oracleGuardRails.validity.confidenceIntervalMaxSize);
29
28
  const oracleIsStale = oraclePriceData.slot
30
29
  .sub(new index_1.BN(slot))
31
30
  .gt(oracleGuardRails.validity.slotsBeforeStaleForAmm);
@@ -1,7 +1,6 @@
1
- /// <reference types="bn.js" />
2
1
  import { User } from '../user';
3
2
  import { PerpMarketAccount, AMM, Order } from '../types';
4
- import { BN } from '@project-serum/anchor';
3
+ import { BN } from '@coral-xyz/anchor';
5
4
  import { OraclePriceData } from '../oracles/types';
6
5
  export declare function isOrderRiskIncreasing(user: User, order: Order): boolean;
7
6
  export declare function isOrderRiskIncreasingInSameDirection(user: User, order: Order): boolean;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
4
4
  const types_1 = require("../types");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
- const anchor_1 = require("@project-serum/anchor");
6
+ const anchor_1 = require("@coral-xyz/anchor");
7
7
  const auction_1 = require("./auction");
8
8
  const amm_1 = require("./amm");
9
9
  function isOrderRiskIncreasing(user, order) {
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN, SpotMarketAccount } from '../';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { PerpMarketAccount, PositionDirection, PerpPosition } from '../types';
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { AMM } from '../types';
4
3
  /**
5
4
  * Helper function calculating adjust k cost
package/lib/math/repeg.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateBudgetedPeg = exports.calculateBudgetedK = exports.calculateBudgetedKBN = exports.calculateRepegCost = exports.calculateAdjustKCost = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const assert_1 = require("../assert/assert");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  /**
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  import { SpotMarketAccount, SpotBalanceType, MarginCategory } from '../types';
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  export declare function getBalance(tokenAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
6
5
  export declare function getTokenAmount(balanceAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateWithdrawLimit = exports.calculateInterestAccumulated = exports.calculateBorrowRate = exports.calculateDepositRate = exports.calculateInterestRate = exports.calculateUtilization = exports.calculateLiabilityWeight = exports.calculateAssetWeight = exports.getTokenValue = exports.getStrictTokenValue = exports.getSignedTokenAmount = exports.getTokenAmount = exports.getBalance = void 0;
4
4
  const types_1 = require("../types");
5
- const anchor_1 = require("@project-serum/anchor");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  const margin_1 = require("./margin");
8
8
  const numericConstants_2 = require("../constants/numericConstants");
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { MarginCategory, SpotBalanceType, SpotMarketAccount } from '../types';
4
3
  export declare function castNumberToSpotPrecision(value: number, spotMarket: SpotMarketAccount): BN;
5
4
  export declare function calculateSpotMarketMarginRatio(market: SpotMarketAccount, marginCategory: MarginCategory, size: BN, balanceType: SpotBalanceType): number;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateSpotMarketMarginRatio = exports.castNumberToSpotPrecision = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const types_1 = require("../types");
6
6
  const spotBalance_1 = require("./spotBalance");
7
7
  const numericConstants_1 = require("../constants/numericConstants");
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  import { SpotMarketAccount, SpotPosition } from '../types';
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  export declare function isSpotPositionAvailable(position: SpotPosition): boolean;
6
5
  export declare function getWorstCaseTokenAmounts(spotPosition: SpotPosition, spotMarketAccount: SpotMarketAccount, oraclePriceData: OraclePriceData): [BN, BN];
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  import { PerpMarketAccount, PositionDirection, SpotMarketAccount } from '../types';
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { AssetType } from './amm';
5
4
  import { OraclePriceData } from '../oracles/types';
6
5
  import { DLOB } from '../dlob/DLOB';
package/lib/math/trade.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateEstimatedSpotEntryPrice = exports.calculateEstimatedPerpEntryPrice = exports.calculateTargetPriceTrade = exports.calculateTradeAcquiredAmounts = exports.calculateTradeSlippage = void 0;
4
4
  const types_1 = require("../types");
5
- const anchor_1 = require("@project-serum/anchor");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
6
  const assert_1 = require("../assert/assert");
7
7
  const numericConstants_1 = require("../constants/numericConstants");
8
8
  const market_1 = require("./market");
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../';
3
2
  export declare function clampBN(x: BN, min: BN, max: BN): BN;
4
3
  export declare const squareRootBN: (n: BN) => BN;
@@ -1,13 +1,12 @@
1
- /// <reference types="bn.js" />
2
1
  /// <reference types="node" />
3
2
  import { Connection, PublicKey } from '@solana/web3.js';
4
3
  import { OracleClient, OraclePriceData } from './types';
5
- import { BN } from '@project-serum/anchor';
4
+ import { BN } from '@coral-xyz/anchor';
6
5
  export declare class PythClient implements OracleClient {
7
6
  private connection;
8
7
  private multiple;
9
8
  private stableCoin;
10
- constructor(connection: Connection, multiple?: BN, stableCoin?: boolean);
9
+ constructor(connection: Connection, multiple?: any, stableCoin?: boolean);
11
10
  getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
12
11
  getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
13
12
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertPythPrice = exports.PythClient = void 0;
4
4
  const client_1 = require("@pythnetwork/client");
5
- const anchor_1 = require("@project-serum/anchor");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  class PythClient {
8
8
  constructor(connection, multiple = numericConstants_1.ONE, stableCoin = false) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QuoteAssetOracleClient = exports.QUOTE_ORACLE_PRICE_DATA = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  exports.QUOTE_ORACLE_PRICE_DATA = {
7
7
  price: numericConstants_1.PRICE_PRECISION,
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  /// <reference types="node" />
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { PublicKey } from '@solana/web3.js';
5
4
  import { OracleSource } from '../types';
6
5
  export type OraclePriceData = {