@mysten/deepbook-v3 1.3.5 → 1.4.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 (54) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/contracts/deepbook/account.d.mts +18 -18
  3. package/dist/contracts/deepbook/balances.d.mts +4 -4
  4. package/dist/contracts/deepbook/balances.d.mts.map +1 -1
  5. package/dist/transactions/balanceManager.d.mts +12 -12
  6. package/dist/transactions/deepbook.d.mts +20 -20
  7. package/dist/transactions/deepbookAdmin.d.mts +31 -2
  8. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  9. package/dist/transactions/deepbookAdmin.mjs +34 -2
  10. package/dist/transactions/deepbookAdmin.mjs.map +1 -1
  11. package/dist/transactions/marginAdmin.d.mts +38 -7
  12. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  13. package/dist/transactions/marginAdmin.mjs +48 -0
  14. package/dist/transactions/marginAdmin.mjs.map +1 -1
  15. package/dist/transactions/marginLiquidations.d.mts +3 -3
  16. package/dist/transactions/marginMaintainer.d.mts +5 -5
  17. package/dist/transactions/marginMaintainer.d.mts.map +1 -1
  18. package/dist/transactions/marginMaintainer.mjs +4 -4
  19. package/dist/transactions/marginMaintainer.mjs.map +1 -1
  20. package/dist/transactions/marginManager.d.mts +116 -23
  21. package/dist/transactions/marginManager.d.mts.map +1 -1
  22. package/dist/transactions/marginManager.mjs +133 -1
  23. package/dist/transactions/marginManager.mjs.map +1 -1
  24. package/dist/transactions/marginPool.d.mts +18 -18
  25. package/dist/transactions/marginRegistry.d.mts +15 -15
  26. package/dist/transactions/marginRegistry.d.mts.map +1 -1
  27. package/dist/transactions/marginTPSL.d.mts +14 -11
  28. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  29. package/dist/transactions/marginTPSL.mjs +5 -1
  30. package/dist/transactions/marginTPSL.mjs.map +1 -1
  31. package/dist/transactions/poolProxy.d.mts +19 -9
  32. package/dist/transactions/poolProxy.d.mts.map +1 -1
  33. package/dist/transactions/poolProxy.mjs +31 -21
  34. package/dist/transactions/poolProxy.mjs.map +1 -1
  35. package/dist/types/index.d.mts +1 -1
  36. package/dist/types/index.mjs.map +1 -1
  37. package/dist/utils/config.d.mts +1 -0
  38. package/dist/utils/config.d.mts.map +1 -1
  39. package/dist/utils/config.mjs +3 -0
  40. package/dist/utils/config.mjs.map +1 -1
  41. package/dist/utils/constants.d.mts +3 -0
  42. package/dist/utils/constants.d.mts.map +1 -1
  43. package/dist/utils/constants.mjs +4 -2
  44. package/dist/utils/constants.mjs.map +1 -1
  45. package/package.json +3 -3
  46. package/src/transactions/deepbookAdmin.ts +64 -2
  47. package/src/transactions/marginAdmin.ts +79 -0
  48. package/src/transactions/marginMaintainer.ts +4 -4
  49. package/src/transactions/marginManager.ts +244 -1
  50. package/src/transactions/marginTPSL.ts +10 -3
  51. package/src/transactions/poolProxy.ts +45 -21
  52. package/src/types/index.ts +1 -1
  53. package/src/utils/config.ts +4 -0
  54. package/src/utils/constants.ts +5 -2
@@ -26,7 +26,9 @@ export class PoolProxyContract {
26
26
  }
27
27
 
28
28
  /**
29
- * @description Place a limit order
29
+ * @description Place a limit order. Enforces a post-trade `risk_ratio >=
30
+ * min_borrow_risk_ratio` invariant on the manager (skipped when the manager
31
+ * has no debt).
30
32
  * @param {PlaceMarginLimitOrderParams} params Parameters for placing a limit order
31
33
  * @returns A function that takes a Transaction object
32
34
  */
