@drift-labs/common 1.0.59 → 1.0.60
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/_deprecated/common-math.d.ts +10 -0
- package/lib/_deprecated/common-math.js +9 -0
- package/lib/_deprecated/common-math.js.map +1 -0
- package/lib/_deprecated/common-ui-utils.d.ts +248 -0
- package/lib/_deprecated/common-ui-utils.js +59 -0
- package/lib/_deprecated/common-ui-utils.js.map +1 -0
- package/lib/_deprecated/equality-checks.d.ts +2 -0
- package/lib/_deprecated/equality-checks.js +7 -0
- package/lib/_deprecated/equality-checks.js.map +1 -0
- package/lib/{common-ui-utils/market.d.ts → _deprecated/market-utils.d.ts} +5 -7
- package/lib/_deprecated/market-utils.js +18 -0
- package/lib/_deprecated/market-utils.js.map +1 -0
- package/lib/_deprecated/order-utils.d.ts +12 -0
- package/lib/_deprecated/order-utils.js +18 -0
- package/lib/_deprecated/order-utils.js.map +1 -0
- package/lib/_deprecated/trading-utils.d.ts +52 -0
- package/lib/_deprecated/trading-utils.js +27 -0
- package/lib/_deprecated/trading-utils.js.map +1 -0
- package/lib/_deprecated/user-utils.d.ts +17 -0
- package/lib/_deprecated/user-utils.js +12 -0
- package/lib/_deprecated/user-utils.js.map +1 -0
- package/lib/_deprecated/utils.d.ts +40 -0
- package/lib/_deprecated/utils.js +47 -0
- package/lib/_deprecated/utils.js.map +1 -0
- package/lib/clients/tvFeed.js +2 -2
- package/lib/clients/tvFeed.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +8 -8
- package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
- package/lib/drift/Drift/clients/AuthorityDrift/index.js +9 -9
- package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -1
- package/lib/drift/Drift/clients/CentralServerDrift/index.js +2 -2
- package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
- package/lib/drift/base/actions/trade/editOrder.d.ts +1 -1
- package/lib/drift/base/actions/trade/editOrder.js.map +1 -1
- package/lib/drift/base/actions/trade/margin.js +4 -4
- package/lib/drift/base/actions/trade/margin.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/auction.d.ts +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/auction.js +4 -3
- package/lib/drift/base/actions/trade/openPerpOrder/auction.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js +2 -2
- package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js +2 -2
- package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +4 -4
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +2 -2
- package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +4 -3
- package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
- package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js +2 -2
- package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js.map +1 -1
- package/lib/drift/base/actions/user/create.js +2 -2
- package/lib/drift/base/actions/user/create.js.map +1 -1
- package/lib/drift/base/details/user/balances.js +2 -2
- package/lib/drift/base/details/user/balances.js.map +1 -1
- package/lib/drift/base/details/user/positions.js +2 -2
- package/lib/drift/base/details/user/positions.js.map +1 -1
- package/lib/index.d.ts +28 -28
- package/lib/index.js +44 -29
- package/lib/index.js.map +1 -1
- package/lib/utils/accounts/index.d.ts +6 -0
- package/lib/utils/accounts/index.js +23 -0
- package/lib/utils/accounts/index.js.map +1 -0
- package/lib/utils/accounts/init.d.ts +22 -0
- package/lib/utils/accounts/init.js +90 -0
- package/lib/utils/accounts/init.js.map +1 -0
- package/lib/utils/accounts/keys.d.ts +22 -0
- package/lib/utils/accounts/keys.js +36 -0
- package/lib/utils/accounts/keys.js.map +1 -0
- package/lib/utils/accounts/multiple.d.ts +14 -0
- package/lib/utils/accounts/multiple.js +45 -0
- package/lib/utils/accounts/multiple.js.map +1 -0
- package/lib/utils/accounts/signature.d.ts +6 -0
- package/lib/utils/accounts/signature.js +53 -0
- package/lib/utils/accounts/signature.js.map +1 -0
- package/lib/utils/accounts/subaccounts.d.ts +8 -0
- package/lib/utils/accounts/subaccounts.js +31 -0
- package/lib/utils/accounts/subaccounts.js.map +1 -0
- package/lib/utils/{WalletConnectionState.d.ts → accounts/wallet.d.ts} +7 -1
- package/lib/utils/{WalletConnectionState.js → accounts/wallet.js} +32 -2
- package/lib/utils/accounts/wallet.js.map +1 -0
- package/lib/utils/core/arrays.d.ts +2 -0
- package/lib/utils/core/arrays.js +25 -0
- package/lib/utils/core/arrays.js.map +1 -0
- package/lib/utils/core/async.d.ts +5 -0
- package/lib/utils/core/async.js +17 -0
- package/lib/utils/core/async.js.map +1 -0
- package/lib/utils/core/cache.d.ts +1 -0
- package/lib/utils/core/cache.js +40 -0
- package/lib/utils/core/cache.js.map +1 -0
- package/lib/utils/core/data-structures.d.ts +30 -0
- package/lib/utils/core/data-structures.js +84 -0
- package/lib/utils/core/data-structures.js.map +1 -0
- package/lib/utils/{equalityChecks.d.ts → core/equality.d.ts} +1 -1
- package/lib/utils/{equalityChecks.js → core/equality.js} +3 -3
- package/lib/utils/core/equality.js.map +1 -0
- package/lib/utils/core/fetch.js.map +1 -0
- package/lib/utils/core/index.d.ts +7 -0
- package/lib/utils/core/index.js +24 -0
- package/lib/utils/core/index.js.map +1 -0
- package/lib/utils/core/serialization.d.ts +30 -0
- package/lib/utils/core/serialization.js +92 -0
- package/lib/utils/core/serialization.js.map +1 -0
- package/lib/utils/{enum.js → enum/index.js} +1 -1
- package/lib/utils/enum/index.js.map +1 -0
- package/lib/utils/index.d.ts +11 -176
- package/lib/utils/index.js +25 -594
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/markets/balances.d.ts +6 -0
- package/lib/utils/markets/balances.js +29 -0
- package/lib/utils/markets/balances.js.map +1 -0
- package/lib/utils/markets/config.d.ts +5 -0
- package/lib/utils/markets/config.js +24 -0
- package/lib/utils/markets/config.js.map +1 -0
- package/lib/utils/markets/index.d.ts +6 -0
- package/lib/utils/markets/index.js +23 -0
- package/lib/utils/markets/index.js.map +1 -0
- package/lib/utils/markets/interest.d.ts +25 -0
- package/lib/utils/markets/interest.js +65 -0
- package/lib/utils/markets/interest.js.map +1 -0
- package/lib/utils/markets/leverage.d.ts +12 -0
- package/lib/utils/markets/leverage.js +60 -0
- package/lib/utils/markets/leverage.js.map +1 -0
- package/lib/utils/markets/operations.d.ts +21 -0
- package/lib/utils/markets/operations.js +59 -0
- package/lib/utils/markets/operations.js.map +1 -0
- package/lib/utils/math/bignum.d.ts +3 -0
- package/lib/utils/math/bignum.js +16 -0
- package/lib/utils/math/bignum.js.map +1 -0
- package/lib/utils/math/bn.d.ts +7 -0
- package/lib/utils/math/bn.js +58 -0
- package/lib/utils/math/bn.js.map +1 -0
- package/lib/utils/math/index.d.ts +7 -0
- package/lib/utils/math/index.js +24 -0
- package/lib/utils/math/index.js.map +1 -0
- package/lib/utils/math/numbers.d.ts +13 -0
- package/lib/utils/math/numbers.js +56 -0
- package/lib/utils/math/numbers.js.map +1 -0
- package/lib/utils/math/precision.d.ts +19 -0
- package/lib/utils/math/precision.js +73 -0
- package/lib/utils/math/precision.js.map +1 -0
- package/lib/utils/math/price.d.ts +12 -0
- package/lib/utils/math/price.js +45 -0
- package/lib/utils/math/price.js.map +1 -0
- package/lib/utils/math/sort.d.ts +13 -0
- package/lib/utils/math/sort.js +33 -0
- package/lib/utils/math/sort.js.map +1 -0
- package/lib/utils/math/spread.d.ts +8 -0
- package/lib/utils/math/spread.js +87 -0
- package/lib/utils/math/spread.js.map +1 -0
- package/lib/utils/orderbook/index.js +4 -4
- package/lib/utils/orderbook/index.js.map +1 -1
- package/lib/utils/orders/filters.d.ts +7 -0
- package/lib/utils/orders/filters.js +31 -0
- package/lib/utils/orders/filters.js.map +1 -0
- package/lib/utils/orders/flags.d.ts +12 -0
- package/lib/utils/orders/flags.js +44 -0
- package/lib/utils/orders/flags.js.map +1 -0
- package/lib/utils/orders/index.d.ts +6 -0
- package/lib/utils/orders/index.js +23 -0
- package/lib/utils/orders/index.js.map +1 -0
- package/lib/utils/orders/labels.d.ts +4 -0
- package/lib/utils/orders/labels.js +122 -0
- package/lib/utils/orders/labels.js.map +1 -0
- package/lib/utils/orders/misc.d.ts +11 -0
- package/lib/utils/orders/misc.js +27 -0
- package/lib/utils/orders/misc.js.map +1 -0
- package/lib/utils/orders/oracle.d.ts +5 -0
- package/lib/utils/orders/oracle.js +23 -0
- package/lib/utils/orders/oracle.js.map +1 -0
- package/lib/utils/orders/sort.d.ts +38 -0
- package/lib/utils/orders/sort.js +83 -0
- package/lib/utils/orders/sort.js.map +1 -0
- package/lib/utils/positions/index.d.ts +2 -0
- package/lib/{common-ui-utils → utils/positions}/index.js +1 -5
- package/lib/utils/positions/index.js.map +1 -0
- package/lib/utils/positions/open.d.ts +4 -0
- package/lib/{common-ui-utils/user.js → utils/positions/open.js} +10 -81
- package/lib/utils/positions/open.js.map +1 -0
- package/lib/utils/positions/user.d.ts +37 -0
- package/lib/utils/positions/user.js +74 -0
- package/lib/utils/positions/user.js.map +1 -0
- package/lib/utils/settings/settings.js.map +1 -0
- package/lib/utils/strings/convert.d.ts +11 -0
- package/lib/utils/{strings.js → strings/convert.js} +2 -51
- package/lib/utils/strings/convert.js.map +1 -0
- package/lib/utils/strings/format.d.ts +14 -0
- package/lib/utils/strings/format.js +61 -0
- package/lib/utils/strings/format.js.map +1 -0
- package/lib/utils/strings/index.d.ts +4 -0
- package/lib/utils/strings/index.js +21 -0
- package/lib/utils/strings/index.js.map +1 -0
- package/lib/utils/strings/parse.d.ts +4 -0
- package/lib/utils/strings/parse.js +25 -0
- package/lib/utils/strings/parse.js.map +1 -0
- package/lib/utils/strings/status.d.ts +15 -0
- package/lib/utils/strings/status.js +21 -0
- package/lib/utils/strings/status.js.map +1 -0
- package/lib/utils/token/account.d.ts +16 -0
- package/lib/utils/token/account.js +36 -0
- package/lib/utils/token/account.js.map +1 -0
- package/lib/utils/{token.d.ts → token/address.d.ts} +2 -7
- package/lib/utils/token/address.js +30 -0
- package/lib/utils/token/address.js.map +1 -0
- package/lib/utils/token/index.d.ts +3 -0
- package/lib/utils/token/index.js +20 -0
- package/lib/utils/token/index.js.map +1 -0
- package/lib/utils/token/instructions.d.ts +3 -0
- package/lib/utils/token/instructions.js +17 -0
- package/lib/utils/token/instructions.js.map +1 -0
- package/lib/utils/trading/auction.d.ts +82 -0
- package/lib/utils/trading/auction.js +208 -0
- package/lib/utils/trading/auction.js.map +1 -0
- package/lib/utils/trading/index.d.ts +7 -0
- package/lib/utils/trading/index.js +24 -0
- package/lib/utils/trading/index.js.map +1 -0
- package/lib/utils/trading/leverage.d.ts +18 -0
- package/lib/utils/trading/leverage.js +79 -0
- package/lib/utils/trading/leverage.js.map +1 -0
- package/lib/utils/trading/liquidation.d.ts +22 -0
- package/lib/utils/trading/liquidation.js +67 -0
- package/lib/utils/trading/liquidation.js.map +1 -0
- package/lib/utils/trading/lp.d.ts +4 -0
- package/lib/utils/trading/lp.js +20 -0
- package/lib/utils/trading/lp.js.map +1 -0
- package/lib/utils/trading/pnl.d.ts +34 -0
- package/lib/utils/trading/pnl.js +88 -0
- package/lib/utils/trading/pnl.js.map +1 -0
- package/lib/utils/trading/price.d.ts +12 -0
- package/lib/utils/trading/price.js +36 -0
- package/lib/utils/trading/price.js.map +1 -0
- package/lib/utils/trading/size.d.ts +27 -0
- package/lib/utils/trading/size.js +83 -0
- package/lib/utils/trading/size.js.map +1 -0
- package/lib/utils/{validation.d.ts → validation/address.d.ts} +1 -2
- package/lib/utils/{validation.js → validation/address.js} +4 -6
- package/lib/utils/validation/address.js.map +1 -0
- package/lib/utils/validation/index.d.ts +3 -0
- package/lib/utils/validation/index.js +20 -0
- package/lib/utils/validation/index.js.map +1 -0
- package/lib/utils/validation/input.d.ts +3 -0
- package/lib/utils/validation/input.js +33 -0
- package/lib/utils/validation/input.js.map +1 -0
- package/lib/utils/validation/notional.d.ts +2 -0
- package/lib/utils/validation/notional.js +8 -0
- package/lib/utils/validation/notional.js.map +1 -0
- package/package.json +90 -3
- package/lib/common-ui-utils/commonUiUtils.d.ts +0 -251
- package/lib/common-ui-utils/commonUiUtils.js +0 -647
- package/lib/common-ui-utils/commonUiUtils.js.map +0 -1
- package/lib/common-ui-utils/index.d.ts +0 -6
- package/lib/common-ui-utils/index.js.map +0 -1
- package/lib/common-ui-utils/market.js +0 -134
- package/lib/common-ui-utils/market.js.map +0 -1
- package/lib/common-ui-utils/order.d.ts +0 -25
- package/lib/common-ui-utils/order.js +0 -191
- package/lib/common-ui-utils/order.js.map +0 -1
- package/lib/common-ui-utils/settings/settings.js.map +0 -1
- package/lib/common-ui-utils/trading.d.ts +0 -79
- package/lib/common-ui-utils/trading.js +0 -313
- package/lib/common-ui-utils/trading.js.map +0 -1
- package/lib/common-ui-utils/user.d.ts +0 -18
- package/lib/common-ui-utils/user.js.map +0 -1
- package/lib/utils/WalletConnectionState.js.map +0 -1
- package/lib/utils/enum.js.map +0 -1
- package/lib/utils/equalityChecks.js.map +0 -1
- package/lib/utils/fetch.js.map +0 -1
- package/lib/utils/math.d.ts +0 -31
- package/lib/utils/math.js +0 -181
- package/lib/utils/math.js.map +0 -1
- package/lib/utils/strings.d.ts +0 -34
- package/lib/utils/strings.js.map +0 -1
- package/lib/utils/token.js +0 -45
- package/lib/utils/token.js.map +0 -1
- package/lib/utils/validation.js.map +0 -1
- /package/lib/utils/{fetch.d.ts → core/fetch.d.ts} +0 -0
- /package/lib/utils/{fetch.js → core/fetch.js} +0 -0
- /package/lib/utils/{enum.d.ts → enum/index.d.ts} +0 -0
- /package/lib/{common-ui-utils → utils}/settings/settings.d.ts +0 -0
- /package/lib/{common-ui-utils → utils}/settings/settings.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/orderbook/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCASyB;AAEzB,kCAAsC;AACtC,mCAWiB;AACjB,0BAAkC;AAClC,2CAAkD;AAElD,0CAAwB;AACxB,8CAA4B;AAE5B;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CACpC,mBAAgC,EACJ,EAAE;;IAC9B,OAAO;QACN,IAAI,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5C,KAAK,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,IAAI,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;gBACpE,OAAO;oBACN,GAAG,QAAQ;oBACX,CAAC,GAAG,CAAC,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC;iBAClB,CAAC;YACH,CAAC,EAAE,EAAE,CAAC;SACN,CAAC,CAAC;QACH,IAAI,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5C,KAAK,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,IA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;YACf,sBAAsB;YACtB,SAAS;YACT,SAAS;SACT,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AAnFW,QAAA,sBAAsB,0BAmFjC;AAEK,MAAM,sBAAsB,GAAG,CACrC,UAAyC,EACzC,KAAa,EACgC,EAAE;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,+BAAmB,CAAC,CAAC;IAEtD,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtC,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;YACnB,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;QAC1B,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAbW,QAAA,sBAAsB,0BAajC","sourcesContent":["import {\n\tL2OrderBook,\n\tBN,\n\tBigNum,\n\tPERCENTAGE_PRECISION_EXP,\n\tPRICE_PRECISION_EXP,\n\tL2Level,\n\tZERO,\n\tgroupL2,\n} from '@drift-labs/sdk';\nimport { MarketId } from '../../types';\nimport { COMMON_MATH } from '../math';\nimport {\n\tBidsAndAsks,\n\tCategorisedLiquidity,\n\tCUMULATIVE_SIZE_CURRENCY,\n\tEmptyRow,\n\tGroupingSizeQuoteValue,\n\tL2WithOracleAndMarketData,\n\tLiquidityType,\n\tOrderBookBidAsk,\n\tOrderBookDisplayStateBidAsk,\n\tRawL2Output,\n} from './types';\nimport { COMMON_UTILS } from '..';\nimport { EMPTY_ORDERBOOK_ROW } from './constants';\n\nexport * from './types';\nexport * from './constants';\n\n/**\n * Helper function to deserialize the response from the dlob server. (See https://drift-labs.github.io/v2-teacher/#get-l2-l3)\n * @param serializedOrderbook\n * @returns\n */\nexport const deserializeL2Response = (\n\tserializedOrderbook: RawL2Output\n): L2WithOracleAndMarketData => {\n\treturn {\n\t\tasks: serializedOrderbook.asks.map((ask) => ({\n\t\t\tprice: new BN(ask.price),\n\t\t\tsize: new BN(ask.size),\n\t\t\tsources: Object.entries(ask.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\tbids: serializedOrderbook.bids.map((bid) => ({\n\t\t\tprice: new BN(bid.price),\n\t\t\tsize: new BN(bid.size),\n\t\t\tsources: Object.entries(bid.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\toracleData: {\n\t\t\tprice: serializedOrderbook.oracleData.price\n\t\t\t\t? new BN(serializedOrderbook.oracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.oracleData.slot\n\t\t\t\t? new BN(serializedOrderbook.oracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.oracleData.confidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.oracleData.hasSufficientNumberOfDataPoints,\n\t\t\ttwap: serializedOrderbook.oracleData.twap\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twap)\n\t\t\t\t: undefined,\n\t\t\ttwapConfidence: serializedOrderbook.oracleData.twapConfidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twapConfidence)\n\t\t\t\t: undefined,\n\t\t\tmaxPrice: serializedOrderbook.oracleData.maxPrice\n\t\t\t\t? new BN(serializedOrderbook.oracleData.maxPrice)\n\t\t\t\t: undefined,\n\t\t},\n\t\tmmOracleData: {\n\t\t\tprice: serializedOrderbook.mmOracleData?.price\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.mmOracleData?.slot\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.mmOracleData?.confidence\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.mmOracleData?.hasSufficientNumberOfDataPoints,\n\t\t\tisMMOracleActive:\n\t\t\t\tserializedOrderbook.mmOracleData?.isMMOracleActive ?? false,\n\t\t},\n\t\tslot: serializedOrderbook.slot,\n\t\tmarketSlot: serializedOrderbook.marketSlot,\n\t\tmarketType: serializedOrderbook.marketType,\n\t\tmarketIndex: serializedOrderbook.marketIndex,\n\t\tmarketName: serializedOrderbook.marketName,\n\t\tmarkPrice: new BN(serializedOrderbook.markPrice),\n\t\tbestBidPrice: new BN(serializedOrderbook.bestBidPrice),\n\t\tbestAskPrice: new BN(serializedOrderbook.bestAskPrice),\n\t\tspreadPct: new BN(serializedOrderbook.spreadPct),\n\t\tspreadQuote: new BN(serializedOrderbook.spreadQuote),\n\t};\n};\n\nexport const convertToL2OrderBook = (\n\tl2Data: L2WithOracleAndMarketData[]\n): L2OrderBook => {\n\t// Find the market data - there should be one entry for our market\n\tconst marketData = l2Data[0];\n\n\tif (!marketData) {\n\t\tthrow new Error('No L2 data available for market');\n\t}\n\n\t// L2WithOracleAndMarketData extends L2OrderBook, so we can use it directly\n\treturn {\n\t\tasks: marketData.asks,\n\t\tbids: marketData.bids,\n\t\tslot: marketData.slot,\n\t};\n};\n\nexport interface DynamicSlippageConfig {\n\tdynamicSlippageMin?: number;\n\tdynamicSlippageMax?: number;\n\tdynamicBaseSlippageMajor?: number;\n\tdynamicBaseSlippageNonMajor?: number;\n\tdynamicSlippageMultiplierMajor?: number;\n\tdynamicSlippageMultiplierNonMajor?: number;\n}\n\nconst DEFAULT_DYNAMIC_SLIPPAGE_CONFIG: DynamicSlippageConfig = {\n\tdynamicSlippageMin: 0.05,\n\tdynamicSlippageMax: 5,\n\tdynamicBaseSlippageMajor: 0,\n\tdynamicBaseSlippageNonMajor: 0.5,\n\tdynamicSlippageMultiplierMajor: 1.02,\n\tdynamicSlippageMultiplierNonMajor: 1.2,\n};\n\nexport const calculateDynamicSlippageFromL2 = ({\n\tl2Data,\n\tmarketId,\n\tstartPrice,\n\tworstPrice,\n\toraclePrice,\n\tdynamicSlippageConfig,\n}: {\n\tl2Data: L2OrderBook;\n\tmarketId: MarketId;\n\tstartPrice: BN;\n\tworstPrice: BN;\n\toraclePrice?: BN;\n\tdynamicSlippageConfig?: DynamicSlippageConfig;\n}): number => {\n\tconst dynamicSlippageConfigToUse = dynamicSlippageConfig\n\t\t? { ...DEFAULT_DYNAMIC_SLIPPAGE_CONFIG, ...dynamicSlippageConfig }\n\t\t: DEFAULT_DYNAMIC_SLIPPAGE_CONFIG;\n\n\t// Calculate spread information from L2 data using the oracle price\n\tconst spreadBidAskMark = COMMON_MATH.calculateSpreadBidAskMark(\n\t\tl2Data,\n\t\toraclePrice\n\t);\n\n\tconst bestAskNum = spreadBidAskMark.bestAskPrice?.toNumber?.() || 0;\n\tconst bestBidNum = spreadBidAskMark.bestBidPrice?.toNumber?.() || 0;\n\n\tconst spreadPctFromL2 = BigNum.from(\n\t\tspreadBidAskMark.spreadPct,\n\t\tPERCENTAGE_PRECISION_EXP\n\t).toNum();\n\n\t// Calculate spread percentage\n\tconst spreadPct =\n\t\tspreadPctFromL2 ||\n\t\t(Math.abs(bestAskNum - bestBidNum) / ((bestAskNum + bestBidNum) / 2)) * 100;\n\n\t// Default to 0.5% if we get invalid spread info\n\tif (isNaN(spreadPct) || spreadPct <= 0) {\n\t\treturn 0.5;\n\t}\n\n\t// Apply a buffer based on the tier of the contract\n\t// Currently no buffer for SOL/BTC/ETH perp and a +10% buffer for other markets\n\tconst isMajor = marketId.isPerp && marketId.marketIndex < 3;\n\n\tconst spreadBaseSlippage = spreadPct / 2;\n\n\tconst baseSlippage = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicBaseSlippageMajor\n\t\t: dynamicSlippageConfigToUse.dynamicBaseSlippageNonMajor;\n\tlet dynamicSlippage = baseSlippage + spreadBaseSlippage;\n\n\t// Use halfway to worst price as size adjusted slippage\n\tif (startPrice && worstPrice) {\n\t\tconst sizeAdjustedSlippage =\n\t\t\t(startPrice.sub(worstPrice).abs().toNumber() /\n\t\t\t\tBN.max(startPrice, worstPrice).toNumber() /\n\t\t\t\t2) *\n\t\t\t100;\n\n\t\tdynamicSlippage = Math.max(dynamicSlippage, sizeAdjustedSlippage);\n\t}\n\n\t// Apply multiplier from env var\n\tconst multiplier = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicSlippageMultiplierMajor\n\t\t: dynamicSlippageConfigToUse.dynamicSlippageMultiplierNonMajor;\n\n\tdynamicSlippage = dynamicSlippage * multiplier;\n\n\t// Enforce .05% minimum, 5% maximum, can change these in env vars\n\tconst finalSlippage = Math.min(\n\t\tMath.max(dynamicSlippage, dynamicSlippageConfigToUse.dynamicSlippageMin),\n\t\tdynamicSlippageConfigToUse.dynamicSlippageMax\n\t);\n\n\t// Round to avoid floating point precision issues, preserving 6 decimal places\n\treturn Math.round(finalSlippage * 1000000) / 1000000;\n};\n\nexport const getFormattedSize = (\n\tsizesObject: Partial<Record<LiquidityType, number>>,\n\tprice: number,\n\tcurrency: CUMULATIVE_SIZE_CURRENCY,\n\tdisplayDecimals: number\n) => {\n\tconst sizeSum = Object.values(sizesObject || {}).reduce(\n\t\t(acc, curr) => acc + curr,\n\t\t0\n\t);\n\n\tconst displayValue =\n\t\tcurrency === CUMULATIVE_SIZE_CURRENCY.USD && price\n\t\t\t? sizeSum * price\n\t\t\t: sizeSum;\n\n\treturn BigNum.fromPrint(\n\t\tdisplayValue.toFixed(displayDecimals),\n\t\tnew BN(displayDecimals)\n\t).toMillified(3);\n};\n\nexport const getLiquidityPcts = (\n\ttotalSize: number,\n\tcumulativeSize: CategorisedLiquidity = {}\n) => {\n\tconst totalCumulativeSize = Object.values(cumulativeSize).reduce(\n\t\t(acc, curr) => acc + curr,\n\t\t0\n\t);\n\n\tconst cumulativeSizePct = totalSize\n\t\t? (totalCumulativeSize / totalSize) * 100\n\t\t: 0; // This is the portion of the total size of the orderbook that the cumulative size of the liquidity should be occupying.\n\n\tconst cumulativeRestingSize =\n\t\ttotalCumulativeSize - (cumulativeSize?.indicative ?? 0);\n\tconst cumulativeIndicativeSize = cumulativeSize?.indicative ?? 0;\n\n\tconst restingLiquidityPct =\n\t\t(cumulativeRestingSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the resting liquidity should be occupying\n\n\tconst indicativeLiquidityPct =\n\t\t(cumulativeIndicativeSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the indicative liquidity should be occupying\n\n\treturn {\n\t\trestingLiquidityPct,\n\t\tindicativeLiquidityPct,\n\t};\n};\n\nconst roundForOrderbook = (num: number) => Number(num.toFixed(6));\n\nexport const getBucketFloorForPrice = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst priceIsNegative = price < 0;\n\n\tconst _groupingSize = groupingSize as unknown as number;\n\n\tif (COMMON_UTILS.dividesExactly(price, _groupingSize)) {\n\t\treturn roundForOrderbook(price);\n\t}\n\n\tconst amountToDeduct = priceIsNegative\n\t\t? _groupingSize - (Math.abs(price) % _groupingSize)\n\t\t: Math.abs(price) % _groupingSize;\n\n\tconst floorPrice = price - amountToDeduct;\n\n\treturn roundForOrderbook(floorPrice);\n};\n\nexport const getUserLiquidityForPrice = ({\n\tprice,\n\tside,\n\tgroupingSizeValue,\n\tuserAskPriceBucketLookup,\n\tuserBidPriceBucketLookup,\n}: {\n\tprice: number;\n\tside: 'bid' | 'ask';\n\tgroupingSizeValue: GroupingSizeQuoteValue;\n\tuserAskPriceBucketLookup: Map<number, OrderBookBidAsk>;\n\tuserBidPriceBucketLookup: Map<number, OrderBookBidAsk>;\n}) => {\n\tlet isCurrentUserLiquidity = false;\n\tlet currentUserLiquiditySize = 0;\n\n\tconst priceToUse = price;\n\tconst priceBucket = getBucketFloorForPrice(priceToUse, groupingSizeValue);\n\n\tconst lookupBucket =\n\t\tside === 'bid' ? userBidPriceBucketLookup : userAskPriceBucketLookup;\n\n\tconst matchingUserBidAsk = lookupBucket.get(priceBucket);\n\n\tif (matchingUserBidAsk) {\n\t\tisCurrentUserLiquidity = true;\n\t\tcurrentUserLiquiditySize = matchingUserBidAsk.size;\n\t}\n\n\treturn { isCurrentUserLiquidity, currentUserLiquiditySize };\n};\n\nconst getBucketCeilingForPrice = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst _groupingSize = groupingSize as unknown as number;\n\treturn getBucketFloorForPrice(price + _groupingSize, groupingSize);\n};\n\nexport const getBucketAnchorPrice = (\n\ttype: 'bid' | 'ask',\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\t// If the grouping size matches exactly then the anchor price should be the same as the floor price regardless\n\tif (COMMON_UTILS.dividesExactly(price, groupingSize as unknown as number)) {\n\t\treturn getBucketFloorForPrice(price, groupingSize);\n\t}\n\n\tif (type === 'bid') {\n\t\treturn getBucketFloorForPrice(price, groupingSize);\n\t} else {\n\t\treturn getBucketCeilingForPrice(price, groupingSize);\n\t}\n};\n\nexport const getBucketForUserLiquidity = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue,\n\ttype: 'bid' | 'ask'\n) => getBucketAnchorPrice(type, price, groupingSize);\n\nexport const mergeBidsAndAsksForGroupsize = (\n\ttype: 'bid' | 'ask',\n\tbidsAsks: OrderBookBidAsk[],\n\tgroupingSize: GroupingSizeQuoteValue\n): OrderBookBidAsk[] => {\n\tconst bidsAsksBucketLookup = new Map<number, OrderBookBidAsk>();\n\n\tfor (const bidAsk of bidsAsks) {\n\t\tconst anchorPrice = getBucketAnchorPrice(type, bidAsk.price, groupingSize);\n\t\tconst existingBucket = bidsAsksBucketLookup.get(anchorPrice);\n\t\tif (existingBucket) {\n\t\t\texistingBucket.size += bidAsk.size;\n\t\t} else {\n\t\t\tbidsAsksBucketLookup.set(anchorPrice, { ...bidAsk });\n\t\t}\n\t}\n\n\treturn Array.from(bidsAsksBucketLookup.values());\n};\n\nexport const getZeroPaddingForGroupingSize = (\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst _groupingSize = groupingSize as unknown as number;\n\n\tconst precision = Math.floor(Math.log10(_groupingSize));\n\n\tif (precision >= 0 || _groupingSize === 0) return 0;\n\n\treturn Math.abs(precision);\n};\n\nconst sizeToNum = (size: BN, precision: BN) =>\n\tBigNum.from(size, precision).toNum();\n\nexport const getCategorisedLiquidityForLevel = (\n\tlevel: L2Level,\n\tbasePrecision: BN\n): CategorisedLiquidity => {\n\tconst dlobSize = sizeToNum(level?.sources?.dlob ?? ZERO, basePrecision);\n\tconst vammSize = sizeToNum(level?.sources?.vamm ?? ZERO, basePrecision);\n\tconst serumSize = sizeToNum(level?.sources?.serum ?? ZERO, basePrecision);\n\tconst phoenixSize = sizeToNum(level?.sources?.phoenix ?? ZERO, basePrecision);\n\tconst openbookSize = sizeToNum(\n\t\tlevel?.sources?.openbook ?? ZERO,\n\t\tbasePrecision\n\t);\n\tconst indicativeSize = sizeToNum(\n\t\tlevel?.sources?.indicative ?? ZERO,\n\t\tbasePrecision\n\t);\n\n\tconst categorisedLiquidity: CategorisedLiquidity = {\n\t\tdlob: dlobSize,\n\t\tvamm: vammSize,\n\t\tserum: serumSize,\n\t\tphoenix: phoenixSize,\n\t\topenbook: openbookSize,\n\t\tindicative: indicativeSize,\n\t};\n\n\treturn categorisedLiquidity;\n};\n\nconst formatLevelsToDisplay = (\n\tlevels: L2Level[],\n\tbasePrecision: BN,\n\tdepth?: number\n): {\n\tformattedLevels: OrderBookDisplayStateBidAsk[];\n\tbestLevel: number;\n\tcumulativeSize: number;\n} => {\n\tconst relevantSources: Set<LiquidityType> = new Set();\n\n\tfor (const level of levels) {\n\t\tfor (const source of Object.keys(level.sources)) {\n\t\t\trelevantSources.add(source as LiquidityType);\n\t\t}\n\t}\n\n\tconst cumulativeSizes: CategorisedLiquidity = Array.from(\n\t\trelevantSources\n\t).reduce((acc, source) => {\n\t\tacc[source] = 0;\n\t\treturn acc;\n\t}, {} as CategorisedLiquidity);\n\n\tlet cumulativePriceSizeProduct = 0;\n\tlet cumulativeTotalSize = 0;\n\n\tconst formattedLevels: OrderBookDisplayStateBidAsk[] = levels.map((level) => {\n\t\tconst bucketSize = getCategorisedLiquidityForLevel(level, basePrecision);\n\t\tconst price = BigNum.from(level.price, PRICE_PRECISION_EXP).toNum();\n\t\tconst totalSize = Object.values(bucketSize).reduce(\n\t\t\t(sum, size) => sum + size,\n\t\t\t0\n\t\t);\n\n\t\tfor (const source of relevantSources) {\n\t\t\tconst currentValue = cumulativeSizes[source];\n\t\t\tif (currentValue !== undefined) {\n\t\t\t\tcumulativeSizes[source] = currentValue + (bucketSize[source] ?? 0);\n\t\t\t}\n\t\t}\n\n\t\tcumulativePriceSizeProduct += price * totalSize;\n\t\tcumulativeTotalSize += totalSize;\n\n\t\treturn {\n\t\t\tprice,\n\t\t\tsize: bucketSize,\n\t\t\tcumulativeSize: { ...cumulativeSizes },\n\t\t\tcumulativeAvgPrice:\n\t\t\t\tcumulativeTotalSize > 0\n\t\t\t\t\t? cumulativePriceSizeProduct / cumulativeTotalSize\n\t\t\t\t\t: 0,\n\t\t};\n\t});\n\n\tif (depth && depth > 0) {\n\t\tconst visibleLevels = formattedLevels.slice(0, depth);\n\t\tconst maxCumulativeSize = Math.max(\n\t\t\t0,\n\t\t\t...visibleLevels.map((level) =>\n\t\t\t\tObject.values(level.cumulativeSize).reduce((sum, size) => sum + size, 0)\n\t\t\t)\n\t\t);\n\n\t\treturn {\n\t\t\tformattedLevels: visibleLevels,\n\t\t\tbestLevel: visibleLevels?.[0]?.price,\n\t\t\tcumulativeSize: maxCumulativeSize,\n\t\t};\n\t}\n\n\tconst totalSizeToReturn = Object.values(cumulativeSizes).reduce(\n\t\t(total, current) => total + current,\n\t\t0\n\t);\n\n\treturn {\n\t\tformattedLevels,\n\t\tbestLevel: formattedLevels?.[0]?.price,\n\t\tcumulativeSize: totalSizeToReturn,\n\t};\n};\n\nexport const formatL2ToDisplay = (\n\tl2State: L2OrderBook,\n\tbasePrecision: BN,\n\tdepth?: number\n) => {\n\tconst formattedBids = formatLevelsToDisplay(\n\t\tl2State.bids,\n\t\tbasePrecision,\n\t\tdepth\n\t);\n\tconst formattedAsks = formatLevelsToDisplay(\n\t\tl2State.asks,\n\t\tbasePrecision,\n\t\tdepth\n\t);\n\n\treturn {\n\t\tbids: formattedBids.formattedLevels,\n\t\tasks: formattedAsks.formattedLevels,\n\t\tbidTotalSize: formattedBids.cumulativeSize,\n\t\taskTotalSize: formattedAsks.cumulativeSize,\n\t};\n};\n\nconst filterOutDisabledLiquidityTypes = (\n\tl2Levels: L2Level[],\n\tdisabledLiquidityTypes: LiquidityType[]\n) =>\n\tl2Levels\n\t\t.map((level) => {\n\t\t\tlet totalDisabledSize = ZERO;\n\t\t\tconst disabledSourceObj: Record<LiquidityType, BN> = {} as Record<\n\t\t\t\tLiquidityType,\n\t\t\t\tBN\n\t\t\t>;\n\n\t\t\tfor (const liquidityType of disabledLiquidityTypes) {\n\t\t\t\tconst disabledLiqSize = level.sources?.[liquidityType];\n\t\t\t\tif (disabledLiqSize?.gt(ZERO)) {\n\t\t\t\t\ttotalDisabledSize = totalDisabledSize.add(disabledLiqSize);\n\t\t\t\t\tdisabledSourceObj[liquidityType] = ZERO;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn totalDisabledSize.gt(ZERO)\n\t\t\t\t? {\n\t\t\t\t\t\t...level,\n\t\t\t\t\t\tsize: level.size.sub(totalDisabledSize),\n\t\t\t\t\t\tsources: {\n\t\t\t\t\t\t\t...level.sources,\n\t\t\t\t\t\t\t...disabledSourceObj,\n\t\t\t\t\t\t},\n\t\t\t\t }\n\t\t\t\t: level;\n\t\t})\n\t\t.filter((level) => level.size.gt(ZERO));\n\nexport const l2ToDisplayBidsAndAsks = (\n\tl2Orderbook: L2OrderBook,\n\toraclePrice: BN,\n\ttickSizeForMarket: BN,\n\tgroupSizeTickMultiplier: number,\n\tuserBidsAndAsks: BidsAndAsks,\n\tbasePrecisionForMarket: BN,\n\tdisabledLiquidityTypes: LiquidityType[],\n\tmaxDepth: number,\n\tdepth?: number // limit the number of visible rows to calculate totalSize from\n) => {\n\tconst filteredBids =\n\t\tdisabledLiquidityTypes.length > 0\n\t\t\t? filterOutDisabledLiquidityTypes(\n\t\t\t\t\tl2Orderbook.bids,\n\t\t\t\t\tdisabledLiquidityTypes\n\t\t\t )\n\t\t\t: l2Orderbook.bids;\n\n\tconst filteredAsks =\n\t\tdisabledLiquidityTypes.length > 0\n\t\t\t? filterOutDisabledLiquidityTypes(\n\t\t\t\t\tl2Orderbook.asks,\n\t\t\t\t\tdisabledLiquidityTypes\n\t\t\t )\n\t\t\t: l2Orderbook.asks;\n\n\t// # Uncross the liquidity\n\tconst uncrossed = {\n\t\tl2Orderbook,\n\t\tbids: filteredBids,\n\t\tasks: filteredAsks,\n\t};\n\n\t// Group the orderbook into levels based on the grouping size\n\tconst grouped = groupL2(\n\t\tuncrossed,\n\t\ttickSizeForMarket.muln(groupSizeTickMultiplier ?? 1), // one user had a weird error where .muln was throwing assertion failed error\n\t\tmaxDepth\n\t);\n\n\t// # Convert to UI format\n\tconst formatted = formatL2ToDisplay(grouped, basePrecisionForMarket, depth);\n\n\t// Check that bids are in descending order\n\tif (\n\t\tformatted.bids.some((bid, index) => {\n\t\t\tif (index === 0) return false;\n\n\t\t\treturn bid.price > formatted.bids[index - 1].price;\n\t\t})\n\t) {\n\t\tconsole.log('orderbook - bids_not_in_descending_order', {\n\t\t\tl2Orderbook,\n\t\t\toraclePrice,\n\t\t\ttickSizeForMarket,\n\t\t\tuserBidsAndAsks,\n\t\t\tbasePrecisionForMarket,\n\t\t\tuncrossed,\n\t\t\tformatted,\n\t\t});\n\t}\n\n\t// Check that asks are in ascending order\n\tif (\n\t\tformatted.asks.some((ask, index) => {\n\t\t\tif (index === 0) return false;\n\n\t\t\treturn ask.price < formatted.asks[index - 1].price;\n\t\t})\n\t) {\n\t\tconsole.log('orderbook - asks_not_in_ascending_order', {\n\t\t\tl2Orderbook,\n\t\t\toraclePrice,\n\t\t\ttickSizeForMarket,\n\t\t\tuserBidsAndAsks,\n\t\t\tbasePrecisionForMarket,\n\t\t\tuncrossed,\n\t\t\tformatted,\n\t\t});\n\t}\n\n\treturn formatted;\n};\n\nexport const getEmptyFilledBidsAsks = (\n\tbidsOrAsks: OrderBookDisplayStateBidAsk[],\n\tdepth: number\n): (OrderBookDisplayStateBidAsk | EmptyRow)[] => {\n\tconst result = Array(depth).fill(EMPTY_ORDERBOOK_ROW);\n\n\tbidsOrAsks.forEach((bidOrAsk, index) => {\n\t\tif (index < depth) {\n\t\t\tresult[index] = bidOrAsk;\n\t\t}\n\t});\n\n\treturn result;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/orderbook/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCASyB;AAEzB,kCAAoD;AACpD,mCAWiB;AACjB,kCAAyC;AACzC,2CAAkD;AAElD,0CAAwB;AACxB,8CAA4B;AAE5B;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CACpC,mBAAgC,EACJ,EAAE;;IAC9B,OAAO;QACN,IAAI,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5C,KAAK,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,KAAK,CAAC;YACxB,IAAI,EAAE,IAAI,QAAE,CAAC,GAAG,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAA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AI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClC,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAE9B,OAAO,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;IACpD,CAAC,CAAC,EACD,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,yCAAyC,EAAE;YACtD,WAAW;YACX,WAAW;YACX,iBAAiB;YACjB,eAAe;YACf,sBAAsB;YACtB,SAAS;YACT,SAAS;SACT,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AAnFW,QAAA,sBAAsB,0BAmFjC;AAEK,MAAM,sBAAsB,GAAG,CACrC,UAAyC,EACzC,KAAa,EACgC,EAAE;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,+BAAmB,CAAC,CAAC;IAEtD,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtC,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;YACnB,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;QAC1B,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAbW,QAAA,sBAAsB,0BAajC","sourcesContent":["import {\n\tL2OrderBook,\n\tBN,\n\tBigNum,\n\tPERCENTAGE_PRECISION_EXP,\n\tPRICE_PRECISION_EXP,\n\tL2Level,\n\tZERO,\n\tgroupL2,\n} from '@drift-labs/sdk';\nimport { MarketId } from '../../types';\nimport { calculateSpreadBidAskMark } from '../math';\nimport {\n\tBidsAndAsks,\n\tCategorisedLiquidity,\n\tCUMULATIVE_SIZE_CURRENCY,\n\tEmptyRow,\n\tGroupingSizeQuoteValue,\n\tL2WithOracleAndMarketData,\n\tLiquidityType,\n\tOrderBookBidAsk,\n\tOrderBookDisplayStateBidAsk,\n\tRawL2Output,\n} from './types';\nimport { dividesExactly } from '../math';\nimport { EMPTY_ORDERBOOK_ROW } from './constants';\n\nexport * from './types';\nexport * from './constants';\n\n/**\n * Helper function to deserialize the response from the dlob server. (See https://drift-labs.github.io/v2-teacher/#get-l2-l3)\n * @param serializedOrderbook\n * @returns\n */\nexport const deserializeL2Response = (\n\tserializedOrderbook: RawL2Output\n): L2WithOracleAndMarketData => {\n\treturn {\n\t\tasks: serializedOrderbook.asks.map((ask) => ({\n\t\t\tprice: new BN(ask.price),\n\t\t\tsize: new BN(ask.size),\n\t\t\tsources: Object.entries(ask.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\tbids: serializedOrderbook.bids.map((bid) => ({\n\t\t\tprice: new BN(bid.price),\n\t\t\tsize: new BN(bid.size),\n\t\t\tsources: Object.entries(bid.sources).reduce((previous, [key, val]) => {\n\t\t\t\treturn {\n\t\t\t\t\t...previous,\n\t\t\t\t\t[key]: new BN(val),\n\t\t\t\t};\n\t\t\t}, {}),\n\t\t})),\n\t\toracleData: {\n\t\t\tprice: serializedOrderbook.oracleData.price\n\t\t\t\t? new BN(serializedOrderbook.oracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.oracleData.slot\n\t\t\t\t? new BN(serializedOrderbook.oracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.oracleData.confidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.oracleData.hasSufficientNumberOfDataPoints,\n\t\t\ttwap: serializedOrderbook.oracleData.twap\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twap)\n\t\t\t\t: undefined,\n\t\t\ttwapConfidence: serializedOrderbook.oracleData.twapConfidence\n\t\t\t\t? new BN(serializedOrderbook.oracleData.twapConfidence)\n\t\t\t\t: undefined,\n\t\t\tmaxPrice: serializedOrderbook.oracleData.maxPrice\n\t\t\t\t? new BN(serializedOrderbook.oracleData.maxPrice)\n\t\t\t\t: undefined,\n\t\t},\n\t\tmmOracleData: {\n\t\t\tprice: serializedOrderbook.mmOracleData?.price\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.price)\n\t\t\t\t: undefined,\n\t\t\tslot: serializedOrderbook.mmOracleData?.slot\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.slot)\n\t\t\t\t: undefined,\n\t\t\tconfidence: serializedOrderbook.mmOracleData?.confidence\n\t\t\t\t? new BN(serializedOrderbook.mmOracleData.confidence)\n\t\t\t\t: undefined,\n\t\t\thasSufficientNumberOfDataPoints:\n\t\t\t\tserializedOrderbook.mmOracleData?.hasSufficientNumberOfDataPoints,\n\t\t\tisMMOracleActive:\n\t\t\t\tserializedOrderbook.mmOracleData?.isMMOracleActive ?? false,\n\t\t},\n\t\tslot: serializedOrderbook.slot,\n\t\tmarketSlot: serializedOrderbook.marketSlot,\n\t\tmarketType: serializedOrderbook.marketType,\n\t\tmarketIndex: serializedOrderbook.marketIndex,\n\t\tmarketName: serializedOrderbook.marketName,\n\t\tmarkPrice: new BN(serializedOrderbook.markPrice),\n\t\tbestBidPrice: new BN(serializedOrderbook.bestBidPrice),\n\t\tbestAskPrice: new BN(serializedOrderbook.bestAskPrice),\n\t\tspreadPct: new BN(serializedOrderbook.spreadPct),\n\t\tspreadQuote: new BN(serializedOrderbook.spreadQuote),\n\t};\n};\n\nexport const convertToL2OrderBook = (\n\tl2Data: L2WithOracleAndMarketData[]\n): L2OrderBook => {\n\t// Find the market data - there should be one entry for our market\n\tconst marketData = l2Data[0];\n\n\tif (!marketData) {\n\t\tthrow new Error('No L2 data available for market');\n\t}\n\n\t// L2WithOracleAndMarketData extends L2OrderBook, so we can use it directly\n\treturn {\n\t\tasks: marketData.asks,\n\t\tbids: marketData.bids,\n\t\tslot: marketData.slot,\n\t};\n};\n\nexport interface DynamicSlippageConfig {\n\tdynamicSlippageMin?: number;\n\tdynamicSlippageMax?: number;\n\tdynamicBaseSlippageMajor?: number;\n\tdynamicBaseSlippageNonMajor?: number;\n\tdynamicSlippageMultiplierMajor?: number;\n\tdynamicSlippageMultiplierNonMajor?: number;\n}\n\nconst DEFAULT_DYNAMIC_SLIPPAGE_CONFIG: DynamicSlippageConfig = {\n\tdynamicSlippageMin: 0.05,\n\tdynamicSlippageMax: 5,\n\tdynamicBaseSlippageMajor: 0,\n\tdynamicBaseSlippageNonMajor: 0.5,\n\tdynamicSlippageMultiplierMajor: 1.02,\n\tdynamicSlippageMultiplierNonMajor: 1.2,\n};\n\nexport const calculateDynamicSlippageFromL2 = ({\n\tl2Data,\n\tmarketId,\n\tstartPrice,\n\tworstPrice,\n\toraclePrice,\n\tdynamicSlippageConfig,\n}: {\n\tl2Data: L2OrderBook;\n\tmarketId: MarketId;\n\tstartPrice: BN;\n\tworstPrice: BN;\n\toraclePrice?: BN;\n\tdynamicSlippageConfig?: DynamicSlippageConfig;\n}): number => {\n\tconst dynamicSlippageConfigToUse = dynamicSlippageConfig\n\t\t? { ...DEFAULT_DYNAMIC_SLIPPAGE_CONFIG, ...dynamicSlippageConfig }\n\t\t: DEFAULT_DYNAMIC_SLIPPAGE_CONFIG;\n\n\t// Calculate spread information from L2 data using the oracle price\n\tconst spreadBidAskMark = calculateSpreadBidAskMark(l2Data, oraclePrice);\n\n\tconst bestAskNum = spreadBidAskMark.bestAskPrice?.toNumber?.() || 0;\n\tconst bestBidNum = spreadBidAskMark.bestBidPrice?.toNumber?.() || 0;\n\n\tconst spreadPctFromL2 = BigNum.from(\n\t\tspreadBidAskMark.spreadPct,\n\t\tPERCENTAGE_PRECISION_EXP\n\t).toNum();\n\n\t// Calculate spread percentage\n\tconst spreadPct =\n\t\tspreadPctFromL2 ||\n\t\t(Math.abs(bestAskNum - bestBidNum) / ((bestAskNum + bestBidNum) / 2)) * 100;\n\n\t// Default to 0.5% if we get invalid spread info\n\tif (isNaN(spreadPct) || spreadPct <= 0) {\n\t\treturn 0.5;\n\t}\n\n\t// Apply a buffer based on the tier of the contract\n\t// Currently no buffer for SOL/BTC/ETH perp and a +10% buffer for other markets\n\tconst isMajor = marketId.isPerp && marketId.marketIndex < 3;\n\n\tconst spreadBaseSlippage = spreadPct / 2;\n\n\tconst baseSlippage = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicBaseSlippageMajor\n\t\t: dynamicSlippageConfigToUse.dynamicBaseSlippageNonMajor;\n\tlet dynamicSlippage = baseSlippage + spreadBaseSlippage;\n\n\t// Use halfway to worst price as size adjusted slippage\n\tif (startPrice && worstPrice) {\n\t\tconst sizeAdjustedSlippage =\n\t\t\t(startPrice.sub(worstPrice).abs().toNumber() /\n\t\t\t\tBN.max(startPrice, worstPrice).toNumber() /\n\t\t\t\t2) *\n\t\t\t100;\n\n\t\tdynamicSlippage = Math.max(dynamicSlippage, sizeAdjustedSlippage);\n\t}\n\n\t// Apply multiplier from env var\n\tconst multiplier = isMajor\n\t\t? dynamicSlippageConfigToUse.dynamicSlippageMultiplierMajor\n\t\t: dynamicSlippageConfigToUse.dynamicSlippageMultiplierNonMajor;\n\n\tdynamicSlippage = dynamicSlippage * multiplier;\n\n\t// Enforce .05% minimum, 5% maximum, can change these in env vars\n\tconst finalSlippage = Math.min(\n\t\tMath.max(dynamicSlippage, dynamicSlippageConfigToUse.dynamicSlippageMin),\n\t\tdynamicSlippageConfigToUse.dynamicSlippageMax\n\t);\n\n\t// Round to avoid floating point precision issues, preserving 6 decimal places\n\treturn Math.round(finalSlippage * 1000000) / 1000000;\n};\n\nexport const getFormattedSize = (\n\tsizesObject: Partial<Record<LiquidityType, number>>,\n\tprice: number,\n\tcurrency: CUMULATIVE_SIZE_CURRENCY,\n\tdisplayDecimals: number\n) => {\n\tconst sizeSum = Object.values(sizesObject || {}).reduce(\n\t\t(acc, curr) => acc + curr,\n\t\t0\n\t);\n\n\tconst displayValue =\n\t\tcurrency === CUMULATIVE_SIZE_CURRENCY.USD && price\n\t\t\t? sizeSum * price\n\t\t\t: sizeSum;\n\n\treturn BigNum.fromPrint(\n\t\tdisplayValue.toFixed(displayDecimals),\n\t\tnew BN(displayDecimals)\n\t).toMillified(3);\n};\n\nexport const getLiquidityPcts = (\n\ttotalSize: number,\n\tcumulativeSize: CategorisedLiquidity = {}\n) => {\n\tconst totalCumulativeSize = Object.values(cumulativeSize).reduce(\n\t\t(acc, curr) => acc + curr,\n\t\t0\n\t);\n\n\tconst cumulativeSizePct = totalSize\n\t\t? (totalCumulativeSize / totalSize) * 100\n\t\t: 0; // This is the portion of the total size of the orderbook that the cumulative size of the liquidity should be occupying.\n\n\tconst cumulativeRestingSize =\n\t\ttotalCumulativeSize - (cumulativeSize?.indicative ?? 0);\n\tconst cumulativeIndicativeSize = cumulativeSize?.indicative ?? 0;\n\n\tconst restingLiquidityPct =\n\t\t(cumulativeRestingSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the resting liquidity should be occupying\n\n\tconst indicativeLiquidityPct =\n\t\t(cumulativeIndicativeSize / totalCumulativeSize) * cumulativeSizePct; // This is the portion of the width of the orderbook that the indicative liquidity should be occupying\n\n\treturn {\n\t\trestingLiquidityPct,\n\t\tindicativeLiquidityPct,\n\t};\n};\n\nconst roundForOrderbook = (num: number) => Number(num.toFixed(6));\n\nexport const getBucketFloorForPrice = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst priceIsNegative = price < 0;\n\n\tconst _groupingSize = groupingSize as unknown as number;\n\n\tif (dividesExactly(price, _groupingSize)) {\n\t\treturn roundForOrderbook(price);\n\t}\n\n\tconst amountToDeduct = priceIsNegative\n\t\t? _groupingSize - (Math.abs(price) % _groupingSize)\n\t\t: Math.abs(price) % _groupingSize;\n\n\tconst floorPrice = price - amountToDeduct;\n\n\treturn roundForOrderbook(floorPrice);\n};\n\nexport const getUserLiquidityForPrice = ({\n\tprice,\n\tside,\n\tgroupingSizeValue,\n\tuserAskPriceBucketLookup,\n\tuserBidPriceBucketLookup,\n}: {\n\tprice: number;\n\tside: 'bid' | 'ask';\n\tgroupingSizeValue: GroupingSizeQuoteValue;\n\tuserAskPriceBucketLookup: Map<number, OrderBookBidAsk>;\n\tuserBidPriceBucketLookup: Map<number, OrderBookBidAsk>;\n}) => {\n\tlet isCurrentUserLiquidity = false;\n\tlet currentUserLiquiditySize = 0;\n\n\tconst priceToUse = price;\n\tconst priceBucket = getBucketFloorForPrice(priceToUse, groupingSizeValue);\n\n\tconst lookupBucket =\n\t\tside === 'bid' ? userBidPriceBucketLookup : userAskPriceBucketLookup;\n\n\tconst matchingUserBidAsk = lookupBucket.get(priceBucket);\n\n\tif (matchingUserBidAsk) {\n\t\tisCurrentUserLiquidity = true;\n\t\tcurrentUserLiquiditySize = matchingUserBidAsk.size;\n\t}\n\n\treturn { isCurrentUserLiquidity, currentUserLiquiditySize };\n};\n\nconst getBucketCeilingForPrice = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst _groupingSize = groupingSize as unknown as number;\n\treturn getBucketFloorForPrice(price + _groupingSize, groupingSize);\n};\n\nexport const getBucketAnchorPrice = (\n\ttype: 'bid' | 'ask',\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\t// If the grouping size matches exactly then the anchor price should be the same as the floor price regardless\n\tif (dividesExactly(price, groupingSize as unknown as number)) {\n\t\treturn getBucketFloorForPrice(price, groupingSize);\n\t}\n\n\tif (type === 'bid') {\n\t\treturn getBucketFloorForPrice(price, groupingSize);\n\t} else {\n\t\treturn getBucketCeilingForPrice(price, groupingSize);\n\t}\n};\n\nexport const getBucketForUserLiquidity = (\n\tprice: number,\n\tgroupingSize: GroupingSizeQuoteValue,\n\ttype: 'bid' | 'ask'\n) => getBucketAnchorPrice(type, price, groupingSize);\n\nexport const mergeBidsAndAsksForGroupsize = (\n\ttype: 'bid' | 'ask',\n\tbidsAsks: OrderBookBidAsk[],\n\tgroupingSize: GroupingSizeQuoteValue\n): OrderBookBidAsk[] => {\n\tconst bidsAsksBucketLookup = new Map<number, OrderBookBidAsk>();\n\n\tfor (const bidAsk of bidsAsks) {\n\t\tconst anchorPrice = getBucketAnchorPrice(type, bidAsk.price, groupingSize);\n\t\tconst existingBucket = bidsAsksBucketLookup.get(anchorPrice);\n\t\tif (existingBucket) {\n\t\t\texistingBucket.size += bidAsk.size;\n\t\t} else {\n\t\t\tbidsAsksBucketLookup.set(anchorPrice, { ...bidAsk });\n\t\t}\n\t}\n\n\treturn Array.from(bidsAsksBucketLookup.values());\n};\n\nexport const getZeroPaddingForGroupingSize = (\n\tgroupingSize: GroupingSizeQuoteValue\n) => {\n\tconst _groupingSize = groupingSize as unknown as number;\n\n\tconst precision = Math.floor(Math.log10(_groupingSize));\n\n\tif (precision >= 0 || _groupingSize === 0) return 0;\n\n\treturn Math.abs(precision);\n};\n\nconst sizeToNum = (size: BN, precision: BN) =>\n\tBigNum.from(size, precision).toNum();\n\nexport const getCategorisedLiquidityForLevel = (\n\tlevel: L2Level,\n\tbasePrecision: BN\n): CategorisedLiquidity => {\n\tconst dlobSize = sizeToNum(level?.sources?.dlob ?? ZERO, basePrecision);\n\tconst vammSize = sizeToNum(level?.sources?.vamm ?? ZERO, basePrecision);\n\tconst serumSize = sizeToNum(level?.sources?.serum ?? ZERO, basePrecision);\n\tconst phoenixSize = sizeToNum(level?.sources?.phoenix ?? ZERO, basePrecision);\n\tconst openbookSize = sizeToNum(\n\t\tlevel?.sources?.openbook ?? ZERO,\n\t\tbasePrecision\n\t);\n\tconst indicativeSize = sizeToNum(\n\t\tlevel?.sources?.indicative ?? ZERO,\n\t\tbasePrecision\n\t);\n\n\tconst categorisedLiquidity: CategorisedLiquidity = {\n\t\tdlob: dlobSize,\n\t\tvamm: vammSize,\n\t\tserum: serumSize,\n\t\tphoenix: phoenixSize,\n\t\topenbook: openbookSize,\n\t\tindicative: indicativeSize,\n\t};\n\n\treturn categorisedLiquidity;\n};\n\nconst formatLevelsToDisplay = (\n\tlevels: L2Level[],\n\tbasePrecision: BN,\n\tdepth?: number\n): {\n\tformattedLevels: OrderBookDisplayStateBidAsk[];\n\tbestLevel: number;\n\tcumulativeSize: number;\n} => {\n\tconst relevantSources: Set<LiquidityType> = new Set();\n\n\tfor (const level of levels) {\n\t\tfor (const source of Object.keys(level.sources)) {\n\t\t\trelevantSources.add(source as LiquidityType);\n\t\t}\n\t}\n\n\tconst cumulativeSizes: CategorisedLiquidity = Array.from(\n\t\trelevantSources\n\t).reduce((acc, source) => {\n\t\tacc[source] = 0;\n\t\treturn acc;\n\t}, {} as CategorisedLiquidity);\n\n\tlet cumulativePriceSizeProduct = 0;\n\tlet cumulativeTotalSize = 0;\n\n\tconst formattedLevels: OrderBookDisplayStateBidAsk[] = levels.map((level) => {\n\t\tconst bucketSize = getCategorisedLiquidityForLevel(level, basePrecision);\n\t\tconst price = BigNum.from(level.price, PRICE_PRECISION_EXP).toNum();\n\t\tconst totalSize = Object.values(bucketSize).reduce(\n\t\t\t(sum, size) => sum + size,\n\t\t\t0\n\t\t);\n\n\t\tfor (const source of relevantSources) {\n\t\t\tconst currentValue = cumulativeSizes[source];\n\t\t\tif (currentValue !== undefined) {\n\t\t\t\tcumulativeSizes[source] = currentValue + (bucketSize[source] ?? 0);\n\t\t\t}\n\t\t}\n\n\t\tcumulativePriceSizeProduct += price * totalSize;\n\t\tcumulativeTotalSize += totalSize;\n\n\t\treturn {\n\t\t\tprice,\n\t\t\tsize: bucketSize,\n\t\t\tcumulativeSize: { ...cumulativeSizes },\n\t\t\tcumulativeAvgPrice:\n\t\t\t\tcumulativeTotalSize > 0\n\t\t\t\t\t? cumulativePriceSizeProduct / cumulativeTotalSize\n\t\t\t\t\t: 0,\n\t\t};\n\t});\n\n\tif (depth && depth > 0) {\n\t\tconst visibleLevels = formattedLevels.slice(0, depth);\n\t\tconst maxCumulativeSize = Math.max(\n\t\t\t0,\n\t\t\t...visibleLevels.map((level) =>\n\t\t\t\tObject.values(level.cumulativeSize).reduce((sum, size) => sum + size, 0)\n\t\t\t)\n\t\t);\n\n\t\treturn {\n\t\t\tformattedLevels: visibleLevels,\n\t\t\tbestLevel: visibleLevels?.[0]?.price,\n\t\t\tcumulativeSize: maxCumulativeSize,\n\t\t};\n\t}\n\n\tconst totalSizeToReturn = Object.values(cumulativeSizes).reduce(\n\t\t(total, current) => total + current,\n\t\t0\n\t);\n\n\treturn {\n\t\tformattedLevels,\n\t\tbestLevel: formattedLevels?.[0]?.price,\n\t\tcumulativeSize: totalSizeToReturn,\n\t};\n};\n\nexport const formatL2ToDisplay = (\n\tl2State: L2OrderBook,\n\tbasePrecision: BN,\n\tdepth?: number\n) => {\n\tconst formattedBids = formatLevelsToDisplay(\n\t\tl2State.bids,\n\t\tbasePrecision,\n\t\tdepth\n\t);\n\tconst formattedAsks = formatLevelsToDisplay(\n\t\tl2State.asks,\n\t\tbasePrecision,\n\t\tdepth\n\t);\n\n\treturn {\n\t\tbids: formattedBids.formattedLevels,\n\t\tasks: formattedAsks.formattedLevels,\n\t\tbidTotalSize: formattedBids.cumulativeSize,\n\t\taskTotalSize: formattedAsks.cumulativeSize,\n\t};\n};\n\nconst filterOutDisabledLiquidityTypes = (\n\tl2Levels: L2Level[],\n\tdisabledLiquidityTypes: LiquidityType[]\n) =>\n\tl2Levels\n\t\t.map((level) => {\n\t\t\tlet totalDisabledSize = ZERO;\n\t\t\tconst disabledSourceObj: Record<LiquidityType, BN> = {} as Record<\n\t\t\t\tLiquidityType,\n\t\t\t\tBN\n\t\t\t>;\n\n\t\t\tfor (const liquidityType of disabledLiquidityTypes) {\n\t\t\t\tconst disabledLiqSize = level.sources?.[liquidityType];\n\t\t\t\tif (disabledLiqSize?.gt(ZERO)) {\n\t\t\t\t\ttotalDisabledSize = totalDisabledSize.add(disabledLiqSize);\n\t\t\t\t\tdisabledSourceObj[liquidityType] = ZERO;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn totalDisabledSize.gt(ZERO)\n\t\t\t\t? {\n\t\t\t\t\t\t...level,\n\t\t\t\t\t\tsize: level.size.sub(totalDisabledSize),\n\t\t\t\t\t\tsources: {\n\t\t\t\t\t\t\t...level.sources,\n\t\t\t\t\t\t\t...disabledSourceObj,\n\t\t\t\t\t\t},\n\t\t\t\t }\n\t\t\t\t: level;\n\t\t})\n\t\t.filter((level) => level.size.gt(ZERO));\n\nexport const l2ToDisplayBidsAndAsks = (\n\tl2Orderbook: L2OrderBook,\n\toraclePrice: BN,\n\ttickSizeForMarket: BN,\n\tgroupSizeTickMultiplier: number,\n\tuserBidsAndAsks: BidsAndAsks,\n\tbasePrecisionForMarket: BN,\n\tdisabledLiquidityTypes: LiquidityType[],\n\tmaxDepth: number,\n\tdepth?: number // limit the number of visible rows to calculate totalSize from\n) => {\n\tconst filteredBids =\n\t\tdisabledLiquidityTypes.length > 0\n\t\t\t? filterOutDisabledLiquidityTypes(\n\t\t\t\t\tl2Orderbook.bids,\n\t\t\t\t\tdisabledLiquidityTypes\n\t\t\t )\n\t\t\t: l2Orderbook.bids;\n\n\tconst filteredAsks =\n\t\tdisabledLiquidityTypes.length > 0\n\t\t\t? filterOutDisabledLiquidityTypes(\n\t\t\t\t\tl2Orderbook.asks,\n\t\t\t\t\tdisabledLiquidityTypes\n\t\t\t )\n\t\t\t: l2Orderbook.asks;\n\n\t// # Uncross the liquidity\n\tconst uncrossed = {\n\t\tl2Orderbook,\n\t\tbids: filteredBids,\n\t\tasks: filteredAsks,\n\t};\n\n\t// Group the orderbook into levels based on the grouping size\n\tconst grouped = groupL2(\n\t\tuncrossed,\n\t\ttickSizeForMarket.muln(groupSizeTickMultiplier ?? 1), // one user had a weird error where .muln was throwing assertion failed error\n\t\tmaxDepth\n\t);\n\n\t// # Convert to UI format\n\tconst formatted = formatL2ToDisplay(grouped, basePrecisionForMarket, depth);\n\n\t// Check that bids are in descending order\n\tif (\n\t\tformatted.bids.some((bid, index) => {\n\t\t\tif (index === 0) return false;\n\n\t\t\treturn bid.price > formatted.bids[index - 1].price;\n\t\t})\n\t) {\n\t\tconsole.log('orderbook - bids_not_in_descending_order', {\n\t\t\tl2Orderbook,\n\t\t\toraclePrice,\n\t\t\ttickSizeForMarket,\n\t\t\tuserBidsAndAsks,\n\t\t\tbasePrecisionForMarket,\n\t\t\tuncrossed,\n\t\t\tformatted,\n\t\t});\n\t}\n\n\t// Check that asks are in ascending order\n\tif (\n\t\tformatted.asks.some((ask, index) => {\n\t\t\tif (index === 0) return false;\n\n\t\t\treturn ask.price < formatted.asks[index - 1].price;\n\t\t})\n\t) {\n\t\tconsole.log('orderbook - asks_not_in_ascending_order', {\n\t\t\tl2Orderbook,\n\t\t\toraclePrice,\n\t\t\ttickSizeForMarket,\n\t\t\tuserBidsAndAsks,\n\t\t\tbasePrecisionForMarket,\n\t\t\tuncrossed,\n\t\t\tformatted,\n\t\t});\n\t}\n\n\treturn formatted;\n};\n\nexport const getEmptyFilledBidsAsks = (\n\tbidsOrAsks: OrderBookDisplayStateBidAsk[],\n\tdepth: number\n): (OrderBookDisplayStateBidAsk | EmptyRow)[] => {\n\tconst result = Array(depth).fill(EMPTY_ORDERBOOK_ROW);\n\n\tbidsOrAsks.forEach((bidOrAsk, index) => {\n\t\tif (index < depth) {\n\t\t\tresult[index] = bidOrAsk;\n\t\t}\n\t});\n\n\treturn result;\n};\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OrderActionRecord } from '@drift-labs/sdk';
|
|
2
|
+
import { UISerializableOrder, UISerializableOrderActionRecord } from '../../serializableTypes';
|
|
3
|
+
export declare const orderActionRecordIsTrade: (orderRecord: OrderActionRecord) => boolean;
|
|
4
|
+
export declare const uiOrderActionRecordIsTrade: (orderRecord: UISerializableOrderActionRecord) => boolean;
|
|
5
|
+
export declare const filterTradeRecordsFromOrderActionRecords: (orderRecords: OrderActionRecord[]) => OrderActionRecord[];
|
|
6
|
+
export declare const filterTradeRecordsFromUIOrderRecords: (orderRecords: UISerializableOrderActionRecord[]) => UISerializableOrderActionRecord[];
|
|
7
|
+
export declare const isOrderTriggered: (order: Pick<UISerializableOrder, 'orderType' | 'triggerCondition' | 'status'>) => boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOrderTriggered = exports.filterTradeRecordsFromUIOrderRecords = exports.filterTradeRecordsFromOrderActionRecords = exports.uiOrderActionRecordIsTrade = exports.orderActionRecordIsTrade = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const enum_1 = require("../enum");
|
|
6
|
+
// Trade records are order records which have been filled
|
|
7
|
+
const orderActionRecordIsTrade = (orderRecord) => orderRecord.baseAssetAmountFilled.gt(sdk_1.ZERO) &&
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
(0, enum_1.matchEnum)(orderRecord.action, sdk_1.OrderAction.FILL) &&
|
|
10
|
+
true;
|
|
11
|
+
exports.orderActionRecordIsTrade = orderActionRecordIsTrade;
|
|
12
|
+
const uiOrderActionRecordIsTrade = (orderRecord) => orderRecord.baseAssetAmountFilled.gtZero() &&
|
|
13
|
+
(0, enum_1.matchEnum)(orderRecord.action, sdk_1.OrderAction.FILL) &&
|
|
14
|
+
true;
|
|
15
|
+
exports.uiOrderActionRecordIsTrade = uiOrderActionRecordIsTrade;
|
|
16
|
+
// Trade records are order records which have been filled
|
|
17
|
+
const filterTradeRecordsFromOrderActionRecords = (orderRecords) => orderRecords.filter(exports.orderActionRecordIsTrade);
|
|
18
|
+
exports.filterTradeRecordsFromOrderActionRecords = filterTradeRecordsFromOrderActionRecords;
|
|
19
|
+
// Trade records are order records which have been filled
|
|
20
|
+
const filterTradeRecordsFromUIOrderRecords = (orderRecords) => orderRecords.filter(exports.uiOrderActionRecordIsTrade);
|
|
21
|
+
exports.filterTradeRecordsFromUIOrderRecords = filterTradeRecordsFromUIOrderRecords;
|
|
22
|
+
const isOrderTriggered = (order) => {
|
|
23
|
+
const isTriggerOrderType = enum_1.ENUM_UTILS.match(order.orderType, sdk_1.OrderType.TRIGGER_MARKET) ||
|
|
24
|
+
enum_1.ENUM_UTILS.match(order.orderType, sdk_1.OrderType.TRIGGER_LIMIT);
|
|
25
|
+
const orderWasCancelled = enum_1.ENUM_UTILS.match(order.status, sdk_1.OrderStatus.CANCELED);
|
|
26
|
+
const orderWasTriggered = enum_1.ENUM_UTILS.match(order.triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_ABOVE) ||
|
|
27
|
+
enum_1.ENUM_UTILS.match(order.triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_BELOW);
|
|
28
|
+
return isTriggerOrderType && orderWasTriggered && !orderWasCancelled;
|
|
29
|
+
};
|
|
30
|
+
exports.isOrderTriggered = isOrderTriggered;
|
|
31
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../src/utils/orders/filters.ts"],"names":[],"mappings":";;;AAAA,yCAOyB;AAKzB,kCAAgD;AAEhD,yDAAyD;AAClD,MAAM,wBAAwB,GAAG,CAAC,WAA8B,EAAE,EAAE,CAC1E,WAAW,CAAC,qBAAqB,CAAC,EAAE,CAAC,UAAI,CAAC;IAC1C,aAAa;IACb,IAAA,gBAAS,EAAC,WAAW,CAAC,MAAM,EAAE,iBAAW,CAAC,IAAI,CAAC;IAC/C,IAAI,CAAC;AAJO,QAAA,wBAAwB,4BAI/B;AAEC,MAAM,0BAA0B,GAAG,CACzC,WAA4C,EAC3C,EAAE,CACH,WAAW,CAAC,qBAAqB,CAAC,MAAM,EAAE;IAC1C,IAAA,gBAAS,EAAC,WAAW,CAAC,MAAM,EAAE,iBAAW,CAAC,IAAI,CAAC;IAC/C,IAAI,CAAC;AALO,QAAA,0BAA0B,8BAKjC;AAEN,yDAAyD;AAClD,MAAM,wCAAwC,GAAG,CACvD,YAAiC,EACX,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,gCAAwB,CAAC,CAAC;AAF3D,QAAA,wCAAwC,4CAEmB;AAExE,yDAAyD;AAClD,MAAM,oCAAoC,GAAG,CACnD,YAA+C,EACX,EAAE,CACtC,YAAY,CAAC,MAAM,CAAC,kCAA0B,CAAC,CAAC;AAHpC,QAAA,oCAAoC,wCAGA;AAE1C,MAAM,gBAAgB,GAAG,CAC/B,KAA6E,EACnE,EAAE;IACZ,MAAM,kBAAkB,GACvB,iBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,eAAS,CAAC,cAAc,CAAC;QAC3D,iBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,eAAS,CAAC,aAAa,CAAC,CAAC;IAE5D,MAAM,iBAAiB,GAAG,iBAAU,CAAC,KAAK,CACzC,KAAK,CAAC,MAAM,EACZ,iBAAW,CAAC,QAAQ,CACpB,CAAC;IAEF,MAAM,iBAAiB,GACtB,iBAAU,CAAC,KAAK,CACf,KAAK,CAAC,gBAAgB,EACtB,2BAAqB,CAAC,eAAe,CACrC;QACD,iBAAU,CAAC,KAAK,CACf,KAAK,CAAC,gBAAgB,EACtB,2BAAqB,CAAC,eAAe,CACrC,CAAC;IAEH,OAAO,kBAAkB,IAAI,iBAAiB,IAAI,CAAC,iBAAiB,CAAC;AACtE,CAAC,CAAC;AAvBW,QAAA,gBAAgB,oBAuB3B","sourcesContent":["import {\n\tOrderAction,\n\tOrderActionRecord,\n\tOrderStatus,\n\tOrderTriggerCondition,\n\tOrderType,\n\tZERO,\n} from '@drift-labs/sdk';\nimport {\n\tUISerializableOrder,\n\tUISerializableOrderActionRecord,\n} from '../../serializableTypes';\nimport { matchEnum, ENUM_UTILS } from '../enum';\n\n// Trade records are order records which have been filled\nexport const orderActionRecordIsTrade = (orderRecord: OrderActionRecord) =>\n\torderRecord.baseAssetAmountFilled.gt(ZERO) &&\n\t// @ts-ignore\n\tmatchEnum(orderRecord.action, OrderAction.FILL) &&\n\ttrue;\n\nexport const uiOrderActionRecordIsTrade = (\n\torderRecord: UISerializableOrderActionRecord\n) =>\n\torderRecord.baseAssetAmountFilled.gtZero() &&\n\tmatchEnum(orderRecord.action, OrderAction.FILL) &&\n\ttrue;\n\n// Trade records are order records which have been filled\nexport const filterTradeRecordsFromOrderActionRecords = (\n\torderRecords: OrderActionRecord[]\n): OrderActionRecord[] => orderRecords.filter(orderActionRecordIsTrade);\n\n// Trade records are order records which have been filled\nexport const filterTradeRecordsFromUIOrderRecords = (\n\torderRecords: UISerializableOrderActionRecord[]\n): UISerializableOrderActionRecord[] =>\n\torderRecords.filter(uiOrderActionRecordIsTrade);\n\nexport const isOrderTriggered = (\n\torder: Pick<UISerializableOrder, 'orderType' | 'triggerCondition' | 'status'>\n): boolean => {\n\tconst isTriggerOrderType =\n\t\tENUM_UTILS.match(order.orderType, OrderType.TRIGGER_MARKET) ||\n\t\tENUM_UTILS.match(order.orderType, OrderType.TRIGGER_LIMIT);\n\n\tconst orderWasCancelled = ENUM_UTILS.match(\n\t\torder.status,\n\t\tOrderStatus.CANCELED\n\t);\n\n\tconst orderWasTriggered =\n\t\tENUM_UTILS.match(\n\t\t\torder.triggerCondition,\n\t\t\tOrderTriggerCondition.TRIGGERED_ABOVE\n\t\t) ||\n\t\tENUM_UTILS.match(\n\t\t\torder.triggerCondition,\n\t\t\tOrderTriggerCondition.TRIGGERED_BELOW\n\t\t);\n\n\treturn isTriggerOrderType && orderWasTriggered && !orderWasCancelled;\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BN, ContractTier, DriftClient, User } from '@drift-labs/sdk';
|
|
2
|
+
export type HighLeverageOptions = {
|
|
3
|
+
numOfOpenHighLeverageSpots?: number;
|
|
4
|
+
enterHighLeverageModeBufferPct?: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function getPerpAuctionDuration(priceDiff: BN, price: BN, contractTier: ContractTier): number;
|
|
7
|
+
/**
|
|
8
|
+
* Mainly checks if the user will be entering high leverage mode through this order.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPerpOrderParamsBitFlags(marketIndex: number, driftClient: DriftClient, userAccount: User, attemptedLeverage: number, highLeverageOptions?: {
|
|
11
|
+
numOfOpenHighLeverageSpots?: number;
|
|
12
|
+
}): number | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPerpOrderParamsBitFlags = exports.getPerpAuctionDuration = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const leverage_1 = require("../markets/leverage");
|
|
6
|
+
function getPerpAuctionDuration(priceDiff, price, contractTier) {
|
|
7
|
+
const percentDiff = priceDiff.mul(sdk_1.PERCENTAGE_PRECISION).div(price);
|
|
8
|
+
const slotsPerBp = (0, sdk_1.isOneOfVariant)(contractTier, ['a', 'b'])
|
|
9
|
+
? new sdk_1.BN(100)
|
|
10
|
+
: new sdk_1.BN(60);
|
|
11
|
+
const rawSlots = percentDiff
|
|
12
|
+
.mul(slotsPerBp)
|
|
13
|
+
.div(sdk_1.PERCENTAGE_PRECISION.divn(100));
|
|
14
|
+
const clamped = sdk_1.BN.min(sdk_1.BN.max(rawSlots, new sdk_1.BN(5)), new sdk_1.BN(180));
|
|
15
|
+
return clamped.toNumber();
|
|
16
|
+
}
|
|
17
|
+
exports.getPerpAuctionDuration = getPerpAuctionDuration;
|
|
18
|
+
/**
|
|
19
|
+
* Mainly checks if the user will be entering high leverage mode through this order.
|
|
20
|
+
*/
|
|
21
|
+
function getPerpOrderParamsBitFlags(marketIndex, driftClient, userAccount, attemptedLeverage, highLeverageOptions) {
|
|
22
|
+
if (attemptedLeverage < 5) {
|
|
23
|
+
// there is no high leverage mode leverage that is higher than 4
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const { numOfOpenHighLeverageSpots = Number.MAX_SAFE_INTEGER } = highLeverageOptions || {};
|
|
27
|
+
if (numOfOpenHighLeverageSpots <= 0) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const { hasHighLeverage: isMarketAHighLeverageMarket, maxLeverage: regularMaxLeverage, } = (0, leverage_1.getMaxLeverageForMarket)(sdk_1.MarketType.PERP, marketIndex, driftClient);
|
|
31
|
+
if (!isMarketAHighLeverageMarket) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
// Check if user is already in high leverage mode
|
|
35
|
+
if (userAccount.isHighLeverageMode('Initial')) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (attemptedLeverage > regularMaxLeverage) {
|
|
39
|
+
return sdk_1.OrderParamsBitFlag.UpdateHighLeverageMode;
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
exports.getPerpOrderParamsBitFlags = getPerpOrderParamsBitFlags;
|
|
44
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../../../src/utils/orders/flags.ts"],"names":[],"mappings":";;;AAAA,yCASyB;AACzB,kDAA8D;AAO9D,SAAgB,sBAAsB,CACrC,SAAa,EACb,KAAS,EACT,YAA0B;IAE1B,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,0BAAoB,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAEnE,MAAM,UAAU,GAAG,IAAA,oBAAc,EAAC,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC1D,CAAC,CAAC,IAAI,QAAE,CAAC,GAAG,CAAC;QACb,CAAC,CAAC,IAAI,QAAE,CAAC,EAAE,CAAC,CAAC;IAEd,MAAM,QAAQ,GAAG,WAAW;SAC1B,GAAG,CAAC,UAAU,CAAC;SACf,GAAG,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n\tOrderParamsBitFlag,\n\tPERCENTAGE_PRECISION,\n\tUser,\n} from '@drift-labs/sdk';\nimport { getMaxLeverageForMarket } from '../markets/leverage';\n\nexport type HighLeverageOptions = {\n\tnumOfOpenHighLeverageSpots?: number; // if not provided, the method will assume that there is spots open\n\tenterHighLeverageModeBufferPct?: number;\n};\n\nexport function getPerpAuctionDuration(\n\tpriceDiff: BN,\n\tprice: BN,\n\tcontractTier: ContractTier\n): number {\n\tconst percentDiff = priceDiff.mul(PERCENTAGE_PRECISION).div(price);\n\n\tconst slotsPerBp = isOneOfVariant(contractTier, ['a', 'b'])\n\t\t? new BN(100)\n\t\t: new BN(60);\n\n\tconst rawSlots = percentDiff\n\t\t.mul(slotsPerBp)\n\t\t.div(PERCENTAGE_PRECISION.divn(100));\n\n\tconst clamped = BN.min(BN.max(rawSlots, new BN(5)), new BN(180));\n\n\treturn clamped.toNumber();\n}\n\n/**\n * Mainly checks if the user will be entering high leverage mode through this order.\n */\nexport function getPerpOrderParamsBitFlags(\n\tmarketIndex: number,\n\tdriftClient: DriftClient,\n\tuserAccount: User,\n\tattemptedLeverage: number,\n\thighLeverageOptions?: {\n\t\tnumOfOpenHighLeverageSpots?: number; // if not provided, the method will assume that there is spots open\n\t}\n): number | undefined {\n\tif (attemptedLeverage < 5) {\n\t\t// there is no high leverage mode leverage that is higher than 4\n\t\treturn undefined;\n\t}\n\n\tconst { numOfOpenHighLeverageSpots = Number.MAX_SAFE_INTEGER } =\n\t\thighLeverageOptions || {};\n\n\tif (numOfOpenHighLeverageSpots <= 0) {\n\t\treturn undefined;\n\t}\n\n\tconst {\n\t\thasHighLeverage: isMarketAHighLeverageMarket,\n\t\tmaxLeverage: regularMaxLeverage,\n\t} = getMaxLeverageForMarket(MarketType.PERP, marketIndex, driftClient);\n\n\tif (!isMarketAHighLeverageMarket) {\n\t\treturn undefined;\n\t}\n\n\t// Check if user is already in high leverage mode\n\tif (userAccount.isHighLeverageMode('Initial')) {\n\t\treturn undefined;\n\t}\n\n\tif (attemptedLeverage > regularMaxLeverage) {\n\t\treturn OrderParamsBitFlag.UpdateHighLeverageMode;\n\t}\n\n\treturn undefined;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sort"), exports);
|
|
18
|
+
__exportStar(require("./filters"), exports);
|
|
19
|
+
__exportStar(require("./labels"), exports);
|
|
20
|
+
__exportStar(require("./oracle"), exports);
|
|
21
|
+
__exportStar(require("./flags"), exports);
|
|
22
|
+
__exportStar(require("./misc"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/orders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB","sourcesContent":["export * from './sort';\nexport * from './filters';\nexport * from './labels';\nexport * from './oracle';\nexport * from './flags';\nexport * from './misc';\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { OrderType, OrderTriggerCondition, PositionDirection, BigNum } from '@drift-labs/sdk';
|
|
2
|
+
import { UISerializableOrder } from '../../serializableTypes';
|
|
3
|
+
export declare const getOrderLabelFromOrderDetails: (orderDetails: Pick<UISerializableOrder, 'orderType' | 'oraclePriceOffset' | 'direction' | 'triggerCondition' | 'existingPositionDirection'>) => string;
|
|
4
|
+
export declare const getUIOrderTypeFromSdkOrderType: (orderType: OrderType, triggerCondition: OrderTriggerCondition, direction: PositionDirection, oracleOffset: BigNum | undefined) => import("../..").UIOrderTypeValue;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUIOrderTypeFromSdkOrderType = exports.getOrderLabelFromOrderDetails = void 0;
|
|
4
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
+
const orders_1 = require("../../constants/orders");
|
|
6
|
+
const enum_1 = require("../enum");
|
|
7
|
+
const getOrderLabelFromOrderDetails = (orderDetails) => {
|
|
8
|
+
var _a;
|
|
9
|
+
if ((0, enum_1.matchEnum)(orderDetails.orderType, sdk_1.OrderType.MARKET))
|
|
10
|
+
return orders_1.UI_ORDER_TYPES.market.label;
|
|
11
|
+
if ((0, enum_1.matchEnum)(orderDetails.orderType, sdk_1.OrderType.LIMIT))
|
|
12
|
+
return `${orderDetails.oraclePriceOffset &&
|
|
13
|
+
!((_a = orderDetails.oraclePriceOffset) === null || _a === void 0 ? void 0 : _a.eqZero())
|
|
14
|
+
? 'Oracle '
|
|
15
|
+
: ''}${orders_1.UI_ORDER_TYPES.limit.label}`;
|
|
16
|
+
if ((0, enum_1.matchEnum)(orderDetails.orderType, sdk_1.OrderType.ORACLE))
|
|
17
|
+
return orders_1.UI_ORDER_TYPES.oracle.label;
|
|
18
|
+
if ((0, enum_1.matchEnum)(orderDetails.orderType, sdk_1.OrderType.TRIGGER_MARKET)) {
|
|
19
|
+
const isTriggered = (0, enum_1.matchEnum)(orderDetails.triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_ABOVE) ||
|
|
20
|
+
(0, enum_1.matchEnum)(orderDetails.triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_BELOW);
|
|
21
|
+
if (isTriggered) {
|
|
22
|
+
return 'Market (Triggered)';
|
|
23
|
+
}
|
|
24
|
+
const isTriggerAbove = (0, enum_1.matchEnum)(orderDetails.triggerCondition, sdk_1.OrderTriggerCondition.ABOVE);
|
|
25
|
+
const isOrderDirectionShort = (0, enum_1.matchEnum)(orderDetails.direction, sdk_1.PositionDirection.SHORT);
|
|
26
|
+
if (isTriggerAbove) {
|
|
27
|
+
return isOrderDirectionShort
|
|
28
|
+
? orders_1.UI_ORDER_TYPES.takeProfitMarket.label
|
|
29
|
+
: orders_1.UI_ORDER_TYPES.stopMarket.label;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return isOrderDirectionShort
|
|
33
|
+
? orders_1.UI_ORDER_TYPES.stopMarket.label
|
|
34
|
+
: orders_1.UI_ORDER_TYPES.takeProfitMarket.label;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if ((0, enum_1.matchEnum)(orderDetails.orderType, sdk_1.OrderType.TRIGGER_LIMIT)) {
|
|
38
|
+
const isTriggered = (0, enum_1.matchEnum)(orderDetails.triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_ABOVE) ||
|
|
39
|
+
(0, enum_1.matchEnum)(orderDetails.triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_BELOW);
|
|
40
|
+
const isTriggerAbove = (0, enum_1.matchEnum)(orderDetails.triggerCondition, sdk_1.OrderTriggerCondition.ABOVE);
|
|
41
|
+
const isOrderDirectionShort = (0, enum_1.matchEnum)(orderDetails.direction, sdk_1.PositionDirection.SHORT);
|
|
42
|
+
if (isTriggered) {
|
|
43
|
+
return 'Limit (Triggered)';
|
|
44
|
+
}
|
|
45
|
+
if (isTriggerAbove) {
|
|
46
|
+
return isOrderDirectionShort
|
|
47
|
+
? orders_1.UI_ORDER_TYPES.takeProfitLimit.label
|
|
48
|
+
: orders_1.UI_ORDER_TYPES.stopLimit.label;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return isOrderDirectionShort
|
|
52
|
+
? orders_1.UI_ORDER_TYPES.stopLimit.label
|
|
53
|
+
: orders_1.UI_ORDER_TYPES.takeProfitLimit.label;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return '-';
|
|
57
|
+
};
|
|
58
|
+
exports.getOrderLabelFromOrderDetails = getOrderLabelFromOrderDetails;
|
|
59
|
+
const getUIOrderTypeFromSdkOrderType = (orderType, triggerCondition, direction, oracleOffset) => {
|
|
60
|
+
const isLong = enum_1.ENUM_UTILS.match(direction, sdk_1.PositionDirection.LONG);
|
|
61
|
+
const triggerAbove = (0, enum_1.matchEnum)(triggerCondition, sdk_1.OrderTriggerCondition.ABOVE) ||
|
|
62
|
+
(0, enum_1.matchEnum)(triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_ABOVE);
|
|
63
|
+
const triggerBelow = (0, enum_1.matchEnum)(triggerCondition, sdk_1.OrderTriggerCondition.BELOW) ||
|
|
64
|
+
(0, enum_1.matchEnum)(triggerCondition, sdk_1.OrderTriggerCondition.TRIGGERED_BELOW);
|
|
65
|
+
// Buy side + trigger below: take profit for a short position
|
|
66
|
+
// Buy side + trigger above: stop loss for a short position
|
|
67
|
+
// Sell side + trigger above: take profit for a long position
|
|
68
|
+
// Sell side + trigger below: stop loss for a long position
|
|
69
|
+
if ((0, enum_1.matchEnum)(orderType, sdk_1.OrderType.MARKET)) {
|
|
70
|
+
return orders_1.MARKET_ORDER_TYPE_CONFIG;
|
|
71
|
+
}
|
|
72
|
+
else if ((0, enum_1.matchEnum)(orderType, sdk_1.OrderType.LIMIT)) {
|
|
73
|
+
if (oracleOffset && !oracleOffset.eq(sdk_1.ZERO)) {
|
|
74
|
+
return orders_1.ORACLE_LIMIT_ORDER_TYPE_CONFIG;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return orders_1.LIMIT_ORDER_TYPE_CONFIG;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if ((0, enum_1.matchEnum)(orderType, sdk_1.OrderType.TRIGGER_MARKET)) {
|
|
81
|
+
if (isLong) {
|
|
82
|
+
if (triggerAbove) {
|
|
83
|
+
return orders_1.STOP_MARKET_ORDER_TYPE_CONFIG;
|
|
84
|
+
}
|
|
85
|
+
else if (triggerBelow) {
|
|
86
|
+
return orders_1.TAKE_PROFIT_MARKET_ORDER_TYPE_CONFIG;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
if (triggerAbove) {
|
|
91
|
+
return orders_1.TAKE_PROFIT_MARKET_ORDER_TYPE_CONFIG;
|
|
92
|
+
}
|
|
93
|
+
else if (triggerBelow) {
|
|
94
|
+
return orders_1.STOP_MARKET_ORDER_TYPE_CONFIG;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if ((0, enum_1.matchEnum)(orderType, sdk_1.OrderType.TRIGGER_LIMIT)) {
|
|
99
|
+
if (isLong) {
|
|
100
|
+
if (triggerAbove) {
|
|
101
|
+
return orders_1.STOP_LIMIT_ORDER_TYPE_CONFIG;
|
|
102
|
+
}
|
|
103
|
+
else if (triggerBelow) {
|
|
104
|
+
return orders_1.TAKE_PROFIT_LIMIT_ORDER_TYPE_CONFIG;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (triggerAbove) {
|
|
109
|
+
return orders_1.TAKE_PROFIT_LIMIT_ORDER_TYPE_CONFIG;
|
|
110
|
+
}
|
|
111
|
+
else if (triggerBelow) {
|
|
112
|
+
return orders_1.STOP_LIMIT_ORDER_TYPE_CONFIG;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if ((0, enum_1.matchEnum)(orderType, sdk_1.OrderType.ORACLE)) {
|
|
117
|
+
return orders_1.ORACLE_MARKET_ORDER_TYPE_CONFIG;
|
|
118
|
+
}
|
|
119
|
+
throw new Error('Invalid order type');
|
|
120
|
+
};
|
|
121
|
+
exports.getUIOrderTypeFromSdkOrderType = getUIOrderTypeFromSdkOrderType;
|
|
122
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.js","sourceRoot":"","sources":["../../../src/utils/orders/labels.ts"],"names":[],"mappings":";;;AAAA,yCAMyB;AACzB,mDAUgC;AAEhC,kCAAgD;AAEzC,MAAM,6BAA6B,GAAG,CAC5C,YAOC,EACA,EAAE;;IACH,IAAI,IAAA,gBAAS,EAAC,YAAY,CAAC,SAAS,EAAE,eAAS,CAAC,MAAM,CAAC;QACtD,OAAO,uBAAc,CAAC,MAAM,CAAC,KAAK,CAAC;IAEpC,IAAI,IAAA,gBAAS,EAAC,YAAY,CAAC,SAAS,EAAE,eAAS,CAAC,KAAK,CAAC;QACrD,OAAO,GACN,YAAY,CAAC,iBAAiB;YAC9B,CAAC,CAAA,MAAA,YAAY,CAAC,iBAAiB,0CAAE,MAAM,EAAE,CAAA;YACxC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,EACJ,GAAG,uBAAc,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAEjC,IAAI,IAAA,gBAAS,EAAC,YAAY,CAAC,SAAS,EAAE,eAAS,CAAC,MAAM,CAAC;QACtD,OAAO,uBAAc,CAAC,MAAM,CAAC,KAAK,CAAC;IAEpC,IAAI,IAAA,gBAAS,EAAC,YAAY,CAAC,SAAS,EAAE,eAAS,CAAC,cAAc,CAAC,EAAE,CAAC;QACjE,MAAM,WAAW,GAChB,IAAA,gBAAS,EACR,YAAY,CAAC,gBAAgB,EAC7B,2BAAqB,CAAC,eAAe,CACrC;YACD,IAAA,gBAAS,EACR,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Condition,\n\tPositionDirection,\n\tBigNum,\n\tZERO,\n} from '@drift-labs/sdk';\nimport {\n\tLIMIT_ORDER_TYPE_CONFIG,\n\tMARKET_ORDER_TYPE_CONFIG,\n\tORACLE_LIMIT_ORDER_TYPE_CONFIG,\n\tORACLE_MARKET_ORDER_TYPE_CONFIG,\n\tSTOP_LIMIT_ORDER_TYPE_CONFIG,\n\tSTOP_MARKET_ORDER_TYPE_CONFIG,\n\tTAKE_PROFIT_LIMIT_ORDER_TYPE_CONFIG,\n\tTAKE_PROFIT_MARKET_ORDER_TYPE_CONFIG,\n\tUI_ORDER_TYPES,\n} from '../../constants/orders';\nimport { UISerializableOrder } from '../../serializableTypes';\nimport { ENUM_UTILS, matchEnum } from '../enum';\n\nexport const getOrderLabelFromOrderDetails = (\n\torderDetails: Pick<\n\t\tUISerializableOrder,\n\t\t| 'orderType'\n\t\t| 'oraclePriceOffset'\n\t\t| 'direction'\n\t\t| 'triggerCondition'\n\t\t| 'existingPositionDirection'\n\t>\n) => {\n\tif (matchEnum(orderDetails.orderType, OrderType.MARKET))\n\t\treturn UI_ORDER_TYPES.market.label;\n\n\tif (matchEnum(orderDetails.orderType, OrderType.LIMIT))\n\t\treturn `${\n\t\t\torderDetails.oraclePriceOffset &&\n\t\t\t!orderDetails.oraclePriceOffset?.eqZero()\n\t\t\t\t? 'Oracle '\n\t\t\t\t: ''\n\t\t}${UI_ORDER_TYPES.limit.label}`;\n\n\tif (matchEnum(orderDetails.orderType, OrderType.ORACLE))\n\t\treturn UI_ORDER_TYPES.oracle.label;\n\n\tif (matchEnum(orderDetails.orderType, OrderType.TRIGGER_MARKET)) {\n\t\tconst isTriggered =\n\t\t\tmatchEnum(\n\t\t\t\torderDetails.triggerCondition,\n\t\t\t\tOrderTriggerCondition.TRIGGERED_ABOVE\n\t\t\t) ||\n\t\t\tmatchEnum(\n\t\t\t\torderDetails.triggerCondition,\n\t\t\t\tOrderTriggerCondition.TRIGGERED_BELOW\n\t\t\t);\n\t\tif (isTriggered) {\n\t\t\treturn 'Market (Triggered)';\n\t\t}\n\n\t\tconst isTriggerAbove = matchEnum(\n\t\t\torderDetails.triggerCondition,\n\t\t\tOrderTriggerCondition.ABOVE\n\t\t);\n\t\tconst isOrderDirectionShort = matchEnum(\n\t\t\torderDetails.direction,\n\t\t\tPositionDirection.SHORT\n\t\t);\n\n\t\tif (isTriggerAbove) {\n\t\t\treturn isOrderDirectionShort\n\t\t\t\t? UI_ORDER_TYPES.takeProfitMarket.label\n\t\t\t\t: UI_ORDER_TYPES.stopMarket.label;\n\t\t} else {\n\t\t\treturn isOrderDirectionShort\n\t\t\t\t? UI_ORDER_TYPES.stopMarket.label\n\t\t\t\t: UI_ORDER_TYPES.takeProfitMarket.label;\n\t\t}\n\t}\n\n\tif (matchEnum(orderDetails.orderType, OrderType.TRIGGER_LIMIT)) {\n\t\tconst isTriggered =\n\t\t\tmatchEnum(\n\t\t\t\torderDetails.triggerCondition,\n\t\t\t\tOrderTriggerCondition.TRIGGERED_ABOVE\n\t\t\t) ||\n\t\t\tmatchEnum(\n\t\t\t\torderDetails.triggerCondition,\n\t\t\t\tOrderTriggerCondition.TRIGGERED_BELOW\n\t\t\t);\n\n\t\tconst isTriggerAbove = matchEnum(\n\t\t\torderDetails.triggerCondition,\n\t\t\tOrderTriggerCondition.ABOVE\n\t\t);\n\t\tconst isOrderDirectionShort = matchEnum(\n\t\t\torderDetails.direction,\n\t\t\tPositionDirection.SHORT\n\t\t);\n\n\t\tif (isTriggered) {\n\t\t\treturn 'Limit (Triggered)';\n\t\t}\n\n\t\tif (isTriggerAbove) {\n\t\t\treturn isOrderDirectionShort\n\t\t\t\t? UI_ORDER_TYPES.takeProfitLimit.label\n\t\t\t\t: UI_ORDER_TYPES.stopLimit.label;\n\t\t} else {\n\t\t\treturn isOrderDirectionShort\n\t\t\t\t? UI_ORDER_TYPES.stopLimit.label\n\t\t\t\t: UI_ORDER_TYPES.takeProfitLimit.label;\n\t\t}\n\t}\n\n\treturn '-';\n};\n\nexport const getUIOrderTypeFromSdkOrderType = (\n\torderType: OrderType,\n\ttriggerCondition: OrderTriggerCondition,\n\tdirection: PositionDirection,\n\toracleOffset: BigNum | undefined\n) => {\n\tconst isLong = ENUM_UTILS.match(direction, PositionDirection.LONG);\n\tconst triggerAbove =\n\t\tmatchEnum(triggerCondition, OrderTriggerCondition.ABOVE) ||\n\t\tmatchEnum(triggerCondition, OrderTriggerCondition.TRIGGERED_ABOVE);\n\n\tconst triggerBelow =\n\t\tmatchEnum(triggerCondition, OrderTriggerCondition.BELOW) ||\n\t\tmatchEnum(triggerCondition, OrderTriggerCondition.TRIGGERED_BELOW);\n\n\t// Buy side + trigger below: take profit for a short position\n\t// Buy side + trigger above: stop loss for a short position\n\t// Sell side + trigger above: take profit for a long position\n\t// Sell side + trigger below: stop loss for a long position\n\n\tif (matchEnum(orderType, OrderType.MARKET)) {\n\t\treturn MARKET_ORDER_TYPE_CONFIG;\n\t} else if (matchEnum(orderType, OrderType.LIMIT)) {\n\t\tif (oracleOffset && !oracleOffset.eq(ZERO)) {\n\t\t\treturn ORACLE_LIMIT_ORDER_TYPE_CONFIG;\n\t\t} else {\n\t\t\treturn LIMIT_ORDER_TYPE_CONFIG;\n\t\t}\n\t} else if (matchEnum(orderType, OrderType.TRIGGER_MARKET)) {\n\t\tif (isLong) {\n\t\t\tif (triggerAbove) {\n\t\t\t\treturn STOP_MARKET_ORDER_TYPE_CONFIG;\n\t\t\t} else if (triggerBelow) {\n\t\t\t\treturn TAKE_PROFIT_MARKET_ORDER_TYPE_CONFIG;\n\t\t\t}\n\t\t} else {\n\t\t\tif (triggerAbove) {\n\t\t\t\treturn TAKE_PROFIT_MARKET_ORDER_TYPE_CONFIG;\n\t\t\t} else if (triggerBelow) {\n\t\t\t\treturn STOP_MARKET_ORDER_TYPE_CONFIG;\n\t\t\t}\n\t\t}\n\t} else if (matchEnum(orderType, OrderType.TRIGGER_LIMIT)) {\n\t\tif (isLong) {\n\t\t\tif (triggerAbove) {\n\t\t\t\treturn STOP_LIMIT_ORDER_TYPE_CONFIG;\n\t\t\t} else if (triggerBelow) {\n\t\t\t\treturn TAKE_PROFIT_LIMIT_ORDER_TYPE_CONFIG;\n\t\t\t}\n\t\t} else {\n\t\t\tif (triggerAbove) {\n\t\t\t\treturn TAKE_PROFIT_LIMIT_ORDER_TYPE_CONFIG;\n\t\t\t} else if (triggerBelow) {\n\t\t\t\treturn STOP_LIMIT_ORDER_TYPE_CONFIG;\n\t\t\t}\n\t\t}\n\t} else if (matchEnum(orderType, OrderType.ORACLE)) {\n\t\treturn ORACLE_MARKET_ORDER_TYPE_CONFIG;\n\t}\n\tthrow new Error('Invalid order type');\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Event, OrderActionRecord } from '@drift-labs/sdk';
|
|
2
|
+
import { UISerializableOrderActionRecord } from '../../serializableTypes';
|
|
3
|
+
import { PartialUISerializableOrderActionRecord } from './sort';
|
|
4
|
+
export declare const orderIsNull: (order: UISerializableOrderActionRecord | Event<OrderActionRecord>, side: 'taker' | 'maker') => boolean;
|
|
5
|
+
export declare const getTradeInfoFromActionRecord: (actionRecord: PartialUISerializableOrderActionRecord) => {
|
|
6
|
+
ts: BN;
|
|
7
|
+
baseAssetAmount: import("@drift-labs/sdk").BigNum;
|
|
8
|
+
baseAssetAmountFilled: import("@drift-labs/sdk").BigNum;
|
|
9
|
+
quoteAssetAmountFilled: import("@drift-labs/sdk").BigNum;
|
|
10
|
+
};
|
|
11
|
+
export declare const getAnchorEnumString: (enumVal: Record<string, unknown>) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAnchorEnumString = exports.getTradeInfoFromActionRecord = exports.orderIsNull = void 0;
|
|
4
|
+
const orderIsNull = (order, side) => {
|
|
5
|
+
return side === 'taker' ? !order.taker : !order.maker;
|
|
6
|
+
};
|
|
7
|
+
exports.orderIsNull = orderIsNull;
|
|
8
|
+
const getTradeInfoFromActionRecord = (actionRecord) => {
|
|
9
|
+
return {
|
|
10
|
+
ts: actionRecord.ts,
|
|
11
|
+
baseAssetAmount: actionRecord.taker
|
|
12
|
+
? actionRecord.takerOrderBaseAssetAmount
|
|
13
|
+
: actionRecord.makerOrderBaseAssetAmount,
|
|
14
|
+
baseAssetAmountFilled: actionRecord.taker
|
|
15
|
+
? actionRecord.takerOrderCumulativeBaseAssetAmountFilled
|
|
16
|
+
: actionRecord.makerOrderCumulativeBaseAssetAmountFilled,
|
|
17
|
+
quoteAssetAmountFilled: actionRecord.taker
|
|
18
|
+
? actionRecord.takerOrderCumulativeQuoteAssetAmountFilled
|
|
19
|
+
: actionRecord.makerOrderCumulativeQuoteAssetAmountFilled,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.getTradeInfoFromActionRecord = getTradeInfoFromActionRecord;
|
|
23
|
+
const getAnchorEnumString = (enumVal) => {
|
|
24
|
+
return Object.keys(enumVal)[0];
|
|
25
|
+
};
|
|
26
|
+
exports.getAnchorEnumString = getAnchorEnumString;
|
|
27
|
+
//# sourceMappingURL=misc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../../src/utils/orders/misc.ts"],"names":[],"mappings":";;;AAIO,MAAM,WAAW,GAAG,CAC1B,KAAiE,EACjE,IAAuB,EACtB,EAAE;IACH,OAAO,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;AACvD,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB;AAEK,MAAM,4BAA4B,GAAG,CAC3C,YAAoD,EACnD,EAAE;IACH,OAAO;QACN,EAAE,EAAE,YAAY,CAAC,EAAE;QACnB,eAAe,EAAE,YAAY,CAAC,KAAK;YAClC,CAAC,CAAC,YAAY,CAAC,yBAAyB;YACxC,CAAC,CAAC,YAAY,CAAC,yBAAyB;QACzC,qBAAqB,EAAE,YAAY,CAAC,KAAK;YACxC,CAAC,CAAC,YAAY,CAAC,yCAAyC;YACxD,CAAC,CAAC,YAAY,CAAC,yCAAyC;QACzD,sBAAsB,EAAE,YAAY,CAAC,KAAK;YACzC,CAAC,CAAC,YAAY,CAAC,0CAA0C;YACzD,CAAC,CAAC,YAAY,CAAC,0CAA0C;KAC1D,CAAC;AACH,CAAC,CAAC;AAfW,QAAA,4BAA4B,gCAevC;AAEK,MAAM,mBAAmB,GAAG,CAAC,OAAgC,EAAE,EAAE;IACvE,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["import { Event, OrderActionRecord } from '@drift-labs/sdk';\nimport { UISerializableOrderActionRecord } from '../../serializableTypes';\nimport { PartialUISerializableOrderActionRecord } from './sort';\n\nexport const orderIsNull = (\n\torder: UISerializableOrderActionRecord | Event<OrderActionRecord>,\n\tside: 'taker' | 'maker'\n) => {\n\treturn side === 'taker' ? !order.taker : !order.maker;\n};\n\nexport const getTradeInfoFromActionRecord = (\n\tactionRecord: PartialUISerializableOrderActionRecord\n) => {\n\treturn {\n\t\tts: actionRecord.ts,\n\t\tbaseAssetAmount: actionRecord.taker\n\t\t\t? actionRecord.takerOrderBaseAssetAmount\n\t\t\t: actionRecord.makerOrderBaseAssetAmount,\n\t\tbaseAssetAmountFilled: actionRecord.taker\n\t\t\t? actionRecord.takerOrderCumulativeBaseAssetAmountFilled\n\t\t\t: actionRecord.makerOrderCumulativeBaseAssetAmountFilled,\n\t\tquoteAssetAmountFilled: actionRecord.taker\n\t\t\t? actionRecord.takerOrderCumulativeQuoteAssetAmountFilled\n\t\t\t: actionRecord.makerOrderCumulativeQuoteAssetAmountFilled,\n\t};\n};\n\nexport const getAnchorEnumString = (enumVal: Record<string, unknown>) => {\n\treturn Object.keys(enumVal)[0];\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BigNum } from '@drift-labs/sdk';
|
|
2
|
+
import { AuctionParams } from '../../types';
|
|
3
|
+
import { UISerializableOrder } from '../../serializableTypes';
|
|
4
|
+
export declare const getLimitPriceFromOracleOffset: (order: UISerializableOrder, oraclePrice: BigNum) => BigNum;
|
|
5
|
+
export declare function isAuctionEmpty(auctionParams: AuctionParams): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAuctionEmpty = exports.getLimitPriceFromOracleOffset = void 0;
|
|
4
|
+
const trade_1 = require("../../constants/trade");
|
|
5
|
+
const getLimitPriceFromOracleOffset = (order, oraclePrice) => {
|
|
6
|
+
if ((order.price && !order.price.eqZero()) ||
|
|
7
|
+
!order.oraclePriceOffset ||
|
|
8
|
+
order.oraclePriceOffset.eqZero() ||
|
|
9
|
+
!oraclePrice ||
|
|
10
|
+
(oraclePrice === null || oraclePrice === void 0 ? void 0 : oraclePrice.eqZero())) {
|
|
11
|
+
return order.price;
|
|
12
|
+
}
|
|
13
|
+
return oraclePrice.add(order.oraclePriceOffset);
|
|
14
|
+
};
|
|
15
|
+
exports.getLimitPriceFromOracleOffset = getLimitPriceFromOracleOffset;
|
|
16
|
+
function isAuctionEmpty(auctionParams) {
|
|
17
|
+
return (auctionParams.auctionStartPrice ===
|
|
18
|
+
trade_1.EMPTY_AUCTION_PARAMS.auctionStartPrice &&
|
|
19
|
+
auctionParams.auctionEndPrice === trade_1.EMPTY_AUCTION_PARAMS.auctionEndPrice &&
|
|
20
|
+
auctionParams.auctionDuration === trade_1.EMPTY_AUCTION_PARAMS.auctionDuration);
|
|
21
|
+
}
|
|
22
|
+
exports.isAuctionEmpty = isAuctionEmpty;
|
|
23
|
+
//# sourceMappingURL=oracle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oracle.js","sourceRoot":"","sources":["../../../src/utils/orders/oracle.ts"],"names":[],"mappings":";;;AAEA,iDAA6D;AAGtD,MAAM,6BAA6B,GAAG,CAC5C,KAA0B,EAC1B,WAAmB,EACV,EAAE;IACX,IACC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACtC,CAAC,KAAK,CAAC,iBAAiB;QACxB,KAAK,CAAC,iBAAiB,CAAC,MAAM,EAAE;QAChC,CAAC,WAAW;SACZ,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,EAAE,CAAA,EACpB,CAAC;QACF,OAAO,KAAK,CAAC,KAAK,CAAC;IACpB,CAAC;IACD,OAAO,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACjD,CAAC,CAAC;AAdW,QAAA,6BAA6B,iCAcxC;AAEF,SAAgB,cAAc,CAAC,aAA4B;IAC1D,OAAO,CACN,aAAa,CAAC,iBAAiB;QAC9B,4BAAoB,CAAC,iBAAiB;QACvC,aAAa,CAAC,eAAe,KAAK,4BAAoB,CAAC,eAAe;QACtE,aAAa,CAAC,eAAe,KAAK,4BAAoB,CAAC,eAAe,CACtE,CAAC;AACH,CAAC;AAPD,wCAOC","sourcesContent":["import { BigNum } from '@drift-labs/sdk';\nimport { AuctionParams } from '../../types';\nimport { EMPTY_AUCTION_PARAMS } from '../../constants/trade';\nimport { UISerializableOrder } from '../../serializableTypes';\n\nexport const getLimitPriceFromOracleOffset = (\n\torder: UISerializableOrder,\n\toraclePrice: BigNum\n): BigNum => {\n\tif (\n\t\t(order.price && !order.price.eqZero()) ||\n\t\t!order.oraclePriceOffset ||\n\t\torder.oraclePriceOffset.eqZero() ||\n\t\t!oraclePrice ||\n\t\toraclePrice?.eqZero()\n\t) {\n\t\treturn order.price;\n\t}\n\treturn oraclePrice.add(order.oraclePriceOffset);\n};\n\nexport function isAuctionEmpty(auctionParams: AuctionParams) {\n\treturn (\n\t\tauctionParams.auctionStartPrice ===\n\t\t\tEMPTY_AUCTION_PARAMS.auctionStartPrice &&\n\t\tauctionParams.auctionEndPrice === EMPTY_AUCTION_PARAMS.auctionEndPrice &&\n\t\tauctionParams.auctionDuration === EMPTY_AUCTION_PARAMS.auctionDuration\n\t);\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Event, OrderActionRecord, OrderRecord } from '@drift-labs/sdk';
|
|
2
|
+
import { UIMatchedOrderRecordAndAction, UISerializableOrderActionRecord } from '../../serializableTypes';
|
|
3
|
+
export type PartialOrderActionRecord = PartialUISerializableOrderActionRecord | PartialOrderActionEventRecord;
|
|
4
|
+
export type PartialUISerializableOrderActionRecord = Pick<UISerializableOrderActionRecord, 'quoteAssetAmountFilled' | 'baseAssetAmountFilled' | 'ts' | 'slot' | 'action' | 'fillRecordId' | 'taker' | 'takerOrderBaseAssetAmount' | 'makerOrderBaseAssetAmount' | 'takerOrderCumulativeBaseAssetAmountFilled' | 'makerOrderCumulativeBaseAssetAmountFilled' | 'takerOrderCumulativeQuoteAssetAmountFilled' | 'makerOrderCumulativeQuoteAssetAmountFilled' | 'oraclePrice'>;
|
|
5
|
+
export type PartialOrderActionEventRecord = Pick<Event<OrderActionRecord>, 'quoteAssetAmountFilled' | 'baseAssetAmountFilled' | 'ts' | 'slot' | 'action' | 'fillRecordId' | 'taker' | 'takerOrderBaseAssetAmount' | 'makerOrderBaseAssetAmount' | 'takerOrderCumulativeBaseAssetAmountFilled' | 'makerOrderCumulativeBaseAssetAmountFilled' | 'takerOrderCumulativeQuoteAssetAmountFilled' | 'makerOrderCumulativeQuoteAssetAmountFilled'>;
|
|
6
|
+
/**
|
|
7
|
+
* Returns 1 if the first Order is chronologically later than the second Order, -1 if before, 0 if equal
|
|
8
|
+
* @param orderA
|
|
9
|
+
* @param orderB
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getSortScoreForOrderRecords: (orderA: {
|
|
13
|
+
slot: number;
|
|
14
|
+
}, orderB: {
|
|
15
|
+
slot: number;
|
|
16
|
+
}) => 1 | 0 | -1;
|
|
17
|
+
/**
|
|
18
|
+
* Returns 1 if the first Order is chronologically later than the second Order, -1 if before, 0 if equal
|
|
19
|
+
* @param orderA
|
|
20
|
+
* @param orderB
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare const getSortScoreForOrderActionRecords: (orderA: PartialOrderActionRecord, orderB: PartialOrderActionRecord) => 1 | 0 | -1;
|
|
24
|
+
export declare const sortUIMatchedOrderRecordAndAction: (records: UIMatchedOrderRecordAndAction[], direction?: 'asc' | 'desc') => UIMatchedOrderRecordAndAction[];
|
|
25
|
+
export declare const sortUIOrderActionRecords: (records: PartialUISerializableOrderActionRecord[], direction?: 'asc' | 'desc') => PartialUISerializableOrderActionRecord[];
|
|
26
|
+
export declare const sortUIOrderRecords: <T extends {
|
|
27
|
+
slot: number;
|
|
28
|
+
}>(records: T[], direction?: 'asc' | 'desc') => T[];
|
|
29
|
+
export declare const sortOrderRecords: (records: Event<OrderRecord>[], direction?: 'asc' | 'desc') => Event<OrderRecord>[];
|
|
30
|
+
export declare const getLatestOfTwoUIOrderRecords: <T extends {
|
|
31
|
+
slot: number;
|
|
32
|
+
}>(orderA: T, orderB: T) => T;
|
|
33
|
+
export declare const getLatestOfTwoOrderRecords: <T extends {
|
|
34
|
+
slot: number;
|
|
35
|
+
}>(orderA: T, orderB: T) => T;
|
|
36
|
+
export declare const getUIOrderRecordsLaterThanTarget: <T extends {
|
|
37
|
+
slot: number;
|
|
38
|
+
}>(target: T, records: T[]) => T[];
|