@mysten/deepbook-v3
Advanced tools
Comparing version 0.0.0-experimental-20240816131213 to 0.0.0-experimental-20240816171921
# @mysten/deepbook-v3 | ||
## 0.0.0-experimental-20240816131213 | ||
## 0.0.0-experimental-20240816171921 | ||
### Minor Changes | ||
- 36f1c6f: Rounding for numbers, exports update | ||
- c51f186: New contract constants | ||
@@ -8,0 +9,0 @@ |
@@ -98,3 +98,3 @@ "use strict"; | ||
coinType: coin.type, | ||
balance: adjusted_balance | ||
balance: Number(adjusted_balance.toFixed(9)) | ||
}; | ||
@@ -140,5 +140,5 @@ } | ||
baseQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / import_config.DEEP_SCALAR | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -168,5 +168,5 @@ } | ||
quoteQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / import_config.DEEP_SCALAR | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -198,5 +198,5 @@ } | ||
quoteQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / import_config.DEEP_SCALAR | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / import_config.DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -283,5 +283,7 @@ } | ||
prices: parsed_prices.map( | ||
(price) => Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar | ||
(price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9)) | ||
), | ||
quantities: parsed_quantities.map((price) => Number(price) / baseCoin.scalar) | ||
quantities: parsed_quantities.map( | ||
(price) => Number((Number(price) / baseCoin.scalar).toFixed(9)) | ||
) | ||
}; | ||
@@ -316,9 +318,13 @@ } | ||
bid_prices: bid_parsed_prices.map( | ||
(price) => Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar | ||
(price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9)) | ||
), | ||
bid_quantities: bid_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar), | ||
bid_quantities: bid_parsed_quantities.map( | ||
(quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9)) | ||
), | ||
ask_prices: ask_parsed_prices.map( | ||
(price) => Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar | ||
(price) => Number((Number(price) / import_config.FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9)) | ||
), | ||
ask_quantities: ask_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar) | ||
ask_quantities: ask_parsed_quantities.map( | ||
(quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9)) | ||
) | ||
}; | ||
@@ -346,5 +352,5 @@ } | ||
return { | ||
base: baseInVault / baseScalar, | ||
quote: quoteInVault / quoteScalar, | ||
deep: deepInVault / import_config.DEEP_SCALAR | ||
base: Number((baseInVault / baseScalar).toFixed(9)), | ||
quote: Number((quoteInVault / quoteScalar).toFixed(9)), | ||
deep: Number((deepInVault / import_config.DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -389,3 +395,3 @@ } | ||
const adjusted_mid_price = parsed_mid_price * baseCoin.scalar / quoteCoin.scalar / import_config.FLOAT_SCALAR; | ||
return adjusted_mid_price; | ||
return Number(adjusted_mid_price.toFixed(9)); | ||
} | ||
@@ -392,0 +398,0 @@ } |
@@ -8,1 +8,3 @@ export { DeepBookClient } from './client.js'; | ||
export { DeepBookConfig } from './utils/config.js'; | ||
export type { BalanceManager, Coin, Pool } from './types/index.js'; | ||
export type { CoinMap, PoolMap } from './utils/constants.js'; |
@@ -64,5 +64,6 @@ "use strict"; | ||
const coin = __privateGet(this, _config).getCoin(coinKey); | ||
const depositInput = Math.round(amountToDeposit * coin.scalar); | ||
const deposit = (0, import_transactions.coinWithBalance)({ | ||
type: coin.type, | ||
balance: amountToDeposit * coin.scalar | ||
balance: depositInput | ||
}); | ||
@@ -86,5 +87,6 @@ tx.moveCall({ | ||
const coin = __privateGet(this, _config).getCoin(coinKey); | ||
const withdrawInput = Math.round(amountToWithdraw * coin.scalar); | ||
const coinObject = tx.moveCall({ | ||
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`, | ||
arguments: [tx.object(managerId), tx.pure.u64(amountToWithdraw * coin.scalar)], | ||
arguments: [tx.object(managerId), tx.pure.u64(withdrawInput)], | ||
typeArguments: [coin.type] | ||
@@ -91,0 +93,0 @@ }); |
@@ -65,4 +65,4 @@ "use strict"; | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const inputPrice = price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar; | ||
const inputQuantity = quantity * baseCoin.scalar; | ||
const inputPrice = Math.round(price * import_config.FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar); | ||
const inputQuantity = Math.round(quantity * baseCoin.scalar); | ||
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey)); | ||
@@ -109,2 +109,3 @@ tx.moveCall({ | ||
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey)); | ||
const inputQuantity = Math.round(quantity * baseCoin.scalar); | ||
tx.moveCall({ | ||
@@ -118,3 +119,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_market_order`, | ||
tx.pure.u8(selfMatchingOption), | ||
tx.pure.u64(quantity * baseCoin.scalar), | ||
tx.pure.u64(inputQuantity), | ||
tx.pure.bool(isBid), | ||
@@ -141,2 +142,3 @@ tx.pure.bool(payWithDeep), | ||
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey)); | ||
const inputQuantity = Math.round(newQuantity * baseCoin.scalar); | ||
tx.moveCall({ | ||
@@ -149,3 +151,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::modify_order`, | ||
tx.pure.u128(orderId), | ||
tx.pure.u64(newQuantity), | ||
tx.pure.u64(inputQuantity), | ||
tx.object(import_utils.SUI_CLOCK_OBJECT_ID) | ||
@@ -500,4 +502,5 @@ ], | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const baseCoinInput = params.baseCoin ?? (0, import_transactions.coinWithBalance)({ type: baseCoin.type, balance: baseAmount * baseCoin.scalar }); | ||
const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: deepAmount * import_config.DEEP_SCALAR }); | ||
const baseCoinInput = params.baseCoin ?? (0, import_transactions.coinWithBalance)({ type: baseCoin.type, balance: Math.round(baseAmount * baseCoin.scalar) }); | ||
const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) }); | ||
const minQuoteInput = Math.round(minQuote * quoteCoin.scalar); | ||
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({ | ||
@@ -509,3 +512,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`, | ||
deepCoin, | ||
tx.pure.u64(quoteCoin.scalar * minQuote), | ||
tx.pure.u64(minQuoteInput), | ||
tx.object(import_utils.SUI_CLOCK_OBJECT_ID) | ||
@@ -533,4 +536,8 @@ ], | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const quoteCoinInput = params.quoteCoin ?? (0, import_transactions.coinWithBalance)({ type: quoteCoin.type, balance: quoteAmount * quoteCoin.scalar }); | ||
const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: deepAmount * import_config.DEEP_SCALAR }); | ||
const quoteCoinInput = params.quoteCoin ?? (0, import_transactions.coinWithBalance)({ | ||
type: quoteCoin.type, | ||
balance: Math.round(quoteAmount * quoteCoin.scalar) | ||
}); | ||
const deepCoin = params.deepCoin ?? (0, import_transactions.coinWithBalance)({ type: deepCoinType, balance: Math.round(deepAmount * import_config.DEEP_SCALAR) }); | ||
const minBaseInput = Math.round(minBase * baseCoin.scalar); | ||
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({ | ||
@@ -542,3 +549,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`, | ||
deepCoin, | ||
tx.pure.u64(baseCoin.scalar * minBase), | ||
tx.pure.u64(minBaseInput), | ||
tx.object(import_utils.SUI_CLOCK_OBJECT_ID) | ||
@@ -545,0 +552,0 @@ ], |
@@ -48,5 +48,6 @@ "use strict"; | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const inputQuantity = Math.round(borrowAmount * baseCoin.scalar); | ||
const [baseCoinResult, flashLoan] = tx.moveCall({ | ||
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`, | ||
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * baseCoin.scalar)], | ||
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)], | ||
typeArguments: [baseCoin.type, quoteCoin.type] | ||
@@ -70,3 +71,3 @@ }); | ||
const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [ | ||
tx.pure.u64(borrowAmount * borrowScalar) | ||
tx.pure.u64(Math.round(borrowAmount * borrowScalar)) | ||
]); | ||
@@ -90,5 +91,6 @@ tx.moveCall({ | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const inputQuantity = Math.round(borrowAmount * quoteCoin.scalar); | ||
const [quoteCoinResult, flashLoan] = tx.moveCall({ | ||
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`, | ||
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * quoteCoin.scalar)], | ||
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)], | ||
typeArguments: [baseCoin.type, quoteCoin.type] | ||
@@ -112,3 +114,3 @@ }); | ||
const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [ | ||
tx.pure.u64(borrowAmount * borrowScalar) | ||
tx.pure.u64(Math.round(borrowAmount * borrowScalar)) | ||
]); | ||
@@ -115,0 +117,0 @@ tx.moveCall({ |
@@ -52,2 +52,3 @@ "use strict"; | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const stakeInput = Math.round(stakeAmount * import_config.DEEP_SCALAR); | ||
tx.moveCall({ | ||
@@ -59,3 +60,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::stake`, | ||
tradeProof, | ||
tx.pure.u64(stakeAmount * import_config.DEEP_SCALAR) | ||
tx.pure.u64(stakeInput) | ||
], | ||
@@ -101,5 +102,5 @@ typeArguments: [baseCoin.type, quoteCoin.type] | ||
tradeProof, | ||
tx.pure.u64(takerFee * import_config.FLOAT_SCALAR), | ||
tx.pure.u64(makerFee * import_config.FLOAT_SCALAR), | ||
tx.pure.u64(stakeRequired * import_config.DEEP_SCALAR) | ||
tx.pure.u64(Math.round(takerFee * import_config.FLOAT_SCALAR)), | ||
tx.pure.u64(Math.round(makerFee * import_config.FLOAT_SCALAR)), | ||
tx.pure.u64(Math.round(stakeRequired * import_config.DEEP_SCALAR)) | ||
], | ||
@@ -106,0 +107,0 @@ typeArguments: [baseCoin.type, quoteCoin.type] |
@@ -75,3 +75,3 @@ var __typeError = (msg) => { | ||
coinType: coin.type, | ||
balance: adjusted_balance | ||
balance: Number(adjusted_balance.toFixed(9)) | ||
}; | ||
@@ -117,5 +117,5 @@ } | ||
baseQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / DEEP_SCALAR | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -145,5 +145,5 @@ } | ||
quoteQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / DEEP_SCALAR | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -175,5 +175,5 @@ } | ||
quoteQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / DEEP_SCALAR | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -260,5 +260,7 @@ } | ||
prices: parsed_prices.map( | ||
(price) => Number(price) / FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar | ||
(price) => Number((Number(price) / FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9)) | ||
), | ||
quantities: parsed_quantities.map((price) => Number(price) / baseCoin.scalar) | ||
quantities: parsed_quantities.map( | ||
(price) => Number((Number(price) / baseCoin.scalar).toFixed(9)) | ||
) | ||
}; | ||
@@ -293,9 +295,13 @@ } | ||
bid_prices: bid_parsed_prices.map( | ||
(price) => Number(price) / FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar | ||
(price) => Number((Number(price) / FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9)) | ||
), | ||
bid_quantities: bid_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar), | ||
bid_quantities: bid_parsed_quantities.map( | ||
(quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9)) | ||
), | ||
ask_prices: ask_parsed_prices.map( | ||
(price) => Number(price) / FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar | ||
(price) => Number((Number(price) / FLOAT_SCALAR / quoteCoin.scalar * baseCoin.scalar).toFixed(9)) | ||
), | ||
ask_quantities: ask_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar) | ||
ask_quantities: ask_parsed_quantities.map( | ||
(quantity) => Number((Number(quantity) / baseCoin.scalar).toFixed(9)) | ||
) | ||
}; | ||
@@ -323,5 +329,5 @@ } | ||
return { | ||
base: baseInVault / baseScalar, | ||
quote: quoteInVault / quoteScalar, | ||
deep: deepInVault / DEEP_SCALAR | ||
base: Number((baseInVault / baseScalar).toFixed(9)), | ||
quote: Number((quoteInVault / quoteScalar).toFixed(9)), | ||
deep: Number((deepInVault / DEEP_SCALAR).toFixed(9)) | ||
}; | ||
@@ -366,3 +372,3 @@ } | ||
const adjusted_mid_price = parsed_mid_price * baseCoin.scalar / quoteCoin.scalar / FLOAT_SCALAR; | ||
return adjusted_mid_price; | ||
return Number(adjusted_mid_price.toFixed(9)); | ||
} | ||
@@ -369,0 +375,0 @@ } |
@@ -8,1 +8,3 @@ export { DeepBookClient } from './client.js'; | ||
export { DeepBookConfig } from './utils/config.js'; | ||
export type { BalanceManager, Coin, Pool } from './types/index.js'; | ||
export type { CoinMap, PoolMap } from './utils/constants.js'; |
@@ -41,5 +41,6 @@ var __typeError = (msg) => { | ||
const coin = __privateGet(this, _config).getCoin(coinKey); | ||
const depositInput = Math.round(amountToDeposit * coin.scalar); | ||
const deposit = coinWithBalance({ | ||
type: coin.type, | ||
balance: amountToDeposit * coin.scalar | ||
balance: depositInput | ||
}); | ||
@@ -63,5 +64,6 @@ tx.moveCall({ | ||
const coin = __privateGet(this, _config).getCoin(coinKey); | ||
const withdrawInput = Math.round(amountToWithdraw * coin.scalar); | ||
const coinObject = tx.moveCall({ | ||
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`, | ||
arguments: [tx.object(managerId), tx.pure.u64(amountToWithdraw * coin.scalar)], | ||
arguments: [tx.object(managerId), tx.pure.u64(withdrawInput)], | ||
typeArguments: [coin.type] | ||
@@ -68,0 +70,0 @@ }); |
@@ -42,4 +42,4 @@ var __typeError = (msg) => { | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const inputPrice = price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar; | ||
const inputQuantity = quantity * baseCoin.scalar; | ||
const inputPrice = Math.round(price * FLOAT_SCALAR * quoteCoin.scalar / baseCoin.scalar); | ||
const inputQuantity = Math.round(quantity * baseCoin.scalar); | ||
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey)); | ||
@@ -86,2 +86,3 @@ tx.moveCall({ | ||
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey)); | ||
const inputQuantity = Math.round(quantity * baseCoin.scalar); | ||
tx.moveCall({ | ||
@@ -95,3 +96,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::place_market_order`, | ||
tx.pure.u8(selfMatchingOption), | ||
tx.pure.u64(quantity * baseCoin.scalar), | ||
tx.pure.u64(inputQuantity), | ||
tx.pure.bool(isBid), | ||
@@ -118,2 +119,3 @@ tx.pure.bool(payWithDeep), | ||
const tradeProof = tx.add(__privateGet(this, _config).balanceManager.generateProof(balanceManagerKey)); | ||
const inputQuantity = Math.round(newQuantity * baseCoin.scalar); | ||
tx.moveCall({ | ||
@@ -126,3 +128,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::modify_order`, | ||
tx.pure.u128(orderId), | ||
tx.pure.u64(newQuantity), | ||
tx.pure.u64(inputQuantity), | ||
tx.object(SUI_CLOCK_OBJECT_ID) | ||
@@ -477,4 +479,5 @@ ], | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const baseCoinInput = params.baseCoin ?? coinWithBalance({ type: baseCoin.type, balance: baseAmount * baseCoin.scalar }); | ||
const deepCoin = params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: deepAmount * DEEP_SCALAR }); | ||
const baseCoinInput = params.baseCoin ?? coinWithBalance({ type: baseCoin.type, balance: Math.round(baseAmount * baseCoin.scalar) }); | ||
const deepCoin = params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) }); | ||
const minQuoteInput = Math.round(minQuote * quoteCoin.scalar); | ||
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({ | ||
@@ -486,3 +489,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`, | ||
deepCoin, | ||
tx.pure.u64(quoteCoin.scalar * minQuote), | ||
tx.pure.u64(minQuoteInput), | ||
tx.object(SUI_CLOCK_OBJECT_ID) | ||
@@ -510,4 +513,8 @@ ], | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const quoteCoinInput = params.quoteCoin ?? coinWithBalance({ type: quoteCoin.type, balance: quoteAmount * quoteCoin.scalar }); | ||
const deepCoin = params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: deepAmount * DEEP_SCALAR }); | ||
const quoteCoinInput = params.quoteCoin ?? coinWithBalance({ | ||
type: quoteCoin.type, | ||
balance: Math.round(quoteAmount * quoteCoin.scalar) | ||
}); | ||
const deepCoin = params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) }); | ||
const minBaseInput = Math.round(minBase * baseCoin.scalar); | ||
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({ | ||
@@ -519,3 +526,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`, | ||
deepCoin, | ||
tx.pure.u64(baseCoin.scalar * minBase), | ||
tx.pure.u64(minBaseInput), | ||
tx.object(SUI_CLOCK_OBJECT_ID) | ||
@@ -522,0 +529,0 @@ ], |
@@ -25,5 +25,6 @@ var __typeError = (msg) => { | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const inputQuantity = Math.round(borrowAmount * baseCoin.scalar); | ||
const [baseCoinResult, flashLoan] = tx.moveCall({ | ||
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`, | ||
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * baseCoin.scalar)], | ||
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)], | ||
typeArguments: [baseCoin.type, quoteCoin.type] | ||
@@ -47,3 +48,3 @@ }); | ||
const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [ | ||
tx.pure.u64(borrowAmount * borrowScalar) | ||
tx.pure.u64(Math.round(borrowAmount * borrowScalar)) | ||
]); | ||
@@ -67,5 +68,6 @@ tx.moveCall({ | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const inputQuantity = Math.round(borrowAmount * quoteCoin.scalar); | ||
const [quoteCoinResult, flashLoan] = tx.moveCall({ | ||
target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`, | ||
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * quoteCoin.scalar)], | ||
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)], | ||
typeArguments: [baseCoin.type, quoteCoin.type] | ||
@@ -89,3 +91,3 @@ }); | ||
const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [ | ||
tx.pure.u64(borrowAmount * borrowScalar) | ||
tx.pure.u64(Math.round(borrowAmount * borrowScalar)) | ||
]); | ||
@@ -92,0 +94,0 @@ tx.moveCall({ |
@@ -29,2 +29,3 @@ var __typeError = (msg) => { | ||
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin); | ||
const stakeInput = Math.round(stakeAmount * DEEP_SCALAR); | ||
tx.moveCall({ | ||
@@ -36,3 +37,3 @@ target: `${__privateGet(this, _config).DEEPBOOK_PACKAGE_ID}::pool::stake`, | ||
tradeProof, | ||
tx.pure.u64(stakeAmount * DEEP_SCALAR) | ||
tx.pure.u64(stakeInput) | ||
], | ||
@@ -78,5 +79,5 @@ typeArguments: [baseCoin.type, quoteCoin.type] | ||
tradeProof, | ||
tx.pure.u64(takerFee * FLOAT_SCALAR), | ||
tx.pure.u64(makerFee * FLOAT_SCALAR), | ||
tx.pure.u64(stakeRequired * DEEP_SCALAR) | ||
tx.pure.u64(Math.round(takerFee * FLOAT_SCALAR)), | ||
tx.pure.u64(Math.round(makerFee * FLOAT_SCALAR)), | ||
tx.pure.u64(Math.round(stakeRequired * DEEP_SCALAR)) | ||
], | ||
@@ -83,0 +84,0 @@ typeArguments: [baseCoin.type, quoteCoin.type] |
@@ -5,3 +5,3 @@ { | ||
"description": "Sui Deepbook SDK", | ||
"version": "0.0.0-experimental-20240816131213", | ||
"version": "0.0.0-experimental-20240816171921", | ||
"license": "Apache-2.0", | ||
@@ -8,0 +8,0 @@ "type": "commonjs", |
@@ -96,3 +96,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
coinType: coin.type, | ||
balance: adjusted_balance, | ||
balance: Number(adjusted_balance.toFixed(9)), | ||
}; | ||
@@ -146,5 +146,5 @@ } | ||
baseQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / DEEP_SCALAR, | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)), | ||
}; | ||
@@ -178,5 +178,5 @@ } | ||
quoteQuantity: quoteQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / DEEP_SCALAR, | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)), | ||
}; | ||
@@ -212,5 +212,5 @@ } | ||
quoteQuantity, | ||
baseOut: baseOut / baseScalar, | ||
quoteOut: quoteOut / quoteScalar, | ||
deepRequired: deepRequired / DEEP_SCALAR, | ||
baseOut: Number((baseOut / baseScalar).toFixed(9)), | ||
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)), | ||
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)), | ||
}; | ||
@@ -308,6 +308,8 @@ } | ||
return { | ||
prices: parsed_prices.map( | ||
(price) => (Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar, | ||
prices: parsed_prices.map((price) => | ||
Number(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)), | ||
), | ||
quantities: parsed_quantities.map((price) => Number(price) / baseCoin.scalar), | ||
quantities: parsed_quantities.map((price) => | ||
Number((Number(price) / baseCoin.scalar).toFixed(9)), | ||
), | ||
}; | ||
@@ -346,10 +348,14 @@ } | ||
return { | ||
bid_prices: bid_parsed_prices.map( | ||
(price) => (Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar, | ||
bid_prices: bid_parsed_prices.map((price) => | ||
Number(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)), | ||
), | ||
bid_quantities: bid_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar), | ||
ask_prices: ask_parsed_prices.map( | ||
(price) => (Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar, | ||
bid_quantities: bid_parsed_quantities.map((quantity) => | ||
Number((Number(quantity) / baseCoin.scalar).toFixed(9)), | ||
), | ||
ask_quantities: ask_parsed_quantities.map((quantity) => Number(quantity) / baseCoin.scalar), | ||
ask_prices: ask_parsed_prices.map((price) => | ||
Number(((Number(price) / FLOAT_SCALAR / quoteCoin.scalar) * baseCoin.scalar).toFixed(9)), | ||
), | ||
ask_quantities: ask_parsed_quantities.map((quantity) => | ||
Number((Number(quantity) / baseCoin.scalar).toFixed(9)), | ||
), | ||
}; | ||
@@ -381,5 +387,5 @@ } | ||
return { | ||
base: baseInVault / baseScalar, | ||
quote: quoteInVault / quoteScalar, | ||
deep: deepInVault / DEEP_SCALAR, | ||
base: Number((baseInVault / baseScalar).toFixed(9)), | ||
quote: Number((quoteInVault / quoteScalar).toFixed(9)), | ||
deep: Number((deepInVault / DEEP_SCALAR).toFixed(9)), | ||
}; | ||
@@ -434,4 +440,4 @@ } | ||
return adjusted_mid_price; | ||
return Number(adjusted_mid_price.toFixed(9)); | ||
} | ||
} |
@@ -11,1 +11,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
export { DeepBookConfig } from './utils/config.js'; | ||
export type { BalanceManager, Coin, Pool } from './types/index.js'; | ||
export type { CoinMap, PoolMap } from './utils/constants.js'; |
@@ -49,5 +49,6 @@ // Copyright (c) Mysten Labs, Inc. | ||
const coin = this.#config.getCoin(coinKey); | ||
const depositInput = Math.round(amountToDeposit * coin.scalar); | ||
const deposit = coinWithBalance({ | ||
type: coin.type, | ||
balance: amountToDeposit * coin.scalar, | ||
balance: depositInput, | ||
}); | ||
@@ -75,5 +76,6 @@ | ||
const coin = this.#config.getCoin(coinKey); | ||
const withdrawInput = Math.round(amountToWithdraw * coin.scalar); | ||
const coinObject = tx.moveCall({ | ||
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::withdraw`, | ||
arguments: [tx.object(managerId), tx.pure.u64(amountToWithdraw * coin.scalar)], | ||
arguments: [tx.object(managerId), tx.pure.u64(withdrawInput)], | ||
typeArguments: [coin.type], | ||
@@ -80,0 +82,0 @@ }); |
@@ -49,4 +49,4 @@ // Copyright (c) Mysten Labs, Inc. | ||
const quoteCoin = this.#config.getCoin(pool.quoteCoin); | ||
const inputPrice = (price * FLOAT_SCALAR * quoteCoin.scalar) / baseCoin.scalar; | ||
const inputQuantity = quantity * baseCoin.scalar; | ||
const inputPrice = Math.round((price * FLOAT_SCALAR * quoteCoin.scalar) / baseCoin.scalar); | ||
const inputQuantity = Math.round(quantity * baseCoin.scalar); | ||
@@ -97,2 +97,3 @@ const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey)); | ||
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey)); | ||
const inputQuantity = Math.round(quantity * baseCoin.scalar); | ||
@@ -107,3 +108,3 @@ tx.moveCall({ | ||
tx.pure.u8(selfMatchingOption), | ||
tx.pure.u64(quantity * baseCoin.scalar), | ||
tx.pure.u64(inputQuantity), | ||
tx.pure.bool(isBid), | ||
@@ -133,2 +134,3 @@ tx.pure.bool(payWithDeep), | ||
const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey)); | ||
const inputQuantity = Math.round(newQuantity * baseCoin.scalar); | ||
@@ -142,3 +144,3 @@ tx.moveCall({ | ||
tx.pure.u128(orderId), | ||
tx.pure.u64(newQuantity), | ||
tx.pure.u64(inputQuantity), | ||
tx.object(SUI_CLOCK_OBJECT_ID), | ||
@@ -532,7 +534,10 @@ ], | ||
params.baseCoin ?? | ||
coinWithBalance({ type: baseCoin.type, balance: baseAmount * baseCoin.scalar }); | ||
coinWithBalance({ type: baseCoin.type, balance: Math.round(baseAmount * baseCoin.scalar) }); | ||
const deepCoin = | ||
params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: deepAmount * DEEP_SCALAR }); | ||
params.deepCoin ?? | ||
coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) }); | ||
const minQuoteInput = Math.round(minQuote * quoteCoin.scalar); | ||
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({ | ||
@@ -544,3 +549,3 @@ target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_base_for_quote`, | ||
deepCoin, | ||
tx.pure.u64(quoteCoin.scalar * minQuote), | ||
tx.pure.u64(minQuoteInput), | ||
tx.object(SUI_CLOCK_OBJECT_ID), | ||
@@ -575,7 +580,13 @@ ], | ||
params.quoteCoin ?? | ||
coinWithBalance({ type: quoteCoin.type, balance: quoteAmount * quoteCoin.scalar }); | ||
coinWithBalance({ | ||
type: quoteCoin.type, | ||
balance: Math.round(quoteAmount * quoteCoin.scalar), | ||
}); | ||
const deepCoin = | ||
params.deepCoin ?? coinWithBalance({ type: deepCoinType, balance: deepAmount * DEEP_SCALAR }); | ||
params.deepCoin ?? | ||
coinWithBalance({ type: deepCoinType, balance: Math.round(deepAmount * DEEP_SCALAR) }); | ||
const minBaseInput = Math.round(minBase * baseCoin.scalar); | ||
const [baseCoinResult, quoteCoinResult, deepCoinResult] = tx.moveCall({ | ||
@@ -587,3 +598,3 @@ target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::swap_exact_quote_for_base`, | ||
deepCoin, | ||
tx.pure.u64(baseCoin.scalar * minBase), | ||
tx.pure.u64(minBaseInput), | ||
tx.object(SUI_CLOCK_OBJECT_ID), | ||
@@ -590,0 +601,0 @@ ], |
@@ -30,5 +30,6 @@ // Copyright (c) Mysten Labs, Inc. | ||
const quoteCoin = this.#config.getCoin(pool.quoteCoin); | ||
const inputQuantity = Math.round(borrowAmount * baseCoin.scalar); | ||
const [baseCoinResult, flashLoan] = tx.moveCall({ | ||
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`, | ||
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * baseCoin.scalar)], | ||
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)], | ||
typeArguments: [baseCoin.type, quoteCoin.type], | ||
@@ -61,3 +62,3 @@ }); | ||
const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [ | ||
tx.pure.u64(borrowAmount * borrowScalar), | ||
tx.pure.u64(Math.round(borrowAmount * borrowScalar)), | ||
]); | ||
@@ -83,5 +84,6 @@ tx.moveCall({ | ||
const quoteCoin = this.#config.getCoin(pool.quoteCoin); | ||
const inputQuantity = Math.round(borrowAmount * quoteCoin.scalar); | ||
const [quoteCoinResult, flashLoan] = tx.moveCall({ | ||
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`, | ||
arguments: [tx.object(pool.address), tx.pure.u64(borrowAmount * quoteCoin.scalar)], | ||
arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)], | ||
typeArguments: [baseCoin.type, quoteCoin.type], | ||
@@ -114,3 +116,3 @@ }); | ||
const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [ | ||
tx.pure.u64(borrowAmount * borrowScalar), | ||
tx.pure.u64(Math.round(borrowAmount * borrowScalar)), | ||
]); | ||
@@ -117,0 +119,0 @@ tx.moveCall({ |
@@ -36,2 +36,3 @@ // Copyright (c) Mysten Labs, Inc. | ||
const quoteCoin = this.#config.getCoin(pool.quoteCoin); | ||
const stakeInput = Math.round(stakeAmount * DEEP_SCALAR); | ||
@@ -44,3 +45,3 @@ tx.moveCall({ | ||
tradeProof, | ||
tx.pure.u64(stakeAmount * DEEP_SCALAR), | ||
tx.pure.u64(stakeInput), | ||
], | ||
@@ -91,5 +92,5 @@ typeArguments: [baseCoin.type, quoteCoin.type], | ||
tradeProof, | ||
tx.pure.u64(takerFee * FLOAT_SCALAR), | ||
tx.pure.u64(makerFee * FLOAT_SCALAR), | ||
tx.pure.u64(stakeRequired * DEEP_SCALAR), | ||
tx.pure.u64(Math.round(takerFee * FLOAT_SCALAR)), | ||
tx.pure.u64(Math.round(makerFee * FLOAT_SCALAR)), | ||
tx.pure.u64(Math.round(stakeRequired * DEEP_SCALAR)), | ||
], | ||
@@ -96,0 +97,0 @@ typeArguments: [baseCoin.type, quoteCoin.type], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
645375
6673