@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
@@ -175,6 +175,32 @@ class DeepBookContract {
175
175
  typeArguments: [baseCoin.type, quoteCoin.type]
176
176
  });
177
177
  };
178
+ /**
179
+ * @description Cancel multiple orders
180
+ * @param {string} poolKey The key to identify the pool
181
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
182
+ * @param {string[]} orderIds Array of order IDs to cancel
183
+ * @returns A function that takes a Transaction object
184
+ */
185
+ this.cancelOrders = (poolKey, balanceManagerKey, orderIds) => (tx) => {
186
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
187
+ const pool = __privateGet(this, _config).getPool(poolKey);
188
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
189
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
190
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
191
+ const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
192
+ tx.moveCall({
193
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::cancel_orders`,
194
+ arguments: [
195
+ tx.object(pool.address),
196
+ tx.object(balanceManager.address),
197
+ tradeProof,
198
+ tx.pure.vector("u128", orderIds),
199
+ tx.object.clock()
200
+ ],
201
+ typeArguments: [baseCoin.type, quoteCoin.type]
202
+ });
203
+ };
178
204
  /**
179
205
  * @description Cancel all open orders for a balance manager
180
206
  * @param {string} poolKey The key to identify the pool
@@ -217,6 +243,23 @@ class DeepBookContract {
217
243
  typeArguments: [baseCoin.type, quoteCoin.type]
218
244
  });
219
245
  };
246
+ /**
247
+ * @description Withdraw settled amounts permissionlessly for a balance manager
248
+ * @param {string} poolKey The key to identify the pool
249
+ * @param {string} balanceManagerKey The key to identify the BalanceManager
250
+ * @returns A function that takes a Transaction object
251
+ */
252
+ this.withdrawSettledAmountsPermissionless = (poolKey, balanceManagerKey) => (tx) => {
253
+ const pool = __privateGet(this, _config).getPool(poolKey);
254
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
255
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
256
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
257
+ tx.moveCall({
258
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::withdraw_settled_amounts_permissionless`,
259
+ arguments: [tx.object(pool.address), tx.object(balanceManager.address)],
260
+ typeArguments: [baseCoin.type, quoteCoin.type]
261
+ });
262
+ };
220
263
  /**
221
264
  * @description Add a deep price point for a target pool using a reference pool
222
265
  * @param {string} targetPoolKey The key to identify the target pool
@@ -622,6 +665,180 @@ class DeepBookContract {
622
665
  });
623
666
  return [baseCoinResult, quoteCoinResult, deepCoinResult];
624
667
  };
668
+ /**
669
+ * @description Swap exact quantity without a balance manager
670
+ * @param {SwapParams & {isBaseToCoin: boolean}} params Parameters for the swap
671
+ * @returns A function that takes a Transaction object
672
+ */
673
+ this.swapExactQuantity = (params) => (tx) => {
674
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
675
+ tx.setSenderIfNotSet(__privateGet(this, _config).address);
676
+ const { poolKey, amount, deepAmount, minOut, baseCoin, quoteCoin, deepCoin, isBaseToCoin } = params;
677
+ const pool = __privateGet(this, _config).getPool(poolKey);
678
+ const deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
679
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
680
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
681
+ const baseCoinInput = isBaseToCoin ? baseCoin ?? (0, import_transactions.coinWithBalance)({
682
+ type: baseCoinType.type,
683
+ balance: Math.round(amount * baseCoinType.scalar)
684
+ }) : (0, import_transactions.coinWithBalance)({ type: baseCoinType.type, balance: 0 });
685
+ const quoteCoinInput = isBaseToCoin ? (0, import_transactions.coinWithBalance)({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? (0, import_transactions.coinWithBalance)({
686
+ type: quoteCoinType.type,
687
+ balance: Math.round(amount * quoteCoinType.scalar)
688
+ });
689
+ const deepCoinInput = deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) });
690
+ const minOutInput = Math.round(
691
+ minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
692
+ );
693
+ const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
694
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity`,
695
+ arguments: [
696
+ tx.object(pool.address),
697
+ baseCoinInput,
698
+ quoteCoinInput,
699
+ deepCoinInput,
700
+ tx.pure.u64(minOutInput),
701
+ tx.object.clock()
702
+ ],
703
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
704
+ });
705
+ return [baseCoinResult, quoteCoinResult, deepCoinResult];
706
+ };
707
+ /**
708
+ * @description Swap exact base for quote with a balance manager
709
+ * @param {SwapWithManagerParams} params Parameters for the swap
710
+ * @returns A function that takes a Transaction object
711
+ */
712
+ this.swapExactBaseForQuoteWithManager = (params) => (tx) => {
713
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
714
+ const {
715
+ poolKey,
716
+ balanceManagerKey,
717
+ tradeCap,
718
+ depositCap,
719
+ withdrawCap,
720
+ amount: baseAmount,
721
+ minOut: minQuote,
722
+ baseCoin
723
+ } = params;
724
+ const pool = __privateGet(this, _config).getPool(poolKey);
725
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
726
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
727
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
728
+ const baseCoinInput = baseCoin ?? (0, import_transactions.coinWithBalance)({
729
+ type: baseCoinType.type,
730
+ balance: Math.round(baseAmount * baseCoinType.scalar)
731
+ });
732
+ const minQuoteInput = Math.round(minQuote * quoteCoinType.scalar);
733
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
734
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote_with_manager`,
735
+ arguments: [
736
+ tx.object(pool.address),
737
+ tx.object(balanceManager.address),
738
+ tx.object(tradeCap),
739
+ tx.object(depositCap),
740
+ tx.object(withdrawCap),
741
+ baseCoinInput,
742
+ tx.pure.u64(minQuoteInput),
743
+ tx.object.clock()
744
+ ],
745
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
746
+ });
747
+ return [baseCoinResult, quoteCoinResult];
748
+ };
749
+ /**
750
+ * @description Swap exact quote for base with a balance manager
751
+ * @param {SwapWithManagerParams} params Parameters for the swap
752
+ * @returns A function that takes a Transaction object
753
+ */
754
+ this.swapExactQuoteForBaseWithManager = (params) => (tx) => {
755
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
756
+ const {
757
+ poolKey,
758
+ balanceManagerKey,
759
+ tradeCap,
760
+ depositCap,
761
+ withdrawCap,
762
+ amount: quoteAmount,
763
+ minOut: minBase,
764
+ quoteCoin
765
+ } = params;
766
+ const pool = __privateGet(this, _config).getPool(poolKey);
767
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
768
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
769
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
770
+ const quoteCoinInput = quoteCoin ?? (0, import_transactions.coinWithBalance)({
771
+ type: quoteCoinType.type,
772
+ balance: Math.round(quoteAmount * quoteCoinType.scalar)
773
+ });
774
+ const minBaseInput = Math.round(minBase * baseCoinType.scalar);
775
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
776
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base_with_manager`,
777
+ arguments: [
778
+ tx.object(pool.address),
779
+ tx.object(balanceManager.address),
780
+ tx.object(tradeCap),
781
+ tx.object(depositCap),
782
+ tx.object(withdrawCap),
783
+ quoteCoinInput,
784
+ tx.pure.u64(minBaseInput),
785
+ tx.object.clock()
786
+ ],
787
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
788
+ });
789
+ return [baseCoinResult, quoteCoinResult];
790
+ };
791
+ /**
792
+ * @description Swap exact quantity (base or quote) with a balance manager
793
+ * @param {SwapWithManagerParams & {isBaseToCoin: boolean}} params Parameters for the swap
794
+ * @returns A function that takes a Transaction object
795
+ */
796
+ this.swapExactQuantityWithManager = (params) => (tx) => {
797
+ tx.setGasBudgetIfNotSet(import_config.GAS_BUDGET);
798
+ const {
799
+ poolKey,
800
+ balanceManagerKey,
801
+ tradeCap,
802
+ depositCap,
803
+ withdrawCap,
804
+ amount,
805
+ minOut,
806
+ baseCoin,
807
+ quoteCoin,
808
+ isBaseToCoin
809
+ } = params;
810
+ const pool = __privateGet(this, _config).getPool(poolKey);
811
+ const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
812
+ const baseCoinType = __privateGet(this, _config).getCoin(pool.baseCoin);
813
+ const quoteCoinType = __privateGet(this, _config).getCoin(pool.quoteCoin);
814
+ const baseCoinInput = isBaseToCoin ? baseCoin ?? (0, import_transactions.coinWithBalance)({
815
+ type: baseCoinType.type,
816
+ balance: Math.round(amount * baseCoinType.scalar)
817
+ }) : (0, import_transactions.coinWithBalance)({ type: baseCoinType.type, balance: 0 });
818
+ const quoteCoinInput = isBaseToCoin ? (0, import_transactions.coinWithBalance)({ type: quoteCoinType.type, balance: 0 }) : quoteCoin ?? (0, import_transactions.coinWithBalance)({
819
+ type: quoteCoinType.type,
820
+ balance: Math.round(amount * quoteCoinType.scalar)
821
+ });
822
+ const minOutInput = Math.round(
823
+ minOut * (isBaseToCoin ? quoteCoinType.scalar : baseCoinType.scalar)
824
+ );
825
+ const [baseCoinResult, quoteCoinResult] = tx.moveCall({
826
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quantity_with_manager`,
827
+ arguments: [
828
+ tx.object(pool.address),
829
+ tx.object(balanceManager.address),
830
+ tx.object(tradeCap),
831
+ tx.object(depositCap),
832
+ tx.object(withdrawCap),
833
+ baseCoinInput,
834
+ quoteCoinInput,
835
+ tx.pure.u64(minOutInput),
836
+ tx.object.clock()
837
+ ],
838
+ typeArguments: [baseCoinType.type, quoteCoinType.type]
839
+ });
840
+ return [baseCoinResult, quoteCoinResult];
841
+ };
625
842
  /**
626
843
  * @description Create a new pool permissionlessly
627
844
  * @param {CreatePermissionlessPoolParams} params Parameters for creating permissionless pool
@@ -640,7 +857,7 @@ class DeepBookContract {
640
857
  const adjustedMinSize = Math.round(minSize * baseScalar);
641
858
  const deepCoinInput = deepCoin ?? (0, import_transactions.coinWithBalance)({
642
859
  type: deepCoinType,
643
- balance: import_config.POOL_CREATION_FEE
860
+ balance: import_config.POOL_CREATION_FEE_DEEP
644
861
  });
645
862
  tx.moveCall({
646
863
  target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::create_permissionless_pool`,
@@ -764,6 +981,336 @@ class DeepBookContract {
764
981
  typeArguments: [baseCoin.type, quoteCoin.type]
765
982
  });
766
983
  };
984
+ /**
985
+ * @description Check if a pool is a stable pool
986
+ * @param {string} poolKey The key to identify the pool
987
+ * @returns A function that takes a Transaction object
988
+ */
989
+ this.stablePool = (poolKey) => (tx) => {
990
+ const pool = __privateGet(this, _config).getPool(poolKey);
991
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
992
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
993
+ return tx.moveCall({
994
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::stable_pool`,
995
+ arguments: [tx.object(pool.address)],
996
+ typeArguments: [baseCoin.type, quoteCoin.type]
997
+ });
998
+ };
999
+ /**
1000
+ * @description Check if a pool is registered
1001
+ * @param {string} poolKey The key to identify the pool
1002
+ * @returns A function that takes a Transaction object
1003
+ */
1004
+ this.registeredPool = (poolKey) => (tx) => {
1005
+ const pool = __privateGet(this, _config).getPool(poolKey);
1006
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1007
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1008
+ return tx.moveCall({
1009
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::registered_pool`,
1010
+ arguments: [tx.object(pool.address)],
1011
+ typeArguments: [baseCoin.type, quoteCoin.type]
1012
+ });
1013
+ };
1014
+ /**
1015
+ * @description Get the quote quantity out for a given base quantity using input token as fee
1016
+ * @param {string} poolKey The key to identify the pool
1017
+ * @param {number} baseQuantity Base quantity to convert
1018
+ * @returns A function that takes a Transaction object
1019
+ */
1020
+ this.getQuoteQuantityOutInputFee = (poolKey, baseQuantity) => (tx) => {
1021
+ const pool = __privateGet(this, _config).getPool(poolKey);
1022
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1023
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1024
+ return tx.moveCall({
1025
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_out_input_fee`,
1026
+ arguments: [
1027
+ tx.object(pool.address),
1028
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
1029
+ tx.object.clock()
1030
+ ],
1031
+ typeArguments: [baseCoin.type, quoteCoin.type]
1032
+ });
1033
+ };
1034
+ /**
1035
+ * @description Get the base quantity out for a given quote quantity using input token as fee
1036
+ * @param {string} poolKey The key to identify the pool
1037
+ * @param {number} quoteQuantity Quote quantity to convert
1038
+ * @returns A function that takes a Transaction object
1039
+ */
1040
+ this.getBaseQuantityOutInputFee = (poolKey, quoteQuantity) => (tx) => {
1041
+ const pool = __privateGet(this, _config).getPool(poolKey);
1042
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1043
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1044
+ return tx.moveCall({
1045
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_out_input_fee`,
1046
+ arguments: [
1047
+ tx.object(pool.address),
1048
+ tx.pure.u64(quoteQuantity * quoteCoin.scalar),
1049
+ tx.object.clock()
1050
+ ],
1051
+ typeArguments: [baseCoin.type, quoteCoin.type]
1052
+ });
1053
+ };
1054
+ /**
1055
+ * @description Get the quantity out for a given base or quote quantity using input token as fee
1056
+ * @param {string} poolKey The key to identify the pool
1057
+ * @param {number} baseQuantity Base quantity to convert
1058
+ * @param {number} quoteQuantity Quote quantity to convert
1059
+ * @returns A function that takes a Transaction object
1060
+ */
1061
+ this.getQuantityOutInputFee = (poolKey, baseQuantity, quoteQuantity) => (tx) => {
1062
+ const pool = __privateGet(this, _config).getPool(poolKey);
1063
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1064
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1065
+ return tx.moveCall({
1066
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quantity_out_input_fee`,
1067
+ arguments: [
1068
+ tx.object(pool.address),
1069
+ tx.pure.u64(baseQuantity * baseCoin.scalar),
1070
+ tx.pure.u64(quoteQuantity * quoteCoin.scalar),
1071
+ tx.object.clock()
1072
+ ],
1073
+ typeArguments: [baseCoin.type, quoteCoin.type]
1074
+ });
1075
+ };
1076
+ /**
1077
+ * @description Get the base quantity needed to receive a target quote quantity
1078
+ * @param {string} poolKey The key to identify the pool
1079
+ * @param {number} targetQuoteQuantity Target quote quantity
1080
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1081
+ * @returns A function that takes a Transaction object
1082
+ */
1083
+ this.getBaseQuantityIn = (poolKey, targetQuoteQuantity, payWithDeep) => (tx) => {
1084
+ const pool = __privateGet(this, _config).getPool(poolKey);
1085
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1086
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1087
+ return tx.moveCall({
1088
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_base_quantity_in`,
1089
+ arguments: [
1090
+ tx.object(pool.address),
1091
+ tx.pure.u64(targetQuoteQuantity * quoteCoin.scalar),
1092
+ tx.pure.bool(payWithDeep),
1093
+ tx.object.clock()
1094
+ ],
1095
+ typeArguments: [baseCoin.type, quoteCoin.type]
1096
+ });
1097
+ };
1098
+ /**
1099
+ * @description Get the quote quantity needed to receive a target base quantity
1100
+ * @param {string} poolKey The key to identify the pool
1101
+ * @param {number} targetBaseQuantity Target base quantity
1102
+ * @param {boolean} payWithDeep Whether to pay fees with DEEP
1103
+ * @returns A function that takes a Transaction object
1104
+ */
1105
+ this.getQuoteQuantityIn = (poolKey, targetBaseQuantity, payWithDeep) => (tx) => {
1106
+ const pool = __privateGet(this, _config).getPool(poolKey);
1107
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1108
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1109
+ return tx.moveCall({
1110
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_quote_quantity_in`,
1111
+ arguments: [
1112
+ tx.object(pool.address),
1113
+ tx.pure.u64(targetBaseQuantity * baseCoin.scalar),
1114
+ tx.pure.bool(payWithDeep),
1115
+ tx.object.clock()
1116
+ ],
1117
+ typeArguments: [baseCoin.type, quoteCoin.type]
1118
+ });
1119
+ };
1120
+ /**
1121
+ * @description Get account order details for a balance manager
1122
+ * @param {string} poolKey The key to identify the pool
1123
+ * @param {string} managerKey Key of the balance manager
1124
+ * @returns A function that takes a Transaction object
1125
+ */
1126
+ this.getAccountOrderDetails = (poolKey, managerKey) => (tx) => {
1127
+ const pool = __privateGet(this, _config).getPool(poolKey);
1128
+ const manager = __privateGet(this, _config).getBalanceManager(managerKey);
1129
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1130
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1131
+ return tx.moveCall({
1132
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_account_order_details`,
1133
+ arguments: [tx.object(pool.address), tx.object(manager.address)],
1134
+ typeArguments: [baseCoin.type, quoteCoin.type]
1135
+ });
1136
+ };
1137
+ /**
1138
+ * @description Get the DEEP required for an order
1139
+ * @param {string} poolKey The key to identify the pool
1140
+ * @param {number} baseQuantity Base quantity
1141
+ * @param {number} price Price
1142
+ * @returns A function that takes a Transaction object
1143
+ */
1144
+ this.getOrderDeepRequired = (poolKey, baseQuantity, price) => (tx) => {
1145
+ const pool = __privateGet(this, _config).getPool(poolKey);
1146
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1147
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1148
+ const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1149
+ const inputQuantity = Math.round(baseQuantity * baseCoin.scalar);
1150
+ return tx.moveCall({
1151
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::get_order_deep_required`,
1152
+ arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity), tx.pure.u64(inputPrice)],
1153
+ typeArguments: [baseCoin.type, quoteCoin.type]
1154
+ });
1155
+ };
1156
+ /**
1157
+ * @description Check if account exists for a balance manager
1158
+ * @param {string} poolKey The key to identify the pool
1159
+ * @param {string} managerKey Key of the balance manager
1160
+ * @returns A function that takes a Transaction object
1161
+ */
1162
+ this.accountExists = (poolKey, managerKey) => (tx) => {
1163
+ const pool = __privateGet(this, _config).getPool(poolKey);
1164
+ const manager = __privateGet(this, _config).getBalanceManager(managerKey);
1165
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1166
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1167
+ return tx.moveCall({
1168
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::account_exists`,
1169
+ arguments: [tx.object(pool.address), tx.object(manager.address)],
1170
+ typeArguments: [baseCoin.type, quoteCoin.type]
1171
+ });
1172
+ };
1173
+ /**
1174
+ * @description Get the next epoch trade parameters for a pool
1175
+ * @param {string} poolKey The key to identify the pool
1176
+ * @returns A function that takes a Transaction object
1177
+ */
1178
+ this.poolTradeParamsNext = (poolKey) => (tx) => {
1179
+ const pool = __privateGet(this, _config).getPool(poolKey);
1180
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1181
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1182
+ return tx.moveCall({
1183
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::pool_trade_params_next`,
1184
+ arguments: [tx.object(pool.address)],
1185
+ typeArguments: [baseCoin.type, quoteCoin.type]
1186
+ });
1187
+ };
1188
+ /**
1189
+ * @description Get the quorum for a pool
1190
+ * @param {string} poolKey The key to identify the pool
1191
+ * @returns A function that takes a Transaction object
1192
+ */
1193
+ this.quorum = (poolKey) => (tx) => {
1194
+ const pool = __privateGet(this, _config).getPool(poolKey);
1195
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1196
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1197
+ return tx.moveCall({
1198
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::quorum`,
1199
+ arguments: [tx.object(pool.address)],
1200
+ typeArguments: [baseCoin.type, quoteCoin.type]
1201
+ });
1202
+ };
1203
+ /**
1204
+ * @description Get the pool ID
1205
+ * @param {string} poolKey The key to identify the pool
1206
+ * @returns A function that takes a Transaction object
1207
+ */
1208
+ this.poolId = (poolKey) => (tx) => {
1209
+ const pool = __privateGet(this, _config).getPool(poolKey);
1210
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1211
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1212
+ return tx.moveCall({
1213
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::id`,
1214
+ arguments: [tx.object(pool.address)],
1215
+ typeArguments: [baseCoin.type, quoteCoin.type]
1216
+ });
1217
+ };
1218
+ /**
1219
+ * @description Check if a limit order can be placed
1220
+ * @param {CanPlaceLimitOrderParams} params Parameters for checking limit order validity
1221
+ * @returns A function that takes a Transaction object
1222
+ */
1223
+ this.canPlaceLimitOrder = (params) => (tx) => {
1224
+ const { poolKey, balanceManagerKey, price, quantity, isBid, payWithDeep, expireTimestamp } = params;
1225
+ const pool = __privateGet(this, _config).getPool(poolKey);
1226
+ const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
1227
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1228
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1229
+ const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1230
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1231
+ return tx.moveCall({
1232
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_limit_order`,
1233
+ arguments: [
1234
+ tx.object(pool.address),
1235
+ tx.object(manager.address),
1236
+ tx.pure.u64(inputPrice),
1237
+ tx.pure.u64(inputQuantity),
1238
+ tx.pure.bool(isBid),
1239
+ tx.pure.bool(payWithDeep),
1240
+ tx.pure.u64(expireTimestamp),
1241
+ tx.object.clock()
1242
+ ],
1243
+ typeArguments: [baseCoin.type, quoteCoin.type]
1244
+ });
1245
+ };
1246
+ /**
1247
+ * @description Check if a market order can be placed
1248
+ * @param {CanPlaceMarketOrderParams} params Parameters for checking market order validity
1249
+ * @returns A function that takes a Transaction object
1250
+ */
1251
+ this.canPlaceMarketOrder = (params) => (tx) => {
1252
+ const { poolKey, balanceManagerKey, quantity, isBid, payWithDeep } = params;
1253
+ const pool = __privateGet(this, _config).getPool(poolKey);
1254
+ const manager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
1255
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1256
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1257
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1258
+ return tx.moveCall({
1259
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::can_place_market_order`,
1260
+ arguments: [
1261
+ tx.object(pool.address),
1262
+ tx.object(manager.address),
1263
+ tx.pure.u64(inputQuantity),
1264
+ tx.pure.bool(isBid),
1265
+ tx.pure.bool(payWithDeep),
1266
+ tx.object.clock()
1267
+ ],
1268
+ typeArguments: [baseCoin.type, quoteCoin.type]
1269
+ });
1270
+ };
1271
+ /**
1272
+ * @description Check if market order params are valid
1273
+ * @param {string} poolKey The key to identify the pool
1274
+ * @param {number} quantity Quantity
1275
+ * @returns A function that takes a Transaction object
1276
+ */
1277
+ this.checkMarketOrderParams = (poolKey, quantity) => (tx) => {
1278
+ const pool = __privateGet(this, _config).getPool(poolKey);
1279
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1280
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1281
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1282
+ return tx.moveCall({
1283
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_market_order_params`,
1284
+ arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
1285
+ typeArguments: [baseCoin.type, quoteCoin.type]
1286
+ });
1287
+ };
1288
+ /**
1289
+ * @description Check if limit order params are valid
1290
+ * @param {string} poolKey The key to identify the pool
1291
+ * @param {number} price Price
1292
+ * @param {number} quantity Quantity
1293
+ * @param {number} expireTimestamp Expiration timestamp
1294
+ * @returns A function that takes a Transaction object
1295
+ */
1296
+ this.checkLimitOrderParams = (poolKey, price, quantity, expireTimestamp) => (tx) => {
1297
+ const pool = __privateGet(this, _config).getPool(poolKey);
1298
+ const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
1299
+ const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
1300
+ const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
1301
+ const inputQuantity = Math.round(quantity * baseCoin.scalar);
1302
+ return tx.moveCall({
1303
+ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::check_limit_order_params`,
1304
+ arguments: [
1305
+ tx.object(pool.address),
1306
+ tx.pure.u64(inputPrice),
1307
+ tx.pure.u64(inputQuantity),
1308
+ tx.pure.u64(expireTimestamp),
1309
+ tx.object.clock()
1310
+ ],
1311
+ typeArguments: [baseCoin.type, quoteCoin.type]
1312
+ });
1313
+ };
767
1314
  __privateSet(this, _config, config);
768
1315
  }
769
1316
  }