Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 75 additions & 98 deletions packages/deeptrade-core/Move.lock
Original file line number Diff line number Diff line change
@@ -1,100 +1,77 @@
# @generated by Move, please check-in and do not edit manually.
# Generated by move; do not edit
# This file should be checked in.

[move]
version = 3
manifest_digest = "69931A1480BE3DF484F425E055C6C764F7512F1B0D6FF5EBFE31A5313B1021A4"
deps_digest = "CAFAD8A7CF51067FB4358215BECB86BD100DD64E57C2AC8A7AE7D74B688F5965"
dependencies = [
{ id = "Bridge", name = "Bridge" },
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Pyth", name = "Pyth" },
{ id = "Sui", name = "Sui" },
{ id = "SuiSystem", name = "SuiSystem" },
{ id = "deepbook", name = "deepbook" },
{ id = "multisig", name = "multisig" },
]

[[move.package]]
id = "Bridge"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "4e8b6eda7d6411d80c62f39ac8a4f028e8d174c4", subdir = "crates/sui-framework/packages/bridge" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
{ id = "SuiSystem", name = "SuiSystem" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "4e8b6eda7d6411d80c62f39ac8a4f028e8d174c4", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
id = "Pyth"
source = { git = "https://github.com/pyth-network/pyth-crosschain.git", rev = "sui-contract-mainnet", subdir = "target_chains/sui/contracts" }

dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "Wormhole", name = "Wormhole" },
]

[[move.package]]
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "4e8b6eda7d6411d80c62f39ac8a4f028e8d174c4", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
id = "SuiSystem"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "4e8b6eda7d6411d80c62f39ac8a4f028e8d174c4", subdir = "crates/sui-framework/packages/sui-system" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
]

[[move.package]]
id = "Wormhole"
source = { git = "https://github.com/wormhole-foundation/wormhole.git", rev = "sui/mainnet", subdir = "sui/wormhole" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[[move.package]]
id = "deepbook"
source = { git = "https://github.com/MystenLabs/deepbookv3.git", rev = "v3.0.0", subdir = "packages/deepbook" }

dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "token", name = "token" },
]

[[move.package]]
id = "multisig"
source = { git = "https://github.com/DeeptradeProtocol/multisig-move.git", rev = "v1.0.1", subdir = "move" }

dependencies = [
{ id = "Bridge", name = "Bridge" },
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
{ id = "SuiSystem", name = "SuiSystem" },
]

[[move.package]]
id = "token"
source = { git = "https://github.com/MystenLabs/deepbookv3.git", rev = "v3.0.0", subdir = "packages/token" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.62.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.mainnet]
version = 4

[pinned.mainnet.MoveStdlib]
source = { git = "https://github.com/MystenLabs/sui.git", subdir = 'crates\sui-framework\packages\move-stdlib', rev = "ae59d7718668b468ce65702ecb0440aa2330f389" }
use_environment = "mainnet"
manifest_digest = "C4FE4C91DE74CBF223B2E380AE40F592177D21870DC2D7EB6227D2D694E05363"
deps = {}

[pinned.mainnet.MoveStdlib_1]
source = { git = "https://github.com/MystenLabs/sui.git", subdir = 'crates\sui-framework\packages\move-stdlib', rev = "041c5f2bae2fe52079e44b70514333532d69f4e6" }
use_environment = "mainnet"
manifest_digest = "C4FE4C91DE74CBF223B2E380AE40F592177D21870DC2D7EB6227D2D694E05363"
deps = {}

[pinned.mainnet.Pyth]
source = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = 'target_chains\sui\contracts', rev = "3bd1262dcba9518a6901aa6a15f04072799bfb37" }
use_environment = "mainnet"
manifest_digest = "F2C5AF85C4B72C8F6A8132D05DE4F787F4EB80DBFF812331ED65AE599E7DF92A"
deps = { Sui = "Sui_1", Wormhole = "Wormhole" }

