Skip to content

Commit

Permalink
check uneconomic lock (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicGordon authored Oct 31, 2022
1 parent 87491b5 commit 8bc1e24
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/ref-ve/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ref-ve"
version = "0.2.2"
version = "0.2.3"
authors = ["Marco Sun <[email protected]>", "MagicGordon"]
edition = "2018"
publish = false
Expand Down
1 change: 1 addition & 0 deletions contracts/ref-ve/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl Account {
self.ve_lpt_amount += extra_x;
} else {
self.ve_lpt_amount = compute_ve_lpt_amount(config, self.lpt_amount + amount, duration_sec, lptoken_decimals);
require!(self.ve_lpt_amount > prev, E308_UNECONOMIC_LOCK);
}
self.unlock_timestamp = new_unlock_timestamp;
self.lpt_amount += amount;
Expand Down
1 change: 1 addition & 0 deletions contracts/ref-ve/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub const E304_CAUSE_PRE_UNLOCK: &str = "E304: would cause pre unlock";
pub const E305_STILL_IN_LOCK: &str = "E305: still in locking";
pub const E306_INVALID_LOCK_DURATION_LIMIT: &str = "E306: invalid lock duration limit";
pub const E307_INVALID_VOTING_DURATION_LIMIT: &str = "E307: invalid voting duration limit";
pub const E308_UNECONOMIC_LOCK: &str = "E308: uneconomic lock";

pub const E402_INVALID_START_TIME: &str = "E402: invalid start time";
pub const E404_PROPOSAL_NOT_EXIST: &str = "E404: proposal not exist";
Expand Down
2 changes: 1 addition & 1 deletion contracts/ref-ve/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use ref_ve::{
E002_NOT_ALLOWED,
E100_ACC_NOT_REGISTERED, E101_INSUFFICIENT_BALANCE, E102_INSUFFICIENT_STORAGE, E103_STILL_HAS_REWARD, E104_STILL_HAS_LPT,E106_STILL_HAS_LOVE_TOKEN,
E200_ALREADY_VOTED, E201_INVALID_VOTE, E203_INVALID_INCENTIVE_TOKEN, E204_VOTE_CAN_NOT_CANCEL, E205_NOT_VOTABLE, E206_NO_VOTED, E207_INVALID_INCENTIVE_KEY, E208_DESCRIPTION_TOO_LONG,
E301_INVALID_RATIO, E302_INVALID_DURATION, E305_STILL_IN_LOCK, E306_INVALID_LOCK_DURATION_LIMIT, E307_INVALID_VOTING_DURATION_LIMIT,
E301_INVALID_RATIO, E302_INVALID_DURATION, E305_STILL_IN_LOCK, E306_INVALID_LOCK_DURATION_LIMIT, E307_INVALID_VOTING_DURATION_LIMIT, E308_UNECONOMIC_LOCK,
E402_INVALID_START_TIME, E404_PROPOSAL_NOT_EXIST, E406_EXPIRED_PROPOSAL,
E503_FIRST_LOCK_TOO_FEW
};
Expand Down
2 changes: 1 addition & 1 deletion contracts/ref-ve/tests/test_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fn test_update(){
e.ve_contract.contract.get_config()
).unwrap_json_value());
e.upgrade_contract(&e.owner, ref_ve_wasm_bytes()).assert_success();
assert_eq!(e.get_metadata().version, "0.2.2".to_string());
assert_eq!(e.get_metadata().version, "0.2.3".to_string());
println!("{:?}", e.get_config());
}
3 changes: 3 additions & 0 deletions contracts/ref-ve/tests/test_token_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ fn test_lock_lpt(){
before.cur_lock_lpt = to_yocto("300").into();
assert_eq!(format!("{:?}", before), format!("{:?}", e.get_metadata()));
assert_eq!(to_yocto("100"), e.mft_balance_of(&users.alice, &lpt_id()));

e.near.borrow_runtime_mut().cur_block.block_timestamp += DEFAULT_MAX_LOCKING_DURATION_SEC as u64 * 10u64.pow(9);
assert_err!(e.lock_lpt(&users.alice, to_yocto("1"), DEFAULT_MIN_LOCKING_DURATION_SEC), E308_UNECONOMIC_LOCK);
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions releases/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

Version 0.2.3
1. check uneconomic lock

Version 0.2.2
1. update token icon
2. loveToken balance must be 0 when storage_unregister
Expand Down

0 comments on commit 8bc1e24

Please sign in to comment.