@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.
Files changed (282) hide show
  1. package/lib/_deprecated/common-math.d.ts +10 -0
  2. package/lib/_deprecated/common-math.js +9 -0
  3. package/lib/_deprecated/common-math.js.map +1 -0
  4. package/lib/_deprecated/common-ui-utils.d.ts +248 -0
  5. package/lib/_deprecated/common-ui-utils.js +59 -0
  6. package/lib/_deprecated/common-ui-utils.js.map +1 -0
  7. package/lib/_deprecated/equality-checks.d.ts +2 -0
  8. package/lib/_deprecated/equality-checks.js +7 -0
  9. package/lib/_deprecated/equality-checks.js.map +1 -0
  10. package/lib/{common-ui-utils/market.d.ts → _deprecated/market-utils.d.ts} +5 -7
  11. package/lib/_deprecated/market-utils.js +18 -0
  12. package/lib/_deprecated/market-utils.js.map +1 -0
  13. package/lib/_deprecated/order-utils.d.ts +12 -0
  14. package/lib/_deprecated/order-utils.js +18 -0
  15. package/lib/_deprecated/order-utils.js.map +1 -0
  16. package/lib/_deprecated/trading-utils.d.ts +52 -0
  17. package/lib/_deprecated/trading-utils.js +27 -0
  18. package/lib/_deprecated/trading-utils.js.map +1 -0
  19. package/lib/_deprecated/user-utils.d.ts +17 -0
  20. package/lib/_deprecated/user-utils.js +12 -0
  21. package/lib/_deprecated/user-utils.js.map +1 -0
  22. package/lib/_deprecated/utils.d.ts +40 -0
  23. package/lib/_deprecated/utils.js +47 -0
  24. package/lib/_deprecated/utils.js.map +1 -0
  25. package/lib/clients/tvFeed.js +2 -2
  26. package/lib/clients/tvFeed.js.map +1 -1
  27. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js +8 -8
  28. package/lib/drift/Drift/clients/AuthorityDrift/DriftOperations/index.js.map +1 -1
  29. package/lib/drift/Drift/clients/AuthorityDrift/index.js +9 -9
  30. package/lib/drift/Drift/clients/AuthorityDrift/index.js.map +1 -1
  31. package/lib/drift/Drift/clients/CentralServerDrift/index.js +2 -2
  32. package/lib/drift/Drift/clients/CentralServerDrift/index.js.map +1 -1
  33. package/lib/drift/base/actions/trade/editOrder.d.ts +1 -1
  34. package/lib/drift/base/actions/trade/editOrder.js.map +1 -1
  35. package/lib/drift/base/actions/trade/margin.js +4 -4
  36. package/lib/drift/base/actions/trade/margin.js.map +1 -1
  37. package/lib/drift/base/actions/trade/openPerpOrder/auction.d.ts +1 -1
  38. package/lib/drift/base/actions/trade/openPerpOrder/auction.js +4 -3
  39. package/lib/drift/base/actions/trade/openPerpOrder/auction.js.map +1 -1
  40. package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js +2 -2
  41. package/lib/drift/base/actions/trade/openPerpOrder/dlobServer/index.js.map +1 -1
  42. package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js +2 -2
  43. package/lib/drift/base/actions/trade/openPerpOrder/isolatedPositionDeposit.js.map +1 -1
  44. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.d.ts +1 -1
  45. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js +4 -4
  46. package/lib/drift/base/actions/trade/openPerpOrder/openPerpMarketOrder/index.js.map +1 -1
  47. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.d.ts +1 -1
  48. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js +2 -2
  49. package/lib/drift/base/actions/trade/openPerpOrder/openPerpNonMarketOrder/index.js.map +1 -1
  50. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js +4 -3
  51. package/lib/drift/base/actions/trade/openPerpOrder/openSwiftOrder/index.js.map +1 -1
  52. package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js +2 -2
  53. package/lib/drift/base/actions/trade/openPerpOrder/positionMaxLeverage.js.map +1 -1
  54. package/lib/drift/base/actions/user/create.js +2 -2
  55. package/lib/drift/base/actions/user/create.js.map +1 -1
  56. package/lib/drift/base/details/user/balances.js +2 -2
  57. package/lib/drift/base/details/user/balances.js.map +1 -1
  58. package/lib/drift/base/details/user/positions.js +2 -2
  59. package/lib/drift/base/details/user/positions.js.map +1 -1
  60. package/lib/index.d.ts +28 -28
  61. package/lib/index.js +44 -29
  62. package/lib/index.js.map +1 -1
  63. package/lib/utils/accounts/index.d.ts +6 -0
  64. package/lib/utils/accounts/index.js +23 -0
  65. package/lib/utils/accounts/index.js.map +1 -0
  66. package/lib/utils/accounts/init.d.ts +22 -0
  67. package/lib/utils/accounts/init.js +90 -0
  68. package/lib/utils/accounts/init.js.map +1 -0
  69. package/lib/utils/accounts/keys.d.ts +22 -0
  70. package/lib/utils/accounts/keys.js +36 -0
  71. package/lib/utils/accounts/keys.js.map +1 -0
  72. package/lib/utils/accounts/multiple.d.ts +14 -0
  73. package/lib/utils/accounts/multiple.js +45 -0
  74. package/lib/utils/accounts/multiple.js.map +1 -0
  75. package/lib/utils/accounts/signature.d.ts +6 -0
  76. package/lib/utils/accounts/signature.js +53 -0
  77. package/lib/utils/accounts/signature.js.map +1 -0
  78. package/lib/utils/accounts/subaccounts.d.ts +8 -0
  79. package/lib/utils/accounts/subaccounts.js +31 -0
  80. package/lib/utils/accounts/subaccounts.js.map +1 -0
  81. package/lib/utils/{WalletConnectionState.d.ts → accounts/wallet.d.ts} +7 -1
  82. package/lib/utils/{WalletConnectionState.js → accounts/wallet.js} +32 -2
  83. package/lib/utils/accounts/wallet.js.map +1 -0
  84. package/lib/utils/core/arrays.d.ts +2 -0
  85. package/lib/utils/core/arrays.js +25 -0
  86. package/lib/utils/core/arrays.js.map +1 -0
  87. package/lib/utils/core/async.d.ts +5 -0
  88. package/lib/utils/core/async.js +17 -0
  89. package/lib/utils/core/async.js.map +1 -0
  90. package/lib/utils/core/cache.d.ts +1 -0
  91. package/lib/utils/core/cache.js +40 -0
  92. package/lib/utils/core/cache.js.map +1 -0
  93. package/lib/utils/core/data-structures.d.ts +30 -0
  94. package/lib/utils/core/data-structures.js +84 -0
  95. package/lib/utils/core/data-structures.js.map +1 -0
  96. package/lib/utils/{equalityChecks.d.ts → core/equality.d.ts} +1 -1
  97. package/lib/utils/{equalityChecks.js → core/equality.js} +3 -3
  98. package/lib/utils/core/equality.js.map +1 -0
  99. package/lib/utils/core/fetch.js.map +1 -0
  100. package/lib/utils/core/index.d.ts +7 -0
  101. package/lib/utils/core/index.js +24 -0
  102. package/lib/utils/core/index.js.map +1 -0
  103. package/lib/utils/core/serialization.d.ts +30 -0
  104. package/lib/utils/core/serialization.js +92 -0
  105. package/lib/utils/core/serialization.js.map +1 -0
  106. package/lib/utils/{enum.js → enum/index.js} +1 -1
  107. package/lib/utils/enum/index.js.map +1 -0
  108. package/lib/utils/index.d.ts +11 -176
  109. package/lib/utils/index.js +25 -594
  110. package/lib/utils/index.js.map +1 -1
  111. package/lib/utils/markets/balances.d.ts +6 -0
  112. package/lib/utils/markets/balances.js +29 -0
  113. package/lib/utils/markets/balances.js.map +1 -0
  114. package/lib/utils/markets/config.d.ts +5 -0
  115. package/lib/utils/markets/config.js +24 -0
  116. package/lib/utils/markets/config.js.map +1 -0
  117. package/lib/utils/markets/index.d.ts +6 -0
  118. package/lib/utils/markets/index.js +23 -0
  119. package/lib/utils/markets/index.js.map +1 -0
  120. package/lib/utils/markets/interest.d.ts +25 -0
  121. package/lib/utils/markets/interest.js +65 -0
  122. package/lib/utils/markets/interest.js.map +1 -0
  123. package/lib/utils/markets/leverage.d.ts +12 -0
  124. package/lib/utils/markets/leverage.js +60 -0
  125. package/lib/utils/markets/leverage.js.map +1 -0
  126. package/lib/utils/markets/operations.d.ts +21 -0
  127. package/lib/utils/markets/operations.js +59 -0
  128. package/lib/utils/markets/operations.js.map +1 -0
  129. package/lib/utils/math/bignum.d.ts +3 -0
  130. package/lib/utils/math/bignum.js +16 -0
  131. package/lib/utils/math/bignum.js.map +1 -0
  132. package/lib/utils/math/bn.d.ts +7 -0
  133. package/lib/utils/math/bn.js +58 -0
  134. package/lib/utils/math/bn.js.map +1 -0
  135. package/lib/utils/math/index.d.ts +7 -0
  136. package/lib/utils/math/index.js +24 -0
  137. package/lib/utils/math/index.js.map +1 -0
  138. package/lib/utils/math/numbers.d.ts +13 -0
  139. package/lib/utils/math/numbers.js +56 -0
  140. package/lib/utils/math/numbers.js.map +1 -0
  141. package/lib/utils/math/precision.d.ts +19 -0
  142. package/lib/utils/math/precision.js +73 -0
  143. package/lib/utils/math/precision.js.map +1 -0
  144. package/lib/utils/math/price.d.ts +12 -0
  145. package/lib/utils/math/price.js +45 -0
  146. package/lib/utils/math/price.js.map +1 -0
  147. package/lib/utils/math/sort.d.ts +13 -0
  148. package/lib/utils/math/sort.js +33 -0
  149. package/lib/utils/math/sort.js.map +1 -0
  150. package/lib/utils/math/spread.d.ts +8 -0
  151. package/lib/utils/math/spread.js +87 -0
  152. package/lib/utils/math/spread.js.map +1 -0
  153. package/lib/utils/orderbook/index.js +4 -4
  154. package/lib/utils/orderbook/index.js.map +1 -1
  155. package/lib/utils/orders/filters.d.ts +7 -0
  156. package/lib/utils/orders/filters.js +31 -0
  157. package/lib/utils/orders/filters.js.map +1 -0
  158. package/lib/utils/orders/flags.d.ts +12 -0
  159. package/lib/utils/orders/flags.js +44 -0
  160. package/lib/utils/orders/flags.js.map +1 -0
  161. package/lib/utils/orders/index.d.ts +6 -0
  162. package/lib/utils/orders/index.js +23 -0
  163. package/lib/utils/orders/index.js.map +1 -0
  164. package/lib/utils/orders/labels.d.ts +4 -0
  165. package/lib/utils/orders/labels.js +122 -0
  166. package/lib/utils/orders/labels.js.map +1 -0
  167. package/lib/utils/orders/misc.d.ts +11 -0
  168. package/lib/utils/orders/misc.js +27 -0
  169. package/lib/utils/orders/misc.js.map +1 -0
  170. package/lib/utils/orders/oracle.d.ts +5 -0
  171. package/lib/utils/orders/oracle.js +23 -0
  172. package/lib/utils/orders/oracle.js.map +1 -0
  173. package/lib/utils/orders/sort.d.ts +38 -0
  174. package/lib/utils/orders/sort.js +83 -0
  175. package/lib/utils/orders/sort.js.map +1 -0
  176. package/lib/utils/positions/index.d.ts +2 -0
  177. package/lib/{common-ui-utils → utils/positions}/index.js +1 -5
  178. package/lib/utils/positions/index.js.map +1 -0
  179. package/lib/utils/positions/open.d.ts +4 -0
  180. package/lib/{common-ui-utils/user.js → utils/positions/open.js} +10 -81
  181. package/lib/utils/positions/open.js.map +1 -0
  182. package/lib/utils/positions/user.d.ts +37 -0
  183. package/lib/utils/positions/user.js +74 -0
  184. package/lib/utils/positions/user.js.map +1 -0
  185. package/lib/utils/settings/settings.js.map +1 -0
  186. package/lib/utils/strings/convert.d.ts +11 -0
  187. package/lib/utils/{strings.js → strings/convert.js} +2 -51
  188. package/lib/utils/strings/convert.js.map +1 -0
  189. package/lib/utils/strings/format.d.ts +14 -0
  190. package/lib/utils/strings/format.js +61 -0
  191. package/lib/utils/strings/format.js.map +1 -0
  192. package/lib/utils/strings/index.d.ts +4 -0
  193. package/lib/utils/strings/index.js +21 -0
  194. package/lib/utils/strings/index.js.map +1 -0
  195. package/lib/utils/strings/parse.d.ts +4 -0
  196. package/lib/utils/strings/parse.js +25 -0
  197. package/lib/utils/strings/parse.js.map +1 -0
  198. package/lib/utils/strings/status.d.ts +15 -0
  199. package/lib/utils/strings/status.js +21 -0
  200. package/lib/utils/strings/status.js.map +1 -0
  201. package/lib/utils/token/account.d.ts +16 -0
  202. package/lib/utils/token/account.js +36 -0
  203. package/lib/utils/token/account.js.map +1 -0
  204. package/lib/utils/{token.d.ts → token/address.d.ts} +2 -7
  205. package/lib/utils/token/address.js +30 -0
  206. package/lib/utils/token/address.js.map +1 -0
  207. package/lib/utils/token/index.d.ts +3 -0
  208. package/lib/utils/token/index.js +20 -0
  209. package/lib/utils/token/index.js.map +1 -0
  210. package/lib/utils/token/instructions.d.ts +3 -0
  211. package/lib/utils/token/instructions.js +17 -0
  212. package/lib/utils/token/instructions.js.map +1 -0
  213. package/lib/utils/trading/auction.d.ts +82 -0
  214. package/lib/utils/trading/auction.js +208 -0
  215. package/lib/utils/trading/auction.js.map +1 -0
  216. package/lib/utils/trading/index.d.ts +7 -0
  217. package/lib/utils/trading/index.js +24 -0
  218. package/lib/utils/trading/index.js.map +1 -0
  219. package/lib/utils/trading/leverage.d.ts +18 -0
  220. package/lib/utils/trading/leverage.js +79 -0
  221. package/lib/utils/trading/leverage.js.map +1 -0
  222. package/lib/utils/trading/liquidation.d.ts +22 -0
  223. package/lib/utils/trading/liquidation.js +67 -0
  224. package/lib/utils/trading/liquidation.js.map +1 -0
  225. package/lib/utils/trading/lp.d.ts +4 -0
  226. package/lib/utils/trading/lp.js +20 -0
  227. package/lib/utils/trading/lp.js.map +1 -0
  228. package/lib/utils/trading/pnl.d.ts +34 -0
  229. package/lib/utils/trading/pnl.js +88 -0
  230. package/lib/utils/trading/pnl.js.map +1 -0
  231. package/lib/utils/trading/price.d.ts +12 -0
  232. package/lib/utils/trading/price.js +36 -0
  233. package/lib/utils/trading/price.js.map +1 -0
  234. package/lib/utils/trading/size.d.ts +27 -0
  235. package/lib/utils/trading/size.js +83 -0
  236. package/lib/utils/trading/size.js.map +1 -0
  237. package/lib/utils/{validation.d.ts → validation/address.d.ts} +1 -2
  238. package/lib/utils/{validation.js → validation/address.js} +4 -6
  239. package/lib/utils/validation/address.js.map +1 -0
  240. package/lib/utils/validation/index.d.ts +3 -0
  241. package/lib/utils/validation/index.js +20 -0
  242. package/lib/utils/validation/index.js.map +1 -0
  243. package/lib/utils/validation/input.d.ts +3 -0
  244. package/lib/utils/validation/input.js +33 -0
  245. package/lib/utils/validation/input.js.map +1 -0
  246. package/lib/utils/validation/notional.d.ts +2 -0
  247. package/lib/utils/validation/notional.js +8 -0
  248. package/lib/utils/validation/notional.js.map +1 -0
  249. package/package.json +90 -3
  250. package/lib/common-ui-utils/commonUiUtils.d.ts +0 -251
  251. package/lib/common-ui-utils/commonUiUtils.js +0 -647
  252. package/lib/common-ui-utils/commonUiUtils.js.map +0 -1
  253. package/lib/common-ui-utils/index.d.ts +0 -6
  254. package/lib/common-ui-utils/index.js.map +0 -1
  255. package/lib/common-ui-utils/market.js +0 -134
  256. package/lib/common-ui-utils/market.js.map +0 -1
  257. package/lib/common-ui-utils/order.d.ts +0 -25
  258. package/lib/common-ui-utils/order.js +0 -191
  259. package/lib/common-ui-utils/order.js.map +0 -1
  260. package/lib/common-ui-utils/settings/settings.js.map +0 -1
  261. package/lib/common-ui-utils/trading.d.ts +0 -79
  262. package/lib/common-ui-utils/trading.js +0 -313
  263. package/lib/common-ui-utils/trading.js.map +0 -1
  264. package/lib/common-ui-utils/user.d.ts +0 -18
  265. package/lib/common-ui-utils/user.js.map +0 -1
  266. package/lib/utils/WalletConnectionState.js.map +0 -1
  267. package/lib/utils/enum.js.map +0 -1
  268. package/lib/utils/equalityChecks.js.map +0 -1
  269. package/lib/utils/fetch.js.map +0 -1
  270. package/lib/utils/math.d.ts +0 -31
  271. package/lib/utils/math.js +0 -181
  272. package/lib/utils/math.js.map +0 -1
  273. package/lib/utils/strings.d.ts +0 -34
  274. package/lib/utils/strings.js.map +0 -1
  275. package/lib/utils/token.js +0 -45
  276. package/lib/utils/token.js.map +0 -1
  277. package/lib/utils/validation.js.map +0 -1
  278. /package/lib/utils/{fetch.d.ts → core/fetch.d.ts} +0 -0
  279. /package/lib/utils/{fetch.js → core/fetch.js} +0 -0
  280. /package/lib/utils/{enum.d.ts → enum/index.d.ts} +0 -0
  281. /package/lib/{common-ui-utils → utils}/settings/settings.d.ts +0 -0
  282. /package/lib/{common-ui-utils → utils}/settings/settings.js +0 -0
