@drift-labs/common 1.0.58 → 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 +92 -5
- 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,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEvmChain = exports.getAddressFormatHint = exports.isValidAddressForChain = exports.SOLANA_CHAIN_ID = exports.TRON_CHAIN_ID = exports.BITCOIN_CHAIN_ID = exports.isValidPublicKey = exports.
|
|
3
|
+
exports.isEvmChain = exports.getAddressFormatHint = exports.isValidAddressForChain = exports.SOLANA_CHAIN_ID = exports.TRON_CHAIN_ID = exports.BITCOIN_CHAIN_ID = exports.isValidPublicKey = exports.isValidBase58 = void 0;
|
|
4
4
|
const sdk_1 = require("@drift-labs/sdk");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
exports.isNotionalDust = isNotionalDust;
|
|
5
|
+
var parse_1 = require("../strings/parse");
|
|
6
|
+
Object.defineProperty(exports, "isValidBase58", { enumerable: true, get: function () { return parse_1.isValidBase58; } });
|
|
9
7
|
const isValidPublicKey = (str) => {
|
|
10
8
|
try {
|
|
11
9
|
new sdk_1.PublicKey(str);
|
|
@@ -86,4 +84,4 @@ function isEvmChain(chainId) {
|
|
|
86
84
|
return !NON_EVM_CHAIN_IDS.has(chainId);
|
|
87
85
|
}
|
|
88
86
|
exports.isEvmChain = isEvmChain;
|
|
89
|
-
//# sourceMappingURL=
|
|
87
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/utils/validation/address.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAE5C,0CAAiD;AAAxC,sGAAA,aAAa,OAAA;AAEf,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAW,EAAE;IACxD,IAAI,CAAC;QACJ,IAAI,eAAS,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC,CAAC;AAPW,QAAA,gBAAgB,oBAO3B;AAEF,qBAAqB;AACR,QAAA,gBAAgB,GAAG,SAAS,CAAC;AAC7B,QAAA,aAAa,GAAG,WAAW,CAAC;AAC5B,QAAA,eAAe,GAAG,kBAAkB,CAAC;AAElD,oDAAoD;AACpD,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IACjC,wBAAgB;IAChB,qBAAa;IACb,uBAAe;CACf,CAAC,CAAC;AAEH,SAAS,iBAAiB,CAAC,OAAe;IACzC,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,qBAAqB,CAAC,OAAe;IAC7C,4BAA4B;IAC5B,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,+DAA+D,CAAC,IAAI,CAC1E,OAAO,CACP,CAAC;IACH,CAAC;IACD,mEAAmE;IACnE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAe;IAC1C,uDAAuD;IACvD,OAAO,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAe;IAC5C,OAAO,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CACrC,OAAe,EACf,OAAsB;IAEtB,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAEvC,IAAI,OAAO,KAAK,wBAAgB;QAAE,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACxE,IAAI,OAAO,KAAK,qBAAa;QAAE,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAClE,IAAI,OAAO,KAAK,uBAAe;QAAE,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAEtE,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAXD,wDAWC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,OAAsB;IAC1D,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,IAAI,OAAO,KAAK,wBAAgB;QAAE,OAAO,mCAAmC,CAAC;IAC7E,IAAI,OAAO,KAAK,qBAAa;QAAE,OAAO,oBAAoB,CAAC;IAC3D,IAAI,OAAO,KAAK,uBAAe;QAAE,OAAO,gBAAgB,CAAC;IACzD,OAAO,oBAAoB,CAAC;AAC7B,CAAC;AAND,oDAMC;AAED,SAAgB,UAAU,CAAC,OAAe;IACzC,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AAFD,gCAEC","sourcesContent":["import { PublicKey } from '@drift-labs/sdk';\n\nexport { isValidBase58 } from '../strings/parse';\n\nexport const isValidPublicKey = (str: string): boolean => {\n\ttry {\n\t\tnew PublicKey(str);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\n// Chain ID constants\nexport const BITCOIN_CHAIN_ID = '8253038';\nexport const TRON_CHAIN_ID = '728126428';\nexport const SOLANA_CHAIN_ID = '1151111081099710';\n\n// EVM chains (all others default to EVM validation)\nconst NON_EVM_CHAIN_IDS = new Set([\n\tBITCOIN_CHAIN_ID,\n\tTRON_CHAIN_ID,\n\tSOLANA_CHAIN_ID,\n]);\n\nfunction isValidEvmAddress(address: string): boolean {\n\treturn /^0x[0-9a-fA-F]{40}$/.test(address);\n}\n\nfunction isValidBitcoinAddress(address: string): boolean {\n\t// P2PKH (1...), P2SH (3...)\n\tif (/^[13]/.test(address)) {\n\t\treturn /^(1[1-9A-HJ-NP-Za-km-z]{25,34}|3[1-9A-HJ-NP-Za-km-z]{25,34})$/.test(\n\t\t\taddress\n\t\t);\n\t}\n\t// Bech32 — must be single-case (lowercase or uppercase, not mixed)\n\tif (/^bc1/.test(address)) {\n\t\treturn /^bc1[0-9a-z]{25,62}$/.test(address);\n\t}\n\tif (/^BC1/.test(address)) {\n\t\treturn /^BC1[0-9A-Z]{25,62}$/.test(address);\n\t}\n\treturn false;\n}\n\nfunction isValidTronAddress(address: string): boolean {\n\t// Tron addresses start with T and are 34 chars, base58\n\treturn /^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(address);\n}\n\nfunction isValidSolanaAddress(address: string): boolean {\n\treturn isValidPublicKey(address);\n}\n\n/**\n * Validates a recipient address based on the destination chain.\n * EVM chains use 0x-prefixed hex address format.\n * Bitcoin, Tron, and Solana each have their own format.\n */\nexport function isValidAddressForChain(\n\taddress: string,\n\tchainId: string | null\n): boolean {\n\tif (!address || !chainId) return false;\n\n\tif (chainId === BITCOIN_CHAIN_ID) return isValidBitcoinAddress(address);\n\tif (chainId === TRON_CHAIN_ID) return isValidTronAddress(address);\n\tif (chainId === SOLANA_CHAIN_ID) return isValidSolanaAddress(address);\n\n\treturn isValidEvmAddress(address);\n}\n\n/**\n * Returns a human-readable address format hint for the given chain.\n */\nexport function getAddressFormatHint(chainId: string | null): string {\n\tif (!chainId) return 'address';\n\tif (chainId === BITCOIN_CHAIN_ID) return 'Bitcoin address (1.., 3.., bc1..)';\n\tif (chainId === TRON_CHAIN_ID) return 'Tron address (T..)';\n\tif (chainId === SOLANA_CHAIN_ID) return 'Solana address';\n\treturn 'EVM address (0x..)';\n}\n\nexport function isEvmChain(chainId: string): boolean {\n\treturn !NON_EVM_CHAIN_IDS.has(chainId);\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./address"), exports);
|
|
18
|
+
__exportStar(require("./notional"), exports);
|
|
19
|
+
__exportStar(require("./input"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/validation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB","sourcesContent":["export * from './address';\nexport * from './notional';\nexport * from './input';\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTokenInputCurried = void 0;
|
|
4
|
+
const formatTokenInputCurried = (setAmount, spotMarketConfig) => (newAmount) => {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
if (isNaN(+newAmount))
|
|
7
|
+
return;
|
|
8
|
+
if (newAmount === '') {
|
|
9
|
+
setAmount('');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const lastChar = newAmount[newAmount.length - 1];
|
|
13
|
+
// if last char of string is a decimal point, don't format
|
|
14
|
+
if (lastChar === '.') {
|
|
15
|
+
setAmount(newAmount);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (lastChar === '0') {
|
|
19
|
+
// if last char of string is a zero in the decimal places, cut it off if it exceeds precision
|
|
20
|
+
const numOfDigitsAfterDecimal = (_b = (_a = newAmount.split('.')[1]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
21
|
+
if (numOfDigitsAfterDecimal > spotMarketConfig.precisionExp.toNumber()) {
|
|
22
|
+
setAmount(newAmount.slice(0, -1));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
setAmount(newAmount);
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const formattedAmount = Number((+newAmount).toFixed(spotMarketConfig.precisionExp.toNumber()));
|
|
30
|
+
setAmount(formattedAmount.toString());
|
|
31
|
+
};
|
|
32
|
+
exports.formatTokenInputCurried = formatTokenInputCurried;
|
|
33
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/utils/validation/input.ts"],"names":[],"mappings":";;;AAEA,MAAM,uBAAuB,GAC5B,CAAC,SAAmC,EAAE,gBAAkC,EAAE,EAAE,CAC5E,CAAC,SAAiB,EAAE,EAAE;;IACrB,IAAI,KAAK,CAAC,CAAC,SAAS,CAAC;QAAE,OAAO;IAE9B,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QACtB,SAAS,CAAC,EAAE,CAAC,CAAC;QACd,OAAO;IACR,CAAC;IAED,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEjD,0DAA0D;IAC1D,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QACtB,SAAS,CAAC,SAAS,CAAC,CAAC;QACrB,OAAO;IACR,CAAC;IAED,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QACtB,6FAA6F;QAC7F,MAAM,uBAAuB,GAAG,MAAA,MAAA,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,0CAAE,MAAM,mCAAI,CAAC,CAAC;QACrE,IAAI,uBAAuB,GAAG,gBAAgB,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC;YACxE,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACP,SAAS,CAAC,SAAS,CAAC,CAAC;QACtB,CAAC;QACD,OAAO;IACR,CAAC;IAED,MAAM,eAAe,GAAG,MAAM,CAC7B,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAC9D,CAAC;IACF,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvC,CAAC,CAAC;AAEM,0DAAuB","sourcesContent":["import { SpotMarketConfig } from '@drift-labs/sdk';\n\nconst formatTokenInputCurried =\n\t(setAmount: (amount: string) => void, spotMarketConfig: SpotMarketConfig) =>\n\t(newAmount: string) => {\n\t\tif (isNaN(+newAmount)) return;\n\n\t\tif (newAmount === '') {\n\t\t\tsetAmount('');\n\t\t\treturn;\n\t\t}\n\n\t\tconst lastChar = newAmount[newAmount.length - 1];\n\n\t\t// if last char of string is a decimal point, don't format\n\t\tif (lastChar === '.') {\n\t\t\tsetAmount(newAmount);\n\t\t\treturn;\n\t\t}\n\n\t\tif (lastChar === '0') {\n\t\t\t// if last char of string is a zero in the decimal places, cut it off if it exceeds precision\n\t\t\tconst numOfDigitsAfterDecimal = newAmount.split('.')[1]?.length ?? 0;\n\t\t\tif (numOfDigitsAfterDecimal > spotMarketConfig.precisionExp.toNumber()) {\n\t\t\t\tsetAmount(newAmount.slice(0, -1));\n\t\t\t} else {\n\t\t\t\tsetAmount(newAmount);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst formattedAmount = Number(\n\t\t\t(+newAmount).toFixed(spotMarketConfig.precisionExp.toNumber())\n\t\t);\n\t\tsetAmount(formattedAmount.toString());\n\t};\n\nexport { formatTokenInputCurried };\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNotionalDust = void 0;
|
|
4
|
+
const isNotionalDust = (val) => {
|
|
5
|
+
return !val.eqZero() && val.abs().toNum() < 0.01;
|
|
6
|
+
};
|
|
7
|
+
exports.isNotionalDust = isNotionalDust;
|
|
8
|
+
//# sourceMappingURL=notional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notional.js","sourceRoot":"","sources":["../../../src/utils/validation/notional.ts"],"names":[],"mappings":";;;AAEO,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE;IAC7C,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC;AAClD,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB","sourcesContent":["import { BigNum } from '@drift-labs/sdk';\n\nexport const isNotionalDust = (val: BigNum) => {\n\treturn !val.eqZero() && val.abs().toNum() < 0.01;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"description": "Common functions for Drift",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"author": "Drift Labs",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@drift-labs/sdk": "^2.
|
|
20
|
+
"@drift-labs/sdk": "^2.161.0-beta.4",
|
|
21
21
|
"@solana/spl-token": "^0.4.14",
|
|
22
22
|
"@solana/web3.js": "1.98.0",
|
|
23
23
|
"bcryptjs-react": "2.4.6",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"tweetnacl": "1.0.3"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@drift-labs/sdk": "^2.
|
|
35
|
+
"@drift-labs/sdk": "^2.161.0-beta.4",
|
|
36
36
|
"@solana/web3.js": "1.98.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
@@ -59,8 +59,95 @@
|
|
|
59
59
|
"lib": "lib"
|
|
60
60
|
},
|
|
61
61
|
"exports": {
|
|
62
|
-
".":
|
|
63
|
-
|
|
62
|
+
".": {
|
|
63
|
+
"types": "./lib/index.d.ts",
|
|
64
|
+
"default": "./lib/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./clients": {
|
|
67
|
+
"types": "./lib/clients/index.d.ts",
|
|
68
|
+
"default": "./lib/clients/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./utils/math": {
|
|
71
|
+
"types": "./lib/utils/math/index.d.ts",
|
|
72
|
+
"default": "./lib/utils/math/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./utils/strings": {
|
|
75
|
+
"types": "./lib/utils/strings/index.d.ts",
|
|
76
|
+
"default": "./lib/utils/strings/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./utils/enum": {
|
|
79
|
+
"types": "./lib/utils/enum/index.d.ts",
|
|
80
|
+
"default": "./lib/utils/enum/index.js"
|
|
81
|
+
},
|
|
82
|
+
"./utils/validation": {
|
|
83
|
+
"types": "./lib/utils/validation/index.d.ts",
|
|
84
|
+
"default": "./lib/utils/validation/index.js"
|
|
85
|
+
},
|
|
86
|
+
"./utils/token": {
|
|
87
|
+
"types": "./lib/utils/token/index.d.ts",
|
|
88
|
+
"default": "./lib/utils/token/index.js"
|
|
89
|
+
},
|
|
90
|
+
"./utils/trading": {
|
|
91
|
+
"types": "./lib/utils/trading/index.d.ts",
|
|
92
|
+
"default": "./lib/utils/trading/index.js"
|
|
93
|
+
},
|
|
94
|
+
"./utils/markets": {
|
|
95
|
+
"types": "./lib/utils/markets/index.d.ts",
|
|
96
|
+
"default": "./lib/utils/markets/index.js"
|
|
97
|
+
},
|
|
98
|
+
"./utils/orders": {
|
|
99
|
+
"types": "./lib/utils/orders/index.d.ts",
|
|
100
|
+
"default": "./lib/utils/orders/index.js"
|
|
101
|
+
},
|
|
102
|
+
"./utils/positions": {
|
|
103
|
+
"types": "./lib/utils/positions/index.d.ts",
|
|
104
|
+
"default": "./lib/utils/positions/index.js"
|
|
105
|
+
},
|
|
106
|
+
"./utils/accounts": {
|
|
107
|
+
"types": "./lib/utils/accounts/index.d.ts",
|
|
108
|
+
"default": "./lib/utils/accounts/index.js"
|
|
109
|
+
},
|
|
110
|
+
"./utils/core": {
|
|
111
|
+
"types": "./lib/utils/core/index.d.ts",
|
|
112
|
+
"default": "./lib/utils/core/index.js"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"typesVersions": {
|
|
116
|
+
"*": {
|
|
117
|
+
"utils/math": [
|
|
118
|
+
"lib/utils/math/index.d.ts"
|
|
119
|
+
],
|
|
120
|
+
"utils/strings": [
|
|
121
|
+
"lib/utils/strings/index.d.ts"
|
|
122
|
+
],
|
|
123
|
+
"utils/enum": [
|
|
124
|
+
"lib/utils/enum/index.d.ts"
|
|
125
|
+
],
|
|
126
|
+
"utils/validation": [
|
|
127
|
+
"lib/utils/validation/index.d.ts"
|
|
128
|
+
],
|
|
129
|
+
"utils/token": [
|
|
130
|
+
"lib/utils/token/index.d.ts"
|
|
131
|
+
],
|
|
132
|
+
"utils/trading": [
|
|
133
|
+
"lib/utils/trading/index.d.ts"
|
|
134
|
+
],
|
|
135
|
+
"utils/markets": [
|
|
136
|
+
"lib/utils/markets/index.d.ts"
|
|
137
|
+
],
|
|
138
|
+
"utils/orders": [
|
|
139
|
+
"lib/utils/orders/index.d.ts"
|
|
140
|
+
],
|
|
141
|
+
"utils/positions": [
|
|
142
|
+
"lib/utils/positions/index.d.ts"
|
|
143
|
+
],
|
|
144
|
+
"utils/accounts": [
|
|
145
|
+
"lib/utils/accounts/index.d.ts"
|
|
146
|
+
],
|
|
147
|
+
"utils/core": [
|
|
148
|
+
"lib/utils/core/index.d.ts"
|
|
149
|
+
]
|
|
150
|
+
}
|
|
64
151
|
},
|
|
65
152
|
"files": [
|
|
66
153
|
"lib"
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { BN, BigNum, DriftClient, IWalletV2, MarketType, OptionalOrderParams, OrderType, PositionDirection, PublicKey, SpotMarketConfig, User, UserAccount } from '@drift-labs/sdk';
|
|
4
|
-
import { AccountInfo, Connection, ParsedAccountData } from '@solana/web3.js';
|
|
5
|
-
import { AuctionParams, TradeOffsetPrice } from 'src/types';
|
|
6
|
-
export declare const abbreviateAddress: (address: string | PublicKey, length?: number) => string;
|
|
7
|
-
declare function chunks<T>(array: T[], size: number): T[][];
|
|
8
|
-
export declare const COMMON_UI_UTILS: {
|
|
9
|
-
getOrderLabelFromOrderDetails: (orderDetails: Pick<import("..").UISerializableOrder, "orderType" | "direction" | "triggerCondition" | "oraclePriceOffset" | "existingPositionDirection">) => string;
|
|
10
|
-
getLimitPriceFromOracleOffset: (order: import("..").UISerializableOrder, oraclePrice: BigNum) => BigNum;
|
|
11
|
-
isAuctionEmpty: (auctionParams: AuctionParams) => boolean;
|
|
12
|
-
getUIOrderTypeFromSdkOrderType: (orderType: OrderType, triggerCondition: import("@drift-labs/sdk").OrderTriggerCondition, direction: PositionDirection, oracleOffset: BigNum) => import("src/types").UIOrderTypeValue;
|
|
13
|
-
getPerpAuctionDuration: (priceDiff: BN, price: BN, contractTier: import("@drift-labs/sdk").ContractTier) => number;
|
|
14
|
-
getPerpOrderParamsBitFlags: (marketIndex: number, driftClient: DriftClient, userAccount: User, attemptedLeverage: number, highLeverageOptions?: {
|
|
15
|
-
numOfOpenHighLeverageSpots?: number;
|
|
16
|
-
}) => number;
|
|
17
|
-
isOrderTriggered: (order: Pick<import("..").UISerializableOrder, "status" | "orderType" | "triggerCondition">) => boolean;
|
|
18
|
-
getBaseAssetSymbol: (marketName: string, removePrefix?: boolean) => string;
|
|
19
|
-
getPausedOperations: (marketAccount: import("@drift-labs/sdk").SpotMarketAccount | import("@drift-labs/sdk").PerpMarketAccount) => string[];
|
|
20
|
-
PerpOperationsMap: {
|
|
21
|
-
UPDATE_FUNDING: string;
|
|
22
|
-
AMM_FILL: string;
|
|
23
|
-
FILL: string;
|
|
24
|
-
SETTLE_PNL: string;
|
|
25
|
-
SETTLE_PNL_WITH_POSITION: string;
|
|
26
|
-
};
|
|
27
|
-
SpotOperationsMap: {
|
|
28
|
-
UPDATE_CUMULATIVE_INTEREST: string;
|
|
29
|
-
FILL: string;
|
|
30
|
-
WITHDRAW: string;
|
|
31
|
-
};
|
|
32
|
-
InsuranceFundOperationsMap: {
|
|
33
|
-
INIT: string;
|
|
34
|
-
ADD: string;
|
|
35
|
-
REQUEST_REMOVE: string;
|
|
36
|
-
REMOVE: string;
|
|
37
|
-
};
|
|
38
|
-
getMarketConfig: {
|
|
39
|
-
(driftEnv: import("@drift-labs/sdk").DriftEnv, marketType: {
|
|
40
|
-
perp: {};
|
|
41
|
-
}, marketIndex: number): import("@drift-labs/sdk").PerpMarketConfig;
|
|
42
|
-
(driftEnv: import("@drift-labs/sdk").DriftEnv, marketType: {
|
|
43
|
-
spot: {};
|
|
44
|
-
}, marketIndex: number): SpotMarketConfig;
|
|
45
|
-
};
|
|
46
|
-
getMaxLeverageForMarket: (marketType: MarketType, marketIndex: number, driftClient: DriftClient) => {
|
|
47
|
-
maxLeverage: number;
|
|
48
|
-
highLeverageMaxLeverage: number;
|
|
49
|
-
hasHighLeverage: boolean;
|
|
50
|
-
};
|
|
51
|
-
getMaxLeverageForMarketAccount: (marketType: MarketType, marketAccount: import("@drift-labs/sdk").SpotMarketAccount | import("@drift-labs/sdk").PerpMarketAccount) => {
|
|
52
|
-
maxLeverage: number;
|
|
53
|
-
highLeverageMaxLeverage: number;
|
|
54
|
-
hasHighLeverage: boolean;
|
|
55
|
-
};
|
|
56
|
-
calculatePnlPctFromPosition: (pnl: BN, position: import("src/types").OpenPosition, marginUsed?: BN) => number;
|
|
57
|
-
calculatePotentialProfit: (props: {
|
|
58
|
-
currentPositionSize: BigNum;
|
|
59
|
-
currentPositionDirection: PositionDirection;
|
|
60
|
-
currentPositionEntryPrice: BigNum;
|
|
61
|
-
tradeDirection: PositionDirection;
|
|
62
|
-
exitBaseSize: BigNum;
|
|
63
|
-
exitPrice: BigNum;
|
|
64
|
-
takerFeeBps: number;
|
|
65
|
-
slippageTolerance?: number;
|
|
66
|
-
isMarketOrder?: boolean;
|
|
67
|
-
}) => {
|
|
68
|
-
estimatedProfit: BigNum;
|
|
69
|
-
estimatedProfitBeforeFees: BigNum;
|
|
70
|
-
estimatedTakerFee: BigNum;
|
|
71
|
-
notionalSizeAtEntry: BigNum;
|
|
72
|
-
notionalSizeAtExit: BigNum;
|
|
73
|
-
};
|
|
74
|
-
calculateLiquidationPriceAfterPerpTrade: ({ estEntryPrice, orderType, perpMarketIndex, tradeBaseSize, isLong, userClient, oraclePrice, limitPrice, offsetCollateral, precision, isEnteringHighLeverageMode, capLiqPrice, marginType, }: {
|
|
75
|
-
estEntryPrice: BN;
|
|
76
|
-
orderType: import("src/types").UIOrderType;
|
|
77
|
-
perpMarketIndex: number;
|
|
78
|
-
tradeBaseSize: BN;
|
|
79
|
-
isLong: boolean;
|
|
80
|
-
userClient: User;
|
|
81
|
-
oraclePrice: BN;
|
|
82
|
-
limitPrice?: BN;
|
|
83
|
-
offsetCollateral?: BN;
|
|
84
|
-
precision?: number;
|
|
85
|
-
isEnteringHighLeverageMode?: boolean;
|
|
86
|
-
capLiqPrice?: boolean;
|
|
87
|
-
marginType?: "Cross" | "Isolated";
|
|
88
|
-
}) => number;
|
|
89
|
-
checkIsMarketOrderType: (orderType: import("src/types").UIOrderType) => boolean;
|
|
90
|
-
convertLeverageToMarginRatio: (leverage: number) => number;
|
|
91
|
-
convertMarginRatioToLeverage: (marginRatio: number, decimals?: number) => number;
|
|
92
|
-
getMarketTickSize: (driftClient: DriftClient, marketId: import("src/types").MarketId) => BN;
|
|
93
|
-
getMarketTickSizeDecimals: (driftClient: DriftClient, marketId: import("src/types").MarketId) => number;
|
|
94
|
-
getMarketStepSize: (driftClient: DriftClient, marketId: import("src/types").MarketId) => BN;
|
|
95
|
-
getMarketStepSizeDecimals: (driftClient: DriftClient, marketId: import("src/types").MarketId) => number;
|
|
96
|
-
isEntirePositionOrder: (orderAmount: BigNum) => boolean;
|
|
97
|
-
getMaxLeverageOrderSize: (orderAmount: BigNum) => BigNum;
|
|
98
|
-
formatOrderSize: (orderAmount: BigNum, formatFn?: (amount: BigNum) => string) => string;
|
|
99
|
-
getMarginUsedForPosition: (user: User, marketIndex: number, includeOpenOrders?: boolean) => any;
|
|
100
|
-
validateLeverageChange: ({ user, marketIndex, newLeverage, }: {
|
|
101
|
-
user: User;
|
|
102
|
-
marketIndex: number;
|
|
103
|
-
newLeverage: number;
|
|
104
|
-
}) => boolean;
|
|
105
|
-
getOpenPositionData: (driftClient: DriftClient, userPositions: import("@drift-labs/sdk").PerpPosition[], user: User, perpMarketLookup: import("@drift-labs/sdk").PerpMarketConfig[], markPriceCallback?: (marketIndex: number) => BN) => import("src/types").OpenPosition[];
|
|
106
|
-
checkIfUserAccountExists: (driftClient: DriftClient, config: {
|
|
107
|
-
type: "userPubKey";
|
|
108
|
-
userPubKey: PublicKey;
|
|
109
|
-
} | {
|
|
110
|
-
type: "subAccountId";
|
|
111
|
-
subAccountId: number;
|
|
112
|
-
authority: PublicKey;
|
|
113
|
-
}) => Promise<boolean>;
|
|
114
|
-
getUserMaxLeverageForMarket: (user: User, marketIndex: number, marketLeverageDetails: {
|
|
115
|
-
regularMaxLeverage: number;
|
|
116
|
-
highLeverageMaxLeverage: number;
|
|
117
|
-
hasHighLeverage: boolean;
|
|
118
|
-
}, uiSavedMaxLeverage?: number) => number;
|
|
119
|
-
abbreviateAddress: (address: string | PublicKey, length?: number) => string;
|
|
120
|
-
calculateAverageEntryPrice: (quoteAssetAmount: BigNum, baseAssetAmount: BigNum) => BigNum;
|
|
121
|
-
chunks: typeof chunks;
|
|
122
|
-
compareSignatures: (original: string, hashed: string) => Promise<boolean>;
|
|
123
|
-
createPlaceholderIWallet: (walletPubKey?: PublicKey) => IWalletV2;
|
|
124
|
-
deriveMarketOrderParams: ({ marketType, marketIndex, direction, maxLeverageSelected, maxLeverageOrderSize, baseAmount, reduceOnly, allowInfSlippage, oraclePrice, bestPrice, entryPrice, worstPrice, markPrice, auctionDuration, auctionStartPriceOffset, auctionEndPriceOffset, auctionStartPriceOffsetFrom, auctionEndPriceOffsetFrom, auctionPriceCaps, slippageTolerance, isOracleOrder, additionalEndPriceBuffer, forceUpToSlippage, bestBidPrice, bestAskPrice, ensureCrossingEndPrice, }: {
|
|
125
|
-
marketType: MarketType;
|
|
126
|
-
marketIndex: number;
|
|
127
|
-
direction: PositionDirection;
|
|
128
|
-
maxLeverageSelected: boolean;
|
|
129
|
-
maxLeverageOrderSize: BN;
|
|
130
|
-
baseAmount: BN;
|
|
131
|
-
reduceOnly: boolean;
|
|
132
|
-
allowInfSlippage: boolean;
|
|
133
|
-
oraclePrice: BN;
|
|
134
|
-
bestPrice: BN;
|
|
135
|
-
entryPrice: BN;
|
|
136
|
-
worstPrice: BN;
|
|
137
|
-
markPrice: BN;
|
|
138
|
-
auctionDuration: number;
|
|
139
|
-
auctionStartPriceOffset: number;
|
|
140
|
-
auctionEndPriceOffset: number;
|
|
141
|
-
auctionPriceCaps?: {
|
|
142
|
-
min: BN;
|
|
143
|
-
max: BN;
|
|
144
|
-
};
|
|
145
|
-
auctionStartPriceOffsetFrom: TradeOffsetPrice;
|
|
146
|
-
auctionEndPriceOffsetFrom: TradeOffsetPrice;
|
|
147
|
-
slippageTolerance: number;
|
|
148
|
-
isOracleOrder?: boolean;
|
|
149
|
-
additionalEndPriceBuffer?: BN;
|
|
150
|
-
forceUpToSlippage?: boolean;
|
|
151
|
-
bestBidPrice?: BN;
|
|
152
|
-
bestAskPrice?: BN;
|
|
153
|
-
ensureCrossingEndPrice?: boolean;
|
|
154
|
-
}) => OptionalOrderParams & {
|
|
155
|
-
constrainedBySlippage?: boolean;
|
|
156
|
-
};
|
|
157
|
-
fetchCurrentSubaccounts: (driftClient: DriftClient) => UserAccount[];
|
|
158
|
-
fetchUserClientsAndAccounts: (driftClient: DriftClient) => {
|
|
159
|
-
user: User;
|
|
160
|
-
userAccount: UserAccount;
|
|
161
|
-
}[];
|
|
162
|
-
formatTokenInputCurried: (setAmount: (amount: string) => void, spotMarketConfig: SpotMarketConfig) => (newAmount: string) => void;
|
|
163
|
-
getBalanceFromTokenAccountResult: (account: {
|
|
164
|
-
pubkey: PublicKey;
|
|
165
|
-
account: AccountInfo<ParsedAccountData>;
|
|
166
|
-
}) => any;
|
|
167
|
-
getIdAndAuthorityFromKey: (key: string) => {
|
|
168
|
-
userId: number;
|
|
169
|
-
userAuthority: PublicKey;
|
|
170
|
-
} | {
|
|
171
|
-
userId: undefined;
|
|
172
|
-
userAuthority: undefined;
|
|
173
|
-
};
|
|
174
|
-
getLimitAuctionParams: ({ direction, inputPrice, startPriceFromSettings, duration, auctionStartPriceOffset, oraclePriceBands, }: {
|
|
175
|
-
direction: PositionDirection;
|
|
176
|
-
inputPrice: BigNum;
|
|
177
|
-
startPriceFromSettings: BN;
|
|
178
|
-
duration: number;
|
|
179
|
-
auctionStartPriceOffset: number;
|
|
180
|
-
oraclePriceBands?: [BN, BN];
|
|
181
|
-
}) => AuctionParams;
|
|
182
|
-
getLpSharesAmountForQuote: (driftClient: DriftClient, marketIndex: number, quoteAmount: BN) => BigNum;
|
|
183
|
-
getMarketAuctionParams: ({ direction, startPriceFromSettings, endPriceFromSettings, limitPrice, duration, auctionStartPriceOffset, auctionEndPriceOffset, additionalEndPriceBuffer, forceUpToSlippage, bestBidPrice, bestAskPrice, ensureCrossingEndPrice, }: {
|
|
184
|
-
direction: PositionDirection;
|
|
185
|
-
startPriceFromSettings: BN;
|
|
186
|
-
endPriceFromSettings: BN;
|
|
187
|
-
/**
|
|
188
|
-
* Limit price is the oracle limit price - market orders use the oracle order type under the hood on Drift UI
|
|
189
|
-
* So oracle limit price is the oracle price + oracle offset
|
|
190
|
-
*/
|
|
191
|
-
limitPrice: BN;
|
|
192
|
-
duration: number;
|
|
193
|
-
auctionStartPriceOffset: number;
|
|
194
|
-
auctionEndPriceOffset: number;
|
|
195
|
-
additionalEndPriceBuffer?: BN;
|
|
196
|
-
forceUpToSlippage?: boolean;
|
|
197
|
-
bestBidPrice?: BN;
|
|
198
|
-
bestAskPrice?: BN;
|
|
199
|
-
ensureCrossingEndPrice?: boolean;
|
|
200
|
-
}) => AuctionParams;
|
|
201
|
-
getMarketKey: (marketIndex: number, marketType: MarketType) => string;
|
|
202
|
-
getMarketOrderLimitPrice: ({ direction, baselinePrice, slippageTolerance, }: {
|
|
203
|
-
direction: PositionDirection;
|
|
204
|
-
baselinePrice: BN;
|
|
205
|
-
slippageTolerance: number;
|
|
206
|
-
}) => BN;
|
|
207
|
-
getMultipleAccounts: (connection: any, keys: string[], commitment: string) => Promise<{
|
|
208
|
-
keys: string[];
|
|
209
|
-
array: AccountInfo<Buffer>[];
|
|
210
|
-
}>;
|
|
211
|
-
getMultipleAccountsCore: (connection: any, keys: string[], commitment: string) => Promise<{
|
|
212
|
-
keys: string[];
|
|
213
|
-
array: AccountInfo<string[]>[];
|
|
214
|
-
}>;
|
|
215
|
-
getPriceObject: ({ oraclePrice, bestOffer, entryPrice, worstPrice, markPrice, direction, }: {
|
|
216
|
-
oraclePrice: BN;
|
|
217
|
-
bestOffer: BN;
|
|
218
|
-
entryPrice: BN;
|
|
219
|
-
worstPrice: BN;
|
|
220
|
-
markPrice: BN;
|
|
221
|
-
direction: PositionDirection;
|
|
222
|
-
}) => {
|
|
223
|
-
oracle: BN;
|
|
224
|
-
bestOffer: BN;
|
|
225
|
-
entry: BN;
|
|
226
|
-
best: BN;
|
|
227
|
-
worst: BN;
|
|
228
|
-
mark: BN;
|
|
229
|
-
};
|
|
230
|
-
getQuoteValueForLpShares: (driftClient: DriftClient, marketIndex: number, sharesAmount: BN) => BigNum;
|
|
231
|
-
getSignatureVerificationMessageForSettings: (authority: PublicKey, signTs: number) => Uint8Array;
|
|
232
|
-
getTokenAccount: (connection: Connection, mintAddress: PublicKey, userPubKey: PublicKey) => Promise<{
|
|
233
|
-
tokenAccount: {
|
|
234
|
-
pubkey: PublicKey;
|
|
235
|
-
account: import('@solana/web3.js').AccountInfo<import('@solana/web3.js').ParsedAccountData>;
|
|
236
|
-
};
|
|
237
|
-
tokenAccountWarning: boolean;
|
|
238
|
-
}>;
|
|
239
|
-
getTokenAddress: (mintAddress: PublicKey, userPubKey: PublicKey) => Promise<PublicKey>;
|
|
240
|
-
getUserKey: (userId: number, authority: PublicKey) => string;
|
|
241
|
-
hashSignature: (signature: string) => Promise<string>;
|
|
242
|
-
initializeAndSubscribeToNewUserAccount: (driftClient: DriftClient, userIdToInit: number, authority: PublicKey, callbacks: {
|
|
243
|
-
initializationStep: () => Promise<boolean>;
|
|
244
|
-
postInitializationStep?: () => Promise<boolean>;
|
|
245
|
-
handleSuccessStep?: (accountAlreadyExisted: boolean) => Promise<boolean>;
|
|
246
|
-
}) => Promise<'ok' | 'failed_initializationStep' | 'failed_postInitializationStep' | 'failed_awaitAccountInitializationChainState' | 'failed_handleSuccessStep'>;
|
|
247
|
-
userExists: (driftClient: DriftClient, userId: number, authority: PublicKey) => Promise<boolean>;
|
|
248
|
-
verifySignature: (signature: Uint8Array, message: Uint8Array, pubKey: PublicKey) => boolean;
|
|
249
|
-
trimTrailingZeros: (str: string, zerosToShow?: number) => string;
|
|
250
|
-
};
|
|
251
|
-
export {};
|