@mysten/deepbook-v3 1.1.4 → 1.2.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 +20 -0
- package/dist/client.d.mts +58 -763
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +253 -2127
- package/dist/client.mjs.map +1 -1
- package/dist/contracts/utils/index.mjs +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/pyth/pyth.mjs +1 -1
- package/dist/queries/accountQueries.mjs +104 -0
- package/dist/queries/accountQueries.mjs.map +1 -0
- package/dist/queries/balanceManagerQueries.mjs +113 -0
- package/dist/queries/balanceManagerQueries.mjs.map +1 -0
- package/dist/queries/context.mjs +15 -0
- package/dist/queries/context.mjs.map +1 -0
- package/dist/queries/marginManagerQueries.mjs +365 -0
- package/dist/queries/marginManagerQueries.mjs.map +1 -0
- package/dist/queries/marginPoolQueries.mjs +184 -0
- package/dist/queries/marginPoolQueries.mjs.map +1 -0
- package/dist/queries/orderQueries.mjs +165 -0
- package/dist/queries/orderQueries.mjs.map +1 -0
- package/dist/queries/poolQueries.mjs +234 -0
- package/dist/queries/poolQueries.mjs.map +1 -0
- package/dist/queries/priceFeedQueries.mjs +83 -0
- package/dist/queries/priceFeedQueries.mjs.map +1 -0
- package/dist/queries/quantityQueries.mjs +216 -0
- package/dist/queries/quantityQueries.mjs.map +1 -0
- package/dist/queries/referralQueries.mjs +96 -0
- package/dist/queries/referralQueries.mjs.map +1 -0
- package/dist/queries/registryQueries.mjs +162 -0
- package/dist/queries/registryQueries.mjs.map +1 -0
- package/dist/queries/tpslQueries.mjs +62 -0
- package/dist/queries/tpslQueries.mjs.map +1 -0
- package/dist/transactions/balanceManager.d.mts.map +1 -1
- package/dist/transactions/balanceManager.mjs +5 -4
- package/dist/transactions/balanceManager.mjs.map +1 -1
- package/dist/transactions/deepbook.d.mts +24 -24
- package/dist/transactions/deepbook.d.mts.map +1 -1
- package/dist/transactions/deepbook.mjs +48 -47
- package/dist/transactions/deepbook.mjs.map +1 -1
- package/dist/transactions/deepbookAdmin.d.mts +2 -2
- package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
- package/dist/transactions/deepbookAdmin.mjs +10 -9
- package/dist/transactions/deepbookAdmin.mjs.map +1 -1
- package/dist/transactions/flashLoans.d.mts.map +1 -1
- package/dist/transactions/flashLoans.mjs +6 -4
- package/dist/transactions/flashLoans.mjs.map +1 -1
- package/dist/transactions/governance.d.mts.map +1 -1
- package/dist/transactions/governance.mjs +5 -4
- package/dist/transactions/governance.mjs.map +1 -1
- package/dist/transactions/marginAdmin.d.mts +7 -7
- package/dist/transactions/marginAdmin.d.mts.map +1 -1
- package/dist/transactions/marginAdmin.mjs +8 -7
- package/dist/transactions/marginAdmin.mjs.map +1 -1
- package/dist/transactions/marginLiquidations.d.mts +3 -3
- package/dist/transactions/marginLiquidations.d.mts.map +1 -1
- package/dist/transactions/marginLiquidations.mjs +5 -4
- package/dist/transactions/marginLiquidations.mjs.map +1 -1
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginMaintainer.d.mts.map +1 -1
- package/dist/transactions/marginMaintainer.mjs +15 -14
- package/dist/transactions/marginMaintainer.mjs.map +1 -1
- package/dist/transactions/marginManager.d.mts +23 -23
- package/dist/transactions/marginManager.d.mts.map +1 -1
- package/dist/transactions/marginManager.mjs +12 -11
- package/dist/transactions/marginManager.mjs.map +1 -1
- package/dist/transactions/marginPool.d.mts.map +1 -1
- package/dist/transactions/marginPool.mjs +3 -2
- package/dist/transactions/marginPool.mjs.map +1 -1
- package/dist/transactions/marginRegistry.d.mts +15 -15
- package/dist/transactions/marginTPSL.d.mts +1 -1
- package/dist/transactions/marginTPSL.d.mts.map +1 -1
- package/dist/transactions/marginTPSL.mjs +6 -8
- package/dist/transactions/marginTPSL.mjs.map +1 -1
- package/dist/transactions/poolProxy.d.mts.map +1 -1
- package/dist/transactions/poolProxy.mjs +13 -13
- package/dist/transactions/poolProxy.mjs.map +1 -1
- package/dist/types/index.d.mts +189 -52
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +10 -0
- package/dist/utils/constants.mjs.map +1 -1
- package/dist/utils/conversion.mjs +26 -0
- package/dist/utils/conversion.mjs.map +1 -0
- package/package.json +5 -4
- package/src/client.ts +421 -2662
- package/src/index.ts +27 -0
- package/src/queries/accountQueries.ts +117 -0
- package/src/queries/balanceManagerQueries.ts +156 -0
- package/src/queries/context.ts +44 -0
- package/src/queries/index.ts +16 -0
- package/src/queries/marginManagerQueries.ts +575 -0
- package/src/queries/marginPoolQueries.ts +226 -0
- package/src/queries/orderQueries.ts +202 -0
- package/src/queries/poolQueries.ts +266 -0
- package/src/queries/priceFeedQueries.ts +141 -0
- package/src/queries/quantityQueries.ts +266 -0
- package/src/queries/referralQueries.ts +112 -0
- package/src/queries/registryQueries.ts +185 -0
- package/src/queries/tpslQueries.ts +88 -0
- package/src/transactions/balanceManager.ts +5 -4
- package/src/transactions/deepbook.ts +98 -84
- package/src/transactions/deepbookAdmin.ts +10 -9
- package/src/transactions/flashLoans.ts +5 -4
- package/src/transactions/governance.ts +5 -4
- package/src/transactions/marginAdmin.ts +8 -7
- package/src/transactions/marginLiquidations.ts +5 -4
- package/src/transactions/marginMaintainer.ts +15 -14
- package/src/transactions/marginManager.ts +12 -11
- package/src/transactions/marginPool.ts +3 -2
- package/src/transactions/marginTPSL.ts +11 -6
- package/src/transactions/poolProxy.ts +12 -11
- package/src/types/index.ts +200 -53
- package/src/utils/constants.ts +10 -0
- package/src/utils/conversion.ts +33 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
4
4
|
|
|
5
5
|
import type { DeepBookConfig } from '../utils/config.js';
|
|
6
|
+
import { convertQuantity } from '../utils/conversion.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* FlashLoanContract class for managing flash loans.
|
|
@@ -27,7 +28,7 @@ export class FlashLoanContract {
|
|
|
27
28
|
const pool = this.#config.getPool(poolKey);
|
|
28
29
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
29
30
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
30
|
-
const inputQuantity =
|
|
31
|
+
const inputQuantity = convertQuantity(borrowAmount, baseCoin.scalar);
|
|
31
32
|
const [baseCoinResult, flashLoan] = tx.moveCall({
|
|
32
33
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,
|
|
33
34
|
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
@@ -58,7 +59,7 @@ export class FlashLoanContract {
|
|
|
58
59
|
const borrowScalar = baseCoin.scalar;
|
|
59
60
|
|
|
60
61
|
const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [
|
|
61
|
-
tx.pure.u64(
|
|
62
|
+
tx.pure.u64(convertQuantity(borrowAmount, borrowScalar)),
|
|
62
63
|
]);
|
|
63
64
|
tx.moveCall({
|
|
64
65
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,
|
|
@@ -79,7 +80,7 @@ export class FlashLoanContract {
|
|
|
79
80
|
const pool = this.#config.getPool(poolKey);
|
|
80
81
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
81
82
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
82
|
-
const inputQuantity =
|
|
83
|
+
const inputQuantity = convertQuantity(borrowAmount, quoteCoin.scalar);
|
|
83
84
|
const [quoteCoinResult, flashLoan] = tx.moveCall({
|
|
84
85
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,
|
|
85
86
|
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
@@ -110,7 +111,7 @@ export class FlashLoanContract {
|
|
|
110
111
|
const borrowScalar = quoteCoin.scalar;
|
|
111
112
|
|
|
112
113
|
const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [
|
|
113
|
-
tx.pure.u64(
|
|
114
|
+
tx.pure.u64(convertQuantity(borrowAmount, borrowScalar)),
|
|
114
115
|
]);
|
|
115
116
|
tx.moveCall({
|
|
116
117
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,
|
|
@@ -5,6 +5,7 @@ import type { Transaction } from '@mysten/sui/transactions';
|
|
|
5
5
|
import type { ProposalParams } from '../types/index.js';
|
|
6
6
|
import type { DeepBookConfig } from '../utils/config.js';
|
|
7
7
|
import { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';
|
|
8
|
+
import { convertQuantity, convertRate } from '../utils/conversion.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* GovernanceContract class for managing governance operations in DeepBook.
|
|
@@ -33,7 +34,7 @@ export class GovernanceContract {
|
|
|
33
34
|
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
34
35
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
35
36
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
36
|
-
const stakeInput =
|
|
37
|
+
const stakeInput = convertQuantity(stakeAmount, DEEP_SCALAR);
|
|
37
38
|
|
|
38
39
|
tx.moveCall({
|
|
39
40
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stake`,
|
|
@@ -87,9 +88,9 @@ export class GovernanceContract {
|
|
|
87
88
|
tx.object(pool.address),
|
|
88
89
|
tx.object(balanceManager.address),
|
|
89
90
|
tradeProof,
|
|
90
|
-
tx.pure.u64(
|
|
91
|
-
tx.pure.u64(
|
|
92
|
-
tx.pure.u64(
|
|
91
|
+
tx.pure.u64(convertRate(takerFee, FLOAT_SCALAR)),
|
|
92
|
+
tx.pure.u64(convertRate(makerFee, FLOAT_SCALAR)),
|
|
93
|
+
tx.pure.u64(convertQuantity(stakeRequired, DEEP_SCALAR)),
|
|
93
94
|
],
|
|
94
95
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
95
96
|
});
|
|
@@ -7,6 +7,7 @@ import type { DeepBookConfig } from '../utils/config.js';
|
|
|
7
7
|
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
8
8
|
import type { PoolConfigParams } from '../types/index.js';
|
|
9
9
|
import { FLOAT_SCALAR } from '../utils/config.js';
|
|
10
|
+
import { convertRate } from '../utils/conversion.js';
|
|
10
11
|
import { hexToBytes } from '@noble/hashes/utils.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -239,12 +240,12 @@ export class MarginAdminContract {
|
|
|
239
240
|
target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config`,
|
|
240
241
|
arguments: [
|
|
241
242
|
tx.object(this.#config.MARGIN_REGISTRY_ID),
|
|
242
|
-
tx.pure.u64(
|
|
243
|
-
tx.pure.u64(
|
|
244
|
-
tx.pure.u64(
|
|
245
|
-
tx.pure.u64(
|
|
246
|
-
tx.pure.u64(
|
|
247
|
-
tx.pure.u64(
|
|
243
|
+
tx.pure.u64(convertRate(minWithdrawRiskRatio, FLOAT_SCALAR)),
|
|
244
|
+
tx.pure.u64(convertRate(minBorrowRiskRatio, FLOAT_SCALAR)),
|
|
245
|
+
tx.pure.u64(convertRate(liquidationRiskRatio, FLOAT_SCALAR)),
|
|
246
|
+
tx.pure.u64(convertRate(targetLiquidationRiskRatio, FLOAT_SCALAR)),
|
|
247
|
+
tx.pure.u64(convertRate(userLiquidationReward, FLOAT_SCALAR)),
|
|
248
|
+
tx.pure.u64(convertRate(poolLiquidationReward, FLOAT_SCALAR)),
|
|
248
249
|
],
|
|
249
250
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
250
251
|
});
|
|
@@ -264,7 +265,7 @@ export class MarginAdminContract {
|
|
|
264
265
|
target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config_with_leverage`,
|
|
265
266
|
arguments: [
|
|
266
267
|
tx.object(this.#config.MARGIN_REGISTRY_ID),
|
|
267
|
-
tx.pure.u64(
|
|
268
|
+
tx.pure.u64(convertRate(leverage, FLOAT_SCALAR)),
|
|
268
269
|
],
|
|
269
270
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
270
271
|
});
|
|
@@ -4,6 +4,7 @@ import type { Transaction } from '@mysten/sui/transactions';
|
|
|
4
4
|
import { coinWithBalance } from '@mysten/sui/transactions';
|
|
5
5
|
|
|
6
6
|
import type { DeepBookConfig } from '../utils/config.js';
|
|
7
|
+
import { convertQuantity } from '../utils/conversion.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* MarginLiquidationsContract class for managing LiquidationVault operations.
|
|
@@ -44,7 +45,7 @@ export class MarginLiquidationsContract {
|
|
|
44
45
|
const coin = this.#config.getCoin(coinKey);
|
|
45
46
|
const depositCoin = coinWithBalance({
|
|
46
47
|
type: coin.type,
|
|
47
|
-
balance: amount
|
|
48
|
+
balance: convertQuantity(amount, coin.scalar),
|
|
48
49
|
});
|
|
49
50
|
tx.moveCall({
|
|
50
51
|
target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::deposit`,
|
|
@@ -70,7 +71,7 @@ export class MarginLiquidationsContract {
|
|
|
70
71
|
arguments: [
|
|
71
72
|
tx.object(vaultId),
|
|
72
73
|
tx.object(liquidationAdminCap),
|
|
73
|
-
tx.pure.u64(amount
|
|
74
|
+
tx.pure.u64(convertQuantity(amount, coin.scalar)),
|
|
74
75
|
],
|
|
75
76
|
typeArguments: [coin.type],
|
|
76
77
|
});
|
|
@@ -95,7 +96,7 @@ export class MarginLiquidationsContract {
|
|
|
95
96
|
|
|
96
97
|
const repayAmountArg =
|
|
97
98
|
repayAmount !== undefined
|
|
98
|
-
? tx.pure.option('u64',
|
|
99
|
+
? tx.pure.option('u64', convertQuantity(repayAmount, baseCoin.scalar))
|
|
99
100
|
: tx.pure.option('u64', null);
|
|
100
101
|
|
|
101
102
|
tx.moveCall({
|
|
@@ -135,7 +136,7 @@ export class MarginLiquidationsContract {
|
|
|
135
136
|
|
|
136
137
|
const repayAmountArg =
|
|
137
138
|
repayAmount !== undefined
|
|
138
|
-
? tx.pure.option('u64',
|
|
139
|
+
? tx.pure.option('u64', convertQuantity(repayAmount, quoteCoin.scalar))
|
|
139
140
|
: tx.pure.option('u64', null);
|
|
140
141
|
|
|
141
142
|
tx.moveCall({
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
import type { DeepBookConfig } from '../utils/config.js';
|
|
11
11
|
import type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';
|
|
12
12
|
import { FLOAT_SCALAR } from '../utils/config.js';
|
|
13
|
+
import { convertQuantity, convertRate } from '../utils/conversion.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* DeepBookMaintainerContract class for managing maintainer actions.
|
|
@@ -102,10 +103,10 @@ export class MarginMaintainerContract {
|
|
|
102
103
|
return tx.moveCall({
|
|
103
104
|
target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,
|
|
104
105
|
arguments: [
|
|
105
|
-
tx.pure.u64(
|
|
106
|
-
tx.pure.u64(
|
|
107
|
-
tx.pure.u64(
|
|
108
|
-
tx.pure.u64(
|
|
106
|
+
tx.pure.u64(convertQuantity(supplyCap, coin.scalar)),
|
|
107
|
+
tx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),
|
|
108
|
+
tx.pure.u64(convertRate(referralSpread, FLOAT_SCALAR)),
|
|
109
|
+
tx.pure.u64(convertQuantity(minBorrow, coin.scalar)),
|
|
109
110
|
],
|
|
110
111
|
});
|
|
111
112
|
};
|
|
@@ -141,12 +142,12 @@ export class MarginMaintainerContract {
|
|
|
141
142
|
return tx.moveCall({
|
|
142
143
|
target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,
|
|
143
144
|
arguments: [
|
|
144
|
-
tx.pure.u64(
|
|
145
|
-
tx.pure.u64(
|
|
146
|
-
tx.pure.u64(
|
|
147
|
-
tx.pure.u64(
|
|
148
|
-
tx.pure.u64(
|
|
149
|
-
tx.pure.u64(
|
|
145
|
+
tx.pure.u64(convertQuantity(supplyCap, coin.scalar)),
|
|
146
|
+
tx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),
|
|
147
|
+
tx.pure.u64(convertRate(referralSpread, FLOAT_SCALAR)),
|
|
148
|
+
tx.pure.u64(convertQuantity(minBorrow, coin.scalar)),
|
|
149
|
+
tx.pure.u64(convertQuantity(rateLimitCapacity, coin.scalar)),
|
|
150
|
+
tx.pure.u64(convertQuantity(rateLimitRefillRatePerMs, coin.scalar)),
|
|
150
151
|
tx.pure.bool(rateLimitEnabled),
|
|
151
152
|
],
|
|
152
153
|
});
|
|
@@ -162,10 +163,10 @@ export class MarginMaintainerContract {
|
|
|
162
163
|
return tx.moveCall({
|
|
163
164
|
target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,
|
|
164
165
|
arguments: [
|
|
165
|
-
tx.pure.u64(
|
|
166
|
-
tx.pure.u64(
|
|
167
|
-
tx.pure.u64(
|
|
168
|
-
tx.pure.u64(
|
|
166
|
+
tx.pure.u64(convertRate(baseRate, FLOAT_SCALAR)),
|
|
167
|
+
tx.pure.u64(convertRate(baseSlope, FLOAT_SCALAR)),
|
|
168
|
+
tx.pure.u64(convertRate(optimalUtilization, FLOAT_SCALAR)),
|
|
169
|
+
tx.pure.u64(convertRate(excessSlope, FLOAT_SCALAR)),
|
|
169
170
|
],
|
|
170
171
|
});
|
|
171
172
|
};
|
|
@@ -5,6 +5,7 @@ import { coinWithBalance } from '@mysten/sui/transactions';
|
|
|
5
5
|
|
|
6
6
|
import type { DeepBookConfig } from '../utils/config.js';
|
|
7
7
|
import type { DepositParams, DepositDuringInitParams } from '../types/index.js';
|
|
8
|
+
import { convertQuantity } from '../utils/conversion.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* MarginManagerContract class for managing MarginManager operations.
|
|
@@ -102,7 +103,7 @@ export class MarginManagerContract {
|
|
|
102
103
|
'amount' in params && params.amount !== undefined
|
|
103
104
|
? coinWithBalance({
|
|
104
105
|
type: depositCoin.type,
|
|
105
|
-
balance:
|
|
106
|
+
balance: convertQuantity(params.amount, depositCoin.scalar),
|
|
106
107
|
})
|
|
107
108
|
: params.coin;
|
|
108
109
|
|
|
@@ -135,7 +136,7 @@ export class MarginManagerContract {
|
|
|
135
136
|
'amount' in params && params.amount !== undefined
|
|
136
137
|
? coinWithBalance({
|
|
137
138
|
type: baseCoin.type,
|
|
138
|
-
balance:
|
|
139
|
+
balance: convertQuantity(params.amount, baseCoin.scalar),
|
|
139
140
|
})
|
|
140
141
|
: params.coin;
|
|
141
142
|
tx.moveCall({
|
|
@@ -167,7 +168,7 @@ export class MarginManagerContract {
|
|
|
167
168
|
'amount' in params && params.amount !== undefined
|
|
168
169
|
? coinWithBalance({
|
|
169
170
|
type: quoteCoin.type,
|
|
170
|
-
balance:
|
|
171
|
+
balance: convertQuantity(params.amount, quoteCoin.scalar),
|
|
171
172
|
})
|
|
172
173
|
: params.coin;
|
|
173
174
|
tx.moveCall({
|
|
@@ -200,7 +201,7 @@ export class MarginManagerContract {
|
|
|
200
201
|
'amount' in params && params.amount !== undefined
|
|
201
202
|
? coinWithBalance({
|
|
202
203
|
type: deepCoin.type,
|
|
203
|
-
balance:
|
|
204
|
+
balance: convertQuantity(params.amount, deepCoin.scalar),
|
|
204
205
|
})
|
|
205
206
|
: params.coin;
|
|
206
207
|
tx.moveCall({
|
|
@@ -240,7 +241,7 @@ export class MarginManagerContract {
|
|
|
240
241
|
tx.object(baseCoin.priceInfoObjectId!),
|
|
241
242
|
tx.object(quoteCoin.priceInfoObjectId!),
|
|
242
243
|
tx.object(pool.address),
|
|
243
|
-
tx.pure.u64(
|
|
244
|
+
tx.pure.u64(convertQuantity(amount, baseCoin.scalar)),
|
|
244
245
|
tx.object.clock(),
|
|
245
246
|
],
|
|
246
247
|
typeArguments: [baseCoin.type, quoteCoin.type, baseCoin.type],
|
|
@@ -270,7 +271,7 @@ export class MarginManagerContract {
|
|
|
270
271
|
tx.object(baseCoin.priceInfoObjectId!),
|
|
271
272
|
tx.object(quoteCoin.priceInfoObjectId!),
|
|
272
273
|
tx.object(pool.address),
|
|
273
|
-
tx.pure.u64(
|
|
274
|
+
tx.pure.u64(convertQuantity(amount, quoteCoin.scalar)),
|
|
274
275
|
tx.object.clock(),
|
|
275
276
|
],
|
|
276
277
|
typeArguments: [baseCoin.type, quoteCoin.type, quoteCoin.type],
|
|
@@ -301,7 +302,7 @@ export class MarginManagerContract {
|
|
|
301
302
|
tx.object(baseCoin.priceInfoObjectId!),
|
|
302
303
|
tx.object(quoteCoin.priceInfoObjectId!),
|
|
303
304
|
tx.object(pool.address),
|
|
304
|
-
tx.pure.u64(
|
|
305
|
+
tx.pure.u64(convertQuantity(amount, deepCoin.scalar)),
|
|
305
306
|
tx.object.clock(),
|
|
306
307
|
],
|
|
307
308
|
typeArguments: [baseCoin.type, quoteCoin.type, deepCoin.type],
|
|
@@ -329,7 +330,7 @@ export class MarginManagerContract {
|
|
|
329
330
|
tx.object(baseCoin.priceInfoObjectId!),
|
|
330
331
|
tx.object(quoteCoin.priceInfoObjectId!),
|
|
331
332
|
tx.object(pool.address),
|
|
332
|
-
tx.pure.u64(
|
|
333
|
+
tx.pure.u64(convertQuantity(amount, baseCoin.scalar)),
|
|
333
334
|
tx.object.clock(),
|
|
334
335
|
],
|
|
335
336
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
@@ -357,7 +358,7 @@ export class MarginManagerContract {
|
|
|
357
358
|
tx.object(baseCoin.priceInfoObjectId!),
|
|
358
359
|
tx.object(quoteCoin.priceInfoObjectId!),
|
|
359
360
|
tx.object(pool.address),
|
|
360
|
-
tx.pure.u64(
|
|
361
|
+
tx.pure.u64(convertQuantity(amount, quoteCoin.scalar)),
|
|
361
362
|
tx.object.clock(),
|
|
362
363
|
],
|
|
363
364
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
@@ -384,7 +385,7 @@ export class MarginManagerContract {
|
|
|
384
385
|
tx.object(baseMarginPool.address),
|
|
385
386
|
tx.object.option({
|
|
386
387
|
type: 'u64',
|
|
387
|
-
value: amount ? tx.pure.u64(
|
|
388
|
+
value: amount ? tx.pure.u64(convertQuantity(amount, baseCoin.scalar)) : null,
|
|
388
389
|
}),
|
|
389
390
|
tx.object.clock(),
|
|
390
391
|
],
|
|
@@ -412,7 +413,7 @@ export class MarginManagerContract {
|
|
|
412
413
|
tx.object(quoteMarginPool.address),
|
|
413
414
|
tx.object.option({
|
|
414
415
|
type: 'u64',
|
|
415
|
-
value: amount ? tx.pure.u64(
|
|
416
|
+
value: amount ? tx.pure.u64(convertQuantity(amount, quoteCoin.scalar)) : null,
|
|
416
417
|
}),
|
|
417
418
|
tx.object.clock(),
|
|
418
419
|
],
|
|
@@ -4,6 +4,7 @@ import { coinWithBalance } from '@mysten/sui/transactions';
|
|
|
4
4
|
import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
5
5
|
|
|
6
6
|
import type { DeepBookConfig } from '../utils/config.js';
|
|
7
|
+
import { convertQuantity } from '../utils/conversion.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* MarginPoolContract class for managing MarginPool operations.
|
|
@@ -48,7 +49,7 @@ export class MarginPoolContract {
|
|
|
48
49
|
tx.setSenderIfNotSet(this.#config.address);
|
|
49
50
|
const marginPool = this.#config.getMarginPool(coinKey);
|
|
50
51
|
const coin = this.#config.getCoin(coinKey);
|
|
51
|
-
const depositInput =
|
|
52
|
+
const depositInput = convertQuantity(amountToDeposit, coin.scalar);
|
|
52
53
|
const supply = coinWithBalance({
|
|
53
54
|
type: coin.type,
|
|
54
55
|
balance: depositInput,
|
|
@@ -84,7 +85,7 @@ export class MarginPoolContract {
|
|
|
84
85
|
const marginPool = this.#config.getMarginPool(coinKey);
|
|
85
86
|
const coin = this.#config.getCoin(coinKey);
|
|
86
87
|
const withdrawInput =
|
|
87
|
-
amountToWithdraw !== undefined ?
|
|
88
|
+
amountToWithdraw !== undefined ? convertQuantity(amountToWithdraw, coin.scalar) : null;
|
|
88
89
|
return tx.moveCall({
|
|
89
90
|
target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw`,
|
|
90
91
|
arguments: [
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
} from '../types/index.js';
|
|
11
11
|
import { OrderType, SelfMatchingOptions } from '../types/index.js';
|
|
12
12
|
import { MAX_TIMESTAMP, FLOAT_SCALAR } from '../utils/config.js';
|
|
13
|
+
import { convertQuantity, convertPrice } from '../utils/conversion.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* MarginTPSLContract class for managing Take Profit / Stop Loss operations.
|
|
@@ -34,12 +35,16 @@ export class MarginTPSLContract {
|
|
|
34
35
|
* @returns A function that takes a Transaction object
|
|
35
36
|
*/
|
|
36
37
|
newCondition =
|
|
37
|
-
(poolKey: string, triggerBelowPrice: boolean, triggerPrice: number
|
|
38
|
+
(poolKey: string, triggerBelowPrice: boolean, triggerPrice: number | bigint) =>
|
|
39
|
+
(tx: Transaction) => {
|
|
38
40
|
const pool = this.#config.getPool(poolKey);
|
|
39
41
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
40
42
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
41
|
-
const inputPrice =
|
|
42
|
-
|
|
43
|
+
const inputPrice = convertPrice(
|
|
44
|
+
triggerPrice,
|
|
45
|
+
FLOAT_SCALAR,
|
|
46
|
+
quoteCoin.scalar,
|
|
47
|
+
baseCoin.scalar,
|
|
43
48
|
);
|
|
44
49
|
return tx.moveCall({
|
|
45
50
|
target: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_condition`,
|
|
@@ -68,8 +73,8 @@ export class MarginTPSLContract {
|
|
|
68
73
|
const pool = this.#config.getPool(poolKey);
|
|
69
74
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
70
75
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
71
|
-
const inputPrice =
|
|
72
|
-
const inputQuantity =
|
|
76
|
+
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
77
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
73
78
|
return tx.moveCall({
|
|
74
79
|
target: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_pending_limit_order`,
|
|
75
80
|
arguments: [
|
|
@@ -102,7 +107,7 @@ export class MarginTPSLContract {
|
|
|
102
107
|
} = params;
|
|
103
108
|
const pool = this.#config.getPool(poolKey);
|
|
104
109
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
105
|
-
const inputQuantity =
|
|
110
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
106
111
|
return tx.moveCall({
|
|
107
112
|
target: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_pending_market_order`,
|
|
108
113
|
arguments: [
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
import type { DeepBookConfig } from '../utils/config.js';
|
|
11
11
|
import { OrderType, SelfMatchingOptions } from '../types/index.js';
|
|
12
12
|
import { MAX_TIMESTAMP, FLOAT_SCALAR } from '../utils/config.js';
|
|
13
|
+
import { convertQuantity, convertPrice, convertRate } from '../utils/conversion.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* PoolProxyContract class for managing PoolProxy operations.
|
|
@@ -46,8 +47,8 @@ export class PoolProxyContract {
|
|
|
46
47
|
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
47
48
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
48
49
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
49
|
-
const inputPrice =
|
|
50
|
-
const inputQuantity =
|
|
50
|
+
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
51
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
51
52
|
return tx.moveCall({
|
|
52
53
|
target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_limit_order`,
|
|
53
54
|
arguments: [
|
|
@@ -87,7 +88,7 @@ export class PoolProxyContract {
|
|
|
87
88
|
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
88
89
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
89
90
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
90
|
-
const inputQuantity =
|
|
91
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
91
92
|
return tx.moveCall({
|
|
92
93
|
target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_market_order`,
|
|
93
94
|
arguments: [
|
|
@@ -127,8 +128,8 @@ export class PoolProxyContract {
|
|
|
127
128
|
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
128
129
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
129
130
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
130
|
-
const inputPrice =
|
|
131
|
-
const inputQuantity =
|
|
131
|
+
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
132
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
132
133
|
const marginPool = isBid
|
|
133
134
|
? this.#config.getMarginPool(pool.baseCoin)
|
|
134
135
|
: this.#config.getMarginPool(pool.quoteCoin);
|
|
@@ -173,7 +174,7 @@ export class PoolProxyContract {
|
|
|
173
174
|
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
174
175
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
175
176
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
176
|
-
const inputQuantity =
|
|
177
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
177
178
|
const marginPool = isBid
|
|
178
179
|
? this.#config.getMarginPool(pool.baseCoin)
|
|
179
180
|
: this.#config.getMarginPool(pool.quoteCoin);
|
|
@@ -209,7 +210,7 @@ export class PoolProxyContract {
|
|
|
209
210
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
210
211
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
211
212
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
212
|
-
const inputQuantity =
|
|
213
|
+
const inputQuantity = convertQuantity(newQuantity, baseCoin.scalar);
|
|
213
214
|
|
|
214
215
|
tx.moveCall({
|
|
215
216
|
target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::modify_order`,
|
|
@@ -328,7 +329,7 @@ export class PoolProxyContract {
|
|
|
328
329
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
329
330
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
330
331
|
const deepCoin = this.#config.getCoin('DEEP');
|
|
331
|
-
const stakeInput =
|
|
332
|
+
const stakeInput = convertQuantity(stakeAmount, deepCoin.scalar);
|
|
332
333
|
tx.moveCall({
|
|
333
334
|
target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::stake`,
|
|
334
335
|
arguments: [
|
|
@@ -375,9 +376,9 @@ export class PoolProxyContract {
|
|
|
375
376
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
376
377
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
377
378
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
378
|
-
const stakeInput =
|
|
379
|
-
const takerFeeInput =
|
|
380
|
-
const makerFeeInput =
|
|
379
|
+
const stakeInput = convertRate(stakeRequired, FLOAT_SCALAR);
|
|
380
|
+
const takerFeeInput = convertRate(takerFee, FLOAT_SCALAR);
|
|
381
|
+
const makerFeeInput = convertRate(makerFee, FLOAT_SCALAR);
|
|
381
382
|
tx.moveCall({
|
|
382
383
|
target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::submit_proposal`,
|
|
383
384
|
arguments: [
|