@mysten/deepbook-v3 0.22.2 → 0.23.0

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 (65) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/client.d.ts +167 -1
  3. package/dist/cjs/client.js +354 -3
  4. package/dist/cjs/client.js.map +2 -2
  5. package/dist/cjs/contracts/utils/index.d.ts +13 -0
  6. package/dist/cjs/contracts/utils/index.js +6 -9
  7. package/dist/cjs/contracts/utils/index.js.map +2 -2
  8. package/dist/cjs/index.d.ts +3 -1
  9. package/dist/cjs/index.js +16 -3
  10. package/dist/cjs/index.js.map +2 -2
  11. package/dist/cjs/transactions/deepbook.d.ts +189 -1
  12. package/dist/cjs/transactions/deepbook.js +548 -1
  13. package/dist/cjs/transactions/deepbook.js.map +2 -2
  14. package/dist/cjs/types/index.d.ts +41 -0
  15. package/dist/cjs/types/index.js.map +1 -1
  16. package/dist/cjs/utils/config.d.ts +8 -8
  17. package/dist/cjs/utils/config.js +12 -11
  18. package/dist/cjs/utils/config.js.map +2 -2
  19. package/dist/cjs/utils/constants.d.ts +8 -0
  20. package/dist/cjs/utils/constants.js +18 -7
  21. package/dist/cjs/utils/constants.js.map +2 -2
  22. package/dist/cjs/utils/errors.d.ts +42 -0
  23. package/dist/cjs/utils/errors.js +70 -0
  24. package/dist/cjs/utils/errors.js.map +7 -0
  25. package/dist/cjs/utils/validation.d.ts +50 -0
  26. package/dist/cjs/utils/validation.js +67 -0
  27. package/dist/cjs/utils/validation.js.map +7 -0
  28. package/dist/esm/client.d.ts +167 -1
  29. package/dist/esm/client.js +355 -4
  30. package/dist/esm/client.js.map +2 -2
  31. package/dist/esm/contracts/utils/index.d.ts +13 -0
  32. package/dist/esm/contracts/utils/index.js +6 -9
  33. package/dist/esm/contracts/utils/index.js.map +2 -2
  34. package/dist/esm/index.d.ts +3 -1
  35. package/dist/esm/index.js +31 -5
  36. package/dist/esm/index.js.map +2 -2
  37. package/dist/esm/transactions/deepbook.d.ts +189 -1
  38. package/dist/esm/transactions/deepbook.js +549 -2
  39. package/dist/esm/transactions/deepbook.js.map +2 -2
  40. package/dist/esm/types/index.d.ts +41 -0
  41. package/dist/esm/types/index.js.map +1 -1
  42. package/dist/esm/utils/config.d.ts +8 -8
  43. package/dist/esm/utils/config.js +12 -11
  44. package/dist/esm/utils/config.js.map +2 -2
  45. package/dist/esm/utils/constants.d.ts +8 -0
  46. package/dist/esm/utils/constants.js +18 -7
  47. package/dist/esm/utils/constants.js.map +2 -2
  48. package/dist/esm/utils/errors.d.ts +42 -0
  49. package/dist/esm/utils/errors.js +50 -0
  50. package/dist/esm/utils/errors.js.map +7 -0
  51. package/dist/esm/utils/validation.d.ts +50 -0
  52. package/dist/esm/utils/validation.js +47 -0
  53. package/dist/esm/utils/validation.js.map +7 -0
  54. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/package.json +15 -8
  57. package/src/client.ts +427 -4
  58. package/src/contracts/utils/index.ts +27 -11
  59. package/src/index.ts +21 -2
  60. package/src/transactions/deepbook.ts +647 -2
  61. package/src/types/index.ts +47 -0
  62. package/src/utils/config.ts +28 -15
  63. package/src/utils/constants.ts +17 -6
  64. package/src/utils/errors.ts +67 -0
  65. package/src/utils/validation.ts +91 -0
