@drift-labs/sdk 0.2.0-master.2 → 0.2.0-master.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
- /// <reference types="node" />
4
3
  import { BankAccount, MarketAccount, OracleSource, StateAccount, UserAccount } from '../types';
5
4
  import StrictEventEmitter from 'strict-event-emitter-types';
6
5
  import { EventEmitter } from 'events';
package/lib/admin.d.ts CHANGED
@@ -5,7 +5,7 @@ import { BN } from '@project-serum/anchor';
5
5
  import { ClearingHouse } from './clearingHouse';
6
6
  export declare class Admin extends ClearingHouse {
7
7
  initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[TransactionSignature]>;
8
- initializeBank(mint: PublicKey, optimalUtilization: BN, optimalRate: BN, maxRate: BN, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: BN, maintenanceAssetWeight: BN, initialLiabilityWeight: BN, maintenanceLiabilityWeight: BN): Promise<TransactionSignature>;
8
+ initializeBank(mint: PublicKey, optimalUtilization: BN, optimalRate: BN, maxRate: BN, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: BN, maintenanceAssetWeight: BN, initialLiabilityWeight: BN, maintenanceLiabilityWeight: BN, imfFactor?: BN): Promise<TransactionSignature>;
9
9
  initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioPartial?: number, marginRatioMaintenance?: number): Promise<TransactionSignature>;
10
10
  moveAmmPrice(baseAssetReserve: BN, quoteAssetReserve: BN, marketIndex: BN): Promise<TransactionSignature>;
11
11
  updateK(sqrtK: BN, marketIndex: BN): Promise<TransactionSignature>;
