@mysten/deepbook-v3 1.1.5 → 1.2.1

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 (116) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/client.d.mts +58 -763
  3. package/dist/client.d.mts.map +1 -1
  4. package/dist/client.mjs +253 -2127
  5. package/dist/client.mjs.map +1 -1
  6. package/dist/contracts/utils/index.mjs +1 -1
  7. package/dist/index.d.mts +4 -4
  8. package/dist/index.mjs +4 -4
  9. package/dist/pyth/pyth.mjs +1 -1
  10. package/dist/queries/accountQueries.mjs +104 -0
  11. package/dist/queries/accountQueries.mjs.map +1 -0
  12. package/dist/queries/balanceManagerQueries.mjs +113 -0
  13. package/dist/queries/balanceManagerQueries.mjs.map +1 -0
  14. package/dist/queries/context.mjs +15 -0
  15. package/dist/queries/context.mjs.map +1 -0
  16. package/dist/queries/marginManagerQueries.mjs +365 -0
  17. package/dist/queries/marginManagerQueries.mjs.map +1 -0
  18. package/dist/queries/marginPoolQueries.mjs +184 -0
  19. package/dist/queries/marginPoolQueries.mjs.map +1 -0
  20. package/dist/queries/orderQueries.mjs +165 -0
  21. package/dist/queries/orderQueries.mjs.map +1 -0
  22. package/dist/queries/poolQueries.mjs +234 -0
  23. package/dist/queries/poolQueries.mjs.map +1 -0
  24. package/dist/queries/priceFeedQueries.mjs +83 -0
  25. package/dist/queries/priceFeedQueries.mjs.map +1 -0
  26. package/dist/queries/quantityQueries.mjs +216 -0
  27. package/dist/queries/quantityQueries.mjs.map +1 -0
  28. package/dist/queries/referralQueries.mjs +96 -0
  29. package/dist/queries/referralQueries.mjs.map +1 -0
  30. package/dist/queries/registryQueries.mjs +162 -0
  31. package/dist/queries/registryQueries.mjs.map +1 -0
  32. package/dist/queries/tpslQueries.mjs +62 -0
  33. package/dist/queries/tpslQueries.mjs.map +1 -0
  34. package/dist/transactions/balanceManager.d.mts +12 -12
  35. package/dist/transactions/balanceManager.d.mts.map +1 -1
  36. package/dist/transactions/balanceManager.mjs +5 -4
  37. package/dist/transactions/balanceManager.mjs.map +1 -1
  38. package/dist/transactions/deepbook.d.mts +24 -24
  39. package/dist/transactions/deepbook.d.mts.map +1 -1
  40. package/dist/transactions/deepbook.mjs +48 -47
  41. package/dist/transactions/deepbook.mjs.map +1 -1
  42. package/dist/transactions/deepbookAdmin.d.mts +2 -2
  43. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  44. package/dist/transactions/deepbookAdmin.mjs +10 -9
  45. package/dist/transactions/deepbookAdmin.mjs.map +1 -1
  46. package/dist/transactions/flashLoans.d.mts.map +1 -1
  47. package/dist/transactions/flashLoans.mjs +6 -4
  48. package/dist/transactions/flashLoans.mjs.map +1 -1
  49. package/dist/transactions/governance.d.mts.map +1 -1
  50. package/dist/transactions/governance.mjs +5 -4
  51. package/dist/transactions/governance.mjs.map +1 -1
  52. package/dist/transactions/marginAdmin.d.mts +7 -7
  53. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  54. package/dist/transactions/marginAdmin.mjs +8 -7
  55. package/dist/transactions/marginAdmin.mjs.map +1 -1
  56. package/dist/transactions/marginLiquidations.d.mts.map +1 -1
  57. package/dist/transactions/marginLiquidations.mjs +5 -4
  58. package/dist/transactions/marginLiquidations.mjs.map +1 -1
  59. package/dist/transactions/marginMaintainer.d.mts +5 -5
  60. package/dist/transactions/marginMaintainer.d.mts.map +1 -1
  61. package/dist/transactions/marginMaintainer.mjs +15 -14
  62. package/dist/transactions/marginMaintainer.mjs.map +1 -1
  63. package/dist/transactions/marginManager.d.mts +23 -23
  64. package/dist/transactions/marginManager.d.mts.map +1 -1
  65. package/dist/transactions/marginManager.mjs +17 -12
  66. package/dist/transactions/marginManager.mjs.map +1 -1
  67. package/dist/transactions/marginPool.d.mts.map +1 -1
  68. package/dist/transactions/marginPool.mjs +3 -2
  69. package/dist/transactions/marginPool.mjs.map +1 -1
  70. package/dist/transactions/marginTPSL.d.mts +1 -1
  71. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  72. package/dist/transactions/marginTPSL.mjs +6 -8
  73. package/dist/transactions/marginTPSL.mjs.map +1 -1
  74. package/dist/transactions/poolProxy.d.mts.map +1 -1
  75. package/dist/transactions/poolProxy.mjs +13 -13
  76. package/dist/transactions/poolProxy.mjs.map +1 -1
  77. package/dist/types/index.d.mts +189 -52
  78. package/dist/types/index.d.mts.map +1 -1
  79. package/dist/types/index.mjs.map +1 -1
  80. package/dist/utils/constants.d.mts +4 -0
  81. package/dist/utils/constants.d.mts.map +1 -1
  82. package/dist/utils/constants.mjs +12 -5
  83. package/dist/utils/constants.mjs.map +1 -1
  84. package/dist/utils/conversion.mjs +26 -0
  85. package/dist/utils/conversion.mjs.map +1 -0
  86. package/package.json +6 -5
  87. package/src/client.ts +421 -2662
  88. package/src/index.ts +27 -0
  89. package/src/queries/accountQueries.ts +117 -0
  90. package/src/queries/balanceManagerQueries.ts +156 -0
  91. package/src/queries/context.ts +44 -0
  92. package/src/queries/index.ts +16 -0
  93. package/src/queries/marginManagerQueries.ts +575 -0
  94. package/src/queries/marginPoolQueries.ts +226 -0
  95. package/src/queries/orderQueries.ts +202 -0
  96. package/src/queries/poolQueries.ts +266 -0
  97. package/src/queries/priceFeedQueries.ts +141 -0
  98. package/src/queries/quantityQueries.ts +266 -0
  99. package/src/queries/referralQueries.ts +112 -0
  100. package/src/queries/registryQueries.ts +185 -0
  101. package/src/queries/tpslQueries.ts +88 -0
  102. package/src/transactions/balanceManager.ts +5 -4
  103. package/src/transactions/deepbook.ts +98 -84
  104. package/src/transactions/deepbookAdmin.ts +10 -9
  105. package/src/transactions/flashLoans.ts +5 -4
  106. package/src/transactions/governance.ts +5 -4
  107. package/src/transactions/marginAdmin.ts +8 -7
  108. package/src/transactions/marginLiquidations.ts +5 -4
  109. package/src/transactions/marginMaintainer.ts +15 -14
  110. package/src/transactions/marginManager.ts +13 -12
  111. package/src/transactions/marginPool.ts +3 -2
  112. package/src/transactions/marginTPSL.ts +11 -6
  113. package/src/transactions/poolProxy.ts +12 -11
  114. package/src/types/index.ts +200 -53
  115. package/src/utils/constants.ts +12 -5
  116. package/src/utils/conversion.ts +33 -0
