@drift-labs/common 1.0.16 → 1.0.18

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 (88) hide show
  1. package/lib/EnvironmentConstants.js +2 -2
  2. package/lib/EnvironmentConstants.js.map +1 -1
  3. package/lib/clients/DlobWebsocketClient.d.ts +6 -0
  4. package/lib/clients/DlobWebsocketClient.js +24 -4
  5. package/lib/clients/DlobWebsocketClient.js.map +1 -1
  6. package/lib/clients/candleClient.js +12 -0
  7. package/lib/clients/candleClient.js.map +1 -1
  8. package/lib/clients/swiftClient.d.ts +1 -0
  9. package/lib/clients/swiftClient.js +79 -25
  10. package/lib/clients/swiftClient.js.map +1 -1
  11. package/lib/clients/tvFeed.d.ts +5 -1
  12. package/lib/clients/tvFeed.js +32 -5
  13. package/lib/clients/tvFeed.js.map +1 -1
  14. package/lib/common-ui-utils/commonUiUtils.d.ts +1 -2
  15. package/lib/common-ui-utils/commonUiUtils.js +38 -3
  16. package/lib/common-ui-utils/commonUiUtils.js.map +1 -1
  17. package/lib/common-ui-utils/order.d.ts +1 -2
  18. package/lib/common-ui-utils/order.js +9 -10
  19. package/lib/common-ui-utils/order.js.map +1 -1
  20. package/lib/common-ui-utils/user.js +23 -20
  21. package/lib/common-ui-utils/user.js.map +1 -1
  22. package/lib/constants/autogenerated/driftErrors.json +5 -1
  23. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.d.ts +1 -1
  24. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +20 -5
  25. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
  26. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +9 -1
  27. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -1
  28. package/lib/drift/Drift/clients/AuthorityDrift/index.d.ts +1 -1
  29. package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -1
  30. package/lib/drift/Drift/clients/CentralServerDrift/index.d.ts +18 -2
  31. package/lib/drift/Drift/clients/CentralServerDrift/index.js +54 -19
  32. package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
  33. package/lib/drift/base/actions/perp/settlePnl.d.ts +4 -3
  34. package/lib/drift/base/actions/perp/settlePnl.js +6 -3
  35. package/lib/drift/base/actions/perp/settlePnl.js.map +1 -1
  36. package/lib/drift/base/actions/spot/deposit.d.ts +10 -3
  37. package/lib/drift/base/actions/spot/deposit.js +22 -7
  38. package/lib/drift/base/actions/spot/deposit.js.map +1 -1
  39. package/lib/drift/base/actions/trade/editOrder.d.ts +2 -0
  40. package/lib/drift/base/actions/trade/editOrder.js +1 -0
  41. package/lib/drift/base/actions/trade/editOrder.js.map +1 -1
  42. package/lib/drift/base/actions/trade/openPerpOrder/auction.d.ts +4 -1
  43. package/lib/drift/base/actions/trade/openPerpOrder/auction.js +4 -4
  44. package/lib/drift/base/actions/trade/openPerpOrder/auction.js.map +1 -1
  45. package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.d.ts +6 -4
  46. package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js +6 -5
  47. package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js.map +1 -1
  48. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +13 -6
  49. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +26 -16
  50. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
  51. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +1 -4
  52. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +12 -15
  53. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
  54. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.d.ts +48 -11
  55. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +54 -18
  56. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
  57. package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.d.ts +2 -2
  58. package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js +6 -2
  59. package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js.map +1 -1
  60. package/lib/drift/base/actions/trade/openPerpOrder/types.d.ts +5 -3
  61. package/lib/drift/base/actions/trade/openPerpOrder/types.js.map +1 -1
  62. package/lib/drift/base/actions/trade/swap.d.ts +6 -13
  63. package/lib/drift/base/actions/trade/swap.js +11 -36
  64. package/lib/drift/base/actions/trade/swap.js.map +1 -1
  65. package/lib/drift/base/actions/user/create.d.ts +3 -1
  66. package/lib/drift/base/actions/user/create.js +27 -8
  67. package/lib/drift/base/actions/user/create.js.map +1 -1
  68. package/lib/drift/cli.js +16 -2
  69. package/lib/drift/cli.js.map +1 -1
  70. package/lib/drift/utils/auctionParamsResponseMapper.d.ts +2 -1
  71. package/lib/drift/utils/auctionParamsResponseMapper.js +1 -1
  72. package/lib/drift/utils/auctionParamsResponseMapper.js.map +1 -1
  73. package/lib/drift/utils/orderParams.js +1 -1
  74. package/lib/drift/utils/orderParams.js.map +1 -1
  75. package/lib/serializableTypes.d.ts +1 -0
  76. package/lib/serializableTypes.js +4 -0
  77. package/lib/serializableTypes.js.map +1 -1
  78. package/lib/utils/driftEvents.js +18 -2
  79. package/lib/utils/driftEvents.js.map +1 -1
  80. package/lib/utils/logger.js +34 -3
  81. package/lib/utils/logger.js.map +1 -1
  82. package/lib/utils/signedMsgs.d.ts +1 -1
  83. package/lib/utils/signedMsgs.js +2 -2
  84. package/lib/utils/signedMsgs.js.map +1 -1
  85. package/lib/utils/token.d.ts +2 -1
  86. package/lib/utils/token.js +3 -2
  87. package/lib/utils/token.js.map +1 -1
  88. package/package.json +16 -4
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createDepositTxn = exports.createDepositIxs = void 0;
4
- const token_1 = require("../../../../utils/token");
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ const spl_token_1 = require("@solana/spl-token");
5
6
  /**
6
7
  * Creates transaction instructions for depositing a spot token.
7
8
  *
@@ -10,19 +11,24 @@ const token_1 = require("../../../../utils/token");
10
11
  * @param amount - The amount to deposit (in BigNum format)
11
12
  * @param spotMarketConfig - The spot market configuration for the token being deposited
12
13
  * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x, set to reduce only)
14
+ * @param externalWallet - Optional external wallet to deposit from (instead of user's authority wallet)
13
15
  *
14
16
  * @returns Promise resolving to an array of transaction instructions for the deposit
15
17
  */
16
- const createDepositIxs = async ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, }) => {
17
- const authority = user.getUserAccount().authority;
18
- const associatedDepositTokenAddress = await (0, token_1.getTokenAddressForDepositAndWithdraw)(spotMarketConfig.mint, authority);
18
+ const createDepositIxs = async ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, externalWallet, }) => {
19
+ const authority = externalWallet !== null && externalWallet !== void 0 ? externalWallet : user.getUserAccount().authority;
20
+ const spotMarketAccount = driftClient.getSpotMarketAccount(spotMarketConfig.marketIndex);
21
+ const isSol = spotMarketAccount.mint.equals(sdk_1.WRAPPED_SOL_MINT);
22
+ const associatedDepositTokenAddress = isSol
23
+ ? authority
24
+ : await (0, spl_token_1.getAssociatedTokenAddress)(spotMarketAccount.mint, authority, true, (0, sdk_1.getTokenProgramForSpotMarket)(spotMarketAccount));
19
25
  let finalDepositAmount = amount;
20
26
  if (isMaxBorrowRepayment) {
21
27
  // we over-estimate to ensure that there is no borrow dust left
22
28
  // since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate
23
29
  finalDepositAmount = finalDepositAmount.scale(2, 1);
24
30
  }
25
- const depositIxs = await driftClient.getDepositTxnIx(finalDepositAmount.val, spotMarketConfig.marketIndex, associatedDepositTokenAddress, user.getUserAccount().subAccountId, isMaxBorrowRepayment);
31
+ const depositIxs = await driftClient.getDepositTxnIx(finalDepositAmount.val, spotMarketConfig.marketIndex, associatedDepositTokenAddress, user.getUserAccount().subAccountId, isMaxBorrowRepayment, externalWallet ? { authority: externalWallet } : undefined);
26
32
  return depositIxs;
27
33
  };
28
34
  exports.createDepositIxs = createDepositIxs;
@@ -36,10 +42,11 @@ exports.createDepositIxs = createDepositIxs;
36
42
  * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x)
37
43
  * @param txParams - Optional transaction parameters for building the transaction (compute units, priority fees, etc.)
38
44
  * @param initSwiftAccount - Optional flag to initialize a Swift account during the deposit
45
+ * @param externalWallet - Optional external wallet to deposit from (instead of user's authority wallet)
39
46
  *
40
47
  * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)
41
48
  */
