@mysten/deepbook-v3 0.22.2 → 0.23.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 +6 -0
- package/dist/cjs/client.d.ts +167 -1
- package/dist/cjs/client.js +354 -3
- package/dist/cjs/client.js.map +2 -2
- package/dist/cjs/contracts/utils/index.d.ts +13 -0
- package/dist/cjs/contracts/utils/index.js +6 -9
- package/dist/cjs/contracts/utils/index.js.map +2 -2
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +16 -3
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/transactions/deepbook.d.ts +189 -1
- package/dist/cjs/transactions/deepbook.js +548 -1
- package/dist/cjs/transactions/deepbook.js.map +2 -2
- package/dist/cjs/types/index.d.ts +41 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/config.d.ts +8 -8
- package/dist/cjs/utils/config.js +12 -11
- package/dist/cjs/utils/config.js.map +2 -2
- package/dist/cjs/utils/constants.d.ts +8 -0
- package/dist/cjs/utils/constants.js +18 -7
- package/dist/cjs/utils/constants.js.map +2 -2
- package/dist/cjs/utils/errors.d.ts +42 -0
- package/dist/cjs/utils/errors.js +70 -0
- package/dist/cjs/utils/errors.js.map +7 -0
- package/dist/cjs/utils/validation.d.ts +50 -0
- package/dist/cjs/utils/validation.js +67 -0
- package/dist/cjs/utils/validation.js.map +7 -0
- package/dist/esm/client.d.ts +167 -1
- package/dist/esm/client.js +355 -4
- package/dist/esm/client.js.map +2 -2
- package/dist/esm/contracts/utils/index.d.ts +13 -0
- package/dist/esm/contracts/utils/index.js +6 -9
- package/dist/esm/contracts/utils/index.js.map +2 -2
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +31 -5
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/transactions/deepbook.d.ts +189 -1
- package/dist/esm/transactions/deepbook.js +549 -2
- package/dist/esm/transactions/deepbook.js.map +2 -2
- package/dist/esm/types/index.d.ts +41 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/utils/config.d.ts +8 -8
- package/dist/esm/utils/config.js +12 -11
- package/dist/esm/utils/config.js.map +2 -2
- package/dist/esm/utils/constants.d.ts +8 -0
- package/dist/esm/utils/constants.js +18 -7
- package/dist/esm/utils/constants.js.map +2 -2
- package/dist/esm/utils/errors.d.ts +42 -0
- package/dist/esm/utils/errors.js +50 -0
- package/dist/esm/utils/errors.js.map +7 -0
- package/dist/esm/utils/validation.d.ts +50 -0
- package/dist/esm/utils/validation.js +47 -0
- package/dist/esm/utils/validation.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -8
- package/src/client.ts +427 -4
- package/src/contracts/utils/index.ts +27 -11
- package/src/index.ts +21 -2
- package/src/transactions/deepbook.ts +647 -2
- package/src/types/index.ts +47 -0
- package/src/utils/config.ts +28 -15
- package/src/utils/constants.ts +17 -6
- package/src/utils/errors.ts +67 -0
- package/src/utils/validation.ts +91 -0
package/CHANGELOG.md
CHANGED
package/dist/cjs/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { DeepBookContract } from './transactions/deepbook.js';
|
|
|
5
5
|
import { DeepBookAdminContract } from './transactions/deepbookAdmin.js';
|
|
6
6
|
import { FlashLoanContract } from './transactions/flashLoans.js';
|
|
7
7
|
import { GovernanceContract } from './transactions/governance.js';
|
|
8
|
-
import type { BalanceManager, Environment, MarginManager } from './types/index.js';
|
|
8
|
+
import type { BalanceManager, Environment, MarginManager, CanPlaceLimitOrderParams, CanPlaceMarketOrderParams } from './types/index.js';
|
|
9
9
|
import type { CoinMap, PoolMap } from './utils/constants.js';
|
|
10
10
|
import { MarginAdminContract } from './transactions/marginAdmin.js';
|
|
11
11
|
import { MarginMaintainerContract } from './transactions/marginMaintainer.js';
|
|
@@ -556,6 +556,9 @@ export declare class DeepBookClient {
|
|
|
556
556
|
basePythDecimals: number;
|
|
557
557
|
quotePythPrice: string;
|
|
558
558
|
quotePythDecimals: number;
|
|
559
|
+
currentPrice: bigint;
|
|
560
|
+
lowestTriggerAbovePrice: bigint;
|
|
561
|
+
highestTriggerBelowPrice: bigint;
|
|
559
562
|
}>;
|
|
560
563
|
/**
|
|
561
564
|
* @description Get the base asset balance of a margin manager
|
|
@@ -648,4 +651,167 @@ export declare class DeepBookClient {
|
|
|
648
651
|
* @returns {Promise<string[]>} Array of allowed pause cap IDs
|
|
649
652
|
*/
|
|
650
653
|
getAllowedPauseCaps(): Promise<string[]>;
|
|
654
|
+
/**
|
|
655
|
+
* @description Check if a pool is a stable pool
|
|
656
|
+
* @param {string} poolKey Key of the pool
|
|
657
|
+
* @returns {Promise<boolean>} Whether the pool is a stable pool
|
|
658
|
+
*/
|
|
659
|
+
stablePool(poolKey: string): Promise<boolean>;
|
|
660
|
+
/**
|
|
661
|
+
* @description Check if a pool is registered
|
|
662
|
+
* @param {string} poolKey Key of the pool
|
|
663
|
+
* @returns {Promise<boolean>} Whether the pool is registered
|
|
664
|
+
*/
|
|
665
|
+
registeredPool(poolKey: string): Promise<boolean>;
|
|
666
|
+
/**
|
|
667
|
+
* @description Get the quote quantity out using input token as fee
|
|
668
|
+
* @param {string} poolKey Key of the pool
|
|
669
|
+
* @param {number} baseQuantity Base quantity
|
|
670
|
+
* @returns {Promise<{baseQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
|
|
671
|
+
*/
|
|
672
|
+
getQuoteQuantityOutInputFee(poolKey: string, baseQuantity: number): Promise<{
|
|
673
|
+
baseQuantity: number;
|
|
674
|
+
baseOut: number;
|
|
675
|
+
quoteOut: number;
|
|
676
|
+
deepRequired: number;
|
|
677
|
+
}>;
|
|
678
|
+
/**
|
|
679
|
+
* @description Get the base quantity out using input token as fee
|
|
680
|
+
* @param {string} poolKey Key of the pool
|
|
681
|
+
* @param {number} quoteQuantity Quote quantity
|
|
682
|
+
* @returns {Promise<{quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
|
|
683
|
+
*/
|
|
684
|
+
getBaseQuantityOutInputFee(poolKey: string, quoteQuantity: number): Promise<{
|
|
685
|
+
quoteQuantity: number;
|
|
686
|
+
baseOut: number;
|
|
687
|
+
quoteOut: number;
|
|
688
|
+
deepRequired: number;
|
|
689
|
+
}>;
|
|
690
|
+
/**
|
|
691
|
+
* @description Get the quantity out using input token as fee
|
|
692
|
+
* @param {string} poolKey Key of the pool
|
|
693
|
+
* @param {number} baseQuantity Base quantity
|
|
694
|
+
* @param {number} quoteQuantity Quote quantity
|
|
695
|
+
* @returns {Promise<{baseQuantity: number, quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
|
|
696
|
+
*/
|
|
697
|
+
getQuantityOutInputFee(poolKey: string, baseQuantity: number, quoteQuantity: number): Promise<{
|
|
698
|
+
baseQuantity: number;
|
|
699
|
+
quoteQuantity: number;
|
|
700
|
+
baseOut: number;
|
|
701
|
+
quoteOut: number;
|
|
702
|
+
deepRequired: number;
|
|
703
|
+
}>;
|
|
704
|
+
/**
|
|
705
|
+
* @description Get the base quantity needed to receive target quote quantity
|
|
706
|
+
* @param {string} poolKey Key of the pool
|
|
707
|
+
* @param {number} targetQuoteQuantity Target quote quantity
|
|
708
|
+
* @param {boolean} payWithDeep Whether to pay fees with DEEP
|
|
709
|
+
* @returns {Promise<{baseIn: number, quoteOut: number, deepRequired: number}>}
|
|
710
|
+
*/
|
|
711
|
+
getBaseQuantityIn(poolKey: string, targetQuoteQuantity: number, payWithDeep: boolean): Promise<{
|
|
712
|
+
baseIn: number;
|
|
713
|
+
quoteOut: number;
|
|
714
|
+
deepRequired: number;
|
|
715
|
+
}>;
|
|
716
|
+
/**
|
|
717
|
+
* @description Get the quote quantity needed to receive target base quantity
|
|
718
|
+
* @param {string} poolKey Key of the pool
|
|
719
|
+
* @param {number} targetBaseQuantity Target base quantity
|
|
720
|
+
* @param {boolean} payWithDeep Whether to pay fees with DEEP
|
|
721
|
+
* @returns {Promise<{baseOut: number, quoteIn: number, deepRequired: number}>}
|
|
722
|
+
*/
|
|
723
|
+
getQuoteQuantityIn(poolKey: string, targetBaseQuantity: number, payWithDeep: boolean): Promise<{
|
|
724
|
+
baseOut: number;
|
|
725
|
+
quoteIn: number;
|
|
726
|
+
deepRequired: number;
|
|
727
|
+
}>;
|
|
728
|
+
/**
|
|
729
|
+
* @description Get account order details for a balance manager
|
|
730
|
+
* @param {string} poolKey Key of the pool
|
|
731
|
+
* @param {string} managerKey Key of the balance manager
|
|
732
|
+
* @returns {Promise<Array>} Array of order details
|
|
733
|
+
*/
|
|
734
|
+
getAccountOrderDetails(poolKey: string, managerKey: string): Promise<{
|
|
735
|
+
balance_manager_id: string;
|
|
736
|
+
order_id: string;
|
|
737
|
+
client_order_id: string;
|
|
738
|
+
quantity: string;
|
|
739
|
+
filled_quantity: string;
|
|
740
|
+
fee_is_deep: boolean;
|
|
741
|
+
order_deep_price: {
|
|
742
|
+
asset_is_base: boolean;
|
|
743
|
+
deep_per_asset: string;
|
|
744
|
+
};
|
|
745
|
+
epoch: string;
|
|
746
|
+
status: number;
|
|
747
|
+
expire_timestamp: string;
|
|
748
|
+
}[]>;
|
|
749
|
+
/**
|
|
750
|
+
* @description Get the DEEP required for an order
|
|
751
|
+
* @param {string} poolKey Key of the pool
|
|
752
|
+
* @param {number} baseQuantity Base quantity
|
|
753
|
+
* @param {number} price Price
|
|
754
|
+
* @returns {Promise<{deepRequiredTaker: number, deepRequiredMaker: number}>}
|
|
755
|
+
*/
|
|
756
|
+
getOrderDeepRequired(poolKey: string, baseQuantity: number, price: number): Promise<{
|
|
757
|
+
deepRequiredTaker: number;
|
|
758
|
+
deepRequiredMaker: number;
|
|
759
|
+
}>;
|
|
760
|
+
/**
|
|
761
|
+
* @description Check if account exists for a balance manager
|
|
762
|
+
* @param {string} poolKey Key of the pool
|
|
763
|
+
* @param {string} managerKey Key of the balance manager
|
|
764
|
+
* @returns {Promise<boolean>} Whether account exists
|
|
765
|
+
*/
|
|
766
|
+
accountExists(poolKey: string, managerKey: string): Promise<boolean>;
|
|
767
|
+
/**
|
|
768
|
+
* @description Get the next epoch trade parameters
|
|
769
|
+
* @param {string} poolKey Key of the pool
|
|
770
|
+
* @returns {Promise<{takerFee: number, makerFee: number, stakeRequired: number}>}
|
|
771
|
+
*/
|
|
772
|
+
poolTradeParamsNext(poolKey: string): Promise<{
|
|
773
|
+
takerFee: number;
|
|
774
|
+
makerFee: number;
|
|
775
|
+
stakeRequired: number;
|
|
776
|
+
}>;
|
|
777
|
+
/**
|
|
778
|
+
* @description Get the quorum for a pool
|
|
779
|
+
* @param {string} poolKey Key of the pool
|
|
780
|
+
* @returns {Promise<number>} The quorum amount in DEEP
|
|
781
|
+
*/
|
|
782
|
+
quorum(poolKey: string): Promise<number>;
|
|
783
|
+
/**
|
|
784
|
+
* @description Get the pool ID
|
|
785
|
+
* @param {string} poolKey Key of the pool
|
|
786
|
+
* @returns {Promise<string>} The pool ID
|
|
787
|
+
*/
|
|
788
|
+
poolId(poolKey: string): Promise<string>;
|
|
789
|
+
/**
|
|
790
|
+
* @description Check if a limit order can be placed
|
|
791
|
+
* @param {CanPlaceLimitOrderParams} params Parameters for checking limit order placement
|
|
792
|
+
* @returns {Promise<boolean>} Whether order can be placed
|
|
793
|
+
*/
|
|
794
|
+
canPlaceLimitOrder(params: CanPlaceLimitOrderParams): Promise<boolean>;
|
|
795
|
+
/**
|
|
796
|
+
* @description Check if a market order can be placed
|
|
797
|
+
* @param {CanPlaceMarketOrderParams} params Parameters for checking market order placement
|
|
798
|
+
* @returns {Promise<boolean>} Whether order can be placed
|
|
799
|
+
*/
|
|
800
|
+
canPlaceMarketOrder(params: CanPlaceMarketOrderParams): Promise<boolean>;
|
|
801
|
+
/**
|
|
802
|
+
* @description Check if market order params are valid
|
|
803
|
+
* @param {string} poolKey Key of the pool
|
|
804
|
+
* @param {number} quantity Quantity
|
|
805
|
+
* @returns {Promise<boolean>} Whether params are valid
|
|
806
|
+
*/
|
|
807
|
+
checkMarketOrderParams(poolKey: string, quantity: number): Promise<boolean>;
|
|
808
|
+
/**
|
|
809
|
+
* @description Check if limit order params are valid
|
|
810
|
+
* @param {string} poolKey Key of the pool
|
|
811
|
+
* @param {number} price Price
|
|
812
|
+
* @param {number} quantity Quantity
|
|
813
|
+
* @param {number} expireTimestamp Expiration timestamp
|
|
814
|
+
* @returns {Promise<boolean>} Whether params are valid
|
|
815
|
+
*/
|
|
816
|
+
checkLimitOrderParams(poolKey: string, price: number, quantity: number, expireTimestamp: number): Promise<boolean>;
|
|
651
817
|
}
|
package/dist/cjs/client.js
CHANGED
|
@@ -675,8 +675,8 @@ class DeepBookClient {
|
|
|
675
675
|
}
|
|
676
676
|
async getPriceInfoObject(tx, coinKey) {
|
|
677
677
|
const currentTime = Date.now();
|
|
678
|
-
const
|
|
679
|
-
if (currentTime -
|
|
678
|
+
const priceInfoObjectAge = await this.getPriceInfoObjectAge(coinKey) * 1e3;
|
|
679
|
+
if (currentTime - priceInfoObjectAge < import_config.PRICE_INFO_OBJECT_MAX_AGE_MS) {
|
|
680
680
|
return await __privateGet(this, _config).getCoin(coinKey).priceInfoObjectId;
|
|
681
681
|
}
|
|
682
682
|
const endpoint = __privateGet(this, _config).env === "testnet" ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network";
|
|
@@ -1195,6 +1195,13 @@ class DeepBookClient {
|
|
|
1195
1195
|
const quotePythDecimals = Number(
|
|
1196
1196
|
import_bcs.bcs.u8().parse(new Uint8Array(res.results[0].returnValues[10][0]))
|
|
1197
1197
|
);
|
|
1198
|
+
const currentPrice = BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[11][0])));
|
|
1199
|
+
const lowestTriggerAbovePrice = BigInt(
|
|
1200
|
+
import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[12][0]))
|
|
1201
|
+
);
|
|
1202
|
+
const highestTriggerBelowPrice = BigInt(
|
|
1203
|
+
import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[13][0]))
|
|
1204
|
+
);
|
|
1198
1205
|
return {
|
|
1199
1206
|
managerId,
|
|
1200
1207
|
deepbookPoolId,
|
|
@@ -1206,7 +1213,10 @@ class DeepBookClient {
|
|
|
1206
1213
|
basePythPrice: basePythPrice.toString(),
|
|
1207
1214
|
basePythDecimals,
|
|
1208
1215
|
quotePythPrice: quotePythPrice.toString(),
|
|
1209
|
-
quotePythDecimals
|
|
1216
|
+
quotePythDecimals,
|
|
1217
|
+
currentPrice,
|
|
1218
|
+
lowestTriggerAbovePrice,
|
|
1219
|
+
highestTriggerBelowPrice
|
|
1210
1220
|
};
|
|
1211
1221
|
}
|
|
1212
1222
|
/**
|
|
@@ -1470,6 +1480,347 @@ class DeepBookClient {
|
|
|
1470
1480
|
const vecSet = (0, import_bcs2.VecSet)(import_bcs.bcs.Address).parse(new Uint8Array(bytes));
|
|
1471
1481
|
return vecSet.contents.map((id) => (0, import_utils.normalizeSuiAddress)(id));
|
|
1472
1482
|
}
|
|
1483
|
+
/**
|
|
1484
|
+
* @description Check if a pool is a stable pool
|
|
1485
|
+
* @param {string} poolKey Key of the pool
|
|
1486
|
+
* @returns {Promise<boolean>} Whether the pool is a stable pool
|
|
1487
|
+
*/
|
|
1488
|
+
async stablePool(poolKey) {
|
|
1489
|
+
const tx = new import_transactions.Transaction();
|
|
1490
|
+
tx.add(this.deepBook.stablePool(poolKey));
|
|
1491
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1492
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1493
|
+
transactionBlock: tx
|
|
1494
|
+
});
|
|
1495
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1496
|
+
return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* @description Check if a pool is registered
|
|
1500
|
+
* @param {string} poolKey Key of the pool
|
|
1501
|
+
* @returns {Promise<boolean>} Whether the pool is registered
|
|
1502
|
+
*/
|
|
1503
|
+
async registeredPool(poolKey) {
|
|
1504
|
+
const tx = new import_transactions.Transaction();
|
|
1505
|
+
tx.add(this.deepBook.registeredPool(poolKey));
|
|
1506
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1507
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1508
|
+
transactionBlock: tx
|
|
1509
|
+
});
|
|
1510
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1511
|
+
return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* @description Get the quote quantity out using input token as fee
|
|
1515
|
+
* @param {string} poolKey Key of the pool
|
|
1516
|
+
* @param {number} baseQuantity Base quantity
|
|
1517
|
+
* @returns {Promise<{baseQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
|
|
1518
|
+
*/
|
|
1519
|
+
async getQuoteQuantityOutInputFee(poolKey, baseQuantity) {
|
|
1520
|
+
const tx = new import_transactions.Transaction();
|
|
1521
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1522
|
+
const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
|
|
1523
|
+
const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
|
|
1524
|
+
tx.add(this.deepBook.getQuoteQuantityOutInputFee(poolKey, baseQuantity));
|
|
1525
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1526
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1527
|
+
transactionBlock: tx
|
|
1528
|
+
});
|
|
1529
|
+
const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
|
|
1530
|
+
const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
|
|
1531
|
+
const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
1532
|
+
return {
|
|
1533
|
+
baseQuantity,
|
|
1534
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
1535
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
1536
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* @description Get the base quantity out using input token as fee
|
|
1541
|
+
* @param {string} poolKey Key of the pool
|
|
1542
|
+
* @param {number} quoteQuantity Quote quantity
|
|
1543
|
+
* @returns {Promise<{quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
|
|
1544
|
+
*/
|
|
1545
|
+
async getBaseQuantityOutInputFee(poolKey, quoteQuantity) {
|
|
1546
|
+
const tx = new import_transactions.Transaction();
|
|
1547
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1548
|
+
const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
|
|
1549
|
+
const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
|
|
1550
|
+
tx.add(this.deepBook.getBaseQuantityOutInputFee(poolKey, quoteQuantity));
|
|
1551
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1552
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1553
|
+
transactionBlock: tx
|
|
1554
|
+
});
|
|
1555
|
+
const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
|
|
1556
|
+
const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
|
|
1557
|
+
const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
1558
|
+
return {
|
|
1559
|
+
quoteQuantity,
|
|
1560
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
1561
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
1562
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* @description Get the quantity out using input token as fee
|
|
1567
|
+
* @param {string} poolKey Key of the pool
|
|
1568
|
+
* @param {number} baseQuantity Base quantity
|
|
1569
|
+
* @param {number} quoteQuantity Quote quantity
|
|
1570
|
+
* @returns {Promise<{baseQuantity: number, quoteQuantity: number, baseOut: number, quoteOut: number, deepRequired: number}>}
|
|
1571
|
+
*/
|
|
1572
|
+
async getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity) {
|
|
1573
|
+
const tx = new import_transactions.Transaction();
|
|
1574
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1575
|
+
const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
|
|
1576
|
+
const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
|
|
1577
|
+
tx.add(this.deepBook.getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity));
|
|
1578
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1579
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1580
|
+
transactionBlock: tx
|
|
1581
|
+
});
|
|
1582
|
+
const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
|
|
1583
|
+
const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
|
|
1584
|
+
const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
1585
|
+
return {
|
|
1586
|
+
baseQuantity,
|
|
1587
|
+
quoteQuantity,
|
|
1588
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
1589
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
1590
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* @description Get the base quantity needed to receive target quote quantity
|
|
1595
|
+
* @param {string} poolKey Key of the pool
|
|
1596
|
+
* @param {number} targetQuoteQuantity Target quote quantity
|
|
1597
|
+
* @param {boolean} payWithDeep Whether to pay fees with DEEP
|
|
1598
|
+
* @returns {Promise<{baseIn: number, quoteOut: number, deepRequired: number}>}
|
|
1599
|
+
*/
|
|
1600
|
+
async getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep) {
|
|
1601
|
+
const tx = new import_transactions.Transaction();
|
|
1602
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1603
|
+
const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
|
|
1604
|
+
const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
|
|
1605
|
+
tx.add(this.deepBook.getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep));
|
|
1606
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1607
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1608
|
+
transactionBlock: tx
|
|
1609
|
+
});
|
|
1610
|
+
const baseIn = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
|
|
1611
|
+
const quoteOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
|
|
1612
|
+
const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
1613
|
+
return {
|
|
1614
|
+
baseIn: Number((baseIn / baseScalar).toFixed(9)),
|
|
1615
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
1616
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* @description Get the quote quantity needed to receive target base quantity
|
|
1621
|
+
* @param {string} poolKey Key of the pool
|
|
1622
|
+
* @param {number} targetBaseQuantity Target base quantity
|
|
1623
|
+
* @param {boolean} payWithDeep Whether to pay fees with DEEP
|
|
1624
|
+
* @returns {Promise<{baseOut: number, quoteIn: number, deepRequired: number}>}
|
|
1625
|
+
*/
|
|
1626
|
+
async getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep) {
|
|
1627
|
+
const tx = new import_transactions.Transaction();
|
|
1628
|
+
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1629
|
+
const baseScalar = __privateGet(this, _config).getCoin(pool.baseCoin).scalar;
|
|
1630
|
+
const quoteScalar = __privateGet(this, _config).getCoin(pool.quoteCoin).scalar;
|
|
1631
|
+
tx.add(this.deepBook.getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep));
|
|
1632
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1633
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1634
|
+
transactionBlock: tx
|
|
1635
|
+
});
|
|
1636
|
+
const baseOut = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
|
|
1637
|
+
const quoteIn = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
|
|
1638
|
+
const deepRequired = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0])));
|
|
1639
|
+
return {
|
|
1640
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
1641
|
+
quoteIn: Number((quoteIn / quoteScalar).toFixed(9)),
|
|
1642
|
+
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9))
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* @description Get account order details for a balance manager
|
|
1647
|
+
* @param {string} poolKey Key of the pool
|
|
1648
|
+
* @param {string} managerKey Key of the balance manager
|
|
1649
|
+
* @returns {Promise<Array>} Array of order details
|
|
1650
|
+
*/
|
|
1651
|
+
async getAccountOrderDetails(poolKey, managerKey) {
|
|
1652
|
+
const tx = new import_transactions.Transaction();
|
|
1653
|
+
tx.add(this.deepBook.getAccountOrderDetails(poolKey, managerKey));
|
|
1654
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1655
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1656
|
+
transactionBlock: tx
|
|
1657
|
+
});
|
|
1658
|
+
try {
|
|
1659
|
+
const orderInformation = res.results[0].returnValues[0][0];
|
|
1660
|
+
return import_bcs.bcs.vector(import_bcs2.Order).parse(new Uint8Array(orderInformation));
|
|
1661
|
+
} catch {
|
|
1662
|
+
return [];
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* @description Get the DEEP required for an order
|
|
1667
|
+
* @param {string} poolKey Key of the pool
|
|
1668
|
+
* @param {number} baseQuantity Base quantity
|
|
1669
|
+
* @param {number} price Price
|
|
1670
|
+
* @returns {Promise<{deepRequiredTaker: number, deepRequiredMaker: number}>}
|
|
1671
|
+
*/
|
|
1672
|
+
async getOrderDeepRequired(poolKey, baseQuantity, price) {
|
|
1673
|
+
const tx = new import_transactions.Transaction();
|
|
1674
|
+
tx.add(this.deepBook.getOrderDeepRequired(poolKey, baseQuantity, price));
|
|
1675
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1676
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1677
|
+
transactionBlock: tx
|
|
1678
|
+
});
|
|
1679
|
+
const deepRequiredTaker = Number(
|
|
1680
|
+
import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0]))
|
|
1681
|
+
);
|
|
1682
|
+
const deepRequiredMaker = Number(
|
|
1683
|
+
import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0]))
|
|
1684
|
+
);
|
|
1685
|
+
return {
|
|
1686
|
+
deepRequiredTaker: Number((deepRequiredTaker / import_config.DEEP_SCALAR).toFixed(9)),
|
|
1687
|
+
deepRequiredMaker: Number((deepRequiredMaker / import_config.DEEP_SCALAR).toFixed(9))
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* @description Check if account exists for a balance manager
|
|
1692
|
+
* @param {string} poolKey Key of the pool
|
|
1693
|
+
* @param {string} managerKey Key of the balance manager
|
|
1694
|
+
* @returns {Promise<boolean>} Whether account exists
|
|
1695
|
+
*/
|
|
1696
|
+
async accountExists(poolKey, managerKey) {
|
|
1697
|
+
const tx = new import_transactions.Transaction();
|
|
1698
|
+
tx.add(this.deepBook.accountExists(poolKey, managerKey));
|
|
1699
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1700
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1701
|
+
transactionBlock: tx
|
|
1702
|
+
});
|
|
1703
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1704
|
+
return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
|
|
1705
|
+
}
|
|
1706
|
+
/**
|
|
1707
|
+
* @description Get the next epoch trade parameters
|
|
1708
|
+
* @param {string} poolKey Key of the pool
|
|
1709
|
+
* @returns {Promise<{takerFee: number, makerFee: number, stakeRequired: number}>}
|
|
1710
|
+
*/
|
|
1711
|
+
async poolTradeParamsNext(poolKey) {
|
|
1712
|
+
const tx = new import_transactions.Transaction();
|
|
1713
|
+
tx.add(this.deepBook.poolTradeParamsNext(poolKey));
|
|
1714
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1715
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1716
|
+
transactionBlock: tx
|
|
1717
|
+
});
|
|
1718
|
+
const takerFee = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[0][0])));
|
|
1719
|
+
const makerFee = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[1][0])));
|
|
1720
|
+
const stakeRequired = Number(
|
|
1721
|
+
import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0]))
|
|
1722
|
+
);
|
|
1723
|
+
return {
|
|
1724
|
+
takerFee: takerFee / import_config.FLOAT_SCALAR,
|
|
1725
|
+
makerFee: makerFee / import_config.FLOAT_SCALAR,
|
|
1726
|
+
stakeRequired: stakeRequired / import_config.DEEP_SCALAR
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* @description Get the quorum for a pool
|
|
1731
|
+
* @param {string} poolKey Key of the pool
|
|
1732
|
+
* @returns {Promise<number>} The quorum amount in DEEP
|
|
1733
|
+
*/
|
|
1734
|
+
async quorum(poolKey) {
|
|
1735
|
+
const tx = new import_transactions.Transaction();
|
|
1736
|
+
tx.add(this.deepBook.quorum(poolKey));
|
|
1737
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1738
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1739
|
+
transactionBlock: tx
|
|
1740
|
+
});
|
|
1741
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1742
|
+
const quorum = Number(import_bcs.bcs.U64.parse(new Uint8Array(bytes)));
|
|
1743
|
+
return quorum / import_config.DEEP_SCALAR;
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* @description Get the pool ID
|
|
1747
|
+
* @param {string} poolKey Key of the pool
|
|
1748
|
+
* @returns {Promise<string>} The pool ID
|
|
1749
|
+
*/
|
|
1750
|
+
async poolId(poolKey) {
|
|
1751
|
+
const tx = new import_transactions.Transaction();
|
|
1752
|
+
tx.add(this.deepBook.poolId(poolKey));
|
|
1753
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1754
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1755
|
+
transactionBlock: tx
|
|
1756
|
+
});
|
|
1757
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1758
|
+
return (0, import_utils.normalizeSuiAddress)(import_bcs.bcs.Address.parse(new Uint8Array(bytes)));
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* @description Check if a limit order can be placed
|
|
1762
|
+
* @param {CanPlaceLimitOrderParams} params Parameters for checking limit order placement
|
|
1763
|
+
* @returns {Promise<boolean>} Whether order can be placed
|
|
1764
|
+
*/
|
|
1765
|
+
async canPlaceLimitOrder(params) {
|
|
1766
|
+
const tx = new import_transactions.Transaction();
|
|
1767
|
+
tx.add(this.deepBook.canPlaceLimitOrder(params));
|
|
1768
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1769
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1770
|
+
transactionBlock: tx
|
|
1771
|
+
});
|
|
1772
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1773
|
+
return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* @description Check if a market order can be placed
|
|
1777
|
+
* @param {CanPlaceMarketOrderParams} params Parameters for checking market order placement
|
|
1778
|
+
* @returns {Promise<boolean>} Whether order can be placed
|
|
1779
|
+
*/
|
|
1780
|
+
async canPlaceMarketOrder(params) {
|
|
1781
|
+
const tx = new import_transactions.Transaction();
|
|
1782
|
+
tx.add(this.deepBook.canPlaceMarketOrder(params));
|
|
1783
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1784
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1785
|
+
transactionBlock: tx
|
|
1786
|
+
});
|
|
1787
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1788
|
+
return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
|
|
1789
|
+
}
|
|
1790
|
+
/**
|
|
1791
|
+
* @description Check if market order params are valid
|
|
1792
|
+
* @param {string} poolKey Key of the pool
|
|
1793
|
+
* @param {number} quantity Quantity
|
|
1794
|
+
* @returns {Promise<boolean>} Whether params are valid
|
|
1795
|
+
*/
|
|
1796
|
+
async checkMarketOrderParams(poolKey, quantity) {
|
|
1797
|
+
const tx = new import_transactions.Transaction();
|
|
1798
|
+
tx.add(this.deepBook.checkMarketOrderParams(poolKey, quantity));
|
|
1799
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1800
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1801
|
+
transactionBlock: tx
|
|
1802
|
+
});
|
|
1803
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1804
|
+
return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* @description Check if limit order params are valid
|
|
1808
|
+
* @param {string} poolKey Key of the pool
|
|
1809
|
+
* @param {number} price Price
|
|
1810
|
+
* @param {number} quantity Quantity
|
|
1811
|
+
* @param {number} expireTimestamp Expiration timestamp
|
|
1812
|
+
* @returns {Promise<boolean>} Whether params are valid
|
|
1813
|
+
*/
|
|
1814
|
+
async checkLimitOrderParams(poolKey, price, quantity, expireTimestamp) {
|
|
1815
|
+
const tx = new import_transactions.Transaction();
|
|
1816
|
+
tx.add(this.deepBook.checkLimitOrderParams(poolKey, price, quantity, expireTimestamp));
|
|
1817
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1818
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1819
|
+
transactionBlock: tx
|
|
1820
|
+
});
|
|
1821
|
+
const bytes = res.results[0].returnValues[0][0];
|
|
1822
|
+
return import_bcs.bcs.bool().parse(new Uint8Array(bytes));
|
|
1823
|
+
}
|
|
1473
1824
|
}
|
|
1474
1825
|
_config = new WeakMap();
|
|
1475
1826
|
_address = new WeakMap();
|