[pinned.mainnet.PythProCompatible]
source = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = 'target_chains\sui\contracts', rev = "aa291266173173480efef77b9454f2dbc2b4fd62" }
use_environment = "mainnet"
manifest_digest = "3D2B5BBF2058F3C9DCA3527CC2486C518124687B60479CA9875E5475652B7BBC"
deps = { Sui = "Sui_1", WormholeSimpleMajority = "WormholeSimpleMajority" }

[pinned.mainnet.Sui]
source = { git = "https://github.com/MystenLabs/sui.git", subdir = 'crates\sui-framework\packages\sui-framework', rev = "ae59d7718668b468ce65702ecb0440aa2330f389" }
use_environment = "mainnet"
manifest_digest = "CD547CB1ACCE0880C835DAED2D8FFCB91D56C833AE5240D3AA5B918398263195"
deps = { MoveStdlib = "MoveStdlib" }

[pinned.mainnet.Sui_1]
source = { git = "https://github.com/MystenLabs/sui.git", subdir = 'crates\sui-framework\packages\sui-framework', rev = "041c5f2bae2fe52079e44b70514333532d69f4e6" }
use_environment = "mainnet"
manifest_digest = "CD547CB1ACCE0880C835DAED2D8FFCB91D56C833AE5240D3AA5B918398263195"
deps = { MoveStdlib = "MoveStdlib_1" }

[pinned.mainnet.Wormhole]
source = { git = "https://github.com/wormhole-foundation/wormhole.git", subdir = 'sui\wormhole', rev = "b71be5cbb9537c4aac8e23e74371affa3825efcd" }
use_environment = "mainnet"
manifest_digest = "0D766A0380B75080707CFA6099AF469A2E502B0D9DC334A9E9983B391C5555D9"
deps = { Sui = "Sui_1" }

[pinned.mainnet.WormholeSimpleMajority]
source = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = 'target_chains\sui\vendor\wormhole_simple_majority\wormhole', rev = "aa291266173173480efef77b9454f2dbc2b4fd62" }
use_environment = "mainnet"
manifest_digest = "0D766A0380B75080707CFA6099AF469A2E502B0D9DC334A9E9983B391C5555D9"
deps = { Sui = "Sui_1" }

[pinned.mainnet.deepbook]
source = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = 'packages\deepbook', rev = "8a46552dfac02f2225965dda243bdea1ddcbec89" }
use_environment = "mainnet"
manifest_digest = "BBE7F8BFEF088532C5358623C6F5B3153EE14B3265ABA833B0F3CF9D313264A7"
deps = { std = "MoveStdlib", sui = "Sui", token = "token" }

[pinned.mainnet.deeptrade_core]
source = { root = true }
use_environment = "mainnet"
manifest_digest = "349A4DE56587A83933E2890B98CC6978620033B8002BE40ABC22DBFE28820C32"
deps = { deepbook = "deepbook", multisig = "multisig", pyth = "Pyth", pyth_upgraded = "PythProCompatible", std = "MoveStdlib", sui = "Sui", token = "token" }

[pinned.mainnet.multisig]
source = { git = "https://github.com/DeeptradeProtocol/multisig-move.git", subdir = "move", rev = "263aeb17cd55115a1b2300a6cf5272e7962e7f7a" }
use_environment = "mainnet"
manifest_digest = "E41BBD67BE8940D26C79D78B028477EF5B33BA217A1282C78ACB344CF8A5ECF6"
deps = { std = "MoveStdlib", sui = "Sui" }

[pinned.mainnet.token]
source = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = 'packages\token', rev = "8a46552dfac02f2225965dda243bdea1ddcbec89" }
use_environment = "mainnet"
manifest_digest = "E41BBD67BE8940D26C79D78B028477EF5B33BA217A1282C78ACB344CF8A5ECF6"
deps = { std = "MoveStdlib", sui = "Sui" }
7 changes: 4 additions & 3 deletions packages/deeptrade-core/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "2.0.0"
edition = "2024.alpha"

