@@ -3,6 +3,86 @@ use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
33use near_sdk:: collections:: { LazyOption , LookupMap } ;
44use 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 ) ]
787pub 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