42
- const createDepositTxn = async ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, txParams, initSwiftAccount: _initSwiftAccount, }) => {
49
+ const createDepositTxn = async ({ driftClient, user, amount, spotMarketConfig, isMaxBorrowRepayment, txParams, initSwiftAccount: _initSwiftAccount, externalWallet, }) => {
43
50
  // const authority = user.getUserAccount().authority;
44
51
  // const associatedDepositTokenAddress =
45
52
  // await getTokenAddressForDepositAndWithdraw(
@@ -68,13 +75,21 @@ const createDepositTxn = async ({ driftClient, user, amount, spotMarketConfig, i
68
75
  amount: finalDepositAmount,
69
76
  spotMarketConfig,
70
77
  isMaxBorrowRepayment,
78
+ externalWallet,
71
79
  });
80
+ // Wrapper to filter out null lookup tables from the driftClient
81
+ const fetchFilteredLookupTables = async () => {
82
+ var _a;
83
+ const lookupTables = await driftClient.fetchAllLookupTableAccounts();
84
+ // Filter out null/undefined values and return empty array if undefined
85
+ return ((_a = lookupTables === null || lookupTables === void 0 ? void 0 : lookupTables.filter((table) => table !== null && table !== undefined)) !== null && _a !== void 0 ? _a : []);
86
+ };
72
87
  const depositTxn = await driftClient.txHandler.buildTransaction({
73
88
  instructions: depositIxs,
74
89
  txVersion: 0,
75
90
  connection: driftClient.connection,
76
91
  preFlightCommitment: 'confirmed',
77
- fetchAllMarketLookupTableAccounts: driftClient.fetchAllLookupTableAccounts.bind(driftClient),
92
+ fetchAllMarketLookupTableAccounts: fetchFilteredLookupTables,
78
93
  txParams,
79
94
  });
80
95
  return depositTxn;
@@ -1 +1 @@
1
- {"version":3,"file":"deposit.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/spot/deposit.ts"],"names":[],"mappings":";;;AAYA,mDAA+E;AAU/E;;;;;;;;;;GAUG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACtC,WAAW,EACX,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,oBAAoB,GACG,EAAqC,EAAE;IAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC;IAClD,MAAM,6BAA6B,GAClC,MAAM,IAAA,4CAAoC,EACzC,gBAAgB,CAAC,IAAI,EACrB,SAAS,CACT,CAAC;IAEH,IAAI,kBAAkB,GAAG,MAAM,CAAC;IAEhC,IAAI,oBAAoB,EAAE,CAAC;QAC1B,+DAA+D;QAC/D,uEAAuE;QACvE,kBAAkB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,eAAe,CACnD,kBAAkB,CAAC,GAAG,EACtB,gBAAgB,CAAC,WAAW,EAC5B,6BAA6B,EAC7B,IAAI,CAAC,cAAc,EAAE,CAAC,YAAY,EAClC,oBAAoB,CACpB,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AA/BW,QAAA,gBAAgB,oBA+B3B;AAOF;;;;;;;;;;;;GAYG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACtC,WAAW,EACX,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,oBAAoB,EACpB,QAAQ,EACR,gBAAgB,EAAE,iBAAiB,GACX,EAA+C,EAAE;IACzE,qDAAqD;IACrD,wCAAwC;IACxC,+CAA+C;IAC/C,2BAA2B;IAC3B,cAAc;IACd,MAAM;IAEN,IAAI,kBAAkB,GAAG,MAAM,CAAC;IAEhC,IAAI,oBAAoB,EAAE,CAAC;QAC1B,+DAA+D;QAC/D,uEAAuE;QACvE,kBAAkB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,gGAAgG;IAChG,yDAAyD;IACzD,2BAA2B;IAC3B,iCAAiC;IACjC,kCAAkC;IAClC,uCAAuC;IACvC,yBAAyB;IACzB,aAAa;IACb,oBAAoB;IACpB,KAAK;IACL,MAAM,UAAU,GAAG,MAAM,IAAA,wBAAgB,EAAC;QACzC,WAAW;QACX,IAAI;QACJ,MAAM,EAAE,kBAAkB;QAC1B,gBAAgB;QAChB,oBAAoB;KACpB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC;QAC/D,YAAY,EAAE,UAAU;QACxB,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAChC,WAAW,CAAC,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;QAC1D,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AArDW,QAAA,gBAAgB,oBAqD3B","sourcesContent":["import {\n\tBigNum,\n\tDriftClient,\n\tSpotMarketConfig,\n\tTxParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { getTokenAddressForDepositAndWithdraw } from '../../../../utils/token';\n\ninterface CreateDepositIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tamount: BigNum;\n\tspotMarketConfig: Pick<SpotMarketConfig, 'mint' | 'marketIndex'>;\n\tisMaxBorrowRepayment?: boolean;\n}\n\n/**\n * Creates transaction instructions for depositing a spot token.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will perform the deposit\n * @param amount - The amount to deposit (in BigNum format)\n * @param spotMarketConfig - The spot market configuration for the token being deposited\n * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x, set to reduce only)\n *\n * @returns Promise resolving to an array of transaction instructions for the deposit\n */\nexport const createDepositIxs = async ({\n\tdriftClient,\n\tuser,\n\tamount,\n\tspotMarketConfig,\n\tisMaxBorrowRepayment,\n}: CreateDepositIxParams): Promise<TransactionInstruction[]> => {\n\tconst authority = user.getUserAccount().authority;\n\tconst associatedDepositTokenAddress =\n\t\tawait getTokenAddressForDepositAndWithdraw(\n\t\t\tspotMarketConfig.mint,\n\t\t\tauthority\n\t\t);\n\n\tlet finalDepositAmount = amount;\n\n\tif (isMaxBorrowRepayment) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate\n\t\tfinalDepositAmount = finalDepositAmount.scale(2, 1);\n\t}\n\n\tconst depositIxs = await driftClient.getDepositTxnIx(\n\t\tfinalDepositAmount.val,\n\t\tspotMarketConfig.marketIndex,\n\t\tassociatedDepositTokenAddress,\n\t\tuser.getUserAccount().subAccountId,\n\t\tisMaxBorrowRepayment\n\t);\n\n\treturn depositIxs;\n};\n\ninterface CreateDepositTxnParams extends CreateDepositIxParams {\n\ttxParams?: TxParams;\n\tinitSwiftAccount?: boolean;\n}\n\n/**\n * Creates a complete transaction for depositing assets into a spot market.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will perform the deposit\n * @param amount - The amount to deposit (in BigNum format)\n * @param spotMarketConfig - The spot market configuration for the token being deposited\n * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x)\n * @param txParams - Optional transaction parameters for building the transaction (compute units, priority fees, etc.)\n * @param initSwiftAccount - Optional flag to initialize a Swift account during the deposit\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createDepositTxn = async ({\n\tdriftClient,\n\tuser,\n\tamount,\n\tspotMarketConfig,\n\tisMaxBorrowRepayment,\n\ttxParams,\n\tinitSwiftAccount: _initSwiftAccount,\n}: CreateDepositTxnParams): Promise<Transaction | VersionedTransaction> => {\n\t// const authority = user.getUserAccount().authority;\n\t// const associatedDepositTokenAddress =\n\t// \tawait getTokenAddressForDepositAndWithdraw(\n\t// \t\tspotMarketConfig.mint,\n\t// \t\tauthority\n\t// \t);\n\n\tlet finalDepositAmount = amount;\n\n\tif (isMaxBorrowRepayment) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate\n\t\tfinalDepositAmount = finalDepositAmount.scale(2, 1);\n\t}\n\n\t// we choose to not use createDepositIxs here because it doesn't have the initSwiftAccount logic\n\t// const depositTxn = await driftClient.createDepositTxn(\n\t// \tfinalDepositAmount.val,\n\t// \tspotMarketConfig.marketIndex,\n\t// \tassociatedDepositTokenAddress,\n\t// \tuser.getUserAccount().subAccountId,\n\t// \tisMaxBorrowRepayment,\n\t// \ttxParams,\n\t// \tinitSwiftAccount\n\t// );\n\tconst depositIxs = await createDepositIxs({\n\t\tdriftClient,\n\t\tuser,\n\t\tamount: finalDepositAmount,\n\t\tspotMarketConfig,\n\t\tisMaxBorrowRepayment,\n\t});\n\n\tconst depositTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: depositIxs,\n\t\ttxVersion: 0,\n\t\tconnection: driftClient.connection,\n\t\tpreFlightCommitment: 'confirmed',\n\t\tfetchAllMarketLookupTableAccounts:\n\t\t\tdriftClient.fetchAllLookupTableAccounts.bind(driftClient),\n\t\ttxParams,\n\t});\n\n\treturn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AAC;QAC/D,YAAY,EAAE,UAAU;QACxB,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,mBAAmB,EAAE,WAAW;QAChC,iCAAiC,EAAE,yBAAyB;QAC5D,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAhEW,QAAA,gBAAgB,oBAgE3B","sourcesContent":["import {\n\tBigNum,\n\tDriftClient,\n\tgetTokenProgramForSpotMarket,\n\tSpotMarketConfig,\n\tTxParams,\n\tUser,\n\tWRAPPED_SOL_MINT,\n} from '@drift-labs/sdk';\nimport {\n\tPublicKey,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { getAssociatedTokenAddress } from '@solana/spl-token';\n\ninterface CreateDepositIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tamount: BigNum;\n\tspotMarketConfig: Pick<SpotMarketConfig, 'mint' | 'marketIndex'>;\n\tisMaxBorrowRepayment?: boolean;\n\t/**\n\t * Optional external wallet to deposit from. If provided, the deposit will be made\n\t * from this wallet instead of the user's authority wallet.\n\t */\n\texternalWallet?: PublicKey;\n}\n\n/**\n * Creates transaction instructions for depositing a spot token.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will perform the deposit\n * @param amount - The amount to deposit (in BigNum format)\n * @param spotMarketConfig - The spot market configuration for the token being deposited\n * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x, set to reduce only)\n * @param externalWallet - Optional external wallet to deposit from (instead of user's authority wallet)\n *\n * @returns Promise resolving to an array of transaction instructions for the deposit\n */\nexport const createDepositIxs = async ({\n\tdriftClient,\n\tuser,\n\tamount,\n\tspotMarketConfig,\n\tisMaxBorrowRepayment,\n\texternalWallet,\n}: CreateDepositIxParams): Promise<TransactionInstruction[]> => {\n\tconst authority = externalWallet ?? user.getUserAccount().authority;\n\tconst spotMarketAccount = driftClient.getSpotMarketAccount(\n\t\tspotMarketConfig.marketIndex\n\t);\n\tconst isSol = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);\n\tconst associatedDepositTokenAddress = isSol\n\t\t? authority\n\t\t: await getAssociatedTokenAddress(\n\t\t\t\tspotMarketAccount.mint,\n\t\t\t\tauthority,\n\t\t\t\ttrue,\n\t\t\t\tgetTokenProgramForSpotMarket(spotMarketAccount)\n\t\t );\n\n\tlet finalDepositAmount = amount;\n\n\tif (isMaxBorrowRepayment) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate\n\t\tfinalDepositAmount = finalDepositAmount.scale(2, 1);\n\t}\n\n\tconst depositIxs = await driftClient.getDepositTxnIx(\n\t\tfinalDepositAmount.val,\n\t\tspotMarketConfig.marketIndex,\n\t\tassociatedDepositTokenAddress,\n\t\tuser.getUserAccount().subAccountId,\n\t\tisMaxBorrowRepayment,\n\t\texternalWallet ? { authority: externalWallet } : undefined\n\t);\n\n\treturn depositIxs;\n};\n\ninterface CreateDepositTxnParams extends CreateDepositIxParams {\n\ttxParams?: TxParams;\n\tinitSwiftAccount?: boolean;\n}\n\n/**\n * Creates a complete transaction for depositing assets into a spot market.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will perform the deposit\n * @param amount - The amount to deposit (in BigNum format)\n * @param spotMarketConfig - The spot market configuration for the token being deposited\n * @param isMaxBorrowRepayment - Whether this deposit is for maximum borrow repayment (scales amount by 2x)\n * @param txParams - Optional transaction parameters for building the transaction (compute units, priority fees, etc.)\n * @param initSwiftAccount - Optional flag to initialize a Swift account during the deposit\n * @param externalWallet - Optional external wallet to deposit from (instead of user's authority wallet)\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createDepositTxn = async ({\n\tdriftClient,\n\tuser,\n\tamount,\n\tspotMarketConfig,\n\tisMaxBorrowRepayment,\n\ttxParams,\n\tinitSwiftAccount: _initSwiftAccount,\n\texternalWallet,\n}: CreateDepositTxnParams): Promise<Transaction | VersionedTransaction> => {\n\t// const authority = user.getUserAccount().authority;\n\t// const associatedDepositTokenAddress =\n\t// \tawait getTokenAddressForDepositAndWithdraw(\n\t// \t\tspotMarketConfig.mint,\n\t// \t\tauthority\n\t// \t);\n\n\tlet finalDepositAmount = amount;\n\n\tif (isMaxBorrowRepayment) {\n\t\t// we over-estimate to ensure that there is no borrow dust left\n\t\t// since isMaxBorrowRepayment = reduceOnly, it is safe to over-estimate\n\t\tfinalDepositAmount = finalDepositAmount.scale(2, 1);\n\t}\n\n\t// we choose to not use createDepositIxs here because it doesn't have the initSwiftAccount logic\n\t// const depositTxn = await driftClient.createDepositTxn(\n\t// \tfinalDepositAmount.val,\n\t// \tspotMarketConfig.marketIndex,\n\t// \tassociatedDepositTokenAddress,\n\t// \tuser.getUserAccount().subAccountId,\n\t// \tisMaxBorrowRepayment,\n\t// \ttxParams,\n\t// \tinitSwiftAccount\n\t// );\n\tconst depositIxs = await createDepositIxs({\n\t\tdriftClient,\n\t\tuser,\n\t\tamount: finalDepositAmount,\n\t\tspotMarketConfig,\n\t\tisMaxBorrowRepayment,\n\t\texternalWallet,\n\t});\n\n\t// Wrapper to filter out null lookup tables from the driftClient\n\tconst fetchFilteredLookupTables = async () => {\n\t\tconst lookupTables = await driftClient.fetchAllLookupTableAccounts();\n\t\t// Filter out null/undefined values and return empty array if undefined\n\t\treturn (\n\t\t\tlookupTables?.filter((table) => table !== null && table !== undefined) ??\n\t\t\t[]\n\t\t);\n\t};\n\n\tconst depositTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: depositIxs,\n\t\ttxVersion: 0,\n\t\tconnection: driftClient.connection,\n\t\tpreFlightCommitment: 'confirmed',\n\t\tfetchAllMarketLookupTableAccounts: fetchFilteredLookupTables,\n\t\ttxParams,\n\t});\n\n\treturn depositTxn;\n};\n"]}
@@ -37,6 +37,8 @@ interface EditOrderParams {
37
37
  policy?: number;
38
38
  /** Optional high leverage options */
39
39
  highLeverageOptions?: HighLeverageOptions;
40
+ /** The leverage to be used for this position. */
41
+ positionMaxLeverage?: number;
40
42
  }
41
43
  export interface CreateEditOrderIxParams {
42
44
  driftClient: DriftClient;
@@ -38,6 +38,7 @@ const createEditOrderIx = async (params) => {
38
38
  reduceOnly: currentOrder.reduceOnly,
39
39
  postOnly: currentOrder.postOnly,
40
40
  orderConfig: limitAuctionOrderConfig,
41
+ positionMaxLeverage: editOrderParams.positionMaxLeverage,
41
42
  });
42
43
  finalEditOrderParams = {
43
44
  ...editOrderParams,
@@ -1 +1 @@
1
- {"version":3,"file":"editOrder.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/trade/editOrder.ts"],"names":[],"mappings":";;;;;;AAAA,yCAQyB;AAOzB,6CAA+C;AAC/C,oEAAuC;AACvC,qDAAqE;AAuDrE;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACrC,MAA+B,EACG,EAAE;IACpC,MAAM,EACL,WAAW,EACX,IAAI,EACJ,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,uBAAuB,GACvB,GAAG,MAAM,CAAC;IACX,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE5C,IAAA,wBAAS,EAAC,YAAY,EAAE,yBAAyB,CAAC,CAAC;IAEnD,MAAM,YAAY,GAAG,kBAAU,CAAC,KAAK,CACpC,YAAY,CAAC,SAAS,EACtB,eAAS,CAAC,KAAK,CACf,CAAC;IAEF,IAAI,oBAAoB,GAAG,eAAe,CAAC;IAE3C,6CAA6C;IAC7C,IACC,YAAY;QACZ,uBAAuB;QACvB,kBAAU,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,oBAAc,CAAC,IAAI,CAAC,EAC3D,CAAC;QACF,MAAM,uBAAuB,GAAG,MAAM,IAAA,oCAA0B,EAAC;YAChE,WAAW;YACX,IAAI;YACJ,WAAW,EAAE,YAAY,CAAC,WAAW;YACrC,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,SAAS,EAAE,YAAY,CAAC,SAAS;YACjC,eAAe,EAAE,YAAY,CAAC,eAAe;YAC7C,WAAW,EAAE,YAAY,CAAC,WAAW;YACrC,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,WAAW,EAAE,uBAAuB;SACpC,CAAC,CAAC;QAEH,oBAAoB,GAAG;YACtB,GAAG,eAAe;YAClB,eAAe,EAAE,uBAAuB,CAAC,eAAe;YACxD,iBAAiB,EAAE,uBAAuB,CAAC,iBAAiB;YAC5D,eAAe,EAAE,uBAAuB,CAAC,eAAe;SACxD,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC,gBAAgB,CAClC;QACC,OAAO;QACP,GAAG,oBAAoB;KACvB,EACD,SAAS,EACT;QACC,IAAI;QACJ,SAAS,EAAE,kBAAkB;KAC7B,CACD,CAAC;AACH,CAAC,CAAC;AA5DW,QAAA,iBAAiB,qBA4D5B;AAIF;;;;;;;;GAQG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACxC,QAAQ,EACR,GAAG,MAAM,EACiB,EAA+C,EAAE;IAC3E,OAAO,MAAM,CAAC,WAAW,CAAC,gBAAgB,CACzC,MAAM,IAAA,yBAAiB,EAAC,MAAM,CAAC,EAC/B,QAAQ,CACR,CAAC;AACH,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B","sourcesContent":["import {\n\tBN,\n\tDriftClient,\n\tOrderTriggerCondition,\n\tOrderType,\n\tPositionDirection,\n\tPostOnlyParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tPublicKey,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { ENUM_UTILS } from '../../../../utils';\nimport invariant from 'tiny-invariant';\nimport { getLimitAuctionOrderParams } from './openPerpOrder/auction';\nimport {\n\tLimitAuctionConfig,\n\tLimitOrderParamsOrderConfig,\n} from './openPerpOrder/types';\nimport { WithTxnParams } from '../../types';\nimport { HighLeverageOptions } from '../../../../common-ui-utils/order';\n\n/**\n * Parameters for editing an existing order\n */\ninterface EditOrderParams {\n\t/** New direction for the order (long/short) */\n\tnewDirection?: PositionDirection;\n\t/** New base amount for the order */\n\tnewBaseAmount?: BN;\n\t/** New limit price for the order */\n\tnewLimitPrice?: BN;\n\t/** New oracle price offset for oracle market/limit orders */\n\tnewOraclePriceOffset?: number;\n\t/** New trigger price for conditional orders */\n\tnewTriggerPrice?: BN;\n\t/** New trigger condition for conditional orders */\n\tnewTriggerCondition?: OrderTriggerCondition;\n\t/** Duration of the auction in slots */\n\tauctionDuration?: number;\n\t/** Starting price for the auction */\n\tauctionStartPrice?: BN;\n\t/** Ending price for the auction */\n\tauctionEndPrice?: BN;\n\t/** Whether the order should only reduce position size */\n\treduceOnly?: boolean;\n\t/** Whether the order should only be posted (maker only) */\n\tpostOnly?: boolean;\n\t/** Bit flags for additional order configuration */\n\tbitFlags?: number;\n\t/** Maximum timestamp for order validity */\n\tmaxTs?: BN;\n\t/** Order policy configuration */\n\tpolicy?: number;\n\t/** Optional high leverage options */\n\thighLeverageOptions?: HighLeverageOptions;\n}\n\nexport interface CreateEditOrderIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\torderId: number;\n\teditOrderParams: EditOrderParams;\n\tmainSignerOverride?: PublicKey;\n\tlimitAuctionOrderConfig?: LimitOrderParamsOrderConfig & {\n\t\tlimitAuction: LimitAuctionConfig;\n\t};\n}\n\n/**\n * Creates a transaction instruction to edit an existing order\n * @param driftClient - The DriftClient instance\n * @param userPublicKey - The public key of the user who owns the order\n * @param orderId - The ID of the order to edit\n * @param editOrderParams - Parameters containing the new order values\n * @param limitAuctionOrderConfig - Configuration for the limit auction order. If not provided, limit auction will not be enabled when relevant.\n * @returns Promise that resolves to a TransactionInstruction\n */\nexport const createEditOrderIx = async (\n\tparams: CreateEditOrderIxParams\n): Promise<TransactionInstruction> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\torderId,\n\t\teditOrderParams,\n\t\tmainSignerOverride,\n\t\tlimitAuctionOrderConfig,\n\t} = params;\n\tconst currentOrder = user.getOrder(orderId);\n\n\tinvariant(currentOrder, 'Current order not found');\n\n\tconst isLimitOrder = ENUM_UTILS.match(\n\t\tcurrentOrder.orderType,\n\t\tOrderType.LIMIT\n\t);\n\n\tlet finalEditOrderParams = editOrderParams;\n\n\t// handle limit auction if config is provided\n\tif (\n\t\tisLimitOrder &&\n\t\tlimitAuctionOrderConfig &&\n\t\tENUM_UTILS.match(currentOrder.postOnly, PostOnlyParams.NONE)\n\t) {\n\t\tconst limitAuctionOrderParams = await getLimitAuctionOrderParams({\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex: currentOrder.marketIndex,\n\t\t\tmarketType: currentOrder.marketType,\n\t\t\tdirection: currentOrder.direction,\n\t\t\tbaseAssetAmount: currentOrder.baseAssetAmount,\n\t\t\tuserOrderId: currentOrder.userOrderId,\n\t\t\treduceOnly: currentOrder.reduceOnly,\n\t\t\tpostOnly: currentOrder.postOnly,\n\t\t\torderConfig: limitAuctionOrderConfig,\n\t\t});\n\n\t\tfinalEditOrderParams = {\n\t\t\t...editOrderParams,\n\t\t\tauctionDuration: limitAuctionOrderParams.auctionDuration,\n\t\t\tauctionStartPrice: limitAuctionOrderParams.auctionStartPrice,\n\t\t\tauctionEndPrice: limitAuctionOrderParams.auctionEndPrice,\n\t\t};\n\t}\n\n\treturn driftClient.getModifyOrderIx(\n\t\t{\n\t\t\torderId,\n\t\t\t...finalEditOrderParams,\n\t\t},\n\t\tundefined,\n\t\t{\n\t\t\tuser,\n\t\t\tauthority: mainSignerOverride,\n\t\t}\n\t);\n};\n\ntype CreateEditOrderTxnParams = WithTxnParams<CreateEditOrderIxParams>;\n\n/**\n * Creates a complete transaction to edit an existing order\n * @param driftClient - The DriftClient instance\n * @param userPublicKey - The public key of the user who owns the order\n * @param orderId - The ID of the order to edit\n * @param editOrderParams - Parameters containing the new order values\n * @param txParams - Optional transaction parameters (compute units, priority fees, etc.)\n * @returns Promise that resolves to a Transaction or VersionedTransaction\n */\nexport const createEditOrderTxn = async ({\n\ttxParams,\n\t...params\n}: CreateEditOrderTxnParams): Promise<Transaction | VersionedTransaction> => {\n\treturn params.driftClient.buildTransaction(\n\t\tawait createEditOrderIx(params),\n\t\ttxParams\n\t);\n};\n"]}
1
+ {"version":3,"file":"editOrder.js","sourceRoot":"","sources":["../../../../../src/drift/base/actions/trade/editOrder.ts"],"names":[],"mappings":";;;;;;AAAA,yCAQyB;AAOzB,6CAA+C;AAC/C,oEAAuC;AACvC,qDAAqE;AAyDrE;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,KAAK,EACrC,MAA+B,EACG,EAAE;IACpC,MAAM,EACL,WAAW,EACX,IAAI,EACJ,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,uBAAuB,GACvB,GAAG,MAAM,CAAC;IACX,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE5C,IAAA,wBAAS,EAAC,YAAY,EAAE,yBAAyB,CAAC,CAAC;IAEnD,MAAM,YAAY,GAAG,kBAAU,CAAC,KAAK,CACpC,YAAY,CAAC,SAAS,EACtB,eAAS,CAAC,KAAK,CACf,CAAC;IAEF,IAAI,oBAAoB,GAAG,eAAe,CAAC;IAE3C,6CAA6C;IAC7C,IACC,YAAY;QACZ,uBAAuB;QACvB,kBAAU,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,oBAAc,CAAC,IAAI,CAAC,EAC3D,CAAC;QACF,MAAM,uBAAuB,GAAG,MAAM,IAAA,oCAA0B,EAAC;YAChE,WAAW;YACX,IAAI;YACJ,WAAW,EAAE,YAAY,CAAC,WAAW;YACrC,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,SAAS,EAAE,YAAY,CAAC,SAAS;YACjC,eAAe,EAAE,YAAY,CAAC,eAAe;YAC7C,WAAW,EAAE,YAAY,CAAC,WAAW;YACrC,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,WAAW,EAAE,uBAAuB;YACpC,mBAAmB,EAAE,eAAe,CAAC,mBAAmB;SACxD,CAAC,CAAC;QAEH,oBAAoB,GAAG;YACtB,GAAG,eAAe;YAClB,eAAe,EAAE,uBAAuB,CAAC,eAAe;YACxD,iBAAiB,EAAE,uBAAuB,CAAC,iBAAiB;YAC5D,eAAe,EAAE,uBAAuB,CAAC,eAAe;SACxD,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC,gBAAgB,CAClC;QACC,OAAO;QACP,GAAG,oBAAoB;KACvB,EACD,SAAS,EACT;QACC,IAAI;QACJ,SAAS,EAAE,kBAAkB;KAC7B,CACD,CAAC;AACH,CAAC,CAAC;AA7DW,QAAA,iBAAiB,qBA6D5B;AAIF;;;;;;;;GAQG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACxC,QAAQ,EACR,GAAG,MAAM,EACiB,EAA+C,EAAE;IAC3E,OAAO,MAAM,CAAC,WAAW,CAAC,gBAAgB,CACzC,MAAM,IAAA,yBAAiB,EAAC,MAAM,CAAC,EAC/B,QAAQ,CACR,CAAC;AACH,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B","sourcesContent":["import {\n\tBN,\n\tDriftClient,\n\tOrderTriggerCondition,\n\tOrderType,\n\tPositionDirection,\n\tPostOnlyParams,\n\tUser,\n} from '@drift-labs/sdk';\nimport {\n\tPublicKey,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport { ENUM_UTILS } from '../../../../utils';\nimport invariant from 'tiny-invariant';\nimport { getLimitAuctionOrderParams } from './openPerpOrder/auction';\nimport {\n\tLimitAuctionConfig,\n\tLimitOrderParamsOrderConfig,\n} from './openPerpOrder/types';\nimport { WithTxnParams } from '../../types';\nimport { HighLeverageOptions } from '../../../../common-ui-utils/order';\n\n/**\n * Parameters for editing an existing order\n */\ninterface EditOrderParams {\n\t/** New direction for the order (long/short) */\n\tnewDirection?: PositionDirection;\n\t/** New base amount for the order */\n\tnewBaseAmount?: BN;\n\t/** New limit price for the order */\n\tnewLimitPrice?: BN;\n\t/** New oracle price offset for oracle market/limit orders */\n\tnewOraclePriceOffset?: number;\n\t/** New trigger price for conditional orders */\n\tnewTriggerPrice?: BN;\n\t/** New trigger condition for conditional orders */\n\tnewTriggerCondition?: OrderTriggerCondition;\n\t/** Duration of the auction in slots */\n\tauctionDuration?: number;\n\t/** Starting price for the auction */\n\tauctionStartPrice?: BN;\n\t/** Ending price for the auction */\n\tauctionEndPrice?: BN;\n\t/** Whether the order should only reduce position size */\n\treduceOnly?: boolean;\n\t/** Whether the order should only be posted (maker only) */\n\tpostOnly?: boolean;\n\t/** Bit flags for additional order configuration */\n\tbitFlags?: number;\n\t/** Maximum timestamp for order validity */\n\tmaxTs?: BN;\n\t/** Order policy configuration */\n\tpolicy?: number;\n\t/** Optional high leverage options */\n\thighLeverageOptions?: HighLeverageOptions;\n\t/** The leverage to be used for this position. */\n\tpositionMaxLeverage?: number;\n}\n\nexport interface CreateEditOrderIxParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\torderId: number;\n\teditOrderParams: EditOrderParams;\n\tmainSignerOverride?: PublicKey;\n\tlimitAuctionOrderConfig?: LimitOrderParamsOrderConfig & {\n\t\tlimitAuction: LimitAuctionConfig;\n\t};\n}\n\n/**\n * Creates a transaction instruction to edit an existing order\n * @param driftClient - The DriftClient instance\n * @param userPublicKey - The public key of the user who owns the order\n * @param orderId - The ID of the order to edit\n * @param editOrderParams - Parameters containing the new order values\n * @param limitAuctionOrderConfig - Configuration for the limit auction order. If not provided, limit auction will not be enabled when relevant.\n * @returns Promise that resolves to a TransactionInstruction\n */\nexport const createEditOrderIx = async (\n\tparams: CreateEditOrderIxParams\n): Promise<TransactionInstruction> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\torderId,\n\t\teditOrderParams,\n\t\tmainSignerOverride,\n\t\tlimitAuctionOrderConfig,\n\t} = params;\n\tconst currentOrder = user.getOrder(orderId);\n\n\tinvariant(currentOrder, 'Current order not found');\n\n\tconst isLimitOrder = ENUM_UTILS.match(\n\t\tcurrentOrder.orderType,\n\t\tOrderType.LIMIT\n\t);\n\n\tlet finalEditOrderParams = editOrderParams;\n\n\t// handle limit auction if config is provided\n\tif (\n\t\tisLimitOrder &&\n\t\tlimitAuctionOrderConfig &&\n\t\tENUM_UTILS.match(currentOrder.postOnly, PostOnlyParams.NONE)\n\t) {\n\t\tconst limitAuctionOrderParams = await getLimitAuctionOrderParams({\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex: currentOrder.marketIndex,\n\t\t\tmarketType: currentOrder.marketType,\n\t\t\tdirection: currentOrder.direction,\n\t\t\tbaseAssetAmount: currentOrder.baseAssetAmount,\n\t\t\tuserOrderId: currentOrder.userOrderId,\n\t\t\treduceOnly: currentOrder.reduceOnly,\n\t\t\tpostOnly: currentOrder.postOnly,\n\t\t\torderConfig: limitAuctionOrderConfig,\n\t\t\tpositionMaxLeverage: editOrderParams.positionMaxLeverage,\n\t\t});\n\n\t\tfinalEditOrderParams = {\n\t\t\t...editOrderParams,\n\t\t\tauctionDuration: limitAuctionOrderParams.auctionDuration,\n\t\t\tauctionStartPrice: limitAuctionOrderParams.auctionStartPrice,\n\t\t\tauctionEndPrice: limitAuctionOrderParams.auctionEndPrice,\n\t\t};\n\t}\n\n\treturn driftClient.getModifyOrderIx(\n\t\t{\n\t\t\torderId,\n\t\t\t...finalEditOrderParams,\n\t\t},\n\t\tundefined,\n\t\t{\n\t\t\tuser,\n\t\t\tauthority: mainSignerOverride,\n\t\t}\n\t);\n};\n\ntype CreateEditOrderTxnParams = WithTxnParams<CreateEditOrderIxParams>;\n\n/**\n * Creates a complete transaction to edit an existing order\n * @param driftClient - The DriftClient instance\n * @param userPublicKey - The public key of the user who owns the order\n * @param orderId - The ID of the order to edit\n * @param editOrderParams - Parameters containing the new order values\n * @param txParams - Optional transaction parameters (compute units, priority fees, etc.)\n * @returns Promise that resolves to a Transaction or VersionedTransaction\n */\nexport const createEditOrderTxn = async ({\n\ttxParams,\n\t...params\n}: CreateEditOrderTxnParams): Promise<Transaction | VersionedTransaction> => {\n\treturn params.driftClient.buildTransaction(\n\t\tawait createEditOrderIx(params),\n\t\ttxParams\n\t);\n};\n"]}
@@ -1,13 +1,15 @@
1
1
  import { PostOnlyParams, MarketType, BN, OptionalOrderParams, DriftClient, User, PositionDirection } from '@drift-labs/sdk';
2
2
  import { HighLeverageOptions } from '../../../../../common-ui-utils';
3
3
  import { LimitOrderParamsOrderConfig, LimitAuctionConfig } from './types';
4
- export declare const getLimitAuctionOrderParams: ({ driftClient, user, marketIndex, marketType, direction, baseAssetAmount, userOrderId, reduceOnly, postOnly, orderConfig, highLeverageOptions, }: {
4
+ import { AuctionParamsFetchedCallback } from '../../../../utils/auctionParamsResponseMapper';
5
+ export declare const getLimitAuctionOrderParams: ({ driftClient, user, marketIndex, marketType, direction, baseAssetAmount, positionMaxLeverage, userOrderId, reduceOnly, postOnly, orderConfig, highLeverageOptions, onAuctionParamsFetched, }: {
5
6
  driftClient: DriftClient;
6
7
  user: User;
7
8
  marketIndex: number;
8
9
  marketType: MarketType;
9
10
  direction: PositionDirection;
10
11
  baseAssetAmount: BN;
12
+ positionMaxLeverage: number;
11
13
  userOrderId?: number;
12
14
  reduceOnly?: boolean;
13
15
  postOnly?: PostOnlyParams;
@@ -15,4 +17,5 @@ export declare const getLimitAuctionOrderParams: ({ driftClient, user, marketInd
15
17
  limitAuction: LimitAuctionConfig;
16
18
  };
17
19
  highLeverageOptions?: HighLeverageOptions;
20
+ onAuctionParamsFetched?: AuctionParamsFetchedCallback;
18
21
  }) => Promise<OptionalOrderParams>;
@@ -10,7 +10,7 @@ const auction_1 = require("../../../constants/auction");
10
10
  const utils_1 = require("../../../../../utils");
11
11
  const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
12
12
  const dlobServer_1 = require("./dlobServer");
13
- const getLimitAuctionOrderParams = async ({ driftClient, user, marketIndex, marketType, direction, baseAssetAmount, userOrderId = 0, reduceOnly = false, postOnly = sdk_1.PostOnlyParams.NONE, orderConfig, highLeverageOptions, }) => {
13
+ const getLimitAuctionOrderParams = async ({ driftClient, user, marketIndex, marketType, direction, baseAssetAmount, positionMaxLeverage, userOrderId = 0, reduceOnly = false, postOnly = sdk_1.PostOnlyParams.NONE, orderConfig, highLeverageOptions, onAuctionParamsFetched, }) => {
14
14
  const orderParams = await (0, dlobServer_1.fetchAuctionOrderParams)({
15
15
  driftClient,
16
16
  user,
@@ -19,8 +19,10 @@ const getLimitAuctionOrderParams = async ({ driftClient, user, marketIndex, mark
19
19
  marketType,
20
20
  direction,
21
21
  amount: baseAssetAmount,
22
+ reduceOnly,
22
23
  dlobServerHttpUrl: orderConfig.limitAuction.dlobServerHttpUrl,
23
24
  optionalAuctionParamsInputs: orderConfig.limitAuction.optionalLimitAuctionParams,
25
+ onAuctionParamsFetched: onAuctionParamsFetched,
24
26
  });
25
27
  const isPerp = utils_1.ENUM_UTILS.match(marketType, sdk_1.MarketType.PERP);
26
28
  (0, tiny_invariant_1.default)(orderConfig.limitAuction.oraclePrice, 'Oracle price not found');
@@ -56,9 +58,7 @@ const getLimitAuctionOrderParams = async ({ driftClient, user, marketIndex, mark
56
58
  userOrderId,
57
59
  ...limitAuctionParams,
58
60
  });
59
- const oraclePrice = driftClient.getOracleDataForPerpMarket(marketIndex).price;
60
- const totalQuoteAmount = baseAssetAmount.mul(oraclePrice).div(sdk_1.BASE_PRECISION);
61
- const bitFlags = common_ui_utils_1.ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(marketIndex, driftClient, user, totalQuoteAmount, direction, highLeverageOptions);
61
+ const bitFlags = common_ui_utils_1.ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(marketIndex, driftClient, user, positionMaxLeverage, highLeverageOptions);
62
62
  return {
63
63
  ...limitAuctionOrderParams,
64
64
  bitFlags,
@@ -1 +1 @@
1
- {"version":3,"file":"auction.js","sourceRoot":"","sources":["../../../../../../src/drift/base/actions/trade/openPerpOrder/auction.ts"],"names":[],"mappings":";;;;;;AAAA,yCAayB;AACzB,oEAIwC;AACxC,wDAA4E;AAC5E,gDAAkD;AAClD,oEAAuC;AACvC,6CAAuD;AAGhD,MAAM,0BAA0B,GAAG,KAAK,EAAE,EAChD,WAAW,EACX,IAAI,EACJ,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,WAAW,GAAG,CAAC,EACf,UAAU,GAAG,KAAK,EAClB,QAAQ,GAAG,oBAAc,CAAC,IAAI,EAC9B,WAAW,EACX,mBAAmB,GAenB,EAAgC,EAAE;IAClC,MAAM,WAAW,GAAG,MAAM,IAAA,oCAAuB,EAAC;QACjD,WAAW;QACX,IAAI;QACJ,SAAS,EAAE,MAAM;QACjB,WAAW;QACX,UAAU;QACV,SAAS;QACT,MAAM,EAAE,eAAe;QACvB,iBAAiB,EAAE,WAAW,CAAC,YAAY,CAAC,iBAAiB;QAC7D,2BAA2B,EAC1B,WAAW,CAAC,YAAY,CAAC,0BAA0B;KACpD,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,kBAAU,CAAC,KAAK,CAAC,UAAU,EAAE,gBAAU,CAAC,IAAI,CAAC,CAAC;IAE7D,IAAA,wBAAS,EAAC,WAAW,CAAC,YAAY,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC;IAC1E,IAAA,wBAAS,EAAC,WAAW,CAAC,iBAAiB,EAAE,+BAA+B,CAAC,CAAC;IAE1E,IAAI,gBAAgB,GAAyB,SAAS,CAAC;IACvD,IAAI,eAAe,GAAG,wCAA8B,CAAC;IAErD,IAAI,MAAM,EAAE,CAAC;QACZ,MAAM,iBAAiB,GAAG,WAAW,CAAC,oBAAoB,CAAC,WAAW,CAAC,CA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,WAAW,EACX,IAAI,EACJ,gBAAgB,EAChB,SAAS,EACT,mBAAmB,CACnB,CAAC;IAEF,OAAO;QACN,GAAG,uBAAuB;QAC1B,QAAQ;KACR,CAAC;AACH,CAAC,CAAC;AAtGW,QAAA,0BAA0B,8BAsGrC","sourcesContent":["import {\n\tPostOnlyParams,\n\tMarketType,\n\tBN,\n\tOptionalOrderParams,\n\tBigNum,\n\tPRICE_PRECISION_EXP,\n\tgetLimitOrderParams,\n\tBASE_PRECISION,\n\toraclePriceBands as getOraclePriceBands,\n\tDriftClient,\n\tUser,\n\tPositionDirection,\n} from '@drift-labs/sdk';\nimport {\n\tORDER_COMMON_UTILS,\n\tCOMMON_UI_UTILS,\n\tHighLeverageOptions,\n} from '../../../../../common-ui-utils';\nimport { DEFAULT_LIMIT_AUCTION_DURATION } from '../../../constants/auction';\nimport { ENUM_UTILS } from '../../../../../utils';\nimport invariant from 'tiny-invariant';\nimport { fetchAuctionOrderParams } from './dlobServer';\nimport { LimitOrderParamsOrderConfig, LimitAuctionConfig } from './types';\n\nexport const getLimitAuctionOrderParams = async ({\n\tdriftClient,\n\tuser,\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tbaseAssetAmount,\n\tuserOrderId = 0,\n\treduceOnly = false,\n\tpostOnly = PostOnlyParams.NONE,\n\torderConfig,\n\thighLeverageOptions,\n}: {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tdirection: PositionDirection;\n\tbaseAssetAmount: BN;\n\tuserOrderId?: number;\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\torderConfig: LimitOrderParamsOrderConfig & {\n\t\tlimitAuction: LimitAuctionConfig;\n\t};\n\thighLeverageOptions?: HighLeverageOptions;\n}): Promise<OptionalOrderParams> => {\n\tconst orderParams = await fetchAuctionOrderParams({\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType: 'base',\n\t\tmarketIndex,\n\t\tmarketType,\n\t\tdirection,\n\t\tamount: baseAssetAmount,\n\t\tdlobServerHttpUrl: orderConfig.limitAuction.dlobServerHttpUrl,\n\t\toptionalAuctionParamsInputs:\n\t\t\torderConfig.limitAuction.optionalLimitAuctionParams,\n\t});\n\n\tconst isPerp = ENUM_UTILS.match(marketType, MarketType.PERP);\n\n\tinvariant(orderConfig.limitAuction.oraclePrice, 'Oracle price not found');\n\tinvariant(orderParams.auctionStartPrice, 'Auction start price not found');\n\n\tlet oraclePriceBands: [BN, BN] | undefined = undefined;\n\tlet auctionDuration = DEFAULT_LIMIT_AUCTION_DURATION;\n\n\tif (isPerp) {\n\t\tconst perpMarketAccount = driftClient.getPerpMarketAccount(marketIndex);\n\t\tinvariant(isPerp && perpMarketAccount, 'Perp market account not found');\n\n\t\toraclePriceBands = orderConfig.limitAuction.oraclePrice\n\t\t\t? getOraclePriceBands(perpMarketAccount, {\n\t\t\t\t\tprice: orderConfig.limitAuction.oraclePrice,\n\t\t\t })\n\t\t\t: undefined;\n\n\t\tauctionDuration = ORDER_COMMON_UTILS.getPerpAuctionDuration(\n\t\t\torderConfig.limitPrice.sub(orderParams.auctionStartPrice).abs(),\n\t\t\torderConfig.limitAuction.oraclePrice,\n\t\t\tperpMarketAccount.contractTier\n\t\t);\n\t}\n\n\tconst limitAuctionParams = COMMON_UI_UTILS.getLimitAuctionParams({\n\t\tdirection,\n\t\tinputPrice: BigNum.from(orderConfig.limitPrice, PRICE_PRECISION_EXP),\n\t\tstartPriceFromSettings: orderParams.auctionStartPrice,\n\t\tduration: auctionDuration,\n\t\tauctionStartPriceOffset: orderConfig.limitAuction.auctionStartPriceOffset,\n\t\toraclePriceBands,\n\t});\n\n\tconst limitAuctionOrderParams = getLimitOrderParams({\n\t\tmarketIndex,\n\t\tmarketType,\n\t\tdirection,\n\t\tbaseAssetAmount,\n\t\treduceOnly,\n\t\tpostOnly,\n\t\tprice: orderConfig.limitPrice,\n\t\tuserOrderId,\n\t\t...limitAuctionParams,\n\t});\n\n\tconst oraclePrice = driftClient.getOracleDataForPerpMarket(marketIndex).price;\n\tconst totalQuoteAmount = baseAssetAmount.mul(oraclePrice).div(BASE_PRECISION);\n\n\tconst bitFlags = ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(\n\t\tmarketIndex,\n\t\tdriftClient,\n\t\tuser,\n\t\ttotalQuoteAmount,\n\t\tdirection,\n\t\thighLeverageOptions\n\t);\n\n\treturn {\n\t\t...limitAuctionOrderParams,\n\t\tbitFlags,\n\t};\n};\n"]}
1
+ {"version":3,"file":"auction.js","sourceRoot":"","sources":["../../../../../../src/drift/base/actions/trade/openPerpOrder/auction.ts"],"names":[],"mappings":";;;;;;AAAA,yCAYyB;AACzB,oEAIwC;AACxC,wDAA4E;AAC5E,gDAAkD;AAClD,oEAAuC;AACvC,6CAAuD;AAIhD,MAAM,0BAA0B,GAAG,KAAK,EAAE,EAChD,WAAW,EACX,IAAI,EACJ,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,WAAW,GAAG,CAAC,EACf,UAAU,GAAG,KAAK,EAClB,QAAQ,GAAG,oBAAc,CAAC,IAAI,EAC9B,WAAW,EACX,mBAAmB,EACnB,sBAAsB,GAiBtB,EAAgC,EAAE;IAClC,MAAM,WAAW,GAAG,MAAM,IAAA,oCAAuB,EAAC;QACjD,WAAW;QACX,IAAI;QACJ,SAAS,EAAE,MAAM;QACjB,WAAW;QACX,UAAU;QACV,SAAS;QACT,MAAM,EAAE,eAAe;QACvB,UAAU;QACV,iBAAiB,EAAE,WAAW,CAAC,YAAY,CAAC,iBAAiB;QAC7D,2BAA2B,EAC1B,WAAW,CAAC,YAAY,CAAC,0BAA0B;QACpD,sBAAsB,EAAE,sBAAsB;KAC9C,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,kBAAU,CAAC,KAAK,CAAC,UAAU,EAAE,gBAAU,CAAC,IAAI,CAAC,CAAC;IAE7D,IAAA,wBAAS,EAAC,WAAW,CAAC,YAAY,CAAC,WAAW,E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,kBAAkB;KACrB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,oCAAkB,CAAC,0BAA0B,CAC7D,WAAW,EACX,WAAW,EACX,IAAI,EACJ,mBAAmB,EACnB,mBAAmB,CACnB,CAAC;IAEF,OAAO;QACN,GAAG,uBAAuB;QAC1B,QAAQ;KACR,CAAC;AACH,CAAC,CAAC;AAxGW,QAAA,0BAA0B,8BAwGrC","sourcesContent":["import {\n\tPostOnlyParams,\n\tMarketType,\n\tBN,\n\tOptionalOrderParams,\n\tBigNum,\n\tPRICE_PRECISION_EXP,\n\tgetLimitOrderParams,\n\toraclePriceBands as getOraclePriceBands,\n\tDriftClient,\n\tUser,\n\tPositionDirection,\n} from '@drift-labs/sdk';\nimport {\n\tORDER_COMMON_UTILS,\n\tCOMMON_UI_UTILS,\n\tHighLeverageOptions,\n} from '../../../../../common-ui-utils';\nimport { DEFAULT_LIMIT_AUCTION_DURATION } from '../../../constants/auction';\nimport { ENUM_UTILS } from '../../../../../utils';\nimport invariant from 'tiny-invariant';\nimport { fetchAuctionOrderParams } from './dlobServer';\nimport { LimitOrderParamsOrderConfig, LimitAuctionConfig } from './types';\nimport { AuctionParamsFetchedCallback } from '../../../../utils/auctionParamsResponseMapper';\n\nexport const getLimitAuctionOrderParams = async ({\n\tdriftClient,\n\tuser,\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tbaseAssetAmount,\n\tpositionMaxLeverage,\n\tuserOrderId = 0,\n\treduceOnly = false,\n\tpostOnly = PostOnlyParams.NONE,\n\torderConfig,\n\thighLeverageOptions,\n\tonAuctionParamsFetched,\n}: {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tdirection: PositionDirection;\n\tbaseAssetAmount: BN;\n\tpositionMaxLeverage: number;\n\tuserOrderId?: number;\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\torderConfig: LimitOrderParamsOrderConfig & {\n\t\tlimitAuction: LimitAuctionConfig;\n\t};\n\thighLeverageOptions?: HighLeverageOptions;\n\tonAuctionParamsFetched?: AuctionParamsFetchedCallback;\n}): Promise<OptionalOrderParams> => {\n\tconst orderParams = await fetchAuctionOrderParams({\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType: 'base',\n\t\tmarketIndex,\n\t\tmarketType,\n\t\tdirection,\n\t\tamount: baseAssetAmount,\n\t\treduceOnly,\n\t\tdlobServerHttpUrl: orderConfig.limitAuction.dlobServerHttpUrl,\n\t\toptionalAuctionParamsInputs:\n\t\t\torderConfig.limitAuction.optionalLimitAuctionParams,\n\t\tonAuctionParamsFetched: onAuctionParamsFetched,\n\t});\n\n\tconst isPerp = ENUM_UTILS.match(marketType, MarketType.PERP);\n\n\tinvariant(orderConfig.limitAuction.oraclePrice, 'Oracle price not found');\n\tinvariant(orderParams.auctionStartPrice, 'Auction start price not found');\n\n\tlet oraclePriceBands: [BN, BN] | undefined = undefined;\n\tlet auctionDuration = DEFAULT_LIMIT_AUCTION_DURATION;\n\n\tif (isPerp) {\n\t\tconst perpMarketAccount = driftClient.getPerpMarketAccount(marketIndex);\n\t\tinvariant(isPerp && perpMarketAccount, 'Perp market account not found');\n\n\t\toraclePriceBands = orderConfig.limitAuction.oraclePrice\n\t\t\t? getOraclePriceBands(perpMarketAccount, {\n\t\t\t\t\tprice: orderConfig.limitAuction.oraclePrice,\n\t\t\t })\n\t\t\t: undefined;\n\n\t\tauctionDuration = ORDER_COMMON_UTILS.getPerpAuctionDuration(\n\t\t\torderConfig.limitPrice.sub(orderParams.auctionStartPrice).abs(),\n\t\t\torderConfig.limitAuction.oraclePrice,\n\t\t\tperpMarketAccount.contractTier\n\t\t);\n\t}\n\n\tconst limitAuctionParams = COMMON_UI_UTILS.getLimitAuctionParams({\n\t\tdirection,\n\t\tinputPrice: BigNum.from(orderConfig.limitPrice, PRICE_PRECISION_EXP),\n\t\tstartPriceFromSettings: orderParams.auctionStartPrice,\n\t\tduration: auctionDuration,\n\t\tauctionStartPriceOffset: orderConfig.limitAuction.auctionStartPriceOffset,\n\t\toraclePriceBands,\n\t});\n\n\tconst limitAuctionOrderParams = getLimitOrderParams({\n\t\tmarketIndex,\n\t\tmarketType,\n\t\tdirection,\n\t\tbaseAssetAmount,\n\t\treduceOnly,\n\t\tpostOnly,\n\t\tprice: orderConfig.limitPrice,\n\t\tuserOrderId,\n\t\t...limitAuctionParams,\n\t});\n\n\tconst bitFlags = ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(\n\t\tmarketIndex,\n\t\tdriftClient,\n\t\tuser,\n\t\tpositionMaxLeverage,\n\t\thighLeverageOptions\n\t);\n\n\treturn {\n\t\t...limitAuctionOrderParams,\n\t\tbitFlags,\n\t};\n};\n"]}
@@ -1,11 +1,11 @@
1
1
  import { DriftClient, User, BN, PositionDirection, OptionalOrderParams, MarketType, UserAccount, PublicKey } from '@drift-labs/sdk';
2
+ import { AuctionParamsFetchedCallback } from '../../../../../utils/auctionParamsResponseMapper';
2
3
  import { MarketId, TradeOffsetPrice } from '../../../../../../types';
3
4
  import { DynamicSlippageConfig } from '../../../../../../utils/orderbook';
4
5
  import { L2WithOracleAndMarketData } from '../../../../../../utils/orderbook/types';
5
6
  export interface OptionalAuctionParamsRequestInputs {
6
7
  maxLeverageSelected?: boolean;
7
8
  maxLeverageOrderSize?: BN;
8
- reduceOnly?: boolean;
9
9
  auctionDuration?: number;
10
10
  auctionStartPriceOffset?: number;
11
11
  auctionEndPriceOffset?: number;
@@ -24,9 +24,11 @@ interface RegularOrderParams {
24
24
  marketIndex: number;
25
25
  direction: PositionDirection;
26
26
  amount: BN;
27
- optionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;
28
27
  dlobServerHttpUrl: string;
28
+ reduceOnly?: boolean;
29
+ optionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;
29
30
  dynamicSlippageConfig?: DynamicSlippageConfig;
31
+ onAuctionParamsFetched?: AuctionParamsFetchedCallback;
30
32
  }
31
33
  export interface BulkL2FetchingQueryParams {
32
34
  marketIndex: number;
@@ -54,11 +56,11 @@ export declare function fetchAuctionOrderParams(params: RegularOrderParams): Pro
54
56
  /**
55
57
  * Fetches auction order parameters from the auction params endpoint
56
58
  */
57
- export declare function fetchAuctionOrderParamsFromDlob({ marketIndex, marketType, direction, amount, dlobServerHttpUrl, assetType, driftClient, optionalAuctionParamsInputs, }: RegularOrderParams): Promise<OptionalOrderParams>;
59
+ export declare function fetchAuctionOrderParamsFromDlob({ marketIndex, marketType, direction, amount, dlobServerHttpUrl, assetType, driftClient, reduceOnly, optionalAuctionParamsInputs, }: RegularOrderParams): Promise<OptionalOrderParams>;
58
60
  /**
59
61
  * Fetches auction order parameters from the L2 data
60
62
  */
61
- export declare function fetchAuctionOrderParamsFromL2({ dlobServerHttpUrl, marketIndex, marketType, direction, assetType, amount, optionalAuctionParamsInputs, driftClient, dynamicSlippageConfig, }: RegularOrderParams): Promise<OptionalOrderParams>;
63
+ export declare function fetchAuctionOrderParamsFromL2({ dlobServerHttpUrl, marketIndex, marketType, direction, assetType, amount, reduceOnly, optionalAuctionParamsInputs, driftClient, dynamicSlippageConfig, }: RegularOrderParams): Promise<OptionalOrderParams>;
62
64
  type FetchTopMakersParams = {
63
65
  dlobServerHttpUrl: string;
64
66
  marketIndex: number;
@@ -106,8 +106,8 @@ const calcBaseFromQuote = (driftClient, marketType, marketIndex, amount) => {
106
106
  /**
107
107
  * Fetches auction order parameters from the auction params endpoint
108
108
  */
109
- async function fetchAuctionOrderParamsFromDlob({ marketIndex, marketType, direction, amount, dlobServerHttpUrl, assetType, driftClient, optionalAuctionParamsInputs = {}, }) {
110
- var _a, _b, _c, _d;
109
+ async function fetchAuctionOrderParamsFromDlob({ marketIndex, marketType, direction, amount, dlobServerHttpUrl, assetType, driftClient, reduceOnly, optionalAuctionParamsInputs = {}, }) {
110
+ var _a, _b, _c;
111
111
  const baseAmount = assetType === 'base'
112
112
  ? amount
113
113
  : calcBaseFromQuote(driftClient, marketType, marketIndex, amount);
@@ -119,6 +119,7 @@ async function fetchAuctionOrderParamsFromDlob({ marketIndex, marketType, direct
119
119
  marketIndex: marketIndex.toString(),
120
120
  direction: utils_1.ENUM_UTILS.toStr(direction),
121
121
  amount: baseAmount.toString(),
122
+ reduceOnly: reduceOnly ? 'true' : 'false',
122
123
  };
123
124
  // Add defined optional parameters
124
125
  Object.entries(optionalAuctionParamsInputs).forEach(([key, value]) => {
@@ -149,7 +150,7 @@ async function fetchAuctionOrderParamsFromDlob({ marketIndex, marketType, direct
149
150
  postOnly: (_b = mappedParams.postOnly) !== null && _b !== void 0 ? _b : sdk_1.DefaultOrderParams.postOnly,
150
151
  triggerPrice: mappedParams.triggerPrice || null,
151
152
  triggerCondition: (_c = mappedParams.triggerCondition) !== null && _c !== void 0 ? _c : sdk_1.DefaultOrderParams.triggerCondition,
152
- oraclePriceOffset: ((_d = mappedParams.oraclePriceOffset) === null || _d === void 0 ? void 0 : _d.toNumber()) || null,
153
+ oraclePriceOffset: mappedParams.oraclePriceOffset || null,
153
154
  auctionDuration: mappedParams.auctionDuration || null,
154
155
  maxTs: mappedParams.maxTs,
155
156
  auctionStartPrice: mappedParams.auctionStartPrice || null,
@@ -162,7 +163,7 @@ const DEFAULT_L2_DEPTH_FOR_AUCTION_ORDER_PARAMS = 100;
162
163
  /**
163
164
  * Fetches auction order parameters from the L2 data
164
165
  */
165
- async function fetchAuctionOrderParamsFromL2({ dlobServerHttpUrl, marketIndex, marketType, direction, assetType, amount, optionalAuctionParamsInputs, driftClient, dynamicSlippageConfig, }) {
166
+ async function fetchAuctionOrderParamsFromL2({ dlobServerHttpUrl, marketIndex, marketType, direction, assetType, amount, reduceOnly, optionalAuctionParamsInputs, driftClient, dynamicSlippageConfig, }) {
166
167
  const marketId = new types_1.MarketId(marketIndex, marketType);
167
168
  const baseAmount = assetType === 'base'
168
169
  ? amount
@@ -206,7 +207,7 @@ async function fetchAuctionOrderParamsFromL2({ dlobServerHttpUrl, marketIndex, m
206
207
  maxLeverageSelected: optionalAuctionParamsInputs.maxLeverageSelected,
207
208
  maxLeverageOrderSize: optionalAuctionParamsInputs.maxLeverageOrderSize,
208
209
  baseAmount: baseAmount,
209
- reduceOnly: optionalAuctionParamsInputs.reduceOnly,
210
+ reduceOnly: reduceOnly,
210
211
  allowInfSlippage: false,
211
212
  oraclePrice: oraclePriceBn,
212
213
  bestPrice: priceImpactData.bestPrice,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/dlobServer/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAayB;AACzB,mDAAqD;AACrD,kGAI0D;AAC1D,yDAAkE;AAClE,mDAAqE;AACrE,iEAK2C;AAK3C,uFAAoF;AACpF,qEAAiF;AACjF,uEAAoE;AACpE,oEAAuC;AAgDvC,MAAM,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEtE;;GAEG;AACH,SAAgB,0BAA0B,CACzC,iBAAyB,EACzB,OAGG,EACH,YAAqB,EACrB,0BAA0B,GAAG,KAAK;IAElC,MAAM,MAAM,GAAyB;QACpC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5B,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW;YACnC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa;YACpC,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM;YAC9B,cAAc,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM;YACjC,YAAY,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM;YAC/B,eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM;YAClC,aAAa,EAAE,IAAI;YACnB,iBAAiB,EAAE,CAAC,0BAA0B;SAC9C,CAAC,CAAC;QACH,QAAQ,EAAE,YAAY;KACtB,CAAC;IAEF,MAAM,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n\tUserAccount,\n\tPublicKey,\n\tdecodeUser,\n\tDefaultOrderParams,\n\tBASE_PRECISION,\n\tTEN,\n} from '@drift-labs/sdk';\nimport { ENUM_UTILS } from '../../../../../../utils';\nimport {\n\tmapAuctionParamsResponse,\n\tServerAuctionParamsResponse,\n\tMappedAuctionParams,\n} from '../../../../../utils/auctionParamsResponseMapper';\nimport { encodeQueryParams } from '../../../../../../utils/fetch';\nimport { MarketId, TradeOffsetPrice } from '../../../../../../types';\nimport {\n\tconvertToL2OrderBook,\n\tdeserializeL2Response,\n\tcalculateDynamicSlippageFromL2,\n\tDynamicSlippageConfig,\n} from '../../../../../../utils/orderbook';\nimport {\n\tL2WithOracleAndMarketData,\n\tRawL2Output,\n} from '../../../../../../utils/orderbook/types';\nimport { PollingSequenceGuard } from '../../../../../../utils/pollingSequenceGuard';\nimport { calculatePriceImpactFromL2 } from '../../../../../../utils/priceImpact';\nimport { COMMON_UI_UTILS } from '../../../../../../common-ui-utils';\nimport invariant from 'tiny-invariant';\n\nexport interface OptionalAuctionParamsRequestInputs {\n\t// Optional parameters that can override defaults or provide additional configuration\n\tmaxLeverageSelected?: boolean;\n\tmaxLeverageOrderSize?: BN;\n\treduceOnly?: boolean;\n\tauctionDuration?: number;\n\tauctionStartPriceOffset?: number;\n\tauctionEndPriceOffset?: number;\n\tauctionStartPriceOffsetFrom?: TradeOffsetPrice;\n\tauctionEndPriceOffsetFrom?: TradeOffsetPrice;\n\tslippageTolerance?: number | 'dynamic';\n\tisOracleOrder?: boolean;\n\tadditionalEndPriceBuffer?: BN;\n\tforceUpToSlippage?: boolean;\n}\n\ninterface RegularOrderParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tassetType: 'base' | 'quote';\n\tmarketType: MarketType;\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tamount: BN;\n\toptionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;\n\tdlobServerHttpUrl: string;\n\tdynamicSlippageConfig?: DynamicSlippageConfig;\n}\n\nexport interface BulkL2FetchingQueryParams {\n\tmarketIndex: number;\n\tmarketType: string;\n\tdepth: number;\n\tincludeVamm: boolean;\n\tincludePhoenix: boolean;\n\tincludeOpenbook: boolean;\n\tincludeSerum: boolean;\n\tincludeOracle: boolean;\n\tincludeIndicative: boolean;\n}\n\nexport interface BulkL2FetchingParams {\n\tmarkets: BulkL2FetchingQueryParams[];\n\tgrouping?: number;\n}\n\nconst BACKGROUND_L2_POLLING_KEY = Symbol('BACKGROUND_L2_POLLING_KEY');\n\n/**\n * Fetches the L2 data for the given markets and their depth\n */\nexport function fetchBulkMarketsDlobL2Data(\n\tdlobServerHttpUrl: string,\n\tmarkets: {\n\t\tmarketId: MarketId;\n\t\tdepth: number;\n\t}[],\n\tgroupingSize?: number,\n\texcludeIndicativeLiquidity = false\n): Promise<L2WithOracleAndMarketData[]> {\n\tconst params: BulkL2FetchingParams = {\n\t\tmarkets: markets.map((m) => ({\n\t\t\tmarketIndex: m.marketId.marketIndex,\n\t\t\tmarketType: m.marketId.marketTypeStr,\n\t\t\tdepth: m.depth,\n\t\t\tincludeVamm: m.marketId.isPerp,\n\t\t\tincludePhoenix: m.marketId.isSpot,\n\t\t\tincludeSerum: m.marketId.isSpot,\n\t\t\tincludeOpenbook: m.marketId.isSpot,\n\t\t\tincludeOracle: true,\n\t\t\tincludeIndicative: !excludeIndicativeLiquidity,\n\t\t})),\n\t\tgrouping: groupingSize,\n\t};\n\n\tconst queryParamsMap: {\n\t\t[K in keyof BulkL2FetchingQueryParams]: string;\n\t} & {\n\t\tgrouping?: string;\n\t} = {\n\t\tmarketType: params.markets.map((market) => market.marketType).join(','),\n\t\tmarketIndex: params.markets.map((market) => market.marketIndex).join(','),\n\t\tdepth: params.markets.map((market) => market.depth).join(','),\n\t\tincludeVamm: params.markets.map((market) => market.includeVamm).join(','),\n\t\tincludePhoenix: params.markets\n\t\t\t.map((market) => market.includePhoenix)\n\t\t\t.join(','),\n\t\tincludeOpenbook: params.markets\n\t\t\t.map((market) => market.includeOpenbook)\n\t\t\t.join(','),\n\t\tincludeSerum: params.markets.map((market) => market.includeSerum).join(','),\n\t\tgrouping: params.grouping\n\t\t\t? params.markets.map(() => params.grouping).join(',')\n\t\t\t: undefined,\n\t\tincludeOracle: params.markets\n\t\t\t.map((market) => market.includeOracle)\n\t\t\t.join(','),\n\t\tincludeIndicative: params.markets\n\t\t\t.map((market) => market.includeIndicative)\n\t\t\t.join(','),\n\t};\n\n\tconst queryParams = encodeQueryParams(queryParamsMap);\n\n\t// Use cached endpoint when exclusively fetching background markets\n\tconst useCachedEndpoint = !params.markets.some(\n\t\t(market) => market.depth !== 1\n\t);\n\n\tconst endpoint = useCachedEndpoint\n\t\t? `${dlobServerHttpUrl}/batchL2Cache`\n\t\t: `${dlobServerHttpUrl}/batchL2`;\n\n\treturn new Promise<L2WithOracleAndMarketData[]>((resolve, reject) => {\n\t\tPollingSequenceGuard.fetch(BACKGROUND_L2_POLLING_KEY, () => {\n\t\t\treturn fetch(`${endpoint}?${queryParams}`);\n\t\t})\n\t\t\t.then(async (response) => {\n\t\t\t\tconst responseData = await response.json();\n\t\t\t\tconst resultsArray = responseData.l2s as RawL2Output[];\n\t\t\t\tconst deserializedL2 = resultsArray.map(deserializeL2Response);\n\t\t\t\tresolve(deserializedL2);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\treject(error);\n\t\t\t});\n\t});\n}\n\nexport async function fetchAuctionOrderParams(params: RegularOrderParams) {\n\ttry {\n\t\treturn await fetchAuctionOrderParamsFromDlob(params);\n\t} catch (error) {\n\t\tconsole.error(error);\n\t\tconsole.log('Falling back to L2 data');\n\t\treturn await fetchAuctionOrderParamsFromL2(params);\n\t}\n}\n\nconst calcBaseFromQuote = (\n\tdriftClient: DriftClient,\n\tmarketType: MarketType,\n\tmarketIndex: number,\n\tamount: BN\n) => {\n\tconst isPerp = ENUM_UTILS.match(marketType, MarketType.PERP);\n\n\tconst oraclePrice = isPerp\n\t\t? driftClient.getOracleDataForPerpMarket(marketIndex).price\n\t\t: driftClient.getOracleDataForSpotMarket(marketIndex).price;\n\n\tif (isPerp) {\n\t\treturn amount.mul(BASE_PRECISION).div(oraclePrice);\n\t} else {\n\t\tconst spotMarketAccount = driftClient.getSpotMarketAccount(marketIndex);\n\t\tinvariant(spotMarketAccount, 'Spot market account not found');\n\t\tconst precision = TEN.pow(new BN(spotMarketAccount.decimals));\n\t\treturn amount.mul(precision).div(oraclePrice);\n\t}\n};\n\n/**\n * Fetches auction order parameters from the auction params endpoint\n */\nexport async function fetchAuctionOrderParamsFromDlob({\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tamount,\n\tdlobServerHttpUrl,\n\tassetType,\n\tdriftClient,\n\toptionalAuctionParamsInputs = {},\n}: RegularOrderParams): Promise<OptionalOrderParams> {\n\tconst baseAmount =\n\t\tassetType === 'base'\n\t\t\t? amount\n\t\t\t: calcBaseFromQuote(driftClient, marketType, marketIndex, amount);\n\n\t// Build URL parameters for server request\n\tconst urlParamsObject: Record<string, string> = {\n\t\t// Required fields\n\t\tassetType: 'base',\n\t\tmarketType: ENUM_UTILS.toStr(marketType),\n\t\tmarketIndex: marketIndex.toString(),\n\t\tdirection: ENUM_UTILS.toStr(direction),\n\t\tamount: baseAmount.toString(),\n\t};\n\n\t// Add defined optional parameters\n\tObject.entries(optionalAuctionParamsInputs).forEach(([key, value]) => {\n\t\tif (value !== undefined) {\n\t\t\turlParamsObject[key] = value.toString();\n\t\t}\n\t});\n\n\tconst urlParams = encodeQueryParams(urlParamsObject);\n\n\t// Get order params from server\n\tconst requestUrl = `${dlobServerHttpUrl}/auctionParams?${urlParams.toString()}`;\n\tconst response = await fetch(requestUrl);\n\n\tif (!response.ok) {\n\t\tthrow new Error(\n\t\t\t`Server responded with ${response.status}: ${response.statusText}`\n\t\t);\n\t}\n\n\tconst serverResponse: ServerAuctionParamsResponse = await response.json();\n\tconst serverAuctionParams = serverResponse?.data?.params;\n\tinvariant(serverAuctionParams, 'Server auction params are required');\n\tconst mappedParams: MappedAuctionParams =\n\t\tmapAuctionParamsResponse(serverAuctionParams);\n\n\t// Convert MappedAuctionParams to OptionalOrderParams\n\treturn {\n\t\torderType: mappedParams.orderType,\n\t\tmarketType: mappedParams.marketType,\n\t\tuserOrderId: mappedParams.userOrderId,\n\t\tdirection: mappedParams.direction,\n\t\tbaseAssetAmount: mappedParams.baseAssetAmount,\n\t\tmarketIndex: mappedParams.marketIndex,\n\t\treduceOnly: mappedParams.reduceOnly,\n\t\tpostOnly: mappedParams.postOnly ?? DefaultOrderParams.postOnly,\n\t\ttriggerPrice: mappedParams.triggerPrice || null,\n\t\ttriggerCondition:\n\t\t\tmappedParams.triggerCondition ?? DefaultOrderParams.triggerCondition,\n\t\toraclePriceOffset: mappedParams.oraclePriceOffset?.toNumber() || null,\n\t\tauctionDuration: mappedParams.auctionDuration || null,\n\t\tmaxTs: mappedParams.maxTs,\n\t\tauctionStartPrice: mappedParams.auctionStartPrice || null,\n\t\tauctionEndPrice: mappedParams.auctionEndPrice || null,\n\t\t// no price, because market orders don't need a price\n\t};\n}\n\nconst DEFAULT_L2_DEPTH_FOR_AUCTION_ORDER_PARAMS = 100;\n\n/**\n * Fetches auction order parameters from the L2 data\n */\nexport async function fetchAuctionOrderParamsFromL2({\n\tdlobServerHttpUrl,\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tassetType,\n\tamount,\n\toptionalAuctionParamsInputs,\n\tdriftClient,\n\tdynamicSlippageConfig,\n}: RegularOrderParams): Promise<OptionalOrderParams> {\n\tconst marketId = new MarketId(marketIndex, marketType);\n\tconst baseAmount =\n\t\tassetType === 'base'\n\t\t\t? amount\n\t\t\t: calcBaseFromQuote(driftClient, marketType, marketIndex, amount);\n\n\tconst l2DataResponse = await fetchBulkMarketsDlobL2Data(dlobServerHttpUrl, [\n\t\t{\n\t\t\tmarketId,\n\t\t\tdepth: DEFAULT_L2_DEPTH_FOR_AUCTION_ORDER_PARAMS,\n\t\t},\n\t]);\n\tconst oraclePriceData = l2DataResponse[0].oracleData;\n\tconst oraclePriceBn = oraclePriceData?.price;\n\tconst markPriceBn = l2DataResponse[0].markPrice;\n\tconst l2Data = convertToL2OrderBook(l2DataResponse);\n\n\tconst priceImpactData = calculatePriceImpactFromL2(\n\t\tmarketId,\n\t\tdirection,\n\t\tbaseAmount,\n\t\tl2Data,\n\t\toraclePriceBn\n\t);\n\n\tconst startPrices = COMMON_UI_UTILS.getPriceObject({\n\t\toraclePrice: oraclePriceBn,\n\t\tbestOffer: priceImpactData.bestPrice,\n\t\tentryPrice: priceImpactData.entryPrice,\n\t\tworstPrice: priceImpactData.worstPrice,\n\t\tmarkPrice: markPriceBn,\n\t\tdirection: direction,\n\t});\n\tconst slippageToleranceInput = optionalAuctionParamsInputs.slippageTolerance;\n\tconst derivedSlippage =\n\t\tslippageToleranceInput === 'dynamic'\n\t\t\t? calculateDynamicSlippageFromL2({\n\t\t\t\t\tl2Data,\n\t\t\t\t\tmarketId,\n\t\t\t\t\tstartPrice:\n\t\t\t\t\t\tstartPrices[\n\t\t\t\t\t\t\toptionalAuctionParamsInputs.auctionStartPriceOffsetFrom as keyof typeof startPrices\n\t\t\t\t\t\t],\n\t\t\t\t\tworstPrice: priceImpactData.worstPrice,\n\t\t\t\t\toraclePrice: oraclePriceBn,\n\t\t\t\t\tdynamicSlippageConfig,\n\t\t\t })\n\t\t\t: typeof slippageToleranceInput === 'number'\n\t\t\t? slippageToleranceInput\n\t\t\t: 0.005;\n\n\tconst auctionOrderParams = COMMON_UI_UTILS.deriveMarketOrderParams({\n\t\tmarketType: marketType,\n\t\tmarketIndex: marketIndex,\n\t\tdirection: direction,\n\t\tmaxLeverageSelected: optionalAuctionParamsInputs.maxLeverageSelected,\n\t\tmaxLeverageOrderSize: optionalAuctionParamsInputs.maxLeverageOrderSize,\n\t\tbaseAmount: baseAmount,\n\t\treduceOnly: optionalAuctionParamsInputs.reduceOnly,\n\t\tallowInfSlippage: false,\n\t\toraclePrice: oraclePriceBn,\n\t\tbestPrice: priceImpactData.bestPrice,\n\t\tentryPrice: priceImpactData.entryPrice,\n\t\tworstPrice: priceImpactData.worstPrice,\n\t\tmarkPrice: markPriceBn,\n\t\tauctionDuration: optionalAuctionParamsInputs.auctionDuration,\n\t\tauctionStartPriceOffset:\n\t\t\toptionalAuctionParamsInputs.auctionStartPriceOffset,\n\t\tauctionEndPriceOffset: optionalAuctionParamsInputs.auctionEndPriceOffset,\n\t\tauctionStartPriceOffsetFrom:\n\t\t\toptionalAuctionParamsInputs.auctionStartPriceOffsetFrom,\n\t\tauctionEndPriceOffsetFrom:\n\t\t\toptionalAuctionParamsInputs.auctionEndPriceOffsetFrom,\n\t\tslippageTolerance: derivedSlippage,\n\t\tisOracleOrder: optionalAuctionParamsInputs.isOracleOrder,\n\t\tadditionalEndPriceBuffer:\n\t\t\toptionalAuctionParamsInputs.additionalEndPriceBuffer,\n\t\tforceUpToSlippage: optionalAuctionParamsInputs.forceUpToSlippage,\n\t});\n\n\tif (!auctionOrderParams) {\n\t\tthrow new Error('Failed to derive auction params from L2');\n\t}\n\n\treturn auctionOrderParams;\n}\n\ntype FetchTopMakersParams = {\n\tdlobServerHttpUrl: string;\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tside: 'bid' | 'ask';\n\tlimit: number;\n};\n\n/**\n * Fetches the top makers information, for use as inputs in placeAndTake market orders.\n * The side of the request should be opposite of the side of the placeAndTake market order.\n */\nexport async function fetchTopMakers(params: FetchTopMakersParams): Promise<\n\t{\n\t\tuserAccountPubKey: PublicKey;\n\t\tuserAccount: UserAccount;\n\t}[]\n> {\n\ttry {\n\t\tconst { dlobServerHttpUrl, marketIndex, marketType, side, limit } = params;\n\n\t\tconst urlParams = encodeQueryParams({\n\t\t\tmarketIndex: marketIndex.toString(),\n\t\t\tmarketType: ENUM_UTILS.toStr(marketType),\n\t\t\tside,\n\t\t\tlimit: limit.toString(),\n\t\t\tincludeAccounts: 'true',\n\t\t});\n\n\t\tconst requestUrl = `${dlobServerHttpUrl}/topMakers?${urlParams}`;\n\t\tconst response = await fetch(requestUrl);\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(\n\t\t\t\t`Server responded with ${response.status}: ${response.statusText}`\n\t\t\t);\n\t\t}\n\n\t\tconst serverResponse: {\n\t\t\tuserAccountPubKey: string;\n\t\t\taccountBase64: string;\n\t\t}[] = await response.json();\n\t\tconst mappedParams: {\n\t\t\tuserAccountPubKey: PublicKey;\n\t\t\tuserAccount: UserAccount;\n\t\t}[] = serverResponse.map((value) => ({\n\t\t\tuserAccountPubKey: new PublicKey(value.userAccountPubKey),\n\t\t\tuserAccount: decodeUser(Buffer.from(value.accountBase64, 'base64')),\n\t\t}));\n\n\t\treturn mappedParams;\n\t} catch (e) {\n\t\tconsole.error(e);\n\t\treturn [];\n\t}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/dlobServer/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAayB;AACzB,mDAAqD;AACrD,kGAK0D;AAC1D,yDAAkE;AAClE,mDAAqE;AACrE,iEAK2C;AAK3C,uFAAoF;AACpF,qEAAiF;AACjF,uEAAoE;AACpE,oEAAuC;AAiDvC,MAAM,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEtE;;GAEG;AACH,SAAgB,0BAA0B,CACzC,iBAAyB,EACzB,OAGG,EACH,YAAqB,EACrB,0BAA0B,GAAG,KAAK;IAElC,MAAM,MAAM,GAAyB;QACpC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5B,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW;YACnC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa;YACpC,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM;YAC9B,cAAc,EAAE,CAAC,CAAC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AC,CAAC;SACnE,CAAC,CAAC,CAAC;QAEJ,OAAO,YAAY,CAAC;IACrB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC;AA3CD,wCA2CC","sourcesContent":["import {\n\tDriftClient,\n\tUser,\n\tBN,\n\tPositionDirection,\n\tOptionalOrderParams,\n\tMarketType,\n\tUserAccount,\n\tPublicKey,\n\tdecodeUser,\n\tDefaultOrderParams,\n\tBASE_PRECISION,\n\tTEN,\n} from '@drift-labs/sdk';\nimport { ENUM_UTILS } from '../../../../../../utils';\nimport {\n\tmapAuctionParamsResponse,\n\tServerAuctionParamsResponse,\n\tMappedAuctionParams,\n\tAuctionParamsFetchedCallback,\n} from '../../../../../utils/auctionParamsResponseMapper';\nimport { encodeQueryParams } from '../../../../../../utils/fetch';\nimport { MarketId, TradeOffsetPrice } from '../../../../../../types';\nimport {\n\tconvertToL2OrderBook,\n\tdeserializeL2Response,\n\tcalculateDynamicSlippageFromL2,\n\tDynamicSlippageConfig,\n} from '../../../../../../utils/orderbook';\nimport {\n\tL2WithOracleAndMarketData,\n\tRawL2Output,\n} from '../../../../../../utils/orderbook/types';\nimport { PollingSequenceGuard } from '../../../../../../utils/pollingSequenceGuard';\nimport { calculatePriceImpactFromL2 } from '../../../../../../utils/priceImpact';\nimport { COMMON_UI_UTILS } from '../../../../../../common-ui-utils';\nimport invariant from 'tiny-invariant';\n\nexport interface OptionalAuctionParamsRequestInputs {\n\t// Optional parameters that can override defaults or provide additional configuration\n\tmaxLeverageSelected?: boolean;\n\tmaxLeverageOrderSize?: BN;\n\tauctionDuration?: number;\n\tauctionStartPriceOffset?: number;\n\tauctionEndPriceOffset?: number;\n\tauctionStartPriceOffsetFrom?: TradeOffsetPrice;\n\tauctionEndPriceOffsetFrom?: TradeOffsetPrice;\n\tslippageTolerance?: number | 'dynamic';\n\tisOracleOrder?: boolean;\n\tadditionalEndPriceBuffer?: BN;\n\tforceUpToSlippage?: boolean;\n}\n\ninterface RegularOrderParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tassetType: 'base' | 'quote';\n\tmarketType: MarketType;\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tamount: BN;\n\tdlobServerHttpUrl: string;\n\treduceOnly?: boolean;\n\toptionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;\n\tdynamicSlippageConfig?: DynamicSlippageConfig;\n\tonAuctionParamsFetched?: AuctionParamsFetchedCallback;\n}\n\nexport interface BulkL2FetchingQueryParams {\n\tmarketIndex: number;\n\tmarketType: string;\n\tdepth: number;\n\tincludeVamm: boolean;\n\tincludePhoenix: boolean;\n\tincludeOpenbook: boolean;\n\tincludeSerum: boolean;\n\tincludeOracle: boolean;\n\tincludeIndicative: boolean;\n}\n\nexport interface BulkL2FetchingParams {\n\tmarkets: BulkL2FetchingQueryParams[];\n\tgrouping?: number;\n}\n\nconst BACKGROUND_L2_POLLING_KEY = Symbol('BACKGROUND_L2_POLLING_KEY');\n\n/**\n * Fetches the L2 data for the given markets and their depth\n */\nexport function fetchBulkMarketsDlobL2Data(\n\tdlobServerHttpUrl: string,\n\tmarkets: {\n\t\tmarketId: MarketId;\n\t\tdepth: number;\n\t}[],\n\tgroupingSize?: number,\n\texcludeIndicativeLiquidity = false\n): Promise<L2WithOracleAndMarketData[]> {\n\tconst params: BulkL2FetchingParams = {\n\t\tmarkets: markets.map((m) => ({\n\t\t\tmarketIndex: m.marketId.marketIndex,\n\t\t\tmarketType: m.marketId.marketTypeStr,\n\t\t\tdepth: m.depth,\n\t\t\tincludeVamm: m.marketId.isPerp,\n\t\t\tincludePhoenix: m.marketId.isSpot,\n\t\t\tincludeSerum: m.marketId.isSpot,\n\t\t\tincludeOpenbook: m.marketId.isSpot,\n\t\t\tincludeOracle: true,\n\t\t\tincludeIndicative: !excludeIndicativeLiquidity,\n\t\t})),\n\t\tgrouping: groupingSize,\n\t};\n\n\tconst queryParamsMap: {\n\t\t[K in keyof BulkL2FetchingQueryParams]: string;\n\t} & {\n\t\tgrouping?: string;\n\t} = {\n\t\tmarketType: params.markets.map((market) => market.marketType).join(','),\n\t\tmarketIndex: params.markets.map((market) => market.marketIndex).join(','),\n\t\tdepth: params.markets.map((market) => market.depth).join(','),\n\t\tincludeVamm: params.markets.map((market) => market.includeVamm).join(','),\n\t\tincludePhoenix: params.markets\n\t\t\t.map((market) => market.includePhoenix)\n\t\t\t.join(','),\n\t\tincludeOpenbook: params.markets\n\t\t\t.map((market) => market.includeOpenbook)\n\t\t\t.join(','),\n\t\tincludeSerum: params.markets.map((market) => market.includeSerum).join(','),\n\t\tgrouping: params.grouping\n\t\t\t? params.markets.map(() => params.grouping).join(',')\n\t\t\t: undefined,\n\t\tincludeOracle: params.markets\n\t\t\t.map((market) => market.includeOracle)\n\t\t\t.join(','),\n\t\tincludeIndicative: params.markets\n\t\t\t.map((market) => market.includeIndicative)\n\t\t\t.join(','),\n\t};\n\n\tconst queryParams = encodeQueryParams(queryParamsMap);\n\n\t// Use cached endpoint when exclusively fetching background markets\n\tconst useCachedEndpoint = !params.markets.some(\n\t\t(market) => market.depth !== 1\n\t);\n\n\tconst endpoint = useCachedEndpoint\n\t\t? `${dlobServerHttpUrl}/batchL2Cache`\n\t\t: `${dlobServerHttpUrl}/batchL2`;\n\n\treturn new Promise<L2WithOracleAndMarketData[]>((resolve, reject) => {\n\t\tPollingSequenceGuard.fetch(BACKGROUND_L2_POLLING_KEY, () => {\n\t\t\treturn fetch(`${endpoint}?${queryParams}`);\n\t\t})\n\t\t\t.then(async (response) => {\n\t\t\t\tconst responseData = await response.json();\n\t\t\t\tconst resultsArray = responseData.l2s as RawL2Output[];\n\t\t\t\tconst deserializedL2 = resultsArray.map(deserializeL2Response);\n\t\t\t\tresolve(deserializedL2);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\treject(error);\n\t\t\t});\n\t});\n}\n\nexport async function fetchAuctionOrderParams(params: RegularOrderParams) {\n\ttry {\n\t\treturn await fetchAuctionOrderParamsFromDlob(params);\n\t} catch (error) {\n\t\tconsole.error(error);\n\t\tconsole.log('Falling back to L2 data');\n\t\treturn await fetchAuctionOrderParamsFromL2(params);\n\t}\n}\n\nconst calcBaseFromQuote = (\n\tdriftClient: DriftClient,\n\tmarketType: MarketType,\n\tmarketIndex: number,\n\tamount: BN\n) => {\n\tconst isPerp = ENUM_UTILS.match(marketType, MarketType.PERP);\n\n\tconst oraclePrice = isPerp\n\t\t? driftClient.getOracleDataForPerpMarket(marketIndex).price\n\t\t: driftClient.getOracleDataForSpotMarket(marketIndex).price;\n\n\tif (isPerp) {\n\t\treturn amount.mul(BASE_PRECISION).div(oraclePrice);\n\t} else {\n\t\tconst spotMarketAccount = driftClient.getSpotMarketAccount(marketIndex);\n\t\tinvariant(spotMarketAccount, 'Spot market account not found');\n\t\tconst precision = TEN.pow(new BN(spotMarketAccount.decimals));\n\t\treturn amount.mul(precision).div(oraclePrice);\n\t}\n};\n\n/**\n * Fetches auction order parameters from the auction params endpoint\n */\nexport async function fetchAuctionOrderParamsFromDlob({\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tamount,\n\tdlobServerHttpUrl,\n\tassetType,\n\tdriftClient,\n\treduceOnly,\n\toptionalAuctionParamsInputs = {},\n}: RegularOrderParams): Promise<OptionalOrderParams> {\n\tconst baseAmount =\n\t\tassetType === 'base'\n\t\t\t? amount\n\t\t\t: calcBaseFromQuote(driftClient, marketType, marketIndex, amount);\n\n\t// Build URL parameters for server request\n\tconst urlParamsObject: Record<string, string> = {\n\t\t// Required fields\n\t\tassetType: 'base',\n\t\tmarketType: ENUM_UTILS.toStr(marketType),\n\t\tmarketIndex: marketIndex.toString(),\n\t\tdirection: ENUM_UTILS.toStr(direction),\n\t\tamount: baseAmount.toString(),\n\t\treduceOnly: reduceOnly ? 'true' : 'false',\n\t};\n\n\t// Add defined optional parameters\n\tObject.entries(optionalAuctionParamsInputs).forEach(([key, value]) => {\n\t\tif (value !== undefined) {\n\t\t\turlParamsObject[key] = value.toString();\n\t\t}\n\t});\n\n\tconst urlParams = encodeQueryParams(urlParamsObject);\n\n\t// Get order params from server\n\tconst requestUrl = `${dlobServerHttpUrl}/auctionParams?${urlParams.toString()}`;\n\tconst response = await fetch(requestUrl);\n\n\tif (!response.ok) {\n\t\tthrow new Error(\n\t\t\t`Server responded with ${response.status}: ${response.statusText}`\n\t\t);\n\t}\n\n\tconst serverResponse: ServerAuctionParamsResponse = await response.json();\n\tconst serverAuctionParams = serverResponse?.data?.params;\n\tinvariant(serverAuctionParams, 'Server auction params are required');\n\tconst mappedParams: MappedAuctionParams =\n\t\tmapAuctionParamsResponse(serverAuctionParams);\n\n\t// Convert MappedAuctionParams to OptionalOrderParams\n\treturn {\n\t\torderType: mappedParams.orderType,\n\t\tmarketType: mappedParams.marketType,\n\t\tuserOrderId: mappedParams.userOrderId,\n\t\tdirection: mappedParams.direction,\n\t\tbaseAssetAmount: mappedParams.baseAssetAmount,\n\t\tmarketIndex: mappedParams.marketIndex,\n\t\treduceOnly: mappedParams.reduceOnly,\n\t\tpostOnly: mappedParams.postOnly ?? DefaultOrderParams.postOnly,\n\t\ttriggerPrice: mappedParams.triggerPrice || null,\n\t\ttriggerCondition:\n\t\t\tmappedParams.triggerCondition ?? DefaultOrderParams.triggerCondition,\n\t\toraclePriceOffset: mappedParams.oraclePriceOffset || null,\n\t\tauctionDuration: mappedParams.auctionDuration || null,\n\t\tmaxTs: mappedParams.maxTs,\n\t\tauctionStartPrice: mappedParams.auctionStartPrice || null,\n\t\tauctionEndPrice: mappedParams.auctionEndPrice || null,\n\t\t// no price, because market orders don't need a price\n\t};\n}\n\nconst DEFAULT_L2_DEPTH_FOR_AUCTION_ORDER_PARAMS = 100;\n\n/**\n * Fetches auction order parameters from the L2 data\n */\nexport async function fetchAuctionOrderParamsFromL2({\n\tdlobServerHttpUrl,\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tassetType,\n\tamount,\n\treduceOnly,\n\toptionalAuctionParamsInputs,\n\tdriftClient,\n\tdynamicSlippageConfig,\n}: RegularOrderParams): Promise<OptionalOrderParams> {\n\tconst marketId = new MarketId(marketIndex, marketType);\n\tconst baseAmount =\n\t\tassetType === 'base'\n\t\t\t? amount\n\t\t\t: calcBaseFromQuote(driftClient, marketType, marketIndex, amount);\n\n\tconst l2DataResponse = await fetchBulkMarketsDlobL2Data(dlobServerHttpUrl, [\n\t\t{\n\t\t\tmarketId,\n\t\t\tdepth: DEFAULT_L2_DEPTH_FOR_AUCTION_ORDER_PARAMS,\n\t\t},\n\t]);\n\tconst oraclePriceData = l2DataResponse[0].oracleData;\n\tconst oraclePriceBn = oraclePriceData?.price;\n\tconst markPriceBn = l2DataResponse[0].markPrice;\n\tconst l2Data = convertToL2OrderBook(l2DataResponse);\n\n\tconst priceImpactData = calculatePriceImpactFromL2(\n\t\tmarketId,\n\t\tdirection,\n\t\tbaseAmount,\n\t\tl2Data,\n\t\toraclePriceBn\n\t);\n\n\tconst startPrices = COMMON_UI_UTILS.getPriceObject({\n\t\toraclePrice: oraclePriceBn,\n\t\tbestOffer: priceImpactData.bestPrice,\n\t\tentryPrice: priceImpactData.entryPrice,\n\t\tworstPrice: priceImpactData.worstPrice,\n\t\tmarkPrice: markPriceBn,\n\t\tdirection: direction,\n\t});\n\tconst slippageToleranceInput = optionalAuctionParamsInputs.slippageTolerance;\n\tconst derivedSlippage =\n\t\tslippageToleranceInput === 'dynamic'\n\t\t\t? calculateDynamicSlippageFromL2({\n\t\t\t\t\tl2Data,\n\t\t\t\t\tmarketId,\n\t\t\t\t\tstartPrice:\n\t\t\t\t\t\tstartPrices[\n\t\t\t\t\t\t\toptionalAuctionParamsInputs.auctionStartPriceOffsetFrom as keyof typeof startPrices\n\t\t\t\t\t\t],\n\t\t\t\t\tworstPrice: priceImpactData.worstPrice,\n\t\t\t\t\toraclePrice: oraclePriceBn,\n\t\t\t\t\tdynamicSlippageConfig,\n\t\t\t })\n\t\t\t: typeof slippageToleranceInput === 'number'\n\t\t\t? slippageToleranceInput\n\t\t\t: 0.005;\n\n\tconst auctionOrderParams = COMMON_UI_UTILS.deriveMarketOrderParams({\n\t\tmarketType: marketType,\n\t\tmarketIndex: marketIndex,\n\t\tdirection: direction,\n\t\tmaxLeverageSelected: optionalAuctionParamsInputs.maxLeverageSelected,\n\t\tmaxLeverageOrderSize: optionalAuctionParamsInputs.maxLeverageOrderSize,\n\t\tbaseAmount: baseAmount,\n\t\treduceOnly: reduceOnly,\n\t\tallowInfSlippage: false,\n\t\toraclePrice: oraclePriceBn,\n\t\tbestPrice: priceImpactData.bestPrice,\n\t\tentryPrice: priceImpactData.entryPrice,\n\t\tworstPrice: priceImpactData.worstPrice,\n\t\tmarkPrice: markPriceBn,\n\t\tauctionDuration: optionalAuctionParamsInputs.auctionDuration,\n\t\tauctionStartPriceOffset:\n\t\t\toptionalAuctionParamsInputs.auctionStartPriceOffset,\n\t\tauctionEndPriceOffset: optionalAuctionParamsInputs.auctionEndPriceOffset,\n\t\tauctionStartPriceOffsetFrom:\n\t\t\toptionalAuctionParamsInputs.auctionStartPriceOffsetFrom,\n\t\tauctionEndPriceOffsetFrom:\n\t\t\toptionalAuctionParamsInputs.auctionEndPriceOffsetFrom,\n\t\tslippageTolerance: derivedSlippage,\n\t\tisOracleOrder: optionalAuctionParamsInputs.isOracleOrder,\n\t\tadditionalEndPriceBuffer:\n\t\t\toptionalAuctionParamsInputs.additionalEndPriceBuffer,\n\t\tforceUpToSlippage: optionalAuctionParamsInputs.forceUpToSlippage,\n\t});\n\n\tif (!auctionOrderParams) {\n\t\tthrow new Error('Failed to derive auction params from L2');\n\t}\n\n\treturn auctionOrderParams;\n}\n\ntype FetchTopMakersParams = {\n\tdlobServerHttpUrl: string;\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tside: 'bid' | 'ask';\n\tlimit: number;\n};\n\n/**\n * Fetches the top makers information, for use as inputs in placeAndTake market orders.\n * The side of the request should be opposite of the side of the placeAndTake market order.\n */\nexport async function fetchTopMakers(params: FetchTopMakersParams): Promise<\n\t{\n\t\tuserAccountPubKey: PublicKey;\n\t\tuserAccount: UserAccount;\n\t}[]\n> {\n\ttry {\n\t\tconst { dlobServerHttpUrl, marketIndex, marketType, side, limit } = params;\n\n\t\tconst urlParams = encodeQueryParams({\n\t\t\tmarketIndex: marketIndex.toString(),\n\t\t\tmarketType: ENUM_UTILS.toStr(marketType),\n\t\t\tside,\n\t\t\tlimit: limit.toString(),\n\t\t\tincludeAccounts: 'true',\n\t\t});\n\n\t\tconst requestUrl = `${dlobServerHttpUrl}/topMakers?${urlParams}`;\n\t\tconst response = await fetch(requestUrl);\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(\n\t\t\t\t`Server responded with ${response.status}: ${response.statusText}`\n\t\t\t);\n\t\t}\n\n\t\tconst serverResponse: {\n\t\t\tuserAccountPubKey: string;\n\t\t\taccountBase64: string;\n\t\t}[] = await response.json();\n\t\tconst mappedParams: {\n\t\t\tuserAccountPubKey: PublicKey;\n\t\t\tuserAccount: UserAccount;\n\t\t}[] = serverResponse.map((value) => ({\n\t\t\tuserAccountPubKey: new PublicKey(value.userAccountPubKey),\n\t\t\tuserAccount: decodeUser(Buffer.from(value.accountBase64, 'base64')),\n\t\t}));\n\n\t\treturn mappedParams;\n\t} catch (e) {\n\t\tconsole.error(e);\n\t\treturn [];\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { DriftClient, User, BN, PositionDirection, ReferrerInfo } from '@drift-labs/sdk';
1
+ import { DriftClient, User, BN, PositionDirection, ReferrerInfo, OrderType } from '@drift-labs/sdk';
2
2
  import { PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
3
3
  import { SwiftOrderOptions } from '../openSwiftOrder';
4
4
  import { OptionalAuctionParamsRequestInputs } from '../dlobServer';
@@ -6,6 +6,7 @@ import { HighLeverageOptions } from '../../../../../../common-ui-utils/order';
6
6
  import { WithTxnParams } from '../../../../types';
7
7
  import { TxnOrSwiftResult } from '../types';
8
8
  import { PlaceAndTakeParams, OptionalTriggerOrderParams } from '../types';
9
+ import { AuctionParamsFetchedCallback } from '../../../../../utils/auctionParamsResponseMapper';
9
10
  export interface OpenPerpMarketOrderBaseParams {
10
11
  driftClient: DriftClient;
11
12
  user: User;
@@ -14,6 +15,7 @@ export interface OpenPerpMarketOrderBaseParams {
14
15
  direction: PositionDirection;
15
16
  amount: BN;
16
17
  dlobServerHttpUrl: string;
18
+ reduceOnly?: boolean;
17
19
  userOrderId?: number;
18
20
  placeAndTake?: PlaceAndTakeParams;
19
21
  optionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;
@@ -27,7 +29,7 @@ export interface OpenPerpMarketOrderBaseParams {
27
29
  * to update the position's maxMarginRatio before placing the order.
28
30
  * Example: 5 for 5x leverage, 10 for 10x leverage
29
31
  */
30
- positionMaxLeverage?: number;
32
+ positionMaxLeverage: number;
31
33
  /**
32
34
  * If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.
33
35
  * This is only applicable for non-SWIFT orders.
@@ -62,6 +64,9 @@ export interface OpenPerpMarketOrderBaseParams {
62
64
  builderFeeTenthBps: number;
63
65
  };
64
66
  highLeverageOptions?: HighLeverageOptions;
67
+ callbacks?: {
68
+ onAuctionParamsFetched?: AuctionParamsFetchedCallback;
69
+ };
65
70
  }
66
71
  export interface OpenPerpMarketOrderBaseParamsWithSwift extends Omit<OpenPerpMarketOrderBaseParams, 'placeAndTake'> {
67
72
  swiftOptions: SwiftOrderOptions;
@@ -78,12 +83,14 @@ export type OpenPerpMarketOrderParams<T extends boolean = boolean, S extends Omi
78
83
  /**
79
84
  * Creates and submits a Swift (signed message) order. Only available for perp orders.
80
85
  */
81
- export declare function createSwiftMarketOrder({ driftClient, user, assetType, marketIndex, direction, amount, bracketOrders, dlobServerHttpUrl, optionalAuctionParamsInputs, swiftOptions, userOrderId, positionMaxLeverage, builderParams, highLeverageOptions, }: OpenPerpMarketOrderBaseParamsWithSwift): Promise<void>;
86
+ export declare function createSwiftMarketOrder({ driftClient, user, assetType, marketIndex, direction, amount, reduceOnly, bracketOrders, dlobServerHttpUrl, optionalAuctionParamsInputs, swiftOptions, userOrderId, positionMaxLeverage, builderParams, highLeverageOptions, callbacks, }: OpenPerpMarketOrderBaseParamsWithSwift): Promise<void>;
82
87
  /**
83
88
  * Creates a placeAndTake transaction instruction.
84
89
  * Fallbacks to a regular market order if no top makers are found.
85
90
  */
86
- export declare const createPlaceAndTakePerpMarketOrderIx: ({ assetType, direction, dlobServerHttpUrl, marketIndex, driftClient, user, userOrderId, amount, referrerInfo, auctionDurationPercentage, optionalAuctionParamsInputs, mainSignerOverride, highLeverageOptions, }: OpenPerpMarketOrderBaseParams & {
91
+ export declare const createPlaceAndTakePerpMarketOrderIx: ({ assetType, direction, dlobServerHttpUrl, marketIndex, driftClient, user, userOrderId, amount, orderType, price, reduceOnly, referrerInfo, auctionDurationPercentage, optionalAuctionParamsInputs, mainSignerOverride, highLeverageOptions, positionMaxLeverage, callbacks, }: OpenPerpMarketOrderBaseParams & {
92
+ orderType?: OrderType;
93
+ price?: BN;
87
94
  direction: PositionDirection;
88
95
  dlobServerHttpUrl: string;
89
96
  marketIndex: number;
@@ -107,10 +114,10 @@ export declare const createPlaceAndTakePerpMarketOrderIx: ({ assetType, directio
107
114
  * @param optionalAuctionParamsInputs - Optional parameters for auction params endpoint and order configuration
108
115
  * @param positionMaxLeverage - Optional per-market leverage (e.g., 5 for 5x). If provided and different from current,
109
116
  * adds an instruction to update the position's maxMarginRatio before placing the order.
110
- *
117
+ * @param userOrderId - the order ID in terms of incremental fills (usually 0). do NOT use the nextOrderId from the user account. values over 255 will cause the order to fail onchain.
111
118
  * @returns Promise resolving to an array of transaction instructions for regular orders
112
119
  */
113
- export declare const createOpenPerpMarketOrderIxs: ({ driftClient, user, assetType, marketIndex, direction, amount, bracketOrders, dlobServerHttpUrl, placeAndTake, userOrderId, optionalAuctionParamsInputs, positionMaxLeverage, mainSignerOverride, highLeverageOptions, }: OpenPerpMarketOrderBaseParams) => Promise<TransactionInstruction[]>;
120
+ export declare const createOpenPerpMarketOrderIxs: ({ driftClient, user, assetType, marketIndex, direction, amount, reduceOnly, bracketOrders, dlobServerHttpUrl, placeAndTake, userOrderId, optionalAuctionParamsInputs, positionMaxLeverage, mainSignerOverride, highLeverageOptions, callbacks, }: OpenPerpMarketOrderBaseParams) => Promise<TransactionInstruction[]>;
114
121
  /**
115
122
  * Creates a complete transaction for opening a perp market order.
116
123
  *