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

Add lockup period #49

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7288f7e
feat: managed reward_per_sec WIP
obaranni Feb 1, 2024
b8cb598
feat: mngd rps, tests recover WIP
obaranni Feb 1, 2024
a9baa40
feat: premature unstake are impossible
obaranni Feb 7, 2024
b0fa824
feat: emergency tests recover
obaranni Feb 7, 2024
e3b1fa4
feat: recover deposit reward test
obaranni Feb 7, 2024
d736808
feat: ghost epoch endtime shift. view funcs
obaranni Feb 7, 2024
bad26de
feat: get epoch view fun added
obaranni Feb 7, 2024
1c061ac
feat: check that rewards accumulating after ghost epoch
obaranni Feb 7, 2024
87f769c
feat: stake tests recovered
obaranni Feb 7, 2024
41e485c
feat: scripts tests recover
obaranni Feb 7, 2024
03ddd1a
feat: deposit rew on unfinished rew epoch
obaranni Feb 8, 2024
ff2754b
feat: repair new test
obaranni Feb 8, 2024
5c9e9da
feat: test deposit rew on finished at same sec epoch
obaranni Feb 8, 2024
adbdad9
feat: test deposit rew after a long time ago finished rew epoch
obaranni Feb 8, 2024
5d8eb15
feat: update_unobtainable_reward func
obaranni Feb 8, 2024
d3fb3fb
feat: unobt fun comment
obaranni Feb 9, 2024
232851a
feat: test where epoch fully rewritten with another
obaranni Feb 9, 2024
602fdef
docs: func comments
obaranni Feb 19, 2024
5f42e33
feat: few users with reward changing test
obaranni Feb 19, 2024
ffa29bd
feat: no users then few users test
obaranni Feb 20, 2024
ab7aab3
feat: no pool endtime (tests correction)
obaranni Feb 20, 2024
b0c4e9f
feat: is_ghost field removed from pool
obaranni Feb 20, 2024
23c5e42
feat: whitelist check on stake
obaranni Feb 22, 2024
648e907
feat: remove & add into whitelist scripts
obaranni Feb 22, 2024
cef0448
feat: current_epoch field removed
obaranni Mar 19, 2024
58a59c5
fix: ghost epoch endtime
obaranni Mar 19, 2024
f3255dd
Merge pull request #1 from pontem-network/ability-to-change-reward
obaranni Mar 27, 2024
c1f2b24
feat: add lockup period for stake
Apr 1, 2024
f1d8399
feat: add tests for lockup period
Apr 1, 2024
723b063
feat: custom lockup tests
obaranni Apr 1, 2024
7e5b5f6
fix: ls tests
obaranni Apr 1, 2024
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
2 changes: 1 addition & 1 deletion Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ harvest = "0xb247ddeee87e848315caf9a33b8e4c71ac53db888cb88143d62d2370cca0ead2"
stake_emergency_admin = "0x63e39817ec41fad2e8d0713cc906a5f792e4cd2cf704f8b5fab6b2961281fa11"

# Test addresses.
treasury = "0x13"
treasury = "0x41"
alice = "0x10"
bob = "0x11"
collection_owner = "0x12"
Expand Down
2 changes: 1 addition & 1 deletion liquidswap_staking_tests/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ local = ".."

[dependencies.Liquidswap]
git = 'https://github.com/pontem-network/liquidswap.git'
rev = 'v0.4.4'
rev = 'v0.4.5'
4 changes: 2 additions & 2 deletions liquidswap_staking_tests/tests/lp_staking_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module lp_staking_admin::lp_staking_tests {
let aptos_coins = coin::withdraw<AptosCoin>(&harvest_acc, 50000000000);
let duration = 5000000;
stake::register_pool<LP<BTC, USDT, Uncorrelated>, AptosCoin>(&harvest_acc,
aptos_coins, duration, option::none());
aptos_coins, duration, WEEK_IN_SECONDS, option::none(), vector[]);

