Skip to content

Commit 03e1af6

Browse files
authored
[move] Handling recently introduced warnings in the framework code (#13866)
## Description Recently introduced warnings caused a lot of noise when building framework code itself. While only meaningful to a rather small number of devs (working on the framework code), it was nevertheless annoying and this PR is a cleanup attempt. When compiling user code, these warnings are suppressed anyway - hence no user impact. The strategy was to use suppression unless (and ALWAYS in the governance code) unless it seemed safe to remove a given construct - in particular, if there was an unused constant (particularly indicating an error) and there are no native functions in the module. ## Test Plan All tests in sui-framework-tests must pass --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
1 parent 24e7e97 commit 03e1af6

27 files changed

+102
-56
lines changed

crates/sui-framework/packages/deepbook/sources/clob.move

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#[allow(unused_use)]
45
module deepbook::clob {
56
use std::option;
67
use std::type_name::{Self, TypeName};
@@ -23,7 +24,7 @@ module deepbook::clob {
2324

2425
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
2526
const DEPRECATED: u64 = 0;
26-
const ENotImplemented: u64 = 1;
27+
#[test_only]
2728
const EInvalidFeeRateRebateRate: u64 = 2;
2829
const EInvalidOrderId: u64 = 3;
2930
const EUnauthorizedCancel: u64 = 4;
@@ -37,41 +38,42 @@ module deepbook::clob {
3738
const EOrderCannotBeFullyPassive: u64 = 10;
3839
const EInvalidTickPrice: u64 = 11;
3940
const EInvalidUser: u64 = 12;
41+
#[test_only]
4042
const ENotEqual: u64 = 13;
4143
const EInvalidRestriction: u64 = 14;
42-
const ELevelNotEmpty: u64 = 15;
44+
#[test_only]
4345
const EInvalidPair: u64 = 16;
44-
const EInvalidBaseBalance: u64 = 17;
45-
const EInvalidFee: u64 = 18;
4646
const EInvalidExpireTimestamp: u64 = 19;
47+
#[test_only]
4748
const EInvalidTickSizeLotSize: u64 = 20;
4849

4950
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
5051

5152
// <<<<<<<<<<<<<<<<<<<<<<<< Constants <<<<<<<<<<<<<<<<<<<<<<<<
5253
const FLOAT_SCALING: u64 = 1_000_000_000;
5354
// Restrictions on limit orders.
54-
const N_RESTRICTIONS: u8 = 4;
5555
const NO_RESTRICTION: u8 = 0;
5656
// Mandates that whatever amount of an order that can be executed in the current transaction, be filled and then the rest of the order canceled.
5757
const IMMEDIATE_OR_CANCEL: u8 = 1;
5858
// Mandates that the entire order size be filled in the current transaction. Otherwise, the order is canceled.
5959
const FILL_OR_KILL: u8 = 2;
6060
// Mandates that the entire order be passive. Otherwise, cancel the order.
6161
const POST_OR_ABORT: u8 = 3;
62+
#[test_only]
6263
const MIN_BID_ORDER_ID: u64 = 1;
6364
const MIN_ASK_ORDER_ID: u64 = 1 << 63;
6465
const MIN_PRICE: u64 = 0;
6566
const MAX_PRICE: u64 = ((1u128 << 64 - 1) as u64);
67+
#[test_only]
6668
const TIMESTAMP_INF: u64 = ((1u128 << 64 - 1) as u64);
67-
const REFERENCE_TAKER_FEE_RATE: u64 = 5_000_000;
68-
const REFERENCE_MAKER_REBATE_RATE: u64 = 2_500_000;
69+
#[test_only]
6970
const FEE_AMOUNT_FOR_CREATE_POOL: u64 = 100 * 1_000_000_000; // 100 SUI
7071

7172
// <<<<<<<<<<<<<<<<<<<<<<<< Constants <<<<<<<<<<<<<<<<<<<<<<<<
7273

7374
// <<<<<<<<<<<<<<<<<<<<<<<< Events <<<<<<<<<<<<<<<<<<<<<<<<
7475

76+
#[allow(unused_field)]
7577
/// Emitted when a new pool is created
7678
struct PoolCreated has copy, store, drop {
7779
/// object ID of the newly created pool
@@ -154,6 +156,7 @@ module deepbook::clob {
154156
// other price level info
155157
}
156158

159+
#[allow(unused_field)]
157160
struct Pool<phantom BaseAsset, phantom QuoteAsset> has key {
158161
// The key to the following Critbit Tree are order prices.
159162
id: UID,
@@ -199,6 +202,7 @@ module deepbook::clob {
199202
abort DEPRECATED
200203
}
201204

205+
#[test_only]
202206
fun create_pool_<BaseAsset, QuoteAsset>(
203207
taker_fee_rate: u64,
204208
maker_rebate_rate: u64,
@@ -246,6 +250,7 @@ module deepbook::clob {
246250
})
247251
}
248252

253+
#[allow(unused_type_parameter)]
249254
public fun create_pool<BaseAsset, QuoteAsset>(
250255
_tick_size: u64,
251256
_lot_size: u64,
@@ -1056,7 +1061,7 @@ module deepbook::clob {
10561061
if (is_bid) { &pool.bids } else { &pool.asks },
10571062
tick_price);
10581063
assert!(tick_exists, EInvalidOrderId);
1059-
let order = remove_order<BaseAsset, QuoteAsset>(
1064+
let order = remove_order(
10601065
if (is_bid) { &mut pool.bids } else { &mut pool.asks },
10611066
usr_open_orders,
10621067
tick_index,
@@ -1072,7 +1077,7 @@ module deepbook::clob {
10721077
emit_order_canceled<BaseAsset, QuoteAsset>(*object::uid_as_inner(&pool.id), &order);
10731078
}
10741079

1075-
fun remove_order<BaseAsset, QuoteAsset>(
1080+
fun remove_order(
10761081
open_orders: &mut CritbitTree<TickLevel>,
10771082
usr_open_orders: &mut LinkedTable<u64, u64>,
10781083
tick_index: u64,
@@ -1107,7 +1112,7 @@ module deepbook::clob {
11071112
if (is_bid) { &mut pool.bids }
11081113
else { &mut pool.asks };
11091114
let (_, tick_index) = critbit::find_leaf(open_orders, order_price);
1110-
let order = remove_order<BaseAsset, QuoteAsset>(
1115+
let order = remove_order(
11111116
open_orders,
11121117
usr_open_order_ids,
11131118
tick_index,
@@ -1164,7 +1169,7 @@ module deepbook::clob {
11641169
assert!(tick_exists, EInvalidTickPrice);
11651170
tick_index = new_tick_index;
11661171
};
1167-
let order = remove_order<BaseAsset, QuoteAsset>(
1172+
let order = remove_order(
11681173
if (is_bid) { &mut pool.bids } else { &mut pool.asks },
11691174
usr_open_orders,
11701175
tick_index,
@@ -1250,7 +1255,7 @@ module deepbook::clob {
12501255
let depth_vec = vector::empty<u64>();
12511256
if (price_low == 0) { return (price_vec, depth_vec) };
12521257
while (price_low <= price_high) {
1253-
let depth = get_level2_book_status<BaseAsset, QuoteAsset>(
1258+
let depth = get_level2_book_status(
12541259
&pool.bids,
12551260
price_low,
12561261
clock::timestamp_ms(clock)
@@ -1284,7 +1289,7 @@ module deepbook::clob {
12841289
let depth_vec = vector::empty<u64>();
12851290
if (price_low == 0) { return (price_vec, depth_vec) };
12861291
while (price_low <= price_high) {
1287-
let depth = get_level2_book_status<BaseAsset, QuoteAsset>(
1292+
let depth = get_level2_book_status(
12881293
&pool.asks,
12891294
price_low,
12901295
clock::timestamp_ms(clock)
@@ -1299,7 +1304,7 @@ module deepbook::clob {
12991304
}
13001305

13011306
/// internal func to retrive single depth of a tick price
1302-
fun get_level2_book_status<BaseAsset, QuoteAsset>(
1307+
fun get_level2_book_status(
13031308
open_orders: &CritbitTree<TickLevel>,
13041309
price: u64,
13051310
time_stamp: u64
@@ -1645,15 +1650,15 @@ module deepbook::clob {
16451650
): Order {
16461651
let order;
16471652
if (is_bid) {
1648-
order = remove_order<BaseAsset, QuoteAsset>(
1653+
order = remove_order(
16491654
&mut pool.bids,
16501655
borrow_mut(&mut pool.usr_open_orders, owner),
16511656
tick_index,
16521657
order_id(sequence_id, is_bid),
16531658
owner
16541659
)
16551660
} else {
1656-
order = remove_order<BaseAsset, QuoteAsset>(
1661+
order = remove_order(
16571662
&mut pool.asks,
16581663
borrow_mut(&mut pool.usr_open_orders, owner),
16591664
tick_index,
@@ -1665,6 +1670,7 @@ module deepbook::clob {
16651670
}
16661671

16671672
// === Deprecated ===
1673+
#[allow(unused_field)]
16681674
/// Deprecated since v1.0.0, use `OrderPlacedV2` instead.
16691675
struct OrderPlaced<phantom BaseAsset, phantom QuoteAsset> has copy, store, drop {
16701676
/// object ID of the pool the order was placed on
@@ -1678,6 +1684,7 @@ module deepbook::clob {
16781684
price: u64,
16791685
}
16801686

1687+
#[allow(unused_field)]
16811688
/// Deprecated since v1.0.0, use `OrderFilledV2` instead.
16821689
struct OrderFilled<phantom BaseAsset, phantom QuoteAsset> has copy, store, drop {
16831690
/// object ID of the pool the order was placed on

crates/sui-framework/packages/deepbook/sources/clob_v2.move

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module deepbook::clob_v2 {
2424

2525
friend deepbook::order_query;
2626
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
27-
const ENotImplemented: u64 = 1;
2827
const EInvalidFeeRateRebateRate: u64 = 2;
2928
const EInvalidOrderId: u64 = 3;
3029
const EUnauthorizedCancel: u64 = 4;
@@ -40,9 +39,7 @@ module deepbook::clob_v2 {
4039
const EInvalidUser: u64 = 12;
4140
const ENotEqual: u64 = 13;
4241
const EInvalidRestriction: u64 = 14;
43-
const ELevelNotEmpty: u64 = 15;
4442
const EInvalidPair: u64 = 16;
45-
const EInvalidBaseBalance: u64 = 17;
4643
const EInvalidFee: u64 = 18;
4744
const EInvalidExpireTimestamp: u64 = 19;
4845
const EInvalidTickSizeLotSize: u64 = 20;
@@ -56,7 +53,6 @@ module deepbook::clob_v2 {
5653
// Cancel older (resting) order in full. Continue to execute the newer taking order.
5754
const CANCEL_OLDEST: u8 = 0;
5855
// Restrictions on limit orders.
59-
const N_RESTRICTIONS: u8 = 4;
6056
const NO_RESTRICTION: u8 = 0;
6157
// Mandates that whatever amount of an order that can be executed in the current transaction, be filled and then the rest of the order canceled.
6258
const IMMEDIATE_OR_CANCEL: u8 = 1;
@@ -68,10 +64,12 @@ module deepbook::clob_v2 {
6864
const MIN_ASK_ORDER_ID: u64 = 1 << 63;
6965
const MIN_PRICE: u64 = 0;
7066
const MAX_PRICE: u64 = ((1u128 << 64 - 1) as u64);
67+
#[test_only]
7168
const TIMESTAMP_INF: u64 = ((1u128 << 64 - 1) as u64);
7269
const REFERENCE_TAKER_FEE_RATE: u64 = 2_500_000;
7370
const REFERENCE_MAKER_REBATE_RATE: u64 = 1_500_000;
7471
const FEE_AMOUNT_FOR_CREATE_POOL: u64 = 100 * 1_000_000_000; // 100 SUI
72+
#[test_only]
7573
const PREVENT_SELF_MATCHING_DEFAULT: u8 = 0;
7674

7775
// <<<<<<<<<<<<<<<<<<<<<<<< Constants <<<<<<<<<<<<<<<<<<<<<<<<
@@ -1297,7 +1295,7 @@ module deepbook::clob_v2 {
12971295
if (is_bid) { &pool.bids } else { &pool.asks },
12981296
tick_price);
12991297
assert!(tick_exists, EInvalidOrderId);
1300-
let order = remove_order<BaseAsset, QuoteAsset>(
1298+
let order = remove_order(
13011299
if (is_bid) { &mut pool.bids } else { &mut pool.asks },
13021300
usr_open_orders,
13031301
tick_index,
@@ -1317,7 +1315,7 @@ module deepbook::clob_v2 {
13171315
emit_order_canceled<BaseAsset, QuoteAsset>(*object::uid_as_inner(&pool.id), &order);
13181316
}
13191317

1320-
fun remove_order<BaseAsset, QuoteAsset>(
1318+
fun remove_order(
13211319
open_orders: &mut CritbitTree<TickLevel>,
13221320
usr_open_orders: &mut LinkedTable<u64, u64>,
13231321
tick_index: u64,
@@ -1353,7 +1351,7 @@ module deepbook::clob_v2 {
13531351
if (is_bid) { &mut pool.bids }
13541352
else { &mut pool.asks };
13551353
let (_, tick_index) = critbit::find_leaf(open_orders, order_price);
1356-
let order = remove_order<BaseAsset, QuoteAsset>(
1354+
let order = remove_order(
13571355
open_orders,
13581356
usr_open_order_ids,
13591357
tick_index,
@@ -1431,7 +1429,7 @@ module deepbook::clob_v2 {
14311429
assert!(tick_exists, EInvalidTickPrice);
14321430
tick_index = new_tick_index;
14331431
};
1434-
let order = remove_order<BaseAsset, QuoteAsset>(
1432+
let order = remove_order(
14351433
if (is_bid) { &mut pool.bids } else { &mut pool.asks },
14361434
usr_open_orders,
14371435
tick_index,
@@ -1510,7 +1508,7 @@ module deepbook::clob_v2 {
15101508
assert!(tick_exists, EInvalidTickPrice);
15111509
tick_index = new_tick_index;
15121510
};
1513-
let order = remove_order<BaseAsset, QuoteAsset>(open_orders, usr_open_orders, tick_index, order_id, owner);
1511+
let order = remove_order(open_orders, usr_open_orders, tick_index, order_id, owner);
15141512
assert!(order.expire_timestamp < now, EInvalidExpireTimestamp);
15151513
if (is_bid) {
15161514
let balance_locked = clob_math::mul(order.quantity, order.price);
@@ -1630,7 +1628,7 @@ module deepbook::clob_v2 {
16301628
price_low = critbit::find_closest_key(&pool.bids, price_low);
16311629
price_high = critbit::find_closest_key(&pool.bids, price_high);
16321630
while (price_low <= price_high) {
1633-
let depth = get_level2_book_status<BaseAsset, QuoteAsset>(
1631+
let depth = get_level2_book_status(
16341632
&pool.bids,
16351633
price_low,
16361634
clock::timestamp_ms(clock)
@@ -1672,7 +1670,7 @@ module deepbook::clob_v2 {
16721670
price_low = critbit::find_closest_key(&pool.asks, price_low);
16731671
price_high = critbit::find_closest_key(&pool.asks, price_high);
16741672
while (price_low <= price_high) {
1675-
let depth = get_level2_book_status<BaseAsset, QuoteAsset>(
1673+
let depth = get_level2_book_status(
16761674
&pool.asks,
16771675
price_low,
16781676
clock::timestamp_ms(clock)
@@ -1689,7 +1687,7 @@ module deepbook::clob_v2 {
16891687
}
16901688

16911689
/// internal func to retrive single depth of a tick price
1692-
fun get_level2_book_status<BaseAsset, QuoteAsset>(
1690+
fun get_level2_book_status(
16931691
open_orders: &CritbitTree<TickLevel>,
16941692
price: u64,
16951693
time_stamp: u64
@@ -2106,15 +2104,15 @@ module deepbook::clob_v2 {
21062104
): Order {
21072105
let order;
21082106
if (is_bid) {
2109-
order = remove_order<BaseAsset, QuoteAsset>(
2107+
order = remove_order(
21102108
&mut pool.bids,
21112109
borrow_mut(&mut pool.usr_open_orders, owner),
21122110
tick_index,
21132111
order_id_for_test(sequence_id, is_bid),
21142112
owner
21152113
)
21162114
} else {
2117-
order = remove_order<BaseAsset, QuoteAsset>(
2115+
order = remove_order(
21182116
&mut pool.asks,
21192117
borrow_mut(&mut pool.usr_open_orders, owner),
21202118
tick_index,
@@ -2670,7 +2668,7 @@ module deepbook::clob_v2 {
26702668
public fun check_balance_invariants_for_account<BaseAsset, QuoteAsset>(
26712669
account_cap: &AccountCap,
26722670
quote_custodian: &Custodian<QuoteAsset>,
2673-
base_custodian: &Custodian<BaseAsset>,
2671+
base_custodian: &Custodian<BaseAsset>,
26742672
pool: &Pool<BaseAsset, QuoteAsset>
26752673
) {
26762674
let account_cap_user = custodian::account_owner(account_cap);

crates/sui-framework/packages/deepbook/sources/critbit.move

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ module deepbook::critbit {
1111
friend deepbook::order_query;
1212

1313
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
14-
const ENotImplemented: u64 = 1;
1514
const EExceedCapacity: u64 = 2;
1615
const ETreeNotEmpty: u64 = 3;
1716
const EKeyAlreadyExist: u64 = 4;
1817
const ELeafNotExist: u64 = 5;
19-
const EAssertFalse: u64 = 6;
2018
const EIndexOutOfRange: u64 = 7;
2119
const ENullParent: u64 = 8;
22-
const ENullChild: u64 = 9;
2320
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
2421

2522

crates/sui-framework/packages/deepbook/sources/custodian.move

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module deepbook::custodian {
1111
friend deepbook::clob;
1212

1313
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
14+
#[test_only]
1415
const EUserBalanceDoesNotExist: u64 = 1;
1516
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
1617

@@ -147,6 +148,7 @@ module deepbook::custodian {
147148
table::borrow_mut(&mut custodian.account_balances, user)
148149
}
149150

151+
#[test_only]
150152
fun borrow_account_balance<T>(
151153
custodian: &Custodian<T>,
152154
user: ID,

crates/sui-framework/packages/deepbook/sources/custodian_v2.move

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module deepbook::custodian_v2 {
1111
friend deepbook::clob_v2;
1212

1313
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
14+
#[test_only]
1415
const EUserBalanceDoesNotExist: u64 = 1;
1516
const EAdminAccountCapRequired: u64 = 2;
1617
// <<<<<<<<<<<<<<<<<<<<<<<< Error codes <<<<<<<<<<<<<<<<<<<<<<<<
@@ -184,6 +185,7 @@ module deepbook::custodian_v2 {
184185
table::borrow_mut(&mut custodian.account_balances, owner)
185186
}
186187

188+
#[test_only]
187189
fun borrow_account_balance<T>(
188190
custodian: &Custodian<T>,
189191
owner: address,

crates/sui-framework/packages/deepbook/sources/order_query.move

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ module deepbook::order_query {
159159

160160
// if the order id is greater than max_id, we end the iteration for this tick level.
161161
if (option::is_some(&max_id) && key > option::destroy_some(max_id)) {
162-
break;
162+
break
163163
};
164164

165165
next_order_key = *linked_table::next(open_orders, key);
@@ -204,5 +204,3 @@ module deepbook::order_query {
204204
clob_v2::tick_level(order)
205205
}
206206
}
207-
208-

crates/sui-framework/packages/sui-framework/sources/address.move

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module sui::address {
1313
// The largest integer that can be represented with 32 bytes: 2^(8*32) - 1
1414
const MAX: u256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
1515

16+
#[allow(unused_const)]
1617
/// Error from `from_bytes` when it is supplied too many or too few bytes.
1718
const EAddressParseError: u64 = 0;
1819

0 commit comments

Comments
 (0)