diff --git a/Cargo.lock b/Cargo.lock index caa7b27..90255f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,7 +105,7 @@ checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "appchain-anchor" -version = "2.3.0" +version = "2.3.1" dependencies = [ "beefy-light-client", "ed25519-dalek", @@ -118,7 +118,7 @@ dependencies = [ [[package]] name = "appchain-anchor-wrapper" -version = "2.3.0" +version = "2.3.1" dependencies = [ "anyhow", "appchain-anchor", @@ -2179,8 +2179,8 @@ dependencies = [ [[package]] name = "octopus-council" -version = "0.2.0" -source = "git+https://github.com/octopus-network/octopus-dao?branch=v0.2.0#dd437807ae903d8ba8afdf5b9b7c945c8fab4212" +version = "0.3.0" +source = "git+https://github.com/octopus-network/octopus-dao?branch=main#71bb8551d95c5af2ea9ddcff39693d7999ab0e76" dependencies = [ "near-contract-standards", "near-sdk", diff --git a/Cargo.toml b/Cargo.toml index 68ef193..563ac26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "appchain-anchor-wrapper" -version = "2.3.0" +version = "2.3.1" authors = ["Octopus Network"] edition = "2021" @@ -24,7 +24,7 @@ mock-appchain-registry = { path = "./mock-appchain-registry" } mock-oct-token = { path = "./mock-oct-token" } wrapped-appchain-token = { git = "https://github.com/octopus-network/wrapped-appchain-token.git", branch = "v2.0.0" } wrapped-appchain-nft = { git = "https://github.com/octopus-network/wrapped-appchain-nft.git", branch = "main" } -octopus-council = { git = "https://github.com/octopus-network/octopus-dao", branch = "v0.2.0" } +octopus-council = { git = "https://github.com/octopus-network/octopus-dao", branch = "main" } tokio = { version = "1.14", features = ["full"] } workspaces = "0.4" diff --git a/appchain-anchor/Cargo.toml b/appchain-anchor/Cargo.toml index 1f0f82e..94644f4 100644 --- a/appchain-anchor/Cargo.toml +++ b/appchain-anchor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "appchain-anchor" -version = "2.3.0" +version = "2.3.1" authors = ["Octopus Network"] edition = "2021" diff --git a/appchain-anchor/src/lib.rs b/appchain-anchor/src/lib.rs index b71345b..9f934af 100644 --- a/appchain-anchor/src/lib.rs +++ b/appchain-anchor/src/lib.rs @@ -53,7 +53,7 @@ use validator_set::ValidatorSetViewer; register_custom_getrandom!(get_random_in_near); /// Version of this contract (the same as in Cargo.toml) -const ANCHOR_VERSION: &str = "v2.3.0"; +const ANCHOR_VERSION: &str = "v2.3.1"; /// Constants for gas. const T_GAS_FOR_FT_TRANSFER: u64 = 10; const T_GAS_FOR_BURN_FUNGIBLE_TOKEN: u64 = 10; @@ -62,7 +62,7 @@ const T_GAS_FOR_NFT_TRANSFER: u64 = 10; const T_GAS_FOR_MINT_NFT: u64 = 10; const T_GAS_FOR_RESOLVER_FUNCTION: u64 = 10; const T_GAS_FOR_SYNC_STATE_TO_REGISTRY: u64 = 10; -const T_GAS_CAP_FOR_MULTI_TXS_PROCESSING: u64 = 150; +const T_GAS_CAP_FOR_MULTI_TXS_PROCESSING: u64 = 130; const T_GAS_CAP_FOR_PROCESSING_APPCHAIN_MESSAGES: u64 = 240; const T_GAS_FOR_NFT_CONTRACT_INITIALIZATION: u64 = 50; const T_GAS_FOR_REGISTER_VALIDATOR: u64 = 100; diff --git a/appchain-anchor/src/user_actions/staking.rs b/appchain-anchor/src/user_actions/staking.rs index f8feee5..6af9b15 100644 --- a/appchain-anchor/src/user_actions/staking.rs +++ b/appchain-anchor/src/user_actions/staking.rs @@ -209,6 +209,10 @@ impl AppchainAnchor { serde_json::to_string(&self.appchain_state).unwrap() ), }; + assert!( + !delegator_id.eq(&validator_id), + "You can not delegate to yourself." + ); let mut next_validator_set = self.next_validator_set.get().unwrap(); self.assert_validator_id(&validator_id, &next_validator_set); assert!( @@ -688,9 +692,27 @@ impl StakingManager for AppchainAnchor { }; let mut next_validator_set = self.next_validator_set.get().unwrap(); let delegator_id = env::predecessor_account_id(); + assert!( + !delegator_id.eq(&new_validator_id), + "You can not delegate to yourself." + ); self.assert_delegator_id(&delegator_id, &old_validator_id, &next_validator_set); self.assert_validator_id(&new_validator_id, &next_validator_set); // + let delegator = next_validator_set + .get_delegator(&delegator_id, &old_validator_id) + .unwrap(); + let new_validator = next_validator_set.get_validator(&new_validator_id).unwrap(); + assert!( + new_validator.can_be_delegated_to, + "Validator '{}' cannot be delegated to.", + &new_validator_id + ); + self.assert_validator_stake_is_valid( + new_validator.deposit_amount, + Some(new_validator.total_stake + delegator.deposit_amount), + ); + // let staking_history = self.record_staking_fact(StakingFact::DelegatedValidatorChanged { delegator_id, old_validator_id, diff --git a/appchain-anchor/src/validator_set/mod.rs b/appchain-anchor/src/validator_set/mod.rs index 61c5669..e0b9761 100644 --- a/appchain-anchor/src/validator_set/mod.rs +++ b/appchain-anchor/src/validator_set/mod.rs @@ -372,19 +372,26 @@ impl ValidatorSet { new_validator_id, } => { // - let delegator = self + let old_delegator = self .delegators .remove(&(delegator_id.clone(), old_validator_id.clone())) .unwrap(); + let new_delegator = Delegator { + delegator_id: delegator_id.clone(), + validator_id: new_validator_id.clone(), + registered_block_height: env::block_height(), + registered_timestamp: env::block_timestamp(), + deposit_amount: match self + .delegators + .get(&(delegator_id.clone(), new_validator_id.clone())) + { + Some(delegator) => old_delegator.deposit_amount + delegator.deposit_amount, + None => old_delegator.deposit_amount, + }, + }; self.delegators.insert( &(delegator_id.clone(), new_validator_id.clone()), - &Delegator { - delegator_id: delegator_id.clone(), - validator_id: new_validator_id.clone(), - registered_block_height: env::block_height(), - registered_timestamp: env::block_timestamp(), - deposit_amount: delegator.deposit_amount, - }, + &new_delegator, ); // let mut delegator_id_set = self @@ -431,6 +438,13 @@ impl ValidatorSet { validator_id_set.insert(new_validator_id); self.delegator_id_to_validator_id_set .insert(delegator_id, &validator_id_set); + // + let mut old_validator = self.validators.get(&old_validator_id).unwrap(); + old_validator.total_stake -= old_delegator.deposit_amount; + self.validators.insert(&old_validator_id, &old_validator); + let mut new_validator = self.validators.get(&new_validator_id).unwrap(); + new_validator.total_stake += old_delegator.deposit_amount; + self.validators.insert(&new_validator_id, &new_validator); } } }