Skip to content
Merged
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
38 changes: 18 additions & 20 deletions contracts/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,47 @@

[move]
version = 3
manifest_digest = "06BB9182CE131DFC0277880DBB6779C784DA52BA09DB1E0750169ED16A80D678"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
manifest_digest = "AE832443B65D117CD4F334CE369001B6C6285F8B7044CE77B78BF4048CD6B31C"
deps_digest = "F9B494B64F0615AED0E98FC12A85B85ECD2BC5185C22D30E7F67786BB52E507C"
dependencies = [
{ id = "Bridge", name = "Bridge" },
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
{ id = "SuiSystem", name = "SuiSystem" },
]

[[move.package]]
id = "Bridge"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", 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 = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", 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 = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-system" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", subdir = "crates/sui-framework/packages/sui-system" }

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

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

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x054acc66b4e75276f5c0adc18468170b9d46ccd83cfd00d148af82982a2c0fc6"
latest-published-id = "0x054acc66b4e75276f5c0adc18468170b9d46ccd83cfd00d148af82982a2c0fc6"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xb0575765166030556a6eafd3b1b970eba8183ff748860680245b9edd41c716e7"
latest-published-id = "0xc89f4edb8f4dafb97934dbfce11ac132c07759c3bdda6f31d09c7fdca3b80b76"
published-version = "7"
2 changes: 0 additions & 2 deletions contracts/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ published-at = "0xc89f4edb8f4dafb97934dbfce11ac132c07759c3bdda6f31d09c7fdca3b80b
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"]

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }
SuiSystem = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-system", rev = "framework/mainnet" }


# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
Expand Down
9 changes: 5 additions & 4 deletions contracts/tests/liquid_staking_tests.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(deprecated_usage)]
#[test_only]
module liquid_staking::liquid_staking_tests {
// uncomment this line to import the module
Expand All @@ -11,9 +12,9 @@ module liquid_staking::liquid_staking_tests {
use liquid_staking::fees::{Self};
use sui_system::governance_test_utils::{
advance_epoch_with_reward_amounts,
create_validators_with_stakes,
create_sui_system_state_for_testing,
};
use liquid_staking::test_utils::create_validators_with_stakes;

/* Constants */
const MIST_PER_SUI: u64 = 1_000_000_000;
Expand Down Expand Up @@ -55,7 +56,7 @@ module liquid_staking::liquid_staking_tests {

scenario.next_tx(@0x0);

let mut system_state = scenario.take_shared<SuiSystemState>();
let system_state = scenario.take_shared<SuiSystemState>();

let (admin_cap, lst_info) = create_lst<TEST>(
fees::new_builder(scenario.ctx())
Expand Down Expand Up @@ -125,7 +126,7 @@ module liquid_staking::liquid_staking_tests {

setup_sui_system(&mut scenario, vector[100, 100]);

let mut system_state = scenario.take_shared<SuiSystemState>();
let system_state = scenario.take_shared<SuiSystemState>();

let mut treasury_cap = coin::create_treasury_cap_for_testing(scenario.ctx());
let coins = treasury_cap.mint(1000 * MIST_PER_SUI, scenario.ctx());
Expand Down Expand Up @@ -537,7 +538,7 @@ module liquid_staking::liquid_staking_tests {

scenario.next_tx(@0x0);

let mut system_state = scenario.take_shared<SuiSystemState>();
let system_state = scenario.take_shared<SuiSystemState>();

let (admin_cap, mut lst_info) = create_lst<TEST>(
fees::new_builder(scenario.ctx())
Expand Down
12 changes: 4 additions & 8 deletions contracts/tests/storage_tests.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(deprecated_usage)]
#[test_only]
module liquid_staking::storage_tests {
/* Tests */
Expand All @@ -13,15 +14,12 @@ module liquid_staking::storage_tests {
use sui::balance::{Self};
use liquid_staking::storage::{new};
use sui::sui::SUI;
use std::macros::do;
use liquid_staking::test_utils::create_validators_with_stakes;
use sui_system::governance_test_utils::create_sui_system_state_for_testing;


#[test_only]
fun setup_sui_system(scenario: &mut Scenario, stakes: vector<u64>) {
use sui_system::governance_test_utils::{
create_validators_with_stakes,
create_sui_system_state_for_testing,
};

let validators = create_validators_with_stakes(stakes, scenario.ctx());
create_sui_system_state_for_testing(validators, 0, 0, scenario.ctx());

Expand Down Expand Up @@ -199,8 +197,6 @@ module liquid_staking::storage_tests {
let mut system_state = scenario.take_shared<SuiSystemState>();
storage.refresh(&mut system_state, scenario.ctx());

std::debug::print(&storage);

assert!(storage.validators().length() == 1, 0);
assert!(storage.total_sui_supply() == 150 * MIST_PER_SUI, 0);
assert!(storage.validators()[0].total_sui_amount() == 150 * MIST_PER_SUI, 0);
Expand Down
24 changes: 24 additions & 0 deletions contracts/tests/test_utils.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[allow(deprecated_usage)]
#[test_only]
module liquid_staking::test_utils {
use sui::address;
use sui_system::governance_test_utils::{
create_validator_for_testing,
};
use sui_system::validator::{Validator};

/// Create a validator set with the given stake amounts
public fun create_validators_with_stakes(
stakes: vector<u64>,
ctx: &mut TxContext,
): vector<Validator> {
let mut i = 0;
let mut validators = vector[];
while (i < stakes.length()) {
let validator = create_validator_for_testing(address::from_u256(i as u256), stakes[i], ctx);
validators.push_back(validator);
i = i + 1
};
validators
}
}
8 changes: 2 additions & 6 deletions contracts/tests/weight_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module liquid_staking::weight_tests {
use sui::coin::{Self};
use sui::address;
use sui_system::governance_test_utils::{
create_validators_with_stakes,
create_sui_system_state_for_testing,
advance_epoch_with_reward_amounts,
};
Expand All @@ -16,6 +15,7 @@ module liquid_staking::weight_tests {
use liquid_staking::fees::{Self};
use liquid_staking::liquid_staking::{create_lst};
use liquid_staking::weight::{Self, WeightHook};
use liquid_staking::test_utils::create_validators_with_stakes;

public struct TEST has drop {}

Expand All @@ -39,6 +39,7 @@ module liquid_staking::weight_tests {
staked_sui
}

#[allow(deprecated_usage)]
#[test_only]
fun setup_sui_system(scenario: &mut Scenario, stakes: vector<u64>) {
let validators = create_validators_with_stakes(stakes, scenario.ctx());
Expand Down Expand Up @@ -83,8 +84,6 @@ module liquid_staking::weight_tests {

weight_hook.rebalance(&mut system_state, &mut lst_info, scenario.ctx());

std::debug::print(&lst_info);

assert!(lst_info.storage().validators().borrow(0).total_sui_amount() == 25 * MIST_PER_SUI, 0);
assert!(lst_info.storage().validators().borrow(1).total_sui_amount() == 75 * MIST_PER_SUI, 0);

Expand Down Expand Up @@ -170,16 +169,13 @@ module liquid_staking::weight_tests {

weight_hook.rebalance(&mut system_state, &mut lst_info, scenario.ctx());

std::debug::print(lst_info.storage().validators());

assert!(lst_info.storage().validators().borrow(0).total_sui_amount() == 25 * MIST_PER_SUI, 0);
assert!(lst_info.storage().validators().borrow(1).total_sui_amount() == 75 * MIST_PER_SUI, 0);

let lst_to_unstake = lst.split(10 * MIST_PER_SUI, scenario.ctx());
let mut custom_redeem_request = lst_info.custom_redeem_request(lst_to_unstake,&mut system_state, scenario.ctx());
weight_hook.handle_custom_redeem_request(&mut system_state, &mut lst_info, &mut custom_redeem_request, scenario.ctx());

// std::debug::print(lst_info.storage().validators());
assert!(lst_info.storage().validators().borrow(0).total_sui_amount() == 25 * MIST_PER_SUI - 2_500_000_000, 0);
assert!(lst_info.storage().validators().borrow(1).total_sui_amount() == 75 * MIST_PER_SUI - 7_500_000_000, 0);

Expand Down