Skip to content

Commit 9c58dca

Browse files
authored
Merge pull request #27 from octopus-network/v2.4.0
Upgrade to v2.4.0
2 parents 7ee325d + 10e3fff commit 9c58dca

File tree

18 files changed

+275
-98
lines changed

18 files changed

+275
-98
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "appchain-anchor-wrapper"
3-
version = "2.3.1"
3+
version = "2.4.0"
44
authors = ["Octopus Network"]
55
edition = "2021"
66

@@ -24,7 +24,7 @@ mock-appchain-registry = { path = "./mock-appchain-registry" }
2424
mock-oct-token = { path = "./mock-oct-token" }
2525
wrapped-appchain-token = { git = "https://github.com/octopus-network/wrapped-appchain-token.git", branch = "v2.0.0" }
2626
wrapped-appchain-nft = { git = "https://github.com/octopus-network/wrapped-appchain-nft.git", branch = "main" }
27-
octopus-council = { git = "https://github.com/octopus-network/octopus-dao", branch = "main" }
27+
council-keeper = { git = "https://github.com/octopus-network/octopus-dao", branch = "main" }
2828
tokio = { version = "1.14", features = ["full"] }
2929
workspaces = "0.4"
3030

appchain-anchor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "appchain-anchor"
3-
version = "2.3.1"
3+
version = "2.4.0"
44
authors = ["Octopus Network"]
55
edition = "2021"
66

appchain-anchor/src/interfaces.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub trait AnchorViewer {
159159
}
160160

