@mysten/deepbook-v3 0.26.6 → 0.26.7

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mysten/deepbook-v3
2
2
 
3
+ ## 0.26.7
4
+
5
+ ### Patch Changes
6
+
7
+ - ce90642: Protocol config function updates
8
+
3
9
  ## 0.26.6
4
10
 
5
11
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import type { Transaction, TransactionArgument, TransactionObjectArgument } from '@mysten/sui/transactions';
2
2
  import type { DeepBookConfig } from '../utils/config.js';
3
- import type { MarginPoolConfigParams, MarginPoolConfigWithRateLimitParams, InterestConfigParams } from '../types/index.js';
3
+ import type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';
4
4
  /**
5
5
  * DeepBookMaintainerContract class for managing maintainer actions.
6
6
  */
@@ -20,7 +20,7 @@ export declare class MarginMaintainerContract {
20
20
  /**
21
21
  * @description Create a new protocol config
22
22
  * @param {string} coinKey The key to identify the coin
23
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
23
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
24
24
  * @param {InterestConfigParams} interestConfig The configuration for the interest
25
25
  * @returns A function that takes a Transaction object
26
26
  */
@@ -35,10 +35,10 @@ export declare class MarginMaintainerContract {
35
35
  /**
36
36
  * @description Create a new margin pool config with rate limit
37
37
  * @param {string} coinKey The key to identify the coin
38
- * @param {MarginPoolConfigWithRateLimitParams} marginPoolConfig The configuration for the margin pool with rate limit
38
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
39
39
  * @returns A function that takes a Transaction object
40
40
  */
41
- newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: MarginPoolConfigWithRateLimitParams) => (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
41
+ newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
42
42
  /**
43
43
  * @description Create a new interest config
44
44
  * @param {InterestConfigParams} interestConfig The configuration for the interest
@@ -60,12 +60,18 @@ class MarginMaintainerContract {
60
60
  /**
61
61
  * @description Create a new protocol config
62
62
  * @param {string} coinKey The key to identify the coin
63
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
63
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
64
64
  * @param {InterestConfigParams} interestConfig The configuration for the interest
65
65
  * @returns A function that takes a Transaction object
66
66
  */
67
67
  this.newProtocolConfig = (coinKey, marginPoolConfig, interestConfig) => (tx) => {
68
- const marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
68
+ const hasRateLimit = marginPoolConfig.rateLimitCapacity !== void 0 && marginPoolConfig.rateLimitRefillRatePerMs !== void 0 && marginPoolConfig.rateLimitEnabled !== void 0;
69
+ const marginPoolConfigObject = hasRateLimit ? this.newMarginPoolConfigWithRateLimit(coinKey, {
70
+ ...marginPoolConfig,
71
+ rateLimitCapacity: marginPoolConfig.rateLimitCapacity,
72
+ rateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs,
73
+ rateLimitEnabled: marginPoolConfig.rateLimitEnabled
74
+ })(tx) : this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
69
75
  const interestConfigObject = this.newInterestConfig(interestConfig)(tx);
70
76
  return tx.moveCall({
71
77
  target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,
@@ -94,7 +100,7 @@ class MarginMaintainerContract {
94
100
  /**
95
101
  * @description Create a new margin pool config with rate limit
96
102
  * @param {string} coinKey The key to identify the coin
97
- * @param {MarginPoolConfigWithRateLimitParams} marginPoolConfig The configuration for the margin pool with rate limit
103
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
98
104
  * @returns A function that takes a Transaction object
99
105
  */
100
106
  this.newMarginPoolConfigWithRateLimit = (coinKey, marginPoolConfig) => (tx) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/transactions/marginMaintainer.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type {\n\tMarginPoolConfigParams,\n\tMarginPoolConfigWithRateLimitParams,\n\tInterestConfigParams,\n} from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\n\n/**\n * DeepBookMaintainerContract class for managing maintainer actions.\n */\nexport class MarginMaintainerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginMaintainerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginMaintainerCap() {\n\t\tconst marginMaintainerCap = this.#config.marginMaintainerCap;\n\t\tif (!marginMaintainerCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginMaintainerCap;\n\t}\n\n\t/**\n\t * @description Create a new margin pool\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {TransactionArgument} poolConfig The configuration for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateMarginPool = (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object(this.#marginMaintainerCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new protocol config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewProtocolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,\n\t\t\t\targuments: [marginPoolConfigObject, interestConfigObject],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfig =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst { supplyCap, maxUtilizationRate, referralSpread, minBorrow } = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config with rate limit\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigWithRateLimitParams} marginPoolConfig The configuration for the margin pool with rate limit\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfigWithRateLimit =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigWithRateLimitParams) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst {\n\t\t\t\tsupplyCap,\n\t\t\t\tmaxUtilizationRate,\n\t\t\t\treferralSpread,\n\t\t\t\tminBorrow,\n\t\t\t\trateLimitCapacity,\n\t\t\t\trateLimitRefillRatePerMs,\n\t\t\t\trateLimitEnabled,\n\t\t\t} = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitCapacity * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitRefillRatePerMs * coin.scalar)),\n\t\t\t\t\ttx.pure.bool(rateLimitEnabled),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new interest config\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewInterestConfig = (interestConfig: InterestConfigParams) => (tx: Transaction) => {\n\t\tconst { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,\n\t\t\targuments: [\n\t\t\t\ttx.pure.u64(baseRate * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(baseSlope * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(optimalUtilization * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(excessSlope * FLOAT_SCALAR),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Disable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the interest params\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateInterestParams =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tinterestConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the margin pool config\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateMarginPoolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tmarginPoolConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,oBAA6B;AAf7B;AAoBO,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAMrC,YAAY,QAAwB;AAN9B;AACN;AA2BA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,eAAoC,CAAC,OAAoB;AAC7F,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,sBAAK,6DAAL,UAA2B;AAAA,UACrC,GAAG,OAAO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A;AAAA;AAAA;AAAA;AAAA;AAAA,kCACC,CACC,SACA,eACA,qBAED,CAAC,OAAoB;AACpB,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,YAAM,yBAAyB,KAAK,oBAAoB,SAAS,gBAAgB,EAAE,EAAE;AACrF,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,WAAW,OAAO;AAAA,UAC5B,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,aAAa;AAAA,UACvB,GAAG,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AA3OA,uBAAK,SAAU;AAAA,EAChB;AA2OD;AAlPC;AADM;AAAA;AAAA;AAAA;AAAA;AAcN,yBAAoB,WAAG;AACtB,QAAM,sBAAsB,mBAAK,SAAQ;AACzC,MAAI,CAAC,qBAAqB;AACzB,UAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\n\n/**\n * DeepBookMaintainerContract class for managing maintainer actions.\n */\nexport class MarginMaintainerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginMaintainerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginMaintainerCap() {\n\t\tconst marginMaintainerCap = this.#config.marginMaintainerCap;\n\t\tif (!marginMaintainerCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginMaintainerCap;\n\t}\n\n\t/**\n\t * @description Create a new margin pool\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {TransactionArgument} poolConfig The configuration for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateMarginPool = (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object(this.#marginMaintainerCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new protocol config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewProtocolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst hasRateLimit =\n\t\t\t\tmarginPoolConfig.rateLimitCapacity !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitRefillRatePerMs !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitEnabled !== undefined;\n\t\t\tconst marginPoolConfigObject = hasRateLimit\n\t\t\t\t? this.newMarginPoolConfigWithRateLimit(coinKey, {\n\t\t\t\t\t\t...marginPoolConfig,\n\t\t\t\t\t\trateLimitCapacity: marginPoolConfig.rateLimitCapacity!,\n\t\t\t\t\t\trateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs!,\n\t\t\t\t\t\trateLimitEnabled: marginPoolConfig.rateLimitEnabled!,\n\t\t\t\t\t})(tx)\n\t\t\t\t: this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,\n\t\t\t\targuments: [marginPoolConfigObject, interestConfigObject],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfig =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst { supplyCap, maxUtilizationRate, referralSpread, minBorrow } = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config with rate limit\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfigWithRateLimit =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: Required<\n\t\t\t\tPick<\n\t\t\t\t\tMarginPoolConfigParams,\n\t\t\t\t\t'rateLimitCapacity' | 'rateLimitRefillRatePerMs' | 'rateLimitEnabled'\n\t\t\t\t>\n\t\t\t> &\n\t\t\t\tMarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst {\n\t\t\t\tsupplyCap,\n\t\t\t\tmaxUtilizationRate,\n\t\t\t\treferralSpread,\n\t\t\t\tminBorrow,\n\t\t\t\trateLimitCapacity,\n\t\t\t\trateLimitRefillRatePerMs,\n\t\t\t\trateLimitEnabled,\n\t\t\t} = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitCapacity * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitRefillRatePerMs * coin.scalar)),\n\t\t\t\t\ttx.pure.bool(rateLimitEnabled),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new interest config\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewInterestConfig = (interestConfig: InterestConfigParams) => (tx: Transaction) => {\n\t\tconst { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,\n\t\t\targuments: [\n\t\t\t\ttx.pure.u64(baseRate * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(baseSlope * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(optimalUtilization * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(excessSlope * FLOAT_SCALAR),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Disable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the interest params\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateInterestParams =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tinterestConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the margin pool config\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateMarginPoolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tmarginPoolConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,oBAA6B;AAX7B;AAgBO,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAMrC,YAAY,QAAwB;AAN9B;AACN;AA2BA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,eAAoC,CAAC,OAAoB;AAC7F,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,sBAAK,6DAAL,UAA2B;AAAA,UACrC,GAAG,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,eAAe,CAAC,KAAK,IAAI;AAAA,MAC1B,CAAC;AAAA,IACF;AASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BACC,CACC,SACA,kBACA,mBAED,CAAC,OAAoB;AACpB,YAAM,eACL,iBAAiB,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IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AASD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCACC,CACC,SACA,eACA,qBAED,CAAC,OAAoB;AACpB,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,YAAM,yBAAyB,KAAK,oBAAoB,SAAS,gBAAgB,EAAE,EAAE;AACrF,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,WAAW,OAAO;AAAA,UAC5B,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,aAAa;AAAA,UACvB,GAAG,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AA/PA,uBAAK,SAAU;AAAA,EAChB;AA+PD;AAtQC;AADM;AAAA;AAAA;AAAA;AAAA;AAcN,yBAAoB,WAAG;AACtB,QAAM,sBAAsB,mBAAK,SAAQ;AACzC,MAAI,CAAC,qBAAqB;AACzB,UAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AACA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -200,11 +200,9 @@ export interface MarginPoolConfigParams {
200
200
  maxUtilizationRate: number;
201
201
  referralSpread: number;
202
202
  minBorrow: number;
203
- }
204
- export interface MarginPoolConfigWithRateLimitParams extends MarginPoolConfigParams {
205
- rateLimitCapacity: number;
206
- rateLimitRefillRatePerMs: number;
207
- rateLimitEnabled: boolean;
203
+ rateLimitCapacity?: number;
204
+ rateLimitRefillRatePerMs?: number;
205
+ rateLimitEnabled?: boolean;
208
206
  }
209
207
  export interface InterestConfigParams {
210
208
  baseRate: number;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/types/index.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\n// SPDX-License-Identifier: Apache-2.0\nexport interface BalanceManager {\n\taddress: string;\n\ttradeCap?: string;\n\tdepositCap?: string;\n\twithdrawCap?: string;\n}\n\nexport interface MarginManager {\n\taddress: string;\n\tpoolKey: string;\n}\n\nexport interface Coin {\n\taddress: string;\n\ttype: string;\n\tscalar: number;\n\tfeed?: string;\n\tcurrencyId?: string;\n\tpriceInfoObjectId?: string;\n}\n\nexport interface Pool {\n\taddress: string;\n\tbaseCoin: string;\n\tquoteCoin: string;\n}\n\nexport interface MarginPool {\n\taddress: string;\n\ttype: string;\n}\n\n// Trading constants\nexport enum OrderType {\n\tNO_RESTRICTION,\n\tIMMEDIATE_OR_CANCEL,\n\tFILL_OR_KILL,\n\tPOST_ONLY,\n}\n\n// Self matching options\nexport enum SelfMatchingOptions {\n\tSELF_MATCHING_ALLOWED,\n\tCANCEL_TAKER,\n\tCANCEL_MAKER,\n}\n\nexport interface PlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface CanPlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n\texpireTimestamp: number;\n}\n\nexport interface CanPlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n}\n\nexport interface PlaceMarginLimitOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarginMarketOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PendingLimitOrderParams {\n\tclientOrderId: string;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n\texpireTimestamp?: number | bigint;\n}\n\nexport interface PendingMarketOrderParams {\n\tclientOrderId: string;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n}\n\nexport interface AddConditionalOrderParams {\n\tmarginManagerKey: string;\n\tconditionalOrderId: string;\n\ttriggerBelowPrice: boolean;\n\ttriggerPrice: number;\n\tpendingOrder: PendingLimitOrderParams | PendingMarketOrderParams;\n}\n\nexport interface ProposalParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface MarginProposalParams {\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface SwapParams {\n\tpoolKey: string;\n\tamount: number;\n\tdeepAmount: number;\n\tminOut: number;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface SwapWithManagerParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttradeCap: string;\n\tdepositCap: string;\n\twithdrawCap: string;\n\tamount: number;\n\tminOut: number;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface StakeParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tamount: number;\n}\n\nexport interface VoteParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tproposalId: string;\n}\n\nexport interface FlashLoanParams {\n\tpoolKey: string;\n\tamount: number;\n}\n\nexport interface CreatePoolAdminParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\twhitelisted: boolean;\n\tstablePool: boolean;\n}\n\nexport interface CreatePermissionlessPoolParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\tdeepCoin?: TransactionObjectArgument;\n}\n\nexport interface SetEwmaParams {\n\talpha: number;\n\tzScoreThreshold: number;\n\tadditionalTakerFee: number;\n}\n\nexport interface PoolConfigParams {\n\tminWithdrawRiskRatio: number;\n\tminBorrowRiskRatio: number;\n\tliquidationRiskRatio: number;\n\ttargetLiquidationRiskRatio: number;\n\tuserLiquidationReward: number;\n\tpoolLiquidationReward: number;\n}\n\nexport interface MarginPoolConfigParams {\n\tsupplyCap: number;\n\tmaxUtilizationRate: number;\n\treferralSpread: number;\n\tminBorrow: number;\n}\n\nexport interface MarginPoolConfigWithRateLimitParams extends MarginPoolConfigParams {\n\trateLimitCapacity: number;\n\trateLimitRefillRatePerMs: number;\n\trateLimitEnabled: boolean;\n}\n\nexport interface InterestConfigParams {\n\tbaseRate: number;\n\tbaseSlope: number;\n\toptimalUtilization: number;\n\texcessSlope: number;\n}\n\nexport interface Config {\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n}\n\nexport type Environment = 'mainnet' | 'testnet';\n"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\n// SPDX-License-Identifier: Apache-2.0\nexport interface BalanceManager {\n\taddress: string;\n\ttradeCap?: string;\n\tdepositCap?: string;\n\twithdrawCap?: string;\n}\n\nexport interface MarginManager {\n\taddress: string;\n\tpoolKey: string;\n}\n\nexport interface Coin {\n\taddress: string;\n\ttype: string;\n\tscalar: number;\n\tfeed?: string;\n\tcurrencyId?: string;\n\tpriceInfoObjectId?: string;\n}\n\nexport interface Pool {\n\taddress: string;\n\tbaseCoin: string;\n\tquoteCoin: string;\n}\n\nexport interface MarginPool {\n\taddress: string;\n\ttype: string;\n}\n\n// Trading constants\nexport enum OrderType {\n\tNO_RESTRICTION,\n\tIMMEDIATE_OR_CANCEL,\n\tFILL_OR_KILL,\n\tPOST_ONLY,\n}\n\n// Self matching options\nexport enum SelfMatchingOptions {\n\tSELF_MATCHING_ALLOWED,\n\tCANCEL_TAKER,\n\tCANCEL_MAKER,\n}\n\nexport interface PlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface CanPlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n\texpireTimestamp: number;\n}\n\nexport interface CanPlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n}\n\nexport interface PlaceMarginLimitOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarginMarketOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PendingLimitOrderParams {\n\tclientOrderId: string;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n\texpireTimestamp?: number | bigint;\n}\n\nexport interface PendingMarketOrderParams {\n\tclientOrderId: string;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n}\n\nexport interface AddConditionalOrderParams {\n\tmarginManagerKey: string;\n\tconditionalOrderId: string;\n\ttriggerBelowPrice: boolean;\n\ttriggerPrice: number;\n\tpendingOrder: PendingLimitOrderParams | PendingMarketOrderParams;\n}\n\nexport interface ProposalParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface MarginProposalParams {\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface SwapParams {\n\tpoolKey: string;\n\tamount: number;\n\tdeepAmount: number;\n\tminOut: number;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface SwapWithManagerParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttradeCap: string;\n\tdepositCap: string;\n\twithdrawCap: string;\n\tamount: number;\n\tminOut: number;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface StakeParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tamount: number;\n}\n\nexport interface VoteParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tproposalId: string;\n}\n\nexport interface FlashLoanParams {\n\tpoolKey: string;\n\tamount: number;\n}\n\nexport interface CreatePoolAdminParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\twhitelisted: boolean;\n\tstablePool: boolean;\n}\n\nexport interface CreatePermissionlessPoolParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\tdeepCoin?: TransactionObjectArgument;\n}\n\nexport interface SetEwmaParams {\n\talpha: number;\n\tzScoreThreshold: number;\n\tadditionalTakerFee: number;\n}\n\nexport interface PoolConfigParams {\n\tminWithdrawRiskRatio: number;\n\tminBorrowRiskRatio: number;\n\tliquidationRiskRatio: number;\n\ttargetLiquidationRiskRatio: number;\n\tuserLiquidationReward: number;\n\tpoolLiquidationReward: number;\n}\n\nexport interface MarginPoolConfigParams {\n\tsupplyCap: number;\n\tmaxUtilizationRate: number;\n\treferralSpread: number;\n\tminBorrow: number;\n\trateLimitCapacity?: number;\n\trateLimitRefillRatePerMs?: number;\n\trateLimitEnabled?: boolean;\n}\n\nexport interface InterestConfigParams {\n\tbaseRate: number;\n\tbaseSlope: number;\n\toptimalUtilization: number;\n\texcessSlope: number;\n}\n\nexport interface Config {\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n}\n\nexport type Environment = 'mainnet' | 'testnet';\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCO,IAAK,YAAL,kBAAKA,eAAL;AACN,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAJW,SAAAA;AAAA,GAAA;AAQL,IAAK,sBAAL,kBAAKC,yBAAL;AACN,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AAHW,SAAAA;AAAA,GAAA;",
6
6
  "names": ["OrderType", "SelfMatchingOptions"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import type { Transaction, TransactionArgument, TransactionObjectArgument } from '@mysten/sui/transactions';
2
2
  import type { DeepBookConfig } from '../utils/config.js';
3
- import type { MarginPoolConfigParams, MarginPoolConfigWithRateLimitParams, InterestConfigParams } from '../types/index.js';
3
+ import type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';
4
4
  /**
5
5
  * DeepBookMaintainerContract class for managing maintainer actions.
6
6
  */
@@ -20,7 +20,7 @@ export declare class MarginMaintainerContract {
20
20
  /**
21
21
  * @description Create a new protocol config
22
22
  * @param {string} coinKey The key to identify the coin
23
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
23
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
24
24
  * @param {InterestConfigParams} interestConfig The configuration for the interest
25
25
  * @returns A function that takes a Transaction object
26
26
  */
@@ -35,10 +35,10 @@ export declare class MarginMaintainerContract {
35
35
  /**
36
36
  * @description Create a new margin pool config with rate limit
37
37
  * @param {string} coinKey The key to identify the coin
38
- * @param {MarginPoolConfigWithRateLimitParams} marginPoolConfig The configuration for the margin pool with rate limit
38
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
39
39
  * @returns A function that takes a Transaction object
40
40
  */
41
- newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: MarginPoolConfigWithRateLimitParams) => (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
41
+ newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
42
42
  /**
43
43
  * @description Create a new interest config
44
44
  * @param {InterestConfigParams} interestConfig The configuration for the interest
@@ -37,12 +37,18 @@ class MarginMaintainerContract {
37
37
  /**
38
38
  * @description Create a new protocol config
39
39
  * @param {string} coinKey The key to identify the coin
40
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
40
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
41
41
  * @param {InterestConfigParams} interestConfig The configuration for the interest
42
42
  * @returns A function that takes a Transaction object
43
43
  */
44
44
  this.newProtocolConfig = (coinKey, marginPoolConfig, interestConfig) => (tx) => {
45
- const marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
45
+ const hasRateLimit = marginPoolConfig.rateLimitCapacity !== void 0 && marginPoolConfig.rateLimitRefillRatePerMs !== void 0 && marginPoolConfig.rateLimitEnabled !== void 0;
46
+ const marginPoolConfigObject = hasRateLimit ? this.newMarginPoolConfigWithRateLimit(coinKey, {
47
+ ...marginPoolConfig,
48
+ rateLimitCapacity: marginPoolConfig.rateLimitCapacity,
49
+ rateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs,
50
+ rateLimitEnabled: marginPoolConfig.rateLimitEnabled
51
+ })(tx) : this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
46
52
  const interestConfigObject = this.newInterestConfig(interestConfig)(tx);
47
53
  return tx.moveCall({
48
54
  target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,
@@ -71,7 +77,7 @@ class MarginMaintainerContract {
71
77
  /**
72
78
  * @description Create a new margin pool config with rate limit
73
79
  * @param {string} coinKey The key to identify the coin
74
- * @param {MarginPoolConfigWithRateLimitParams} marginPoolConfig The configuration for the margin pool with rate limit
80
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
75
81
  * @returns A function that takes a Transaction object
76
82
  */
77
83
  this.newMarginPoolConfigWithRateLimit = (coinKey, marginPoolConfig) => (tx) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/transactions/marginMaintainer.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type {\n\tMarginPoolConfigParams,\n\tMarginPoolConfigWithRateLimitParams,\n\tInterestConfigParams,\n} from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\n\n/**\n * DeepBookMaintainerContract class for managing maintainer actions.\n */\nexport class MarginMaintainerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginMaintainerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginMaintainerCap() {\n\t\tconst marginMaintainerCap = this.#config.marginMaintainerCap;\n\t\tif (!marginMaintainerCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginMaintainerCap;\n\t}\n\n\t/**\n\t * @description Create a new margin pool\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {TransactionArgument} poolConfig The configuration for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateMarginPool = (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object(this.#marginMaintainerCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new protocol config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewProtocolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,\n\t\t\t\targuments: [marginPoolConfigObject, interestConfigObject],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfig =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst { supplyCap, maxUtilizationRate, referralSpread, minBorrow } = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config with rate limit\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigWithRateLimitParams} marginPoolConfig The configuration for the margin pool with rate limit\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfigWithRateLimit =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigWithRateLimitParams) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst {\n\t\t\t\tsupplyCap,\n\t\t\t\tmaxUtilizationRate,\n\t\t\t\treferralSpread,\n\t\t\t\tminBorrow,\n\t\t\t\trateLimitCapacity,\n\t\t\t\trateLimitRefillRatePerMs,\n\t\t\t\trateLimitEnabled,\n\t\t\t} = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitCapacity * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitRefillRatePerMs * coin.scalar)),\n\t\t\t\t\ttx.pure.bool(rateLimitEnabled),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new interest config\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewInterestConfig = (interestConfig: InterestConfigParams) => (tx: Transaction) => {\n\t\tconst { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,\n\t\t\targuments: [\n\t\t\t\ttx.pure.u64(baseRate * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(baseSlope * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(optimalUtilization * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(excessSlope * FLOAT_SCALAR),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Disable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the interest params\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateInterestParams =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tinterestConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the margin pool config\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateMarginPoolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tmarginPoolConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n}\n"],
5
- "mappings": ";;;;;;;;AAAA;AAeA,SAAS,oBAAoB;AAKtB,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAMrC,YAAY,QAAwB;AAN9B;AACN;AA2BA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,eAAoC,CAAC,OAAoB;AAC7F,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,sBAAK,6DAAL,UAA2B;AAAA,UACrC,GAAG,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,eAAe,CAAC,KAAK,IAAI;AAAA,MAC1B,CAAC;AAAA,IACF;AASA;AAAA;AAAA;AAAA;AAAA;AA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AM,yBAAyB,KAAK,oBAAoB,SAAS,gBAAgB,EAAE,EAAE;AACrF,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,WAAW,OAAO;AAAA,UAC5B,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,aAAa;AAAA,UACvB,GAAG,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AA3OA,uBAAK,SAAU;AAAA,EAChB;AA2OD;AAlPC;AADM;AAAA;AAAA;AAAA;AAAA;AAcN,yBAAoB,WAAG;AACtB,QAAM,sBAAsB,mBAAK,SAAQ;AACzC,MAAI,CAAC,qBAAqB;AACzB,UAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\n\n/**\n * DeepBookMaintainerContract class for managing maintainer actions.\n */\nexport class MarginMaintainerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginMaintainerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginMaintainerCap() {\n\t\tconst marginMaintainerCap = this.#config.marginMaintainerCap;\n\t\tif (!marginMaintainerCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginMaintainerCap;\n\t}\n\n\t/**\n\t * @description Create a new margin pool\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {TransactionArgument} poolConfig The configuration for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateMarginPool = (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object(this.#marginMaintainerCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new protocol config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewProtocolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst hasRateLimit =\n\t\t\t\tmarginPoolConfig.rateLimitCapacity !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitRefillRatePerMs !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitEnabled !== undefined;\n\t\t\tconst marginPoolConfigObject = hasRateLimit\n\t\t\t\t? this.newMarginPoolConfigWithRateLimit(coinKey, {\n\t\t\t\t\t\t...marginPoolConfig,\n\t\t\t\t\t\trateLimitCapacity: marginPoolConfig.rateLimitCapacity!,\n\t\t\t\t\t\trateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs!,\n\t\t\t\t\t\trateLimitEnabled: marginPoolConfig.rateLimitEnabled!,\n\t\t\t\t\t})(tx)\n\t\t\t\t: this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,\n\t\t\t\targuments: [marginPoolConfigObject, interestConfigObject],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfig =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst { supplyCap, maxUtilizationRate, referralSpread, minBorrow } = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config with rate limit\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfigWithRateLimit =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: Required<\n\t\t\t\tPick<\n\t\t\t\t\tMarginPoolConfigParams,\n\t\t\t\t\t'rateLimitCapacity' | 'rateLimitRefillRatePerMs' | 'rateLimitEnabled'\n\t\t\t\t>\n\t\t\t> &\n\t\t\t\tMarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst {\n\t\t\t\tsupplyCap,\n\t\t\t\tmaxUtilizationRate,\n\t\t\t\treferralSpread,\n\t\t\t\tminBorrow,\n\t\t\t\trateLimitCapacity,\n\t\t\t\trateLimitRefillRatePerMs,\n\t\t\t\trateLimitEnabled,\n\t\t\t} = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(supplyCap * coin.scalar),\n\t\t\t\t\ttx.pure.u64(maxUtilizationRate * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(referralSpread * FLOAT_SCALAR),\n\t\t\t\t\ttx.pure.u64(Math.round(minBorrow * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitCapacity * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(rateLimitRefillRatePerMs * coin.scalar)),\n\t\t\t\t\ttx.pure.bool(rateLimitEnabled),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new interest config\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewInterestConfig = (interestConfig: InterestConfigParams) => (tx: Transaction) => {\n\t\tconst { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,\n\t\t\targuments: [\n\t\t\t\ttx.pure.u64(baseRate * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(baseSlope * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(optimalUtilization * FLOAT_SCALAR),\n\t\t\t\ttx.pure.u64(excessSlope * FLOAT_SCALAR),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Disable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the interest params\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateInterestParams =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tinterestConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the margin pool config\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateMarginPoolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tmarginPoolConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n}\n"],
5
+ "mappings": ";;;;;;;;AAAA;AAWA,SAAS,oBAAoB;AAKtB,MAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAMrC,YAAY,QAAwB;AAN9B;AACN;AA2BA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,eAAoC,CAAC,OAAoB;AAC7F,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,sBAAK,6DAAL,UAA2B;AAAA,UACrC,GAAG,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,eAAe,CAAC,KAAK,IAAI;AAAA,MAC1B,CAAC;AAAA,IACF;AASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BACC,CACC,SACA,kBACA,mBAED,CAAC,OAAoB;AACpB,YAAM,eACL,iBAAiB,sBAAsB,UACvC,iBAAiB,6BAA6B,UAC9C,iBAAiB,qBAAqB;AACvC,YAAM,yBAAyB,eAC5B,KAAK,iCAAiC,SAAS;AAAA,QAC/C,GAAG;AAAA,QACH,mBAAmB,iBAAiB;AAAA,QACpC,0BAA0B,i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AyB,KAAK,oBAAoB,SAAS,gBAAgB,EAAE,EAAE;AACrF,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW;AAAA,UACV,GAAG,OAAO,WAAW,OAAO;AAAA,UAC5B,GAAG,OAAO,mBAAK,SAAQ,kBAAkB;AAAA,UACzC;AAAA,UACA,GAAG,OAAO,aAAa;AAAA,UACvB,GAAG,OAAO,MAAM;AAAA,QACjB;AAAA,QACA,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AA/PA,uBAAK,SAAU;AAAA,EAChB;AA+PD;AAtQC;AADM;AAAA;AAAA;AAAA;AAAA;AAcN,yBAAoB,WAAG;AACtB,QAAM,sBAAsB,mBAAK,SAAQ;AACzC,MAAI,CAAC,qBAAqB;AACzB,UAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AACA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -200,11 +200,9 @@ export interface MarginPoolConfigParams {
200
200
  maxUtilizationRate: number;
201
201
  referralSpread: number;
202
202
  minBorrow: number;
203
- }
204
- export interface MarginPoolConfigWithRateLimitParams extends MarginPoolConfigParams {
205
- rateLimitCapacity: number;
206
- rateLimitRefillRatePerMs: number;
207
- rateLimitEnabled: boolean;
203
+ rateLimitCapacity?: number;
204
+ rateLimitRefillRatePerMs?: number;
205
+ rateLimitEnabled?: boolean;
208
206
  }
209
207
  export interface InterestConfigParams {
210
208
  baseRate: number;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/types/index.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\n// SPDX-License-Identifier: Apache-2.0\nexport interface BalanceManager {\n\taddress: string;\n\ttradeCap?: string;\n\tdepositCap?: string;\n\twithdrawCap?: string;\n}\n\nexport interface MarginManager {\n\taddress: string;\n\tpoolKey: string;\n}\n\nexport interface Coin {\n\taddress: string;\n\ttype: string;\n\tscalar: number;\n\tfeed?: string;\n\tcurrencyId?: string;\n\tpriceInfoObjectId?: string;\n}\n\nexport interface Pool {\n\taddress: string;\n\tbaseCoin: string;\n\tquoteCoin: string;\n}\n\nexport interface MarginPool {\n\taddress: string;\n\ttype: string;\n}\n\n// Trading constants\nexport enum OrderType {\n\tNO_RESTRICTION,\n\tIMMEDIATE_OR_CANCEL,\n\tFILL_OR_KILL,\n\tPOST_ONLY,\n}\n\n// Self matching options\nexport enum SelfMatchingOptions {\n\tSELF_MATCHING_ALLOWED,\n\tCANCEL_TAKER,\n\tCANCEL_MAKER,\n}\n\nexport interface PlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface CanPlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n\texpireTimestamp: number;\n}\n\nexport interface CanPlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n}\n\nexport interface PlaceMarginLimitOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarginMarketOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PendingLimitOrderParams {\n\tclientOrderId: string;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n\texpireTimestamp?: number | bigint;\n}\n\nexport interface PendingMarketOrderParams {\n\tclientOrderId: string;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n}\n\nexport interface AddConditionalOrderParams {\n\tmarginManagerKey: string;\n\tconditionalOrderId: string;\n\ttriggerBelowPrice: boolean;\n\ttriggerPrice: number;\n\tpendingOrder: PendingLimitOrderParams | PendingMarketOrderParams;\n}\n\nexport interface ProposalParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface MarginProposalParams {\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface SwapParams {\n\tpoolKey: string;\n\tamount: number;\n\tdeepAmount: number;\n\tminOut: number;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface SwapWithManagerParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttradeCap: string;\n\tdepositCap: string;\n\twithdrawCap: string;\n\tamount: number;\n\tminOut: number;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface StakeParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tamount: number;\n}\n\nexport interface VoteParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tproposalId: string;\n}\n\nexport interface FlashLoanParams {\n\tpoolKey: string;\n\tamount: number;\n}\n\nexport interface CreatePoolAdminParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\twhitelisted: boolean;\n\tstablePool: boolean;\n}\n\nexport interface CreatePermissionlessPoolParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\tdeepCoin?: TransactionObjectArgument;\n}\n\nexport interface SetEwmaParams {\n\talpha: number;\n\tzScoreThreshold: number;\n\tadditionalTakerFee: number;\n}\n\nexport interface PoolConfigParams {\n\tminWithdrawRiskRatio: number;\n\tminBorrowRiskRatio: number;\n\tliquidationRiskRatio: number;\n\ttargetLiquidationRiskRatio: number;\n\tuserLiquidationReward: number;\n\tpoolLiquidationReward: number;\n}\n\nexport interface MarginPoolConfigParams {\n\tsupplyCap: number;\n\tmaxUtilizationRate: number;\n\treferralSpread: number;\n\tminBorrow: number;\n}\n\nexport interface MarginPoolConfigWithRateLimitParams extends MarginPoolConfigParams {\n\trateLimitCapacity: number;\n\trateLimitRefillRatePerMs: number;\n\trateLimitEnabled: boolean;\n}\n\nexport interface InterestConfigParams {\n\tbaseRate: number;\n\tbaseSlope: number;\n\toptimalUtilization: number;\n\texcessSlope: number;\n}\n\nexport interface Config {\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n}\n\nexport type Environment = 'mainnet' | 'testnet';\n"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { TransactionObjectArgument } from '@mysten/sui/transactions';\n\n// SPDX-License-Identifier: Apache-2.0\nexport interface BalanceManager {\n\taddress: string;\n\ttradeCap?: string;\n\tdepositCap?: string;\n\twithdrawCap?: string;\n}\n\nexport interface MarginManager {\n\taddress: string;\n\tpoolKey: string;\n}\n\nexport interface Coin {\n\taddress: string;\n\ttype: string;\n\tscalar: number;\n\tfeed?: string;\n\tcurrencyId?: string;\n\tpriceInfoObjectId?: string;\n}\n\nexport interface Pool {\n\taddress: string;\n\tbaseCoin: string;\n\tquoteCoin: string;\n}\n\nexport interface MarginPool {\n\taddress: string;\n\ttype: string;\n}\n\n// Trading constants\nexport enum OrderType {\n\tNO_RESTRICTION,\n\tIMMEDIATE_OR_CANCEL,\n\tFILL_OR_KILL,\n\tPOST_ONLY,\n}\n\n// Self matching options\nexport enum SelfMatchingOptions {\n\tSELF_MATCHING_ALLOWED,\n\tCANCEL_TAKER,\n\tCANCEL_MAKER,\n}\n\nexport interface PlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface CanPlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n\texpireTimestamp: number;\n}\n\nexport interface CanPlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n}\n\nexport interface PlaceMarginLimitOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarginMarketOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PendingLimitOrderParams {\n\tclientOrderId: string;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tprice: number;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n\texpireTimestamp?: number | bigint;\n}\n\nexport interface PendingMarketOrderParams {\n\tclientOrderId: string;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tquantity: number;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n}\n\nexport interface AddConditionalOrderParams {\n\tmarginManagerKey: string;\n\tconditionalOrderId: string;\n\ttriggerBelowPrice: boolean;\n\ttriggerPrice: number;\n\tpendingOrder: PendingLimitOrderParams | PendingMarketOrderParams;\n}\n\nexport interface ProposalParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface MarginProposalParams {\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\n\nexport interface SwapParams {\n\tpoolKey: string;\n\tamount: number;\n\tdeepAmount: number;\n\tminOut: number;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface SwapWithManagerParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttradeCap: string;\n\tdepositCap: string;\n\twithdrawCap: string;\n\tamount: number;\n\tminOut: number;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface StakeParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tamount: number;\n}\n\nexport interface VoteParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tproposalId: string;\n}\n\nexport interface FlashLoanParams {\n\tpoolKey: string;\n\tamount: number;\n}\n\nexport interface CreatePoolAdminParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\twhitelisted: boolean;\n\tstablePool: boolean;\n}\n\nexport interface CreatePermissionlessPoolParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n\tdeepCoin?: TransactionObjectArgument;\n}\n\nexport interface SetEwmaParams {\n\talpha: number;\n\tzScoreThreshold: number;\n\tadditionalTakerFee: number;\n}\n\nexport interface PoolConfigParams {\n\tminWithdrawRiskRatio: number;\n\tminBorrowRiskRatio: number;\n\tliquidationRiskRatio: number;\n\ttargetLiquidationRiskRatio: number;\n\tuserLiquidationReward: number;\n\tpoolLiquidationReward: number;\n}\n\nexport interface MarginPoolConfigParams {\n\tsupplyCap: number;\n\tmaxUtilizationRate: number;\n\treferralSpread: number;\n\tminBorrow: number;\n\trateLimitCapacity?: number;\n\trateLimitRefillRatePerMs?: number;\n\trateLimitEnabled?: boolean;\n}\n\nexport interface InterestConfigParams {\n\tbaseRate: number;\n\tbaseSlope: number;\n\toptimalUtilization: number;\n\texcessSlope: number;\n}\n\nexport interface Config {\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n}\n\nexport type Environment = 'mainnet' | 'testnet';\n"],
5
5
  "mappings": "AAuCO,IAAK,YAAL,kBAAKA,eAAL;AACN,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AACA,EAAAA,sBAAA;AAJW,SAAAA;AAAA,GAAA;AAQL,IAAK,sBAAL,kBAAKC,yBAAL;AACN,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AAHW,SAAAA;AAAA,GAAA;",
6
6
  "names": ["OrderType", "SelfMatchingOptions"]
7
7
  }