@@ -47,14 +49,20 @@ export class PoolProxyContract {
47
49
  const manager = this.#config.getMarginManager(marginManagerKey);
48
50
  const baseCoin = this.#config.getCoin(pool.baseCoin);
49
51
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
52
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
53
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
50
54
  const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
51
55
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
52
56
  return tx.moveCall({
53
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_limit_order`,
57
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_limit_order_v2`,
54
58
  arguments: [
55
59
  tx.object(this.#config.MARGIN_REGISTRY_ID),
56
60
  tx.object(manager.address),
57
61
  tx.object(pool.address),
62
+ tx.object(baseMarginPool.address),
63
+ tx.object(quoteMarginPool.address),
64
+ tx.object(baseCoin.priceInfoObjectId!),
65
+ tx.object(quoteCoin.priceInfoObjectId!),
58
66
  tx.pure.u64(clientOrderId),
59
67
  tx.pure.u8(orderType),
60
68
  tx.pure.u8(selfMatchingOption),
@@ -70,7 +78,9 @@ export class PoolProxyContract {
70
78
  };
71
79
 
72
80
  /**
73
- * @description Place a market order
81
+ * @description Place a market order. Enforces a post-trade `risk_ratio >=
82
+ * min_borrow_risk_ratio` invariant on the manager (skipped when the manager
83
+ * has no debt).
74
84
  * @param {PlaceMarginMarketOrderParams} params Parameters for placing a market order
75
85
  * @returns A function that takes a Transaction object
76
86
  */
@@ -88,13 +98,19 @@ export class PoolProxyContract {
88
98
  const manager = this.#config.getMarginManager(marginManagerKey);
89
99
  const baseCoin = this.#config.getCoin(pool.baseCoin);
90
100
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
101
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
102
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
91
103
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
92
104
  return tx.moveCall({
93
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_market_order`,
105
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_market_order_v2`,
94
106
  arguments: [
95
107
  tx.object(this.#config.MARGIN_REGISTRY_ID),
96
108
  tx.object(manager.address),
97
109
  tx.object(pool.address),
110
+ tx.object(baseMarginPool.address),
111
+ tx.object(quoteMarginPool.address),
112
+ tx.object(baseCoin.priceInfoObjectId!),
113
+ tx.object(quoteCoin.priceInfoObjectId!),
98
114
  tx.pure.u64(clientOrderId),
99
115
  tx.pure.u8(selfMatchingOption),
100
116
  tx.pure.u64(inputQuantity),
@@ -107,7 +123,10 @@ export class PoolProxyContract {
107
123
  };
108
124
 
109
125
  /**
110
- * @description Place a reduce only limit order
126
+ * @description Place a reduce only limit order. Requires the manager to have
127
+ * debt on the relevant side; enforces a monotonic `risk_ratio_after >=
128
+ * risk_ratio_before` invariant so the fill cannot leak value to the
129
+ * counterparty.
111
130
  * @param {PlaceMarginLimitOrderParams} params Parameters for placing a reduce only limit order
112
131
  * @returns A function that takes a Transaction object
113
132
  */
@@ -128,19 +147,20 @@ export class PoolProxyContract {
128
147
  const manager = this.#config.getMarginManager(marginManagerKey);
129
148
  const baseCoin = this.#config.getCoin(pool.baseCoin);
130
149
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
150
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
151
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
131
152
  const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
132
153
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
133
- const marginPool = isBid
134
- ? this.#config.getMarginPool(pool.baseCoin)
135
- : this.#config.getMarginPool(pool.quoteCoin);
136
- const debtType = isBid ? baseCoin.type : quoteCoin.type;
137
154
  return tx.moveCall({
138
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_limit_order`,
155
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_limit_order_v2`,
139
156
  arguments: [
140
157
  tx.object(this.#config.MARGIN_REGISTRY_ID),
141
158
  tx.object(manager.address),
142
159
  tx.object(pool.address),
143
- tx.object(marginPool.address),
160
+ tx.object(baseMarginPool.address),
161
+ tx.object(quoteMarginPool.address),
162
+ tx.object(baseCoin.priceInfoObjectId!),
163
+ tx.object(quoteCoin.priceInfoObjectId!),
144
164
  tx.pure.u64(clientOrderId),
145
165
  tx.pure.u8(orderType),
146
166
  tx.pure.u8(selfMatchingOption),
@@ -151,12 +171,15 @@ export class PoolProxyContract {
151
171
  tx.pure.u64(expiration),
152
172
  tx.object.clock(),
153
173
  ],
154
- typeArguments: [baseCoin.type, quoteCoin.type, debtType],
174
+ typeArguments: [baseCoin.type, quoteCoin.type],
155
175
  });
156
176
  };
157
177
 
158
178
  /**
159
- * @description Place a reduce only market order
179
+ * @description Place a reduce only market order. Requires the manager to
180
+ * have debt on the relevant side; enforces a monotonic `risk_ratio_after >=
181
+ * risk_ratio_before` invariant so the fill cannot leak value to the
182
+ * counterparty.
160
183
  * @param {PlaceMarginMarketOrderParams} params Parameters for placing a reduce only market order
161
184
  * @returns A function that takes a Transaction object
162
185
  */
@@ -174,18 +197,19 @@ export class PoolProxyContract {
174
197
  const manager = this.#config.getMarginManager(marginManagerKey);
175
198
  const baseCoin = this.#config.getCoin(pool.baseCoin);
176
199
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
200
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
201
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
177
202
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
178
- const marginPool = isBid
179
- ? this.#config.getMarginPool(pool.baseCoin)
180
- : this.#config.getMarginPool(pool.quoteCoin);
181
- const debtType = isBid ? baseCoin.type : quoteCoin.type;
182
203
  return tx.moveCall({
183
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_market_order`,
204
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_market_order_v2`,
184
205
  arguments: [
185
206
  tx.object(this.#config.MARGIN_REGISTRY_ID),
186
207
  tx.object(manager.address),
187
208
  tx.object(pool.address),
188
- tx.object(marginPool.address),
209
+ tx.object(baseMarginPool.address),
210
+ tx.object(quoteMarginPool.address),
211
+ tx.object(baseCoin.priceInfoObjectId!),
212
+ tx.object(quoteCoin.priceInfoObjectId!),
189
213
  tx.pure.u64(clientOrderId),
190
214
  tx.pure.u8(selfMatchingOption),
191
215
  tx.pure.u64(inputQuantity),
@@ -193,7 +217,7 @@ export class PoolProxyContract {
193
217
  tx.pure.bool(payWithDeep),
194
218
  tx.object.clock(),
195
219
  ],
196
- typeArguments: [baseCoin.type, quoteCoin.type, debtType],
220
+ typeArguments: [baseCoin.type, quoteCoin.type],
197
221
  });
198
222
  };
199
223
 
@@ -427,7 +451,7 @@ export class PoolProxyContract {
427
451
  const baseCoin = this.#config.getCoin(pool.baseCoin);
428
452
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
429
453
  tx.moveCall({
430
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::claim_rebate`,
454
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::claim_rebates`,
431
455
  arguments: [
432
456
  tx.object(this.#config.MARGIN_REGISTRY_ID),
433
457
  tx.object(marginManager.address),
@@ -232,7 +232,7 @@ export interface PoolConfigParams {
232
232
  export interface MarginPoolConfigParams {
233
233
  supplyCap: number | bigint;
234
234
  maxUtilizationRate: number | bigint;
235
- referralSpread: number | bigint;
235
+ protocolSpread: number | bigint;
236
236
  minBorrow: number | bigint;
237
237
  rateLimitCapacity?: number | bigint;
238
238
  rateLimitRefillRatePerMs?: number | bigint;
@@ -49,6 +49,7 @@ export class DeepBookConfig {
49
49
  REGISTRY_ID: string;
50
50
  DEEP_TREASURY_ID: string;
51
51
  MARGIN_PACKAGE_ID: string;
52
+ MARGIN_V1: string;
52
53
  MARGIN_REGISTRY_ID: string;
53
54
  LIQUIDATION_PACKAGE_ID: string;
54
55
  adminCap?: string;
@@ -97,6 +98,7 @@ export class DeepBookConfig {
97
98
  this.REGISTRY_ID = packageIds.REGISTRY_ID || '';
98
99
  this.DEEP_TREASURY_ID = packageIds.DEEP_TREASURY_ID || '';
99
100
  this.MARGIN_PACKAGE_ID = packageIds.MARGIN_PACKAGE_ID || '';
101
+ this.MARGIN_V1 = packageIds.MARGIN_V1 || '';
100
102
  this.MARGIN_REGISTRY_ID = packageIds.MARGIN_REGISTRY_ID || '';
101
103
  this.LIQUIDATION_PACKAGE_ID = packageIds.LIQUIDATION_PACKAGE_ID || '';
102
104
  this.#coins = coins || {};
@@ -111,6 +113,7 @@ export class DeepBookConfig {
111
113
  this.REGISTRY_ID = mainnetPackageIds.REGISTRY_ID;
112
114
  this.DEEP_TREASURY_ID = mainnetPackageIds.DEEP_TREASURY_ID;
113
115
  this.MARGIN_PACKAGE_ID = mainnetPackageIds.MARGIN_PACKAGE_ID;
116
+ this.MARGIN_V1 = mainnetPackageIds.MARGIN_V1;
114
117
  this.MARGIN_REGISTRY_ID = mainnetPackageIds.MARGIN_REGISTRY_ID;
115
118
  this.LIQUIDATION_PACKAGE_ID = mainnetPackageIds.LIQUIDATION_PACKAGE_ID;
116
119
  this.pyth = mainnetPythConfigs;
@@ -122,6 +125,7 @@ export class DeepBookConfig {
122
125
  this.REGISTRY_ID = testnetPackageIds.REGISTRY_ID;
123
126
  this.DEEP_TREASURY_ID = testnetPackageIds.DEEP_TREASURY_ID;
124
127
  this.MARGIN_PACKAGE_ID = testnetPackageIds.MARGIN_PACKAGE_ID;
128
+ this.MARGIN_V1 = testnetPackageIds.MARGIN_V1;
125
129
  this.MARGIN_REGISTRY_ID = testnetPackageIds.MARGIN_REGISTRY_ID;
126
130
  this.LIQUIDATION_PACKAGE_ID = testnetPackageIds.LIQUIDATION_PACKAGE_ID;
127
131
  this.pyth = testnetPythConfigs;
@@ -11,6 +11,7 @@ export interface DeepbookPackageIds {
11
11
  REGISTRY_ID?: string;
12
12
  DEEP_TREASURY_ID?: string;
13
13
  MARGIN_PACKAGE_ID?: string;
14
+ MARGIN_V1?: string;
14
15
  MARGIN_REGISTRY_ID?: string;
15
16
  LIQUIDATION_PACKAGE_ID?: string;
16
17
  }
@@ -20,15 +21,17 @@ export const testnetPackageIds = {
20
21
  REGISTRY_ID: '0x7c256edbda983a2cd6f946655f4bf3f00a41043993781f8674a7046e8c0e11d1',
21
22
  DEEP_TREASURY_ID: '0x69fffdae0075f8f71f4fa793549c11079266910e8905169845af1f5d00e09dcb',
22
23
  MARGIN_PACKAGE_ID: '0xd6a42f4df4db73d68cbeb52be66698d2fe6a9464f45ad113ca52b0c6ebd918b6',
24
+ MARGIN_V1: '0xd6a42f4df4db73d68cbeb52be66698d2fe6a9464f45ad113ca52b0c6ebd918b6',
23
25
  MARGIN_REGISTRY_ID: '0x48d7640dfae2c6e9ceeada197a7a1643984b5a24c55a0c6c023dac77e0339f75',
24
26
  LIQUIDATION_PACKAGE_ID: '0x8d69c3ef3ef580e5bf87b933ce28de19a5d0323588d1a44b9c60b4001741aa24',
25
27
  } satisfies DeepbookPackageIds;
26
28
 
27
29
  export const mainnetPackageIds = {
28
- DEEPBOOK_PACKAGE_ID: '0xf48222c4e057fa468baf136bff8e12504209d43850c5778f76159292a96f621e',
30
+ DEEPBOOK_PACKAGE_ID: '0x0e735f8c93a95722efd73521aca7a7652c0bb71ed1daf41b26dfd7d1ff71f748',
29
31
  REGISTRY_ID: '0xaf16199a2dff736e9f07a845f23c5da6df6f756eddb631aed9d24a93efc4549d',
30
32
  DEEP_TREASURY_ID: '0x032abf8948dda67a271bcc18e776dbbcfb0d58c8d288a700ff0d5521e57a1ffe',
31
- MARGIN_PACKAGE_ID: '0xfbd322126f1452fd4c89aedbaeb9fd0c44df9b5cedbe70d76bf80dc086031377',
33
+ MARGIN_PACKAGE_ID: '0x124bb3d8105d6d301c0d40feaa54d65df6b301e4d8ddd5eb8475b0f8a18cff2e',
34
+ MARGIN_V1: '0x97d9473771b01f77b0940c589484184b49f6444627ec121314fae6a6d36fb86b',
32
35
  MARGIN_REGISTRY_ID: '0x0e40998b359a9ccbab22a98ed21bd4346abf19158bc7980c8291908086b3a742',
33
36
  LIQUIDATION_PACKAGE_ID: '0x55718c06706bee34c9f3c39f662f10be354a4dcc719699ad72091dc343b641b8',
34
37
  } satisfies DeepbookPackageIds;