@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":"orderParams.js","sourceRoot":"","sources":["../../../src/drift/utils/orderParams.ts"],"names":[],"mappings":";;;AAAA,yCAUyB;AACzB,uCAAyC;AAGzC;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACvC,MAAU,EACV,SAA2B,EAC3B,UAAe;IAEf,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACd,mFAAmF,CACnF,CAAC;QACH,CAAC;QACD,wEAAwE;QACxE,iEAAiE;QACjE,MAAM,eAAe,GAAG,IAAI,QAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,QAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;SAAM,CAAC;QACP,4BAA4B;QAC5B,OAAO,MAAM,CAAC;IACf,CAAC;AACF,CAAC;AAnBD,4DAmBC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,MAKtC;IACA,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAElE,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;QACzB,kCAAkC;QAClC,OAAO,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IAChE,CAAC;SAAM,IAAI,eAAe,EAAE,CAAC;QAC5B,kBAAkB;QAClB,OAAO,eAAe,CAAC;IACxB,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACd,iEAAiE,CACjE,CAAC;IACH,CAAC;AACF,CAAC;AAnBD,wDAmBC;AAED;;;;GAIG;AACH,MAAM,mBAAmB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AM,CAAC;YACP,OAAO,IAAA,iCAA2B,EAAC;gBAClC,WAAW;gBACX,UAAU;gBACV,SAAS;gBACT,eAAe;gBACf,YAAY,EAAE,WAAW,CAAC,YAAY;gBACtC,KAAK,EAAE,WAAW,CAAC,UAAU;gBAC7B,gBAAgB;gBAChB,UAAU;gBACV,QAAQ;gBACR,WAAW;aACX,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,IAAI,SAAS,KAAK,aAAa,EAAE,CAAC;QACjC,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,IAAA,yBAAmB,EAAC;YAC1B,WAAW;YACX,UAAU;YACV,SAAS;YACT,eAAe;YACf,KAAK,EAAE,UAAI;YACX,iBAAiB,EAAE,WAAW,CAAC,iBAAiB,CAAC,QAAQ,EAAE;YAC3D,WAAW;YACX,QAAQ;YACR,UAAU;SACV,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;AACzD,CAAC;AA1FD,8DA0FC","sourcesContent":["import {\n\tBN,\n\tPositionDirection,\n\tPostOnlyParams,\n\tOptionalOrderParams,\n\tgetLimitOrderParams,\n\tgetTriggerMarketOrderParams,\n\tgetTriggerLimitOrderParams,\n\tOrderTriggerCondition,\n\tZERO,\n} from '@drift-labs/sdk';\nimport { ENUM_UTILS } from '../../utils';\nimport { NonMarketOrderParamsConfig } from '../base/actions/trade/openPerpOrder/types';\n\n/**\n * Converts amount and assetType to base asset amount\n * @param amount - The amount to convert\n * @param assetType - 'base' or 'quote'\n * @param limitPrice - Required when assetType is 'quote' for conversion\n * @returns Base asset amount\n */\nexport function convertToBaseAssetAmount(\n\tamount: BN,\n\tassetType: 'base' | 'quote',\n\tlimitPrice?: BN\n): BN {\n\tif (assetType === 'quote') {\n\t\tif (!limitPrice || limitPrice.isZero()) {\n\t\t\tthrow new Error(\n\t\t\t\t'When using quote asset type, limitPrice is required for conversion to base amount'\n\t\t\t);\n\t\t}\n\t\t// Convert quote amount to base amount: quoteAmount / price = baseAmount\n\t\t// Using PRICE_PRECISION as the limit price is in price precision\n\t\tconst PRICE_PRECISION = new BN(10).pow(new BN(6));\n\t\treturn amount.mul(PRICE_PRECISION).div(limitPrice);\n\t} else {\n\t\t// Base amount, use directly\n\t\treturn amount;\n\t}\n}\n\n/**\n * Resolves amount parameters from either new (amount + assetType) or legacy (baseAssetAmount) approach\n */\nexport function resolveBaseAssetAmount(params: {\n\tamount?: BN;\n\tassetType?: 'base' | 'quote';\n\tbaseAssetAmount?: BN;\n\tlimitPrice?: BN;\n}): BN {\n\tconst { amount, assetType, baseAssetAmount, limitPrice } = params;\n\n\tif (amount && assetType) {\n\t\t// New approach: convert if needed\n\t\treturn convertToBaseAssetAmount(amount, assetType, limitPrice);\n\t} else if (baseAssetAmount) {\n\t\t// Legacy approach\n\t\treturn baseAssetAmount;\n\t} else {\n\t\tthrow new Error(\n\t\t\t'Either (amount + assetType) or baseAssetAmount must be provided'\n\t\t);\n\t}\n}\n\n/**\n * Determine trigger condition based on direction\n * For stop orders: ABOVE when long, BELOW when short\n * For take profit orders: BELOW when long, ABOVE when short\n */\nconst getTriggerCondition = (\n\tdirection: PositionDirection,\n\ttpOrSl: 'takeProfit' | 'stopLoss'\n) => {\n\tconst isTakeProfit = tpOrSl === 'takeProfit';\n\tconst isLong = ENUM_UTILS.match(direction, PositionDirection.LONG);\n\n\tif (isTakeProfit) {\n\t\tif (isLong) {\n\t\t\treturn OrderTriggerCondition.BELOW;\n\t\t} else {\n\t\t\treturn OrderTriggerCondition.ABOVE;\n\t\t}\n\t} else {\n\t\t// Stop loss\n\t\tif (isLong) {\n\t\t\treturn OrderTriggerCondition.ABOVE;\n\t\t} else {\n\t\t\treturn OrderTriggerCondition.BELOW;\n\t\t}\n\t}\n};\n\n/**\n * Builds proper order parameters for non-market orders using the same logic as the UI\n */\nexport function buildNonMarketOrderParams({\n\tmarketIndex,\n\tmarketType,\n\tdirection,\n\tbaseAssetAmount,\n\torderConfig,\n\treduceOnly = false,\n\tpostOnly = PostOnlyParams.NONE,\n\tuserOrderId = 0,\n}: Omit<\n\tNonMarketOrderParamsConfig,\n\t'positionMaxLeverage'\n>): OptionalOrderParams {\n\tconst orderType = orderConfig.orderType;\n\n\t// Build order params based on order type using SDK functions\n\tif (orderType === 'limit') {\n\t\tif (!orderConfig.limitPrice) {\n\t\t\tthrow new Error('LIMIT orders require limitPrice');\n\t\t}\n\n\t\treturn getLimitOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType,\n\t\t\tdirection,\n\t\t\tbaseAssetAmount,\n\t\t\tprice: orderConfig.limitPrice,\n\t\t\treduceOnly,\n\t\t\tpostOnly,\n\t\t\tuserOrderId,\n\t\t});\n\t}\n\n\tif (orderType === 'takeProfit' || orderType === 'stopLoss') {\n\t\tif (!orderConfig.triggerPrice) {\n\t\t\tthrow new Error('TRIGGER_MARKET orders require triggerPrice');\n\t\t}\n\n\t\tconst triggerCondition = getTriggerCondition(direction, orderType);\n\t\tconst hasLimitPrice =\n\t\t\t!!orderConfig.limitPrice && !orderConfig.limitPrice.isZero();\n\n\t\tif (hasLimitPrice) {\n\t\t\treturn getTriggerLimitOrderParams({\n\t\t\t\tmarketIndex,\n\t\t\t\tmarketType,\n\t\t\t\tdirection,\n\t\t\t\tbaseAssetAmount,\n\t\t\t\ttriggerPrice: orderConfig.triggerPrice,\n\t\t\t\tprice: orderConfig.limitPrice!,\n\t\t\t\ttriggerCondition,\n\t\t\t\treduceOnly,\n\t\t\t\tpostOnly,\n\t\t\t\tuserOrderId,\n\t\t\t});\n\t\t} else {\n\t\t\treturn getTriggerMarketOrderParams({\n\t\t\t\tmarketIndex,\n\t\t\t\tmarketType,\n\t\t\t\tdirection,\n\t\t\t\tbaseAssetAmount,\n\t\t\t\ttriggerPrice: orderConfig.triggerPrice,\n\t\t\t\tprice: orderConfig.limitPrice,\n\t\t\t\ttriggerCondition,\n\t\t\t\treduceOnly,\n\t\t\t\tpostOnly,\n\t\t\t\tuserOrderId,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (orderType === 'oracleLimit') {\n\t\tif (!orderConfig.oraclePriceOffset) {\n\t\t\tthrow new Error('ORACLE orders require oraclePriceOffset');\n\t\t}\n\n\t\treturn getLimitOrderParams({\n\t\t\tmarketIndex,\n\t\t\tmarketType,\n\t\t\tdirection,\n\t\t\tbaseAssetAmount,\n\t\t\tprice: ZERO,\n\t\t\toraclePriceOffset: orderConfig.oraclePriceOffset.toNumber(),\n\t\t\tuserOrderId,\n\t\t\tpostOnly,\n\t\t\treduceOnly,\n\t\t});\n\t}\n\n\tthrow new Error(`Unsupported order type: ${orderType}`);\n}\n"]}
|