// stake 999.999 LP from alice
stake::stake<LP<BTC, USDT, Uncorrelated>, AptosCoin>(&alice_acc, @harvest, lp_coins);
Expand Down Expand Up @@ -106,7 +106,7 @@ module lp_staking_admin::lp_staking_tests {
coin::deposit<LP<BTC, USDT, Uncorrelated>>(@alice, coins);

// 0.00000001 APT lost during calculations
let (reward_per_sec, _, _, _, _) = stake::get_pool_info<LP<BTC, USDT, Uncorrelated>, AptosCoin>(@harvest);
let (reward_per_sec, _, _, _, _, _) = stake::get_pool_info<LP<BTC, USDT, Uncorrelated>, AptosCoin>(@harvest);
let total_rewards = WEEK_IN_SECONDS * reward_per_sec;
let losed_rewards = total_rewards - coin::balance<AptosCoin>(@alice);

Expand Down
40 changes: 34 additions & 6 deletions sources/scripts.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,41 @@ module harvest::scripts {
/// * `pool_owner` - account which will be used as a pool storage.
/// * `reward_amount` - reward amount in R coins.
/// * `duration` - pool life duration, can be increased by depositing more rewards.
public entry fun register_pool<S, R>(pool_owner: &signer, reward_amount: u64, duration: u64) {
/// * `lockup_period` - blocking withdrawal of stake in seconds.
/// * `whitelist` - list of accounts allowed to stake. All are allowed if empty.
public entry fun register_pool<S, R>(
pool_owner: &signer,
reward_amount: u64,
duration: u64,
lockup_period: u64,
whitelist: vector<address>
) {
let rewards = coin::withdraw<R>(pool_owner, reward_amount);
stake::register_pool<S, R>(pool_owner, rewards, duration, option::none());
stake::register_pool<S, R>(pool_owner, rewards, duration, lockup_period, option::none(), whitelist);
}

/// Register new staking pool with staking coin `S` and reward coin `R` with nft boost.
/// * `pool_owner` - account which will be used as a pool storage.
/// * `reward_amount` - reward amount in R coins.
/// * `duration` - pool life duration, can be increased by depositing more rewards.
/// * `lockup_period` - blocking withdrawal of stake in seconds.
/// * `collection_owner` - address of nft collection creator.
/// * `collection_name` - nft collection name.
/// * `boost_percent` - percentage of increasing user stake "power" after nft stake.
/// * `whitelist` - list of accounts allowed to stake. All are allowed if empty.
public entry fun register_pool_with_collection<S, R>(
pool_owner: &signer,
reward_amount: u64,
duration: u64,
lockup_period: u64,
collection_owner: address,
collection_name: String,
boost_percent: u128
boost_percent: u128,
whitelist: vector<address>
) {
let rewards = coin::withdraw<R>(pool_owner, reward_amount);
let boost_config = stake::create_boost_config(collection_owner, collection_name, boost_percent);
stake::register_pool<S, R>(pool_owner, rewards, duration, option::some(boost_config));
stake::register_pool<S, R>(pool_owner, rewards, duration, lockup_period, option::some(boost_config), whitelist);
}

/// Stake an `amount` of `Coin<S>` to the pool of stake coin `S` and reward coin `R` on the address `pool_addr`.
Expand Down Expand Up @@ -115,9 +127,10 @@ module harvest::scripts {
/// * `depositor` - account with the `R` reward coins in the balance.
/// * `pool_addr` - address of the pool.
/// * `reward_amount` - amount of the reward coin `R` to deposit.
public entry fun deposit_reward_coins<S, R>(depositor: &signer, pool_addr: address, reward_amount: u64) {
/// * `duration` - pool life duration.
public entry fun deposit_reward_coins<S, R>(depositor: &signer, pool_addr: address, reward_amount: u64, duration: u64) {
let reward_coins = coin::withdraw<R>(depositor, reward_amount);
stake::deposit_reward_coins<S, R>(depositor, pool_addr, reward_coins);
stake::deposit_reward_coins<S, R>(depositor, pool_addr, reward_coins, duration);
}

/// Boosts user stake with nft.
Expand Down Expand Up @@ -149,6 +162,21 @@ module harvest::scripts {
token::deposit_token(user, nft);
}

/// Add user into whitelist.
/// * `pool_owner` - pool creator account.
/// * `users` - list of users to whitelist.
public entry fun add_into_whitelist<S, R>(pool_owner: &signer, users: vector<address>) {
stake::add_into_whitelist<S, R>(pool_owner, users);
}

/// Remove user from whitelist.
/// * `owner` - pool creator account.
/// * `user` - address of user to remove from whitelist.
/// Note: If no users left in whitelist it become deactivated.
public entry fun remove_from_whitelist<S, R>(pool_owner: &signer, user: address) {
stake::remove_from_whitelist<S, R>(pool_owner, user);
}

/// Enable "emergency state" for a pool on a `pool_addr` address. This state cannot be disabled
/// and removes all operations except for `emergency_unstake()`, which unstakes all the coins for a user.
/// * `admin` - current emergency admin account.
Expand Down
Loading
Loading