@mysten/deepbook-v3 0.28.0 → 0.28.2

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,17 @@
1
1
  # @mysten/deepbook-v3
2
2
 
3
+ ## 0.28.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 24b41ea: Update rate limit in SDK
8
+
9
+ ## 0.28.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 1434c65: Withdraw all fix
14
+
3
15
  ## 0.28.0
4
16
 
5
17
  ### Minor Changes
@@ -73,7 +73,7 @@ export declare class MarginMaintainerContract {
73
73
  * @description Update the margin pool config
74
74
  * @param {string} coinKey The key to identify the margin pool
75
75
  * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
76
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
76
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
77
77
  * @returns A function that takes a Transaction object
78
78
  */
79
79
  updateMarginPoolConfig: (coinKey: string, marginPoolCap: TransactionObjectArgument, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => void;
@@ -214,12 +214,18 @@ class MarginMaintainerContract {
214
214
  * @description Update the margin pool config
215
215
  * @param {string} coinKey The key to identify the margin pool
216
216
  * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
217
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
217
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
218
218
  * @returns A function that takes a Transaction object
219
219
  */
220
220
  this.updateMarginPoolConfig = (coinKey, marginPoolCap, marginPoolConfig) => (tx) => {
221
221
  const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
222
- const marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
222
+ const hasRateLimit = marginPoolConfig.rateLimitCapacity !== void 0 && marginPoolConfig.rateLimitRefillRatePerMs !== void 0 && marginPoolConfig.rateLimitEnabled !== void 0;
223
+ const marginPoolConfigObject = hasRateLimit ? this.newMarginPoolConfigWithRateLimit(coinKey, {
224
+ ...marginPoolConfig,
225
+ rateLimitCapacity: marginPoolConfig.rateLimitCapacity,
226
+ rateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs,
227
+ rateLimitEnabled: marginPoolConfig.rateLimitEnabled
228
+ })(tx) : this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
223
229
  tx.moveCall({
224
230
  target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,
225
231
  arguments: [
@@ -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 { 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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(baseRate * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(baseSlope * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(optimalUtilization * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(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,sBAAsB,UACvC,iBAAiB,6BAA6B,UAC9C,iBAAiB,qBAAqB;AACvC,YAAM,yBAAyB,eAC5B,KAAK,iCAAiC,SAAS;AAAA,QAC/C,GAAG;AAAA,QACH,mBAAmB,iBAAiB;AAAA,QAC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ACA,eAAe,CAAC,WAAW,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;",
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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(baseRate * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(baseSlope * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(optimalUtilization * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(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 (with optional rate limit)\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 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\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;A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BAAgB,EAAE,EAAE;AACzD,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;AA1QA,uBAAK,SAAU;AAAA,EAChB;AA0QD;AAjRC;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
  }
@@ -24,10 +24,10 @@ export declare class MarginPoolContract {
24
24
  */
25
25
  supplyToMarginPool: (coinKey: string, supplierCap: TransactionObjectArgument, amountToDeposit: number, referralId?: string) => (tx: Transaction) => void;
26
26
  /**
27
- * @description Withdraw from a margin pool
27
+ * @description Withdraw from a margin pool. If amountToWithdraw is not provided, withdraws all.
28
28
  * @param {string} coinKey The key to identify the pool
29
29
  * @param {TransactionObjectArgument} supplierCap The supplier cap object
30
- * @param {number} amountToWithdraw The amount to withdraw
30
+ * @param {number} [amountToWithdraw] The amount to withdraw. If omitted, withdraws all.
31
31
  * @returns A function that takes a Transaction object
32
32
  */
33
33
  withdrawFromMarginPool: (coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) => (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
@@ -80,23 +80,23 @@ class MarginPoolContract {
80
80
  });
81
81
  };
82
82
  /**
83
- * @description Withdraw from a margin pool
83
+ * @description Withdraw from a margin pool. If amountToWithdraw is not provided, withdraws all.
84
84
  * @param {string} coinKey The key to identify the pool
85
85
  * @param {TransactionObjectArgument} supplierCap The supplier cap object
86
- * @param {number} amountToWithdraw The amount to withdraw
86
+ * @param {number} [amountToWithdraw] The amount to withdraw. If omitted, withdraws all.
87
87
  * @returns A function that takes a Transaction object
88
88
  */
89
89
  this.withdrawFromMarginPool = (coinKey, supplierCap, amountToWithdraw) => (tx) => {
90
90
  const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
91
91
  const coin = __privateGet(this, _config).getCoin(coinKey);
92
- const withdrawInput = amountToWithdraw ? tx.pure.u64(Math.round(amountToWithdraw * coin.scalar)) : null;
92
+ const withdrawInput = amountToWithdraw !== void 0 ? Math.round(amountToWithdraw * coin.scalar) : null;
93
93
  return tx.moveCall({
94
94
  target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::withdraw`,
95
95
  arguments: [
96
96
  tx.object(marginPool.address),
97
97
  tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
98
98
  supplierCap,
99
- tx.object.option({ type: "u64", value: withdrawInput }),
99
+ tx.pure.option("u64", withdrawInput),
100
100
  tx.object.clock()
101
101
  ],
102
102
  typeArguments: [marginPool.type]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/transactions/marginPool.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * MarginPoolContract class for managing MarginPool operations.\n */\nexport class MarginPoolContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginPoolContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Mint a supplier cap for margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplierCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supplier_cap`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object.clock()],\n\t\t});\n\t};\n\n\t/**\n\t * @description Supply to a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyToMarginPool =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tsupplierCap: TransactionObjectArgument,\n\t\t\tamountToDeposit: number,\n\t\t\treferralId?: string,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = Math.round(amountToDeposit * coin.scalar);\n\t\t\tconst supply = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply`,\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\tsupplierCap,\n\t\t\t\t\tsupply,\n\t\t\t\t\ttx.object.option({\n\t\t\t\t\t\ttype: '0x2::object::ID',\n\t\t\t\t\t\tvalue: referralId ? tx.pure.id(referralId) : null,\n\t\t\t\t\t}),\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 Withdraw from a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} amountToWithdraw The amount to withdraw\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawFromMarginPool =\n\t\t(coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawInput = amountToWithdraw\n\t\t\t\t? tx.pure.u64(Math.round(amountToWithdraw * coin.scalar))\n\t\t\t\t: null;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw`,\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\tsupplierCap,\n\t\t\t\t\ttx.object.option({ type: 'u64', value: withdrawInput }),\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 Mint a referral for a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplyReferral = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supply_referral`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw referral fees from a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawReferralFees = (coinKey: string, referralId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw_referral_fees`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(referralId),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t// === Read-only/View Functions ===\n\n\t/**\n\t * @description Get the margin pool ID\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetId = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::id`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Check if a deepbook pool is allowed for borrowing\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {string} deepbookPoolId The ID of the deepbook pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tdeepbookPoolAllowed = (coinKey: string, deepbookPoolId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::deepbook_pool_allowed`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(deepbookPoolId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalSupply = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_supply`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::borrow_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the last update timestamp\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tlastUpdateTimestamp = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::last_update_timestamp`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the supply cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyCap = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_cap`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the max utilization rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmaxUtilizationRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::max_utilization_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the protocol spread\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tprotocolSpread = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::protocol_spread`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the minimum borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tminBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::min_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the current interest rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tinterestRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::interest_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply shares for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyShares = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply amount for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyAmount = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_amount`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId), tx.object.clock()],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BA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AW,CAAC,GAAG,OAAO,WAAW,OAAO,CAAC;AAAA,QACzC,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,kBAA0B,CAAC,OAAoB;AACnF,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW,CAAC,GAAG,OAAO,WAAW,OAAO,GAAG,GAAG,KAAK,GAAG,aAAa,CAAC;AAAA,QACpE,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,kBAA0B,CAAC,OAAoB;AACnF,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW,CAAC,GAAG,OAAO,WAAW,OAAO,GAAG,GAAG,KAAK,GAAG,aAAa,GAAG,GAAG,OAAO,MAAM,CAAC;AAAA,QACvF,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AAhUC,uBAAK,SAAU;AAAA,EAChB;AAgUD;AAvUC;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * MarginPoolContract class for managing MarginPool operations.\n */\nexport class MarginPoolContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginPoolContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Mint a supplier cap for margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplierCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supplier_cap`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object.clock()],\n\t\t});\n\t};\n\n\t/**\n\t * @description Supply to a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyToMarginPool =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tsupplierCap: TransactionObjectArgument,\n\t\t\tamountToDeposit: number,\n\t\t\treferralId?: string,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = Math.round(amountToDeposit * coin.scalar);\n\t\t\tconst supply = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply`,\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\tsupplierCap,\n\t\t\t\t\tsupply,\n\t\t\t\t\ttx.object.option({\n\t\t\t\t\t\ttype: '0x2::object::ID',\n\t\t\t\t\t\tvalue: referralId ? tx.pure.id(referralId) : null,\n\t\t\t\t\t}),\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 Withdraw from a margin pool. If amountToWithdraw is not provided, withdraws all.\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} [amountToWithdraw] The amount to withdraw. If omitted, withdraws all.\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawFromMarginPool =\n\t\t(coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawInput =\n\t\t\t\tamountToWithdraw !== undefined ? Math.round(amountToWithdraw * coin.scalar) : null;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw`,\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\tsupplierCap,\n\t\t\t\t\ttx.pure.option('u64', withdrawInput),\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 Mint a referral for a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplyReferral = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supply_referral`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw referral fees from a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawReferralFees = (coinKey: string, referralId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw_referral_fees`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(referralId),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t// === Read-only/View Functions ===\n\n\t/**\n\t * @description Get the margin pool ID\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetId = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::id`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Check if a deepbook pool is allowed for borrowing\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {string} deepbookPoolId The ID of the deepbook pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tdeepbookPoolAllowed = (coinKey: string, deepbookPoolId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::deepbook_pool_allowed`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(deepbookPoolId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalSupply = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_supply`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::borrow_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the last update timestamp\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tlastUpdateTimestamp = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::last_update_timestamp`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the supply cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyCap = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_cap`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the max utilization rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmaxUtilizationRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::max_utilization_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the protocol spread\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tprotocolSpread = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::protocol_spread`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the minimum borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tminBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::min_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the current interest rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tinterestRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::interest_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply shares for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyShares = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply amount for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyAmount = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_amount`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId), tx.object.clock()],\n\t\t\ttype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AAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW,CAAC,GAAG,OAAO,WAAW,OAAO,CAAC;AAAA,QACzC,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,kBAA0B,CAAC,OAAoB;AACnF,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW,CAAC,GAAG,OAAO,WAAW,OAAO,GAAG,GAAG,KAAK,GAAG,aAAa,CAAC;AAAA,QACpE,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmB,CAAC,SAAiB,kBAA0B,CAAC,OAAoB;AACnF,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW,CAAC,GAAG,OAAO,WAAW,OAAO,GAAG,GAAG,KAAK,GAAG,aAAa,GAAG,GAAG,OAAO,MAAM,CAAC;AAAA,QACvF,eAAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AA/TC,uBAAK,SAAU;AAAA,EAChB;AA+TD;AAtUC;",
6
6
  "names": []
7
7
  }
@@ -73,7 +73,7 @@ export declare class MarginMaintainerContract {
73
73
  * @description Update the margin pool config
74
74
  * @param {string} coinKey The key to identify the margin pool
75
75
  * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
76
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
76
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
77
77
  * @returns A function that takes a Transaction object
78
78
  */
79
79
  updateMarginPoolConfig: (coinKey: string, marginPoolCap: TransactionObjectArgument, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => void;
@@ -191,12 +191,18 @@ class MarginMaintainerContract {
191
191
  * @description Update the margin pool config
192
192
  * @param {string} coinKey The key to identify the margin pool
193
193
  * @param {TransactionObjectArgument} marginPoolCap The margin pool cap
194
- * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
194
+ * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)
195
195
  * @returns A function that takes a Transaction object
196
196
  */
197
197
  this.updateMarginPoolConfig = (coinKey, marginPoolCap, marginPoolConfig) => (tx) => {
198
198
  const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
199
- const marginPoolConfigObject = this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
199
+ const hasRateLimit = marginPoolConfig.rateLimitCapacity !== void 0 && marginPoolConfig.rateLimitRefillRatePerMs !== void 0 && marginPoolConfig.rateLimitEnabled !== void 0;
200
+ const marginPoolConfigObject = hasRateLimit ? this.newMarginPoolConfigWithRateLimit(coinKey, {
201
+ ...marginPoolConfig,
202
+ rateLimitCapacity: marginPoolConfig.rateLimitCapacity,
203
+ rateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs,
204
+ rateLimitEnabled: marginPoolConfig.rateLimitEnabled
205
+ })(tx) : this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
200
206
  tx.moveCall({
201
207
  target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,
202
208
  arguments: [
@@ -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 { 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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(baseRate * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(baseSlope * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(optimalUtilization * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(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;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,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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(supplyCap * coin.scalar)),\n\t\t\t\t\ttx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(Math.round(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(Math.round(baseRate * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(baseSlope * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(optimalUtilization * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(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 (with optional rate limit)\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 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\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,QAC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AAA,QACjB;AAAA,QACA,eAAe,CAAC,WAAW,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,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,iBAAiB;AAAA,QAC3C,kBAAkB,iBAAiB;AAAA,MACpC,CAAC,EAAE,EAAE,IACJ,KAAK,oBAAoB,SAAS,gBAAgB,EAAE,EAAE;AACzD,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;AA1QA,uBAAK,SAAU;AAAA,EAChB;AA0QD;AAjRC;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
  }
@@ -24,10 +24,10 @@ export declare class MarginPoolContract {
24
24
  */
25
25
  supplyToMarginPool: (coinKey: string, supplierCap: TransactionObjectArgument, amountToDeposit: number, referralId?: string) => (tx: Transaction) => void;
26
26
  /**
27
- * @description Withdraw from a margin pool
27
+ * @description Withdraw from a margin pool. If amountToWithdraw is not provided, withdraws all.
28
28
  * @param {string} coinKey The key to identify the pool
29
29
  * @param {TransactionObjectArgument} supplierCap The supplier cap object
30
- * @param {number} amountToWithdraw The amount to withdraw
30
+ * @param {number} [amountToWithdraw] The amount to withdraw. If omitted, withdraws all.
31
31
  * @returns A function that takes a Transaction object
32
32
  */
33
33
  withdrawFromMarginPool: (coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) => (tx: Transaction) => import("@mysten/sui/transactions").TransactionResult;
@@ -57,23 +57,23 @@ class MarginPoolContract {
57
57
  });
58
58
  };
59
59
  /**
60
- * @description Withdraw from a margin pool
60
+ * @description Withdraw from a margin pool. If amountToWithdraw is not provided, withdraws all.
61
61
  * @param {string} coinKey The key to identify the pool
62
62
  * @param {TransactionObjectArgument} supplierCap The supplier cap object
63
- * @param {number} amountToWithdraw The amount to withdraw
63
+ * @param {number} [amountToWithdraw] The amount to withdraw. If omitted, withdraws all.
64
64
  * @returns A function that takes a Transaction object
65
65
  */
66
66
  this.withdrawFromMarginPool = (coinKey, supplierCap, amountToWithdraw) => (tx) => {
67
67
  const marginPool = __privateGet(this, _config).getMarginPool(coinKey);
68
68
  const coin = __privateGet(this, _config).getCoin(coinKey);
69
- const withdrawInput = amountToWithdraw ? tx.pure.u64(Math.round(amountToWithdraw * coin.scalar)) : null;
69
+ const withdrawInput = amountToWithdraw !== void 0 ? Math.round(amountToWithdraw * coin.scalar) : null;
70
70
  return tx.moveCall({
71
71
  target: `${__privateGet(this, _config).MARGIN_PACKAGE_ID}::margin_pool::withdraw`,
72
72
  arguments: [
73
73
  tx.object(marginPool.address),
74
74
  tx.object(__privateGet(this, _config).MARGIN_REGISTRY_ID),
75
75
  supplierCap,
76
- tx.object.option({ type: "u64", value: withdrawInput }),
76
+ tx.pure.option("u64", withdrawInput),
77
77
  tx.object.clock()
78
78
  ],
79
79
  typeArguments: [marginPool.type]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/transactions/marginPool.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * MarginPoolContract class for managing MarginPool operations.\n */\nexport class MarginPoolContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginPoolContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Mint a supplier cap for margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplierCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supplier_cap`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object.clock()],\n\t\t});\n\t};\n\n\t/**\n\t * @description Supply to a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyToMarginPool =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tsupplierCap: TransactionObjectArgument,\n\t\t\tamountToDeposit: number,\n\t\t\treferralId?: string,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = Math.round(amountToDeposit * coin.scalar);\n\t\t\tconst supply = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply`,\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\tsupplierCap,\n\t\t\t\t\tsupply,\n\t\t\t\t\ttx.object.option({\n\t\t\t\t\t\ttype: '0x2::object::ID',\n\t\t\t\t\t\tvalue: referralId ? tx.pure.id(referralId) : null,\n\t\t\t\t\t}),\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 Withdraw from a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} amountToWithdraw The amount to withdraw\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawFromMarginPool =\n\t\t(coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawInput = amountToWithdraw\n\t\t\t\t? tx.pure.u64(Math.round(amountToWithdraw * coin.scalar))\n\t\t\t\t: null;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw`,\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\tsupplierCap,\n\t\t\t\t\ttx.object.option({ type: 'u64', value: withdrawInput }),\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 Mint a referral for a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplyReferral = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supply_referral`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw referral fees from a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawReferralFees = (coinKey: string, referralId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw_referral_fees`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(referralId),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t// === Read-only/View Functions ===\n\n\t/**\n\t * @description Get the margin pool ID\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetId = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::id`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Check if a deepbook pool is allowed for borrowing\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {string} deepbookPoolId The ID of the deepbook pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tdeepbookPoolAllowed = (coinKey: string, deepbookPoolId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::deepbook_pool_allowed`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(deepbookPoolId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalSupply = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_supply`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::borrow_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the last update timestamp\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tlastUpdateTimestamp = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::last_update_timestamp`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the supply cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyCap = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_cap`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the max utilization rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmaxUtilizationRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::max_utilization_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the protocol spread\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tprotocolSpread = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::protocol_spread`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the minimum borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tminBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::min_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the current interest rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tinterestRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::interest_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply shares for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyShares = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply amount for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyAmount = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_amount`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId), tx.object.clock()],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n}\n"],
5
- "mappings": ";;;;;;;AAAA;AAEA,SAAS,uBAAuB;AAQzB,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAM/B,YAAY,QAAwB;AALpC;AAaA;AAAA;AAAA;AAAA;AAAA,2BAAkB,MAAM,CAAC,OAAoB;AAC5C,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW,CAAC,GAAG,OAAO,mBAAK,SAAQ,kBAAkB,GAAG,GAAG,OAAO,MAAM,CAAC;AAAA,MAC1E,CAAC;AAAA,IACF;AAUA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BACC,CACC,SACA,aACA,iBACA,eAED,CAAC,OAAoB;AACpB,SAAG,kBAAkB,mBAAK,SAAQ,OAAO;AACzC,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,YAAM,eAAe,KAAK,MAAM,kBAAkB,KAAK,MAAM;AAC7D,YAAM,SAAS,gBAAgB;AAAA,QAC9B,MAAM,KAAK;AAAA,QACX,SAAS;AAAA,MACV,CAAC;AAED,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAA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AAe,CAAC,WAAW,IAAI;AAAA,MAChC,CAAC;AAAA,IACF;AAhUC,uBAAK,SAAU;AAAA,EAChB;AAgUD;AAvUC;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * MarginPoolContract class for managing MarginPool operations.\n */\nexport class MarginPoolContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginPoolContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Mint a supplier cap for margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplierCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supplier_cap`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object.clock()],\n\t\t});\n\t};\n\n\t/**\n\t * @description Supply to a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyToMarginPool =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tsupplierCap: TransactionObjectArgument,\n\t\t\tamountToDeposit: number,\n\t\t\treferralId?: string,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = Math.round(amountToDeposit * coin.scalar);\n\t\t\tconst supply = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply`,\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\tsupplierCap,\n\t\t\t\t\tsupply,\n\t\t\t\t\ttx.object.option({\n\t\t\t\t\t\ttype: '0x2::object::ID',\n\t\t\t\t\t\tvalue: referralId ? tx.pure.id(referralId) : null,\n\t\t\t\t\t}),\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 Withdraw from a margin pool. If amountToWithdraw is not provided, withdraws all.\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {TransactionObjectArgument} supplierCap The supplier cap object\n\t * @param {number} [amountToWithdraw] The amount to withdraw. If omitted, withdraws all.\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawFromMarginPool =\n\t\t(coinKey: string, supplierCap: TransactionObjectArgument, amountToWithdraw?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawInput =\n\t\t\t\tamountToWithdraw !== undefined ? Math.round(amountToWithdraw * coin.scalar) : null;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw`,\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\tsupplierCap,\n\t\t\t\t\ttx.pure.option('u64', withdrawInput),\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 Mint a referral for a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintSupplyReferral = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supply_referral`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw referral fees from a margin pool\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} referralId The ID of the referral\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawReferralFees = (coinKey: string, referralId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw_referral_fees`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(referralId),\n\t\t\t],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t// === Read-only/View Functions ===\n\n\t/**\n\t * @description Get the margin pool ID\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetId = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::id`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Check if a deepbook pool is allowed for borrowing\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {string} deepbookPoolId The ID of the deepbook pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tdeepbookPoolAllowed = (coinKey: string, deepbookPoolId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::deepbook_pool_allowed`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(deepbookPoolId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalSupply = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_supply`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total supply shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttotalBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the total borrow shares\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowShares = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::borrow_shares`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the last update timestamp\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tlastUpdateTimestamp = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::last_update_timestamp`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the supply cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tsupplyCap = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_cap`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the max utilization rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tmaxUtilizationRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::max_utilization_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the protocol spread\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tprotocolSpread = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::protocol_spread`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the minimum borrow amount\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tminBorrow = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::min_borrow`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the current interest rate\n\t * @param {string} coinKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tinterestRate = (coinKey: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::interest_rate`,\n\t\t\targuments: [tx.object(marginPool.address)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply shares for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyShares = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_shares`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId)],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get user supply amount for a supplier cap\n\t * @param {string} coinKey The key to identify the pool\n\t * @param {string} supplierCapId The ID of the supplier cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserSupplyAmount = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_amount`,\n\t\t\targuments: [tx.object(marginPool.address), tx.pure.id(supplierCapId), tx.object.clock()],\n\t\t\ttypeArguments: [marginPool.type],\n\t\t});\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;AAAA;AAEA,SAAS,uBAAuB;AAQzB,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAM/B,YAAY,QAAwB;AALpC;AAaA;AAAA;AAAA;AAAA;AAAA,2BAAkB,MAAM,CAAC,OAAoB;AAC5C,aAAO,GAAG,SAAS;AAAA,QAClB,QAAQ,GAAG,mBAAK,SAAQ,iBAAiB;AAAA,QACzC,WAAW,CAAC,GAAG,OAAO,mBAAK,SAAQ,kBAAkB,GAAG,GAAG,OAAO,MAAM,CAAC;AAAA,MAC1E,CAAC;AAAA,IACF;AAUA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BACC,CACC,SACA,aACA,iBACA,eAED,CAAC,OAAoB;AACpB,SAAG,kBAAkB,mBAAK,SAAQ,OAAO;AACzC,YAAM,aAAa,mBAAK,SAAQ,cAAc,OAAO;AACrD,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,YAAM,eAAe,KAAK,MAAM,kBAAkB,KAAK,MAAM;AAC7D,YAAM,SAAS,gBAAgB;AAAA,QAC9B,MAAM,KAAK;AAAA,QACX,SAAS;AAAA,MACV,CAAC;AAED,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