@@ -0,0 +1,21 @@
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("./convert"), exports);
18
+ __exportStar(require("./format"), exports);
19
+ __exportStar(require("./parse"), exports);
20
+ __exportStar(require("./status"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/strings/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB","sourcesContent":["export * from './convert';\nexport * from './format';\nexport * from './parse';\nexport * from './status';\n"]}
@@ -0,0 +1,4 @@
1
+ export declare const isValidBase58: (str: string) => boolean;
2
+ export declare function splitByCapitalLetters(word: string): string;
3
+ export declare function lowerCaseNonFirstWords(sentence: string): string;
4
+ export declare const disallowNegativeStringInput: (str: string) => string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.disallowNegativeStringInput = exports.lowerCaseNonFirstWords = exports.splitByCapitalLetters = exports.isValidBase58 = void 0;
4
+ const isValidBase58 = (str) => /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(str);
5
+ exports.isValidBase58 = isValidBase58;
6
+ function splitByCapitalLetters(word) {
7
+ return word.replace(/([A-Z])/g, ' $1').trim();
8
+ }
9
+ exports.splitByCapitalLetters = splitByCapitalLetters;
10
+ function lowerCaseNonFirstWords(sentence) {
11
+ const words = sentence.split(' ');
12
+ for (let i = 1; i < words.length; i++) {
13
+ words[i] = words[i].toLowerCase();
14
+ }
15
+ return words.join(' ');
16
+ }
17
+ exports.lowerCaseNonFirstWords = lowerCaseNonFirstWords;
18
+ const disallowNegativeStringInput = (str) => {
19
+ if (str && str.charAt(0) === '-') {
20
+ return '0';
21
+ }
22
+ return str;
23
+ };
24
+ exports.disallowNegativeStringInput = disallowNegativeStringInput;
25
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/utils/strings/parse.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,EAAE,CAC5C,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAD9B,QAAA,aAAa,iBACiB;AAE3C,SAAgB,qBAAqB,CAAC,IAAY;IACjD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AAC/C,CAAC;AAFD,sDAEC;AAED,SAAgB,sBAAsB,CAAC,QAAgB;IACtD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAND,wDAMC;AAEM,MAAM,2BAA2B,GAAG,CAAC,GAAW,EAAU,EAAE;IAClE,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QAClC,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC;AALW,QAAA,2BAA2B,+BAKtC","sourcesContent":["export const isValidBase58 = (str: string) =>\n\t/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(str);\n\nexport function splitByCapitalLetters(word: string) {\n\treturn word.replace(/([A-Z])/g, ' $1').trim();\n}\n\nexport function lowerCaseNonFirstWords(sentence: string): string {\n\tconst words = sentence.split(' ');\n\tfor (let i = 1; i < words.length; i++) {\n\t\twords[i] = words[i].toLowerCase();\n\t}\n\treturn words.join(' ');\n}\n\nexport const disallowNegativeStringInput = (str: string): string => {\n\tif (str && str.charAt(0) === '-') {\n\t\treturn '0';\n\t}\n\treturn str;\n};\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * LastOrder status types from https://github.com/drift-labs/infrastructure-v3/blob/8ab1888eaaaed96228406b562d4a399729d042d7/packages/common/src/types/index.ts#L221
3
+ */
4
+ export declare const LAST_ORDER_STATUS_LABELS: {
5
+ readonly open: "Open";
6
+ readonly filled: "Filled";
7
+ readonly partial_fill: "Partially Filled";
8
+ readonly cancelled: "Canceled";
9
+ readonly partial_fill_cancelled: "Partially Filled & Canceled";
10
+ readonly expired: "Expired";
11
+ readonly trigger: "Triggered";
12
+ };
13
+ export type LastOrderStatus = keyof typeof LAST_ORDER_STATUS_LABELS;
14
+ export type LastOrderStatusLabel = (typeof LAST_ORDER_STATUS_LABELS)[LastOrderStatus];
15
+ export declare function lastOrderStatusToNormalEng(status: string): LastOrderStatusLabel | string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lastOrderStatusToNormalEng = exports.LAST_ORDER_STATUS_LABELS = void 0;
4
+ /**
5
+ * LastOrder status types from https://github.com/drift-labs/infrastructure-v3/blob/8ab1888eaaaed96228406b562d4a399729d042d7/packages/common/src/types/index.ts#L221
6
+ */
7
+ exports.LAST_ORDER_STATUS_LABELS = {
8
+ open: 'Open',
9
+ filled: 'Filled',
10
+ partial_fill: 'Partially Filled',
11
+ cancelled: 'Canceled',
12
+ partial_fill_cancelled: 'Partially Filled & Canceled',
13
+ expired: 'Expired',
14
+ trigger: 'Triggered',
15
+ };
16
+ function lastOrderStatusToNormalEng(status) {
17
+ var _a;
18
+ return (_a = exports.LAST_ORDER_STATUS_LABELS[status]) !== null && _a !== void 0 ? _a : status;
19
+ }
20
+ exports.lastOrderStatusToNormalEng = lastOrderStatusToNormalEng;
21
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/utils/strings/status.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,wBAAwB,GAAG;IACvC,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,YAAY,EAAE,kBAAkB;IAChC,SAAS,EAAE,UAAU;IACrB,sBAAsB,EAAE,6BAA6B;IACrD,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,WAAW;CACX,CAAC;AAKX,SAAgB,0BAA0B,CACzC,MAAc;;IAEd,OAAO,MAAA,gCAAwB,CAAC,MAAyB,CAAC,mCAAI,MAAM,CAAC;AACtE,CAAC;AAJD,gEAIC","sourcesContent":["/**\n * LastOrder status types from https://github.com/drift-labs/infrastructure-v3/blob/8ab1888eaaaed96228406b562d4a399729d042d7/packages/common/src/types/index.ts#L221\n */\nexport const LAST_ORDER_STATUS_LABELS = {\n\topen: 'Open',\n\tfilled: 'Filled',\n\tpartial_fill: 'Partially Filled',\n\tcancelled: 'Canceled',\n\tpartial_fill_cancelled: 'Partially Filled & Canceled',\n\texpired: 'Expired',\n\ttrigger: 'Triggered',\n} as const;\nexport type LastOrderStatus = keyof typeof LAST_ORDER_STATUS_LABELS;\nexport type LastOrderStatusLabel =\n\t(typeof LAST_ORDER_STATUS_LABELS)[LastOrderStatus];\n\nexport function lastOrderStatusToNormalEng(\n\tstatus: string\n): LastOrderStatusLabel | string {\n\treturn LAST_ORDER_STATUS_LABELS[status as LastOrderStatus] ?? status;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { AccountInfo, Connection, ParsedAccountData, PublicKey } from '@solana/web3.js';
2
+ export declare const getTokenAccount: (connection: Connection, mintAddress: string, userPubKey: string) => Promise<{
3
+ pubkey: PublicKey;
4
+ account: AccountInfo<ParsedAccountData>;
5
+ }>;
6
+ export declare const getBalanceFromTokenAccountResult: (account: {
7
+ pubkey: PublicKey;
8
+ account: AccountInfo<ParsedAccountData>;
9
+ }) => any;
10
+ export declare const getTokenAccountWithWarning: (connection: Connection, mintAddress: PublicKey, userPubKey: PublicKey) => Promise<{
11
+ tokenAccount: {
12
+ pubkey: PublicKey;
13
+ account: AccountInfo<ParsedAccountData>;
14
+ };
15
+ tokenAccountWarning: boolean;
16
+ }>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTokenAccountWithWarning = exports.getBalanceFromTokenAccountResult = exports.getTokenAccount = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const getTokenAccount = async (connection, mintAddress, userPubKey) => {
7
+ const tokenAccounts = await connection.getParsedTokenAccountsByOwner(new web3_js_1.PublicKey(userPubKey), { mint: new web3_js_1.PublicKey(mintAddress) });
8
+ const associatedAddress = await (0, spl_token_1.getAssociatedTokenAddress)(new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey), true);
9
+ const targetAccount = tokenAccounts.value.filter((account) => account.pubkey.equals(associatedAddress))[0] || tokenAccounts.value[0];
10
+ return targetAccount;
11
+ };
12
+ exports.getTokenAccount = getTokenAccount;
13
+ const getBalanceFromTokenAccountResult = (account) => {
14
+ var _a, _b, _c, _d;
15
+ return (_d = (_c = (_b = (_a = account === null || account === void 0 ? void 0 : account.account.data) === null || _a === void 0 ? void 0 : _a.parsed) === null || _b === void 0 ? void 0 : _b.info) === null || _c === void 0 ? void 0 : _c.tokenAmount) === null || _d === void 0 ? void 0 : _d.uiAmount;
16
+ };
17
+ exports.getBalanceFromTokenAccountResult = getBalanceFromTokenAccountResult;
18
+ const getTokenAccountWithWarning = async (connection, mintAddress, userPubKey) => {
19
+ const tokenAccounts = await connection.getParsedTokenAccountsByOwner(userPubKey, { mint: mintAddress });
20
+ const associatedAddress = await (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, userPubKey, true);
21
+ const targetAccount = tokenAccounts.value.filter((account) => account.pubkey.equals(associatedAddress))[0] || tokenAccounts.value[0];
22
+ const anotherBalanceExists = tokenAccounts.value.find((account) => {
23
+ return (!!(0, exports.getBalanceFromTokenAccountResult)(account) &&
24
+ !account.pubkey.equals(targetAccount.pubkey));
25
+ });
26
+ let tokenAccountWarning = false;
27
+ if (anotherBalanceExists) {
28
+ tokenAccountWarning = true;
29
+ }
30
+ return {
31
+ tokenAccount: targetAccount,
32
+ tokenAccountWarning,
33
+ };
34
+ };
35
+ exports.getTokenAccountWithWarning = getTokenAccountWithWarning;
36
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/utils/token/account.ts"],"names":[],"mappings":";;;AAAA,iDAA8D;AAC9D,6CAKyB;AAElB,MAAM,eAAe,GAAG,KAAK,EACnC,UAAsB,EACtB,WAAmB,EACnB,UAAkB,EAIhB,EAAE;IACJ,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,6BAA6B,CACnE,IAAI,mBAAS,CAAC,UAAU,CAAC,EACzB,EAAE,IAAI,EAAE,IAAI,mBAAS,CAAC,WAAW,CAAC,EAAE,CACpC,CAAC;IAEF,MAAM,iBAAiB,GAAG,MAAM,IAAA,qCAAyB,EACxD,IAAI,mBAAS,CAAC,WAAW,CAAC,EAC1B,IAAI,mBAAS,CAAC,UAAU,CAAC,EACzB,IAAI,CACJ,CAAC;IAEF,MAAM,aAAa,GAClB,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CACtC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CACxC,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEhC,OAAO,aAAa,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KACnB,CAAC;AACH,CAAC,CAAC;AA5CW,QAAA,0BAA0B,8BA4CrC","sourcesContent":["import { getAssociatedTokenAddress } from '@solana/spl-token';\nimport {\n\tAccountInfo,\n\tConnection,\n\tParsedAccountData,\n\tPublicKey,\n} from '@solana/web3.js';\n\nexport const getTokenAccount = async (\n\tconnection: Connection,\n\tmintAddress: string,\n\tuserPubKey: string\n): Promise<{\n\tpubkey: PublicKey;\n\taccount: AccountInfo<ParsedAccountData>;\n}> => {\n\tconst tokenAccounts = await connection.getParsedTokenAccountsByOwner(\n\t\tnew PublicKey(userPubKey),\n\t\t{ mint: new PublicKey(mintAddress) }\n\t);\n\n\tconst associatedAddress = await getAssociatedTokenAddress(\n\t\tnew PublicKey(mintAddress),\n\t\tnew PublicKey(userPubKey),\n\t\ttrue\n\t);\n\n\tconst targetAccount =\n\t\ttokenAccounts.value.filter((account) =>\n\t\t\taccount.pubkey.equals(associatedAddress)\n\t\t)[0] || tokenAccounts.value[0];\n\n\treturn targetAccount;\n};\n\nexport const getBalanceFromTokenAccountResult = (account: {\n\tpubkey: PublicKey;\n\taccount: AccountInfo<ParsedAccountData>;\n}) => {\n\treturn account?.account.data?.parsed?.info?.tokenAmount?.uiAmount;\n};\n\nexport const getTokenAccountWithWarning = async (\n\tconnection: Connection,\n\tmintAddress: PublicKey,\n\tuserPubKey: PublicKey\n): Promise<{\n\ttokenAccount: {\n\t\tpubkey: PublicKey;\n\t\taccount: AccountInfo<ParsedAccountData>;\n\t};\n\ttokenAccountWarning: boolean;\n}> => {\n\tconst tokenAccounts = await connection.getParsedTokenAccountsByOwner(\n\t\tuserPubKey,\n\t\t{ mint: mintAddress }\n\t);\n\n\tconst associatedAddress = await getAssociatedTokenAddress(\n\t\tmintAddress,\n\t\tuserPubKey,\n\t\ttrue\n\t);\n\n\tconst targetAccount =\n\t\ttokenAccounts.value.filter((account) =>\n\t\t\taccount.pubkey.equals(associatedAddress)\n\t\t)[0] || tokenAccounts.value[0];\n\n\tconst anotherBalanceExists = tokenAccounts.value.find((account) => {\n\t\treturn (\n\t\t\t!!getBalanceFromTokenAccountResult(account) &&\n\t\t\t!account.pubkey.equals(targetAccount.pubkey)\n\t\t);\n\t});\n\n\tlet tokenAccountWarning = false;\n\n\tif (anotherBalanceExists) {\n\t\ttokenAccountWarning = true;\n\t}\n\n\treturn {\n\t\ttokenAccount: targetAccount,\n\t\ttokenAccountWarning,\n\t};\n};\n"]}
@@ -1,7 +1,7 @@
1
1
  import { SpotMarketAccount } from '@drift-labs/sdk';
2
- import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
3
- export { TOKEN_PROGRAM_ID, createTransferCheckedInstruction, } from '@solana/spl-token';
2
+ import { PublicKey } from '@solana/web3.js';
4
3
  export declare const getTokenAddress: (mintAddress: string, userPubKey: string) => Promise<PublicKey>;
4
+ export declare const getTokenAddressFromPublicKeys: (mintAddress: PublicKey, userPubKey: PublicKey) => Promise<PublicKey>;
5
5
  /**
6
6
  * Get the associated token address for the given spot market and authority. If the mint is SOL, return the authority public key.
7
7
  * This should be used for spot token movement in and out of the user's wallet.
@@ -11,8 +11,3 @@ export declare const getTokenAddress: (mintAddress: string, userPubKey: string)
11
11
  * @returns The associated token address
12
12
  */
13
13
  export declare const getTokenAddressForDepositAndWithdraw: (spotMarketAccount: SpotMarketAccount, authority: PublicKey) => Promise<PublicKey>;
14
- export declare const getTokenAccount: (connection: Connection, mintAddress: string, userPubKey: string) => Promise<{
15
- pubkey: PublicKey;
16
- account: import('@solana/web3.js').AccountInfo<import('@solana/web3.js').ParsedAccountData>;
17
- }>;
18
- export declare const createTokenAccountIx: (owner: PublicKey, mintAddress: PublicKey, payer?: PublicKey) => Promise<TransactionInstruction>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTokenAddressForDepositAndWithdraw = exports.getTokenAddressFromPublicKeys = exports.getTokenAddress = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ const spl_token_1 = require("@solana/spl-token");
6
+ const web3_js_1 = require("@solana/web3.js");
7
+ const getTokenAddress = (mintAddress, userPubKey) => {
8
+ return (0, spl_token_1.getAssociatedTokenAddress)(new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey), true);
9
+ };
10
+ exports.getTokenAddress = getTokenAddress;
11
+ const getTokenAddressFromPublicKeys = (mintAddress, userPubKey) => {
12
+ return (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, userPubKey, true);
13
+ };
14
+ exports.getTokenAddressFromPublicKeys = getTokenAddressFromPublicKeys;
15
+ /**
16
+ * Get the associated token address for the given spot market and authority. If the mint is SOL, return the authority public key.
17
+ * This should be used for spot token movement in and out of the user's wallet.
18
+ * Automatically resolves the correct token program (TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID) from the spot market account.
19
+ * @param spotMarketAccount - The spot market account
20
+ * @param authority - The authority's public key
21
+ * @returns The associated token address
22
+ */
23
+ const getTokenAddressForDepositAndWithdraw = async (spotMarketAccount, authority) => {
24
+ const isSol = spotMarketAccount.mint.equals(sdk_1.WRAPPED_SOL_MINT);
25
+ if (isSol)
26
+ return authority;
27
+ return (0, spl_token_1.getAssociatedTokenAddress)(spotMarketAccount.mint, authority, true, (0, sdk_1.getTokenProgramForSpotMarket)(spotMarketAccount));
28
+ };
29
+ exports.getTokenAddressForDepositAndWithdraw = getTokenAddressForDepositAndWithdraw;
30
+ //# sourceMappingURL=address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/utils/token/address.ts"],"names":[],"mappings":";;;AAAA,yCAIyB;AACzB,iDAA8D;AAC9D,6CAA4C;AAErC,MAAM,eAAe,GAAG,CAC9B,WAAmB,EACnB,UAAkB,EACG,EAAE;IACvB,OAAO,IAAA,qCAAyB,EAC/B,IAAI,mBAAS,CAAC,WAAW,CAAC,EAC1B,IAAI,mBAAS,CAAC,UAAU,CAAC,EACzB,IAAI,CACJ,CAAC;AACH,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B;AAEK,MAAM,6BAA6B,GAAG,CAC5C,WAAsB,EACtB,UAAqB,EACA,EAAE;IACvB,OAAO,IAAA,qCAAyB,EAAC,WAAW,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC,CAAC;AALW,QAAA,6BAA6B,iCAKxC;AAEF;;;;;;;GAOG;AACI,MAAM,oCAAoC,GAAG,KAAK,EACxD,iBAAoC,EACpC,SAAoB,EACC,EAAE;IACvB,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAgB,CAAC,CAAC;IAE9D,IAAI,KAAK;QAAE,OAAO,SAAS,CAAC;IAE5B,OAAO,IAAA,qCAAyB,EAC/B,iBAAiB,CAAC,IAAI,EACtB,SAAS,EACT,IAAI,EACJ,IAAA,kCAA4B,EAAC,iBAAiB,CAAC,CAC/C,CAAC;AACH,CAAC,CAAC;AAdW,QAAA,oCAAoC,wCAc/C","sourcesContent":["import {\n\tSpotMarketAccount,\n\tWRAPPED_SOL_MINT,\n\tgetTokenProgramForSpotMarket,\n} from '@drift-labs/sdk';\nimport { getAssociatedTokenAddress } from '@solana/spl-token';\nimport { PublicKey } from '@solana/web3.js';\n\nexport const getTokenAddress = (\n\tmintAddress: string,\n\tuserPubKey: string\n): Promise<PublicKey> => {\n\treturn getAssociatedTokenAddress(\n\t\tnew PublicKey(mintAddress),\n\t\tnew PublicKey(userPubKey),\n\t\ttrue\n\t);\n};\n\nexport const getTokenAddressFromPublicKeys = (\n\tmintAddress: PublicKey,\n\tuserPubKey: PublicKey\n): Promise<PublicKey> => {\n\treturn getAssociatedTokenAddress(mintAddress, userPubKey, true);\n};\n\n/**\n * Get the associated token address for the given spot market and authority. If the mint is SOL, return the authority public key.\n * This should be used for spot token movement in and out of the user's wallet.\n * Automatically resolves the correct token program (TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID) from the spot market account.\n * @param spotMarketAccount - The spot market account\n * @param authority - The authority's public key\n * @returns The associated token address\n */\nexport const getTokenAddressForDepositAndWithdraw = async (\n\tspotMarketAccount: SpotMarketAccount,\n\tauthority: PublicKey\n): Promise<PublicKey> => {\n\tconst isSol = spotMarketAccount.mint.equals(WRAPPED_SOL_MINT);\n\n\tif (isSol) return authority;\n\n\treturn getAssociatedTokenAddress(\n\t\tspotMarketAccount.mint,\n\t\tauthority,\n\t\ttrue,\n\t\tgetTokenProgramForSpotMarket(spotMarketAccount)\n\t);\n};\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './address';
2
+ export * from './account';
3
+ export * from './instructions';
@@ -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("./account"), exports);
19
+ __exportStar(require("./instructions"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,iDAA+B","sourcesContent":["export * from './address';\nexport * from './account';\nexport * from './instructions';\n"]}
@@ -0,0 +1,3 @@
1
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+ export { TOKEN_PROGRAM_ID, createTransferCheckedInstruction, } from '@solana/spl-token';
3
+ export declare const createTokenAccountIx: (owner: PublicKey, mintAddress: PublicKey, payer?: PublicKey) => Promise<TransactionInstruction>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTokenAccountIx = exports.createTransferCheckedInstruction = exports.TOKEN_PROGRAM_ID = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ var spl_token_2 = require("@solana/spl-token");
6
+ Object.defineProperty(exports, "TOKEN_PROGRAM_ID", { enumerable: true, get: function () { return spl_token_2.TOKEN_PROGRAM_ID; } });
7
+ Object.defineProperty(exports, "createTransferCheckedInstruction", { enumerable: true, get: function () { return spl_token_2.createTransferCheckedInstruction; } });
8
+ const createTokenAccountIx = async (owner, mintAddress, payer) => {
9
+ if (!payer) {
10
+ payer = owner;
11
+ }
12
+ const associatedAddress = await (0, spl_token_1.getAssociatedTokenAddress)(mintAddress, owner, true);
13
+ const createAtaIx = await (0, spl_token_1.createAssociatedTokenAccountInstruction)(payer, associatedAddress, owner, mintAddress);
14
+ return createAtaIx;
15
+ };
16
+ exports.createTokenAccountIx = createTokenAccountIx;
17
+ //# sourceMappingURL=instructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../../src/utils/token/instructions.ts"],"names":[],"mappings":";;;AAAA,iDAG2B;AAG3B,+CAG2B;AAF1B,6GAAA,gBAAgB,OAAA;AAChB,6HAAA,gCAAgC,OAAA;AAG1B,MAAM,oBAAoB,GAAG,KAAK,EACxC,KAAgB,EAChB,WAAsB,EACtB,KAAiB,EACiB,EAAE;IACpC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,KAAK,GAAG,KAAK,CAAC;IACf,CAAC;IAED,MAAM,iBAAiB,GAAG,MAAM,IAAA,qCAAyB,EACxD,WAAW,EACX,KAAK,EACL,IAAI,CACJ,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,IAAA,mDAAuC,EAChE,KAAK,EACL,iBAAiB,EACjB,KAAK,EACL,WAAW,CACX,CAAC;IAEF,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AAvBW,QAAA,oBAAoB,wBAuB/B","sourcesContent":["import {\n\tcreateAssociatedTokenAccountInstruction,\n\tgetAssociatedTokenAddress,\n} from '@solana/spl-token';\nimport { PublicKey, TransactionInstruction } from '@solana/web3.js';\n\nexport {\n\tTOKEN_PROGRAM_ID,\n\tcreateTransferCheckedInstruction,\n} from '@solana/spl-token';\n\nexport const createTokenAccountIx = async (\n\towner: PublicKey,\n\tmintAddress: PublicKey,\n\tpayer?: PublicKey\n): Promise<TransactionInstruction> => {\n\tif (!payer) {\n\t\tpayer = owner;\n\t}\n\n\tconst associatedAddress = await getAssociatedTokenAddress(\n\t\tmintAddress,\n\t\towner,\n\t\ttrue\n\t);\n\n\tconst createAtaIx = await createAssociatedTokenAccountInstruction(\n\t\tpayer,\n\t\tassociatedAddress,\n\t\towner,\n\t\tmintAddress\n\t);\n\n\treturn createAtaIx;\n};\n"]}
@@ -0,0 +1,82 @@
1
+ import { BN, BigNum, MarketType, OptionalOrderParams, PositionDirection } from '@drift-labs/sdk';
2
+ import { AuctionParams, TradeOffsetPrice } from '../../types';
3
+ declare const getMarketAuctionParams: ({ direction, startPriceFromSettings, endPriceFromSettings, limitPrice, duration, auctionStartPriceOffset, auctionEndPriceOffset, additionalEndPriceBuffer, forceUpToSlippage, bestBidPrice, bestAskPrice, ensureCrossingEndPrice, }: {
4
+ direction: PositionDirection;
5
+ startPriceFromSettings: BN;
6
+ endPriceFromSettings: BN;
7
+ /**
8
+ * Limit price is the oracle limit price - market orders use the oracle order type under the hood on Drift UI
9
+ * So oracle limit price is the oracle price + oracle offset
10
+ */
11
+ limitPrice: BN;
12
+ duration: number;
13
+ auctionStartPriceOffset: number;
14
+ auctionEndPriceOffset: number;
15
+ additionalEndPriceBuffer?: BN;
16
+ forceUpToSlippage?: boolean;
17
+ bestBidPrice?: BN;
18
+ bestAskPrice?: BN;
19
+ ensureCrossingEndPrice?: boolean;
20
+ }) => AuctionParams;
21
+ /**
22
+ * Helper function which derived market order params from the CORE data that is used to create them.
23
+ * @param param0
24
+ * @returns
25
+ */
26
+ declare const 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, }: {
27
+ marketType: MarketType;
28
+ marketIndex: number;
29
+ direction: PositionDirection;
30
+ maxLeverageSelected: boolean;
31
+ maxLeverageOrderSize: BN;
32
+ baseAmount: BN;
33
+ reduceOnly: boolean;
34
+ allowInfSlippage: boolean;
35
+ oraclePrice: BN;
36
+ bestPrice: BN;
37
+ entryPrice: BN;
38
+ worstPrice: BN;
39
+ markPrice: BN;
40
+ auctionDuration: number;
41
+ auctionStartPriceOffset: number;
42
+ auctionEndPriceOffset: number;
43
+ auctionPriceCaps?: {
44
+ min: BN;
45
+ max: BN;
46
+ };
47
+ auctionStartPriceOffsetFrom: TradeOffsetPrice;
48
+ auctionEndPriceOffsetFrom: TradeOffsetPrice;
49
+ slippageTolerance: number;
50
+ isOracleOrder?: boolean;
51
+ additionalEndPriceBuffer?: BN;
52
+ forceUpToSlippage?: boolean;
53
+ bestBidPrice?: BN;
54
+ bestAskPrice?: BN;
55
+ ensureCrossingEndPrice?: boolean;
56
+ }) => OptionalOrderParams & {
57
+ constrainedBySlippage?: boolean;
58
+ };
59
+ declare const getLimitAuctionParams: ({ direction, inputPrice, startPriceFromSettings, duration, auctionStartPriceOffset, oraclePriceBands, }: {
60
+ direction: PositionDirection;
61
+ inputPrice: BigNum;
62
+ startPriceFromSettings: BN;
63
+ duration: number;
64
+ auctionStartPriceOffset: number;
65
+ oraclePriceBands?: [BN, BN];
66
+ }) => AuctionParams;
67
+ declare const getPriceObject: ({ oraclePrice, bestOffer, entryPrice, worstPrice, markPrice, direction, }: {
68
+ oraclePrice: BN;
69
+ bestOffer: BN;
70
+ entryPrice: BN;
71
+ worstPrice: BN;
72
+ markPrice: BN;
73
+ direction: PositionDirection;
74
+ }) => {
75
+ oracle: BN;
76
+ bestOffer: BN;
77
+ entry: BN;
78
+ best: BN;
79
+ worst: BN;
80
+ mark: BN;
81
+ };
82
+ export { getMarketAuctionParams, deriveMarketOrderParams, getLimitAuctionParams, getPriceObject, };
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPriceObject = exports.getLimitAuctionParams = exports.deriveMarketOrderParams = exports.getMarketAuctionParams = void 0;
4
+ const sdk_1 = require("@drift-labs/sdk");
5
+ const trade_1 = require("../../constants/trade");
6
+ const price_1 = require("./price");
7
+ const getMarketAuctionParams = ({ direction, startPriceFromSettings, endPriceFromSettings, limitPrice, duration, auctionStartPriceOffset, auctionEndPriceOffset, additionalEndPriceBuffer, forceUpToSlippage, bestBidPrice, bestAskPrice, ensureCrossingEndPrice, }) => {
8
+ let auctionStartPrice;
9
+ let auctionEndPrice;
10
+ let constrainedBySlippage;
11
+ const auctionEndPriceBuffer = sdk_1.BigNum.from(sdk_1.PRICE_PRECISION).scale(Math.abs(auctionEndPriceOffset * 100), 10000).val;
12
+ const auctionStartPriceBuffer = sdk_1.BigNum.from(startPriceFromSettings).scale(Math.abs(auctionStartPriceOffset * 100), 10000).val;
13
+ if ((0, sdk_1.isVariant)(direction, 'long')) {
14
+ auctionStartPrice = startPriceFromSettings.sub(auctionStartPriceBuffer);
15
+ const worstPriceToUse = sdk_1.BN.max(endPriceFromSettings, startPriceFromSettings); // Handles edge cases like if the worst price on the book was better than the oracle price, and the settings are asking to be relative to the oracle price
16
+ auctionEndPrice = sdk_1.PRICE_PRECISION.add(auctionEndPriceBuffer)
17
+ .mul(worstPriceToUse)
18
+ .div(sdk_1.PRICE_PRECISION);
19
+ constrainedBySlippage = limitPrice.lt(auctionEndPrice);
20
+ // if forceUpToSlippage is passed, use max slippage price as end price
21
+ if (forceUpToSlippage) {
22
+ auctionEndPrice = limitPrice;
23
+ constrainedBySlippage = false;
24
+ }
25
+ else {
26
+ // use BEST (limit price, auction end price) as end price
27
+ auctionEndPrice = sdk_1.BN.min(limitPrice, auctionEndPrice);
28
+ }
29
+ // apply additional buffer if provided
30
+ if (additionalEndPriceBuffer) {
31
+ auctionEndPrice = auctionEndPrice.add(additionalEndPriceBuffer);
32
+ constrainedBySlippage = limitPrice.lt(auctionEndPrice);
33
+ }
34
+ // if ensureCrossingEndPrice is passed, ensure auction end price crosses bestAskPrice
35
+ if (ensureCrossingEndPrice && bestAskPrice) {
36
+ auctionEndPrice = sdk_1.BN.max(auctionEndPrice, bestAskPrice.add(auctionEndPriceBuffer));
37
+ }
38
+ auctionStartPrice = sdk_1.BN.min(auctionStartPrice, auctionEndPrice);
39
+ }
40
+ else {
41
+ auctionStartPrice = startPriceFromSettings.add(auctionStartPriceBuffer);
42
+ const worstPriceToUse = sdk_1.BN.min(endPriceFromSettings, startPriceFromSettings); // Handles edge cases like if the worst price on the book was better than the oracle price, and the settings are asking to be relative to the oracle price
43
+ auctionEndPrice = sdk_1.PRICE_PRECISION.sub(auctionEndPriceBuffer)
44
+ .mul(worstPriceToUse)
45
+ .div(sdk_1.PRICE_PRECISION);
46
+ constrainedBySlippage = limitPrice.gt(auctionEndPrice);
47
+ // if forceUpToSlippage is passed, use max slippage price as end price
48
+ if (forceUpToSlippage) {
49
+ auctionEndPrice = limitPrice;
50
+ constrainedBySlippage = false;
51
+ }
52
+ else {
53
+ // use BEST (limit price, auction end price) as end price
54
+ auctionEndPrice = sdk_1.BN.max(limitPrice, auctionEndPrice);
55
+ }
56
+ // apply additional buffer if provided
57
+ if (additionalEndPriceBuffer) {
58
+ auctionEndPrice = auctionEndPrice.sub(additionalEndPriceBuffer);
59
+ constrainedBySlippage = limitPrice.gt(auctionEndPrice);
60
+ }
61
+ // if ensureCrossingEndPrice is passed, ensure auction end price crosses bestBidPrice
62
+ if (ensureCrossingEndPrice && bestBidPrice) {
63
+ auctionEndPrice = sdk_1.BN.min(auctionEndPrice, bestBidPrice.sub(auctionEndPriceBuffer));
64
+ }
65
+ auctionStartPrice = sdk_1.BN.max(auctionStartPrice, auctionEndPrice);
66
+ }
67
+ return {
68
+ auctionStartPrice,
69
+ auctionEndPrice,
70
+ auctionDuration: duration,
71
+ constrainedBySlippage,
72
+ };
73
+ };
74
+ exports.getMarketAuctionParams = getMarketAuctionParams;
75
+ /**
76
+ * Helper function which derived market order params from the CORE data that is used to create them.
77
+ * @param param0
78
+ * @returns
79
+ */
80
+ const 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, }) => {
81
+ const priceObject = getPriceObject({
82
+ oraclePrice,
83
+ markPrice,
84
+ bestOffer: bestPrice,
85
+ entryPrice,
86
+ worstPrice,
87
+ direction,
88
+ });
89
+ // max slippage price
90
+ let limitPrice = (0, price_1.getMarketOrderLimitPrice)({
91
+ direction,
92
+ baselinePrice: priceObject[auctionStartPriceOffsetFrom],
93
+ slippageTolerance: allowInfSlippage ? undefined : slippageTolerance,
94
+ });
95
+ if (additionalEndPriceBuffer) {
96
+ limitPrice = (0, sdk_1.isVariant)(direction, 'long')
97
+ ? limitPrice.add(additionalEndPriceBuffer)
98
+ : limitPrice.sub(additionalEndPriceBuffer);
99
+ }
100
+ const auctionParams = getMarketAuctionParams({
101
+ direction,
102
+ startPriceFromSettings: priceObject[auctionStartPriceOffsetFrom],
103
+ endPriceFromSettings: priceObject[auctionEndPriceOffsetFrom],
104
+ limitPrice,
105
+ duration: auctionDuration,
106
+ auctionStartPriceOffset: auctionStartPriceOffset,
107
+ auctionEndPriceOffset: auctionEndPriceOffset,
108
+ additionalEndPriceBuffer,
109
+ forceUpToSlippage,
110
+ bestBidPrice,
111
+ bestAskPrice,
112
+ ensureCrossingEndPrice,
113
+ });
114
+ let orderParams = (0, sdk_1.getMarketOrderParams)({
115
+ marketType,
116
+ marketIndex,
117
+ direction,
118
+ baseAssetAmount: maxLeverageSelected ? maxLeverageOrderSize : baseAmount,
119
+ reduceOnly,
120
+ price: allowInfSlippage ? undefined : limitPrice,
121
+ ...auctionParams,
122
+ });
123
+ if (isOracleOrder) {
124
+ // wont work if oracle is zero
125
+ if (!oraclePrice.eq(sdk_1.ZERO)) {
126
+ const oracleAuctionParams = (0, sdk_1.deriveOracleAuctionParams)({
127
+ direction: direction,
128
+ oraclePrice,
129
+ auctionStartPrice: auctionParams.auctionStartPrice,
130
+ auctionEndPrice: auctionParams.auctionEndPrice,
131
+ limitPrice: auctionParams.auctionEndPrice,
132
+ auctionPriceCaps: auctionPriceCaps,
133
+ });
134
+ orderParams = {
135
+ ...orderParams,
136
+ ...oracleAuctionParams,
137
+ price: undefined,
138
+ orderType: sdk_1.OrderType.ORACLE,
139
+ };
140
+ }
141
+ }
142
+ return orderParams;
143
+ };
144
+ exports.deriveMarketOrderParams = deriveMarketOrderParams;
145
+ const getLimitAuctionParams = ({ direction, inputPrice, startPriceFromSettings, duration, auctionStartPriceOffset, oraclePriceBands, }) => {
146
+ let limitAuctionParams = trade_1.EMPTY_AUCTION_PARAMS;
147
+ const auctionStartPriceBuffer = inputPrice.scale(Math.abs(auctionStartPriceOffset * 100), 10000).val;
148
+ if ((0, sdk_1.isVariant)(direction, 'long') &&
149
+ startPriceFromSettings &&
150
+ startPriceFromSettings.lt(inputPrice.val) &&
151
+ startPriceFromSettings.gt(sdk_1.ZERO)) {
152
+ limitAuctionParams = {
153
+ auctionStartPrice: startPriceFromSettings.sub(auctionStartPriceBuffer),
154
+ auctionEndPrice: inputPrice.val,
155
+ auctionDuration: duration,
156
+ };
157
+ }
158
+ else if ((0, sdk_1.isVariant)(direction, 'short') &&
159
+ startPriceFromSettings &&
160
+ startPriceFromSettings.gt(sdk_1.ZERO) &&
161
+ startPriceFromSettings.gt(inputPrice.val)) {
162
+ limitAuctionParams = {
163
+ auctionStartPrice: startPriceFromSettings.add(auctionStartPriceBuffer),
164
+ auctionEndPrice: inputPrice.val,
165
+ auctionDuration: duration,
166
+ };
167
+ }
168
+ if (oraclePriceBands && limitAuctionParams.auctionDuration) {
169
+ const [minPrice, maxPrice] = oraclePriceBands;
170
+ // start and end price cant be outside of the oracle price bands
171
+ limitAuctionParams.auctionStartPrice = sdk_1.BN.max(sdk_1.BN.min(limitAuctionParams.auctionStartPrice, maxPrice), minPrice);
172
+ limitAuctionParams.auctionEndPrice = sdk_1.BN.max(sdk_1.BN.min(limitAuctionParams.auctionEndPrice, maxPrice), minPrice);
173
+ }
174
+ return limitAuctionParams;
175
+ };
176
+ exports.getLimitAuctionParams = getLimitAuctionParams;
177
+ const getPriceObject = ({ oraclePrice, bestOffer, entryPrice, worstPrice, markPrice, direction, }) => {
178
+ let best;
179
+ const nonZeroOptions = [oraclePrice, bestOffer, markPrice].filter((price) => price !== undefined && (price === null || price === void 0 ? void 0 : price.gt(sdk_1.ZERO)));
180
+ if (nonZeroOptions.length === 0) {
181
+ // console.error('Unable to create valid auction params');
182
+ return {
183
+ oracle: sdk_1.ZERO,
184
+ bestOffer: sdk_1.ZERO,
185
+ entry: sdk_1.ZERO,
186
+ best: sdk_1.ZERO,
187
+ worst: sdk_1.ZERO,
188
+ mark: sdk_1.ZERO,
189
+ };
190
+ }
191
+ if ((0, sdk_1.isVariant)(direction, 'long')) {
192
+ best = nonZeroOptions.reduce((a, b) => (a.lt(b) ? a : b)); // lowest price
193
+ }
194
+ else {
195
+ best = nonZeroOptions.reduce((a, b) => (a.gt(b) ? a : b)); // highest price
196
+ }
197
+ // if zero values come through, fallback to nonzero value
198
+ return {
199
+ oracle: (oraclePrice === null || oraclePrice === void 0 ? void 0 : oraclePrice.gt(sdk_1.ZERO)) ? oraclePrice : best,
200
+ bestOffer: (bestOffer === null || bestOffer === void 0 ? void 0 : bestOffer.gt(sdk_1.ZERO)) ? bestOffer : best,
201
+ entry: entryPrice,
202
+ best,
203
+ worst: worstPrice,
204
+ mark: (markPrice === null || markPrice === void 0 ? void 0 : markPrice.gt(sdk_1.ZERO)) ? markPrice : best,
205
+ };
206
+ };
207
+ exports.getPriceObject = getPriceObject;
208
+ //# sourceMappingURL=auction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auction.js","sourceRoot":"","sources":["../../../src/utils/trading/auction.ts"],"names":[],"mappings":";;;AAAA,yCAYyB;AAEzB,iDAA6D;AAC7D,mCAAmD;AAEnD,MAAM,sBAAsB,GAAG,CAAC,EAC/B,SAAS,EACT,sBAAsB,EACtB,oBAAoB,EACpB,UAAU,EACV,QAAQ,EACR,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,sBAAsB,GAkBtB,EAAiB,EAAE;IACnB,IAAI,iBAAqB,CAAC;IAC1B,IAAI,eAAmB,CAAC;IACxB,IAAI,qBAA8B,CAAC;IAEnC,MAAM,qBAAqB,GAAG,YAAM,CAAC,IAAI,CAAC,qBAAe,CAAC,CAAC,KAAK,CAC/D,IAAI,CAAC,GAAG,CAAC,qBAAqB,GAAG,GAAG,CAAC,EACrC,KAAK,CACL,CAAC,GAAG,CAAC;IAEN,MAAM,uBAAuB,GAAG,YAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,KAAK,CACxE,IAAI,CAAC,GAAG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C,CAAC,IAAI;QACjD,KAAK,EAAE,UAAU;QACjB,IAAI;QACJ,KAAK,EAAE,UAAU;QACjB,IAAI,EAAE,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,EAAE,CAAC,UAAI,CAAC,EAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;KAC5C,CAAC;AACH,CAAC,CAAC;AAMD,wCAAc","sourcesContent":["import {\n\tBN,\n\tBigNum,\n\tMarketType,\n\tOptionalOrderParams,\n\tOrderType,\n\tPRICE_PRECISION,\n\tPositionDirection,\n\tZERO,\n\tderiveOracleAuctionParams,\n\tgetMarketOrderParams,\n\tisVariant,\n} from '@drift-labs/sdk';\nimport { AuctionParams, TradeOffsetPrice } from '../../types';\nimport { EMPTY_AUCTION_PARAMS } from '../../constants/trade';\nimport { getMarketOrderLimitPrice } from './price';\n\nconst getMarketAuctionParams = ({\n\tdirection,\n\tstartPriceFromSettings,\n\tendPriceFromSettings,\n\tlimitPrice,\n\tduration,\n\tauctionStartPriceOffset,\n\tauctionEndPriceOffset,\n\tadditionalEndPriceBuffer,\n\tforceUpToSlippage,\n\tbestBidPrice,\n\tbestAskPrice,\n\tensureCrossingEndPrice,\n}: {\n\tdirection: PositionDirection;\n\tstartPriceFromSettings: BN;\n\tendPriceFromSettings: BN;\n\t/**\n\t * Limit price is the oracle limit price - market orders use the oracle order type under the hood on Drift UI\n\t * So oracle limit price is the oracle price + oracle offset\n\t */\n\tlimitPrice: BN;\n\tduration: number;\n\tauctionStartPriceOffset: number;\n\tauctionEndPriceOffset: number;\n\tadditionalEndPriceBuffer?: BN;\n\tforceUpToSlippage?: boolean;\n\tbestBidPrice?: BN;\n\tbestAskPrice?: BN;\n\tensureCrossingEndPrice?: boolean;\n}): AuctionParams => {\n\tlet auctionStartPrice: BN;\n\tlet auctionEndPrice: BN;\n\tlet constrainedBySlippage: boolean;\n\n\tconst auctionEndPriceBuffer = BigNum.from(PRICE_PRECISION).scale(\n\t\tMath.abs(auctionEndPriceOffset * 100),\n\t\t10000\n\t).val;\n\n\tconst auctionStartPriceBuffer = BigNum.from(startPriceFromSettings).scale(\n\t\tMath.abs(auctionStartPriceOffset * 100),\n\t\t10000\n\t).val;\n\n\tif (isVariant(direction, 'long')) {\n\t\tauctionStartPrice = startPriceFromSettings.sub(auctionStartPriceBuffer);\n\n\t\tconst worstPriceToUse = BN.max(\n\t\t\tendPriceFromSettings,\n\t\t\tstartPriceFromSettings\n\t\t); // Handles edge cases like if the worst price on the book was better than the oracle price, and the settings are asking to be relative to the oracle price\n\n\t\tauctionEndPrice = PRICE_PRECISION.add(auctionEndPriceBuffer)\n\t\t\t.mul(worstPriceToUse)\n\t\t\t.div(PRICE_PRECISION);\n\n\t\tconstrainedBySlippage = limitPrice.lt(auctionEndPrice);\n\n\t\t// if forceUpToSlippage is passed, use max slippage price as end price\n\t\tif (forceUpToSlippage) {\n\t\t\tauctionEndPrice = limitPrice;\n\t\t\tconstrainedBySlippage = false;\n\t\t} else {\n\t\t\t// use BEST (limit price, auction end price) as end price\n\t\t\tauctionEndPrice = BN.min(limitPrice, auctionEndPrice);\n\t\t}\n\n\t\t// apply additional buffer if provided\n\t\tif (additionalEndPriceBuffer) {\n\t\t\tauctionEndPrice = auctionEndPrice.add(additionalEndPriceBuffer);\n\t\t\tconstrainedBySlippage = limitPrice.lt(auctionEndPrice);\n\t\t}\n\n\t\t// if ensureCrossingEndPrice is passed, ensure auction end price crosses bestAskPrice\n\t\tif (ensureCrossingEndPrice && bestAskPrice) {\n\t\t\tauctionEndPrice = BN.max(\n\t\t\t\tauctionEndPrice,\n\t\t\t\tbestAskPrice.add(auctionEndPriceBuffer)\n\t\t\t);\n\t\t}\n\n\t\tauctionStartPrice = BN.min(auctionStartPrice, auctionEndPrice);\n\t} else {\n\t\tauctionStartPrice = startPriceFromSettings.add(auctionStartPriceBuffer);\n\n\t\tconst worstPriceToUse = BN.min(\n\t\t\tendPriceFromSettings,\n\t\t\tstartPriceFromSettings\n\t\t); // Handles edge cases like if the worst price on the book was better than the oracle price, and the settings are asking to be relative to the oracle price\n\n\t\tauctionEndPrice = PRICE_PRECISION.sub(auctionEndPriceBuffer)\n\t\t\t.mul(worstPriceToUse)\n\t\t\t.div(PRICE_PRECISION);\n\n\t\tconstrainedBySlippage = limitPrice.gt(auctionEndPrice);\n\n\t\t// if forceUpToSlippage is passed, use max slippage price as end price\n\t\tif (forceUpToSlippage) {\n\t\t\tauctionEndPrice = limitPrice;\n\t\t\tconstrainedBySlippage = false;\n\t\t} else {\n\t\t\t// use BEST (limit price, auction end price) as end price\n\t\t\tauctionEndPrice = BN.max(limitPrice, auctionEndPrice);\n\t\t}\n\n\t\t// apply additional buffer if provided\n\t\tif (additionalEndPriceBuffer) {\n\t\t\tauctionEndPrice = auctionEndPrice.sub(additionalEndPriceBuffer);\n\t\t\tconstrainedBySlippage = limitPrice.gt(auctionEndPrice);\n\t\t}\n\n\t\t// if ensureCrossingEndPrice is passed, ensure auction end price crosses bestBidPrice\n\t\tif (ensureCrossingEndPrice && bestBidPrice) {\n\t\t\tauctionEndPrice = BN.min(\n\t\t\t\tauctionEndPrice,\n\t\t\t\tbestBidPrice.sub(auctionEndPriceBuffer)\n\t\t\t);\n\t\t}\n\n\t\tauctionStartPrice = BN.max(auctionStartPrice, auctionEndPrice);\n\t}\n\n\treturn {\n\t\tauctionStartPrice,\n\t\tauctionEndPrice,\n\t\tauctionDuration: duration,\n\t\tconstrainedBySlippage,\n\t};\n};\n\n/**\n * Helper function which derived market order params from the CORE data that is used to create them.\n * @param param0\n * @returns\n */\nconst deriveMarketOrderParams = ({\n\tmarketType,\n\tmarketIndex,\n\tdirection,\n\tmaxLeverageSelected,\n\tmaxLeverageOrderSize,\n\tbaseAmount,\n\treduceOnly,\n\tallowInfSlippage,\n\toraclePrice,\n\tbestPrice,\n\tentryPrice,\n\tworstPrice,\n\tmarkPrice,\n\tauctionDuration,\n\tauctionStartPriceOffset,\n\tauctionEndPriceOffset,\n\tauctionStartPriceOffsetFrom,\n\tauctionEndPriceOffsetFrom,\n\tauctionPriceCaps,\n\tslippageTolerance,\n\tisOracleOrder,\n\tadditionalEndPriceBuffer,\n\tforceUpToSlippage,\n\tbestBidPrice,\n\tbestAskPrice,\n\tensureCrossingEndPrice,\n}: {\n\tmarketType: MarketType;\n\tmarketIndex: number;\n\tdirection: PositionDirection;\n\tmaxLeverageSelected: boolean;\n\tmaxLeverageOrderSize: BN;\n\tbaseAmount: BN;\n\treduceOnly: boolean;\n\tallowInfSlippage: boolean;\n\toraclePrice: BN;\n\tbestPrice: BN;\n\tentryPrice: BN;\n\tworstPrice: BN;\n\tmarkPrice: BN;\n\tauctionDuration: number;\n\tauctionStartPriceOffset: number;\n\tauctionEndPriceOffset: number;\n\tauctionPriceCaps?: {\n\t\tmin: BN;\n\t\tmax: BN;\n\t};\n\tauctionStartPriceOffsetFrom: TradeOffsetPrice;\n\tauctionEndPriceOffsetFrom: TradeOffsetPrice;\n\tslippageTolerance: number;\n\tisOracleOrder?: boolean;\n\tadditionalEndPriceBuffer?: BN;\n\tforceUpToSlippage?: boolean;\n\tbestBidPrice?: BN;\n\tbestAskPrice?: BN;\n\tensureCrossingEndPrice?: boolean;\n}): OptionalOrderParams & { constrainedBySlippage?: boolean } => {\n\tconst priceObject = getPriceObject({\n\t\toraclePrice,\n\t\tmarkPrice,\n\t\tbestOffer: bestPrice,\n\t\tentryPrice,\n\t\tworstPrice,\n\t\tdirection,\n\t});\n\n\t// max slippage price\n\tlet limitPrice = getMarketOrderLimitPrice({\n\t\tdirection,\n\t\tbaselinePrice: priceObject[auctionStartPriceOffsetFrom],\n\t\tslippageTolerance: allowInfSlippage ? undefined : slippageTolerance,\n\t});\n\n\tif (additionalEndPriceBuffer) {\n\t\tlimitPrice = isVariant(direction, 'long')\n\t\t\t? limitPrice.add(additionalEndPriceBuffer)\n\t\t\t: limitPrice.sub(additionalEndPriceBuffer);\n\t}\n\n\tconst auctionParams = getMarketAuctionParams({\n\t\tdirection,\n\t\tstartPriceFromSettings: priceObject[auctionStartPriceOffsetFrom],\n\t\tendPriceFromSettings: priceObject[auctionEndPriceOffsetFrom],\n\t\tlimitPrice,\n\t\tduration: auctionDuration,\n\t\tauctionStartPriceOffset: auctionStartPriceOffset,\n\t\tauctionEndPriceOffset: auctionEndPriceOffset,\n\t\tadditionalEndPriceBuffer,\n\t\tforceUpToSlippage,\n\t\tbestBidPrice,\n\t\tbestAskPrice,\n\t\tensureCrossingEndPrice,\n\t});\n\n\tlet orderParams = getMarketOrderParams({\n\t\tmarketType,\n\t\tmarketIndex,\n\t\tdirection,\n\t\tbaseAssetAmount: maxLeverageSelected ? maxLeverageOrderSize : baseAmount,\n\t\treduceOnly,\n\t\tprice: allowInfSlippage ? undefined : limitPrice,\n\t\t...auctionParams,\n\t});\n\n\tif (isOracleOrder) {\n\t\t// wont work if oracle is zero\n\t\tif (!oraclePrice.eq(ZERO)) {\n\t\t\tconst oracleAuctionParams = deriveOracleAuctionParams({\n\t\t\t\tdirection: direction,\n\t\t\t\toraclePrice,\n\t\t\t\tauctionStartPrice: auctionParams.auctionStartPrice,\n\t\t\t\tauctionEndPrice: auctionParams.auctionEndPrice,\n\t\t\t\tlimitPrice: auctionParams.auctionEndPrice,\n\t\t\t\tauctionPriceCaps: auctionPriceCaps,\n\t\t\t});\n\n\t\t\torderParams = {\n\t\t\t\t...orderParams,\n\t\t\t\t...oracleAuctionParams,\n\t\t\t\tprice: undefined,\n\t\t\t\torderType: OrderType.ORACLE,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn orderParams;\n};\n\nconst getLimitAuctionParams = ({\n\tdirection,\n\tinputPrice,\n\tstartPriceFromSettings,\n\tduration,\n\tauctionStartPriceOffset,\n\toraclePriceBands,\n}: {\n\tdirection: PositionDirection;\n\tinputPrice: BigNum;\n\tstartPriceFromSettings: BN;\n\tduration: number;\n\tauctionStartPriceOffset: number;\n\toraclePriceBands?: [BN, BN];\n}): AuctionParams => {\n\tlet limitAuctionParams = EMPTY_AUCTION_PARAMS;\n\n\tconst auctionStartPriceBuffer = inputPrice.scale(\n\t\tMath.abs(auctionStartPriceOffset * 100),\n\t\t10000\n\t).val;\n\n\tif (\n\t\tisVariant(direction, 'long') &&\n\t\tstartPriceFromSettings &&\n\t\tstartPriceFromSettings.lt(inputPrice.val) &&\n\t\tstartPriceFromSettings.gt(ZERO)\n\t) {\n\t\tlimitAuctionParams = {\n\t\t\tauctionStartPrice: startPriceFromSettings.sub(auctionStartPriceBuffer),\n\t\t\tauctionEndPrice: inputPrice.val,\n\t\t\tauctionDuration: duration,\n\t\t};\n\t} else if (\n\t\tisVariant(direction, 'short') &&\n\t\tstartPriceFromSettings &&\n\t\tstartPriceFromSettings.gt(ZERO) &&\n\t\tstartPriceFromSettings.gt(inputPrice.val)\n\t) {\n\t\tlimitAuctionParams = {\n\t\t\tauctionStartPrice: startPriceFromSettings.add(auctionStartPriceBuffer),\n\t\t\tauctionEndPrice: inputPrice.val,\n\t\t\tauctionDuration: duration,\n\t\t};\n\t}\n\n\tif (oraclePriceBands && limitAuctionParams.auctionDuration) {\n\t\tconst [minPrice, maxPrice] = oraclePriceBands;\n\n\t\t// start and end price cant be outside of the oracle price bands\n\t\tlimitAuctionParams.auctionStartPrice = BN.max(\n\t\t\tBN.min(limitAuctionParams.auctionStartPrice, maxPrice),\n\t\t\tminPrice\n\t\t);\n\n\t\tlimitAuctionParams.auctionEndPrice = BN.max(\n\t\t\tBN.min(limitAuctionParams.auctionEndPrice, maxPrice),\n\t\t\tminPrice\n\t\t);\n\t}\n\n\treturn limitAuctionParams;\n};\n\nconst getPriceObject = ({\n\toraclePrice,\n\tbestOffer,\n\tentryPrice,\n\tworstPrice,\n\tmarkPrice,\n\tdirection,\n}: {\n\toraclePrice: BN;\n\tbestOffer: BN;\n\tentryPrice: BN;\n\tworstPrice: BN;\n\tmarkPrice: BN;\n\tdirection: PositionDirection;\n}) => {\n\tlet best: BN;\n\n\tconst nonZeroOptions = [oraclePrice, bestOffer, markPrice].filter(\n\t\t(price) => price !== undefined && price?.gt(ZERO)\n\t);\n\n\tif (nonZeroOptions.length === 0) {\n\t\t// console.error('Unable to create valid auction params');\n\t\treturn {\n\t\t\toracle: ZERO,\n\t\t\tbestOffer: ZERO,\n\t\t\tentry: ZERO,\n\t\t\tbest: ZERO,\n\t\t\tworst: ZERO,\n\t\t\tmark: ZERO,\n\t\t};\n\t}\n\n\tif (isVariant(direction, 'long')) {\n\t\tbest = nonZeroOptions.reduce((a, b) => (a.lt(b) ? a : b)); // lowest price\n\t} else {\n\t\tbest = nonZeroOptions.reduce((a, b) => (a.gt(b) ? a : b)); // highest price\n\t}\n\n\t// if zero values come through, fallback to nonzero value\n\treturn {\n\t\toracle: oraclePrice?.gt(ZERO) ? oraclePrice : best,\n\t\tbestOffer: bestOffer?.gt(ZERO) ? bestOffer : best,\n\t\tentry: entryPrice,\n\t\tbest,\n\t\tworst: worstPrice,\n\t\tmark: markPrice?.gt(ZERO) ? markPrice : best,\n\t};\n};\n\nexport {\n\tgetMarketAuctionParams,\n\tderiveMarketOrderParams,\n\tgetLimitAuctionParams,\n\tgetPriceObject,\n};\n"]}
@@ -0,0 +1,7 @@
1
+ export * from './auction';
2
+ export * from './leverage';
3
+ export * from './liquidation';
4
+ export * from './lp';
5
+ export * from './pnl';
6
+ export * from './price';
7
+ export * from './size';