[dependencies]
deepbook = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = "packages/deepbook", rev = "v4.0.0" }
token = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = "packages/token", rev = "main" }
deepbook = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = "packages/deepbook", rev = "v9.0.0" }
token = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = "packages/token", rev = "v9.0.0" }
multisig = { git = "https://github.com/DeeptradeProtocol/multisig-move.git", subdir = "move", rev = "v1.0.1" }

# Pyth dependency
Expand All @@ -16,5 +16,6 @@ pyth_upgraded = { git = "https://github.com/pyth-network/pyth-crosschain.git", s

# For `sui move test`, comment the production pins above and uncomment these.
# Never leave both copies uncommented.
# deepbook = { git = "https://github.com/DeeptradeProtocol/deepbookv3.git", subdir = "packages/deepbook", rev = "v4-tag-fork-test-methods" }
# deepbook = { git = "https://github.com/DeeptradeProtocol/deepbookv3.git", subdir = "packages/deepbook", rev = "v9-tag-fork-test-methods" }
# token = { git = "https://github.com/DeeptradeProtocol/deepbookv3.git", subdir = "packages/token", rev = "v9-tag-fork-test-methods" }
# pyth = { git = "https://github.com/DeeptradeProtocol/pyth-crosschain.git", subdir = "target_chains/sui/contracts", rev = "sui-contract-mainnet" }
32 changes: 30 additions & 2 deletions packages/deeptrade-core/sources/helper.move
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,42 @@ public(package) fun calculate_market_order_params<BaseToken, QuoteToken>(
// Since `get_quantity_out` goes through order book same way as actual order placement,
// we can use its `deep_req` value
// - For asks: Use order_amount directly as base quantity. Since `get_quantity_out` goes through
// order book same way as actual order placement, we can use its `deep_req` value
// order book same way as actual order placement, we can use its `deep_req` value.
// Exception is the dust-bid case handled below.
if (is_bid) {
let (base_out, _, deep_req) = pool.get_quantity_out(0, order_amount, clock);
let (_, lot_size, _) = pool.pool_book_params();
let floored_base_out = base_out - base_out % lot_size;
(floored_base_out, deep_req)
} else {
let (_, _, deep_req) = pool.get_quantity_out(order_amount, 0, clock);
let (base_left, _, mut deep_req) = pool.get_quantity_out(order_amount, 0, clock);
let (_, _, min_size) = pool.pool_book_params();

// DeepBook v9 `get_quantity_out` can return 0 DEEP required for ask that will require
// DEEP on execution. Example: min_size is 1 SUI, the sell is 10 SUI, and the only
// bid is 0.2 SUI. `get_quantity_out` will say nothing is filled, so no DEEP required,
// but the real order will fill that 0.2 SUI and take DEEP fee for that. If the balance
// manager has no DEEP, transaction aborts.
// How do we handle this?
// First, we check that `get_quantity_out` says nothing is filled (`base_left == order_amount`).
// This can be in 3 cases: empty bids, dust bids (< min_size), or order is too small (< min_size).
// So, at second, we check that the order is at least `min_size` (order_amount >= min_size).
// If both are true, we know that either bids are empty or dust.
// Third, we check that the best bid is live (best_bid.is_some()).
// If all three are true, we know that this is the dust-bid case and the order will require
// DEEP on execution. Since we know that sum of dust bids sizes is less than `min_size`
// (otherwise, `get_quantity_out` returns base_left < order_amount), we can estimate the maximum
// DEEP that can be required to fill these dust bids: `min_size * best_bid_price`.
if (base_left == order_amount && order_amount >= min_size) {
let best_bid = pool.best_bid_price(clock);
if (best_bid.is_some()) {
let (taker_deep, _) = pool.get_order_deep_required(
min_size,
best_bid.destroy_some(),
);
deep_req = taker_deep;
}
};
(order_amount, deep_req)
}
}
Expand Down
Loading
Loading