@@ -0,0 +1,96 @@
1
+ import { DEEP_SCALAR, FLOAT_SCALAR } from "../utils/config.mjs";
2
+ import { bcs } from "@mysten/sui/bcs";
3
+ import { Transaction } from "@mysten/sui/transactions";
4
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
5
+
6
+ //#region src/queries/referralQueries.ts
7
+ var ReferralQueries = class {
8
+ #ctx;
9
+ constructor(ctx) {
10
+ this.#ctx = ctx;
11
+ }
12
+ async balanceManagerReferralOwner(referral) {
13
+ const tx = new Transaction();
14
+ tx.add(this.#ctx.balanceManager.balanceManagerReferralOwner(referral));
15
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
16
+ transaction: tx,
17
+ include: {
18
+ commandResults: true,
19
+ effects: true
20
+ }
21
+ })).commandResults[0].returnValues[0].bcs;
22
+ return bcs.Address.parse(bytes);
23
+ }
24
+ async getPoolReferralBalances(poolKey, referral) {
25
+ const tx = new Transaction();
26
+ const pool = this.#ctx.config.getPool(poolKey);
27
+ const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
28
+ const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
29
+ tx.add(this.#ctx.deepBook.getPoolReferralBalances(poolKey, referral));
30
+ const res = await this.#ctx.client.core.simulateTransaction({
31
+ transaction: tx,
32
+ include: {
33
+ commandResults: true,
34
+ effects: true
35
+ }
36
+ });
37
+ const baseBytes = res.commandResults[0].returnValues[0].bcs;
38
+ const quoteBytes = res.commandResults[0].returnValues[1].bcs;
39
+ const deepBytes = res.commandResults[0].returnValues[2].bcs;
40
+ const baseBalance = Number(bcs.U64.parse(baseBytes));
41
+ const quoteBalance = Number(bcs.U64.parse(quoteBytes));
42
+ const deepBalance = Number(bcs.U64.parse(deepBytes));
43
+ return {
44
+ base: baseBalance / baseScalar,
45
+ quote: quoteBalance / quoteScalar,
46
+ deep: deepBalance / DEEP_SCALAR
47
+ };
48
+ }
49
+ async balanceManagerReferralPoolId(referral) {
50
+ const tx = new Transaction();
51
+ tx.add(this.#ctx.balanceManager.balanceManagerReferralPoolId(referral));
52
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
53
+ transaction: tx,
54
+ include: {
55
+ commandResults: true,
56
+ effects: true
57
+ }
58
+ })).commandResults[0].returnValues[0].bcs;
59
+ return normalizeSuiAddress(bcs.Address.parse(bytes));
60
+ }
61
+ async poolReferralMultiplier(poolKey, referral) {
62
+ const tx = new Transaction();
63
+ tx.add(this.#ctx.deepBook.poolReferralMultiplier(poolKey, referral));
64
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
65
+ transaction: tx,
66
+ include: {
67
+ commandResults: true,
68
+ effects: true
69
+ }
70
+ })).commandResults[0].returnValues[0].bcs;
71
+ return Number(bcs.U64.parse(bytes)) / FLOAT_SCALAR;
72
+ }
73
+ async getBalanceManagerReferralId(managerKey, poolKey) {
74
+ const tx = new Transaction();
75
+ tx.add(this.#ctx.balanceManager.getBalanceManagerReferralId(managerKey, poolKey));
76
+ const res = await this.#ctx.client.core.simulateTransaction({
77
+ transaction: tx,
78
+ include: {
79
+ commandResults: true,
80
+ effects: true
81
+ }
82
+ });
83
+ try {
84
+ const bytes = res.commandResults[0].returnValues[0].bcs;
85
+ const optionId = bcs.option(bcs.Address).parse(bytes);
86
+ if (optionId === null) return null;
87
+ return normalizeSuiAddress(optionId);
88
+ } catch {
89
+ return null;
90
+ }
91
+ }
92
+ };
93
+
94
+ //#endregion
95
+ export { ReferralQueries };
96
+ //# sourceMappingURL=referralQueries.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referralQueries.mjs","names":["#ctx"],"sources":["../../src/queries/referralQueries.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport type { ReferralBalances } from '../types/index.js';\nimport { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';\nimport type { QueryContext } from './context.js';\n\nexport class ReferralQueries {\n\t#ctx: QueryContext;\n\n\tconstructor(ctx: QueryContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\tasync balanceManagerReferralOwner(referral: string): Promise<string> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.balanceManager.balanceManagerReferralOwner(referral));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.Address.parse(bytes);\n\t}\n\n\tasync getPoolReferralBalances(poolKey: string, referral: string): Promise<ReferralBalances> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getPoolReferralBalances(poolKey, referral));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseBytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst quoteBytes = res.commandResults![0].returnValues[1].bcs;\n\t\tconst deepBytes = res.commandResults![0].returnValues[2].bcs;\n\n\t\tconst baseBalance = Number(bcs.U64.parse(baseBytes));\n\t\tconst quoteBalance = Number(bcs.U64.parse(quoteBytes));\n\t\tconst deepBalance = Number(bcs.U64.parse(deepBytes));\n\n\t\treturn {\n\t\t\tbase: baseBalance / baseScalar,\n\t\t\tquote: quoteBalance / quoteScalar,\n\t\t\tdeep: deepBalance / DEEP_SCALAR,\n\t\t};\n\t}\n\n\tasync balanceManagerReferralPoolId(referral: string): Promise<string> {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.#ctx.balanceManager.balanceManagerReferralPoolId(referral));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst poolId = bcs.Address.parse(bytes);\n\n\t\treturn normalizeSuiAddress(poolId);\n\t}\n\n\tasync poolReferralMultiplier(poolKey: string, referral: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.#ctx.deepBook.poolReferralMultiplier(poolKey, referral));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst multiplier = Number(bcs.U64.parse(bytes));\n\n\t\treturn multiplier / FLOAT_SCALAR;\n\t}\n\n\tasync getBalanceManagerReferralId(managerKey: string, poolKey: string): Promise<string | null> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.balanceManager.getBalanceManagerReferralId(managerKey, poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\ttry {\n\t\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\t\tconst optionId = bcs.option(bcs.Address).parse(bytes);\n\t\t\tif (optionId === null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn normalizeSuiAddress(optionId);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAWA,IAAa,kBAAb,MAA6B;CAC5B;CAEA,YAAY,KAAmB;AAC9B,QAAKA,MAAO;;CAGb,MAAM,4BAA4B,UAAmC;EACpE,MAAM,KAAK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AM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAAG;AAGrD,SAAO,oBAFQ,IAAI,QAAQ,MAAM,MAAM,CAEL;;CAGnC,MAAM,uBAAuB,SAAiB,UAAmC;EAChF,MAAM,KAAK,IAAI,aAAa;AAE5B,KAAG,IAAI,MAAKA,IAAK,SAAS,uBAAuB,SAAS,SAAS,CAAC;EAOpE,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAAG;AAGrD,SAFmB,OAAO,IAAI,IAAI,MAAM,MAAM,CAAC,GAE3B;;CAGrB,MAAM,4BAA4B,YAAoB,SAAyC;EAC9F,MAAM,KAAK,IAAI,aAAa;AAC5B,KAAG,IAAI,MAAKA,IAAK,eAAe,4BAA4B,YAAY,QAAQ,CAAC;EAEjF,MAAM,MAAM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC;AAEF,MAAI;GACH,MAAM,QAAQ,IAAI,eAAgB,GAAG,aAAa,GAAG;GACrD,MAAM,WAAW,IAAI,OAAO,IAAI,QAAQ,CAAC,MAAM,MAAM;AACrD,OAAI,aAAa,KAChB,QAAO;AAER,UAAO,oBAAoB,SAAS;UAC7B;AACP,UAAO"}
@@ -0,0 +1,162 @@
1
+ import { VecSet } from "../contracts/deepbook/deps/sui/vec_set.mjs";
2
+ import "../types/bcs.mjs";
3
+ import { FLOAT_SCALAR } from "../utils/config.mjs";
4
+ import { bcs } from "@mysten/sui/bcs";
5
+ import { Transaction } from "@mysten/sui/transactions";
6
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
7
+
8
+ //#region src/queries/registryQueries.ts
9
+ var RegistryQueries = class {
10
+ #ctx;
11
+ constructor(ctx) {
12
+ this.#ctx = ctx;
13
+ }
14
+ async isPoolEnabledForMargin(poolKey) {
15
+ const tx = new Transaction();
16
+ tx.add(this.#ctx.marginRegistry.poolEnabled(poolKey));
17
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
18
+ transaction: tx,
19
+ include: {
20
+ commandResults: true,
21
+ effects: true
22
+ }
23
+ })).commandResults[0].returnValues[0].bcs;
24
+ return bcs.Bool.parse(bytes);
25
+ }
26
+ async getMarginManagerIdsForOwner(owner) {
27
+ const tx = new Transaction();
28
+ tx.add(this.#ctx.marginRegistry.getMarginManagerIds(owner));
29
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
30
+ transaction: tx,
31
+ include: {
32
+ commandResults: true,
33
+ effects: true
34
+ }
35
+ })).commandResults[0].returnValues[0].bcs;
36
+ return VecSet(bcs.Address).parse(bytes).contents.map((id) => normalizeSuiAddress(id));
37
+ }
38
+ async getBaseMarginPoolId(poolKey) {
39
+ const tx = new Transaction();
40
+ tx.add(this.#ctx.marginRegistry.baseMarginPoolId(poolKey));
41
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
42
+ transaction: tx,
43
+ include: {
44
+ commandResults: true,
45
+ effects: true
46
+ }
47
+ })).commandResults[0].returnValues[0].bcs;
48
+ return "0x" + bcs.Address.parse(bytes);
49
+ }
50
+ async getQuoteMarginPoolId(poolKey) {
51
+ const tx = new Transaction();
52
+ tx.add(this.#ctx.marginRegistry.quoteMarginPoolId(poolKey));
53
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
54
+ transaction: tx,
55
+ include: {
56
+ commandResults: true,
57
+ effects: true
58
+ }
59
+ })).commandResults[0].returnValues[0].bcs;
60
+ return "0x" + bcs.Address.parse(bytes);
61
+ }
62
+ async getMinWithdrawRiskRatio(poolKey) {
63
+ const tx = new Transaction();
64
+ tx.add(this.#ctx.marginRegistry.minWithdrawRiskRatio(poolKey));
65
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
66
+ transaction: tx,
67
+ include: {
68
+ commandResults: true,
69
+ effects: true
70
+ }
71
+ })).commandResults[0].returnValues[0].bcs;
72
+ return Number(bcs.U64.parse(bytes)) / FLOAT_SCALAR;
73
+ }
74
+ async getMinBorrowRiskRatio(poolKey) {
75
+ const tx = new Transaction();
76
+ tx.add(this.#ctx.marginRegistry.minBorrowRiskRatio(poolKey));
77
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
78
+ transaction: tx,
79
+ include: {
80
+ commandResults: true,
81
+ effects: true
82
+ }
83
+ })).commandResults[0].returnValues[0].bcs;
84
+ return Number(bcs.U64.parse(bytes)) / FLOAT_SCALAR;
85
+ }
86
+ async getLiquidationRiskRatio(poolKey) {
87
+ const tx = new Transaction();
88
+ tx.add(this.#ctx.marginRegistry.liquidationRiskRatio(poolKey));
89
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
90
+ transaction: tx,
91
+ include: {
92
+ commandResults: true,
93
+ effects: true
94
+ }
95
+ })).commandResults[0].returnValues[0].bcs;
96
+ return Number(bcs.U64.parse(bytes)) / FLOAT_SCALAR;
97
+ }
98
+ async getTargetLiquidationRiskRatio(poolKey) {
99
+ const tx = new Transaction();
100
+ tx.add(this.#ctx.marginRegistry.targetLiquidationRiskRatio(poolKey));
101
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
102
+ transaction: tx,
103
+ include: {
104
+ commandResults: true,
105
+ effects: true
106
+ }
107
+ })).commandResults[0].returnValues[0].bcs;
108
+ return Number(bcs.U64.parse(bytes)) / FLOAT_SCALAR;
109
+ }
110
+ async getUserLiquidationReward(poolKey) {
111
+ const tx = new Transaction();
112
+ tx.add(this.#ctx.marginRegistry.userLiquidationReward(poolKey));
113
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
114
+ transaction: tx,
115
+ include: {
116
+ commandResults: true,
117
+ effects: true
118
+ }
119
+ })).commandResults[0].returnValues[0].bcs;
120
+ return Number(bcs.U64.parse(bytes)) / FLOAT_SCALAR;
121
+ }
122
+ async getPoolLiquidationReward(poolKey) {
123
+ const tx = new Transaction();
124
+ tx.add(this.#ctx.marginRegistry.poolLiquidationReward(poolKey));
125
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
126
+ transaction: tx,
127
+ include: {
128
+ commandResults: true,
129
+ effects: true
130
+ }
131
+ })).commandResults[0].returnValues[0].bcs;
132
+ return Number(bcs.U64.parse(bytes)) / FLOAT_SCALAR;
133
+ }
134
+ async getAllowedMaintainers() {
135
+ const tx = new Transaction();
136
+ tx.add(this.#ctx.marginRegistry.allowedMaintainers());
137
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
138
+ transaction: tx,
139
+ include: {
140
+ commandResults: true,
141
+ effects: true
142
+ }
143
+ })).commandResults[0].returnValues[0].bcs;
144
+ return VecSet(bcs.Address).parse(bytes).contents.map((id) => normalizeSuiAddress(id));
145
+ }
146
+ async getAllowedPauseCaps() {
147
+ const tx = new Transaction();
148
+ tx.add(this.#ctx.marginRegistry.allowedPauseCaps());
149
+ const bytes = (await this.#ctx.client.core.simulateTransaction({
150
+ transaction: tx,
151
+ include: {
152
+ commandResults: true,
153
+ effects: true
154
+ }
155
+ })).commandResults[0].returnValues[0].bcs;
156
+ return VecSet(bcs.Address).parse(bytes).contents.map((id) => normalizeSuiAddress(id));
157
+ }
158
+ };
159
+
160
+ //#endregion
161
+ export { RegistryQueries };
162
+ //# sourceMappingURL=registryQueries.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registryQueries.mjs","names":["#ctx"],"sources":["../../src/queries/registryQueries.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport { VecSet } from '../types/bcs.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\nimport type { QueryContext } from './context.js';\n\nexport class RegistryQueries {\n\t#ctx: QueryContext;\n\n\tconstructor(ctx: QueryContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\tasync isPoolEnabledForMargin(poolKey: string): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.poolEnabled(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.Bool.parse(bytes);\n\t}\n\n\tasync getMarginManagerIdsForOwner(owner: string): Promise<string[]> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.getMarginManagerIds(owner));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst vecSet = VecSet(bcs.Address).parse(bytes);\n\t\treturn vecSet.contents.map((id) => normalizeSuiAddress(id));\n\t}\n\n\tasync getBaseMarginPoolId(poolKey: string): Promise<string> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.baseMarginPoolId(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst id = bcs.Address.parse(bytes);\n\t\treturn '0x' + id;\n\t}\n\n\tasync getQuoteMarginPoolId(poolKey: string): Promise<string> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.quoteMarginPoolId(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst id = bcs.Address.parse(bytes);\n\t\treturn '0x' + id;\n\t}\n\n\tasync getMinWithdrawRiskRatio(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.minWithdrawRiskRatio(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst ratio = Number(bcs.U64.parse(bytes));\n\t\treturn ratio / FLOAT_SCALAR;\n\t}\n\n\tasync getMinBorrowRiskRatio(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.minBorrowRiskRatio(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst ratio = Number(bcs.U64.parse(bytes));\n\t\treturn ratio / FLOAT_SCALAR;\n\t}\n\n\tasync getLiquidationRiskRatio(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.liquidationRiskRatio(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst ratio = Number(bcs.U64.parse(bytes));\n\t\treturn ratio / FLOAT_SCALAR;\n\t}\n\n\tasync getTargetLiquidationRiskRatio(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.targetLiquidationRiskRatio(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst ratio = Number(bcs.U64.parse(bytes));\n\t\treturn ratio / FLOAT_SCALAR;\n\t}\n\n\tasync getUserLiquidationReward(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.userLiquidationReward(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst reward = Number(bcs.U64.parse(bytes));\n\t\treturn reward / FLOAT_SCALAR;\n\t}\n\n\tasync getPoolLiquidationReward(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.poolLiquidationReward(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst reward = Number(bcs.U64.parse(bytes));\n\t\treturn reward / FLOAT_SCALAR;\n\t}\n\n\tasync getAllowedMaintainers(): Promise<string[]> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.allowedMaintainers());\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst vecSet = VecSet(bcs.Address).parse(bytes);\n\t\treturn vecSet.contents.map((id) => normalizeSuiAddress(id));\n\t}\n\n\tasync getAllowedPauseCaps(): Promise<string[]> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginRegistry.allowedPauseCaps());\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst vecSet = VecSet(bcs.Address).parse(bytes);\n\t\treturn vecSet.contents.map((id) => normalizeSuiAddress(id));\n\t}\n}\n"],"mappings":";;;;;;;;AAWA,IAAa,kBAAb,MAA6B;CAC5B;CAEA,YAAY,KAAmB;AAC9B,QAAKA,MAAO;;CAGb,MAAM,uBAAuB,SAAmC;EAC/D,MAAM,KAAK,IAAI,aAAa;AAC5B,KAAG,IAAI,MAAKA,IAAK,eAAe,YAAY,QAAQ,CAAC;EAOrD,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAAG;AACrD,SAAO,IAAI,KAAK,MAAM,MAAM;;CAG7B,MAAM,4BAA4B,OAAkC;EACnE,MAAM,KAAK,IAAI,aAAa;AAC5B,KAAG,IAAI,MAAKA,IAAK,eAAe,oBAAoB,MAAM,CAAC;EAO3D,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAAG;AAErD,SADe,OAAO,IAAI,QAAQ,CAAC,MAAM,MAAM,CACjC,SAAS,KAAK,OAAO,oBAAoB,GAAG,CAAC;;CAG5D,MAAM,oBAAoB,SAAkC;EAC3D,MAAM,KAAK,IAAI,aAAa;AAC5B,KAAG,IAAI,MAAKA,IAAK,eAAe,iBAAiB,QAAQ,CAAC;EAO1D,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAA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AAoB,CAAC;EAOrD,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAAG;AAErD,SADe,OAAO,IAAI,QAAQ,CAAC,MAAM,MAAM,CACjC,SAAS,KAAK,OAAO,oBAAoB,GAAG,CAAC;;CAG5D,MAAM,sBAAyC;EAC9C,MAAM,KAAK,IAAI,aAAa;AAC5B,KAAG,IAAI,MAAKA,IAAK,eAAe,kBAAkB,CAAC;EAOnD,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAAG;AAErD,SADe,OAAO,IAAI,QAAQ,CAAC,MAAM,MAAM,CACjC,SAAS,KAAK,OAAO,oBAAoB,GAAG,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { bcs } from "@mysten/sui/bcs";
2
+ import { Transaction } from "@mysten/sui/transactions";
3
+
4
+ //#region src/queries/tpslQueries.ts
5
+ var TPSLQueries = class {
6
+ #ctx;
7
+ constructor(ctx) {
8
+ this.#ctx = ctx;
9
+ }
10
+ async getConditionalOrderIds(marginManagerKey) {
11
+ const manager = this.#ctx.config.getMarginManager(marginManagerKey);
12
+ const tx = new Transaction();
13
+ tx.add(this.#ctx.marginTPSL.conditionalOrderIds(manager.poolKey, manager.address));
14
+ const res = await this.#ctx.client.core.simulateTransaction({
15
+ transaction: tx,
16
+ include: {
17
+ commandResults: true,
18
+ effects: true
19
+ }
20
+ });
21
+ if (res.FailedTransaction) throw new Error(`Transaction failed: ${res.FailedTransaction.status.error?.message || "Unknown error"}`);
22
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) throw new Error(`Failed to get conditional order IDs: Unknown error`);
23
+ const bytes = res.commandResults[0].returnValues[0].bcs;
24
+ return bcs.vector(bcs.u64()).parse(bytes).map((id) => id.toString());
25
+ }
26
+ async getLowestTriggerAbovePrice(marginManagerKey) {
27
+ const manager = this.#ctx.config.getMarginManager(marginManagerKey);
28
+ const tx = new Transaction();
29
+ tx.add(this.#ctx.marginTPSL.lowestTriggerAbovePrice(manager.poolKey, manager.address));
30
+ const res = await this.#ctx.client.core.simulateTransaction({
31
+ transaction: tx,
32
+ include: {
33
+ commandResults: true,
34
+ effects: true
35
+ }
36
+ });
37
+ if (res.FailedTransaction) throw new Error(`Transaction failed: ${res.FailedTransaction.status.error?.message || "Unknown error"}`);
38
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) throw new Error(`Failed to get lowest trigger above price: Unknown error`);
39
+ const bytes = res.commandResults[0].returnValues[0].bcs;
40
+ return BigInt(bcs.U64.parse(bytes));
41
+ }
42
+ async getHighestTriggerBelowPrice(marginManagerKey) {
43
+ const manager = this.#ctx.config.getMarginManager(marginManagerKey);
44
+ const tx = new Transaction();
45
+ tx.add(this.#ctx.marginTPSL.highestTriggerBelowPrice(manager.poolKey, manager.address));
46
+ const res = await this.#ctx.client.core.simulateTransaction({
47
+ transaction: tx,
48
+ include: {
49
+ commandResults: true,
50
+ effects: true
51
+ }
52
+ });
53
+ if (res.FailedTransaction) throw new Error(`Transaction failed: ${res.FailedTransaction.status.error?.message || "Unknown error"}`);
54
+ if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) throw new Error(`Failed to get highest trigger below price: Unknown error`);
55
+ const bytes = res.commandResults[0].returnValues[0].bcs;
56
+ return BigInt(bcs.U64.parse(bytes));
57
+ }
58
+ };
59
+
60
+ //#endregion
61
+ export { TPSLQueries };
62
+ //# sourceMappingURL=tpslQueries.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tpslQueries.mjs","names":["#ctx"],"sources":["../../src/queries/tpslQueries.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { Transaction } from '@mysten/sui/transactions';\n\nimport type { QueryContext } from './context.js';\n\nexport class TPSLQueries {\n\t#ctx: QueryContext;\n\n\tconstructor(ctx: QueryContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\tasync getConditionalOrderIds(marginManagerKey: string): Promise<string[]> {\n\t\tconst manager = this.#ctx.config.getMarginManager(marginManagerKey);\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginTPSL.conditionalOrderIds(manager.poolKey, manager.address));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tif (res.FailedTransaction) {\n\t\t\tthrow new Error(\n\t\t\t\t`Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,\n\t\t\t);\n\t\t}\n\n\t\tif (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {\n\t\t\tthrow new Error(`Failed to get conditional order IDs: Unknown error`);\n\t\t}\n\n\t\tconst bytes = res.commandResults[0].returnValues[0].bcs;\n\t\tconst orderIds = bcs.vector(bcs.u64()).parse(bytes);\n\t\treturn orderIds.map((id) => id.toString());\n\t}\n\n\tasync getLowestTriggerAbovePrice(marginManagerKey: string): Promise<bigint> {\n\t\tconst manager = this.#ctx.config.getMarginManager(marginManagerKey);\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginTPSL.lowestTriggerAbovePrice(manager.poolKey, manager.address));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tif (res.FailedTransaction) {\n\t\t\tthrow new Error(\n\t\t\t\t`Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,\n\t\t\t);\n\t\t}\n\n\t\tif (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {\n\t\t\tthrow new Error(`Failed to get lowest trigger above price: Unknown error`);\n\t\t}\n\n\t\tconst bytes = res.commandResults[0].returnValues[0].bcs;\n\t\treturn BigInt(bcs.U64.parse(bytes));\n\t}\n\n\tasync getHighestTriggerBelowPrice(marginManagerKey: string): Promise<bigint> {\n\t\tconst manager = this.#ctx.config.getMarginManager(marginManagerKey);\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.marginTPSL.highestTriggerBelowPrice(manager.poolKey, manager.address));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tif (res.FailedTransaction) {\n\t\t\tthrow new Error(\n\t\t\t\t`Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,\n\t\t\t);\n\t\t}\n\n\t\tif (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {\n\t\t\tthrow new Error(`Failed to get highest trigger below price: Unknown error`);\n\t\t}\n\n\t\tconst bytes = res.commandResults[0].returnValues[0].bcs;\n\t\treturn BigInt(bcs.U64.parse(bytes));\n\t}\n}\n"],"mappings":";;;;AAQA,IAAa,cAAb,MAAyB;CACxB;CAEA,YAAY,KAAmB;AAC9B,QAAKA,MAAO;;CAGb,MAAM,uBAAuB,kBAA6C;EACzE,MAAM,UAAU,MAAKA,IAAK,OAAO,iBAAiB,iBAAiB;EACnE,MAAM,KAAK,IAAI,aAAa;AAC5B,KAAG,IAAI,MAAKA,IAAK,WAAW,oBAAoB,QAAQ,SAAS,QAAQ,QAAQ,CAAC;EAElF,MAAM,MAAM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC;AAEF,MAAI,IAAI,kBACP,OAAM,IAAI,MACT,uBAAuB,IAAI,kBAAkB,OAAO,OAAO,WAAW,kBACtE;AAGF,MAAI,CA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AI,MACT,uBAAuB,IAAI,kBAAkB,OAAO,OAAO,WAAW,kBACtE;AAGF,MAAI,CAAC,IAAI,kBAAkB,CAAC,IAAI,eAAe,MAAM,CAAC,IAAI,eAAe,GAAG,aAC3E,OAAM,IAAI,MAAM,2DAA2D;EAG5E,MAAM,QAAQ,IAAI,eAAe,GAAG,aAAa,GAAG;AACpD,SAAO,OAAO,IAAI,IAAI,MAAM,MAAM,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { DeepBookConfig } from "../utils/config.mjs";
2
- import * as _mysten_sui_transactions0 from "@mysten/sui/transactions";
2
+ import * as _mysten_sui_transactions21 from "@mysten/sui/transactions";
3
3
  import { Transaction, TransactionArgument } from "@mysten/sui/transactions";