@@ -14,7 +14,7 @@ export declare class Admin extends ClearingHouse {
14
14
  updateAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
15
15
  resetAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
16
16
  withdrawFromInsuranceVault(amount: BN, recipient: PublicKey): Promise<TransactionSignature>;
17
- withdrawFees(marketIndex: BN, amount: BN, recipient: PublicKey): Promise<TransactionSignature>;
17
+ withdrawFromMarketToInsuranceVault(marketIndex: BN, amount: BN, recipient: PublicKey): Promise<TransactionSignature>;
18
18
  withdrawFromInsuranceVaultToMarket(marketIndex: BN, amount: BN): Promise<TransactionSignature>;
19
19
  updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
20
20
  updateCurveUpdateIntensity(marketIndex: BN, curveUpdateIntensity: number): Promise<TransactionSignature>;
@@ -38,5 +38,7 @@ export declare class Admin extends ClearingHouse {
38
38
  updateFundingPaused(fundingPaused: boolean): Promise<TransactionSignature>;
39
39
  updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
40
40
  disableAdminControlsPrices(): Promise<TransactionSignature>;
41
- updateOrderAuctionTime(time: BN | number): Promise<TransactionSignature>;
41
+ updateAuctionDuration(minDuration: BN | number, maxDuration: BN | number): Promise<TransactionSignature>;
42
+ updateMaxBaseAssetAmountRatio(marketIndex: BN, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
43
+ updateMaxSlippageRatio(marketIndex: BN, maxSlippageRatio: number): Promise<TransactionSignature>;
42
44
  }
package/lib/admin.js CHANGED
@@ -58,12 +58,12 @@ class Admin extends clearingHouse_1.ClearingHouse {
58
58
  const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
59
59
  return [initializeTxSig];
60
60
  }
61
- async initializeBank(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight) {
61
+ async initializeBank(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0)) {
62
62
  const bankIndex = this.getStateAccount().numberOfBanks;
63
63
  const bank = await (0, pda_1.getBankPublicKey)(this.program.programId, bankIndex);
64
64
  const bankVault = await (0, pda_1.getBankVaultPublicKey)(this.program.programId, bankIndex);
65
65
  const bankVaultAuthority = await (0, pda_1.getBankVaultAuthorityPublicKey)(this.program.programId, bankIndex);
66
- const initializeTx = await this.program.transaction.initializeBank(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, {
66
+ const initializeTx = await this.program.transaction.initializeBank(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, {
67
67
  accounts: {
68
68
  admin: this.wallet.publicKey,
69
69
  state: await this.getStatePublicKey(),
@@ -177,10 +177,12 @@ class Admin extends clearingHouse_1.ClearingHouse {
177
177
  }
178
178
  async withdrawFromInsuranceVault(amount, recipient) {
179
179
  const state = await this.getStateAccount();
180
+ const bank = this.getQuoteAssetBankAccount();
180
181
  return await this.program.rpc.withdrawFromInsuranceVault(amount, {
181
182
  accounts: {
182
183
  admin: this.wallet.publicKey,
183
184
  state: await this.getStatePublicKey(),
185
+ bank: bank.pubkey,
184
186
  insuranceVault: state.insuranceVault,
185
187
  insuranceVaultAuthority: state.insuranceVaultAuthority,
186
188
  recipient: recipient,
@@ -188,10 +190,10 @@ class Admin extends clearingHouse_1.ClearingHouse {
188
190
  },
189
191
  });
190
192
  }
191
- async withdrawFees(marketIndex, amount, recipient) {
193
+ async withdrawFromMarketToInsuranceVault(marketIndex, amount, recipient) {
192
194
  const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
193
195
  const bank = this.getQuoteAssetBankAccount();
194
- return await this.program.rpc.withdrawFees(amount, {
196
+ return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
195
197
  accounts: {
196
198
  admin: this.wallet.publicKey,
197
199
  state: await this.getStatePublicKey(),
@@ -206,6 +208,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
206
208
  }
207
209
  async withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
208
210
  const state = await this.getStateAccount();
211
+ const bank = this.getQuoteAssetBankAccount();
209
212
  return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
210
213
  accounts: {
211
214
  admin: this.wallet.publicKey,
@@ -213,7 +216,9 @@ class Admin extends clearingHouse_1.ClearingHouse {
213
216
  market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
214
217
  insuranceVault: state.insuranceVault,
215
218
  insuranceVaultAuthority: state.insuranceVaultAuthority,
216
- bankVault: this.getQuoteAssetBankAccount().vault,
219
+ bank: bank.pubkey,
220
+ bankVault: bank.vault,
221
+ bankVaultAuthority: bank.vaultAuthority,
217
222
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
218
223
  },
219
224
  });
@@ -403,11 +408,29 @@ class Admin extends clearingHouse_1.ClearingHouse {
403
408
  },
404
409
  });
405
410
  }
406
- async updateOrderAuctionTime(time) {
407
- return await this.program.rpc.updateOrderAuctionTime(typeof time === 'number' ? time : time.toNumber, {
411
+ async updateAuctionDuration(minDuration, maxDuration) {
412
+ return await this.program.rpc.updateAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(), {
413
+ accounts: {
414
+ admin: this.wallet.publicKey,
415
+ state: await this.getStatePublicKey(),
416
+ },
417
+ });
418
+ }
419
+ async updateMaxBaseAssetAmountRatio(marketIndex, maxBaseAssetAmountRatio) {
420
+ return await this.program.rpc.updateMaxBaseAssetAmountRatio(maxBaseAssetAmountRatio, {
421
+ accounts: {
422
+ admin: this.wallet.publicKey,
423
+ state: await this.getStatePublicKey(),
424
+ market: this.getMarketAccount(marketIndex).pubkey,
425
+ },
426
+ });
427
+ }
428
+ async updateMaxSlippageRatio(marketIndex, maxSlippageRatio) {
429
+ return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
408
430
  accounts: {
409
431
  admin: this.wallet.publicKey,
410
432
  state: await this.getStatePublicKey(),
433
+ market: this.getMarketAccount(marketIndex).pubkey,
411
434
  },
412
435
  });
413
436
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
3
  import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
- import { StateAccount, IWallet, PositionDirection, UserAccount, MarketAccount, OrderParams, Order, BankAccount, UserBankBalance, MakerInfo } from './types';
4
+ import { StateAccount, IWallet, PositionDirection, UserAccount, MarketAccount, OrderParams, Order, BankAccount, UserBankBalance, MakerInfo, TakerInfo, OptionalOrderParams } from './types';
5
5
  import { Connection, PublicKey, TransactionSignature, ConfirmOptions, TransactionInstruction, AccountMeta } from '@solana/web3.js';
6
6
  import { MockUSDCFaucet } from './mockUSDCFaucet';
7
7
  import { EventEmitter } from 'events';
@@ -95,26 +95,23 @@ export declare class ClearingHouse {
95
95
  updateBankCumulativeInterest(bankIndex: BN): Promise<TransactionSignature>;
96
96
  updateBankCumulativeInterestIx(bankIndex: BN): Promise<TransactionInstruction>;
97
97
  openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN): Promise<TransactionSignature>;
98
- placeOrder(orderParams: OrderParams): Promise<TransactionSignature>;
99
- getPlaceOrderIx(orderParams: OrderParams): Promise<TransactionInstruction>;
100
- expireOrders(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
101
- getExpireOrdersIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
98
+ placeOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
99
+ getOrderParams(optionalOrderParams: OptionalOrderParams): OrderParams;
100
+ getPlaceOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
102
101
  updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
103
102
  getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
104
103
  cancelOrder(orderId?: BN): Promise<TransactionSignature>;
105
104
  getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
106
105
  cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
107
106
  getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
108
- cancelAllOrders(bestEffort?: boolean): Promise<TransactionSignature>;
109
- getCancelAllOrdersIx(bestEffort?: boolean): Promise<TransactionInstruction>;
110
- cancelOrdersByMarketAndSide(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
111
- getCancelOrdersByMarketAndSideIx(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
112
107
  fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
113
108
  getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
114
109
  triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
115
110
  getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
116
- placeAndTake(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
117
- getPlaceAndTakeIx(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
111
+ placeAndTake(orderParams: OptionalOrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
112
+ getPlaceAndTakeIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
113
+ placeAndMake(orderParams: OptionalOrderParams, takerInfo: TakerInfo): Promise<TransactionSignature>;
114
+ getPlaceAndMakeIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo): Promise<TransactionInstruction>;
118
115
  /**
119
116
  * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
120
117
  * @param marketIndex
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ClearingHouse = void 0;
30
30
  const anchor_1 = require("@project-serum/anchor");
31
31
  const spl_token_1 = require("@solana/spl-token");
32
+ const types_1 = require("./types");
32
33
  const anchor = __importStar(require("@project-serum/anchor"));
33
34
  const clearing_house_json_1 = __importDefault(require("./idl/clearing_house.json"));
34
35
  const web3_js_1 = require("@solana/web3.js");
@@ -42,7 +43,6 @@ const pollingClearingHouseAccountSubscriber_1 = require("./accounts/pollingClear
42
43
  const webSocketClearingHouseAccountSubscriber_1 = require("./accounts/webSocketClearingHouseAccountSubscriber");
43
44
  const retryTxSender_1 = require("./tx/retryTxSender");
44
45
  const clearingHouseUser_1 = require("./clearingHouseUser");
45
- const orderParams_1 = require("./orderParams");
46
46
  const config_1 = require("./config");
47
47
  /**
48
48
  * # ClearingHouse
@@ -482,17 +482,25 @@ class ClearingHouse {
482
482
  });
483
483
  }
484
484
  async openPosition(direction, amount, marketIndex, limitPrice) {
485
- return await this.placeAndTake((0, orderParams_1.getMarketOrderParams)(marketIndex, direction, numericConstants_1.ZERO, amount, false, limitPrice));
485
+ return await this.placeAndTake({
486
+ orderType: types_1.OrderType.MARKET,
487
+ marketIndex,
488
+ direction,
489
+ baseAssetAmount: amount,
490
+ price: limitPrice,
491
+ });
486
492
  }
487
493
  async placeOrder(orderParams) {
488
494
  const { txSig, slot } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getPlaceOrderIx(orderParams)), [], this.opts);
489
495
  this.marketLastSlotCache.set(orderParams.marketIndex.toNumber(), slot);
490
496
  return txSig;
491
497
  }
498
+ getOrderParams(optionalOrderParams) {
499
+ return Object.assign({}, types_1.DefaultOrderParams, optionalOrderParams);
500
+ }
492
501
  async getPlaceOrderIx(orderParams) {
502
+ orderParams = this.getOrderParams(orderParams);
493
503
  const userAccountPublicKey = await this.getUserAccountPublicKey();
494
- const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
495
- .oracle;
496
504
  const remainingAccounts = this.getRemainingAccounts({
497
505
  writableMarketIndex: orderParams.marketIndex,
498
506
  });
@@ -501,26 +509,10 @@ class ClearingHouse {
501
509
  state: await this.getStatePublicKey(),
502
510
  user: userAccountPublicKey,
503
511
  authority: this.wallet.publicKey,
504
- oracle: priceOracle,
505
512
  },
506
513
  remainingAccounts,
507
514
  });
508
515
  }
509
- async expireOrders(userAccountPublicKey) {
510
- const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getExpireOrdersIx(userAccountPublicKey)), [], this.opts);
511
- return txSig;
512
- }
513
- async getExpireOrdersIx(userAccountPublicKey) {
514
- const fillerPublicKey = await this.getUserAccountPublicKey();
515
- return await this.program.instruction.expireOrders({
516
- accounts: {
517
- state: await this.getStatePublicKey(),
518
- filler: fillerPublicKey,
519
- user: userAccountPublicKey,
520
- authority: this.wallet.publicKey,
521
- },
522
- });
523
- }
524
516
  async updateAMMs(marketIndexes) {
525
517
  const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getUpdateAMMsIx(marketIndexes)), [], this.opts);
526
518
  return txSig;
@@ -590,54 +582,6 @@ class ClearingHouse {
590
582
  remainingAccounts,
591
583
  });
592
584
  }
593
- async cancelAllOrders(bestEffort) {
594
- const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelAllOrdersIx(bestEffort)), [], this.opts);
595
- return txSig;
596
- }
597
- async getCancelAllOrdersIx(bestEffort) {
598
- const userAccountPublicKey = await this.getUserAccountPublicKey();
599
- const remainingAccounts = this.getRemainingAccounts({});
600
- for (const order of this.getUserAccount().orders) {
601
- const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
602
- remainingAccounts.push({
603
- pubkey: oracle,
604
- isWritable: false,
605
- isSigner: false,
606
- });
607
- }
608
- return await this.program.instruction.cancelAllOrders(bestEffort, {
609
- accounts: {
610
- state: await this.getStatePublicKey(),
611
- user: userAccountPublicKey,
612
- authority: this.wallet.publicKey,
613
- },
614
- remainingAccounts,
615
- });
616
- }
617
- async cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly) {
618
- const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelOrdersByMarketAndSideIx(bestEffort, marketIndexOnly, directionOnly)), [], this.opts);
619
- return txSig;
620
- }
621
- async getCancelOrdersByMarketAndSideIx(bestEffort, marketIndexOnly, directionOnly) {
622
- const userAccountPublicKey = await this.getUserAccountPublicKey();
623
- const remainingAccounts = this.getRemainingAccounts({});
624
- for (const order of this.getUserAccount().orders) {
625
- const oracle = this.getMarketAccount(order.marketIndex).amm.oracle;
626
- remainingAccounts.push({
627
- pubkey: oracle,
628
- isWritable: false,
629
- isSigner: false,
630
- });
631
- }
632
- return await this.program.instruction.cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly, {
633
- accounts: {
634
- state: await this.getStatePublicKey(),
635
- user: userAccountPublicKey,
636
- authority: this.wallet.publicKey,
637
- },
638
- remainingAccounts,
639
- });
640
- }
641
585
  async fillOrder(userAccountPublicKey, user, order, makerInfo) {
642
586
  const { txSig } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getFillOrderIx(userAccountPublicKey, user, order, makerInfo)), [], this.opts);
643
587
  return txSig;
@@ -646,7 +590,6 @@ class ClearingHouse {
646
590
  const fillerPublicKey = await this.getUserAccountPublicKey();
647
591
  const marketIndex = order.marketIndex;
648
592
  const marketAccount = this.getMarketAccount(marketIndex);
649
- const oracle = marketAccount.amm.oracle;
650
593
  const bankAccountInfos = [
651
594
  {
652
595
  pubkey: this.getQuoteAssetBankAccount().pubkey,
@@ -674,7 +617,7 @@ class ClearingHouse {
674
617
  const market = this.getMarketAccount(position.marketIndex);
675
618
  marketAccountInfos.push({
676
619
  pubkey: market.pubkey,
677
- isWritable: false,
620
+ isWritable: true,
678
621
  isSigner: false,
679
622
  });
680
623
  oracleAccountInfos.push({
@@ -700,7 +643,6 @@ class ClearingHouse {
700
643
  filler: fillerPublicKey,
701
644
  user: userAccountPublicKey,
702
645
  authority: this.wallet.publicKey,
703
- oracle: oracle,
704
646
  },
705
647
  remainingAccounts,
706
648
  });
@@ -768,9 +710,8 @@ class ClearingHouse {
768
710
  return txSig;
769
711
  }
770
712
  async getPlaceAndTakeIx(orderParams, makerInfo) {
713
+ orderParams = this.getOrderParams(orderParams);
771
714
  const userAccountPublicKey = await this.getUserAccountPublicKey();
772
- const priceOracle = this.getMarketAccount(orderParams.marketIndex).amm
773
- .oracle;
774
715
  const remainingAccounts = this.getRemainingAccounts({
775
716
  writableMarketIndex: orderParams.marketIndex,
776
717
  writableBankIndex: numericConstants_1.QUOTE_ASSET_BANK_INDEX,
@@ -789,7 +730,34 @@ class ClearingHouse {
789
730
  state: await this.getStatePublicKey(),
790
731
  user: userAccountPublicKey,
791
732
  authority: this.wallet.publicKey,
792
- oracle: priceOracle,
733
+ },
734
+ remainingAccounts,
735
+ });
736
+ }
737
+ async placeAndMake(orderParams, takerInfo) {
738
+ const { txSig, slot } = await this.txSender.send((0, utils_1.wrapInTx)(await this.getPlaceAndMakeIx(orderParams, takerInfo)), [], this.opts);
739
+ this.marketLastSlotCache.set(orderParams.marketIndex.toNumber(), slot);
740
+ return txSig;
741
+ }
742
+ async getPlaceAndMakeIx(orderParams, takerInfo) {
743
+ orderParams = this.getOrderParams(orderParams);
744
+ const userAccountPublicKey = await this.getUserAccountPublicKey();
745
+ const remainingAccounts = this.getRemainingAccounts({
746
+ writableMarketIndex: orderParams.marketIndex,
747
+ writableBankIndex: numericConstants_1.QUOTE_ASSET_BANK_INDEX,
748
+ });
749
+ const takerOrderId = takerInfo.order.orderId;
750
+ remainingAccounts.push({
751
+ pubkey: takerInfo.taker,
752
+ isSigner: false,
753
+ isWritable: true,
754
+ });
755
+ return await this.program.instruction.placeAndMake(orderParams, takerOrderId, {
756
+ accounts: {
757
+ state: await this.getStatePublicKey(),
758
+ user: userAccountPublicKey,
759
+ taker: takerInfo.taker,
760
+ authority: this.wallet.publicKey,
793
761
  },
794
762
  remainingAccounts,
795
763
  });
@@ -804,7 +772,13 @@ class ClearingHouse {
804
772
  if (!userPosition) {
805
773
  throw Error(`No position in market ${marketIndex.toString()}`);
806
774
  }
807
- return await this.placeAndTake((0, orderParams_1.getMarketOrderParams)(marketIndex, (0, position_1.findDirectionToClose)(userPosition), numericConstants_1.ZERO, userPosition.baseAssetAmount, true, undefined));
775
+ return await this.placeAndTake({
776
+ orderType: types_1.OrderType.MARKET,
777
+ marketIndex,
778
+ direction: (0, position_1.findDirectionToClose)(userPosition),
779
+ baseAssetAmount: userPosition.baseAssetAmount,
780
+ reduceOnly: true,
781
+ });
808
782
  }
809
783
  async settlePNLs(users, marketIndex) {
810
784
  const ixs = [];
package/lib/config.js CHANGED
@@ -7,7 +7,7 @@ exports.configs = {
7
7
  devnet: {
8
8
  ENV: 'devnet',
9
9
  PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
10
- CLEARING_HOUSE_PROGRAM_ID: '9jwr5nC2f9yAraXrg4UzHXmCX3vi9FQkjD6p9e8bRqNa',
10
+ CLEARING_HOUSE_PROGRAM_ID: 'BMow898PH56jD8z4EaqxicoGXkR1HhN17qrER6Uc4AYq',
11
11
  USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
12
12
  MARKETS: markets_1.DevnetMarkets,
13
13
  BANKS: banks_1.DevnetBanks,