@mysten/deepbook-v3 0.2.1 → 0.3.1
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 +13 -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 +1 -1
- 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
|
@@ -46,8 +46,8 @@ export class DeepBookContract {
|
|
|
46
46
|
const balanceManager = this.#config.getBalanceManager(balanceManagerKey);
|
|
47
47
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
48
48
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
49
|
-
const inputPrice = (price * FLOAT_SCALAR * quoteCoin.scalar) / baseCoin.scalar;
|
|
50
|
-
const inputQuantity = quantity * baseCoin.scalar;
|
|
49
|
+
const inputPrice = Math.round((price * FLOAT_SCALAR * quoteCoin.scalar) / baseCoin.scalar);
|
|
50
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
51
51
|
|
|
52
52
|
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
53
53
|
|
|
@@ -93,6 +93,7 @@ export class DeepBookContract {
|
|
|
93
93
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
94
94
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
95
95
|
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
96
|
+
const inputQuantity = Math.round(quantity * baseCoin.scalar);
|
|
96
97
|
|
|
97
98
|
tx.moveCall({
|
|
98
99
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::place_market_order`,
|
|
@@ -102,7 +103,7 @@ export class DeepBookContract {
|
|
|
102
103
|
tradeProof,
|
|
103
104
|
tx.pure.u64(clientOrderId),
|
|
104
105
|
tx.pure.u8(selfMatchingOption),
|
|
105
|
-
tx.pure.u64(
|
|
106
|
+
tx.pure.u64(inputQuantity),
|
|
106
107
|
tx.pure.bool(isBid),
|
|
107
108
|
tx.pure.bool(payWithDeep),
|
|
108
109
|
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
@@ -127,6 +128,7 @@ export class DeepBookContract {
|
|
|
127
128
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
128
129
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
129
130
|
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
131
|
+
const inputQuantity = Math.round(newQuantity * baseCoin.scalar);
|
|
130
132
|
|
|
131
133
|
tx.moveCall({
|
|
132
134
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::modify_order`,
|
|
@@ -135,7 +137,7 @@ export class DeepBookContract {
|
|
|
135
137
|
tx.object(balanceManager.address),
|
|
136
138
|
tradeProof,
|
|
137
139
|
tx.pure.u128(orderId),
|
|
138
|
-
tx.pure.u64(
|
|
140
|
+
tx.pure.u64(inputQuantity),
|
|
139
141
|
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
140
142
|
],
|
|
141
143
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
@@ -524,10 +526,13 @@ export class DeepBookContract {
|
|
|
524
526
|
|
|
525
527
|
const baseCoinInput =
|
|
526
528
|
params.baseCoin ??
|
|
527
|
-
coinWithBalance({ type: baseCoin.type, balance: baseAmount * baseCoin.scalar });
|
|
529
|
+
coinWithBalance({ type: baseCoin.type, balance: Math.round(baseAmount * baseCoin.scalar) });
|
|
528
530
|
|
|
529
531
|
const deepCoin =
|
|
530
|
-
params.deepCoin ??
|
|
532
|
+
params.deepCoin ??
|
|
533
|
+
coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) });
|
|
534
|
+
|
|
535
|
+
const minQuoteInput = Math.round(minQuote * quoteCoin.scalar);
|
|
531
536
|
|
|
532
537
|
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
533
538
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`,
|
|
@@ -535,7 +540,7 @@ export class DeepBookContract {
|
|
|
535
540
|
tx.object(pool.address),
|
|
536
541
|
baseCoinInput,
|
|
537
542
|
deepCoin,
|
|
538
|
-
tx.pure.u64(
|
|
543
|
+
tx.pure.u64(minQuoteInput),
|
|
539
544
|
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
540
545
|
],
|
|
541
546
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
@@ -565,10 +570,16 @@ export class DeepBookContract {
|
|
|
565
570
|
|
|
566
571
|
const quoteCoinInput =
|
|
567
572
|
params.quoteCoin ??
|
|
568
|
-
coinWithBalance({
|
|
573
|
+
coinWithBalance({
|
|
574
|
+
type: quoteCoin.type,
|
|
575
|
+
balance: Math.round(quoteAmount * quoteCoin.scalar),
|
|
576
|
+
});
|
|
569
577
|
|
|
570
578
|
const deepCoin =
|
|
571
|
-
params.deepCoin ??
|
|
579
|
+
params.deepCoin ??
|
|
580
|
+
coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) });
|
|
581
|
+
|
|
582
|
+
const minBaseInput = Math.round(minBase * baseCoin.scalar);
|
|
572
583
|
|
|
573
584
|
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({
|
|
574
585
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`,
|
|
@@ -576,7 +587,7 @@ export class DeepBookContract {
|
|
|
576
587
|
tx.object(pool.address),
|
|
577
588
|
quoteCoinInput,
|
|
578
589
|
deepCoin,
|
|
579
|
-
tx.pure.u64(
|
|
590
|
+
tx.pure.u64(minBaseInput),
|
|
580
591
|
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
581
592
|
],
|
|
582
593
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
@@ -27,9 +27,10 @@ export class FlashLoanContract {
|
|
|
27
27
|
const pool = this.#config.getPool(poolKey);
|
|
28
28
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
29
29
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
30
|
+
const inputQuantity = Math.round(borrowAmount * baseCoin.scalar);
|
|
30
31
|
const [baseCoinResult, flashLoan] = tx.moveCall({
|
|
31
32
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,
|
|
32
|
-
arguments: [tx.object(pool.address), tx.pure.u64(
|
|
33
|
+
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
33
34
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
34
35
|
});
|
|
35
36
|
return [baseCoinResult, flashLoan] as const;
|
|
@@ -57,7 +58,7 @@ export class FlashLoanContract {
|
|
|
57
58
|
const borrowScalar = baseCoin.scalar;
|
|
58
59
|
|
|
59
60
|
const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [
|
|
60
|
-
tx.pure.u64(borrowAmount * borrowScalar),
|
|
61
|
+
tx.pure.u64(Math.round(borrowAmount * borrowScalar)),
|
|
61
62
|
]);
|
|
62
63
|
tx.moveCall({
|
|
63
64
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,
|
|
@@ -78,9 +79,10 @@ export class FlashLoanContract {
|
|
|
78
79
|
const pool = this.#config.getPool(poolKey);
|
|
79
80
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
80
81
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
82
|
+
const inputQuantity = Math.round(borrowAmount * quoteCoin.scalar);
|
|
81
83
|
const [quoteCoinResult, flashLoan] = tx.moveCall({
|
|
82
84
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,
|
|
83
|
-
arguments: [tx.object(pool.address), tx.pure.u64(
|
|
85
|
+
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
|
|
84
86
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
85
87
|
});
|
|
86
88
|
return [quoteCoinResult, flashLoan] as const;
|
|
@@ -108,7 +110,7 @@ export class FlashLoanContract {
|
|
|
108
110
|
const borrowScalar = quoteCoin.scalar;
|
|
109
111
|
|
|
110
112
|
const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [
|
|
111
|
-
tx.pure.u64(borrowAmount * borrowScalar),
|
|
113
|
+
tx.pure.u64(Math.round(borrowAmount * borrowScalar)),
|
|
112
114
|
]);
|
|
113
115
|
tx.moveCall({
|
|
114
116
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,
|
|
@@ -33,6 +33,7 @@ export class GovernanceContract {
|
|
|
33
33
|
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
|
|
34
34
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
35
35
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
36
|
+
const stakeInput = Math.round(stakeAmount * DEEP_SCALAR);
|
|
36
37
|
|
|
37
38
|
tx.moveCall({
|
|
38
39
|
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stake`,
|
|
@@ -40,7 +41,7 @@ export class GovernanceContract {
|
|
|
40
41
|
tx.object(pool.address),
|
|
41
42
|
tx.object(balanceManager.address),
|
|
42
43
|
tradeProof,
|
|
43
|
-
tx.pure.u64(
|
|
44
|
+
tx.pure.u64(stakeInput),
|
|
44
45
|
],
|
|
45
46
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
46
47
|
});
|
|
@@ -86,9 +87,9 @@ export class GovernanceContract {
|
|
|
86
87
|
tx.object(pool.address),
|
|
87
88
|
tx.object(balanceManager.address),
|
|
88
89
|
tradeProof,
|
|
89
|
-
tx.pure.u64(takerFee * FLOAT_SCALAR),
|
|
90
|
-
tx.pure.u64(makerFee * FLOAT_SCALAR),
|
|
91
|
-
tx.pure.u64(stakeRequired * DEEP_SCALAR),
|
|
90
|
+
tx.pure.u64(Math.round(takerFee * FLOAT_SCALAR)),
|
|
91
|
+
tx.pure.u64(Math.round(makerFee * FLOAT_SCALAR)),
|
|
92
|
+
tx.pure.u64(Math.round(stakeRequired * DEEP_SCALAR)),
|
|
92
93
|
],
|
|
93
94
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
94
95
|
});
|
package/src/utils/constants.ts
CHANGED
|
@@ -12,8 +12,8 @@ export interface DeepbookPackageIds {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const testnetPackageIds = {
|
|
15
|
-
DEEPBOOK_PACKAGE_ID: '
|
|
16
|
-
REGISTRY_ID: '
|
|
15
|
+
DEEPBOOK_PACKAGE_ID: '0x3228ce0225baacb211e230f74891ceaabe3edeae230090ea3a5a176e535af7e9',
|
|
16
|
+
REGISTRY_ID: '0x9162317a81a9eb66ecd42705529b2a39c7805f98f42312275c2e7a599d518437',
|
|
17
17
|
DEEP_TREASURY_ID: '0x69fffdae0075f8f71f4fa793549c11079266910e8905169845af1f5d00e09dcb',
|
|
18
18
|
} satisfies DeepbookPackageIds;
|
|
19
19
|
|
|
@@ -76,22 +76,22 @@ export const mainnetCoins: CoinMap = {
|
|
|
76
76
|
|
|
77
77
|
export const testnetPools: PoolMap = {
|
|
78
78
|
DEEP_SUI: {
|
|
79
|
-
address: `
|
|
79
|
+
address: `0x2decc59a6f05c5800e5c8a1135f9d133d1746f562bf56673e6e81ef4f7ccd3b7`,
|
|
80
80
|
baseCoin: 'DEEP',
|
|
81
81
|
quoteCoin: 'SUI',
|
|
82
82
|
},
|
|
83
83
|
SUI_DBUSDC: {
|
|
84
|
-
address: `
|
|
84
|
+
address: `0xace543e8239f0c19783e57bacb02c581fd38d52899bdce117e49c91b494c8b10`,
|
|
85
85
|
baseCoin: 'SUI',
|
|
86
86
|
quoteCoin: 'DBUSDC',
|
|
87
87
|
},
|
|
88
88
|
DEEP_DBUSDC: {
|
|
89
|
-
address: `
|
|
89
|
+
address: `0x1faaa544a84c16215ef005edb046ddf8e1cfec0792aec3032e86e554b33bd33a`,
|
|
90
90
|
baseCoin: 'DEEP',
|
|
91
91
|
quoteCoin: 'DBUSDC',
|
|
92
92
|
},
|
|
93
93
|
DBUSDT_DBUSDC: {
|
|
94
|
-
address: `
|
|
94
|
+
address: `0x83aca040eaeaf061e3d482a44d1a87a5b8b6206ad52edae9d0479b830a38106f`,
|
|
95
95
|
baseCoin: 'DBUSDT',
|
|
96
96
|
quoteCoin: 'DBUSDC',
|
|
97
97
|
},
|