@mysten/deepbook-v3 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/client.js +26 -20
- package/dist/cjs/client.js.map +2 -2
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/transactions/balanceManager.js +4 -2
- package/dist/cjs/transactions/balanceManager.js.map +2 -2
- package/dist/cjs/transactions/deepbook.js +17 -10
- package/dist/cjs/transactions/deepbook.js.map +2 -2
- package/dist/cjs/transactions/flashLoans.js +6 -4
- package/dist/cjs/transactions/flashLoans.js.map +2 -2
- package/dist/cjs/transactions/governance.js +5 -4
- package/dist/cjs/transactions/governance.js.map +2 -2
- package/dist/cjs/utils/constants.js +6 -6
- package/dist/cjs/utils/constants.js.map +1 -1
- package/dist/esm/client.js +26 -20
- package/dist/esm/client.js.map +2 -2
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/transactions/balanceManager.js +4 -2
- package/dist/esm/transactions/balanceManager.js.map +2 -2
- package/dist/esm/transactions/deepbook.js +17 -10
- package/dist/esm/transactions/deepbook.js.map +2 -2
- package/dist/esm/transactions/flashLoans.js +6 -4
- package/dist/esm/transactions/flashLoans.js.map +2 -2
- package/dist/esm/transactions/governance.js +5 -4
- package/dist/esm/transactions/governance.js.map +2 -2
- package/dist/esm/utils/constants.js +6 -6
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/client.ts +29 -23
- package/src/index.ts +2 -0
- package/src/transactions/balanceManager.ts +4 -2
- package/src/transactions/deepbook.ts +21 -10
- package/src/transactions/flashLoans.ts +6 -4
- package/src/transactions/governance.ts +5 -4
- package/src/utils/constants.ts +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mysten/deepbook-v3
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 36f1c6f: Rounding for numbers, exports update
|
|
8
|
+
- c51f186: New contract constants
|
|
9
|
+
|
|
10
|
+
## 0.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [a3e32fe]
|
|
15
|
+
- @mysten/sui@1.6.0
|
|
16
|
+
|
|
3
17
|
## 0.2.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/cjs/client.js
CHANGED
|
@@ -95,7 +95,7 @@ class DeepBookClient {
|
|
|
95
95
|
const adjusted_balance = balanceNumber / coin.scalar;
|
|
96
96
|
return {
|
|
97
97
|
coinType: coin.type,
|
|
98
|
-
balance: adjusted_balance
|
|
98
|
+
balance: Number(adjusted_balance.toFixed(9))
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
@@ -136,9 +136,9 @@ class DeepBookClient {
|
|
|
136
136
|
const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
137
137
|
return {
|
|
138
138
|
baseQuantity,
|
|
139
|
-
baseOut: baseOut / baseScalar,
|
|
140
|
-
quoteOut: quoteOut / quoteScalar,
|
|
141
|
-
deepRequired: deepRequired / import_config.DEEP_SCALAR
|
|
139
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
140
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
141
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
@@ -163,9 +163,9 @@ class DeepBookClient {
|
|
|
163
163
|
const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
164
164
|
return {
|
|
165
165
|
quoteQuantity,
|
|
166
|
-
baseOut: baseOut / baseScalar,
|
|
167
|
-
quoteOut: quoteOut / quoteScalar,
|
|
168
|
-
deepRequired: deepRequired / import_config.DEEP_SCALAR
|
|
166
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
167
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
168
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
@@ -192,9 +192,9 @@ class DeepBookClient {
|
|
|
192
192
|
return {
|
|
193
193
|
baseQuantity,
|
|
194
194
|
quoteQuantity,
|
|
195
|
-
baseOut: baseOut / baseScalar,
|
|
196
|
-
quoteOut: quoteOut / quoteScalar,
|
|
197
|
-
deepRequired: deepRequired / import_config.DEEP_SCALAR
|
|
195
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
196
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
197
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
@@ -276,9 +276,11 @@ class DeepBookClient {
|
|
|
276
276
|
const parsed_quantities = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(quantities));
|
|
277
277
|
return {
|
|
278
278
|
prices: parsed_prices.map(
|
|
279
|
-
(price) => Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar
|
|
279
|
+
(price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9))
|
|
280
280
|
),
|
|
281
|
-
quantities: parsed_quantities.map(
|
|
281
|
+
quantities: parsed_quantities.map(
|
|
282
|
+
(price) => Number((Number(price) / baseCoin.scalar).toFixed(9))
|
|
283
|
+
)
|
|
282
284
|
};
|
|
283
285
|
}
|
|
284
286
|
/**
|
|
@@ -308,13 +310,17 @@ class DeepBookClient {
|
|
|
308
310
|
const ask_parsed_quantities = import_bcs.bcs.vector(import_bcs.bcs.u64()).parse(new Uint8Array(ask_quantities));
|
|
309
311
|
return {
|
|
310
312
|
bid_prices: bid_parsed_prices.map(
|
|
311
|
-
(price) => Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar
|
|
313
|
+
(price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9))
|
|
314
|
+
),
|
|
315
|
+
bid_quantities: bid_parsed_quantities.map(
|
|
316
|
+
(quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9))
|
|
312
317
|
),
|
|
313
|
-
bid_quantities: bid_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar),
|
|
314
318
|
ask_prices: ask_parsed_prices.map(
|
|
315
|
-
(price) => Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar
|
|
319
|
+
(price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9))
|
|
316
320
|
),
|
|
317
|
-
ask_quantities: ask_parsed_quantities.map(
|
|
321
|
+
ask_quantities: ask_parsed_quantities.map(
|
|
322
|
+
(quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9))
|
|
323
|
+
)
|
|
318
324
|
};
|
|
319
325
|
}
|
|
320
326
|
/**
|
|
@@ -337,9 +343,9 @@ class DeepBookClient {
|
|
|
337
343
|
const quoteInVault = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
|
|
338
344
|
const deepInVault = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
339
345
|
return {
|
|
340
|
-
base: baseInVault / baseScalar,
|
|
341
|
-
quote: quoteInVault / quoteScalar,
|
|
342
|
-
deep: deepInVault / import_config.DEEP_SCALAR
|
|
346
|
+
base: Number((baseInVault / baseScalar).toFixed(9)),
|
|
347
|
+
quote: Number((quoteInVault / quoteScalar).toFixed(9)),
|
|
348
|
+
deep: Number((deepInVault / import_config.DEEP_SCALAR).toFixed(9))
|
|
343
349
|
};
|
|
344
350
|
}
|
|
345
351
|
/**
|
|
@@ -379,7 +385,7 @@ class DeepBookClient {
|
|
|
379
385
|
const bytes = res.results[0].returnValues[0][0];
|
|
380
386
|
const parsed_mid_price = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
|
|
381
387
|
const adjusted_mid_price = parsed_mid_price * baseCoin.scalar / quoteCoin.scalar / import_config.FLOAT_SCALAR;
|
|
382
|
-
return adjusted_mid_price;
|
|
388
|
+
return Number(adjusted_mid_price.toFixed(9));
|
|
383
389
|
}
|
|
384
390
|
}
|
|
385
391
|
_config = new WeakMap();
|
package/dist/cjs/client.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/client.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { bcs } from '@mysten/sui/bcs';\nimport type { SuiClient } from '@mysten/sui/client';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport { BalanceManagerContract } from './transactions/balanceManager.js';\nimport { DeepBookContract } from './transactions/deepbook.js';\nimport { DeepBookAdminContract } from './transactions/deepbookAdmin.js';\nimport { FlashLoanContract } from './transactions/flashLoans.js';\nimport { GovernanceContract } from './transactions/governance.js';\nimport type { BalanceManager, Environment } from './types/index.js';\nimport { DEEP_SCALAR, DeepBookConfig, FLOAT_SCALAR } from './utils/config.js';\nimport type { CoinMap, PoolMap } from './utils/constants.js';\n\n/**\n * DeepBookClient class for managing DeepBook operations.\n */\nexport class DeepBookClient {\n\tclient: SuiClient;\n\t#config: DeepBookConfig;\n\t#address: string;\n\tbalanceManager: BalanceManagerContract;\n\tdeepBook: DeepBookContract;\n\tdeepBookAdmin: DeepBookAdminContract;\n\tflashLoans: FlashLoanContract;\n\tgovernance: GovernanceContract;\n\n\t/**\n\t * @param {SuiClient} client SuiClient instance\n\t * @param {string} address Address of the client\n\t * @param {Environment} env Environment configuration\n\t * @param {Object.<string, BalanceManager>} [balanceManagers] Optional initial BalanceManager map\n\t * @param {CoinMap} [coins] Optional initial CoinMap\n\t * @param {PoolMap} [pools] Optional initial PoolMap\n\t * @param {string} [adminCap] Optional admin capability\n\t */\n\tconstructor({\n\t\tclient,\n\t\taddress,\n\t\tenv,\n\t\tbalanceManagers,\n\t\tcoins,\n\t\tpools,\n\t\tadminCap,\n\t}: {\n\t\tclient: SuiClient;\n\t\taddress: string;\n\t\tenv: Environment;\n\t\tbalanceManagers?: { [key: string]: BalanceManager };\n\t\tcoins?: CoinMap;\n\t\tpools?: PoolMap;\n\t\tadminCap?: string;\n\t}) {\n\t\tthis.client = client;\n\t\tthis.#address = normalizeSuiAddress(address);\n\t\tthis.#config = new DeepBookConfig({\n\t\t\taddress: this.#address,\n\t\t\tenv,\n\t\t\tbalanceManagers,\n\t\t\tcoins,\n\t\t\tpools,\n\t\t\tadminCap,\n\t\t});\n\t\tthis.balanceManager = new BalanceManagerContract(this.#config);\n\t\tthis.deepBook = new DeepBookContract(this.#config);\n\t\tthis.deepBookAdmin = new DeepBookAdminContract(this.#config);\n\t\tthis.flashLoans = new FlashLoanContract(this.#config);\n\t\tthis.governance = new GovernanceContract(this.#config);\n\t}\n\n\t/**\n\t * @description Check the balance of a balance manager for a specific coin\n\t * @param {string} managerKey Key of the balance manager\n\t * @param {string} coinKey Key of the coin\n\t * @returns {Promise<{ coinType: string, balance: number }>} An object with coin type and balance\n\t */\n\tasync checkManagerBalance(managerKey: string, coinKey: string) {\n\t\tconst tx = new Transaction();\n\t\tconst coin = this.#config.getCoin(coinKey);\n\n\t\ttx.add(this.balanceManager.checkManagerBalance(managerKey, coinKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: this.#address,\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bytes = res.results![0].returnValues![0][0];\n\t\tconst parsed_balance = bcs.U64.parse(new Uint8Array(bytes));\n\t\tconst balanceNumber = Number(parsed_balance);\n\t\tconst adjusted_balance = balanceNumber / coin.scalar;\n\n\t\treturn {\n\t\t\tcoinType: coin.type,\n\t\t\tbalance: adjusted_balance,\n\t\t};\n\t}\n\n\t/**\n\t * @description Check if a pool is whitelisted\n\t * @param {string} poolKey Key of the pool\n\t * @returns {Promise<boolean>} Boolean indicating if the pool is whitelisted\n\t */\n\tasync whitelisted(poolKey: string) {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.deepBook.whitelisted(poolKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bytes = res.results![0].returnValues![0][0];\n\t\tconst whitelisted = bcs.Bool.parse(new Uint8Array(bytes));\n\n\t\treturn whitelisted;\n\t}\n\n\t/**\n\t * @description Get the quote quantity out for a given base quantity\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} baseQuantity Base quantity to convert\n\t * @returns {Promise<{ baseQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}\n\t * An object with base quantity, base out, quote out, and deep required for the dry run\n\t */\n\tasync getQuoteQuantityOut(poolKey: string, baseQuantity: number) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.getQuoteQuantityOut(poolKey, baseQuantity));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tbaseQuantity,\n\t\t\tbaseOut: baseOut / baseScalar,\n\t\t\tquoteOut: quoteOut / quoteScalar,\n\t\t\tdeepRequired: deepRequired / DEEP_SCALAR,\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the base quantity out for a given quote quantity\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} quoteQuantity Quote quantity to convert\n\t * @returns {Promise<{ quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}\n\t * An object with quote quantity, base out, quote out, and deep required for the dry run\n\t */\n\tasync getBaseQuantityOut(poolKey: string, quoteQuantity: number) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.getBaseQuantityOut(poolKey, quoteQuantity));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tquoteQuantity: quoteQuantity,\n\t\t\tbaseOut: baseOut / baseScalar,\n\t\t\tquoteOut: quoteOut / quoteScalar,\n\t\t\tdeepRequired: deepRequired / DEEP_SCALAR,\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the output quantities for given base and quote quantities. Only one quantity can be non-zero\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} baseQuantity Base quantity to convert\n\t * @param {number} quoteQuantity Quote quantity to convert\n\t * @returns {Promise<{ baseQuantity: number, quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}\n\t * An object with base quantity, quote quantity, base out, quote out, and deep required for the dry run\n\t */\n\tasync getQuantityOut(poolKey: string, baseQuantity: number, quoteQuantity: number) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.getQuantityOut(poolKey, baseQuantity, quoteQuantity));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tbaseQuantity,\n\t\t\tquoteQuantity,\n\t\t\tbaseOut: baseOut / baseScalar,\n\t\t\tquoteOut: quoteOut / quoteScalar,\n\t\t\tdeepRequired: deepRequired / DEEP_SCALAR,\n\t\t};\n\t}\n\n\t/**\n\t * @description Get open orders for a balance manager in a pool\n\t * @param {string} poolKey Key of the pool\n\t * @param {string} managerKey Key of the balance manager\n\t * @returns {Promise<Array>} An array of open order IDs\n\t */\n\tasync accountOpenOrders(poolKey: string, managerKey: string) {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.deepBook.accountOpenOrders(poolKey, managerKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst order_ids = res.results![0].returnValues![0][0];\n\t\tconst VecSet = bcs.struct('VecSet', {\n\t\t\tconstants: bcs.vector(bcs.U128),\n\t\t});\n\n\t\treturn VecSet.parse(new Uint8Array(order_ids)).constants;\n\t}\n\n\t/**\n\t * @description Get the order information for a specific order in a pool\n\t * @param {string} poolKey Key of the pool\n\t * @param {string} orderId Order ID\n\t * @returns {Promise<Object>} A promise that resolves to an object containing the order information\n\t */\n\tasync getOrder(poolKey: string, orderId: string) {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.deepBook.getOrder(poolKey, orderId));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst ID = bcs.struct('ID', {\n\t\t\tbytes: bcs.Address,\n\t\t});\n\t\tconst OrderDeepPrice = bcs.struct('OrderDeepPrice', {\n\t\t\tasset_is_base: bcs.bool(),\n\t\t\tdeep_per_asset: bcs.u64(),\n\t\t});\n\t\tconst Order = bcs.struct('Order', {\n\t\t\tbalance_manager_id: ID,\n\t\t\torder_id: bcs.u128(),\n\t\t\tclient_order_id: bcs.u64(),\n\t\t\tquantity: bcs.u64(),\n\t\t\tfilled_quantity: bcs.u64(),\n\t\t\tfee_is_deep: bcs.bool(),\n\t\t\torder_deep_price: OrderDeepPrice,\n\t\t\tepoch: bcs.u64(),\n\t\t\tstatus: bcs.u8(),\n\t\t\texpire_timestamp: bcs.u64(),\n\t\t});\n\n\t\tconst orderInformation = res.results![0].returnValues![0][0];\n\t\treturn Order.parse(new Uint8Array(orderInformation));\n\t}\n\n\t/**\n\t * @description Get level 2 order book specifying range of price\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} priceLow Lower bound of the price range\n\t * @param {number} priceHigh Upper bound of the price range\n\t * @param {boolean} isBid Whether to get bid or ask orders\n\t * @returns {Promise<{ prices: Array<number>, quantities: Array<number> }>}\n\t * An object with arrays of prices and quantities\n\t */\n\tasync getLevel2Range(poolKey: string, priceLow: number, priceHigh: number, isBid: boolean) {\n\t\tconst tx = new 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\n\t\ttx.add(this.deepBook.getLevel2Range(poolKey, priceLow, priceHigh, isBid));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst prices = res.results![0].returnValues![0][0];\n\t\tconst parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(prices));\n\t\tconst quantities = res.results![0].returnValues![1][0];\n\t\tconst parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(quantities));\n\n\t\treturn {\n\t\t\tprices: parsed_prices.map(\n\t\t\t\t(price) => (Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar,\n\t\t\t),\n\t\t\tquantities: parsed_quantities.map((price) => Number(price) / baseCoin.scalar),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get level 2 order book ticks from mid-price for a pool\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} ticks Number of ticks from mid-price\n\t * @returns {Promise<{ bid_prices: Array<number>, bid_quantities: Array<number>, ask_prices: Array<number>, ask_quantities: Array<number> }>}\n\t * An object with arrays of prices and quantities\n\t */\n\tasync getLevel2TicksFromMid(poolKey: string, ticks: number) {\n\t\tconst tx = new 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\n\t\ttx.add(this.deepBook.getLevel2TicksFromMid(poolKey, ticks));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bid_prices = res.results![0].returnValues![0][0];\n\t\tconst bid_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_prices));\n\t\tconst bid_quantities = res.results![0].returnValues![1][0];\n\t\tconst bid_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_quantities));\n\n\t\tconst ask_prices = res.results![0].returnValues![2][0];\n\t\tconst ask_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_prices));\n\t\tconst ask_quantities = res.results![0].returnValues![3][0];\n\t\tconst ask_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_quantities));\n\n\t\treturn {\n\t\t\tbid_prices: bid_parsed_prices.map(\n\t\t\t\t(price) => (Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar,\n\t\t\t),\n\t\t\tbid_quantities: bid_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar),\n\t\t\task_prices: ask_parsed_prices.map(\n\t\t\t\t(price) => (Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar,\n\t\t\t),\n\t\t\task_quantities: ask_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the vault balances for a pool\n\t * @param {string} poolKey Key of the pool\n\t * @returns {Promise<{ base: number, quote: number, deep: number }>}\n\t * An object with base, quote, and deep balances in the vault\n\t */\n\tasync vaultBalances(poolKey: string) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.vaultBalances(poolKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tbase: baseInVault / baseScalar,\n\t\t\tquote: quoteInVault / quoteScalar,\n\t\t\tdeep: deepInVault / DEEP_SCALAR,\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the pool ID by asset types\n\t * @param {string} baseType Type of the base asset\n\t * @param {string} quoteType Type of the quote asset\n\t * @returns {Promise<string>} The address of the pool\n\t */\n\tasync getPoolIdByAssets(baseType: string, quoteType: string) {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.deepBook.getPoolIdByAssets(baseType, quoteType));\n\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst ID = bcs.struct('ID', {\n\t\t\tbytes: bcs.Address,\n\t\t});\n\t\tconst address = ID.parse(new Uint8Array(res.results![0].returnValues![0][0]))['bytes'];\n\n\t\treturn address;\n\t}\n\n\t/**\n\t * @description Get the mid price for a pool\n\t * @param {string} poolKey Key of the pool\n\t * @returns {Promise<number>} The mid price\n\t */\n\tasync midPrice(poolKey: string) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\ttx.add(this.deepBook.midPrice(poolKey));\n\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bytes = res.results![0].returnValues![0][0];\n\t\tconst parsed_mid_price = Number(bcs.U64.parse(new Uint8Array(bytes)));\n\t\tconst adjusted_mid_price =\n\t\t\t(parsed_mid_price * baseCoin.scalar) / quoteCoin.scalar / FLOAT_SCALAR;\n\n\t\treturn adjusted_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E,aAAc,CAAC,EAAE,CAAC;AAChD,UAAM,iBAAiB,eAAI,IAAI,MAAM,IAAI,WAAW,KAAK,CAAC;AAC1D,UAAM,gBAAgB,OAAO,cAAc;AAC3C,UAAM,mBAAmB,gBAAgB,KAAK;AAE9C,WAAO;AAAA,MACN,UAAU,KAAK;AAAA,MACf,SAAS;AAAA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { bcs } from '@mysten/sui/bcs';\nimport type { SuiClient } from '@mysten/sui/client';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport { BalanceManagerContract } from './transactions/balanceManager.js';\nimport { DeepBookContract } from './transactions/deepbook.js';\nimport { DeepBookAdminContract } from './transactions/deepbookAdmin.js';\nimport { FlashLoanContract } from './transactions/flashLoans.js';\nimport { GovernanceContract } from './transactions/governance.js';\nimport type { BalanceManager, Environment } from './types/index.js';\nimport { DEEP_SCALAR, DeepBookConfig, FLOAT_SCALAR } from './utils/config.js';\nimport type { CoinMap, PoolMap } from './utils/constants.js';\n\n/**\n * DeepBookClient class for managing DeepBook operations.\n */\nexport class DeepBookClient {\n\tclient: SuiClient;\n\t#config: DeepBookConfig;\n\t#address: string;\n\tbalanceManager: BalanceManagerContract;\n\tdeepBook: DeepBookContract;\n\tdeepBookAdmin: DeepBookAdminContract;\n\tflashLoans: FlashLoanContract;\n\tgovernance: GovernanceContract;\n\n\t/**\n\t * @param {SuiClient} client SuiClient instance\n\t * @param {string} address Address of the client\n\t * @param {Environment} env Environment configuration\n\t * @param {Object.<string, BalanceManager>} [balanceManagers] Optional initial BalanceManager map\n\t * @param {CoinMap} [coins] Optional initial CoinMap\n\t * @param {PoolMap} [pools] Optional initial PoolMap\n\t * @param {string} [adminCap] Optional admin capability\n\t */\n\tconstructor({\n\t\tclient,\n\t\taddress,\n\t\tenv,\n\t\tbalanceManagers,\n\t\tcoins,\n\t\tpools,\n\t\tadminCap,\n\t}: {\n\t\tclient: SuiClient;\n\t\taddress: string;\n\t\tenv: Environment;\n\t\tbalanceManagers?: { [key: string]: BalanceManager };\n\t\tcoins?: CoinMap;\n\t\tpools?: PoolMap;\n\t\tadminCap?: string;\n\t}) {\n\t\tthis.client = client;\n\t\tthis.#address = normalizeSuiAddress(address);\n\t\tthis.#config = new DeepBookConfig({\n\t\t\taddress: this.#address,\n\t\t\tenv,\n\t\t\tbalanceManagers,\n\t\t\tcoins,\n\t\t\tpools,\n\t\t\tadminCap,\n\t\t});\n\t\tthis.balanceManager = new BalanceManagerContract(this.#config);\n\t\tthis.deepBook = new DeepBookContract(this.#config);\n\t\tthis.deepBookAdmin = new DeepBookAdminContract(this.#config);\n\t\tthis.flashLoans = new FlashLoanContract(this.#config);\n\t\tthis.governance = new GovernanceContract(this.#config);\n\t}\n\n\t/**\n\t * @description Check the balance of a balance manager for a specific coin\n\t * @param {string} managerKey Key of the balance manager\n\t * @param {string} coinKey Key of the coin\n\t * @returns {Promise<{ coinType: string, balance: number }>} An object with coin type and balance\n\t */\n\tasync checkManagerBalance(managerKey: string, coinKey: string) {\n\t\tconst tx = new Transaction();\n\t\tconst coin = this.#config.getCoin(coinKey);\n\n\t\ttx.add(this.balanceManager.checkManagerBalance(managerKey, coinKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: this.#address,\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bytes = res.results![0].returnValues![0][0];\n\t\tconst parsed_balance = bcs.U64.parse(new Uint8Array(bytes));\n\t\tconst balanceNumber = Number(parsed_balance);\n\t\tconst adjusted_balance = balanceNumber / coin.scalar;\n\n\t\treturn {\n\t\t\tcoinType: coin.type,\n\t\t\tbalance: Number(adjusted_balance.toFixed(9)),\n\t\t};\n\t}\n\n\t/**\n\t * @description Check if a pool is whitelisted\n\t * @param {string} poolKey Key of the pool\n\t * @returns {Promise<boolean>} Boolean indicating if the pool is whitelisted\n\t */\n\tasync whitelisted(poolKey: string) {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.deepBook.whitelisted(poolKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bytes = res.results![0].returnValues![0][0];\n\t\tconst whitelisted = bcs.Bool.parse(new Uint8Array(bytes));\n\n\t\treturn whitelisted;\n\t}\n\n\t/**\n\t * @description Get the quote quantity out for a given base quantity\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} baseQuantity Base quantity to convert\n\t * @returns {Promise<{ baseQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}\n\t * An object with base quantity, base out, quote out, and deep required for the dry run\n\t */\n\tasync getQuoteQuantityOut(poolKey: string, baseQuantity: number) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.getQuoteQuantityOut(poolKey, baseQuantity));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tbaseQuantity,\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the base quantity out for a given quote quantity\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} quoteQuantity Quote quantity to convert\n\t * @returns {Promise<{ quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}\n\t * An object with quote quantity, base out, quote out, and deep required for the dry run\n\t */\n\tasync getBaseQuantityOut(poolKey: string, quoteQuantity: number) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.getBaseQuantityOut(poolKey, quoteQuantity));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tquoteQuantity: quoteQuantity,\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the output quantities for given base and quote quantities. Only one quantity can be non-zero\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} baseQuantity Base quantity to convert\n\t * @param {number} quoteQuantity Quote quantity to convert\n\t * @returns {Promise<{ baseQuantity: number, quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number }>}\n\t * An object with base quantity, quote quantity, base out, quote out, and deep required for the dry run\n\t */\n\tasync getQuantityOut(poolKey: string, baseQuantity: number, quoteQuantity: number) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.getQuantityOut(poolKey, baseQuantity, quoteQuantity));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteOut = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepRequired = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tbaseQuantity,\n\t\t\tquoteQuantity,\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get open orders for a balance manager in a pool\n\t * @param {string} poolKey Key of the pool\n\t * @param {string} managerKey Key of the balance manager\n\t * @returns {Promise<Array>} An array of open order IDs\n\t */\n\tasync accountOpenOrders(poolKey: string, managerKey: string) {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.deepBook.accountOpenOrders(poolKey, managerKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst order_ids = res.results![0].returnValues![0][0];\n\t\tconst VecSet = bcs.struct('VecSet', {\n\t\t\tconstants: bcs.vector(bcs.U128),\n\t\t});\n\n\t\treturn VecSet.parse(new Uint8Array(order_ids)).constants;\n\t}\n\n\t/**\n\t * @description Get the order information for a specific order in a pool\n\t * @param {string} poolKey Key of the pool\n\t * @param {string} orderId Order ID\n\t * @returns {Promise<Object>} A promise that resolves to an object containing the order information\n\t */\n\tasync getOrder(poolKey: string, orderId: string) {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.deepBook.getOrder(poolKey, orderId));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst ID = bcs.struct('ID', {\n\t\t\tbytes: bcs.Address,\n\t\t});\n\t\tconst OrderDeepPrice = bcs.struct('OrderDeepPrice', {\n\t\t\tasset_is_base: bcs.bool(),\n\t\t\tdeep_per_asset: bcs.u64(),\n\t\t});\n\t\tconst Order = bcs.struct('Order', {\n\t\t\tbalance_manager_id: ID,\n\t\t\torder_id: bcs.u128(),\n\t\t\tclient_order_id: bcs.u64(),\n\t\t\tquantity: bcs.u64(),\n\t\t\tfilled_quantity: bcs.u64(),\n\t\t\tfee_is_deep: bcs.bool(),\n\t\t\torder_deep_price: OrderDeepPrice,\n\t\t\tepoch: bcs.u64(),\n\t\t\tstatus: bcs.u8(),\n\t\t\texpire_timestamp: bcs.u64(),\n\t\t});\n\n\t\tconst orderInformation = res.results![0].returnValues![0][0];\n\t\treturn Order.parse(new Uint8Array(orderInformation));\n\t}\n\n\t/**\n\t * @description Get level 2 order book specifying range of price\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} priceLow Lower bound of the price range\n\t * @param {number} priceHigh Upper bound of the price range\n\t * @param {boolean} isBid Whether to get bid or ask orders\n\t * @returns {Promise<{ prices: Array<number>, quantities: Array<number> }>}\n\t * An object with arrays of prices and quantities\n\t */\n\tasync getLevel2Range(poolKey: string, priceLow: number, priceHigh: number, isBid: boolean) {\n\t\tconst tx = new 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\n\t\ttx.add(this.deepBook.getLevel2Range(poolKey, priceLow, priceHigh, isBid));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst prices = res.results![0].returnValues![0][0];\n\t\tconst parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(prices));\n\t\tconst quantities = res.results![0].returnValues![1][0];\n\t\tconst parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(quantities));\n\n\t\treturn {\n\t\t\tprices: parsed_prices.map((price) =>\n\t\t\t\tNumber(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)),\n\t\t\t),\n\t\t\tquantities: parsed_quantities.map((price) =>\n\t\t\t\tNumber((Number(price) / baseCoin.scalar).toFixed(9)),\n\t\t\t),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get level 2 order book ticks from mid-price for a pool\n\t * @param {string} poolKey Key of the pool\n\t * @param {number} ticks Number of ticks from mid-price\n\t * @returns {Promise<{ bid_prices: Array<number>, bid_quantities: Array<number>, ask_prices: Array<number>, ask_quantities: Array<number> }>}\n\t * An object with arrays of prices and quantities\n\t */\n\tasync getLevel2TicksFromMid(poolKey: string, ticks: number) {\n\t\tconst tx = new 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\n\t\ttx.add(this.deepBook.getLevel2TicksFromMid(poolKey, ticks));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bid_prices = res.results![0].returnValues![0][0];\n\t\tconst bid_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_prices));\n\t\tconst bid_quantities = res.results![0].returnValues![1][0];\n\t\tconst bid_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(bid_quantities));\n\n\t\tconst ask_prices = res.results![0].returnValues![2][0];\n\t\tconst ask_parsed_prices = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_prices));\n\t\tconst ask_quantities = res.results![0].returnValues![3][0];\n\t\tconst ask_parsed_quantities = bcs.vector(bcs.u64()).parse(new Uint8Array(ask_quantities));\n\n\t\treturn {\n\t\t\tbid_prices: bid_parsed_prices.map((price) =>\n\t\t\t\tNumber(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)),\n\t\t\t),\n\t\t\tbid_quantities: bid_parsed_quantities.map((quantity) =>\n\t\t\t\tNumber((Number(quantity) / baseCoin.scalar).toFixed(9)),\n\t\t\t),\n\t\t\task_prices: ask_parsed_prices.map((price) =>\n\t\t\t\tNumber(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)),\n\t\t\t),\n\t\t\task_quantities: ask_parsed_quantities.map((quantity) =>\n\t\t\t\tNumber((Number(quantity) / baseCoin.scalar).toFixed(9)),\n\t\t\t),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the vault balances for a pool\n\t * @param {string} poolKey Key of the pool\n\t * @returns {Promise<{ base: number, quote: number, deep: number }>}\n\t * An object with base, quote, and deep balances in the vault\n\t */\n\tasync vaultBalances(poolKey: string) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseScalar = this.#config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.deepBook.vaultBalances(poolKey));\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst baseInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![0][0])));\n\t\tconst quoteInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![1][0])));\n\t\tconst deepInVault = Number(bcs.U64.parse(new Uint8Array(res.results![0].returnValues![2][0])));\n\n\t\treturn {\n\t\t\tbase: Number((baseInVault / baseScalar).toFixed(9)),\n\t\t\tquote: Number((quoteInVault / quoteScalar).toFixed(9)),\n\t\t\tdeep: Number((deepInVault / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\t/**\n\t * @description Get the pool ID by asset types\n\t * @param {string} baseType Type of the base asset\n\t * @param {string} quoteType Type of the quote asset\n\t * @returns {Promise<string>} The address of the pool\n\t */\n\tasync getPoolIdByAssets(baseType: string, quoteType: string) {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.deepBook.getPoolIdByAssets(baseType, quoteType));\n\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst ID = bcs.struct('ID', {\n\t\t\tbytes: bcs.Address,\n\t\t});\n\t\tconst address = ID.parse(new Uint8Array(res.results![0].returnValues![0][0]))['bytes'];\n\n\t\treturn address;\n\t}\n\n\t/**\n\t * @description Get the mid price for a pool\n\t * @param {string} poolKey Key of the pool\n\t * @returns {Promise<number>} The mid price\n\t */\n\tasync midPrice(poolKey: string) {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\ttx.add(this.deepBook.midPrice(poolKey));\n\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\tconst res = await this.client.devInspectTransactionBlock({\n\t\t\tsender: normalizeSuiAddress(this.#address),\n\t\t\ttransactionBlock: tx,\n\t\t});\n\n\t\tconst bytes = res.results![0].returnValues![0][0];\n\t\tconst parsed_mid_price = Number(bcs.U64.parse(new Uint8Array(bytes)));\n\t\tconst adjusted_mid_price =\n\t\t\t(parsed_mid_price * baseCoin.scalar) / quoteCoin.scalar / FLOAT_SCALAR;\n\n\t\treturn Number(adjusted_mid_price.toFixed(9));\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;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kBAAkB;AAAA,IACnB,CAAC;AAED,UAAM,QAAQ,IAAI,QAAS,CAAC,EAAE,aAAc,CAAC,EAAE,CAAC;AAChD,UAAM,mBAAmB,OAAO,eAAI,IAAI,MAAM,IAAI,WAAW,KAAK,CAAC,CAAC;AACpE,UAAM,qBACJ,mBAAmB,SAAS,SAAU,UAAU,SAAS;AAE3D,WAAO,OAAO,mBAAmB,QAAQ,CAAC,CAAC;AAAA,EAC5C;AACD;AA7ZC;AACA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export { DeepBookAdminContract } from './transactions/deepbookAdmin.js';
|
|
|
5
5
|
export { FlashLoanContract } from './transactions/flashLoans.js';
|
|
6
6
|
export { GovernanceContract } from './transactions/governance.js';
|
|
7
7
|
export { DeepBookConfig } from './utils/config.js';
|
|
8
|
+
export type { BalanceManager, Coin, Pool } from './types/index.js';
|
|
9
|
+
export type { CoinMap, PoolMap } from './utils/constants.js';
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { DeepBookClient } from './client.js';\nexport { BalanceManagerContract } from './transactions/balanceManager.js';\nexport { DeepBookContract } from './transactions/deepbook.js';\nexport { DeepBookAdminContract } from './transactions/deepbookAdmin.js';\nexport { FlashLoanContract } from './transactions/flashLoans.js';\nexport { GovernanceContract } from './transactions/governance.js';\nexport { DeepBookConfig } from './utils/config.js';\n"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { DeepBookClient } from './client.js';\nexport { BalanceManagerContract } from './transactions/balanceManager.js';\nexport { DeepBookContract } from './transactions/deepbook.js';\nexport { DeepBookAdminContract } from './transactions/deepbookAdmin.js';\nexport { FlashLoanContract } from './transactions/flashLoans.js';\nexport { GovernanceContract } from './transactions/governance.js';\nexport { DeepBookConfig } from './utils/config.js';\nexport type { BalanceManager, Coin, Pool } from './types/index.js';\nexport type { CoinMap, PoolMap } from './utils/constants.js';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA+B;AAC/B,4BAAuC;AACvC,sBAAiC;AACjC,2BAAsC;AACtC,wBAAkC;AAClC,wBAAmC;AACnC,oBAA+B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -61,9 +61,10 @@ class BalanceManagerContract {
|
|
|
61
61
|
tx.setSenderIfNotSet(__privateGet(this, _config).address);
|
|
62
62
|
const managerId = __privateGet(this, _config).getBalanceManager(managerKey).address;
|
|
63
63
|
const coin = __privateGet(this, _config).getCoin(coinKey);
|
|
64
|
+
const depositInput = Math.round(amountToDeposit * coin.scalar);
|
|
64
65
|
const deposit = (0, import_transactions.coinWithBalance)({
|
|
65
66
|
type: coin.type,
|
|
66
|
-
balance:
|
|
67
|
+
balance: depositInput
|
|
67
68
|
});
|
|
68
69
|
tx.moveCall({
|
|
69
70
|
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::balance_manager::deposit`,
|
|
@@ -82,9 +83,10 @@ class BalanceManagerContract {
|
|
|
82
83
|
this.withdrawFromManager = (managerKey, coinKey, amountToWithdraw, recipient) => (tx) => {
|
|
83
84
|
const managerId = __privateGet(this, _config).getBalanceManager(managerKey).address;
|
|
84
85
|
const coin = __privateGet(this, _config).getCoin(coinKey);
|
|
86
|
+
const withdrawInput = Math.round(amountToWithdraw * coin.scalar);
|
|
85
87
|
const coinObject = tx.moveCall({
|
|
86
88
|
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`,
|
|
87
|
-
arguments: [tx.object(managerId), tx.pure.u64(
|
|
89
|
+
arguments: [tx.object(managerId), tx.pure.u64(withdrawInput)],
|
|
88
90
|
typeArguments: [coin.type]
|
|
89
91
|
});
|
|
90
92
|
tx.transferObjects([coinObject], recipient);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/transactions/balanceManager.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * BalanceManagerContract class for managing BalanceManager operations.\n */\nexport class BalanceManagerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for BalanceManagerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Create and share a new BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAndShareBalanceManager = () => (tx: Transaction) => {\n\t\tconst manager = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::new`,\n\t\t});\n\n\t\ttx.moveCall({\n\t\t\ttarget: '0x2::transfer::public_share_object',\n\t\t\targuments: [manager],\n\t\t\ttypeArguments: [`${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::BalanceManager`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit funds into the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to deposit\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositIntoManager =\n\t\t(managerKey: string, coinKey: string, amountToDeposit: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst deposit = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAgC;AAFhC;AAUO,MAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA,EAMnC,YAAY,QAAwB;AALpC;AAaA;AAAA;AAAA;AAAA;AAAA,wCAA+B,MAAM,CAAC,OAAoB;AACzD,YAAM,UAAU,GAAG,SAAS;AAAA,QAC3B,QAAQ,GAAG,mBAAK,SAAQ,mBAAmB;AAAA,MAC5C,CAAC;AAED,SAAG,SAAS;AAAA,QACX,QAAQ;AAAA,QACR,WAAW,CAAC,OAAO;AAAA,QACnB,eAAe,CAAC,GAAG,mBAAK,SAAQ,mBAAmB,mCAAmC;AAAA,MACvF,CAAC;AAAA,IACF;AASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BACC,CAAC,YAAoB,SAAiB,oBAA4B,CAAC,OAAoB;AACtF,SAAG,kBAAkB,mBAAK,SAAQ,OAAO;AACzC,YAAM,YAAY,mBAAK,SAAQ,kBAAkB,UAAU,EAAE;AAC7D,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,YAAM,cAAU,qCAAgB;AAAA,QAC/B,MAAM,KAAK;AAAA,QACX,SAAS
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { coinWithBalance } from '@mysten/sui/transactions';\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * BalanceManagerContract class for managing BalanceManager operations.\n */\nexport class BalanceManagerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for BalanceManagerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Create and share a new BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateAndShareBalanceManager = () => (tx: Transaction) => {\n\t\tconst manager = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::new`,\n\t\t});\n\n\t\ttx.moveCall({\n\t\t\ttarget: '0x2::transfer::public_share_object',\n\t\t\targuments: [manager],\n\t\t\ttypeArguments: [`${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::BalanceManager`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit funds into the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to deposit\n\t * @param {number} amountToDeposit The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdepositIntoManager =\n\t\t(managerKey: string, coinKey: string, amountToDeposit: number) => (tx: Transaction) => {\n\t\t\ttx.setSenderIfNotSet(this.#config.address);\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositInput = Math.round(amountToDeposit * coin.scalar);\n\t\t\tconst deposit = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: depositInput,\n\t\t\t});\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::deposit`,\n\t\t\t\targuments: [tx.object(managerId), deposit],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Withdraw funds from the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to withdraw\n\t * @param {number} amountToWithdraw The amount to withdraw\n\t * @param {string} recipient The recipient of the withdrawn funds\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawFromManager =\n\t\t(managerKey: string, coinKey: string, amountToWithdraw: number, recipient: string) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawInput = Math.round(amountToWithdraw * coin.scalar);\n\t\t\tconst coinObject = tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`,\n\t\t\t\targuments: [tx.object(managerId), tx.pure.u64(withdrawInput)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\n\t\t\ttx.transferObjects([coinObject], recipient);\n\t\t};\n\n\t/**\n\t * @description Withdraw all funds from the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to withdraw\n\t * @param {string} recipient The recipient of the withdrawn funds\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawAllFromManager =\n\t\t(managerKey: string, coinKey: string, recipient: string) => (tx: Transaction) => {\n\t\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst withdrawalCoin = tx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw_all`,\n\t\t\t\targuments: [tx.object(managerId)],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\n\t\t\ttx.transferObjects([withdrawalCoin], recipient);\n\t\t};\n\n\t/**\n\t * @description Check the balance of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @param {string} coinKey The key of the coin to check the balance of\n\t * @returns A function that takes a Transaction object\n\t */\n\tcheckManagerBalance = (managerKey: string, coinKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Generate a trade proof for the BalanceManager. Calls the appropriate function based on whether tradeCap is set.\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProof = (managerKey: string) => (tx: Transaction) => {\n\t\tconst balanceManager = this.#config.getBalanceManager(managerKey);\n\t\treturn tx.add(\n\t\t\tbalanceManager.tradeCap\n\t\t\t\t? this.generateProofAsTrader(balanceManager.address, balanceManager.tradeCap)\n\t\t\t\t: this.generateProofAsOwner(balanceManager.address),\n\t\t);\n\t};\n\n\t/**\n\t * @description Generate a trade proof as the owner\n\t * @param {string} managerId The ID of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProofAsOwner = (managerId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::generate_proof_as_owner`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Generate a trade proof as a trader\n\t * @param {string} managerId The ID of the BalanceManager\n\t * @param {string} tradeCapId The ID of the tradeCap\n\t * @returns A function that takes a Transaction object\n\t */\n\tgenerateProofAsTrader = (managerId: string, tradeCapId: string) => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::generate_proof_as_trader`,\n\t\t\targuments: [tx.object(managerId), tx.object(tradeCapId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the owner of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\towner = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::owner`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the ID of the BalanceManager\n\t * @param {string} managerKey The key of the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tid = (managerKey: string) => (tx: Transaction) => {\n\t\tconst managerId = this.#config.getBalanceManager(managerKey).address;\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::id`,\n\t\t\targuments: [tx.object(managerId)],\n\t\t});\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAgC;AAFhC;AAUO,MAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA,EAMnC,YAAY,QAAwB;AALpC;AAaA;AAAA;AAAA;AAAA;AAAA,wCAA+B,MAAM,CAAC,OAAoB;AACzD,YAAM,UAAU,GAAG,SAAS;AAAA,QAC3B,QAAQ,GAAG,mBAAK,SAAQ,mBAAmB;AAAA,MAC5C,CAAC;AAED,SAAG,SAAS;AAAA,QACX,QAAQ;AAAA,QACR,WAAW,CAAC,OAAO;AAAA,QACnB,eAAe,CAAC,GAAG,mBAAK,SAAQ,mBAAmB,mCAAmC;AAAA,MACvF,CAAC;AAAA,IACF;AASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BACC,CAAC,YAAoB,SAAiB,oBAA4B,CAAC,OAAoB;AACtF,SAAG,kBAAkB,mBAAK,SAAQ,OAAO;AACzC,YAAM,YAAY,mBAAK,SAAQ,kBAAkB,UAAU,EAAE;AAC7D,YAAM,OAAO,mBAAK,SAAQ,QAAQ,OAAO;AACzC,YAAM,eAAe,KAAK,MAAM,kBAAkB,KAAK,MAAM;AAC7D,YAAM,cAAU,qCAAgB;AAAA,QAC/B,MAAM,KAAK;AAAA,QACX,SAAS;AAAA,MACV,CAAC;AAED,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,mBAAmB;AAAA,QAC3C,WAAW,CAAC,GAAG,OAAO,SAAS,GAAG,OAAO;A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AC,OAAoB;AACjD,YAAM,YAAY,mBAAK,SAAQ,kBAAkB,UAAU,EAAE;AAC7D,SAAG,SAAS;AAAA,QACX,QAAQ,GAAG,mBAAK,SAAQ,mBAAmB;AAAA,QAC3C,WAAW,CAAC,GAAG,OAAO,SAAS,CAAC;AAAA,MACjC,CAAC;AAAA,IACF;AAtKC,uBAAK,SAAU;AAAA,EAChB;AAsKD;AA7KC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -62,8 +62,8 @@ class DeepBookContract {
|
|
|
62
62
|
const balanceManager = __privateGet(this, _config).getBalanceManager(balanceManagerKey);
|
|
63
63
|
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
64
64
|
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
65
|
-
const inputPrice = price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar;
|
|
66
|
-
const inputQuantity = quantity * baseCoin.scalar;
|
|
65
|
+
const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar);
|
|
66
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
67
67
|
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
68
68
|
tx.moveCall({
|
|
69
69
|
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_limit_order`,
|
|
@@ -105,6 +105,7 @@ class DeepBookContract {
|
|
|
105
105
|
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
106
106
|
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
107
107
|
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
108
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
108
109
|
tx.moveCall({
|
|
109
110
|
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_market_order`,
|
|
110
111
|
arguments: [
|
|
@@ -113,7 +114,7 @@ class DeepBookContract {
|
|
|
113
114
|
tradeProof,
|
|
114
115
|
tx.pure.u64(clientOrderId),
|
|
115
116
|
tx.pure.u8(selfMatchingOption),
|
|
116
|
-
tx.pure.u64(
|
|
117
|
+
tx.pure.u64(inputQuantity),
|
|
117
118
|
tx.pure.bool(isBid),
|
|
118
119
|
tx.pure.bool(payWithDeep),
|
|
119
120
|
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
@@ -135,6 +136,7 @@ class DeepBookContract {
|
|
|
135
136
|
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
136
137
|
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
137
138
|
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey));
|
|
139
|
+
const inputQuantity = Math.round(newQuantity * baseCoin.scalar);
|
|
138
140
|
tx.moveCall({
|
|
139
141
|
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::modify_order`,
|
|
140
142
|
arguments: [
|
|
@@ -142,7 +144,7 @@ class DeepBookContract {
|
|
|
142
144
|
tx.object(balanceManager.address),
|
|
143
145
|
tradeProof,
|
|
144
146
|
tx.pure.u128(orderId),
|
|
145
|
-
tx.pure.u64(
|
|
147
|
+
tx.pure.u64(inputQuantity),
|
|
146
148
|
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
147
149
|
],
|
|
148
150
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
@@ -492,15 +494,16 @@ class DeepBookContract {
|
|
|
492
494
|
let deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
|
|
493
495
|
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
494
496
|
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
495
|
-
const baseCoinInput = params.baseCoin ?? (0, import_transactions.coinWithBalance)({ type: baseCoin.type, balance: baseAmount * baseCoin.scalar });
|
|
496
|
-
const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: deepAmount * import_config.DEEP_SCALAR });
|
|
497
|
+
const baseCoinInput = params.baseCoin ?? (0, import_transactions.coinWithBalance)({ type: baseCoin.type, balance: Math.round(baseAmount * baseCoin.scalar) });
|
|
498
|
+
const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) });
|
|
499
|
+
const minQuoteInput = Math.round(minQuote * quoteCoin.scalar);
|
|
497
500
|
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
498
501
|
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`,
|
|
499
502
|
arguments: [
|
|
500
503
|
tx.object(pool.address),
|
|
501
504
|
baseCoinInput,
|
|
502
505
|
deepCoin,
|
|
503
|
-
tx.pure.u64(
|
|
506
|
+
tx.pure.u64(minQuoteInput),
|
|
504
507
|
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
505
508
|
],
|
|
506
509
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
@@ -523,15 +526,19 @@ class DeepBookContract {
|
|
|
523
526
|
let deepCoinType = __privateGet(this, _config).getCoin("DEEP").type;
|
|
524
527
|
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
525
528
|
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
526
|
-
const quoteCoinInput = params.quoteCoin ?? (0, import_transactions.coinWithBalance)({
|
|
527
|
-
|
|
529
|
+
const quoteCoinInput = params.quoteCoin ?? (0, import_transactions.coinWithBalance)({
|
|
530
|
+
type: quoteCoin.type,
|
|
531
|
+
balance: Math.round(quoteAmount * quoteCoin.scalar)
|
|
532
|
+
});
|
|
533
|
+
const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) });
|
|
534
|
+
const minBaseInput = Math.round(minBase * baseCoin.scalar);
|
|
528
535
|
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
529
536
|
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`,
|
|
530
537
|
arguments: [
|
|
531
538
|
tx.object(pool.address),
|
|
532
539
|
quoteCoinInput,
|
|
533
540
|
deepCoin,
|
|
534
|
-
tx.pure.u64(
|
|
541
|
+
tx.pure.u64(minBaseInput),
|
|
535
542
|
tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
|
|
536
543
|
],
|
|
537
544
|
typeArguments: [baseCoin.type, quoteCoin.type]
|