@drift-labs/sdk 2.24.0 → 2.25.0-beta.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.
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 +1 -2
  15. package/lib/adminClient.js +2 -2
  16. package/lib/constants/numericConstants.d.ts +59 -61
  17. package/lib/constants/perpMarkets.js +10 -0
  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 +38 -23
  25. package/lib/driftClient.js +85 -131
  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 +181 -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 +8 -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 +2 -2
  92. package/src/constants/perpMarkets.ts +10 -0
  93. package/src/dlob/DLOBOrders.ts +2 -2
  94. package/src/driftClient.ts +136 -153
  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 +181 -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 +6 -1
  124. package/src/userMap/userStatsMap.ts +1 -1
@@ -4,7 +4,7 @@ import {
4
4
  Idl,
5
5
  Program,
6
6
  ProgramAccount,
7
- } from '@project-serum/anchor';
7
+ } from '@coral-xyz/anchor';
8
8
  import bs58 from 'bs58';
9
9
  import {
10
10
  ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -33,13 +33,12 @@ import {
33
33
  isVariant,
34
34
  ReferrerNameAccount,
35
35
  OrderTriggerCondition,
36
- isOneOfVariant,
37
- PostOnlyParams,
38
36
  SpotBalanceType,
39
37
  PerpMarketExtendedInfo,
40
38
  UserStatsAccount,
39
+ ModifyOrderParams,
41
40
  } from './types';
42
- import * as anchor from '@project-serum/anchor';
41
+ import * as anchor from '@coral-xyz/anchor';
43
42
  import driftIDL from './idl/drift.json';
44
43
 
45
44
  import {
@@ -3390,221 +3389,205 @@ export class DriftClient {
3390
3389
  /**
3391
3390
  * Modifies an open order (spot or perp) by closing it and replacing it with a new order.
3392
3391
  * @param orderId: The open order to modify
3393
- * @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
3394
- * @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
3395
- * @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
3396
- * @param newOrderType: Optional - New order type for the order.
3392
+ * @param newDirection: The new direction for the order
3393
+ * @param newBaseAmount: The new base amount for the order
3394
+ * @param newLimitPice: The new limit price for the order
3395
+ * @param newOraclePriceOffset: The new oracle price offset for the order
3397
3396
  * @param newTriggerPrice: Optional - Thew new trigger price for the order.
3398
- * @param isSpot: Optional - Set to true if the order is a spot order
3399
- * @param auctionDuration: Only required if order type changed to market from something else
3400
- * @param auctionStartPrice: Only required if order type changed to market from something else
3401
- * @param auctionEndPrice: Only required if order type changed to market from something else
3397
+ * @param auctionDuration:
3398
+ * @param auctionStartPrice:
3399
+ * @param auctionEndPrice:
3400
+ * @param reduceOnly:
3401
+ * @param postOnly:
3402
+ * @param immediateOrCancel:
3403
+ * @param maxTs:
3402
3404
  * @returns
3403
3405
  */
3404
3406
  public async modifyOrder({
3405
3407
  orderId,
3408
+ newDirection,
3406
3409
  newBaseAmount,
3407
3410
  newLimitPrice,
3408
3411
  newOraclePriceOffset,
3409
- newOrderType,
3410
3412
  newTriggerPrice,
3411
3413
  newTriggerCondition,
3412
- isSpot,
3413
3414
  auctionDuration,
3414
3415
  auctionStartPrice,
3415
3416
  auctionEndPrice,
3417
+ reduceOnly,
3418
+ postOnly,
3419
+ immediateOrCancel,
3420
+ maxTs,
3421
+ txParams,
3416
3422
  }: {
3417
3423
  orderId: number;
3424
+ newDirection?: PositionDirection;
3418
3425
  newBaseAmount?: BN;
3419
3426
  newLimitPrice?: BN;
3420
3427
  newOraclePriceOffset?: number;
3421
- newOrderType?: OrderType;
3422
3428
  newTriggerPrice?: BN;
3423
3429
  newTriggerCondition?: OrderTriggerCondition;
3424
- isSpot?: boolean;
3425
3430
  auctionDuration?: number;
3426
3431
  auctionStartPrice?: BN;
3427
3432
  auctionEndPrice?: BN;
3433
+ reduceOnly?: boolean;
3434
+ postOnly?: boolean;
3435
+ immediateOrCancel?: boolean;
3436
+ maxTs?: BN;
3437
+ txParams?: TxParams;
3428
3438
  }): Promise<TransactionSignature> {
3429
- if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
3430
- throw new Error(
3431
- `Must provide newBaseAmount or newLimitPrice or newOraclePriceOffset to modify order`
3432
- );
3433
- }
3434
-
3435
- const openOrder = this.getUser().getOrder(orderId);
3436
- if (!openOrder) {
3437
- throw new Error(`No open order with id ${orderId.toString()}`);
3438
- }
3439
- const cancelOrderIx = await this.getCancelOrderIx(orderId);
3440
-
3441
- const orderTypeHasTrigger = newOrderType
3442
- ? isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
3443
- : isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
3444
- const orderTypeHasLimitPrice = newOrderType
3445
- ? isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
3446
- : isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
3447
-
3448
- const newOrderParams: OptionalOrderParams = {
3449
- orderType: newOrderType || openOrder.orderType,
3450
- marketType: openOrder.marketType,
3451
- direction: openOrder.direction,
3452
- baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
3453
- price: orderTypeHasLimitPrice
3454
- ? newLimitPrice || openOrder.price
3455
- : undefined,
3456
- marketIndex: openOrder.marketIndex,
3457
- reduceOnly: openOrder.reduceOnly,
3458
- postOnly: openOrder.postOnly
3459
- ? PostOnlyParams.MUST_POST_ONLY
3460
- : PostOnlyParams.NONE,
3461
- immediateOrCancel: openOrder.immediateOrCancel,
3462
- triggerPrice: orderTypeHasTrigger
3463
- ? newTriggerPrice || openOrder.triggerPrice
3464
- : undefined,
3465
- triggerCondition: orderTypeHasTrigger
3466
- ? newTriggerCondition || openOrder.triggerCondition
3467
- : undefined,
3468
- oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
3469
- auctionDuration: auctionDuration ?? openOrder.auctionDuration,
3470
- maxTs: openOrder.maxTs,
3471
- auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
3472
- auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
3473
- userOrderId: openOrder.userOrderId,
3439
+ const orderParams: ModifyOrderParams = {
3440
+ baseAssetAmount: newBaseAmount || null,
3441
+ direction: newDirection || null,
3442
+ price: newLimitPrice || null,
3443
+ oraclePriceOffset: newOraclePriceOffset || null,
3444
+ triggerPrice: newTriggerPrice || null,
3445
+ triggerCondition: newTriggerCondition || null,
3446
+ auctionDuration: auctionDuration || null,
3447
+ auctionStartPrice: auctionStartPrice || null,
3448
+ auctionEndPrice: auctionEndPrice || null,
3449
+ reduceOnly: reduceOnly || null,
3450
+ postOnly: postOnly || null,
3451
+ immediateOrCancel: immediateOrCancel || null,
3452
+ maxTs: maxTs || null,
3474
3453
  };
3475
- const placeOrderIx = isSpot
3476
- ? await this.getPlaceSpotOrderIx(newOrderParams)
3477
- : await this.getPlacePerpOrderIx(newOrderParams);
3478
3454
 
3479
- const tx = new Transaction();
3480
- tx.add(
3481
- ComputeBudgetProgram.setComputeUnitLimit({
3482
- units: 1_000_000,
3483
- })
3455
+ const { txSig } = await this.sendTransaction(
3456
+ wrapInTx(
3457
+ await this.getModifyOrderIx(orderId, orderParams),
3458
+ txParams?.computeUnits,
3459
+ txParams?.computeUnitsPrice
3460
+ ),
3461
+ [],
3462
+ this.opts
3484
3463
  );
3485
- tx.add(cancelOrderIx);
3486
- tx.add(placeOrderIx);
3487
- const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
3464
+ return txSig;
3465
+ }
3488
3466
 
3489
- if (isSpot) {
3490
- this.spotMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
3491
- this.spotMarketLastSlotCache.set(QUOTE_SPOT_MARKET_INDEX, slot);
3492
- } else {
3493
- this.perpMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
3494
- }
3467
+ public async getModifyOrderIx(
3468
+ orderId: number,
3469
+ orderParams: ModifyOrderParams
3470
+ ): Promise<TransactionInstruction> {
3471
+ const userAccountPublicKey = await this.getUserAccountPublicKey();
3495
3472
 
3496
- return txSig;
3473
+ const remainingAccounts = this.getRemainingAccounts({
3474
+ userAccounts: [this.getUserAccount()],
3475
+ useMarketLastSlotCache: true,
3476
+ });
3477
+
3478
+ return await this.program.instruction.modifyOrder(orderId, orderParams, {
3479
+ accounts: {
3480
+ state: await this.getStatePublicKey(),
3481
+ user: userAccountPublicKey,
3482
+ userStats: this.getUserStatsAccountPublicKey(),
3483
+ authority: this.wallet.publicKey,
3484
+ },
3485
+ remainingAccounts,
3486
+ });
3497
3487
  }
3498
3488
 
3499
3489
  /**
3500
3490
  * Modifies an open order by closing it and replacing it with a new order.
3501
3491
  * @param userOrderId: The open order to modify
3502
- * @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
3503
- * @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
3504
- * @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
3505
- * @param newOrderType: Optional - New order type for the order.
3492
+ * @param newDirection: The new direction for the order
3493
+ * @param newBaseAmount: The new base amount for the order
3494
+ * @param newLimitPice: The new limit price for the order
3495
+ * @param newOraclePriceOffset: The new oracle price offset for the order
3506
3496
  * @param newTriggerPrice: Optional - Thew new trigger price for the order.
3507
- * @param isSpot: Set to true if the order is a spot order
3508
3497
  * @param auctionDuration: Only required if order type changed to market from something else
3509
3498
  * @param auctionStartPrice: Only required if order type changed to market from something else
3510
3499
  * @param auctionEndPrice: Only required if order type changed to market from something else
3500
+ * @param reduceOnly:
3501
+ * @param postOnly:
3502
+ * @param immediateOrCancel:
3503
+ * @param maxTs:
3511
3504
  * @returns
3512
3505
  */
3513
3506
  public async modifyOrderByUserOrderId({
3514
3507
  userOrderId,
3508
+ newDirection,
3515
3509
  newBaseAmount,
3516
3510
  newLimitPrice,
3517
3511
  newOraclePriceOffset,
3518
- newOrderType,
3519
3512
  newTriggerPrice,
3520
3513
  newTriggerCondition,
3521
- isSpot,
3522
3514
  auctionDuration,
3523
3515
  auctionStartPrice,
3524
3516
  auctionEndPrice,
3517
+ reduceOnly,
3518
+ postOnly,
3519
+ immediateOrCancel,
3520
+ maxTs,
3521
+ txParams,
3525
3522
  }: {
3526
3523
  userOrderId: number;
3524
+ newDirection?: PositionDirection;
3527
3525
  newBaseAmount?: BN;
3528
3526
  newLimitPrice?: BN;
3529
3527
  newOraclePriceOffset?: number;
3530
- newOrderType?: OrderType;
3531
3528
  newTriggerPrice?: BN;
3532
3529
  newTriggerCondition?: OrderTriggerCondition;
3533
- isSpot?: boolean;
3534
3530
  auctionDuration?: number;
3535
3531
  auctionStartPrice?: BN;
3536
3532
  auctionEndPrice?: BN;
3533
+ reduceOnly?: boolean;
3534
+ postOnly?: boolean;
3535
+ immediateOrCancel?: boolean;
3536
+ maxTs?: BN;
3537
+ txParams?: TxParams;
3537
3538
  }): Promise<TransactionSignature> {
3538
- if (!newBaseAmount && !newLimitPrice && !newOraclePriceOffset) {
3539
- throw new Error(
3540
- `Must provide newBaseAmount or newLimitPrice or newOraclePriceOffset to modify order`
3541
- );
3542
- }
3543
-
3544
- const openOrder = this.getUser().getOrderByUserOrderId(userOrderId);
3545
- if (!openOrder) {
3546
- throw new Error(
3547
- `No open order with user order id ${userOrderId.toString()}`
3548
- );
3549
- }
3550
- const cancelOrderIx = await this.getCancelOrderByUserIdIx(userOrderId);
3551
-
3552
- const orderTypeHasTrigger = newOrderType
3553
- ? isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
3554
- : isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
3555
- const orderTypeHasLimitPrice = newOrderType
3556
- ? isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
3557
- : isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
3558
-
3559
- const newOrderParams: OptionalOrderParams = {
3560
- orderType: newOrderType || openOrder.orderType,
3561
- marketType: openOrder.marketType,
3562
- direction: openOrder.direction,
3563
- baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
3564
- price: orderTypeHasLimitPrice
3565
- ? newLimitPrice || openOrder.price
3566
- : undefined,
3567
- marketIndex: openOrder.marketIndex,
3568
- reduceOnly: openOrder.reduceOnly,
3569
- postOnly: openOrder.postOnly
3570
- ? PostOnlyParams.MUST_POST_ONLY
3571
- : PostOnlyParams.NONE,
3572
- immediateOrCancel: openOrder.immediateOrCancel,
3573
- triggerPrice: orderTypeHasTrigger
3574
- ? newTriggerPrice || openOrder.triggerPrice
3575
- : undefined,
3576
- triggerCondition: orderTypeHasTrigger
3577
- ? newTriggerCondition || openOrder.triggerCondition
3578
- : undefined,
3579
- oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
3580
- auctionDuration: auctionDuration || openOrder.auctionDuration,
3581
- maxTs: openOrder.maxTs,
3582
- auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
3583
- auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
3584
- userOrderId: openOrder.userOrderId,
3539
+ const orderParams: ModifyOrderParams = {
3540
+ baseAssetAmount: newBaseAmount || null,
3541
+ direction: newDirection || null,
3542
+ price: newLimitPrice || null,
3543
+ oraclePriceOffset: newOraclePriceOffset || null,
3544
+ triggerPrice: newTriggerPrice || null,
3545
+ triggerCondition: newTriggerCondition || null,
3546
+ auctionDuration: auctionDuration || null,
3547
+ auctionStartPrice: auctionStartPrice || null,
3548
+ auctionEndPrice: auctionEndPrice || null,
3549
+ reduceOnly: reduceOnly || null,
3550
+ postOnly: postOnly || null,
3551
+ immediateOrCancel: immediateOrCancel || null,
3552
+ maxTs: maxTs || null,
3585
3553
  };
3586
- const placeOrderIx = isSpot
3587
- ? await this.getPlaceSpotOrderIx(newOrderParams)
3588
- : await this.getPlacePerpOrderIx(newOrderParams);
3589
3554
 
3590
- const tx = new Transaction();
3591
- tx.add(
3592
- ComputeBudgetProgram.setComputeUnitLimit({
3593
- units: 1_000_000,
3594
- })
3555
+ const { txSig } = await this.sendTransaction(
3556
+ wrapInTx(
3557
+ await this.getModifyOrderByUserIdIx(userOrderId, orderParams),
3558
+ txParams?.computeUnits,
3559
+ txParams?.computeUnitsPrice
3560
+ ),
3561
+ [],
3562
+ this.opts
3595
3563
  );
3596
- tx.add(cancelOrderIx);
3597
- tx.add(placeOrderIx);
3598
- const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
3564
+ return txSig;
3565
+ }
3599
3566
 
3600
- if (isSpot) {
3601
- this.spotMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
3602
- this.spotMarketLastSlotCache.set(QUOTE_SPOT_MARKET_INDEX, slot);
3603
- } else {
3604
- this.perpMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
3605
- }
3567
+ public async getModifyOrderByUserIdIx(
3568
+ userOrderId: number,
3569
+ orderParams: ModifyOrderParams
3570
+ ): Promise<TransactionInstruction> {
3571
+ const userAccountPublicKey = await this.getUserAccountPublicKey();
3606
3572
 
3607
- return txSig;
3573
+ const remainingAccounts = this.getRemainingAccounts({
3574
+ userAccounts: [this.getUserAccount()],
3575
+ useMarketLastSlotCache: true,
3576
+ });
3577
+
3578
+ return await this.program.instruction.modifyOrderByUserId(
3579
+ userOrderId,
3580
+ orderParams,
3581
+ {
3582
+ accounts: {
3583
+ state: await this.getStatePublicKey(),
3584
+ user: userAccountPublicKey,
3585
+ userStats: this.getUserStatsAccountPublicKey(),
3586
+ authority: this.wallet.publicKey,
3587
+ },
3588
+ remainingAccounts,
3589
+ }
3590
+ );
3608
3591
  }
3609
3592
 
3610
3593
  public async settlePNLs(
@@ -1,5 +1,5 @@
1
1
  import { Connection, TransactionSignature } from '@solana/web3.js';
2
- import { Program } from '@project-serum/anchor';
2
+ import { Program } from '@coral-xyz/anchor';
3
3
  import {
4
4
  DefaultEventSubscriptionOptions,
5
5
  EventSubscriptionOptions,
@@ -164,7 +164,11 @@ export class EventSubscriber {
164
164
  ): WrappedEvents {
165
165
  const records = [];
166
166
  // @ts-ignore
167
- this.program._events._eventParser.parseLogs(logs, (event) => {
167
+ const eventGenerator = this.program._events._eventParser.parseLogs(
168
+ logs,
169
+ false
170
+ );
171
+ for (const event of eventGenerator) {
168
172
  const expectRecordType = this.eventListMap.has(event.name);
169
173
  if (expectRecordType) {
170
174
  event.data.txSig = txSig;
@@ -172,7 +176,7 @@ export class EventSubscriber {
172
176
  event.data.eventType = event.name;
173
177
  records.push(event.data);
174
178
  }
175
- });
179
+ }
176
180
  return records;
177
181
  }
178
182
 
@@ -1,4 +1,4 @@
1
- import { Program } from '@project-serum/anchor';
1
+ import { Program } from '@coral-xyz/anchor';
2
2
  import {
3
3
  Connection,
4
4
  Finality,
@@ -120,12 +120,16 @@ export class LogParser {
120
120
  public parseEventsFromLogs(event: Log): WrappedEvents {
121
121
  const records: WrappedEvents = [];
122
122
  // @ts-ignore
123
- this.program._events._eventParser.parseLogs(event.logs, (eventLog) => {
123
+ const eventGenerator = this.program._events._eventParser.parseLogs(
124
+ event.logs,
125
+ false
126
+ );
127
+ for (const eventLog of eventGenerator) {
124
128
  eventLog.data.txSig = event.txSig;
125
129
  eventLog.data.slot = event.slot;
126
130
  eventLog.data.eventType = eventLog.name;
127
131
  records.push(eventLog.data);
128
- });
132
+ }
129
133
  return records;
130
134
  }
131
135
  }
@@ -1,4 +1,4 @@
1
- import { AnchorProvider } from '@project-serum/anchor';
1
+ import { AnchorProvider } from '@coral-xyz/anchor';
2
2
  import { DLOB, UserMap, Wallet } from '..';
3
3
  import { Connection, Keypair, PublicKey } from '@solana/web3.js';
4
4
  import {
@@ -1,4 +1,4 @@
1
- import { AnchorProvider, BN } from '@project-serum/anchor';
1
+ import { AnchorProvider, BN } from '@coral-xyz/anchor';
2
2
  import {
3
3
  BASE_PRECISION,
4
4
  calculateBidAskPrice,
@@ -1,4 +1,4 @@
1
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
2
2
  import { assert } from '../assert/assert';
3
3
  import { ZERO } from './../constants/numericConstants';
4
4
 
@@ -4,7 +4,7 @@ import { OracleClient } from '../oracles/types';
4
4
  import { PythClient } from '../oracles/pythClient';
5
5
  // import { SwitchboardClient } from '../oracles/switchboardClient';
6
6
  import { QuoteAssetOracleClient } from '../oracles/quoteAssetOracleClient';
7
- import { BN } from '@project-serum/anchor';
7
+ import { BN } from '@coral-xyz/anchor';
8
8
 
9
9
  export function getOracleClient(
10
10
  oracleSource: OracleSource,