1
1
use crate :: {
2
2
contract:: { CONTRACT_NAME , CONTRACT_VERSION } ,
3
3
error:: ContractResult ,
4
- helpers:: validate_denom,
4
+ helpers:: { validate_address , validate_address_prefix , validate_denom} ,
5
5
migrations:: states:: v0_4_20,
6
6
state:: { Config , NativeChainConfig , ProtocolChainConfig , ProtocolFeeConfig , CONFIG } ,
7
7
} ;
@@ -21,10 +21,45 @@ pub fn migrate(
21
21
// Ensure that we are migrating from the correct version.
22
22
assert_contract_version ( deps. storage , CONTRACT_NAME , FROM_VERSION ) ?;
23
23
24
+ // Ensure the address prefixes are valid
25
+ let native_account_address_prefix = validate_address_prefix ( & native_account_address_prefix) ?;
26
+ let native_validator_address_prefix =
27
+ validate_address_prefix ( & native_validator_address_prefix) ?;
28
+ let protocol_account_address_prefix =
29
+ validate_address_prefix ( & protocol_account_address_prefix) ?;
30
+
24
31
// Ensure that the token denom is valid
25
32
validate_denom ( & native_token_denom) ?;
26
33
27
34
let old_config = v0_4_20:: CONFIG . load ( deps. storage ) ?;
35
+
36
+ // Ensure the currently configured native chain addresses have the provided prefixes
37
+ validate_address (
38
+ old_config. multisig_address_config . staker_address . as_str ( ) ,
39
+ & native_account_address_prefix,
40
+ ) ?;
41
+ validate_address (
42
+ old_config
43
+ . multisig_address_config
44
+ . reward_collector_address
45
+ . as_str ( ) ,
46
+ & native_account_address_prefix,
47
+ ) ?;
48
+ for address in old_config. validators . iter ( ) {
49
+ validate_address ( address. as_str ( ) , & native_validator_address_prefix) ?;
50
+ }
51
+
52
+ // Ensure the currently configured protocol chain addresses have the provided prefixes
53
+ if let Some ( address) = & old_config. oracle_address {
54
+ validate_address ( address. as_str ( ) , & protocol_account_address_prefix) ?;
55
+ }
56
+ if old_config. send_fees_to_treasury {
57
+ validate_address (
58
+ old_config. treasury_address . as_str ( ) ,
59
+ & protocol_account_address_prefix,
60
+ ) ?;
61
+ }
62
+
28
63
// Convert the old config format to the new one.
29
64
let new_config = Config {
30
65
native_chain_config : NativeChainConfig {
0 commit comments