{"version":3,"file":"marginRegistry.mjs","names":["#config","marginRegistryMoveCalls.poolEnabled","marginRegistryMoveCalls.getMarginPoolId","marginRegistryMoveCalls.getDeepbookPoolMarginPoolIds","marginRegistryMoveCalls.getMarginManagerIds","marginRegistryMoveCalls.baseMarginPoolId","marginRegistryMoveCalls.quoteMarginPoolId","marginRegistryMoveCalls.minWithdrawRiskRatio","marginRegistryMoveCalls.minBorrowRiskRatio","marginRegistryMoveCalls.minOpenRiskRatio","marginRegistryMoveCalls.liquidationRiskRatio","marginRegistryMoveCalls.targetLiquidationRiskRatio","marginRegistryMoveCalls.userLiquidationReward","marginRegistryMoveCalls.poolLiquidationReward","marginRegistryMoveCalls.allowedMaintainers","marginRegistryMoveCalls.allowedPauseCaps"],"sources":["../../src/transactions/marginRegistry.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport * as marginRegistryMoveCalls from '../contracts/deepbook_margin/margin_registry.js';\n\n/**\n * MarginRegistryContract class for managing MarginRegistry read-only operations.\n */\nexport class MarginRegistryContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginRegistryContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Check if a deepbook pool is enabled for margin trading\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tpoolEnabled = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.poolEnabled({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, pool: pool.address },\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the margin pool ID for a given asset\n\t * @param {string} coinKey The key to identify the coin\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetMarginPoolId = (coinKey: string) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.getMarginPoolId({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID },\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the margin pool IDs (base and quote) for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetDeepbookPoolMarginPoolIds = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.getDeepbookPoolMarginPoolIds({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the margin manager IDs for a given owner\n\t * @param {string} owner The owner address\n\t * @returns A function that takes a Transaction object\n\t */\n\tgetMarginManagerIds = (owner: string) => (tx: Transaction) => {\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.getMarginManagerIds({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, owner },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the base margin pool ID for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tbaseMarginPoolId = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.baseMarginPoolId({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the quote margin pool ID for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tquoteMarginPoolId = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.quoteMarginPoolId({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the minimum withdraw risk ratio for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tminWithdrawRiskRatio = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.minWithdrawRiskRatio({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the minimum borrow risk ratio for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tminBorrowRiskRatio = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.minBorrowRiskRatio({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the minimum risk ratio required to open a new position on\n\t * a deepbook pool. Distinct from `minBorrowRiskRatio`, which gates borrowing.\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tminOpenRiskRatio = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.minOpenRiskRatio({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the liquidation risk ratio for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tliquidationRiskRatio = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.liquidationRiskRatio({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the target liquidation risk ratio for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\ttargetLiquidationRiskRatio = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.targetLiquidationRiskRatio({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the user liquidation reward for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tuserLiquidationReward = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.userLiquidationReward({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get the pool liquidation reward for a deepbook pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tpoolLiquidationReward = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.poolLiquidationReward({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get all allowed maintainer cap IDs\n\t * @returns A function that takes a Transaction object\n\t */\n\tallowedMaintainers = () => (tx: Transaction) => {\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.allowedMaintainers({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Get all allowed pause cap IDs\n\t * @returns A function that takes a Transaction object\n\t */\n\tallowedPauseCaps = () => (tx: Transaction) => {\n\t\treturn tx.add(\n\t\t\tmarginRegistryMoveCalls.allowedPauseCaps({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: { self: this.#config.MARGIN_REGISTRY_ID },\n\t\t\t}),\n\t\t);\n\t};\n}\n"],"mappings":";;;;;;AAUA,IAAa,yBAAb,M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