4
4
 
5
5
  //#region src/transactions/balanceManager.d.ts
@@ -21,7 +21,7 @@ declare class BalanceManagerContract {
21
21
  * @description Create a new BalanceManager, manually set the owner. Returns the manager.
22
22
  * @returns A function that takes a Transaction object
23
23
  */
24
- createBalanceManagerWithOwner: (ownerAddress: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
24
+ createBalanceManagerWithOwner: (ownerAddress: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
25
25
  /**
26
26
  * @description Share the BalanceManager
27
27
  * @param {TransactionArgument} manager The BalanceManager to share
@@ -65,38 +65,38 @@ declare class BalanceManagerContract {
65
65
  * @param {string} managerKey The key of the BalanceManager
66
66
  * @returns A function that takes a Transaction object
67
67
  */
68
- generateProof: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
68
+ generateProof: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
69
69
  /**
70
70
  * @description Generate a trade proof as the owner
71
71
  * @param {string} managerId The ID of the BalanceManager
72
72
  * @returns A function that takes a Transaction object
73
73
  */
74
- generateProofAsOwner: (managerId: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
74
+ generateProofAsOwner: (managerId: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
75
75
  /**
76
76
  * @description Generate a trade proof as a trader
77
77
  * @param {string} managerId The ID of the BalanceManager
78
78
  * @param {string} tradeCapId The ID of the tradeCap
79
79
  * @returns A function that takes a Transaction object
80
80
  */
81
- generateProofAsTrader: (managerId: string, tradeCapId: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
81
+ generateProofAsTrader: (managerId: string, tradeCapId: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
82
82
  /**
83
83
  * @description Mint a TradeCap
84
84
  * @param {string} managerKey The name of the BalanceManager
85
85
  * @returns A function that takes a Transaction object
86
86
  */
87
- mintTradeCap: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
87
+ mintTradeCap: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
88
88
  /**
89
89
  * @description Mint a DepositCap
90
90
  * @param {string} managerKey The name of the BalanceManager
91
91
  * @returns A function that takes a Transaction object
92
92
  */
93
- mintDepositCap: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
93
+ mintDepositCap: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
94
94
  /**
95
95
  * @description Mint a WithdrawalCap
96
96
  * @param {string} managerKey The name of the BalanceManager
97
97
  * @returns A function that takes a Transaction object
98
98
  */
99
- mintWithdrawalCap: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
99
+ mintWithdrawalCap: (managerKey: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
100
100
  /**
101
101
  * @description Deposit using the DepositCap
102
102
  * @param {string} managerKey The name of the BalanceManager
@@ -112,7 +112,7 @@ declare class BalanceManagerContract {
112
112
  * @param {number} amountToWithdraw The amount to withdraw
113
113
  * @returns A function that takes a Transaction object
114
114
  */
115
- withdrawWithCap: (managerKey: string, coinKey: string, amountToWithdraw: number) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
115
+ withdrawWithCap: (managerKey: string, coinKey: string, amountToWithdraw: number) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
116
116
  /**
117
117
  * @description Set the referral for the BalanceManager for a specific pool
118
118
  * @param {string} managerKey The name of the BalanceManager
@@ -147,20 +147,20 @@ declare class BalanceManagerContract {
147
147
  * @param {string} referralId The ID of the referral to get the owner of
148
148
  * @returns A function that takes a Transaction object
149
149
  */
150
- balanceManagerReferralOwner: (referralId: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
150
+ balanceManagerReferralOwner: (referralId: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
151
151
  /**
152
152
  * @description Get the pool ID associated with a referral (DeepBookPoolReferral)
153
153
  * @param {string} referralId The ID of the referral to get the pool ID of
154
154
  * @returns A function that takes a Transaction object
155
155
  */
156
- balanceManagerReferralPoolId: (referralId: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
156
+ balanceManagerReferralPoolId: (referralId: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
157
157
  /**
158
158
  * @description Get the referral ID from the balance manager for a specific pool
159
159
  * @param {string} managerKey The name of the BalanceManager
160
160
  * @param {string} poolKey Key of the pool to get the referral for
161
161
  * @returns A function that takes a Transaction object
162
162
  */
163
- getBalanceManagerReferralId: (managerKey: string, poolKey: string) => (tx: Transaction) => _mysten_sui_transactions0.TransactionResult;
163
+ getBalanceManagerReferralId: (managerKey: string, poolKey: string) => (tx: Transaction) => _mysten_sui_transactions21.TransactionResult;
164
164
  /**
165
165
  * @description Revoke a TradeCap. This also revokes the associated DepositCap and WithdrawCap.
166
166
  * @param {string} managerKey The name of the BalanceManager
@@ -1 +1 @@
1
- {"version":3,"file":"balanceManager.d.mts","names":[],"sources":["../../src/transactions/balanceManager.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUa,cAAA,sBAAA,CAAsB;EAMd,CAAA,OAAA;EAQsB;;;EA4BV,WAAA,CAAA,MAAA,EApCZ,cAoCY;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,gBAAW,0BAAA,CAAA;;;;;;6DAYV,gBAAW,0BAAA,CAAA;;;;;;;6EAaK,gBAAW,0BAAA,CAAA;;;;;;;mEAerB"}
@@ -1,3 +1,4 @@
1
+ import { convertQuantity } from "../utils/conversion.mjs";
1
2
  import { coinWithBalance } from "@mysten/sui/transactions";
2
3
 
3
4
  //#region src/transactions/balanceManager.ts
@@ -35,7 +36,7 @@ var BalanceManagerContract = class {
35
36
  tx.setSenderIfNotSet(this.#config.address);
36
37
  const managerId = this.#config.getBalanceManager(managerKey).address;
37
38
  const coin = this.#config.getCoin(coinKey);
38
- const depositInput = Math.round(amountToDeposit * coin.scalar);
39
+ const depositInput = convertQuantity(amountToDeposit, coin.scalar);
39
40
  const deposit = coinWithBalance({
40
41
  type: coin.type,
41
42
  balance: depositInput
@@ -49,7 +50,7 @@ var BalanceManagerContract = class {
49
50
  this.withdrawFromManager = (managerKey, coinKey, amountToWithdraw, recipient) => (tx) => {
50
51
  const managerId = this.#config.getBalanceManager(managerKey).address;
51
52
  const coin = this.#config.getCoin(coinKey);
52
- const withdrawInput = Math.round(amountToWithdraw * coin.scalar);
53
+ const withdrawInput = convertQuantity(amountToWithdraw, coin.scalar);
53
54
  const coinObject = tx.moveCall({
54
55
  target: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`,
55
56
  arguments: [tx.object(managerId), tx.pure.u64(withdrawInput)],
@@ -120,7 +121,7 @@ var BalanceManagerContract = class {
120
121
  if (!manager.depositCap) throw new Error(`DepositCap not set for ${managerKey}`);
121
122
  const depositCapId = manager.depositCap;
122
123
  const coin = this.#config.getCoin(coinKey);
123
- const depositInput = Math.round(amountToDeposit * coin.scalar);
124
+ const depositInput = convertQuantity(amountToDeposit, coin.scalar);
124
125
  const deposit = coinWithBalance({
125
126
  type: coin.type,
126
127
  balance: depositInput
@@ -142,7 +143,7 @@ var BalanceManagerContract = class {
142
143
  if (!manager.withdrawCap) throw new Error(`WithdrawCap not set for ${managerKey}`);
143
144
  const withdrawCapId = manager.withdrawCap;
144
145
  const coin = this.#config.getCoin(coinKey);
145
- const withdrawAmount = Math.round(amountToWithdraw * coin.scalar);
146
+ const withdrawAmount = convertQuantity(amountToWithdraw, coin.scalar);
146
147
  return tx.moveCall({
147
148
  target: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw_with_cap`,
148
149
  arguments: [
@@ -1 +1 @@
1
- {"version":3,"file":"balanceManager.mjs","names":["#config"],"sources":["../../src/transactions/balanceManager.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction, TransactionArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * BalanceManagerContract class for managing BalanceManager operations.\n */\nexport class BalanceManagerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for BalanceManagerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Create and share a new BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAndShareBalanceManager = () => (tx: Transaction) => {\n\t\tconst manager = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::new`,\n\t\t});\n\n\t\ttx.moveCall({\n\t\t\ttarget: '0x2::transfer::public_share_object',\n\t\t\targuments: [manager],\n\t\t\ttypeArguments: [`${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::BalanceManager`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new BalanceManager, manually set the owner. Returns the manager.\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateBalanceManagerWithOwner = (ownerAddress: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::new_with_custom_owner`,\n\t\t\targuments: [tx.pure.address(ownerAddress)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Share the BalanceManager\n\t * @param {TransactionArgument} manager The BalanceManager to share\n\t * @returns A function that takes a Transaction object\n\t */\n\tshareBalanceManager = (manager: TransactionArgument) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: '0x2::transfer::public_share_object',\n\t\t\targuments: [manager],\n\t\t\ttypeArguments: [`${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::BalanceManager`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit funds into the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to deposit\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositIntoManager =\n\t\t(managerKey: string, coinKey: string, amountToDeposit: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = Math.round(amountToDeposit * coin.scalar);\n\t\t\tconst deposit = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::deposit`,\n\t\t\t\targuments: [tx.object(managerId), deposit],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Withdraw funds from the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to withdraw\n\t * @param {number} amountToWithdraw The amount to withdraw\n\t * @param {string} recipient The recipient of the withdrawn funds\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawFromManager =\n\t\t(managerKey: string, coinKey: string, amountToWithdraw: number, recipient: string) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawInput = Math.round(amountToWithdraw * coin.scalar);\n\t\t\tconst coinObject = tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`,\n\t\t\t\targuments: [tx.object(managerId), tx.pure.u64(withdrawInput)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\n\t\t\ttx.transferObjects([coinObject], recipient);\n\t\t};\n\n\t/**\n\t * @description Withdraw all funds from the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to withdraw\n\t * @param {string} recipient The recipient of the withdrawn funds\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawAllFromManager =\n\t\t(managerKey: string, coinKey: string, recipient: string) => (tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawalCoin = tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw_all`,\n\t\t\t\targuments: [tx.object(managerId)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\n\t\t\ttx.transferObjects([withdrawalCoin], recipient);\n\t\t};\n\n\t/**\n\t * @description Check the balance of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to check the balance of\n\t * @returns A function that takes a Transaction object\n\t */\n\tcheckManagerBalance = (managerKey: string, coinKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Generate a trade proof for the BalanceManager. Calls the appropriate function based on whether tradeCap is set.\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProof = (managerKey: string) => (tx: Transaction) => {\n\t\tconst balanceManager = this.#config.getBalanceManager(managerKey);\n\t\treturn tx.add(\n\t\t\tbalanceManager.tradeCap\n\t\t\t\t? this.generateProofAsTrader(balanceManager.address, balanceManager.tradeCap)\n\t\t\t\t: this.generateProofAsOwner(balanceManager.address),\n\t\t);\n\t};\n\n\t/**\n\t * @description Generate a trade proof as the owner\n\t * @param {string} managerId The ID of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProofAsOwner = (managerId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::generate_proof_as_owner`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Generate a trade proof as a trader\n\t * @param {string} managerId The ID of the BalanceManager\n\t * @param {string} tradeCapId The ID of the tradeCap\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProofAsTrader = (managerId: string, tradeCapId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::generate_proof_as_trader`,\n\t\t\targuments: [tx.object(managerId), tx.object(tradeCapId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Mint a TradeCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintTradeCap = (managerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\tconst managerId = manager.address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::mint_trade_cap`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Mint a DepositCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintDepositCap = (managerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\tconst managerId = manager.address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::mint_deposit_cap`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Mint a WithdrawalCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintWithdrawalCap = (managerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\tconst managerId = manager.address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::mint_withdraw_cap`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit using the DepositCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} coinKey The name of the coin to deposit\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositWithCap =\n\t\t(managerKey: string, coinKey: string, amountToDeposit: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\t\tconst managerId = manager.address;\n\t\t\tif (!manager.depositCap) {\n\t\t\t\tthrow new Error(`DepositCap not set for ${managerKey}`);\n\t\t\t}\n\t\t\tconst depositCapId = manager.depositCap;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = Math.round(amountToDeposit * coin.scalar);\n\t\t\tconst deposit = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::deposit_with_cap`,\n\t\t\t\targuments: [tx.object(managerId), tx.object(depositCapId), deposit],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Withdraw using the WithdrawCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} coinKey The name of the coin to withdraw\n\t * @param {number} amountToWithdraw The amount to withdraw\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawWithCap =\n\t\t(managerKey: string, coinKey: string, amountToWithdraw: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\t\tconst managerId = manager.address;\n\t\t\tif (!manager.withdrawCap) {\n\t\t\t\tthrow new Error(`WithdrawCap not set for ${managerKey}`);\n\t\t\t}\n\t\t\tconst withdrawCapId = manager.withdrawCap;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawAmount = Math.round(amountToWithdraw * coin.scalar);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw_with_cap`,\n\t\t\t\targuments: [tx.object(managerId), tx.object(withdrawCapId), tx.pure.u64(withdrawAmount)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Set the referral for the BalanceManager for a specific pool\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} referral The referral (DeepBookPoolReferral) to set the BalanceManager to\n\t * @param {TransactionArgument} tradeCap The tradeCap for permission checking\n\t * @returns A function that takes a Transaction object\n\t */\n\tsetBalanceManagerReferral =\n\t\t(managerKey: string, referral: string, tradeCap: TransactionArgument) => (tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::set_balance_manager_referral`,\n\t\t\t\targuments: [tx.object(managerId), tx.object(referral), tradeCap],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Unset the referral for the BalanceManager for a specific pool\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} poolKey The key of the pool to unset the referral for\n\t * @param {TransactionArgument} tradeCap The tradeCap for permission checking\n\t * @returns A function that takes a Transaction object\n\t */\n\tunsetBalanceManagerReferral =\n\t\t(managerKey: string, poolKey: string, tradeCap: TransactionArgument) => (tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst poolId = this.#config.getPool(poolKey).address;\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::unset_balance_manager_referral`,\n\t\t\t\targuments: [tx.object(managerId), tx.pure.id(poolId), tradeCap],\n\t\t\t});\n\t\t};\n\n\tregisterBalanceManager = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::register_balance_manager`,\n\t\t\targuments: [tx.object(managerId), tx.object(this.#config.REGISTRY_ID)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the owner of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\towner = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::owner`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the ID of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tid = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::id`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the owner of the referral (DeepBookPoolReferral)\n\t * @param {string} referralId The ID of the referral to get the owner of\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalanceManagerReferralOwner = (referralId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance_manager_referral_owner`,\n\t\t\targuments: [tx.object(referralId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the pool ID associated with a referral (DeepBookPoolReferral)\n\t * @param {string} referralId The ID of the referral to get the pool ID of\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalanceManagerReferralPoolId = (referralId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance_manager_referral_pool_id`,\n\t\t\targuments: [tx.object(referralId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the referral ID from the balance manager for a specific pool\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} poolKey Key of the pool to get the referral for\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetBalanceManagerReferralId = (managerKey: string, poolKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\tconst poolId = this.#config.getPool(poolKey).address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::get_balance_manager_referral_id`,\n\t\t\targuments: [tx.object(managerId), tx.pure.id(poolId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a TradeCap. This also revokes the associated DepositCap and WithdrawCap.\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} tradeCapId The ID of the TradeCap to revoke\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokeTradeCap = (managerKey: string, tradeCapId: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::revoke_trade_cap`,\n\t\t\targuments: [tx.object(managerId), tx.pure.id(tradeCapId)],\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;AAUA,IAAa,yBAAb,MAAoC;CACnC;;;;CAKA,YAAY,QAAwB;6CAQE,OAAoB;GACzD,MAAM,UAAU,GAAG,SAAS,EAC3B,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB,yBAC5C,CAAC;AAEF,MAAG,SAAS;IACX,QAAQ;IACR,WAAW,CAAC,QAAQ;IACpB,eAAe,CAAC,GAAG,MAAKA,OAAQ,oBAAoB,mCAAmC;IACvF,CAAC;;wCAO8B,kBAA0B,OAAoB;AAC9E,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW,CAAC,GAAG,KAAK,QAAQ,aAAa,CAAC;IAC1C,CAAC;;8BAQoB,aAAkC,OAAoB;AAC5E,MAAG,SAAS;IACX,QAAQ;IACR,WAAW,CAAC,QAAQ;IACpB,eAAe,CAAC,GAAG,MAAKA,OAAQ,oBAAoB,mCAAmC;IACvF,CAAC;;6BAWD,YAAoB,SAAiB,qBAA6B,OAAoB;AACtF,MAAG,kBAAkB,MAAKA,OAAQ,QAAQ;GAC1C,MAAM,YAAY,MAAKA,OAAQ,kBAAkB,WAAW,CAAC;GAC7D,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,eAAe,KAAK,MAAM,kBAAkB,KAAK,OAAO;GAC9D,MAAM,UAAU,gBAAgB;IAC/B,MAAM,KAAK;IACX,SAAS;IACT,CAAC;AAEF,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW,CAAC,GAAG,OAAO,UAAU,EAAE,QAAQ;IAC1C,eA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AQ,QAAQ,CAAC;AAC7C,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW,CAAC,GAAG,OAAO,UAAU,EAAE,GAAG,KAAK,GAAG,OAAO,CAAC;IACrD,CAAC;;yBASe,YAAoB,gBAAwB,OAAoB;GACjF,MAAM,YAAY,MAAKA,OAAQ,kBAAkB,WAAW,CAAC;AAC7D,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW,CAAC,GAAG,OAAO,UAAU,EAAE,GAAG,KAAK,GAAG,WAAW,CAAC;IACzD,CAAC;;AA3XF,QAAKA,SAAU"}
1
+ {"version":3,"file":"balanceManager.mjs","names":["#config"],"sources":["../../src/transactions/balanceManager.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction, TransactionArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { convertQuantity } from '../utils/conversion.js';\n\n/**\n * BalanceManagerContract class for managing BalanceManager operations.\n */\nexport class BalanceManagerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for BalanceManagerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Create and share a new BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAndShareBalanceManager = () => (tx: Transaction) => {\n\t\tconst manager = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::new`,\n\t\t});\n\n\t\ttx.moveCall({\n\t\t\ttarget: '0x2::transfer::public_share_object',\n\t\t\targuments: [manager],\n\t\t\ttypeArguments: [`${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::BalanceManager`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new BalanceManager, manually set the owner. Returns the manager.\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateBalanceManagerWithOwner = (ownerAddress: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::new_with_custom_owner`,\n\t\t\targuments: [tx.pure.address(ownerAddress)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Share the BalanceManager\n\t * @param {TransactionArgument} manager The BalanceManager to share\n\t * @returns A function that takes a Transaction object\n\t */\n\tshareBalanceManager = (manager: TransactionArgument) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: '0x2::transfer::public_share_object',\n\t\t\targuments: [manager],\n\t\t\ttypeArguments: [`${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::BalanceManager`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit funds into the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to deposit\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositIntoManager =\n\t\t(managerKey: string, coinKey: string, amountToDeposit: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = convertQuantity(amountToDeposit, coin.scalar);\n\t\t\tconst deposit = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::deposit`,\n\t\t\t\targuments: [tx.object(managerId), deposit],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Withdraw funds from the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to withdraw\n\t * @param {number} amountToWithdraw The amount to withdraw\n\t * @param {string} recipient The recipient of the withdrawn funds\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawFromManager =\n\t\t(managerKey: string, coinKey: string, amountToWithdraw: number, recipient: string) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawInput = convertQuantity(amountToWithdraw, coin.scalar);\n\t\t\tconst coinObject = tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`,\n\t\t\t\targuments: [tx.object(managerId), tx.pure.u64(withdrawInput)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\n\t\t\ttx.transferObjects([coinObject], recipient);\n\t\t};\n\n\t/**\n\t * @description Withdraw all funds from the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to withdraw\n\t * @param {string} recipient The recipient of the withdrawn funds\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawAllFromManager =\n\t\t(managerKey: string, coinKey: string, recipient: string) => (tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawalCoin = tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw_all`,\n\t\t\t\targuments: [tx.object(managerId)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\n\t\t\ttx.transferObjects([withdrawalCoin], recipient);\n\t\t};\n\n\t/**\n\t * @description Check the balance of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to check the balance of\n\t * @returns A function that takes a Transaction object\n\t */\n\tcheckManagerBalance = (managerKey: string, coinKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Generate a trade proof for the BalanceManager. Calls the appropriate function based on whether tradeCap is set.\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProof = (managerKey: string) => (tx: Transaction) => {\n\t\tconst balanceManager = this.#config.getBalanceManager(managerKey);\n\t\treturn tx.add(\n\t\t\tbalanceManager.tradeCap\n\t\t\t\t? this.generateProofAsTrader(balanceManager.address, balanceManager.tradeCap)\n\t\t\t\t: this.generateProofAsOwner(balanceManager.address),\n\t\t);\n\t};\n\n\t/**\n\t * @description Generate a trade proof as the owner\n\t * @param {string} managerId The ID of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProofAsOwner = (managerId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::generate_proof_as_owner`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Generate a trade proof as a trader\n\t * @param {string} managerId The ID of the BalanceManager\n\t * @param {string} tradeCapId The ID of the tradeCap\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProofAsTrader = (managerId: string, tradeCapId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::generate_proof_as_trader`,\n\t\t\targuments: [tx.object(managerId), tx.object(tradeCapId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Mint a TradeCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintTradeCap = (managerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\tconst managerId = manager.address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::mint_trade_cap`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Mint a DepositCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintDepositCap = (managerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\tconst managerId = manager.address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::mint_deposit_cap`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Mint a WithdrawalCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintWithdrawalCap = (managerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\tconst managerId = manager.address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::mint_withdraw_cap`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit using the DepositCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} coinKey The name of the coin to deposit\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositWithCap =\n\t\t(managerKey: string, coinKey: string, amountToDeposit: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\t\tconst managerId = manager.address;\n\t\t\tif (!manager.depositCap) {\n\t\t\t\tthrow new Error(`DepositCap not set for ${managerKey}`);\n\t\t\t}\n\t\t\tconst depositCapId = manager.depositCap;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = convertQuantity(amountToDeposit, coin.scalar);\n\t\t\tconst deposit = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::deposit_with_cap`,\n\t\t\t\targuments: [tx.object(managerId), tx.object(depositCapId), deposit],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Withdraw using the WithdrawCap\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} coinKey The name of the coin to withdraw\n\t * @param {number} amountToWithdraw The amount to withdraw\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawWithCap =\n\t\t(managerKey: string, coinKey: string, amountToWithdraw: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst manager = this.#config.getBalanceManager(managerKey);\n\t\t\tconst managerId = manager.address;\n\t\t\tif (!manager.withdrawCap) {\n\t\t\t\tthrow new Error(`WithdrawCap not set for ${managerKey}`);\n\t\t\t}\n\t\t\tconst withdrawCapId = manager.withdrawCap;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawAmount = convertQuantity(amountToWithdraw, coin.scalar);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw_with_cap`,\n\t\t\t\targuments: [tx.object(managerId), tx.object(withdrawCapId), tx.pure.u64(withdrawAmount)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Set the referral for the BalanceManager for a specific pool\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} referral The referral (DeepBookPoolReferral) to set the BalanceManager to\n\t * @param {TransactionArgument} tradeCap The tradeCap for permission checking\n\t * @returns A function that takes a Transaction object\n\t */\n\tsetBalanceManagerReferral =\n\t\t(managerKey: string, referral: string, tradeCap: TransactionArgument) => (tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::set_balance_manager_referral`,\n\t\t\t\targuments: [tx.object(managerId), tx.object(referral), tradeCap],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Unset the referral for the BalanceManager for a specific pool\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} poolKey The key of the pool to unset the referral for\n\t * @param {TransactionArgument} tradeCap The tradeCap for permission checking\n\t * @returns A function that takes a Transaction object\n\t */\n\tunsetBalanceManagerReferral =\n\t\t(managerKey: string, poolKey: string, tradeCap: TransactionArgument) => (tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst poolId = this.#config.getPool(poolKey).address;\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::unset_balance_manager_referral`,\n\t\t\t\targuments: [tx.object(managerId), tx.pure.id(poolId), tradeCap],\n\t\t\t});\n\t\t};\n\n\tregisterBalanceManager = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::register_balance_manager`,\n\t\t\targuments: [tx.object(managerId), tx.object(this.#config.REGISTRY_ID)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the owner of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\towner = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::owner`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the ID of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tid = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::id`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the owner of the referral (DeepBookPoolReferral)\n\t * @param {string} referralId The ID of the referral to get the owner of\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalanceManagerReferralOwner = (referralId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance_manager_referral_owner`,\n\t\t\targuments: [tx.object(referralId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the pool ID associated with a referral (DeepBookPoolReferral)\n\t * @param {string} referralId The ID of the referral to get the pool ID of\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalanceManagerReferralPoolId = (referralId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance_manager_referral_pool_id`,\n\t\t\targuments: [tx.object(referralId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the referral ID from the balance manager for a specific pool\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} poolKey Key of the pool to get the referral for\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetBalanceManagerReferralId = (managerKey: string, poolKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\tconst poolId = this.#config.getPool(poolKey).address;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::get_balance_manager_referral_id`,\n\t\t\targuments: [tx.object(managerId), tx.pure.id(poolId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a TradeCap. This also revokes the associated DepositCap and WithdrawCap.\n\t * @param {string} managerKey The name of the BalanceManager\n\t * @param {string} tradeCapId The ID of the TradeCap to revoke\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokeTradeCap = (managerKey: string, tradeCapId: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::revoke_trade_cap`,\n\t\t\targuments: [tx.object(managerId), tx.pure.id(tradeCapId)],\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;;AAWA,IAAa,yBAAb,MAAoC;CACnC;;;;CAKA,YAAY,QAAwB;6CAQE,OAAoB;GACzD,MAAM,UAAU,GAAG,SAAS,EAC3B,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB,yBAC5C,CAAC;AAEF,MAAG,SAAS;IACX,QAAQ;IACR,WAAW,CAAC,QAAQ;IACpB,eAAe,CAAC,GAAG,MAAKA,OAAQ,oBAAoB,mCAAmC;IACvF,CAAC;;wCAO8B,kBAA0B,OAAoB;AAC9E,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW,CAAC,GAAG,KAAK,QAAQ,aAAa,CAAC;IAC1C,CAAC;;8BAQoB,aAAkC,OAAoB;AAC5E,MAAG,SAAS;IACX,QAAQ;IACR,WAAW,CAAC,QAAQ;IACpB,eAAe,CAAC,GAAG,MAAKA,OAAQ,oBAAoB,mCAAmC;IACvF,CAAC;;6BAWD,YAAoB,SAAiB,qBAA6B,OAAoB;AACtF,MAAG,kBAAkB,MAAKA,OAAQ,QAAQ;GAC1C,MAAM,YAAY,MAAKA,OAAQ,kBAAkB,WAAW,CAAC;GAC7D,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,eAAe,gBAA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