Skip to content

Commit 220df36

Browse files
tzakiandamirkaTimothy Zakian
authored
[cherry-pick] fungible token changes (#22069)
## Description Cherry-pick #22066 into `main` ## Test plan CI --------- Co-authored-by: Damir Shamanaev <damir@mystenlabs.com> Co-authored-by: Timothy Zakian <timothyzakian@mac.lan>
1 parent 91c76d2 commit 220df36

File tree

7 files changed

+81
-26
lines changed

7 files changed

+81
-26
lines changed

crates/sui-framework-snapshot/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@
18001800
]
18011801
},
18021802
"82": {
1803-
"git_revision": "e54b798790ed",
1803+
"git_revision": "3802482bd4e3",
18041804
"packages": [
18051805
{
18061806
"name": "MoveStdlib",

crates/sui-framework/docs/sui_system/staking_pool.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,11 @@ StakedSui objects cannot be split to below this amount.
506506

507507

508508

509-
<a name="sui_system_staking_pool_EPoolNotPreactive"></a>
509+
<a name="sui_system_staking_pool_EPoolPreactiveOrInactive"></a>
510510

511511

512512

513-
<pre><code><b>const</b> <a href="../sui_system/staking_pool.md#sui_system_staking_pool_EPoolNotPreactive">EPoolNotPreactive</a>: u64 = 15;
513+
<pre><code><b>const</b> <a href="../sui_system/staking_pool.md#sui_system_staking_pool_EPoolPreactiveOrInactive">EPoolPreactiveOrInactive</a>: u64 = 15;
514514
</code></pre>
515515

516516

@@ -678,8 +678,8 @@ A proportional amount of pool token withdraw is recorded and processed at epoch
678678
pool.pending_total_sui_withdraw = pool.pending_total_sui_withdraw + total_sui_withdraw_amount;
679679
pool.pending_pool_token_withdraw =
680680
pool.pending_pool_token_withdraw + pool_token_withdraw_amount;
681-
// If the pool is inactive, we immediately process the withdrawal.
682-
<b>if</b> (pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_is_inactive">is_inactive</a>()) pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_process_pending_stake_withdraw">process_pending_stake_withdraw</a>();
681+
// If the pool is inactive or preactive, we immediately process the withdrawal.
682+
<b>if</b> (pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_is_inactive">is_inactive</a>() || pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_is_preactive">is_preactive</a>()) pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_process_pending_stake_withdraw">process_pending_stake_withdraw</a>();
683683
// TODO: implement withdraw bonding period here.
684684
principal_withdraw.join(rewards_withdraw);
685685
principal_withdraw
@@ -819,6 +819,7 @@ Convert the given staked SUI to an FungibleStakedSui object
819819
<b>let</b> <a href="../sui_system/staking_pool.md#sui_system_staking_pool_StakedSui">StakedSui</a> { id, <a href="../sui_system/staking_pool.md#sui_system_staking_pool_pool_id">pool_id</a>, <a href="../sui_system/staking_pool.md#sui_system_staking_pool_stake_activation_epoch">stake_activation_epoch</a>, principal } = staked_sui;
820820
<b>assert</b>!(<a href="../sui_system/staking_pool.md#sui_system_staking_pool_pool_id">pool_id</a> == object::id(pool), <a href="../sui_system/staking_pool.md#sui_system_staking_pool_EWrongPool">EWrongPool</a>);
821821
<b>assert</b>!(ctx.epoch() &gt;= <a href="../sui_system/staking_pool.md#sui_system_staking_pool_stake_activation_epoch">stake_activation_epoch</a>, <a href="../sui_system/staking_pool.md#sui_system_staking_pool_ECannotMintFungibleStakedSuiYet">ECannotMintFungibleStakedSuiYet</a>);
822+
<b>assert</b>!(!pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_is_preactive">is_preactive</a>() && !pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_is_inactive">is_inactive</a>(), <a href="../sui_system/staking_pool.md#sui_system_staking_pool_EPoolPreactiveOrInactive">EPoolPreactiveOrInactive</a>);
822823
id.delete();
823824
<b>let</b> exchange_rate_at_staking_epoch = pool.<a href="../sui_system/staking_pool.md#sui_system_staking_pool_pool_token_exchange_rate_at_epoch">pool_token_exchange_rate_at_epoch</a>(
824825
<a href="../sui_system/staking_pool.md#sui_system_staking_pool_stake_activation_epoch">stake_activation_epoch</a>,

crates/sui-framework/packages/sui-system/sources/staking_pool.move

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const EDeactivationOfInactivePool: u64 = 11;
2727
const EIncompatibleStakedSui: u64 = 12;
2828
const EWithdrawalInSameEpoch: u64 = 13;
2929
const EPoolAlreadyActive: u64 = 14;
30-
const EPoolNotPreactive: u64 = 15;
30+
const EPoolPreactiveOrInactive: u64 = 15;
3131
const EActivationOfInactivePool: u64 = 16;
3232
const EDelegationOfZeroSui: u64 = 17;
3333
const EStakedSuiBelowThreshold: u64 = 18;
@@ -179,8 +179,8 @@ public(package) fun request_withdraw_stake(
179179
pool.pending_pool_token_withdraw =
180180
pool.pending_pool_token_withdraw + pool_token_withdraw_amount;
181181

182-
// If the pool is inactive, we immediately process the withdrawal.
183-
if (pool.is_inactive()) pool.process_pending_stake_withdraw();
182+
// If the pool is inactive or preactive, we immediately process the withdrawal.
183+
if (pool.is_inactive() || pool.is_preactive()) pool.process_pending_stake_withdraw();
184184

185185
// TODO: implement withdraw bonding period here.
186186
principal_withdraw.join(rewards_withdraw);
@@ -275,6 +275,7 @@ public(package) fun convert_to_fungible_staked_sui(
275275

276276
assert!(pool_id == object::id(pool), EWrongPool);
277277
assert!(ctx.epoch() >= stake_activation_epoch, ECannotMintFungibleStakedSuiYet);
278+
assert!(!pool.is_preactive() && !pool.is_inactive(), EPoolPreactiveOrInactive);
278279

279280
id.delete();
280281

crates/sui-framework/packages/sui-system/tests/staking_pool.move

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fun test_join_fungible_staked_sui_happy() {
3434
}
3535

3636
#[test]
37-
#[expected_failure(abort_code = 1, location = sui_system::staking_pool)]
37+
#[expected_failure(abort_code = staking_pool::EWrongPool)]
3838
fun test_join_fungible_staked_sui_fail() {
3939
let mut scenario = test_scenario::begin(@0x0);
4040
let staking_pool_1 = staking_pool::new(scenario.ctx());
@@ -81,7 +81,7 @@ fun test_split_fungible_staked_sui_happy() {
8181
}
8282

8383
#[test]
84-
#[expected_failure(abort_code = 0, location = sui_system::staking_pool)]
84+
#[expected_failure(abort_code = staking_pool::EInsufficientPoolTokenBalance)]
8585
fun test_split_fungible_staked_sui_fail_too_much() {
8686
let mut scenario = test_scenario::begin(@0x0);
8787
let staking_pool = staking_pool::new(scenario.ctx());
@@ -101,7 +101,7 @@ fun test_split_fungible_staked_sui_fail_too_much() {
101101
}
102102

103103
#[test]
104-
#[expected_failure(abort_code = 19, location = sui_system::staking_pool)]
104+
#[expected_failure(abort_code = staking_pool::ECannotMintFungibleStakedSuiYet)]
105105
fun test_convert_to_fungible_staked_sui_fail_too_early() {
106106
let mut scenario = test_scenario::begin(@0x0);
107107
let mut staking_pool = staking_pool::new(scenario.ctx());
@@ -124,7 +124,60 @@ fun test_convert_to_fungible_staked_sui_fail_too_early() {
124124
}
125125

126126
#[test]
127-
#[expected_failure(abort_code = 1, location = sui_system::staking_pool)]
127+
#[expected_failure(abort_code = staking_pool::EPoolPreactiveOrInactive)]
128+
fun test_convert_to_fungible_staked_sui_fail_too_early_preactive() {
129+
let mut scenario = test_scenario::begin(@0x0);
130+
let mut staking_pool = staking_pool::new(scenario.ctx());
131+
132+
let sui = balance::create_for_testing(1_000_000_000);
133+
let activation_epoch = scenario.ctx().epoch() + 1;
134+
let staked_sui = staking_pool.request_add_stake(
135+
sui,
136+
activation_epoch,
137+
scenario.ctx(),
138+
);
139+
140+
scenario.skip_to_epoch(activation_epoch);
141+
let fungible_staked_sui = staking_pool.convert_to_fungible_staked_sui(
142+
staked_sui,
143+
scenario.ctx(),
144+
);
145+
146+
destroy(staking_pool);
147+
destroy(fungible_staked_sui);
148+
149+
scenario.end();
150+
}
151+
152+
#[test]
153+
#[expected_failure(abort_code = staking_pool::EPoolPreactiveOrInactive)]
154+
fun test_convert_to_fungible_staked_sui_fail_too_early_inactive() {
155+
let mut scenario = test_scenario::begin(@0x0);
156+
let mut staking_pool = staking_pool::new(scenario.ctx());
157+
158+
let sui = balance::create_for_testing(1_000_000_000);
159+
let activation_epoch = scenario.ctx().epoch() + 1;
160+
let staked_sui = staking_pool.request_add_stake(
161+
sui,
162+
activation_epoch,
163+
scenario.ctx(),
164+
);
165+
166+
scenario.skip_to_epoch(activation_epoch);
167+
staking_pool.deactivate_staking_pool(0);
168+
let fungible_staked_sui = staking_pool.convert_to_fungible_staked_sui(
169+
staked_sui,
170+
scenario.ctx(),
171+
);
172+
173+
destroy(staking_pool);
174+
destroy(fungible_staked_sui);
175+
176+
scenario.end();
177+
}
178+
179+
#[test]
180+
#[expected_failure(abort_code = staking_pool::EWrongPool)]
128181
fun test_convert_to_fungible_staked_sui_fail_wrong_pool() {
129182
let mut scenario = test_scenario::begin(@0x0);
130183
let mut staking_pool_1 = staking_pool::new(scenario.ctx());
54 Bytes
Binary file not shown.

crates/sui-swarm-config/tests/snapshots/snapshot_tests__populated_genesis_snapshot_matches-2.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -240,56 +240,56 @@ validators:
240240
next_epoch_worker_address: ~
241241
extra_fields:
242242
id:
243-
id: "0xd8bca734d53435dd44f92c90da348f4d135745b16b6da30c3a3d854077117abb"
243+
id: "0x172f267734d9bd1d6935ba2a99c6cec120df43c7019ca1cabf716a392951d225"
244244
size: 0
245245
voting_power: 10000
246-
operation_cap_id: "0xe8d5d8756d88ff17d9370d22a23d6bf6548e4a632e0325fdf7eb07db4493cf48"
246+
operation_cap_id: "0x949cd447b809ff5c75851342160be4fedd0beebb442d0814160db82a314dc690"
247247
gas_price: 1000
248248
staking_pool:
249-
id: "0xc541465e5bbd531bd551267d15f410d9c7f67523da3899a312d9a230f9ce2157"
249+
id: "0xa8ae79305b5e56c4fc64beb1b370f48659a198289878c4c04b4079d5d13cd251"
250250
activation_epoch: 0
251251
deactivation_epoch: ~
252252
sui_balance: 20000000000000000
253253
rewards_pool:
254254
value: 0
255255
pool_token_balance: 20000000000000000
256256
exchange_rates:
257-
id: "0x1f83938549c75b679a91208d1a0a43e9e3e2b30ff797451c106d446a8056a8ca"
257+
id: "0x83cbd8c2bdfe887d62661540fa6f908ccee72f4781c5fd84c0016b1adad61679"
258258
size: 1
259259
pending_stake: 0
260260
pending_total_sui_withdraw: 0
261261
pending_pool_token_withdraw: 0
262262
extra_fields:
263263
id:
264-
id: "0x3d9f9dac2db050e6b9942169161356814396ef08a651efed1a360960e08da157"
264+
id: "0x50b7a96c181be8108786f94f2f8b62fffd0870eb759f10eb31a52844a8ea9b15"
265265
size: 0
266266
commission_rate: 200
267267
next_epoch_stake: 20000000000000000
268268
next_epoch_gas_price: 1000
269269
next_epoch_commission_rate: 200
270270
extra_fields:
271271
id:
272-
id: "0x858f722d14c682362ce3572c4ec99734ec986b18b5066ee9adf78a54bd03ad74"
272+
id: "0xe1801ac1d28e6c8de7158834f922abe887ef5ae328d563a240e3f1d0c2c5333e"
273273
size: 0
274274
pending_active_validators:
275275
contents:
276-
id: "0x24c82dcace93b55d2ea37a2628ea929ca69a755a408dd3cc6ef3ca18aeec694a"
276+
id: "0xb7467b4c9ceac494ccba440c64f6d68fc4ddb4d514358462fa8102e094450d2d"
277277
size: 0
278278
pending_removals: []
279279
staking_pool_mappings:
280-
id: "0xf58f7119eb4725dd22cab03fafeb88d3b6e6a1a186154224d6775cd2631f5f81"
280+
id: "0xbbef3d8db5372ea32064877faf2d0cbfce15c76076e92626565e8bfe6e9a1467"
281281
size: 1
282282
inactive_validators:
283-
id: "0x6177d6349a93c1fc9f22c228d387888c187aa66f9f790dff358c54fab8e73230"
283+
id: "0x4b2d06e955508027c8a027c432b849b3497225a6e3a8d4f4d02aa55a03f390f8"
284284
size: 0
285285
validator_candidates:
286-
id: "0xd6166375b58f472ec12c3753ac6a8450a146ad6e3ea5f4ca8594281d512bb924"
286+
id: "0x82823e496516ba598a7c8b0d66931247c09c5bd1ddade90bfc92353f8fe652a1"
287287
size: 0
288288
at_risk_validators:
289289
contents: []
290290
extra_fields:
291291
id:
292-
id: "0x96d17f1b4d80841f557ae840dd5a51c5af69de67998f1d62db4edc46f6f5061c"
292+
id: "0x8561359531aff3bd1266510b4e2217eda05298551598cf8ab38d603435dddbf5"
293293
size: 0
294294
storage_fund:
295295
total_object_storage_rebates:
@@ -306,7 +306,7 @@ parameters:
306306
validator_low_stake_grace_period: 7
307307
extra_fields:
308308
id:
309-
id: "0xeebc4a1a6aedc4fba7cca5fbaa3e5ad562a48a98c474356cac3ad4ca7a4f548d"
309+
id: "0x0ee19a1b262a3433440d8a526e78f5e1010c6f45d14ef4ada9ca248bdfb565a8"
310310
size: 0
311311
reference_gas_price: 1000
312312
validator_report_records:
@@ -320,7 +320,7 @@ stake_subsidy:
320320
stake_subsidy_decrease_rate: 1000
321321
extra_fields:
322322
id:
323-
id: "0xb24081d3c1a29cfe898bc52c3f6ec351bac697e7ae60b49423ba779597a54e3d"
323+
id: "0x3d229ed7f408f248ce0448da2ce3cad6ec0a68f4fbeadcb8c167e11b2e86e720"
324324
size: 0
325325
safe_mode: false
326326
safe_mode_storage_rewards:
@@ -332,5 +332,5 @@ safe_mode_non_refundable_storage_fee: 0
332332
epoch_start_timestamp_ms: 10
333333
extra_fields:
334334
id:
335-
id: "0xc27f56ef9549b0347c9d2550d0bb723624bfa7eef5ecf08493e03674e16763d3"
335+
id: "0x067bd60ade98bdaf6d5085c8a73ee75434fac08b25cd32dea7442a6f34a93b24"
336336
size: 0

0 commit comments

Comments
 (0)