@@ -13,7 +13,7 @@ import {
13
13
  FLOAT_SCALAR,
14
14
  GAS_BUDGET,
15
15
  MAX_TIMESTAMP,
16
- POOL_CREATION_FEE
16
+ POOL_CREATION_FEE_DEEP
17
17
  } from "../utils/config.js";
18
18
  class DeepBookContract {
19
19
  /**
@@ -158,6 +158,32 @@ class DeepBookContract {
158
158
  typeArguments: [baseCoin.type, quoteCoin.type]
159
159
  });
160
160
  };
161
+ /**
162
+ * @description Cancel multiple orders
163
+ * @param {string} poolKey The key to identify the pool
164
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
165
+ * @param {string[]} orderIds Array of order IDs to cancel
166
+ * @returns A function that takes a Transaction object
167
+ */
168
+ this.cancelOrders = (poolKey, balanceManagerKey, orderIds) => (tx) => {
169
+ tx.setGasBudgetIfNotSet(GAS_BUDGET);
170
+ const pool = __privateGet(this, _config).getPool(poolKey);
171
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
172
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
173
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
174
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
175
+ tx.moveCall({
176
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_orders`,
177
+ arguments: [
178
+ tx.object(pool.address),
179
+ tx.object(balanceManager.address),
180
+ tradeProof,
181
+ tx.pure.vector("u128", orderIds),
182
+ tx.object.clock()
183
+ ],
184
+ typeArguments: [baseCoin.type, quoteCoin.type]
185
+ });
186
+ };
161
187
  /**
162
188
  * @description Cancel all open orders for a balance manager
163
189
  * @param {string} poolKey The key to identify the pool
@@ -200,6 +226,23 @@ class DeepBookContract {
200
226
  typeArguments: [baseCoin.type, quoteCoin.type]
201
227
  });
202
228
  };
229
+ /**
230
+ * @description Withdraw settled amounts permissionlessly for a balance manager
231
+ * @param {string} poolKey The key to identify the pool
232
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
233
+ * @returns A function that takes a Transaction object
234
+ */
235
+ this.withdrawSettledAmountsPermissionless = (poolKey, balanceManagerKey) => (tx) => {
236
+ const pool = __privateGet(this, _config).getPool(poolKey);
237
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
238
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
239
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
240
+ tx.moveCall({
241
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts_permissionless`,
242
+ arguments: [tx.object(pool.address), tx.object(balanceManager.address)],
243
+ typeArguments: [baseCoin.type, quoteCoin.type]
244
+ });
245
+ };
203
246
  /**
204
247
  * @description Add a deep price point for a target pool using a reference pool
205
248
  * @param {string} targetPoolKey The key to identify the target pool
@@ -605,6 +648,180 @@ class DeepBookContract {
605
648
  });
606
649
  return [baseCoinResult, quoteCoinResult, deepCoinResult];
607
650
  };
651
+ /**
652
+ * @description Swap exact quantity without a balance manager
653
+ * @param {SwapParams & {isBaseToCoin: boolean}} params Parameters for the swap
654
+ * @returns A function that takes a Transaction object
655
+ */
656
+ this.swapExactQuantity = (params) => (tx) => {
657
+ tx.setGasBudgetIfNotSet(GAS_BUDGET);
658
+ tx.setSenderIfNotSet(__privateGet(this, _config).address);
659
+ const { poolKey, amount, deepAmount, minOut, baseCoin, quoteCoin, deepCoin, isBaseToCoin } = params;
660
+ const pool = __privateGet(this, _config).getPool(poolKey);
661
+ const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
662
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
663
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
664
+ const baseCoinInput = isBaseToCoin ? baseCoin ?? coinWithBalance({
665
+ type: baseCoinType.type,
666
+ balance: Math.round(amount * baseCoinType.scalar)
667
+ }) : coinWithBalance({ type: baseCoinType.type, balance: 0 });
668
+ const quoteCoinInput = isBaseToCoin ? coinWithBalance({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? coinWithBalance({
669
+ type: quoteCoinType.type,
670
+ balance: Math.round(amount * quoteCoinType.scalar)
671
+ });
672
+ const deepCoinInput = deepCoin ?? coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) });
673
+ const minOutInput = Math.round(
674
+ minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
675
+ );
676
+ const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
677
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity`,
678
+ arguments: [
679
+ tx.object(pool.address),
680
+ baseCoinInput,
681
+ quoteCoinInput,
682
+ deepCoinInput,
683
+ tx.pure.u64(minOutInput),
684
+ tx.object.clock()
685
+ ],
686
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
687
+ });
688
+ return [baseCoinResult, quoteCoinResult, deepCoinResult];
689
+ };
690
+ /**
691
+ * @description Swap exact base for quote with a balance manager
692
+ * @param {SwapWithManagerParams} params Parameters for the swap
693
+ * @returns A function that takes a Transaction object
694
+ */
695
+ this.swapExactBaseForQuoteWithManager = (params) => (tx) => {
696
+ tx.setGasBudgetIfNotSet(GAS_BUDGET);
697
+ const {
698
+ poolKey,
699
+ balanceManagerKey,
700
+ tradeCap,
701
+ depositCap,
702
+ withdrawCap,
703
+ amount: baseAmount,
704
+ minOut: minQuote,
705
+ baseCoin
706
+ } = params;
707
+ const pool = __privateGet(this, _config).getPool(poolKey);
708
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
709
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
710
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
711
+ const baseCoinInput = baseCoin ?? coinWithBalance({
712
+ type: baseCoinType.type,
713
+ balance: Math.round(baseAmount * baseCoinType.scalar)
714
+ });
715
+ const minQuoteInput = Math.round(minQuote * quoteCoinType.scalar);
716
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
717
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote_with_manager`,
718
+ arguments: [
719
+ tx.object(pool.address),
720
+ tx.object(balanceManager.address),
721
+ tx.object(tradeCap),
722
+ tx.object(depositCap),
723
+ tx.object(withdrawCap),
724
+ baseCoinInput,
725
+ tx.pure.u64(minQuoteInput),
726
+ tx.object.clock()
727
+ ],
728
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
729
+ });
730
+ return [baseCoinResult, quoteCoinResult];
731
+ };
732
+ /**
733
+ * @description Swap exact quote for base with a balance manager
734
+ * @param {SwapWithManagerParams} params Parameters for the swap
735
+ * @returns A function that takes a Transaction object
736
+ */
737
+ this.swapExactQuoteForBaseWithManager = (params) => (tx) => {
738
+ tx.setGasBudgetIfNotSet(GAS_BUDGET);
739
+ const {
740
+ poolKey,
741
+ balanceManagerKey,
742
+ tradeCap,
743
+ depositCap,
744
+ withdrawCap,
745
+ amount: quoteAmount,
746
+ minOut: minBase,
747
+ quoteCoin
748
+ } = params;
749
+ const pool = __privateGet(this, _config).getPool(poolKey);
750
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
751
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
752
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
753
+ const quoteCoinInput = quoteCoin ?? coinWithBalance({
754
+ type: quoteCoinType.type,
755
+ balance: Math.round(quoteAmount * quoteCoinType.scalar)
756
+ });
757
+ const minBaseInput = Math.round(minBase * baseCoinType.scalar);
758
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
759
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base_with_manager`,
760
+ arguments: [
761
+ tx.object(pool.address),
762
+ tx.object(balanceManager.address),
763
+ tx.object(tradeCap),
764
+ tx.object(depositCap),
765
+ tx.object(withdrawCap),
766
+ quoteCoinInput,
767
+ tx.pure.u64(minBaseInput),
768
+ tx.object.clock()
769
+ ],
770
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
771
+ });
772
+ return [baseCoinResult, quoteCoinResult];
773
+ };
774
+ /**
775
+ * @description Swap exact quantity (base or quote) with a balance manager
776
+ * @param {SwapWithManagerParams & {isBaseToCoin: boolean}} params Parameters for the swap
777
+ * @returns A function that takes a Transaction object
778
+ */
779
+ this.swapExactQuantityWithManager = (params) => (tx) => {
780
+ tx.setGasBudgetIfNotSet(GAS_BUDGET);
781
+ const {
782
+ poolKey,
783
+ balanceManagerKey,
784
+ tradeCap,
785
+ depositCap,
786
+ withdrawCap,
787
+ amount,
788
+ minOut,
789
+ baseCoin,
790
+ quoteCoin,
791
+ isBaseToCoin
792
+ } = params;
793
+ const pool = __privateGet(this, _config).getPool(poolKey);
794
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
795
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
796
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
797
+ const baseCoinInput = isBaseToCoin ? baseCoin ?? coinWithBalance({
798
+ type: baseCoinType.type,
799
+ balance: Math.round(amount * baseCoinType.scalar)
800
+ }) : coinWithBalance({ type: baseCoinType.type, balance: 0 });
801
+ const quoteCoinInput = isBaseToCoin ? coinWithBalance({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? coinWithBalance({
802
+ type: quoteCoinType.type,
803
+ balance: Math.round(amount * quoteCoinType.scalar)
804
+ });
805
+ const minOutInput = Math.round(
806
+ minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
807
+ );
808
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
809
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity_with_manager`,
810
+ arguments: [
811
+ tx.object(pool.address),
812
+ tx.object(balanceManager.address),
813
+ tx.object(tradeCap),
814
+ tx.object(depositCap),
815
+ tx.object(withdrawCap),
816
+ baseCoinInput,
817
+ quoteCoinInput,
818
+ tx.pure.u64(minOutInput),
819
+ tx.object.clock()
820
+ ],
821
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
822
+ });
823
+ return [baseCoinResult, quoteCoinResult];
824
+ };
608
825
  /**
609
826
  * @description Create a new pool permissionlessly
610
827
  * @param {CreatePermissionlessPoolParams} params Parameters for creating permissionless pool
@@ -623,7 +840,7 @@ class DeepBookContract {
623
840
  const adjustedMinSize = Math.round(minSize * baseScalar);
624
841
  const deepCoinInput = deepCoin ?? coinWithBalance({
625
842
  type: deepCoinType,
626
- balance: POOL_CREATION_FEE
843
+ balance: POOL_CREATION_FEE_DEEP
627
844
  });
628
845
  tx.moveCall({
629
846
  target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::create_permissionless_pool`,
@@ -747,6 +964,336 @@ class DeepBookContract {
747
964
  typeArguments: [baseCoin.type, quoteCoin.type]
748
965
  });
749
966
  };
967
+ /**
968
+ * @description Check if a pool is a stable pool
969
+ * @param {string} poolKey The key to identify the pool
970
+ * @returns A function that takes a Transaction object
971
+ */
972
+ this.stablePool = (poolKey) => (tx) => {
973
+ const pool = __privateGet(this, _config).getPool(poolKey);
974
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
975
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
976
+ return tx.moveCall({
977
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::stable_pool`,
978
+ arguments: [tx.object(pool.address)],
979
+ typeArguments: [baseCoin.type, quoteCoin.type]
980
+ });
981
+ };
982
+ /**
983
+ * @description Check if a pool is registered
984
+ * @param {string} poolKey The key to identify the pool
985
+ * @returns A function that takes a Transaction object
986
+ */
987
+ this.registeredPool = (poolKey) => (tx) => {
988
+ const pool = __privateGet(this, _config).getPool(poolKey);
989
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
990
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
991
+ return tx.moveCall({
992
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::registered_pool`,
993
+ arguments: [tx.object(pool.address)],
994
+ typeArguments: [baseCoin.type, quoteCoin.type]
995
+ });
996
+ };
997
+ /**
998
+ * @description Get the quote quantity out for a given base quantity using input token as fee
999
+ * @param {string} poolKey The key to identify the pool
1000
+ * @param {number} baseQuantity Base quantity to convert
1001
+ * @returns A function that takes a Transaction object
1002
+ */
1003
+ this.getQuoteQuantityOutInputFee = (poolKey, baseQuantity) => (tx) => {
1004
+ const pool = __privateGet(this, _config).getPool(poolKey);
1005
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1006
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1007
+ return tx.moveCall({
1008
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out_input_fee`,
1009
+ arguments: [
1010
+ tx.object(pool.address),
1011
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
1012
+ tx.object.clock()
1013
+ ],
1014
+ typeArguments: [baseCoin.type, quoteCoin.type]
1015
+ });
1016
+ };
1017
+ /**
1018
+ * @description Get the base quantity out for a given quote quantity using input token as fee
1019
+ * @param {string} poolKey The key to identify the pool
1020
+ * @param {number} quoteQuantity Quote quantity to convert
1021
+ * @returns A function that takes a Transaction object
1022
+ */
1023
+ this.getBaseQuantityOutInputFee = (poolKey, quoteQuantity) => (tx) => {
1024
+ const pool = __privateGet(this, _config).getPool(poolKey);
1025
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1026
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1027
+ return tx.moveCall({
1028
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out_input_fee`,
1029
+ arguments: [
1030
+ tx.object(pool.address),
1031
+ tx.pure.u64(quoteQuantity * quoteCoin.scalar),
1032
+ tx.object.clock()
1033
+ ],
1034
+ typeArguments: [baseCoin.type, quoteCoin.type]
1035
+ });
1036
+ };
1037
+ /**
1038
+ * @description Get the quantity out for a given base or quote quantity using input token as fee
1039
+ * @param {string} poolKey The key to identify the pool
1040
+ * @param {number} baseQuantity Base quantity to convert
1041
+ * @param {number} quoteQuantity Quote quantity to convert
1042
+ * @returns A function that takes a Transaction object
1043
+ */
1044
+ this.getQuantityOutInputFee = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
1045
+ const pool = __privateGet(this, _config).getPool(poolKey);
1046
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1047
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1048
+ return tx.moveCall({
1049
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out_input_fee`,
1050
+ arguments: [
1051
+ tx.object(pool.address),
1052
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
1053
+ tx.pure.u64(quoteQuantity * quoteCoin.scalar),
1054
+ tx.object.clock()
1055
+ ],
1056
+ typeArguments: [baseCoin.type, quoteCoin.type]
1057
+ });
1058
+ };
1059
+ /**
1060
+ * @description Get the base quantity needed to receive a target quote quantity
1061
+ * @param {string} poolKey The key to identify the pool
1062
+ * @param {number} targetQuoteQuantity Target quote quantity
1063
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1064
+ * @returns A function that takes a Transaction object
1065
+ */
1066
+ this.getBaseQuantityIn = (poolKey, targetQuoteQuantity, payWithDeep) => (tx) => {
1067
+ const pool = __privateGet(this, _config).getPool(poolKey);
1068
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1069
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1070
+ return tx.moveCall({
1071
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_in`,
1072
+ arguments: [
1073
+ tx.object(pool.address),
1074
+ tx.pure.u64(targetQuoteQuantity * quoteCoin.scalar),
1075
+ tx.pure.bool(payWithDeep),
1076
+ tx.object.clock()
1077
+ ],
1078
+ typeArguments: [baseCoin.type, quoteCoin.type]
1079
+ });
1080
+ };
1081
+ /**
1082
+ * @description Get the quote quantity needed to receive a target base quantity
1083
+ * @param {string} poolKey The key to identify the pool
1084
+ * @param {number} targetBaseQuantity Target base quantity
1085
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1086
+ * @returns A function that takes a Transaction object
1087
+ */
1088
+ this.getQuoteQuantityIn = (poolKey, targetBaseQuantity, payWithDeep) => (tx) => {
1089
+ const pool = __privateGet(this, _config).getPool(poolKey);
1090
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1091
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1092
+ return tx.moveCall({
1093
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_in`,
1094
+ arguments: [
1095
+ tx.object(pool.address),
1096
+ tx.pure.u64(targetBaseQuantity * baseCoin.scalar),
1097
+ tx.pure.bool(payWithDeep),
1098
+ tx.object.clock()
1099
+ ],
1100
+ typeArguments: [baseCoin.type, quoteCoin.type]
1101
+ });
1102
+ };
1103
+ /**
1104
+ * @description Get account order details for a balance manager
1105
+ * @param {string} poolKey The key to identify the pool
1106
+ * @param {string} managerKey Key of the balance manager
1107
+ * @returns A function that takes a Transaction object
1108
+ */
1109
+ this.getAccountOrderDetails = (poolKey, managerKey) => (tx) => {
1110
+ const pool = __privateGet(this, _config).getPool(poolKey);
1111
+ const manager = __privateGet(this, _config).getBalanceManager(managerKey);
1112
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1113
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1114
+ return tx.moveCall({
1115
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_account_order_details`,
1116
+ arguments: [tx.object(pool.address), tx.object(manager.address)],
1117
+ typeArguments: [baseCoin.type, quoteCoin.type]
1118
+ });
1119
+ };
1120
+ /**
1121
+ * @description Get the DEEP required for an order
1122
+ * @param {string} poolKey The key to identify the pool
1123
+ * @param {number} baseQuantity Base quantity
1124
+ * @param {number} price Price
1125
+ * @returns A function that takes a Transaction object
1126
+ */
1127
+ this.getOrderDeepRequired = (poolKey, baseQuantity, price) => (tx) => {
1128
+ const pool = __privateGet(this, _config).getPool(poolKey);
1129
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1130
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1131
+ const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1132
+ const inputQuantity = Math.round(baseQuantity * baseCoin.scalar);
1133
+ return tx.moveCall({
1134
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_required`,
1135
+ arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity), tx.pure.u64(inputPrice)],
1136
+ typeArguments: [baseCoin.type, quoteCoin.type]
1137
+ });
1138
+ };
1139
+ /**
1140
+ * @description Check if account exists for a balance manager
1141
+ * @param {string} poolKey The key to identify the pool
1142
+ * @param {string} managerKey Key of the balance manager
1143
+ * @returns A function that takes a Transaction object
1144
+ */
1145
+ this.accountExists = (poolKey, managerKey) => (tx) => {
1146
+ const pool = __privateGet(this, _config).getPool(poolKey);
1147
+ const manager = __privateGet(this, _config).getBalanceManager(managerKey);
1148
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1149
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1150
+ return tx.moveCall({
1151
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account_exists`,
1152
+ arguments: [tx.object(pool.address), tx.object(manager.address)],
1153
+ typeArguments: [baseCoin.type, quoteCoin.type]
1154
+ });
1155
+ };
1156
+ /**
1157
+ * @description Get the next epoch trade parameters for a pool
1158
+ * @param {string} poolKey The key to identify the pool
1159
+ * @returns A function that takes a Transaction object
1160
+ */
1161
+ this.poolTradeParamsNext = (poolKey) => (tx) => {
1162
+ const pool = __privateGet(this, _config).getPool(poolKey);
1163
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1164
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1165
+ return tx.moveCall({
1166
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params_next`,
1167
+ arguments: [tx.object(pool.address)],
1168
+ typeArguments: [baseCoin.type, quoteCoin.type]
1169
+ });
1170
+ };
1171
+ /**
1172
+ * @description Get the quorum for a pool
1173
+ * @param {string} poolKey The key to identify the pool
1174
+ * @returns A function that takes a Transaction object
1175
+ */
1176
+ this.quorum = (poolKey) => (tx) => {
1177
+ const pool = __privateGet(this, _config).getPool(poolKey);
1178
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1179
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1180
+ return tx.moveCall({
1181
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::quorum`,
1182
+ arguments: [tx.object(pool.address)],
1183
+ typeArguments: [baseCoin.type, quoteCoin.type]
1184
+ });
1185
+ };
1186
+ /**
1187
+ * @description Get the pool ID
1188
+ * @param {string} poolKey The key to identify the pool
1189
+ * @returns A function that takes a Transaction object
1190
+ */
1191
+ this.poolId = (poolKey) => (tx) => {
1192
+ const pool = __privateGet(this, _config).getPool(poolKey);
1193
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1194
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1195
+ return tx.moveCall({
1196
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::id`,
1197
+ arguments: [tx.object(pool.address)],
1198
+ typeArguments: [baseCoin.type, quoteCoin.type]
1199
+ });
1200
+ };
1201
+ /**
1202
+ * @description Check if a limit order can be placed
1203
+ * @param {CanPlaceLimitOrderParams} params Parameters for checking limit order validity
1204
+ * @returns A function that takes a Transaction object
1205
+ */
1206
+ this.canPlaceLimitOrder = (params) => (tx) => {
1207
+ const { poolKey, balanceManagerKey, price, quantity, isBid, payWithDeep, expireTimestamp } = params;
1208
+ const pool = __privateGet(this, _config).getPool(poolKey);
1209
+ const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
1210
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1211
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1212
+ const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1213
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1214
+ return tx.moveCall({
1215
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_limit_order`,
1216
+ arguments: [
1217
+ tx.object(pool.address),
1218
+ tx.object(manager.address),
1219
+ tx.pure.u64(inputPrice),
1220
+ tx.pure.u64(inputQuantity),
1221
+ tx.pure.bool(isBid),
1222
+ tx.pure.bool(payWithDeep),
1223
+ tx.pure.u64(expireTimestamp),
1224
+ tx.object.clock()
1225
+ ],
1226
+ typeArguments: [baseCoin.type, quoteCoin.type]
1227
+ });
1228
+ };
1229
+ /**
1230
+ * @description Check if a market order can be placed
1231
+ * @param {CanPlaceMarketOrderParams} params Parameters for checking market order validity
1232
+ * @returns A function that takes a Transaction object
1233
+ */
1234
+ this.canPlaceMarketOrder = (params) => (tx) => {
1235
+ const { poolKey, balanceManagerKey, quantity, isBid, payWithDeep } = params;
1236
+ const pool = __privateGet(this, _config).getPool(poolKey);
1237
+ const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
1238
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1239
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1240
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1241
+ return tx.moveCall({
1242
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_market_order`,
1243
+ arguments: [
1244
+ tx.object(pool.address),
1245
+ tx.object(manager.address),
1246
+ tx.pure.u64(inputQuantity),
1247
+ tx.pure.bool(isBid),
1248
+ tx.pure.bool(payWithDeep),
1249
+ tx.object.clock()
1250
+ ],
1251
+ typeArguments: [baseCoin.type, quoteCoin.type]
1252
+ });
1253
+ };
1254
+ /**
1255
+ * @description Check if market order params are valid
1256
+ * @param {string} poolKey The key to identify the pool
1257
+ * @param {number} quantity Quantity
1258
+ * @returns A function that takes a Transaction object
1259
+ */
1260
+ this.checkMarketOrderParams = (poolKey, quantity) => (tx) => {
1261
+ const pool = __privateGet(this, _config).getPool(poolKey);
1262
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1263
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1264
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1265
+ return tx.moveCall({
1266
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_market_order_params`,
1267
+ arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
1268
+ typeArguments: [baseCoin.type, quoteCoin.type]
1269
+ });
1270
+ };
1271
+ /**
1272
+ * @description Check if limit order params are valid
1273
+ * @param {string} poolKey The key to identify the pool
1274
+ * @param {number} price Price
1275
+ * @param {number} quantity Quantity
1276
+ * @param {number} expireTimestamp Expiration timestamp
1277
+ * @returns A function that takes a Transaction object
1278
+ */
1279
+ this.checkLimitOrderParams = (poolKey, price, quantity, expireTimestamp) => (tx) => {
1280
+ const pool = __privateGet(this, _config).getPool(poolKey);
1281
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1282
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1283
+ const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1284
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1285
+ return tx.moveCall({
1286
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_limit_order_params`,
1287
+ arguments: [
1288
+ tx.object(pool.address),
1289
+ tx.pure.u64(inputPrice),
1290
+ tx.pure.u64(inputQuantity),
1291
+ tx.pure.u64(expireTimestamp),
1292
+ tx.object.clock()
1293
+ ],
1294
+ typeArguments: [baseCoin.type, quoteCoin.type]
1295
+ });
1296
+ };
750
1297
  __privateSet(this, _config, config);
751
1298
  }
752
1299
  }