161161
pub trait AppchainLifecycleManager {
162-
/// Verify and change the state of corresponding appchain to `booting`.
163-
fn go_booting(&mut self);
162+
/// Generate the initial validator set for the appchain.
163+
fn generate_initial_validator_set(&mut self);
164164
/// Verify and change the state of corresponding appchain to `active`.
165165
fn go_live(&mut self);
166166
/// Initialize the beefy light client
@@ -276,6 +276,8 @@ pub trait ProtocolSettingsManager {
276276
fn change_validator_commission_percent(&mut self, value: u16);
277277
///
278278
fn change_maximum_allowed_unprofitable_era_count(&mut self, value: u16);
279+
///
280+
fn change_subaccount_for_council_keeper_contract(&mut self, subaccount_name: String);
279281
}
280282

281283
pub trait AppchainSettingsManager {

appchain-anchor/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use validator_set::ValidatorSetViewer;
5353
register_custom_getrandom!(get_random_in_near);
5454

5555
/// Version of this contract (the same as in Cargo.toml)
56-
const ANCHOR_VERSION: &str = "v2.3.1";
56+
const ANCHOR_VERSION: &str = "v2.4.0";
5757
/// Constants for gas.
5858
const T_GAS_FOR_FT_TRANSFER: u64 = 10;
5959
const T_GAS_FOR_BURN_FUNGIBLE_TOKEN: u64 = 10;
@@ -265,7 +265,7 @@ impl AppchainAnchor {
265265
StorageKey::ProtocolSettings.into_bytes(),
266266
Some(&ProtocolSettings::default()),
267267
),
268-
appchain_state: AppchainState::Staging,
268+
appchain_state: AppchainState::Booting,
269269
staking_histories: LazyOption::new(
270270
StorageKey::StakingHistories.into_bytes(),
271271
Some(&LookupArray::new(StorageKey::StakingHistoriesMap)),
@@ -502,7 +502,7 @@ impl AppchainAnchor {
502502
let predecessor_account_id = env::predecessor_account_id();
503503
match deposit_message {
504504
FTDepositMessage::RegisterValidator { .. }
505-
| FTDepositMessage::IncreaseStake
505+
| FTDepositMessage::IncreaseStake { .. }
506506
| FTDepositMessage::RegisterDelegator { .. }
507507
| FTDepositMessage::IncreaseDelegation { .. } => {
508508
assert!(

appchain-anchor/src/permissionless_actions/switching_era.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,15 @@ impl AppchainAnchor {
240240
let args = near_sdk::serde_json::to_vec(&args)
241241
.expect("Failed to serialize the cross contract args using JSON.");
242242
let contract_account = AccountId::from_str(
243-
format!("octopus-council.{}", self.appchain_registry).as_str(),
243+
format!(
244+
"{}.{}",
245+
self.protocol_settings
246+
.get()
247+
.unwrap()
248+
.subaccount_for_council_keeper_contract,
249+
self.appchain_registry
250+
)
251+
.as_str(),
244252
)
245253
.unwrap();
246254
Promise::new(contract_account).function_call(

appchain-anchor/src/storage_migration.rs

Lines changed: 141 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,86 @@ use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
33
use near_sdk::collections::{LazyOption, LookupMap};
44
use near_sdk::{env, near_bindgen, AccountId, Balance};
55

6+
#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize, Debug, PartialEq)]
7+
#[serde(crate = "near_sdk::serde")]
8+
pub enum OldAppchainState {
9+
/// The initial state of an appchain, after it is successfully registered.
10+
/// This state is managed by appchain registry.
11+
Registered,
12+
/// The state while the appchain is under auditing by Octopus Network.
13+
/// This state is managed by appchain registry.
14+
Auditing,
15+
/// The state while voter can upvote or downvote an appchain.
16+
/// This state is managed by appchain registry.
17+
InQueue,
18+
/// The state while validator and delegator can deposit OCT tokens to this contract
19+
/// to indicate their willing of staking for an appchain.
20+
Staging,
21+
/// The state while an appchain is booting.
22+
Booting,
23+
/// The state while an appchain is active normally.
24+
Active,
25+
/// The state while an appchain is under challenging, which all deposit and withdraw actions
26+
/// are frozen.
27+
Frozen,
28+
/// The state which an appchain is broken for some technical or governance reasons.
29+
Broken,
30+
/// The state which the lifecycle of an appchain is end.
31+
Dead,
32+
}
33+
34+
#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone)]
35+
#[serde(crate = "near_sdk::serde")]
36+
pub struct OldProtocolSettings {
37+
/// A validator has to deposit a certain amount of OCT token to this contract for
38+
/// being validator of the appchain.
39+
pub minimum_validator_deposit: U128,
40+
/// The minimum amount for a validator to increase or decrease his/her deposit.
41+
pub minimum_validator_deposit_changing_amount: U128,
42+
/// The maximum percent value that the deposit of a validator in total stake
43+
pub maximum_validator_stake_percent: u16,
44+
/// The minimum deposit amount for a delegator to delegate his voting weight to
45+
/// a certain validator.
46+
pub minimum_delegator_deposit: U128,
47+
/// The minimum amount for a delegator to increase or decrease his/her delegation
48+
/// to a validator.
49+
pub minimum_delegator_deposit_changing_amount: U128,
50+
/// The minimum price (in USD) of total stake in this contract for
51+
/// booting corresponding appchain
52+
pub minimum_total_stake_price_for_booting: U128,
53+
/// The maximum percentage of the total market value of all NEP-141 tokens to the total
54+
/// market value of OCT token staked in this contract
55+
pub maximum_market_value_percent_of_near_fungible_tokens: u16,
56+
/// The maximum percentage of the total market value of wrapped appchain token to the total
57+
/// market value of OCT token staked in this contract
58+
pub maximum_market_value_percent_of_wrapped_appchain_token: u16,
59+
/// The minimum number of validator(s) registered in this contract for
60+
/// booting the corresponding appchain and keep it alive.
61+
pub minimum_validator_count: U64,
62+
/// The maximum number of validator(s) registered in this contract for
63+
/// the corresponding appchain.
64+
pub maximum_validator_count: U64,
65+
/// The maximum number of validator(s) which a delegator can delegate to.
66+
pub maximum_validators_per_delegator: U64,
67+
/// The unlock period (in days) for validator(s) can withdraw their deposit after
68+
/// they are removed from the corresponding appchain.
69+
pub unlock_period_of_validator_deposit: U64,
70+
/// The unlock period (in days) for delegator(s) can withdraw their deposit after
71+
/// they no longer delegates their stake to a certain validator on the corresponding appchain.
72+
pub unlock_period_of_delegator_deposit: U64,
73+
/// The maximum number of historical eras that the validators or delegators are allowed to
74+
/// withdraw their reward
75+
pub maximum_era_count_of_unwithdrawn_reward: U64,
76+
/// The maximum number of valid appchain message.
77+
/// If the era number of appchain message is smaller than the latest era number minus
78+
/// this value, the message will be considered as `invalid`.
79+
pub maximum_era_count_of_valid_appchain_message: U64,
80+
/// The percent of commission fees of a validator's reward in an era
81+
pub validator_commission_percent: u16,
82+
/// The maximum unprofitable era count for auto-unbonding a validator
83+
pub maximum_allowed_unprofitable_era_count: u16,
84+
}
85+
686
#[derive(BorshDeserialize, BorshSerialize)]
787
pub struct OldAppchainAnchor {
888
/// The id of corresponding appchain.
@@ -41,9 +121,9 @@ pub struct OldAppchainAnchor {
41121
/// The anchor settings for appchain.
42122
anchor_settings: LazyOption<AnchorSettings>,
43123
/// The protocol settings for appchain anchor.
44-
protocol_settings: LazyOption<ProtocolSettings>,
124+
protocol_settings: LazyOption<OldProtocolSettings>,
45125
/// The state of the corresponding appchain.
46-
appchain_state: AppchainState,
126+
appchain_state: OldAppchainState,
47127
/// The staking history data happened in this contract.
48128
staking_histories: LazyOption<LookupArray<StakingHistory>>,
49129
/// The appchain notification history data.
@@ -66,6 +146,8 @@ pub struct OldAppchainAnchor {
66146
appchain_challenges: LazyOption<LookupArray<AppchainChallenge>>,
67147
/// The wrapped appchain NFT data
68148
wrapped_appchain_nfts: LazyOption<WrappedAppchainNFTs>,
149+
/// The native NEAR token data
150+
native_near_token: LazyOption<NativeNearToken>,
69151
}
70152

71153
#[near_bindgen]
@@ -95,8 +177,13 @@ impl AppchainAnchor {
95177
validator_profiles: old_contract.validator_profiles,
96178
appchain_settings: old_contract.appchain_settings,
97179
anchor_settings: old_contract.anchor_settings,
98-
protocol_settings: old_contract.protocol_settings,
99-
appchain_state: old_contract.appchain_state,
180+
protocol_settings: LazyOption::new(
181+
StorageKey::ProtocolSettings.into_bytes(),
182+
Some(&ProtocolSettings::from_old_version(
183+
old_contract.protocol_settings.get().unwrap(),
184+
)),
185+
),
186+
appchain_state: AppchainState::from_old_version(old_contract.appchain_state),
100187
staking_histories: old_contract.staking_histories,
101188
appchain_notification_histories: old_contract.appchain_notification_histories,
102189
permissionless_actions_status: old_contract.permissionless_actions_status,
@@ -108,13 +195,59 @@ impl AppchainAnchor {
108195
appchain_messages: old_contract.appchain_messages,
109196
appchain_challenges: old_contract.appchain_challenges,
110197
wrapped_appchain_nfts: old_contract.wrapped_appchain_nfts,
111-
native_near_token: LazyOption::new(
112-
StorageKey::NativeNearToken.into_bytes(),
113-
Some(&NativeNearToken::default()),
114-
),
198+
native_near_token: old_contract.native_near_token,
115199
};
116200
//
117201
//
118202
new_contract
119203
}
120204
}
205+
206+
impl AppchainState {
207+
pub fn from_old_version(old_version: OldAppchainState) -> Self {
208+
match old_version {
209+
OldAppchainState::Registered => AppchainState::Registered,
210+
OldAppchainState::Auditing => AppchainState::Audited,
211+
OldAppchainState::InQueue => AppchainState::Voting,
212+
OldAppchainState::Staging => AppchainState::Booting,
213+
OldAppchainState::Booting => AppchainState::Booting,
214+
OldAppchainState::Active => AppchainState::Active,
215+
OldAppchainState::Frozen => AppchainState::Closing,
216+
OldAppchainState::Broken => AppchainState::Closing,
217+
OldAppchainState::Dead => AppchainState::Closed,
218+
}
219+
}
220+
}
221+
222+
impl ProtocolSettings {
223+
pub fn from_old_version(old_version: OldProtocolSettings) -> Self {
224+
ProtocolSettings {
225+
minimum_validator_deposit: old_version.minimum_validator_deposit,
226+
minimum_validator_deposit_changing_amount: old_version
227+
.minimum_validator_deposit_changing_amount,
228+
maximum_validator_stake_percent: old_version.maximum_validator_stake_percent,
229+
minimum_delegator_deposit: old_version.minimum_delegator_deposit,
230+
minimum_delegator_deposit_changing_amount: old_version
231+
.minimum_delegator_deposit_changing_amount,
232+
minimum_total_stake_price_for_booting: old_version
233+
.minimum_total_stake_price_for_booting,
234+
maximum_market_value_percent_of_near_fungible_tokens: old_version
235+
.maximum_market_value_percent_of_near_fungible_tokens,
236+
maximum_market_value_percent_of_wrapped_appchain_token: old_version
237+
.maximum_market_value_percent_of_wrapped_appchain_token,
238+
minimum_validator_count: old_version.minimum_validator_count,
239+
maximum_validator_count: old_version.maximum_validator_count,
240+
maximum_validators_per_delegator: old_version.maximum_validators_per_delegator,
241+
unlock_period_of_validator_deposit: old_version.unlock_period_of_validator_deposit,
242+
unlock_period_of_delegator_deposit: old_version.unlock_period_of_delegator_deposit,
243+
maximum_era_count_of_unwithdrawn_reward: old_version
244+
.maximum_era_count_of_unwithdrawn_reward,
245+
maximum_era_count_of_valid_appchain_message: old_version
246+
.maximum_era_count_of_valid_appchain_message,
247+
validator_commission_percent: old_version.validator_commission_percent,
248+
maximum_allowed_unprofitable_era_count: old_version
249+
.maximum_allowed_unprofitable_era_count,
250+
subaccount_for_council_keeper_contract: "octopus-council".to_string(),
251+
}
252+
}
253+
}

0 commit comments

Comments
 (0)