@drift-labs/common 1.0.47 → 1.0.48
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.
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +8 -4
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.d.ts +4 -2
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/types.js.map +1 -1
- package/lib/drift/Drift/clients/CentralServerDrift/index.js +0 -1
- package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
- package/lib/drift/Drift/clients/CentralServerDrift/types.d.ts +8 -10
- package/lib/drift/Drift/clients/CentralServerDrift/types.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.d.ts +56 -1
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js +102 -4
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +13 -12
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +51 -17
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +14 -7
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +56 -23
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/types.d.ts +10 -6
- package/lib/drift/base/actions/trade/openPerpOrder/types.js.map +1 -1
- package/lib/drift/base/details/user/positionMarginMode.d.ts +8 -0
- package/lib/drift/base/details/user/positionMarginMode.js +18 -0
- package/lib/drift/base/details/user/positionMarginMode.js.map +1 -0
- package/lib/drift/utils/orderParams.d.ts +1 -1
- package/lib/drift/utils/orderParams.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.ts"],"names":[],"mappings":";;;AAAA,yCAUyB;AAOzB,mDAAqD;AACrD,sDAK2B;AAC3B,kEAA6E;AAC7E,8CAIuB;AACvB,mEAGiD;AAGjD,kEAAyE;AAMzE,gEAA0E;AAE1E,wEAAkF;AAmGlF;;;GAGG;AACH,KAAK,UAAU,wBAAwB,CAAC,MAAqC;IAC5E,MAAM,EACL,WAAW,EACX,IAAI,EACJ,SAAS,EACT,WAAW,EACX,SAAS,EACT,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,GAAG,CAAC,EACf,SAAS,GACT,GAAG,MAAM,CAAC;IAEX,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAM,IAAA,oCAAuB,EAAC;QACxD,WAAW;QACX,IAAI;QACJ,SAAS;QACT,WAAW;QACX,UAAU,EAAE,gBAAU,CAAC,IAAI;QAC3B,SAAS;QACT,MAAM;QACN,iBAAiB;QACjB,2BAA2B;QAC3B,UAAU;QACV,sBAAsB,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,sBAAsB;KACzD,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,0BAAkB,CAAC,0BAA0B,CAC7D,WAAW,EACX,WAAW,EACX,IAAI,EACJ,mBAAmB,EACnB,mBAAmB,CACnB,CAAC;IAEF,MAAM,WAAW,GAAG;QACnB,GAAG,kBAAkB;QACrB,WAAW;QACX,QAAQ;KACR,CAAC;IAEF,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IAE1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,EACvC,EAAE;IACjC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAEnD,wDAAwD;IACxD,IAAI,QAAQ,EAAE,CAAC;QACd,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACnE,CAAC;QAED,MAAM,gBAAgB,GAAG,MAAM,sBAAsB,CAAC;YACrD,GAAG,IAAI;YACP,YAAY;SACZ,CAAC,CAAC;QAEH,OAAO,gBAAuC,CAAC;IAChD,CAAC;IAED,MAAM,sBAAsB,GAAG,MAAM,IAAA,oCAA4B,EAAC,IAAI,CAAC,CAAC;IAExE,OAAO,sBAA6C,CAAC;AACtD,CAAC,CAAC;AAtBW,QAAA,yBAAyB,6BAsBpC","sourcesContent":["import {\n\tDriftClient,\n\tUser,\n\tBN,\n\tPositionDirection,\n\tOptionalOrderParams,\n\tMarketType,\n\tgetUserStatsAccountPublicKey,\n\tReferrerInfo,\n\tOrderType,\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 {\n\tprepSignAndSendSwiftOrder,\n\tprepSwiftOrderMessage,\n\tSwiftOrderOptions,\n\tSwiftOrderMessage,\n} from '../openSwiftOrder';\nimport { buildNonMarketOrderParams } from '../../../../../utils/orderParams';\nimport {\n\tfetchAuctionOrderParams,\n\tfetchTopMakers,\n\tOptionalAuctionParamsRequestInputs,\n} from '../dlobServer';\nimport {\n\tHighLeverageOptions,\n\tORDER_COMMON_UTILS,\n} from '../../../../../../common-ui-utils/order';\nimport { WithTxnParams } from '../../../../types';\nimport { TxnOrSwiftResult } from '../types';\nimport { NoTopMakersError } from '../../../../../Drift/constants/errors';\nimport {\n\tPlaceAndTakeParams,\n\tOptionalTriggerOrderParams,\n\tAdditionalIsolatedPositionDeposit,\n} from '../types';\nimport { getPositionMaxLeverageIxIfNeeded } from '../positionMaxLeverage';\nimport { AuctionParamsFetchedCallback } from '../../../../../utils/auctionParamsResponseMapper';\nimport { getIsolatedPositionDepositIxIfNeeded } from '../isolatedPositionDeposit';\n\nexport interface OpenPerpMarketOrderBaseParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tassetType: 'base' | 'quote';\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tamount: BN;\n\tdlobServerHttpUrl: string;\n\treduceOnly?: boolean;\n\t// mainly used for UI order identification\n\tuserOrderId?: number;\n\tplaceAndTake?: PlaceAndTakeParams;\n\toptionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;\n\tbracketOrders?: {\n\t\ttakeProfit?: OptionalTriggerOrderParams;\n\t\tstopLoss?: OptionalTriggerOrderParams;\n\t};\n\t/**\n\t * Optional per-market leverage to set for this position.\n\t * If provided and different from current position's leverage, will add an instruction\n\t * to update the position's maxMarginRatio before placing the order.\n\t * Example: 5 for 5x leverage, 10 for 10x leverage\n\t */\n\tpositionMaxLeverage: number;\n\t/**\n\t * Optional isolated position deposit amount.\n\t * If provided, it will be added to the order params as isolatedPositionDeposit.\n\t * This field is used for opening isolated positions.\n\t */\n\tisolatedPositionDeposit?: BN;\n\t/**\n\t * Additional isolated position deposits needed to top up other\n\t * under-collateralized isolated positions before placing the order.\n\t * Each deposit will create a separate instruction.\n\t */\n\tadditionalIsolatedPositionDeposits?: AdditionalIsolatedPositionDeposit[];\n\t/**\n\t * If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.\n\t * This is only applicable for non-SWIFT orders.\n\t */\n\tmainSignerOverride?: PublicKey;\n\t/**\n\t * Optional builder code parameters for revenue sharing.\n\t * Only applicable for Swift orders.\n\t *\n\t * Prerequisites:\n\t * - User must have initialized a RevenueShareEscrow account\n\t * - Builder must be in the user's approved_builders list\n\t * - builderFeeTenthBps must not exceed the builder's max_fee_tenth_bps\n\t *\n\t * @example\n\t * ```typescript\n\t * builderParams: {\n\t * builderIdx: 0, // First builder in approved list\n\t * builderFeeTenthBps: 50 // 5 bps = 0.05%\n\t * }\n\t * ```\n\t */\n\tbuilderParams?: {\n\t\t/**\n\t\t * Index of the builder in the user's approved_builders list.\n\t\t */\n\t\tbuilderIdx: number;\n\t\t/**\n\t\t * Fee to charge for this order, in tenths of basis points.\n\t\t * Must be <= the builder's max_fee_tenth_bps.\n\t\t */\n\t\tbuilderFeeTenthBps: number;\n\t};\n\thighLeverageOptions?: HighLeverageOptions;\n\tcallbacks?: {\n\t\tonAuctionParamsFetched?: AuctionParamsFetchedCallback;\n\t};\n}\n\nexport interface OpenPerpMarketOrderBaseParamsWithSwift\n\textends Omit<OpenPerpMarketOrderBaseParams, 'placeAndTake'> {\n\tswiftOptions: SwiftOrderOptions;\n}\n\nexport type OpenPerpMarketOrderParams<\n\tT extends boolean = boolean,\n\tS extends Omit<SwiftOrderOptions, 'swiftServerUrl'> = Omit<\n\t\tSwiftOrderOptions,\n\t\t'swiftServerUrl'\n\t>\n> = T extends true\n\t? OpenPerpMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tswiftOptions: S;\n\t\t\tplaceAndTake?: never;\n\t }\n\t: OpenPerpMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tplaceAndTake?: PlaceAndTakeParams;\n\t\t\tswiftOptions?: never;\n\t };\n/**\n * Shared prep logic for swift market orders: validates input, fetches auction params,\n * computes bit flags, and resolves the user account.\n */\nasync function prepSwiftMarketOrderData(params: OpenPerpMarketOrderBaseParams) {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType,\n\t\tmarketIndex,\n\t\tdirection,\n\t\tamount,\n\t\treduceOnly,\n\t\tdlobServerHttpUrl,\n\t\toptionalAuctionParamsInputs,\n\t\tpositionMaxLeverage,\n\t\thighLeverageOptions,\n\t\tuserOrderId = 0,\n\t\tcallbacks,\n\t} = params;\n\n\tif (amount.isZero()) {\n\t\tthrow new Error('Amount must be greater than zero');\n\t}\n\n\tconst fetchedOrderParams = await fetchAuctionOrderParams({\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType,\n\t\tmarketIndex,\n\t\tmarketType: MarketType.PERP,\n\t\tdirection,\n\t\tamount,\n\t\tdlobServerHttpUrl,\n\t\toptionalAuctionParamsInputs,\n\t\treduceOnly,\n\t\tonAuctionParamsFetched: callbacks?.onAuctionParamsFetched,\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\tconst orderParams = {\n\t\t...fetchedOrderParams,\n\t\tuserOrderId,\n\t\tbitFlags,\n\t};\n\n\tconst userAccount = user.getUserAccount();\n\n\treturn { userAccount, orderParams };\n}\n\n/**\n * Creates and submits a Swift (signed message) order. Only available for perp orders.\n */\nexport async function createSwiftMarketOrder(\n\tparams: OpenPerpMarketOrderBaseParamsWithSwift\n): Promise<void> {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tbracketOrders,\n\t\tswiftOptions,\n\t\tpositionMaxLeverage,\n\t\tisolatedPositionDeposit,\n\t\tbuilderParams,\n\t} = params;\n\n\tconst { userAccount, orderParams } = await prepSwiftMarketOrderData(params);\n\n\tawait prepSignAndSendSwiftOrder({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer: swiftOptions.userSigningSlotBuffer,\n\t\tswiftOptions,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: bracketOrders?.takeProfit,\n\t\t\tstopLoss: bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage,\n\t\t\tisolatedPositionDeposit,\n\t\t},\n\t\tbuilderParams,\n\t});\n}\n\nexport type CreateSwiftMarketOrderMessageParams = Omit<\n\tOpenPerpMarketOrderBaseParams,\n\t'placeAndTake' | 'mainSignerOverride'\n> & {\n\tisDelegate?: boolean;\n\tuserSigningSlotBuffer?: number;\n};\n\n/**\n * Prepares a Swift market order message without signing or sending it.\n * Fetches auction params from the DLOB server and creates the prepared message.\n *\n * @returns The prepared SwiftOrderMessage ready for client-side signing and sending\n */\nexport async function createSwiftMarketOrderMessage(\n\tparams: CreateSwiftMarketOrderMessageParams\n): Promise<SwiftOrderMessage> {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tbracketOrders,\n\t\tpositionMaxLeverage,\n\t\tisolatedPositionDeposit,\n\t\tbuilderParams,\n\t\tisDelegate = false,\n\t\tuserSigningSlotBuffer,\n\t} = params;\n\n\tconst { userAccount, orderParams } = await prepSwiftMarketOrderData(params);\n\n\treturn prepSwiftOrderMessage({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer,\n\t\tisDelegate,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: bracketOrders?.takeProfit,\n\t\t\tstopLoss: bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage,\n\t\t\tisolatedPositionDeposit,\n\t\t},\n\t\tbuilderParams,\n\t});\n}\n\n/**\n * Creates a placeAndTake transaction instruction.\n * Fallbacks to a regular market order if no top makers are found.\n */\nexport const createPlaceAndTakePerpMarketOrderIx = async ({\n\tassetType,\n\tdirection,\n\tdlobServerHttpUrl,\n\tmarketIndex,\n\tdriftClient,\n\tuser,\n\tuserOrderId,\n\tamount,\n\torderType,\n\tprice,\n\treduceOnly,\n\treferrerInfo,\n\tauctionDurationPercentage,\n\toptionalAuctionParamsInputs,\n\tmainSignerOverride,\n\thighLeverageOptions,\n\tpositionMaxLeverage,\n\tcallbacks,\n}: OpenPerpMarketOrderBaseParams & {\n\torderType?: OrderType;\n\tprice?: BN;\n\tdirection: PositionDirection;\n\tdlobServerHttpUrl: string;\n\tmarketIndex: number;\n\tdriftClient: DriftClient;\n\tuser: User;\n\treferrerInfo?: ReferrerInfo;\n\tauctionDurationPercentage?: number;\n\thighLeverageOptions?: HighLeverageOptions;\n}) => {\n\tconst counterPartySide = ENUM_UTILS.match(direction, PositionDirection.LONG)\n\t\t? 'ask'\n\t\t: 'bid';\n\n\tconst [fetchedOrderParams, topMakersResult] = await Promise.all([\n\t\tfetchAuctionOrderParams({\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tassetType,\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection,\n\t\t\tamount,\n\t\t\treduceOnly,\n\t\t\tdlobServerHttpUrl,\n\t\t\toptionalAuctionParamsInputs,\n\t\t\tonAuctionParamsFetched: callbacks?.onAuctionParamsFetched,\n\t\t}),\n\t\tfetchTopMakers({\n\t\t\tdlobServerHttpUrl,\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tside: counterPartySide,\n\t\t\tlimit: 4,\n\t\t}),\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\tfetchedOrderParams.bitFlags = bitFlags;\n\tfetchedOrderParams.userOrderId = userOrderId;\n\n\tif (orderType) {\n\t\tfetchedOrderParams.orderType = orderType;\n\t}\n\n\tif (price) {\n\t\tfetchedOrderParams.price = price;\n\t\tfetchedOrderParams.auctionEndPrice = price;\n\t}\n\n\tif (!topMakersResult || topMakersResult.length === 0) {\n\t\tthrow new NoTopMakersError('No top makers found', fetchedOrderParams);\n\t}\n\n\tconst topMakersInfo = topMakersResult.map((maker) => ({\n\t\tmaker: maker.userAccountPubKey,\n\t\tmakerUserAccount: maker.userAccount,\n\t\tmakerStats: getUserStatsAccountPublicKey(\n\t\t\tdriftClient.program.programId,\n\t\t\tmaker.userAccount.authority\n\t\t),\n\t}));\n\n\tconst placeAndTakeIx = await driftClient.getPlaceAndTakePerpOrderIx(\n\t\tfetchedOrderParams,\n\t\ttopMakersInfo,\n\t\treferrerInfo,\n\t\tundefined,\n\t\tauctionDurationPercentage,\n\t\tuser.getUserAccount().subAccountId,\n\t\t{\n\t\t\tauthority: mainSignerOverride,\n\t\t}\n\t);\n\n\treturn placeAndTakeIx;\n};\n\n/**\n * Creates transaction instructions for opening a perp market order.\n * If swiftOptions is provided, it will create a Swift (signed message) order instead.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param assetType - Whether the amount is in base or quote units\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n * @param optionalAuctionParamsInputs - Optional parameters for auction params endpoint and order configuration\n * @param positionMaxLeverage - Optional per-market leverage (e.g., 5 for 5x). If provided and different from current,\n * adds an instruction to update the position's maxMarginRatio before placing the order.\n * @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.\n * @returns Promise resolving to an array of transaction instructions for regular orders\n */\nexport const createOpenPerpMarketOrderIxs = async ({\n\tdriftClient,\n\tuser,\n\tassetType,\n\tmarketIndex,\n\tdirection,\n\tamount,\n\treduceOnly,\n\tbracketOrders,\n\tdlobServerHttpUrl,\n\tplaceAndTake,\n\tuserOrderId,\n\toptionalAuctionParamsInputs = {},\n\tpositionMaxLeverage,\n\tmainSignerOverride,\n\thighLeverageOptions,\n\tisolatedPositionDeposit,\n\tadditionalIsolatedPositionDeposits,\n\tcallbacks,\n}: OpenPerpMarketOrderBaseParams): Promise<TransactionInstruction[]> => {\n\tif (!amount || amount.isZero()) {\n\t\tthrow new Error('Amount must be greater than zero');\n\t}\n\n\tconst allOrders: OptionalOrderParams[] = [];\n\tconst allIxs: TransactionInstruction[] = [];\n\n\tconst leverageIx = await getPositionMaxLeverageIxIfNeeded(\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tpositionMaxLeverage,\n\t\tmainSignerOverride\n\t);\n\tif (leverageIx) {\n\t\tallIxs.push(leverageIx);\n\t}\n\n\t// Add additional isolated position deposit ixs for other under-collateralized positions\n\tif (additionalIsolatedPositionDeposits?.length) {\n\t\tconst additionalDepositIxPromises = additionalIsolatedPositionDeposits.map(\n\t\t\t(deposit) =>\n\t\t\t\tgetIsolatedPositionDepositIxIfNeeded(\n\t\t\t\t\tdriftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tdeposit.marketIndex,\n\t\t\t\t\tdeposit.amount,\n\t\t\t\t\tmainSignerOverride\n\t\t\t\t)\n\t\t);\n\t\tconst additionalDepositIxs = await Promise.all(additionalDepositIxPromises);\n\t\tfor (const ix of additionalDepositIxs) {\n\t\t\tif (ix) {\n\t\t\t\tallIxs.push(ix);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst isolatedPositionDepositIx = await getIsolatedPositionDepositIxIfNeeded(\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tisolatedPositionDeposit,\n\t\tmainSignerOverride\n\t);\n\n\tif (isolatedPositionDepositIx) {\n\t\tallIxs.push(isolatedPositionDepositIx);\n\t}\n\n\tif (placeAndTake?.enable) {\n\t\ttry {\n\t\t\tconst placeAndTakeIx = await createPlaceAndTakePerpMarketOrderIx({\n\t\t\t\tassetType,\n\t\t\t\tamount,\n\t\t\t\tdirection,\n\t\t\t\tdlobServerHttpUrl,\n\t\t\t\tmarketIndex,\n\t\t\t\tdriftClient,\n\t\t\t\tuser,\n\t\t\t\tuserOrderId,\n\t\t\t\treduceOnly,\n\t\t\t\treferrerInfo: placeAndTake.referrerInfo,\n\t\t\t\tauctionDurationPercentage: placeAndTake.auctionDurationPercentage,\n\t\t\t\toptionalAuctionParamsInputs,\n\t\t\t\tmainSignerOverride,\n\t\t\t\tpositionMaxLeverage,\n\t\t\t});\n\t\t\tallIxs.push(placeAndTakeIx);\n\t\t} catch (e) {\n\t\t\tif (e instanceof NoTopMakersError) {\n\t\t\t\t// fallback to regular order\n\t\t\t\tallOrders.push(e.orderParams);\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconst fetchedOrderParams = await fetchAuctionOrderParams({\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tassetType,\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection,\n\t\t\tamount,\n\t\t\tdlobServerHttpUrl,\n\t\t\toptionalAuctionParamsInputs,\n\t\t\treduceOnly,\n\t\t\tonAuctionParamsFetched: callbacks?.onAuctionParamsFetched,\n\t\t});\n\n\t\tconst bitFlags = ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(\n\t\t\tmarketIndex,\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tpositionMaxLeverage,\n\t\t\thighLeverageOptions\n\t\t);\n\n\t\tconst orderParams = {\n\t\t\t...fetchedOrderParams,\n\t\t\tuserOrderId,\n\t\t\tbitFlags,\n\t\t};\n\n\t\tallOrders.push(orderParams);\n\t}\n\n\tconst bracketOrdersDirection = ENUM_UTILS.match(\n\t\tdirection,\n\t\tPositionDirection.LONG\n\t)\n\t\t? PositionDirection.SHORT\n\t\t: PositionDirection.LONG;\n\n\tif (bracketOrders?.takeProfit) {\n\t\tconst takeProfitParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount: bracketOrders.takeProfit.baseAssetAmount ?? amount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'takeProfit',\n\t\t\t\ttriggerPrice: bracketOrders.takeProfit.triggerPrice,\n\t\t\t\tlimitPrice: bracketOrders.takeProfit.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: bracketOrders.takeProfit.reduceOnly ?? true,\n\t\t\tpositionMaxLeverage,\n\t\t});\n\t\tallOrders.push(takeProfitParams);\n\t}\n\n\tif (bracketOrders?.stopLoss) {\n\t\tconst stopLossParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount: bracketOrders.stopLoss.baseAssetAmount ?? amount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'stopLoss',\n\t\t\t\ttriggerPrice: bracketOrders.stopLoss.triggerPrice,\n\t\t\t\tlimitPrice: bracketOrders.stopLoss.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: bracketOrders.stopLoss.reduceOnly ?? true,\n\t\t\tpositionMaxLeverage,\n\t\t});\n\t\tallOrders.push(stopLossParams);\n\t}\n\n\t// Regular order flow - create transaction instruction\n\tif (allOrders.length > 0) {\n\t\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(\n\t\t\tallOrders,\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\tauthority: mainSignerOverride,\n\t\t\t}\n\t\t);\n\t\tallIxs.push(placeOrderIx);\n\t}\n\n\treturn allIxs;\n};\n\n/**\n * Creates a complete transaction for opening a perp market order.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param optionalAuctionParamsInputs - Optional parameters for auction params endpoint and order configuration\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n * @param positionMaxLeverage - Optional per-market leverage (e.g., 5 for 5x). If provided and different from current,\n * includes an instruction to update the position's maxMarginRatio.\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createOpenPerpMarketOrderTxn = async (\n\tparams: WithTxnParams<OpenPerpMarketOrderBaseParams>\n): Promise<Transaction | VersionedTransaction> => {\n\tconst { driftClient } = params;\n\n\t// Regular order flow - create transaction instruction and build transaction\n\tconst placeOrderIxs = await createOpenPerpMarketOrderIxs(params);\n\tconst openPerpMarketOrderTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: placeOrderIxs,\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: params.txParams,\n\t});\n\n\treturn openPerpMarketOrderTxn;\n};\n\n/**\n * Creates a transaction or swift order for a perp market order.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param optionalAuctionParamsInputs - Optional parameters for auction params endpoint and order configuration\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n * @param useSwift - Whether to use Swift (signed message) orders instead of regular transactions\n * @param swiftOptions - Options for Swift (signed message) orders. Required if useSwift is true\n * @param userOrderId - The user order id for UI identification\n * @param positionMaxLeverage - Optional per-market leverage (e.g., 5 for 5x). Only supported for regular transactions (not Swift).\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createOpenPerpMarketOrder = async <T extends boolean>(\n\tparams: WithTxnParams<OpenPerpMarketOrderParams<T, SwiftOrderOptions>>\n): Promise<TxnOrSwiftResult<T>> => {\n\tconst { useSwift, swiftOptions, ...rest } = params;\n\n\t// If useSwift is true, return the Swift result directly\n\tif (useSwift) {\n\t\tif (!swiftOptions) {\n\t\t\tthrow new Error('swiftOptions is required when useSwift is true');\n\t\t}\n\n\t\tconst swiftOrderResult = await createSwiftMarketOrder({\n\t\t\t...rest,\n\t\t\tswiftOptions,\n\t\t});\n\n\t\treturn swiftOrderResult as TxnOrSwiftResult<T>;\n\t}\n\n\tconst openPerpMarketOrderTxn = await createOpenPerpMarketOrderTxn(rest);\n\n\treturn openPerpMarketOrderTxn as TxnOrSwiftResult<T>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.ts"],"names":[],"mappings":";;;AAAA,yCAUyB;AAOzB,mDAAqD;AACrD,sDAK2B;AAC3B,kEAA6E;AAC7E,8CAIuB;AACvB,mEAGiD;AAGjD,kEAAyE;AAEzE,gEAA0E;AAE1E,wEAGoC;AAoGpC;;;GAGG;AACH,KAAK,UAAU,wBAAwB,CAAC,MAAqC;IAC5E,MAAM,EACL,WAAW,EACX,IAAI,EACJ,SAAS,EACT,WAAW,EACX,SAAS,EACT,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,GAAG,CAAC,EACf,SAAS,GACT,GAAG,MAAM,CAAC;IAEX,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAM,IAAA,oCAAuB,EAAC;QACxD,WAAW;QACX,IAAI;QACJ,SAAS;QACT,WAAW;QACX,UAAU,EAAE,gBAAU,CAAC,IAAI;QAC3B,SAAS;QACT,MAAM;QACN,iBAAiB;QACjB,2BAA2B;QAC3B,UAAU;QACV,sBAAsB,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,sBAAsB;KACzD,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,0BAAkB,CAAC,0BAA0B,CAC7D,WAAW,EACX,WAAW,EACX,IAAI,EACJ,mBAAmB,EACnB,mBAAmB,CACnB,CAAC;IAEF,MAAM,WAAW,GAAG;QACnB,GAAG,kBAAkB;QACrB,WAAW;QACX,QAAQ;KACR,CAAC;IAEF,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IAE1C,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IACjC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAEnD,wDAAwD;IACxD,IAAI,QAAQ,EAAE,CAAC;QACd,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACnE,CAAC;QAED,MAAM,gBAAgB,GAAG,MAAM,sBAAsB,CAAC;YACrD,GAAG,IAAI;YACP,YAAY;SACZ,CAAC,CAAC;QAEH,OAAO,gBAAuC,CAAC;IAChD,CAAC;IAED,MAAM,sBAAsB,GAAG,MAAM,IAAA,oCAA4B,EAAC,IAAI,CAAC,CAAC;IAExE,OAAO,sBAA6C,CAAC;AACtD,CAAC,CAAC;AAtBW,QAAA,yBAAyB,6BAsBpC","sourcesContent":["import {\n\tDriftClient,\n\tUser,\n\tBN,\n\tPositionDirection,\n\tOptionalOrderParams,\n\tMarketType,\n\tgetUserStatsAccountPublicKey,\n\tReferrerInfo,\n\tOrderType,\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 {\n\tprepSignAndSendSwiftOrder,\n\tprepSwiftOrderMessage,\n\tSwiftOrderOptions,\n\tSwiftOrderMessage,\n} from '../openSwiftOrder';\nimport { buildNonMarketOrderParams } from '../../../../../utils/orderParams';\nimport {\n\tfetchAuctionOrderParams,\n\tfetchTopMakers,\n\tOptionalAuctionParamsRequestInputs,\n} from '../dlobServer';\nimport {\n\tHighLeverageOptions,\n\tORDER_COMMON_UTILS,\n} from '../../../../../../common-ui-utils/order';\nimport { WithTxnParams } from '../../../../types';\nimport { TxnOrSwiftResult, IsolatedPositionDepositsOverride } from '../types';\nimport { NoTopMakersError } from '../../../../../Drift/constants/errors';\nimport { PlaceAndTakeParams, OptionalTriggerOrderParams } from '../types';\nimport { getPositionMaxLeverageIxIfNeeded } from '../positionMaxLeverage';\nimport { AuctionParamsFetchedCallback } from '../../../../../utils/auctionParamsResponseMapper';\nimport {\n\tgetIsolatedPositionDepositIxIfNeeded,\n\tresolveIsolatedPositionDepositsWithOverride,\n} from '../isolatedPositionDeposit';\n\nexport interface OpenPerpMarketOrderBaseParams {\n\tdriftClient: DriftClient;\n\tuser: User;\n\tassetType: 'base' | 'quote';\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tamount: BN;\n\tdlobServerHttpUrl: string;\n\treduceOnly?: boolean;\n\t// mainly used for UI order identification\n\tuserOrderId?: number;\n\tplaceAndTake?: PlaceAndTakeParams;\n\toptionalAuctionParamsInputs?: OptionalAuctionParamsRequestInputs;\n\tbracketOrders?: {\n\t\ttakeProfit?: OptionalTriggerOrderParams;\n\t\tstopLoss?: OptionalTriggerOrderParams;\n\t};\n\t/**\n\t * Optional per-market leverage to set for this position.\n\t * If provided and different from current position's leverage, will add an instruction\n\t * to update the position's maxMarginRatio before placing the order.\n\t * Example: 5 for 5x leverage, 10 for 10x leverage\n\t */\n\tpositionMaxLeverage: number;\n\t/**\n\t * Position margin mode to use for the order.\n\t * When 'isolated', auto-computes isolated position deposit from positionMaxLeverage,\n\t * and any additional isolated position deposits need to replenish under-collateralized positions.\n\t * If not provided, the position margin mode will be derived from the user's position margin mode,\n\t * and if that does not exist, it will default to 'cross'.\n\t */\n\tmarginMode?: 'isolated' | 'cross';\n\t/**\n\t * Pre-computed isolated position deposits override. When provided,\n\t * skips auto-compute and uses these values directly.\n\t */\n\tisolatedPositionDepositsOverride?: IsolatedPositionDepositsOverride;\n\t/**\n\t * If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.\n\t * This is only applicable for non-SWIFT orders.\n\t */\n\tmainSignerOverride?: PublicKey;\n\t/**\n\t * Optional builder code parameters for revenue sharing.\n\t * Only applicable for Swift orders.\n\t *\n\t * Prerequisites:\n\t * - User must have initialized a RevenueShareEscrow account\n\t * - Builder must be in the user's approved_builders list\n\t * - builderFeeTenthBps must not exceed the builder's max_fee_tenth_bps\n\t *\n\t * @example\n\t * ```typescript\n\t * builderParams: {\n\t * builderIdx: 0, // First builder in approved list\n\t * builderFeeTenthBps: 50 // 5 bps = 0.05%\n\t * }\n\t * ```\n\t */\n\tbuilderParams?: {\n\t\t/**\n\t\t * Index of the builder in the user's approved_builders list.\n\t\t */\n\t\tbuilderIdx: number;\n\t\t/**\n\t\t * Fee to charge for this order, in tenths of basis points.\n\t\t * Must be <= the builder's max_fee_tenth_bps.\n\t\t */\n\t\tbuilderFeeTenthBps: number;\n\t};\n\thighLeverageOptions?: HighLeverageOptions;\n\tcallbacks?: {\n\t\tonAuctionParamsFetched?: AuctionParamsFetchedCallback;\n\t};\n}\n\nexport interface OpenPerpMarketOrderBaseParamsWithSwift\n\textends Omit<OpenPerpMarketOrderBaseParams, 'placeAndTake'> {\n\tswiftOptions: SwiftOrderOptions;\n}\n\nexport type OpenPerpMarketOrderParams<\n\tT extends boolean = boolean,\n\tS extends Omit<SwiftOrderOptions, 'swiftServerUrl'> = Omit<\n\t\tSwiftOrderOptions,\n\t\t'swiftServerUrl'\n\t>\n> = T extends true\n\t? OpenPerpMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tswiftOptions: S;\n\t\t\tplaceAndTake?: never;\n\t }\n\t: OpenPerpMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tplaceAndTake?: PlaceAndTakeParams;\n\t\t\tswiftOptions?: never;\n\t };\n/**\n * Shared prep logic for swift market orders: validates input, fetches auction params,\n * computes bit flags, and resolves the user account.\n */\nasync function prepSwiftMarketOrderData(params: OpenPerpMarketOrderBaseParams) {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType,\n\t\tmarketIndex,\n\t\tdirection,\n\t\tamount,\n\t\treduceOnly,\n\t\tdlobServerHttpUrl,\n\t\toptionalAuctionParamsInputs,\n\t\tpositionMaxLeverage,\n\t\thighLeverageOptions,\n\t\tuserOrderId = 0,\n\t\tcallbacks,\n\t} = params;\n\n\tif (amount.isZero()) {\n\t\tthrow new Error('Amount must be greater than zero');\n\t}\n\n\tconst fetchedOrderParams = await fetchAuctionOrderParams({\n\t\tdriftClient,\n\t\tuser,\n\t\tassetType,\n\t\tmarketIndex,\n\t\tmarketType: MarketType.PERP,\n\t\tdirection,\n\t\tamount,\n\t\tdlobServerHttpUrl,\n\t\toptionalAuctionParamsInputs,\n\t\treduceOnly,\n\t\tonAuctionParamsFetched: callbacks?.onAuctionParamsFetched,\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\tconst orderParams = {\n\t\t...fetchedOrderParams,\n\t\tuserOrderId,\n\t\tbitFlags,\n\t};\n\n\tconst userAccount = user.getUserAccount();\n\n\treturn { userAccount, orderParams };\n}\n\n/**\n * Creates and submits a Swift (signed message) order. Only available for perp orders.\n */\nexport async function createSwiftMarketOrder(\n\tparams: OpenPerpMarketOrderBaseParamsWithSwift\n): Promise<void> {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tamount,\n\t\tdirection,\n\t\tbracketOrders,\n\t\tswiftOptions,\n\t\tpositionMaxLeverage,\n\t\tmarginMode,\n\t\thighLeverageOptions,\n\t\tbuilderParams,\n\t} = params;\n\n\tconst resolvedDeposits = resolveIsolatedPositionDepositsWithOverride(\n\t\tparams.isolatedPositionDepositsOverride,\n\t\t{\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex,\n\t\t\tbaseAssetAmount: amount,\n\t\t\tdirection,\n\t\t\tpositionMaxLeverage,\n\t\t\tmarginMode,\n\t\t\treplenishUnderwaterPositions: false, // Swift doesn't support additional deposits. Will throw error if other isolated position shortfalls exists.\n\t\t\tnumOfOpenHighLeverageSpots:\n\t\t\t\thighLeverageOptions?.numOfOpenHighLeverageSpots,\n\t\t}\n\t);\n\n\tconst { userAccount, orderParams } = await prepSwiftMarketOrderData(params);\n\n\tawait prepSignAndSendSwiftOrder({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer: swiftOptions.userSigningSlotBuffer,\n\t\tswiftOptions,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: bracketOrders?.takeProfit,\n\t\t\tstopLoss: bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage,\n\t\t\tisolatedPositionDeposit: resolvedDeposits?.mainDeposit,\n\t\t},\n\t\tbuilderParams,\n\t});\n}\n\nexport type CreateSwiftMarketOrderMessageParams = Omit<\n\tOpenPerpMarketOrderBaseParams,\n\t'placeAndTake' | 'mainSignerOverride'\n> & {\n\tisDelegate?: boolean;\n\tuserSigningSlotBuffer?: number;\n};\n\n/**\n * Prepares a Swift market order message without signing or sending it.\n * Fetches auction params from the DLOB server and creates the prepared message.\n *\n * @returns The prepared SwiftOrderMessage ready for client-side signing and sending\n */\nexport async function createSwiftMarketOrderMessage(\n\tparams: CreateSwiftMarketOrderMessageParams\n): Promise<SwiftOrderMessage> {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tamount,\n\t\tdirection,\n\t\tbracketOrders,\n\t\tpositionMaxLeverage,\n\t\tmarginMode,\n\t\thighLeverageOptions,\n\t\tbuilderParams,\n\t\tisDelegate = false,\n\t\tuserSigningSlotBuffer,\n\t} = params;\n\n\tconst resolvedDeposits = resolveIsolatedPositionDepositsWithOverride(\n\t\tparams.isolatedPositionDepositsOverride,\n\t\t{\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex,\n\t\t\tbaseAssetAmount: amount,\n\t\t\tdirection,\n\t\t\tpositionMaxLeverage,\n\t\t\tmarginMode,\n\t\t\treplenishUnderwaterPositions: false, // Swift doesn't support additional deposits. Will throw error if other isolated position shortfalls exists.\n\t\t\tnumOfOpenHighLeverageSpots:\n\t\t\t\thighLeverageOptions?.numOfOpenHighLeverageSpots,\n\t\t}\n\t);\n\n\tconst { userAccount, orderParams } = await prepSwiftMarketOrderData(params);\n\n\treturn prepSwiftOrderMessage({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer,\n\t\tisDelegate,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: bracketOrders?.takeProfit,\n\t\t\tstopLoss: bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage,\n\t\t\tisolatedPositionDeposit: resolvedDeposits?.mainDeposit,\n\t\t},\n\t\tbuilderParams,\n\t});\n}\n\n/**\n * Creates a placeAndTake transaction instruction.\n * Fallbacks to a regular market order if no top makers are found.\n */\nexport const createPlaceAndTakePerpMarketOrderIx = async ({\n\tassetType,\n\tdirection,\n\tdlobServerHttpUrl,\n\tmarketIndex,\n\tdriftClient,\n\tuser,\n\tuserOrderId,\n\tamount,\n\torderType,\n\tprice,\n\treduceOnly,\n\treferrerInfo,\n\tauctionDurationPercentage,\n\toptionalAuctionParamsInputs,\n\tmainSignerOverride,\n\thighLeverageOptions,\n\tpositionMaxLeverage,\n\tcallbacks,\n}: Omit<\n\tOpenPerpMarketOrderBaseParams,\n\t'marginMode' | 'isolatedPositionDepositsOverride'\n> & {\n\torderType?: OrderType;\n\tprice?: BN;\n\tdirection: PositionDirection;\n\tdlobServerHttpUrl: string;\n\tmarketIndex: number;\n\tdriftClient: DriftClient;\n\tuser: User;\n\treferrerInfo?: ReferrerInfo;\n\tauctionDurationPercentage?: number;\n\thighLeverageOptions?: HighLeverageOptions;\n}) => {\n\tconst counterPartySide = ENUM_UTILS.match(direction, PositionDirection.LONG)\n\t\t? 'ask'\n\t\t: 'bid';\n\n\tconst [fetchedOrderParams, topMakersResult] = await Promise.all([\n\t\tfetchAuctionOrderParams({\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tassetType,\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection,\n\t\t\tamount,\n\t\t\treduceOnly,\n\t\t\tdlobServerHttpUrl,\n\t\t\toptionalAuctionParamsInputs,\n\t\t\tonAuctionParamsFetched: callbacks?.onAuctionParamsFetched,\n\t\t}),\n\t\tfetchTopMakers({\n\t\t\tdlobServerHttpUrl,\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tside: counterPartySide,\n\t\t\tlimit: 4,\n\t\t}),\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\tfetchedOrderParams.bitFlags = bitFlags;\n\tfetchedOrderParams.userOrderId = userOrderId;\n\n\tif (orderType) {\n\t\tfetchedOrderParams.orderType = orderType;\n\t}\n\n\tif (price) {\n\t\tfetchedOrderParams.price = price;\n\t\tfetchedOrderParams.auctionEndPrice = price;\n\t}\n\n\tif (!topMakersResult || topMakersResult.length === 0) {\n\t\tthrow new NoTopMakersError('No top makers found', fetchedOrderParams);\n\t}\n\n\tconst topMakersInfo = topMakersResult.map((maker) => ({\n\t\tmaker: maker.userAccountPubKey,\n\t\tmakerUserAccount: maker.userAccount,\n\t\tmakerStats: getUserStatsAccountPublicKey(\n\t\t\tdriftClient.program.programId,\n\t\t\tmaker.userAccount.authority\n\t\t),\n\t}));\n\n\tconst placeAndTakeIx = await driftClient.getPlaceAndTakePerpOrderIx(\n\t\tfetchedOrderParams,\n\t\ttopMakersInfo,\n\t\treferrerInfo,\n\t\tundefined,\n\t\tauctionDurationPercentage,\n\t\tuser.getUserAccount().subAccountId,\n\t\t{\n\t\t\tauthority: mainSignerOverride,\n\t\t}\n\t);\n\n\treturn placeAndTakeIx;\n};\n\n/**\n * Creates transaction instructions for opening a perp market order.\n * If swiftOptions is provided, it will create a Swift (signed message) order instead.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param assetType - Whether the amount is in base or quote units\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n * @param optionalAuctionParamsInputs - Optional parameters for auction params endpoint and order configuration\n * @param positionMaxLeverage - Optional per-market leverage (e.g., 5 for 5x). If provided and different from current,\n * adds an instruction to update the position's maxMarginRatio before placing the order.\n * @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.\n * @returns Promise resolving to an array of transaction instructions for regular orders\n */\nexport const createOpenPerpMarketOrderIxs = async ({\n\tdriftClient,\n\tuser,\n\tassetType,\n\tmarketIndex,\n\tdirection,\n\tamount,\n\treduceOnly,\n\tbracketOrders,\n\tdlobServerHttpUrl,\n\tplaceAndTake,\n\tuserOrderId,\n\toptionalAuctionParamsInputs = {},\n\tpositionMaxLeverage,\n\tmainSignerOverride,\n\thighLeverageOptions,\n\tmarginMode,\n\tisolatedPositionDepositsOverride,\n\tcallbacks,\n}: OpenPerpMarketOrderBaseParams): Promise<TransactionInstruction[]> => {\n\tif (!amount || amount.isZero()) {\n\t\tthrow new Error('Amount must be greater than zero');\n\t}\n\n\tconst resolvedDeposits = resolveIsolatedPositionDepositsWithOverride(\n\t\tisolatedPositionDepositsOverride,\n\t\t{\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex,\n\t\t\tbaseAssetAmount: amount,\n\t\t\tdirection,\n\t\t\tpositionMaxLeverage,\n\t\t\tmarginMode,\n\t\t\treplenishUnderwaterPositions: true,\n\t\t\tnumOfOpenHighLeverageSpots:\n\t\t\t\thighLeverageOptions?.numOfOpenHighLeverageSpots,\n\t\t}\n\t);\n\n\tconst mainIsolatedDeposit = resolvedDeposits?.mainDeposit;\n\tconst resolvedAdditionalDeposits =\n\t\tresolvedDeposits?.additionalIsolatedPositionDeposits;\n\n\tconst allOrders: OptionalOrderParams[] = [];\n\tconst allIxs: TransactionInstruction[] = [];\n\n\t// Fetch all deposit/leverage ixs in parallel\n\tconst [leverageIx, additionalDepositIxs, isolatedPositionDepositIx] =\n\t\tawait Promise.all([\n\t\t\tgetPositionMaxLeverageIxIfNeeded(\n\t\t\t\tdriftClient,\n\t\t\t\tuser,\n\t\t\t\tmarketIndex,\n\t\t\t\tpositionMaxLeverage,\n\t\t\t\tmainSignerOverride\n\t\t\t),\n\t\t\tresolvedAdditionalDeposits?.length\n\t\t\t\t? Promise.all(\n\t\t\t\t\t\tresolvedAdditionalDeposits.map((deposit) =>\n\t\t\t\t\t\t\tgetIsolatedPositionDepositIxIfNeeded(\n\t\t\t\t\t\t\t\tdriftClient,\n\t\t\t\t\t\t\t\tuser,\n\t\t\t\t\t\t\t\tdeposit.marketIndex,\n\t\t\t\t\t\t\t\tdeposit.amount,\n\t\t\t\t\t\t\t\tmainSignerOverride\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t: Promise.resolve([] as (TransactionInstruction | undefined)[]),\n\t\t\tgetIsolatedPositionDepositIxIfNeeded(\n\t\t\t\tdriftClient,\n\t\t\t\tuser,\n\t\t\t\tmarketIndex,\n\t\t\t\tmainIsolatedDeposit,\n\t\t\t\tmainSignerOverride\n\t\t\t),\n\t\t]);\n\n\tif (leverageIx) {\n\t\tallIxs.push(leverageIx);\n\t}\n\tfor (const ix of additionalDepositIxs) {\n\t\tif (ix) {\n\t\t\tallIxs.push(ix);\n\t\t}\n\t}\n\tif (isolatedPositionDepositIx) {\n\t\tallIxs.push(isolatedPositionDepositIx);\n\t}\n\n\tif (placeAndTake?.enable) {\n\t\ttry {\n\t\t\tconst placeAndTakeIx = await createPlaceAndTakePerpMarketOrderIx({\n\t\t\t\tassetType,\n\t\t\t\tamount,\n\t\t\t\tdirection,\n\t\t\t\tdlobServerHttpUrl,\n\t\t\t\tmarketIndex,\n\t\t\t\tdriftClient,\n\t\t\t\tuser,\n\t\t\t\tuserOrderId,\n\t\t\t\treduceOnly,\n\t\t\t\treferrerInfo: placeAndTake.referrerInfo,\n\t\t\t\tauctionDurationPercentage: placeAndTake.auctionDurationPercentage,\n\t\t\t\toptionalAuctionParamsInputs,\n\t\t\t\tmainSignerOverride,\n\t\t\t\tpositionMaxLeverage,\n\t\t\t});\n\t\t\tallIxs.push(placeAndTakeIx);\n\t\t} catch (e) {\n\t\t\tif (e instanceof NoTopMakersError) {\n\t\t\t\t// fallback to regular order\n\t\t\t\tallOrders.push(e.orderParams);\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconst fetchedOrderParams = await fetchAuctionOrderParams({\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tassetType,\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection,\n\t\t\tamount,\n\t\t\tdlobServerHttpUrl,\n\t\t\toptionalAuctionParamsInputs,\n\t\t\treduceOnly,\n\t\t\tonAuctionParamsFetched: callbacks?.onAuctionParamsFetched,\n\t\t});\n\n\t\tconst bitFlags = ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(\n\t\t\tmarketIndex,\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tpositionMaxLeverage,\n\t\t\thighLeverageOptions\n\t\t);\n\n\t\tconst orderParams = {\n\t\t\t...fetchedOrderParams,\n\t\t\tuserOrderId,\n\t\t\tbitFlags,\n\t\t};\n\n\t\tallOrders.push(orderParams);\n\t}\n\n\tconst bracketOrdersDirection = ENUM_UTILS.match(\n\t\tdirection,\n\t\tPositionDirection.LONG\n\t)\n\t\t? PositionDirection.SHORT\n\t\t: PositionDirection.LONG;\n\n\tif (bracketOrders?.takeProfit) {\n\t\tconst takeProfitParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount: bracketOrders.takeProfit.baseAssetAmount ?? amount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'takeProfit',\n\t\t\t\ttriggerPrice: bracketOrders.takeProfit.triggerPrice,\n\t\t\t\tlimitPrice: bracketOrders.takeProfit.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: bracketOrders.takeProfit.reduceOnly ?? true,\n\t\t});\n\t\tallOrders.push(takeProfitParams);\n\t}\n\n\tif (bracketOrders?.stopLoss) {\n\t\tconst stopLossParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount: bracketOrders.stopLoss.baseAssetAmount ?? amount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'stopLoss',\n\t\t\t\ttriggerPrice: bracketOrders.stopLoss.triggerPrice,\n\t\t\t\tlimitPrice: bracketOrders.stopLoss.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: bracketOrders.stopLoss.reduceOnly ?? true,\n\t\t});\n\t\tallOrders.push(stopLossParams);\n\t}\n\n\t// Regular order flow - create transaction instruction\n\tif (allOrders.length > 0) {\n\t\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(\n\t\t\tallOrders,\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\tauthority: mainSignerOverride,\n\t\t\t}\n\t\t);\n\t\tallIxs.push(placeOrderIx);\n\t}\n\n\treturn allIxs;\n};\n\n/**\n * Creates a complete transaction for opening a perp market order.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param optionalAuctionParamsInputs - Optional parameters for auction params endpoint and order configuration\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n * @param positionMaxLeverage - Optional per-market leverage (e.g., 5 for 5x). If provided and different from current,\n * includes an instruction to update the position's maxMarginRatio.\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createOpenPerpMarketOrderTxn = async (\n\tparams: WithTxnParams<OpenPerpMarketOrderBaseParams>\n): Promise<Transaction | VersionedTransaction> => {\n\tconst { driftClient } = params;\n\n\t// Regular order flow - create transaction instruction and build transaction\n\tconst placeOrderIxs = await createOpenPerpMarketOrderIxs(params);\n\tconst openPerpMarketOrderTxn = await driftClient.txHandler.buildTransaction({\n\t\tinstructions: placeOrderIxs,\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: params.txParams,\n\t});\n\n\treturn openPerpMarketOrderTxn;\n};\n\n/**\n * Creates a transaction or swift order for a perp market order.\n *\n * @param driftClient - The Drift client instance for interacting with the protocol\n * @param user - The user account that will place the order\n * @param marketIndex - The perp market index to trade\n * @param direction - The direction of the trade (long/short)\n * @param amount - The amount to trade\n * @param optionalAuctionParamsInputs - Optional parameters for auction params endpoint and order configuration\n * @param dlobServerHttpUrl - Server URL for the auction params endpoint\n * @param useSwift - Whether to use Swift (signed message) orders instead of regular transactions\n * @param swiftOptions - Options for Swift (signed message) orders. Required if useSwift is true\n * @param userOrderId - The user order id for UI identification\n * @param positionMaxLeverage - Optional per-market leverage (e.g., 5 for 5x). Only supported for regular transactions (not Swift).\n *\n * @returns Promise resolving to a built transaction ready for signing (Transaction or VersionedTransaction)\n */\nexport const createOpenPerpMarketOrder = async <T extends boolean>(\n\tparams: WithTxnParams<OpenPerpMarketOrderParams<T, SwiftOrderOptions>>\n): Promise<TxnOrSwiftResult<T>> => {\n\tconst { useSwift, swiftOptions, ...rest } = params;\n\n\t// If useSwift is true, return the Swift result directly\n\tif (useSwift) {\n\t\tif (!swiftOptions) {\n\t\t\tthrow new Error('swiftOptions is required when useSwift is true');\n\t\t}\n\n\t\tconst swiftOrderResult = await createSwiftMarketOrder({\n\t\t\t...rest,\n\t\t\tswiftOptions,\n\t\t});\n\n\t\treturn swiftOrderResult as TxnOrSwiftResult<T>;\n\t}\n\n\tconst openPerpMarketOrderTxn = await createOpenPerpMarketOrderTxn(rest);\n\n\treturn openPerpMarketOrderTxn as TxnOrSwiftResult<T>;\n};\n"]}
|
|
@@ -2,7 +2,7 @@ import { DriftClient, User, BN, PostOnlyParams } from '@drift-labs/sdk';
|
|
|
2
2
|
import { PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
3
|
import { SwiftOrderOptions, SwiftOrderMessage } from '../openSwiftOrder';
|
|
4
4
|
import { HighLeverageOptions } from '../../../../../../common-ui-utils';
|
|
5
|
-
import { TxnOrSwiftResult, LimitOrderParamsOrderConfig, NonMarketOrderParamsConfig,
|
|
5
|
+
import { TxnOrSwiftResult, LimitOrderParamsOrderConfig, NonMarketOrderParamsConfig, IsolatedPositionDepositsOverride } from '../types';
|
|
6
6
|
import { WithTxnParams } from '../../../../types';
|
|
7
7
|
export interface OpenPerpNonMarketOrderBaseParams extends Omit<NonMarketOrderParamsConfig, 'marketType' | 'baseAssetAmount'> {
|
|
8
8
|
driftClient: DriftClient;
|
|
@@ -13,6 +13,19 @@ export interface OpenPerpNonMarketOrderBaseParams extends Omit<NonMarketOrderPar
|
|
|
13
13
|
reduceOnly?: boolean;
|
|
14
14
|
postOnly?: PostOnlyParams;
|
|
15
15
|
userOrderId?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Position margin mode to use for the order.
|
|
18
|
+
* When 'isolated', auto-computes isolated position deposit from positionMaxLeverage,
|
|
19
|
+
* and any additional isolated position deposits need to replenish under-collateralized positions.
|
|
20
|
+
* If not provided, the position margin mode will be derived from the user's position margin mode,
|
|
21
|
+
* and if that does not exist, it will default to 'cross'.
|
|
22
|
+
*/
|
|
23
|
+
marginMode?: 'isolated' | 'cross';
|
|
24
|
+
/**
|
|
25
|
+
* Pre-computed isolated position deposits override. When provided,
|
|
26
|
+
* skips auto-compute and uses these values directly.
|
|
27
|
+
*/
|
|
28
|
+
isolatedPositionDepositsOverride?: IsolatedPositionDepositsOverride;
|
|
16
29
|
autoEnterHighLeverageModeBufferPct?: number;
|
|
17
30
|
/**
|
|
18
31
|
* If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.
|
|
@@ -28,12 +41,6 @@ export interface OpenPerpNonMarketOrderBaseParams extends Omit<NonMarketOrderPar
|
|
|
28
41
|
builderFeeTenthBps: number;
|
|
29
42
|
};
|
|
30
43
|
highLeverageOptions?: HighLeverageOptions;
|
|
31
|
-
/**
|
|
32
|
-
* Additional isolated position deposits needed to top up other
|
|
33
|
-
* under-collateralized isolated positions before placing the order.
|
|
34
|
-
* Each deposit will create a separate instruction.
|
|
35
|
-
*/
|
|
36
|
-
additionalIsolatedPositionDeposits?: AdditionalIsolatedPositionDeposit[];
|
|
37
44
|
}
|
|
38
45
|
export interface OpenPerpNonMarketOrderParamsWithSwift extends OpenPerpNonMarketOrderBaseParams {
|
|
39
46
|
swiftOptions: SwiftOrderOptions;
|
|
@@ -10,6 +10,7 @@ const openPerpMarketOrder_1 = require("../openPerpMarketOrder");
|
|
|
10
10
|
const positionMaxLeverage_1 = require("../positionMaxLeverage");
|
|
11
11
|
const auction_1 = require("../auction");
|
|
12
12
|
const isolatedPositionDeposit_1 = require("../isolatedPositionDeposit");
|
|
13
|
+
// TODO: add isolated margin?
|
|
13
14
|
/**
|
|
14
15
|
* Creates a transaction instruction to open multiple non-market orders.
|
|
15
16
|
*/
|
|
@@ -34,7 +35,7 @@ exports.createMultipleOpenPerpNonMarketOrderIx = createMultipleOpenPerpNonMarket
|
|
|
34
35
|
*/
|
|
35
36
|
const createOpenPerpNonMarketOrderIxs = async (params) => {
|
|
36
37
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
37
|
-
const { driftClient, user, marketIndex, direction, reduceOnly = false, postOnly = sdk_1.PostOnlyParams.NONE, orderConfig, userOrderId = 0, positionMaxLeverage,
|
|
38
|
+
const { driftClient, user, marketIndex, direction, reduceOnly = false, postOnly = sdk_1.PostOnlyParams.NONE, orderConfig, userOrderId = 0, positionMaxLeverage, marginMode, mainSignerOverride, highLeverageOptions, isolatedPositionDepositsOverride, } = params;
|
|
38
39
|
// Support both new (amount + assetType) and legacy (baseAssetAmount) approaches
|
|
39
40
|
const finalBaseAssetAmount = (0, orderParams_1.resolveBaseAssetAmount)({
|
|
40
41
|
amount: 'amount' in params ? params.amount : undefined,
|
|
@@ -47,23 +48,37 @@ const createOpenPerpNonMarketOrderIxs = async (params) => {
|
|
|
47
48
|
if (!finalBaseAssetAmount || finalBaseAssetAmount.isZero()) {
|
|
48
49
|
throw new Error('Final base asset amount must be greater than zero');
|
|
49
50
|
}
|
|
51
|
+
const resolvedDeposits = (0, isolatedPositionDeposit_1.resolveIsolatedPositionDepositsWithOverride)(isolatedPositionDepositsOverride, {
|
|
52
|
+
driftClient,
|
|
53
|
+
user,
|
|
54
|
+
marketIndex,
|
|
55
|
+
baseAssetAmount: finalBaseAssetAmount,
|
|
56
|
+
direction,
|
|
57
|
+
positionMaxLeverage,
|
|
58
|
+
marginMode,
|
|
59
|
+
replenishUnderwaterPositions: true,
|
|
60
|
+
numOfOpenHighLeverageSpots: highLeverageOptions === null || highLeverageOptions === void 0 ? void 0 : highLeverageOptions.numOfOpenHighLeverageSpots,
|
|
61
|
+
});
|
|
62
|
+
const mainIsolatedPositionDeposit = resolvedDeposits === null || resolvedDeposits === void 0 ? void 0 : resolvedDeposits.mainDeposit;
|
|
63
|
+
const resolvedAdditionalDeposits = resolvedDeposits === null || resolvedDeposits === void 0 ? void 0 : resolvedDeposits.additionalIsolatedPositionDeposits;
|
|
50
64
|
const allOrders = [];
|
|
51
65
|
const allIxs = [];
|
|
52
|
-
|
|
66
|
+
// Fetch all deposit/leverage ixs in parallel
|
|
67
|
+
const [leverageIx, additionalDepositIxs, isolatedPositionDepositIx] = await Promise.all([
|
|
68
|
+
(0, positionMaxLeverage_1.getPositionMaxLeverageIxIfNeeded)(driftClient, user, marketIndex, positionMaxLeverage, mainSignerOverride),
|
|
69
|
+
(resolvedAdditionalDeposits === null || resolvedAdditionalDeposits === void 0 ? void 0 : resolvedAdditionalDeposits.length)
|
|
70
|
+
? Promise.all(resolvedAdditionalDeposits.map((deposit) => (0, isolatedPositionDeposit_1.getIsolatedPositionDepositIxIfNeeded)(driftClient, user, deposit.marketIndex, deposit.amount, mainSignerOverride)))
|
|
71
|
+
: Promise.resolve([]),
|
|
72
|
+
(0, isolatedPositionDeposit_1.getIsolatedPositionDepositIxIfNeeded)(driftClient, user, marketIndex, mainIsolatedPositionDeposit, mainSignerOverride),
|
|
73
|
+
]);
|
|
53
74
|
if (leverageIx) {
|
|
54
75
|
allIxs.push(leverageIx);
|
|
55
76
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const additionalDepositIxs = await Promise.all(additionalDepositIxPromises);
|
|
60
|
-
for (const ix of additionalDepositIxs) {
|
|
61
|
-
if (ix) {
|
|
62
|
-
allIxs.push(ix);
|
|
63
|
-
}
|
|
77
|
+
for (const ix of additionalDepositIxs) {
|
|
78
|
+
if (ix) {
|
|
79
|
+
allIxs.push(ix);
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
|
-
const isolatedPositionDepositIx = await (0, isolatedPositionDeposit_1.getIsolatedPositionDepositIxIfNeeded)(driftClient, user, marketIndex, isolatedPositionDeposit, mainSignerOverride);
|
|
67
82
|
if (isolatedPositionDepositIx) {
|
|
68
83
|
allIxs.push(isolatedPositionDepositIx);
|
|
69
84
|
}
|
|
@@ -126,7 +141,6 @@ const createOpenPerpNonMarketOrderIxs = async (params) => {
|
|
|
126
141
|
reduceOnly,
|
|
127
142
|
postOnly,
|
|
128
143
|
userOrderId,
|
|
129
|
-
positionMaxLeverage,
|
|
130
144
|
});
|
|
131
145
|
const bitFlags = common_ui_utils_1.ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(marketIndex, driftClient, user, positionMaxLeverage, highLeverageOptions);
|
|
132
146
|
orderParams.bitFlags = bitFlags;
|
|
@@ -147,7 +161,6 @@ const createOpenPerpNonMarketOrderIxs = async (params) => {
|
|
|
147
161
|
limitPrice: orderConfig.bracketOrders.takeProfit.limitPrice,
|
|
148
162
|
},
|
|
149
163
|
reduceOnly: (_f = orderConfig.bracketOrders.takeProfit.reduceOnly) !== null && _f !== void 0 ? _f : true,
|
|
150
|
-
positionMaxLeverage,
|
|
151
164
|
});
|
|
152
165
|
allOrders.push(takeProfitParams);
|
|
153
166
|
}
|
|
@@ -163,7 +176,6 @@ const createOpenPerpNonMarketOrderIxs = async (params) => {
|
|
|
163
176
|
limitPrice: orderConfig.bracketOrders.stopLoss.limitPrice,
|
|
164
177
|
},
|
|
165
178
|
reduceOnly: (_j = orderConfig.bracketOrders.stopLoss.reduceOnly) !== null && _j !== void 0 ? _j : true,
|
|
166
|
-
positionMaxLeverage,
|
|
167
179
|
});
|
|
168
180
|
allOrders.push(stopLossParams);
|
|
169
181
|
}
|
|
@@ -209,15 +221,25 @@ async function prepSwiftLimitOrderData(params) {
|
|
|
209
221
|
reduceOnly: params.reduceOnly,
|
|
210
222
|
postOnly: params.postOnly,
|
|
211
223
|
userOrderId: params.userOrderId,
|
|
212
|
-
positionMaxLeverage: params.positionMaxLeverage,
|
|
213
224
|
});
|
|
214
225
|
const userAccount = user.getUserAccount();
|
|
215
226
|
return { userAccount, orderParams };
|
|
216
227
|
}
|
|
217
228
|
const createSwiftLimitOrder = async (params) => {
|
|
218
|
-
var _a, _b;
|
|
229
|
+
var _a, _b, _c;
|
|
219
230
|
const { driftClient, user, marketIndex, swiftOptions, orderConfig } = params;
|
|
220
231
|
const { userAccount, orderParams } = await prepSwiftLimitOrderData(params);
|
|
232
|
+
const resolvedDeposits = (0, isolatedPositionDeposit_1.resolveIsolatedPositionDepositsWithOverride)(params.isolatedPositionDepositsOverride, {
|
|
233
|
+
driftClient,
|
|
234
|
+
user,
|
|
235
|
+
marketIndex,
|
|
236
|
+
baseAssetAmount: orderParams.baseAssetAmount,
|
|
237
|
+
direction: orderParams.direction,
|
|
238
|
+
positionMaxLeverage: params.positionMaxLeverage,
|
|
239
|
+
marginMode: params.marginMode,
|
|
240
|
+
replenishUnderwaterPositions: false, // Swift doesn't support additional deposits, so throw on underwater positions
|
|
241
|
+
numOfOpenHighLeverageSpots: (_a = params.highLeverageOptions) === null || _a === void 0 ? void 0 : _a.numOfOpenHighLeverageSpots,
|
|
242
|
+
});
|
|
221
243
|
await (0, openSwiftOrder_1.prepSignAndSendSwiftOrder)({
|
|
222
244
|
driftClient,
|
|
223
245
|
subAccountId: userAccount.subAccountId,
|
|
@@ -227,10 +249,10 @@ const createSwiftLimitOrder = async (params) => {
|
|
|
227
249
|
swiftOptions,
|
|
228
250
|
orderParams: {
|
|
229
251
|
main: orderParams,
|
|
230
|
-
takeProfit: (
|
|
231
|
-
stopLoss: (
|
|
252
|
+
takeProfit: (_b = orderConfig.bracketOrders) === null || _b === void 0 ? void 0 : _b.takeProfit,
|
|
253
|
+
stopLoss: (_c = orderConfig.bracketOrders) === null || _c === void 0 ? void 0 : _c.stopLoss,
|
|
232
254
|
positionMaxLeverage: params.positionMaxLeverage,
|
|
233
|
-
isolatedPositionDeposit:
|
|
255
|
+
isolatedPositionDeposit: resolvedDeposits === null || resolvedDeposits === void 0 ? void 0 : resolvedDeposits.mainDeposit,
|
|
234
256
|
},
|
|
235
257
|
builderParams: params.builderParams,
|
|
236
258
|
});
|
|
@@ -242,9 +264,20 @@ exports.createSwiftLimitOrder = createSwiftLimitOrder;
|
|
|
242
264
|
* @returns The prepared SwiftOrderMessage ready for client-side signing and sending
|
|
243
265
|
*/
|
|
244
266
|
const createSwiftLimitOrderMessage = async (params) => {
|
|
245
|
-
var _a, _b;
|
|
267
|
+
var _a, _b, _c;
|
|
246
268
|
const { driftClient, user, marketIndex, orderConfig, isDelegate = false, userSigningSlotBuffer, } = params;
|
|
247
269
|
const { userAccount, orderParams } = await prepSwiftLimitOrderData(params);
|
|
270
|
+
const resolvedDeposits = (0, isolatedPositionDeposit_1.resolveIsolatedPositionDepositsWithOverride)(params.isolatedPositionDepositsOverride, {
|
|
271
|
+
driftClient,
|
|
272
|
+
user,
|
|
273
|
+
marketIndex,
|
|
274
|
+
baseAssetAmount: orderParams.baseAssetAmount,
|
|
275
|
+
direction: orderParams.direction,
|
|
276
|
+
positionMaxLeverage: params.positionMaxLeverage,
|
|
277
|
+
marginMode: params.marginMode,
|
|
278
|
+
replenishUnderwaterPositions: false, // Swift doesn't support additional deposits, so throw on underwater positions
|
|
279
|
+
numOfOpenHighLeverageSpots: (_a = params.highLeverageOptions) === null || _a === void 0 ? void 0 : _a.numOfOpenHighLeverageSpots,
|
|
280
|
+
});
|
|
248
281
|
return (0, openSwiftOrder_1.prepSwiftOrderMessage)({
|
|
249
282
|
driftClient,
|
|
250
283
|
subAccountId: userAccount.subAccountId,
|
|
@@ -254,10 +287,10 @@ const createSwiftLimitOrderMessage = async (params) => {
|
|
|
254
287
|
isDelegate,
|
|
255
288
|
orderParams: {
|
|
256
289
|
main: orderParams,
|
|
257
|
-
takeProfit: (
|
|
258
|
-
stopLoss: (
|
|
290
|
+
takeProfit: (_b = orderConfig.bracketOrders) === null || _b === void 0 ? void 0 : _b.takeProfit,
|
|
291
|
+
stopLoss: (_c = orderConfig.bracketOrders) === null || _c === void 0 ? void 0 : _c.stopLoss,
|
|
259
292
|
positionMaxLeverage: params.positionMaxLeverage,
|
|
260
|
-
isolatedPositionDeposit:
|
|
293
|
+
isolatedPositionDeposit: resolvedDeposits === null || resolvedDeposits === void 0 ? void 0 : resolvedDeposits.mainDeposit,
|
|
261
294
|
},
|
|
262
295
|
builderParams: params.builderParams,
|
|
263
296
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.ts"],"names":[],"mappings":";;;AAAA,yCAUyB;AAOzB,sDAK2B;AAC3B,kEAG0C;AAC1C,mDAAqD;AACrD,uEAG2C;AAC3C,gEAA6E;AAS7E,gEAA0E;AAC1E,wCAAwD;AACxD,wEAAkF;AA2DlF;;GAEG;AACI,MAAM,sCAAsC,GAAG,KAAK,EAAE,MAS5D,EAAmC,EAAE;IACrC,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAAC;IAEvE,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,uCAAyB,CAAC,CAAC;IAEtE,IAAI,MAAM,CAAC,qBAAqB,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5D,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,wBAAkB,CAAC,sBAAsB,CAAC;IACrE,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,gBAAgB,CACtD,WAAW,EACX,SAAS,EACT;QACC,SAAS,EAAE,kBAAkB;KAC7B,CACD,CAAC;IACF,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC;AA1BW,QAAA,sCAAsC,0CA0BjD;AAEF;;;;;;GAMG;AACI,MAAM,+BAA+B,GAAG,KAAK,EACnD,MAAwC,EACJ,EAAE;;IACtC,MAAM,EACL,WAAW,EACX,IAAI,EACJ,WAAW,EACX,SAAS,EACT,UAAU,GAAG,KAAK,EAClB,QAAQ,GAAG,oBAAc,CAAC,IAAI,EAC9B,WAAW,EACX,WAAW,GAAG,CAAC,EACf,mBAAmB,EACnB,uBAAuB,EACvB,kCAAkC,EAClC,kBAAkB,EAClB,mBAAmB,GACnB,GAAG,MAAM,CAAC;IACX,gFAAgF;IAChF,MAAM,oBAAoB,GAAG,IAAA,oCAAsB,EAAC;QACnD,MAA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EAAE;IACjC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAEvD,wDAAwD;IACxD,IAAI,QAAQ,EAAE,CAAC;QACd,IAAI,WAAW,CAAC,SAAS,KAAK,OAAO,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACnE,CAAC;QAED,MAAM,gBAAgB,GAAG,MAAM,IAAA,6BAAqB,EAAC;YACpD,GAAG,MAAM;YACT,YAAY;YACZ,WAAW;SACX,CAAC,CAAC;QAEH,OAAO,gBAAuC,CAAC;IAChD,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,IAAA,uCAA+B,EAAC,MAAM,CAAC,CAAC;IAErE,OAAO,cAAqC,CAAC;AAC9C,CAAC,CAAC;AA3BW,QAAA,4BAA4B,gCA2BvC","sourcesContent":["import {\n\tDriftClient,\n\tUser,\n\tBN,\n\tMarketType,\n\tPostOnlyParams,\n\tOptionalOrderParams,\n\tPositionDirection,\n\tOrderParamsBitFlag,\n\tOrderType,\n} from '@drift-labs/sdk';\nimport {\n\tPublicKey,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport {\n\tprepSignAndSendSwiftOrder,\n\tprepSwiftOrderMessage,\n\tSwiftOrderOptions,\n\tSwiftOrderMessage,\n} from '../openSwiftOrder';\nimport {\n\tbuildNonMarketOrderParams,\n\tresolveBaseAssetAmount,\n} from '../../../../../utils/orderParams';\nimport { ENUM_UTILS } from '../../../../../../utils';\nimport {\n\tHighLeverageOptions,\n\tORDER_COMMON_UTILS,\n} from '../../../../../../common-ui-utils';\nimport { createPlaceAndTakePerpMarketOrderIx } from '../openPerpMarketOrder';\nimport {\n\tTxnOrSwiftResult,\n\tLimitAuctionConfig,\n\tLimitOrderParamsOrderConfig,\n\tNonMarketOrderParamsConfig,\n\tAdditionalIsolatedPositionDeposit,\n} from '../types';\nimport { WithTxnParams } from '../../../../types';\nimport { getPositionMaxLeverageIxIfNeeded } from '../positionMaxLeverage';\nimport { getLimitAuctionOrderParams } from '../auction';\nimport { getIsolatedPositionDepositIxIfNeeded } from '../isolatedPositionDeposit';\n\nexport interface OpenPerpNonMarketOrderBaseParams\n\textends Omit<NonMarketOrderParamsConfig, 'marketType' | 'baseAssetAmount'> {\n\tdriftClient: DriftClient;\n\tuser: User;\n\t// Either new approach\n\tamount?: BN;\n\tassetType?: 'base' | 'quote';\n\t// Or legacy approach\n\tbaseAssetAmount?: BN;\n\t// Common optional params\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\tuserOrderId?: number;\n\tautoEnterHighLeverageModeBufferPct?: number;\n\t/**\n\t * If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.\n\t * This is only applicable for non-SWIFT orders.\n\t */\n\tmainSignerOverride?: PublicKey;\n\t/**\n\t * Optional builder code parameters for revenue sharing.\n\t * Only applicable for Swift orders for now.\n\t */\n\tbuilderParams?: {\n\t\tbuilderIdx: number;\n\t\tbuilderFeeTenthBps: number;\n\t};\n\thighLeverageOptions?: HighLeverageOptions;\n\t/**\n\t * Additional isolated position deposits needed to top up other\n\t * under-collateralized isolated positions before placing the order.\n\t * Each deposit will create a separate instruction.\n\t */\n\tadditionalIsolatedPositionDeposits?: AdditionalIsolatedPositionDeposit[];\n}\n\nexport interface OpenPerpNonMarketOrderParamsWithSwift\n\textends OpenPerpNonMarketOrderBaseParams {\n\tswiftOptions: SwiftOrderOptions;\n}\n\nexport type OpenPerpNonMarketOrderParams<\n\tT extends boolean = boolean,\n\tS extends Omit<SwiftOrderOptions, 'swiftServerUrl'> = Omit<\n\t\tSwiftOrderOptions,\n\t\t'swiftServerUrl'\n\t>\n> = T extends true\n\t? OpenPerpNonMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tswiftOptions: S;\n\t }\n\t: OpenPerpNonMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tswiftOptions?: never;\n\t };\n\n/**\n * Creates a transaction instruction to open multiple non-market orders.\n */\nexport const createMultipleOpenPerpNonMarketOrderIx = async (params: {\n\tdriftClient: DriftClient;\n\tuser: User;\n\torderParamsConfigs: NonMarketOrderParamsConfig[];\n\tenterHighLeverageMode?: boolean;\n\t/**\n\t * If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.\n\t */\n\tmainSignerOverride?: PublicKey;\n}): Promise<TransactionInstruction> => {\n\tconst { driftClient, orderParamsConfigs, mainSignerOverride } = params;\n\n\tconst orderParams = orderParamsConfigs.map(buildNonMarketOrderParams);\n\n\tif (params.enterHighLeverageMode && orderParams.length > 0) {\n\t\torderParams[0].bitFlags = OrderParamsBitFlag.UpdateHighLeverageMode;\n\t}\n\n\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(\n\t\torderParams,\n\t\tundefined,\n\t\t{\n\t\t\tauthority: mainSignerOverride,\n\t\t}\n\t);\n\treturn placeOrderIx;\n};\n\n/**\n * Creates a transaction instruction to open a non-market order.\n * Allows for bracket orders to be opened in the same transaction.\n *\n * If `limitAuction` is enabled, a placeAndTake order is created to simulate a market auction order,\n * with the end price being the limit price.\n */\nexport const createOpenPerpNonMarketOrderIxs = async (\n\tparams: OpenPerpNonMarketOrderBaseParams\n): Promise<TransactionInstruction[]> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tdirection,\n\t\treduceOnly = false,\n\t\tpostOnly = PostOnlyParams.NONE,\n\t\torderConfig,\n\t\tuserOrderId = 0,\n\t\tpositionMaxLeverage,\n\t\tisolatedPositionDeposit,\n\t\tadditionalIsolatedPositionDeposits,\n\t\tmainSignerOverride,\n\t\thighLeverageOptions,\n\t} = params;\n\t// Support both new (amount + assetType) and legacy (baseAssetAmount) approaches\n\tconst finalBaseAssetAmount = resolveBaseAssetAmount({\n\t\tamount: 'amount' in params ? params.amount : undefined,\n\t\tassetType: 'assetType' in params ? params.assetType : undefined,\n\t\tbaseAssetAmount:\n\t\t\t'baseAssetAmount' in params ? params.baseAssetAmount : undefined,\n\t\tlimitPrice:\n\t\t\t'limitPrice' in params.orderConfig\n\t\t\t\t? params.orderConfig.limitPrice\n\t\t\t\t: undefined,\n\t});\n\n\tif (!finalBaseAssetAmount || finalBaseAssetAmount.isZero()) {\n\t\tthrow new Error('Final base asset amount must be greater than zero');\n\t}\n\n\tconst allOrders: OptionalOrderParams[] = [];\n\tconst allIxs: TransactionInstruction[] = [];\n\n\tconst leverageIx = await getPositionMaxLeverageIxIfNeeded(\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tpositionMaxLeverage,\n\t\tmainSignerOverride\n\t);\n\tif (leverageIx) {\n\t\tallIxs.push(leverageIx);\n\t}\n\n\t// Add additional isolated position deposit ixs for other under-collateralized positions\n\tif (additionalIsolatedPositionDeposits?.length) {\n\t\tconst additionalDepositIxPromises = additionalIsolatedPositionDeposits.map(\n\t\t\t(deposit) =>\n\t\t\t\tgetIsolatedPositionDepositIxIfNeeded(\n\t\t\t\t\tdriftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tdeposit.marketIndex,\n\t\t\t\t\tdeposit.amount,\n\t\t\t\t\tmainSignerOverride\n\t\t\t\t)\n\t\t);\n\t\tconst additionalDepositIxs = await Promise.all(additionalDepositIxPromises);\n\t\tfor (const ix of additionalDepositIxs) {\n\t\t\tif (ix) {\n\t\t\t\tallIxs.push(ix);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst isolatedPositionDepositIx: TransactionInstruction | undefined =\n\t\tawait getIsolatedPositionDepositIxIfNeeded(\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex,\n\t\t\tisolatedPositionDeposit,\n\t\t\tmainSignerOverride\n\t\t);\n\tif (isolatedPositionDepositIx) {\n\t\tallIxs.push(isolatedPositionDepositIx);\n\t}\n\n\t// handle limit auction\n\tif (\n\t\torderConfig.orderType === 'limit' &&\n\t\torderConfig.limitAuction?.enable &&\n\t\tENUM_UTILS.match(postOnly, PostOnlyParams.NONE)\n\t) {\n\t\tconst limitAuctionOrderParams = await getLimitAuctionOrderParams({\n\t\t\t...params,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\torderConfig: orderConfig as LimitOrderParamsOrderConfig & {\n\t\t\t\tlimitAuction: LimitAuctionConfig;\n\t\t\t},\n\t\t});\n\n\t\tlet createdPlaceAndTakeIx = false;\n\n\t\t// if it is a limit auction order, we create a placeAndTake order to simulate a market order.\n\t\t// this is useful when a limit order is crossing, and we want to achieve the best fill price through a placeAndTake.\n\t\t// falls back to limit order with auction params if the placeAndTake order creation fails\n\t\tif (\n\t\t\tlimitAuctionOrderParams.auctionDuration &&\n\t\t\tlimitAuctionOrderParams.auctionDuration > 0 &&\n\t\t\torderConfig.limitAuction?.usePlaceAndTake?.enable\n\t\t) {\n\t\t\ttry {\n\t\t\t\tconst placeAndTakeIx = await createPlaceAndTakePerpMarketOrderIx({\n\t\t\t\t\tassetType: 'base',\n\t\t\t\t\tamount: finalBaseAssetAmount,\n\t\t\t\t\torderType: OrderType.LIMIT,\n\t\t\t\t\tprice: orderConfig.limitPrice,\n\t\t\t\t\tdirection,\n\t\t\t\t\tdlobServerHttpUrl: orderConfig.limitAuction.dlobServerHttpUrl,\n\t\t\t\t\tmarketIndex,\n\t\t\t\t\tdriftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tuserOrderId,\n\t\t\t\t\treduceOnly,\n\t\t\t\t\tpositionMaxLeverage,\n\t\t\t\t\toptionalAuctionParamsInputs:\n\t\t\t\t\t\torderConfig.limitAuction.optionalLimitAuctionParams,\n\t\t\t\t\tauctionDurationPercentage:\n\t\t\t\t\t\torderConfig.limitAuction.usePlaceAndTake.auctionDurationPercentage,\n\t\t\t\t\treferrerInfo: orderConfig.limitAuction.usePlaceAndTake.referrerInfo,\n\t\t\t\t\thighLeverageOptions,\n\t\t\t\t});\n\t\t\t\tallIxs.push(placeAndTakeIx);\n\t\t\t\tcreatedPlaceAndTakeIx = true;\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t'Failed to create placeAndTake order for limit auction order',\n\t\t\t\t\te\n\t\t\t\t);\n\t\t\t\tcreatedPlaceAndTakeIx = false;\n\t\t\t}\n\t\t}\n\n\t\t// fallback to normal limit order with auction params\n\t\tif (!createdPlaceAndTakeIx) {\n\t\t\tallOrders.push(limitAuctionOrderParams);\n\t\t}\n\t} else {\n\t\tconst orderParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection,\n\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\torderConfig,\n\t\t\treduceOnly,\n\t\t\tpostOnly,\n\t\t\tuserOrderId,\n\t\t\tpositionMaxLeverage,\n\t\t});\n\n\t\tconst bitFlags = ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(\n\t\t\tmarketIndex,\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tpositionMaxLeverage,\n\t\t\thighLeverageOptions\n\t\t);\n\t\torderParams.bitFlags = bitFlags;\n\n\t\tallOrders.push(orderParams);\n\t}\n\n\tconst bracketOrdersDirection = ENUM_UTILS.match(\n\t\tdirection,\n\t\tPositionDirection.LONG\n\t)\n\t\t? PositionDirection.SHORT\n\t\t: PositionDirection.LONG;\n\n\tif ('bracketOrders' in orderConfig && orderConfig.bracketOrders?.takeProfit) {\n\t\tconst takeProfitParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount:\n\t\t\t\torderConfig.bracketOrders.takeProfit.baseAssetAmount ??\n\t\t\t\tfinalBaseAssetAmount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'takeProfit',\n\t\t\t\ttriggerPrice: orderConfig.bracketOrders.takeProfit.triggerPrice,\n\t\t\t\tlimitPrice: orderConfig.bracketOrders.takeProfit.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: orderConfig.bracketOrders.takeProfit.reduceOnly ?? true,\n\t\t\tpositionMaxLeverage,\n\t\t});\n\t\tallOrders.push(takeProfitParams);\n\t}\n\n\tif ('bracketOrders' in orderConfig && orderConfig.bracketOrders?.stopLoss) {\n\t\tconst stopLossParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount:\n\t\t\t\torderConfig.bracketOrders.stopLoss.baseAssetAmount ??\n\t\t\t\tfinalBaseAssetAmount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'stopLoss',\n\t\t\t\ttriggerPrice: orderConfig.bracketOrders.stopLoss.triggerPrice,\n\t\t\t\tlimitPrice: orderConfig.bracketOrders.stopLoss.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: orderConfig.bracketOrders.stopLoss.reduceOnly ?? true,\n\t\t\tpositionMaxLeverage,\n\t\t});\n\t\tallOrders.push(stopLossParams);\n\t}\n\n\tif (allOrders.length > 0) {\n\t\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(\n\t\t\tallOrders,\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\tauthority: mainSignerOverride,\n\t\t\t}\n\t\t);\n\t\tallIxs.push(placeOrderIx);\n\t}\n\n\treturn allIxs;\n};\n\n/**\n * Shared prep logic for swift limit orders: validates limit price, resolves base asset amount,\n * computes order params (with or without limit auction), and resolves the user account.\n */\nasync function prepSwiftLimitOrderData(\n\tparams: OpenPerpNonMarketOrderBaseParams & {\n\t\torderConfig: LimitOrderParamsOrderConfig;\n\t}\n) {\n\tconst { user, marketIndex, orderConfig } = params;\n\n\tconst limitPrice = orderConfig.limitPrice;\n\n\tif (limitPrice.isZero()) {\n\t\tthrow new Error('LIMIT orders require limitPrice');\n\t}\n\n\tconst finalBaseAssetAmount = resolveBaseAssetAmount({\n\t\tamount: 'amount' in params ? params.amount : undefined,\n\t\tassetType: 'assetType' in params ? params.assetType : undefined,\n\t\tbaseAssetAmount:\n\t\t\t'baseAssetAmount' in params ? params.baseAssetAmount : undefined,\n\t\tlimitPrice,\n\t});\n\n\tconst orderParams = orderConfig.limitAuction?.enable\n\t\t? await getLimitAuctionOrderParams({\n\t\t\t\t...params,\n\t\t\t\tmarketType: MarketType.PERP,\n\t\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\t\torderConfig: orderConfig as LimitOrderParamsOrderConfig & {\n\t\t\t\t\tlimitAuction: LimitAuctionConfig;\n\t\t\t\t},\n\t\t })\n\t\t: buildNonMarketOrderParams({\n\t\t\t\tmarketIndex,\n\t\t\t\tmarketType: MarketType.PERP,\n\t\t\t\tdirection: params.direction,\n\t\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\t\torderConfig,\n\t\t\t\treduceOnly: params.reduceOnly,\n\t\t\t\tpostOnly: params.postOnly,\n\t\t\t\tuserOrderId: params.userOrderId,\n\t\t\t\tpositionMaxLeverage: params.positionMaxLeverage,\n\t\t });\n\n\tconst userAccount = user.getUserAccount();\n\n\treturn { userAccount, orderParams };\n}\n\nexport const createSwiftLimitOrder = async (\n\tparams: OpenPerpNonMarketOrderParamsWithSwift & {\n\t\torderConfig: LimitOrderParamsOrderConfig;\n\t}\n): Promise<void> => {\n\tconst { driftClient, user, marketIndex, swiftOptions, orderConfig } = params;\n\n\tconst { userAccount, orderParams } = await prepSwiftLimitOrderData(params);\n\n\tawait prepSignAndSendSwiftOrder({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer: swiftOptions.userSigningSlotBuffer,\n\t\tswiftOptions,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: orderConfig.bracketOrders?.takeProfit,\n\t\t\tstopLoss: orderConfig.bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage: params.positionMaxLeverage,\n\t\t\tisolatedPositionDeposit: params.isolatedPositionDeposit,\n\t\t},\n\t\tbuilderParams: params.builderParams,\n\t});\n};\n\nexport type CreateSwiftLimitOrderMessageParams = Omit<\n\tOpenPerpNonMarketOrderBaseParams,\n\t'mainSignerOverride'\n> & {\n\torderConfig: LimitOrderParamsOrderConfig;\n\tisDelegate?: boolean;\n\tuserSigningSlotBuffer?: number;\n};\n\n/**\n * Prepares a Swift limit order message without signing or sending it.\n *\n * @returns The prepared SwiftOrderMessage ready for client-side signing and sending\n */\nexport const createSwiftLimitOrderMessage = async (\n\tparams: CreateSwiftLimitOrderMessageParams\n): Promise<SwiftOrderMessage> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\torderConfig,\n\t\tisDelegate = false,\n\t\tuserSigningSlotBuffer,\n\t} = params;\n\n\tconst { userAccount, orderParams } = await prepSwiftLimitOrderData(params);\n\n\treturn prepSwiftOrderMessage({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer,\n\t\tisDelegate,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: orderConfig.bracketOrders?.takeProfit,\n\t\t\tstopLoss: orderConfig.bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage: params.positionMaxLeverage,\n\t\t\tisolatedPositionDeposit: params.isolatedPositionDeposit,\n\t\t},\n\t\tbuilderParams: params.builderParams,\n\t});\n};\n\nexport const createOpenPerpNonMarketOrderTxn = async (\n\tparams: WithTxnParams<OpenPerpNonMarketOrderBaseParams>\n): Promise<Transaction | VersionedTransaction> => {\n\tconst { driftClient } = params;\n\n\tconst instructions = await createOpenPerpNonMarketOrderIxs(params);\n\n\tconst openPerpNonMarketOrderTxn = await driftClient.buildTransaction(\n\t\tinstructions,\n\t\tparams.txParams\n\t);\n\n\treturn openPerpNonMarketOrderTxn;\n};\n\nexport const createOpenPerpNonMarketOrder = async <T extends boolean>(\n\tparams: WithTxnParams<OpenPerpNonMarketOrderParams<T, SwiftOrderOptions>>\n): Promise<TxnOrSwiftResult<T>> => {\n\tconst { swiftOptions, useSwift, orderConfig } = params;\n\n\t// If useSwift is true, return the Swift result directly\n\tif (useSwift) {\n\t\tif (orderConfig.orderType !== 'limit') {\n\t\t\tthrow new Error('Only limit orders are supported with Swift');\n\t\t}\n\n\t\tif (!swiftOptions) {\n\t\t\tthrow new Error('swiftOptions is required when useSwift is true');\n\t\t}\n\n\t\tconst swiftOrderResult = await createSwiftLimitOrder({\n\t\t\t...params,\n\t\t\tswiftOptions,\n\t\t\torderConfig,\n\t\t});\n\n\t\treturn swiftOrderResult as TxnOrSwiftResult<T>;\n\t}\n\n\tconst marketOrderTxn = await createOpenPerpNonMarketOrderTxn(params);\n\n\treturn marketOrderTxn as TxnOrSwiftResult<T>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.ts"],"names":[],"mappings":";;;AAAA,yCAUyB;AAOzB,sDAK2B;AAC3B,kEAG0C;AAC1C,mDAAqD;AACrD,uEAG2C;AAC3C,gEAA6E;AAS7E,gEAA0E;AAC1E,wCAAwD;AACxD,wEAGoC;AAkEpC,6BAA6B;AAC7B;;GAEG;AACI,MAAM,sCAAsC,GAAG,KAAK,EAAE,MAS5D,EAAmC,EAAE;IACrC,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAAC;IAEvE,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,uCAAyB,CAAC,CAAC;IAEtE,IAAI,MAAM,CAAC,qBAAqB,IAAI,WAA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AM,CAAC,CAAC;IAErE,OAAO,cAAqC,CAAC;AAC9C,CAAC,CAAC;AA3BW,QAAA,4BAA4B,gCA2BvC","sourcesContent":["import {\n\tDriftClient,\n\tUser,\n\tBN,\n\tMarketType,\n\tPostOnlyParams,\n\tOptionalOrderParams,\n\tPositionDirection,\n\tOrderParamsBitFlag,\n\tOrderType,\n} from '@drift-labs/sdk';\nimport {\n\tPublicKey,\n\tTransaction,\n\tTransactionInstruction,\n\tVersionedTransaction,\n} from '@solana/web3.js';\nimport {\n\tprepSignAndSendSwiftOrder,\n\tprepSwiftOrderMessage,\n\tSwiftOrderOptions,\n\tSwiftOrderMessage,\n} from '../openSwiftOrder';\nimport {\n\tbuildNonMarketOrderParams,\n\tresolveBaseAssetAmount,\n} from '../../../../../utils/orderParams';\nimport { ENUM_UTILS } from '../../../../../../utils';\nimport {\n\tHighLeverageOptions,\n\tORDER_COMMON_UTILS,\n} from '../../../../../../common-ui-utils';\nimport { createPlaceAndTakePerpMarketOrderIx } from '../openPerpMarketOrder';\nimport {\n\tTxnOrSwiftResult,\n\tLimitAuctionConfig,\n\tLimitOrderParamsOrderConfig,\n\tNonMarketOrderParamsConfig,\n\tIsolatedPositionDepositsOverride,\n} from '../types';\nimport { WithTxnParams } from '../../../../types';\nimport { getPositionMaxLeverageIxIfNeeded } from '../positionMaxLeverage';\nimport { getLimitAuctionOrderParams } from '../auction';\nimport {\n\tgetIsolatedPositionDepositIxIfNeeded,\n\tresolveIsolatedPositionDepositsWithOverride,\n} from '../isolatedPositionDeposit';\n\nexport interface OpenPerpNonMarketOrderBaseParams\n\textends Omit<NonMarketOrderParamsConfig, 'marketType' | 'baseAssetAmount'> {\n\tdriftClient: DriftClient;\n\tuser: User;\n\t// Either new approach\n\tamount?: BN;\n\tassetType?: 'base' | 'quote';\n\t// Or legacy approach\n\tbaseAssetAmount?: BN;\n\t// Common optional params\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\tuserOrderId?: number;\n\t/**\n\t * Position margin mode to use for the order.\n\t * When 'isolated', auto-computes isolated position deposit from positionMaxLeverage,\n\t * and any additional isolated position deposits need to replenish under-collateralized positions.\n\t * If not provided, the position margin mode will be derived from the user's position margin mode,\n\t * and if that does not exist, it will default to 'cross'.\n\t */\n\tmarginMode?: 'isolated' | 'cross';\n\t/**\n\t * Pre-computed isolated position deposits override. When provided,\n\t * skips auto-compute and uses these values directly.\n\t */\n\tisolatedPositionDepositsOverride?: IsolatedPositionDepositsOverride;\n\tautoEnterHighLeverageModeBufferPct?: number;\n\t/**\n\t * If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.\n\t * This is only applicable for non-SWIFT orders.\n\t */\n\tmainSignerOverride?: PublicKey;\n\t/**\n\t * Optional builder code parameters for revenue sharing.\n\t * Only applicable for Swift orders for now.\n\t */\n\tbuilderParams?: {\n\t\tbuilderIdx: number;\n\t\tbuilderFeeTenthBps: number;\n\t};\n\thighLeverageOptions?: HighLeverageOptions;\n}\n\nexport interface OpenPerpNonMarketOrderParamsWithSwift\n\textends OpenPerpNonMarketOrderBaseParams {\n\tswiftOptions: SwiftOrderOptions;\n}\n\nexport type OpenPerpNonMarketOrderParams<\n\tT extends boolean = boolean,\n\tS extends Omit<SwiftOrderOptions, 'swiftServerUrl'> = Omit<\n\t\tSwiftOrderOptions,\n\t\t'swiftServerUrl'\n\t>\n> = T extends true\n\t? OpenPerpNonMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tswiftOptions: S;\n\t }\n\t: OpenPerpNonMarketOrderBaseParams & {\n\t\t\tuseSwift: T;\n\t\t\tswiftOptions?: never;\n\t };\n\n// TODO: add isolated margin?\n/**\n * Creates a transaction instruction to open multiple non-market orders.\n */\nexport const createMultipleOpenPerpNonMarketOrderIx = async (params: {\n\tdriftClient: DriftClient;\n\tuser: User;\n\torderParamsConfigs: NonMarketOrderParamsConfig[];\n\tenterHighLeverageMode?: boolean;\n\t/**\n\t * If provided, will override the main signer for the order. Otherwise, the main signer will be the user's authority.\n\t */\n\tmainSignerOverride?: PublicKey;\n}): Promise<TransactionInstruction> => {\n\tconst { driftClient, orderParamsConfigs, mainSignerOverride } = params;\n\n\tconst orderParams = orderParamsConfigs.map(buildNonMarketOrderParams);\n\n\tif (params.enterHighLeverageMode && orderParams.length > 0) {\n\t\torderParams[0].bitFlags = OrderParamsBitFlag.UpdateHighLeverageMode;\n\t}\n\n\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(\n\t\torderParams,\n\t\tundefined,\n\t\t{\n\t\t\tauthority: mainSignerOverride,\n\t\t}\n\t);\n\treturn placeOrderIx;\n};\n\n/**\n * Creates a transaction instruction to open a non-market order.\n * Allows for bracket orders to be opened in the same transaction.\n *\n * If `limitAuction` is enabled, a placeAndTake order is created to simulate a market auction order,\n * with the end price being the limit price.\n */\nexport const createOpenPerpNonMarketOrderIxs = async (\n\tparams: OpenPerpNonMarketOrderBaseParams\n): Promise<TransactionInstruction[]> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\tdirection,\n\t\treduceOnly = false,\n\t\tpostOnly = PostOnlyParams.NONE,\n\t\torderConfig,\n\t\tuserOrderId = 0,\n\t\tpositionMaxLeverage,\n\t\tmarginMode,\n\t\tmainSignerOverride,\n\t\thighLeverageOptions,\n\t\tisolatedPositionDepositsOverride,\n\t} = params;\n\t// Support both new (amount + assetType) and legacy (baseAssetAmount) approaches\n\tconst finalBaseAssetAmount = resolveBaseAssetAmount({\n\t\tamount: 'amount' in params ? params.amount : undefined,\n\t\tassetType: 'assetType' in params ? params.assetType : undefined,\n\t\tbaseAssetAmount:\n\t\t\t'baseAssetAmount' in params ? params.baseAssetAmount : undefined,\n\t\tlimitPrice:\n\t\t\t'limitPrice' in params.orderConfig\n\t\t\t\t? params.orderConfig.limitPrice\n\t\t\t\t: undefined,\n\t});\n\n\tif (!finalBaseAssetAmount || finalBaseAssetAmount.isZero()) {\n\t\tthrow new Error('Final base asset amount must be greater than zero');\n\t}\n\n\tconst resolvedDeposits = resolveIsolatedPositionDepositsWithOverride(\n\t\tisolatedPositionDepositsOverride,\n\t\t{\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex,\n\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\tdirection,\n\t\t\tpositionMaxLeverage,\n\t\t\tmarginMode,\n\t\t\treplenishUnderwaterPositions: true,\n\t\t\tnumOfOpenHighLeverageSpots:\n\t\t\t\thighLeverageOptions?.numOfOpenHighLeverageSpots,\n\t\t}\n\t);\n\n\tconst mainIsolatedPositionDeposit = resolvedDeposits?.mainDeposit;\n\tconst resolvedAdditionalDeposits =\n\t\tresolvedDeposits?.additionalIsolatedPositionDeposits;\n\n\tconst allOrders: OptionalOrderParams[] = [];\n\tconst allIxs: TransactionInstruction[] = [];\n\n\t// Fetch all deposit/leverage ixs in parallel\n\tconst [leverageIx, additionalDepositIxs, isolatedPositionDepositIx] =\n\t\tawait Promise.all([\n\t\t\tgetPositionMaxLeverageIxIfNeeded(\n\t\t\t\tdriftClient,\n\t\t\t\tuser,\n\t\t\t\tmarketIndex,\n\t\t\t\tpositionMaxLeverage,\n\t\t\t\tmainSignerOverride\n\t\t\t),\n\t\t\tresolvedAdditionalDeposits?.length\n\t\t\t\t? Promise.all(\n\t\t\t\t\t\tresolvedAdditionalDeposits.map((deposit) =>\n\t\t\t\t\t\t\tgetIsolatedPositionDepositIxIfNeeded(\n\t\t\t\t\t\t\t\tdriftClient,\n\t\t\t\t\t\t\t\tuser,\n\t\t\t\t\t\t\t\tdeposit.marketIndex,\n\t\t\t\t\t\t\t\tdeposit.amount,\n\t\t\t\t\t\t\t\tmainSignerOverride\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t: Promise.resolve([] as (TransactionInstruction | undefined)[]),\n\t\t\tgetIsolatedPositionDepositIxIfNeeded(\n\t\t\t\tdriftClient,\n\t\t\t\tuser,\n\t\t\t\tmarketIndex,\n\t\t\t\tmainIsolatedPositionDeposit,\n\t\t\t\tmainSignerOverride\n\t\t\t),\n\t\t]);\n\n\tif (leverageIx) {\n\t\tallIxs.push(leverageIx);\n\t}\n\tfor (const ix of additionalDepositIxs) {\n\t\tif (ix) {\n\t\t\tallIxs.push(ix);\n\t\t}\n\t}\n\tif (isolatedPositionDepositIx) {\n\t\tallIxs.push(isolatedPositionDepositIx);\n\t}\n\n\t// handle limit auction\n\tif (\n\t\torderConfig.orderType === 'limit' &&\n\t\torderConfig.limitAuction?.enable &&\n\t\tENUM_UTILS.match(postOnly, PostOnlyParams.NONE)\n\t) {\n\t\tconst limitAuctionOrderParams = await getLimitAuctionOrderParams({\n\t\t\t...params,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\torderConfig: orderConfig as LimitOrderParamsOrderConfig & {\n\t\t\t\tlimitAuction: LimitAuctionConfig;\n\t\t\t},\n\t\t});\n\n\t\tlet createdPlaceAndTakeIx = false;\n\n\t\t// if it is a limit auction order, we create a placeAndTake order to simulate a market order.\n\t\t// this is useful when a limit order is crossing, and we want to achieve the best fill price through a placeAndTake.\n\t\t// falls back to limit order with auction params if the placeAndTake order creation fails\n\t\tif (\n\t\t\tlimitAuctionOrderParams.auctionDuration &&\n\t\t\tlimitAuctionOrderParams.auctionDuration > 0 &&\n\t\t\torderConfig.limitAuction?.usePlaceAndTake?.enable\n\t\t) {\n\t\t\ttry {\n\t\t\t\tconst placeAndTakeIx = await createPlaceAndTakePerpMarketOrderIx({\n\t\t\t\t\tassetType: 'base',\n\t\t\t\t\tamount: finalBaseAssetAmount,\n\t\t\t\t\torderType: OrderType.LIMIT,\n\t\t\t\t\tprice: orderConfig.limitPrice,\n\t\t\t\t\tdirection,\n\t\t\t\t\tdlobServerHttpUrl: orderConfig.limitAuction.dlobServerHttpUrl,\n\t\t\t\t\tmarketIndex,\n\t\t\t\t\tdriftClient,\n\t\t\t\t\tuser,\n\t\t\t\t\tuserOrderId,\n\t\t\t\t\treduceOnly,\n\t\t\t\t\tpositionMaxLeverage,\n\t\t\t\t\toptionalAuctionParamsInputs:\n\t\t\t\t\t\torderConfig.limitAuction.optionalLimitAuctionParams,\n\t\t\t\t\tauctionDurationPercentage:\n\t\t\t\t\t\torderConfig.limitAuction.usePlaceAndTake.auctionDurationPercentage,\n\t\t\t\t\treferrerInfo: orderConfig.limitAuction.usePlaceAndTake.referrerInfo,\n\t\t\t\t\thighLeverageOptions,\n\t\t\t\t});\n\t\t\t\tallIxs.push(placeAndTakeIx);\n\t\t\t\tcreatedPlaceAndTakeIx = true;\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t'Failed to create placeAndTake order for limit auction order',\n\t\t\t\t\te\n\t\t\t\t);\n\t\t\t\tcreatedPlaceAndTakeIx = false;\n\t\t\t}\n\t\t}\n\n\t\t// fallback to normal limit order with auction params\n\t\tif (!createdPlaceAndTakeIx) {\n\t\t\tallOrders.push(limitAuctionOrderParams);\n\t\t}\n\t} else {\n\t\tconst orderParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection,\n\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\torderConfig,\n\t\t\treduceOnly,\n\t\t\tpostOnly,\n\t\t\tuserOrderId,\n\t\t});\n\n\t\tconst bitFlags = ORDER_COMMON_UTILS.getPerpOrderParamsBitFlags(\n\t\t\tmarketIndex,\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tpositionMaxLeverage,\n\t\t\thighLeverageOptions\n\t\t);\n\t\torderParams.bitFlags = bitFlags;\n\n\t\tallOrders.push(orderParams);\n\t}\n\n\tconst bracketOrdersDirection = ENUM_UTILS.match(\n\t\tdirection,\n\t\tPositionDirection.LONG\n\t)\n\t\t? PositionDirection.SHORT\n\t\t: PositionDirection.LONG;\n\n\tif ('bracketOrders' in orderConfig && orderConfig.bracketOrders?.takeProfit) {\n\t\tconst takeProfitParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount:\n\t\t\t\torderConfig.bracketOrders.takeProfit.baseAssetAmount ??\n\t\t\t\tfinalBaseAssetAmount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'takeProfit',\n\t\t\t\ttriggerPrice: orderConfig.bracketOrders.takeProfit.triggerPrice,\n\t\t\t\tlimitPrice: orderConfig.bracketOrders.takeProfit.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: orderConfig.bracketOrders.takeProfit.reduceOnly ?? true,\n\t\t});\n\t\tallOrders.push(takeProfitParams);\n\t}\n\n\tif ('bracketOrders' in orderConfig && orderConfig.bracketOrders?.stopLoss) {\n\t\tconst stopLossParams = buildNonMarketOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType: MarketType.PERP,\n\t\t\tdirection: bracketOrdersDirection,\n\t\t\tbaseAssetAmount:\n\t\t\t\torderConfig.bracketOrders.stopLoss.baseAssetAmount ??\n\t\t\t\tfinalBaseAssetAmount,\n\t\t\torderConfig: {\n\t\t\t\torderType: 'stopLoss',\n\t\t\t\ttriggerPrice: orderConfig.bracketOrders.stopLoss.triggerPrice,\n\t\t\t\tlimitPrice: orderConfig.bracketOrders.stopLoss.limitPrice,\n\t\t\t},\n\t\t\treduceOnly: orderConfig.bracketOrders.stopLoss.reduceOnly ?? true,\n\t\t});\n\t\tallOrders.push(stopLossParams);\n\t}\n\n\tif (allOrders.length > 0) {\n\t\tconst placeOrderIx = await driftClient.getPlaceOrdersIx(\n\t\t\tallOrders,\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\tauthority: mainSignerOverride,\n\t\t\t}\n\t\t);\n\t\tallIxs.push(placeOrderIx);\n\t}\n\n\treturn allIxs;\n};\n\n/**\n * Shared prep logic for swift limit orders: validates limit price, resolves base asset amount,\n * computes order params (with or without limit auction), and resolves the user account.\n */\nasync function prepSwiftLimitOrderData(\n\tparams: OpenPerpNonMarketOrderBaseParams & {\n\t\torderConfig: LimitOrderParamsOrderConfig;\n\t}\n) {\n\tconst { user, marketIndex, orderConfig } = params;\n\n\tconst limitPrice = orderConfig.limitPrice;\n\n\tif (limitPrice.isZero()) {\n\t\tthrow new Error('LIMIT orders require limitPrice');\n\t}\n\n\tconst finalBaseAssetAmount = resolveBaseAssetAmount({\n\t\tamount: 'amount' in params ? params.amount : undefined,\n\t\tassetType: 'assetType' in params ? params.assetType : undefined,\n\t\tbaseAssetAmount:\n\t\t\t'baseAssetAmount' in params ? params.baseAssetAmount : undefined,\n\t\tlimitPrice,\n\t});\n\n\tconst orderParams = orderConfig.limitAuction?.enable\n\t\t? await getLimitAuctionOrderParams({\n\t\t\t\t...params,\n\t\t\t\tmarketType: MarketType.PERP,\n\t\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\t\torderConfig: orderConfig as LimitOrderParamsOrderConfig & {\n\t\t\t\t\tlimitAuction: LimitAuctionConfig;\n\t\t\t\t},\n\t\t })\n\t\t: buildNonMarketOrderParams({\n\t\t\t\tmarketIndex,\n\t\t\t\tmarketType: MarketType.PERP,\n\t\t\t\tdirection: params.direction,\n\t\t\t\tbaseAssetAmount: finalBaseAssetAmount,\n\t\t\t\torderConfig,\n\t\t\t\treduceOnly: params.reduceOnly,\n\t\t\t\tpostOnly: params.postOnly,\n\t\t\t\tuserOrderId: params.userOrderId,\n\t\t });\n\n\tconst userAccount = user.getUserAccount();\n\n\treturn { userAccount, orderParams };\n}\n\nexport const createSwiftLimitOrder = async (\n\tparams: OpenPerpNonMarketOrderParamsWithSwift & {\n\t\torderConfig: LimitOrderParamsOrderConfig;\n\t}\n): Promise<void> => {\n\tconst { driftClient, user, marketIndex, swiftOptions, orderConfig } = params;\n\n\tconst { userAccount, orderParams } = await prepSwiftLimitOrderData(params);\n\n\tconst resolvedDeposits = resolveIsolatedPositionDepositsWithOverride(\n\t\tparams.isolatedPositionDepositsOverride,\n\t\t{\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex,\n\t\t\tbaseAssetAmount: orderParams.baseAssetAmount,\n\t\t\tdirection: orderParams.direction,\n\t\t\tpositionMaxLeverage: params.positionMaxLeverage,\n\t\t\tmarginMode: params.marginMode,\n\t\t\treplenishUnderwaterPositions: false, // Swift doesn't support additional deposits, so throw on underwater positions\n\t\t\tnumOfOpenHighLeverageSpots:\n\t\t\t\tparams.highLeverageOptions?.numOfOpenHighLeverageSpots,\n\t\t}\n\t);\n\n\tawait prepSignAndSendSwiftOrder({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer: swiftOptions.userSigningSlotBuffer,\n\t\tswiftOptions,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: orderConfig.bracketOrders?.takeProfit,\n\t\t\tstopLoss: orderConfig.bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage: params.positionMaxLeverage,\n\t\t\tisolatedPositionDeposit: resolvedDeposits?.mainDeposit,\n\t\t},\n\t\tbuilderParams: params.builderParams,\n\t});\n};\n\nexport type CreateSwiftLimitOrderMessageParams = Omit<\n\tOpenPerpNonMarketOrderBaseParams,\n\t'mainSignerOverride'\n> & {\n\torderConfig: LimitOrderParamsOrderConfig;\n\tisDelegate?: boolean;\n\tuserSigningSlotBuffer?: number;\n};\n\n/**\n * Prepares a Swift limit order message without signing or sending it.\n *\n * @returns The prepared SwiftOrderMessage ready for client-side signing and sending\n */\nexport const createSwiftLimitOrderMessage = async (\n\tparams: CreateSwiftLimitOrderMessageParams\n): Promise<SwiftOrderMessage> => {\n\tconst {\n\t\tdriftClient,\n\t\tuser,\n\t\tmarketIndex,\n\t\torderConfig,\n\t\tisDelegate = false,\n\t\tuserSigningSlotBuffer,\n\t} = params;\n\n\tconst { userAccount, orderParams } = await prepSwiftLimitOrderData(params);\n\n\tconst resolvedDeposits = resolveIsolatedPositionDepositsWithOverride(\n\t\tparams.isolatedPositionDepositsOverride,\n\t\t{\n\t\t\tdriftClient,\n\t\t\tuser,\n\t\t\tmarketIndex,\n\t\t\tbaseAssetAmount: orderParams.baseAssetAmount,\n\t\t\tdirection: orderParams.direction,\n\t\t\tpositionMaxLeverage: params.positionMaxLeverage,\n\t\t\tmarginMode: params.marginMode,\n\t\t\treplenishUnderwaterPositions: false, // Swift doesn't support additional deposits, so throw on underwater positions\n\t\t\tnumOfOpenHighLeverageSpots:\n\t\t\t\tparams.highLeverageOptions?.numOfOpenHighLeverageSpots,\n\t\t}\n\t);\n\n\treturn prepSwiftOrderMessage({\n\t\tdriftClient,\n\t\tsubAccountId: userAccount.subAccountId,\n\t\tuserAccountPubKey: user.userAccountPublicKey,\n\t\tmarketIndex,\n\t\tuserSigningSlotBuffer,\n\t\tisDelegate,\n\t\torderParams: {\n\t\t\tmain: orderParams,\n\t\t\ttakeProfit: orderConfig.bracketOrders?.takeProfit,\n\t\t\tstopLoss: orderConfig.bracketOrders?.stopLoss,\n\t\t\tpositionMaxLeverage: params.positionMaxLeverage,\n\t\t\tisolatedPositionDeposit: resolvedDeposits?.mainDeposit,\n\t\t},\n\t\tbuilderParams: params.builderParams,\n\t});\n};\n\nexport const createOpenPerpNonMarketOrderTxn = async (\n\tparams: WithTxnParams<OpenPerpNonMarketOrderBaseParams>\n): Promise<Transaction | VersionedTransaction> => {\n\tconst { driftClient } = params;\n\n\tconst instructions = await createOpenPerpNonMarketOrderIxs(params);\n\n\tconst openPerpNonMarketOrderTxn = await driftClient.buildTransaction(\n\t\tinstructions,\n\t\tparams.txParams\n\t);\n\n\treturn openPerpNonMarketOrderTxn;\n};\n\nexport const createOpenPerpNonMarketOrder = async <T extends boolean>(\n\tparams: WithTxnParams<OpenPerpNonMarketOrderParams<T, SwiftOrderOptions>>\n): Promise<TxnOrSwiftResult<T>> => {\n\tconst { swiftOptions, useSwift, orderConfig } = params;\n\n\t// If useSwift is true, return the Swift result directly\n\tif (useSwift) {\n\t\tif (orderConfig.orderType !== 'limit') {\n\t\t\tthrow new Error('Only limit orders are supported with Swift');\n\t\t}\n\n\t\tif (!swiftOptions) {\n\t\t\tthrow new Error('swiftOptions is required when useSwift is true');\n\t\t}\n\n\t\tconst swiftOrderResult = await createSwiftLimitOrder({\n\t\t\t...params,\n\t\t\tswiftOptions,\n\t\t\torderConfig,\n\t\t});\n\n\t\treturn swiftOrderResult as TxnOrSwiftResult<T>;\n\t}\n\n\tconst marketOrderTxn = await createOpenPerpNonMarketOrderTxn(params);\n\n\treturn marketOrderTxn as TxnOrSwiftResult<T>;\n};\n"]}
|
|
@@ -11,6 +11,16 @@ export interface AdditionalIsolatedPositionDeposit {
|
|
|
11
11
|
marketIndex: number;
|
|
12
12
|
amount: BN;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Override for isolated position deposits. When provided on order params,
|
|
16
|
+
* skips auto-compute and uses these values directly.
|
|
17
|
+
*/
|
|
18
|
+
export interface IsolatedPositionDepositsOverride {
|
|
19
|
+
/** The main deposit amount for this market's isolated position. */
|
|
20
|
+
mainDeposit: BN;
|
|
21
|
+
/** Additional deposits for other under-collateralized isolated positions. */
|
|
22
|
+
additionalDeposits?: AdditionalIsolatedPositionDeposit[];
|
|
23
|
+
}
|
|
14
24
|
export type PlaceAndTakeParams = {
|
|
15
25
|
enable: false;
|
|
16
26
|
} | {
|
|
@@ -67,12 +77,6 @@ export interface NonMarketOrderParamsConfig {
|
|
|
67
77
|
* Example: 5 for 5x leverage, 10 for 10x leverage
|
|
68
78
|
*/
|
|
69
79
|
positionMaxLeverage: number;
|
|
70
|
-
isolatedPositionDeposit?: BN;
|
|
71
|
-
/**
|
|
72
|
-
* Additional isolated position deposits needed to top up other
|
|
73
|
-
* under-collateralized isolated positions before placing the order.
|
|
74
|
-
*/
|
|
75
|
-
additionalIsolatedPositionDeposits?: AdditionalIsolatedPositionDeposit[];
|
|
76
80
|
orderConfig: LimitOrderParamsOrderConfig | {
|
|
77
81
|
orderType: Extract<NonMarketOrderType, 'takeProfit' | 'stopLoss'>;
|
|
78
82
|
triggerPrice: BN;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/drift/base/actions/trade/openPerpOrder/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n\tBN,\n\tMarketType,\n\tPositionDirection,\n\tPostOnlyParams,\n\tReferrerInfo,\n} from '@drift-labs/sdk';\nimport { Transaction, VersionedTransaction } from '@solana/web3.js';\nimport { OptionalAuctionParamsRequestInputs } from './dlobServer';\nimport { AuctionParamsFetchedCallback } from '../../../../utils/auctionParamsResponseMapper';\n\nexport type TxnOrSwiftResult<T extends boolean> = T extends true\n\t? void\n\t: Transaction | VersionedTransaction;\n\n/**\n * Represents an additional isolated position deposit needed to top up\n * an under-collateralized isolated position before placing an order.\n */\nexport interface AdditionalIsolatedPositionDeposit {\n\tmarketIndex: number;\n\tamount: BN;\n}\n\nexport type PlaceAndTakeParams =\n\t| {\n\t\t\tenable: false;\n\t }\n\t| {\n\t\t\tenable: true;\n\t\t\tauctionDurationPercentage?: number;\n\t\t\treferrerInfo: ReferrerInfo | undefined;\n\t };\n\nexport type NonMarketOrderType =\n\t| 'limit'\n\t| 'takeProfit'\n\t| 'stopLoss'\n\t| 'oracleLimit';\n\nexport interface LimitAuctionConfig {\n\tenable: boolean;\n\tdlobServerHttpUrl: string;\n\tauctionStartPriceOffset: number;\n\toraclePrice?: BN; // used to calculate oracle price bands\n\toptionalLimitAuctionParams?: OptionalAuctionParamsRequestInputs;\n\tusePlaceAndTake?: {\n\t\tenable: boolean;\n\t\treferrerInfo?: ReferrerInfo; // needed for place and take fallback\n\t\tauctionDurationPercentage?: number;\n\t};\n\tonAuctionParamsFetched?: AuctionParamsFetchedCallback;\n}\n\nexport interface OptionalTriggerOrderParams {\n\tbaseAssetAmount?: BN;\n\ttriggerPrice: BN;\n\tlimitPrice?: BN;\n\treduceOnly?: boolean;\n}\n\nexport interface LimitOrderParamsOrderConfig {\n\torderType: Extract<NonMarketOrderType, 'limit'>;\n\tlimitPrice: BN;\n\tbracketOrders?: {\n\t\ttakeProfit?: OptionalTriggerOrderParams;\n\t\tstopLoss?: OptionalTriggerOrderParams;\n\t};\n\t/**\n\t * Limit orders can have an optional auction that allows it to go through the auction process.\n\t * Usually, the auction params are set up to the limit price, to allow for a possible improved\n\t * fill price. This is useful for when a limit order is crossing the orderbook.\n\t */\n\tlimitAuction?: LimitAuctionConfig;\n}\n\nexport interface NonMarketOrderParamsConfig {\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tdirection: PositionDirection;\n\tbaseAssetAmount: BN;\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\tuserOrderId?: number;\n\t/**\n\t * The leverage to be used for this position.\n\t * If different from current position's leverage, will add an instruction\n\t * to update the position's maxMarginRatio before placing the order.\n\t * Example: 5 for 5x leverage, 10 for 10x leverage\n\t */\n\tpositionMaxLeverage: number;\n\
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/drift/base/actions/trade/openPerpOrder/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n\tBN,\n\tMarketType,\n\tPositionDirection,\n\tPostOnlyParams,\n\tReferrerInfo,\n} from '@drift-labs/sdk';\nimport { Transaction, VersionedTransaction } from '@solana/web3.js';\nimport { OptionalAuctionParamsRequestInputs } from './dlobServer';\nimport { AuctionParamsFetchedCallback } from '../../../../utils/auctionParamsResponseMapper';\n\nexport type TxnOrSwiftResult<T extends boolean> = T extends true\n\t? void\n\t: Transaction | VersionedTransaction;\n\n/**\n * Represents an additional isolated position deposit needed to top up\n * an under-collateralized isolated position before placing an order.\n */\nexport interface AdditionalIsolatedPositionDeposit {\n\tmarketIndex: number;\n\tamount: BN;\n}\n\n/**\n * Override for isolated position deposits. When provided on order params,\n * skips auto-compute and uses these values directly.\n */\nexport interface IsolatedPositionDepositsOverride {\n\t/** The main deposit amount for this market's isolated position. */\n\tmainDeposit: BN;\n\t/** Additional deposits for other under-collateralized isolated positions. */\n\tadditionalDeposits?: AdditionalIsolatedPositionDeposit[];\n}\n\nexport type PlaceAndTakeParams =\n\t| {\n\t\t\tenable: false;\n\t }\n\t| {\n\t\t\tenable: true;\n\t\t\tauctionDurationPercentage?: number;\n\t\t\treferrerInfo: ReferrerInfo | undefined;\n\t };\n\nexport type NonMarketOrderType =\n\t| 'limit'\n\t| 'takeProfit'\n\t| 'stopLoss'\n\t| 'oracleLimit';\n\nexport interface LimitAuctionConfig {\n\tenable: boolean;\n\tdlobServerHttpUrl: string;\n\tauctionStartPriceOffset: number;\n\toraclePrice?: BN; // used to calculate oracle price bands\n\toptionalLimitAuctionParams?: OptionalAuctionParamsRequestInputs;\n\tusePlaceAndTake?: {\n\t\tenable: boolean;\n\t\treferrerInfo?: ReferrerInfo; // needed for place and take fallback\n\t\tauctionDurationPercentage?: number;\n\t};\n\tonAuctionParamsFetched?: AuctionParamsFetchedCallback;\n}\n\nexport interface OptionalTriggerOrderParams {\n\tbaseAssetAmount?: BN;\n\ttriggerPrice: BN;\n\tlimitPrice?: BN;\n\treduceOnly?: boolean;\n}\n\nexport interface LimitOrderParamsOrderConfig {\n\torderType: Extract<NonMarketOrderType, 'limit'>;\n\tlimitPrice: BN;\n\tbracketOrders?: {\n\t\ttakeProfit?: OptionalTriggerOrderParams;\n\t\tstopLoss?: OptionalTriggerOrderParams;\n\t};\n\t/**\n\t * Limit orders can have an optional auction that allows it to go through the auction process.\n\t * Usually, the auction params are set up to the limit price, to allow for a possible improved\n\t * fill price. This is useful for when a limit order is crossing the orderbook.\n\t */\n\tlimitAuction?: LimitAuctionConfig;\n}\n\nexport interface NonMarketOrderParamsConfig {\n\tmarketIndex: number;\n\tmarketType: MarketType;\n\tdirection: PositionDirection;\n\tbaseAssetAmount: BN;\n\treduceOnly?: boolean;\n\tpostOnly?: PostOnlyParams;\n\tuserOrderId?: number;\n\t/**\n\t * The leverage to be used for this position.\n\t * If different from current position's leverage, will add an instruction\n\t * to update the position's maxMarginRatio before placing the order.\n\t * Example: 5 for 5x leverage, 10 for 10x leverage\n\t */\n\tpositionMaxLeverage: number;\n\torderConfig:\n\t\t| LimitOrderParamsOrderConfig\n\t\t| {\n\t\t\t\torderType: Extract<NonMarketOrderType, 'takeProfit' | 'stopLoss'>;\n\t\t\t\ttriggerPrice: BN;\n\t\t\t\tlimitPrice?: BN;\n\t\t }\n\t\t| {\n\t\t\t\torderType: Extract<NonMarketOrderType, 'oracleLimit'>;\n\t\t\t\toraclePriceOffset: BN;\n\t\t };\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { User } from '@drift-labs/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* The position's margin mode based on the position's `positionFlag`. Returns 'cross' if no position is found.
|
|
4
|
+
*
|
|
5
|
+
* @param user - The user to get the position margin mode for
|
|
6
|
+
* @param marketIndex - The market index to get the position margin mode for
|
|
7
|
+
*/
|
|
8
|
+
export declare const getPositionMarginMode: (user: User, marketIndex: number) => 'isolated' | 'cross';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPositionMarginMode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The position's margin mode based on the position's `positionFlag`. Returns 'cross' if no position is found.
|
|
6
|
+
*
|
|
7
|
+
* @param user - The user to get the position margin mode for
|
|
8
|
+
* @param marketIndex - The market index to get the position margin mode for
|
|
9
|
+
*/
|
|
10
|
+
const getPositionMarginMode = (user, marketIndex) => {
|
|
11
|
+
const perpPosition = user.getPerpPosition(marketIndex);
|
|
12
|
+
if (!perpPosition)
|
|
13
|
+
return 'cross';
|
|
14
|
+
const isIsolated = user.isPerpPositionIsolated(perpPosition);
|
|
15
|
+
return isIsolated ? 'isolated' : 'cross';
|
|
16
|
+
};
|
|
17
|
+
exports.getPositionMarginMode = getPositionMarginMode;
|
|
18
|
+
//# sourceMappingURL=positionMarginMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positionMarginMode.js","sourceRoot":"","sources":["../../../../../src/drift/base/details/user/positionMarginMode.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,MAAM,qBAAqB,GAAG,CACpC,IAAU,EACV,WAAmB,EACI,EAAE;IACzB,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IACvD,IAAI,CAAC,YAAY;QAAE,OAAO,OAAO,CAAC;IAClC,MAAM,UAAU,GAAG,IAAI,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAC7D,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;AAC1C,CAAC,CAAC;AARW,QAAA,qBAAqB,yBAQhC","sourcesContent":["import { User } from '@drift-labs/sdk';\n\n/**\n * The position's margin mode based on the position's `positionFlag`. Returns 'cross' if no position is found.\n *\n * @param user - The user to get the position margin mode for\n * @param marketIndex - The market index to get the position margin mode for\n */\nexport const getPositionMarginMode = (\n\tuser: User,\n\tmarketIndex: number\n): 'isolated' | 'cross' => {\n\tconst perpPosition = user.getPerpPosition(marketIndex);\n\tif (!perpPosition) return 'cross';\n\tconst isIsolated = user.isPerpPositionIsolated(perpPosition);\n\treturn isIsolated ? 'isolated' : 'cross';\n};\n"]}
|
|
@@ -20,4 +20,4 @@ export declare function resolveBaseAssetAmount(params: {
|
|
|
20
20
|
/**
|
|
21
21
|
* Builds proper order parameters for non-market orders using the same logic as the UI
|
|
22
22
|
*/
|
|
23
|
-
export declare function buildNonMarketOrderParams({ marketIndex, marketType, direction, baseAssetAmount, orderConfig, reduceOnly, postOnly, userOrderId, }: NonMarketOrderParamsConfig): OptionalOrderParams;
|
|
23
|
+
export declare function buildNonMarketOrderParams({ marketIndex, marketType, direction, baseAssetAmount, orderConfig, reduceOnly, postOnly, userOrderId, }: Omit<NonMarketOrderParamsConfig, 'positionMaxLeverage'>): OptionalOrderParams;
|