Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stake: using tag v1.0.0 impl #429

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c169fc8
adds stake from tag v1.0.0
gangov Jan 27, 2025
9936644
deletes stake_rewards contract
gangov Jan 27, 2025
dc545a6
lints
gangov Jan 27, 2025
037b49f
brings back the TTL extension in storage of Stake
gangov Jan 27, 2025
81b3934
keys for admin
gangov Jan 27, 2025
fe10053
instance bump for every msg
gangov Jan 27, 2025
a2f8c23
extends the ttl in distribution
gangov Jan 27, 2025
915a048
assertion in test
gangov Jan 27, 2025
64a3082
assertions about auth in bond
gangov Jan 27, 2025
bd4cdf3
better math in stake
gangov Jan 28, 2025
d7a73ff
fixes .unwrap()
gangov Jan 28, 2025
b45597e
logs
gangov Jan 28, 2025
b89193f
more logs
gangov Jan 28, 2025
9c10207
adds missing Error
gangov Jan 28, 2025
bcedbc8
[no ci] test for stake upgrade
gangov Jan 29, 2025
8e0fb59
[no ci] adds old deprecated methods
gangov Jan 29, 2025
c9b14c4
wip
gangov Jan 29, 2025
8dac7b3
[no ci] wip
gangov Jan 30, 2025
dff85f7
solves the distribute rewards err
gangov Jan 30, 2025
e69a2af
[no ci] before migration
gangov Jan 30, 2025
f5640eb
[no ci]] adds deprecated methods for rewards query
gangov Jan 30, 2025
6d5a3cb
migration works and users are able to withdraw old rewards
gangov Jan 30, 2025
ec32a56
wip unbonding fails
gangov Jan 31, 2025
dc503f6
[no ci] new error
gangov Jan 31, 2025
83db94c
[no ci] wip
gangov Jan 31, 2025
fbeded9
Merge pull request #432 from Phoenix-Protocol-Group/430-test-for-migr…
gangov Jan 31, 2025
c4edfc7
new error
gangov Jan 31, 2025
21a19b0
wip - bond fails because of missing distribution
gangov Jan 31, 2025
0c39fb9
adds migration for the distributions
gangov Feb 3, 2025
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
21 changes: 21 additions & 0 deletions contracts/stake/src/contract.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,27 @@ impl Staking {

env.deployer().update_current_contract_wasm(new_wasm_hash);
}

#[allow(dead_code)]
pub fn migrate_distributions(env: Env) {
let distributions = get_distributions(&env);

distributions.iter().for_each(|distribution_addr| {
save_distribution(
&env,
&distribution_addr,
&Distribution {
shares_per_point: 1u128,
shares_leftover: 0u64,
distributed_total: 0u128,
withdrawable_total: 0u128,
max_bonus_bps: 0u64,
bonus_per_day_bps: 0u64,
},
);
save_reward_curve(&env, distribution_addr, &Curve::Constant(0));
})
}
}

// Function to remove a stake from the vector
Expand Down
22 changes: 19 additions & 3 deletions contracts/stake/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,12 @@ mod tests {
let new_stake_wasm = install_stake_wasm(&env);

old_stake_client.update(&new_stake_wasm);
//old_stake_client.update(&new_stake_wasm);

let latest_stake_client = latest_stake::Client::new(&env, &stake_addr);

// now we migrate the distributions
latest_stake_client.migrate_distributions();

// check the rewards again, this time with the old deprecated method
assert_eq!(
latest_stake_client.query_withdrawable_rewards_dep(&user_1),
Expand Down Expand Up @@ -450,15 +452,29 @@ mod tests {

lp_token_client.mint(&new_user, &10_000_000_000_000);

soroban_sdk::testutils::arbitrary::std::dbg!("BEFORE");
latest_stake_client.bond(&new_user, &10_000_000_000); // new_user also bonds 1,000 tokens
soroban_sdk::testutils::arbitrary::std::dbg!("AFTER");

// two months pass by
env.ledger()
.with_mut(|li| li.timestamp += 60 * DAY_AS_SECONDS);

// distribute and take the rewards
latest_stake_client.distribute_rewards();

assert_eq!(
latest_stake_client.query_withdrawable_rewards(&new_user),
latest_stake::WithdrawableRewardsResponse {
rewards: vec![
&env,
latest_stake::WithdrawableReward {
reward_address: reward_token_addr.clone(),
reward_amount: 5_000_000,
}
]
}
);

latest_stake_client.withdraw_rewards(&new_user);
assert_eq!(reward_token_client.balance(&new_user), 5_000_000);
}
}
Loading