@@ -3,14 +3,16 @@ use std::collections::BTreeMap;
3
3
use borsh:: { BorshDeserialize , BorshSerialize } ;
4
4
use namada_macros:: BorshDeserializer ;
5
5
use namada_sdk:: address:: Address ;
6
+ use namada_sdk:: ibc:: trace:: ibc_token;
6
7
use namada_sdk:: masp_primitives:: asset_type:: AssetType ;
7
8
use namada_sdk:: masp_primitives:: merkle_tree:: FrozenCommitmentTree ;
8
9
use namada_sdk:: masp_primitives:: sapling;
9
10
use namada_sdk:: migrations;
10
11
use namada_sdk:: storage:: DbColFam ;
12
+ use namada_shielded_token:: storage_key:: masp_reward_precision_key;
11
13
use namada_shielded_token:: { ConversionLeaf , ConversionState } ;
12
14
use namada_trans_token:: storage_key:: { balance_key, minted_balance_key} ;
13
- use namada_trans_token:: Amount ;
15
+ use namada_trans_token:: { Amount , Store } ;
14
16
15
17
pub const OLD_CONVERSION_STATE_TYPE_HASH : & str =
16
18
"05E2FD0BEBD54A05AAE349BBDE61F90893F09A72850EFD4F69060821EC5DE65F" ;
@@ -38,8 +40,8 @@ impl From<ConversionState> for NewConversionState {
38
40
}
39
41
}
40
42
41
- # [ allow ( dead_code ) ]
42
- fn example ( ) {
43
+ // Demonstrate how to set the minted balance using a migration
44
+ fn minted_balance_migration ( ) {
43
45
let person =
44
46
Address :: decode ( "tnam1q9rhgyv3ydq0zu3whnftvllqnvhvhm270qxay5tn" )
45
47
. unwrap ( ) ;
@@ -68,10 +70,59 @@ fn example() {
68
70
let changes = migrations:: DbChanges {
69
71
changes : updates. into_iter ( ) . collect ( ) ,
70
72
} ;
71
- std:: fs:: write ( "migrations.json" , serde_json:: to_string ( & changes) . unwrap ( ) )
72
- . unwrap ( ) ;
73
+ std:: fs:: write (
74
+ "minted_balance_migration.json" ,
75
+ serde_json:: to_string ( & changes) . unwrap ( ) ,
76
+ )
77
+ . unwrap ( ) ;
78
+ }
79
+
80
+ // Demonstrate how to set the shielded reward precision of IBC tokens using a
81
+ // migration
82
+ fn shielded_reward_precision_migration ( ) {
83
+ pub type ChannelId = & ' static str ;
84
+ pub type BaseToken = & ' static str ;
85
+ pub type Precision = u128 ;
86
+
87
+ const IBC_TOKENS : [ ( ChannelId , BaseToken , Precision ) ; 6 ] = [
88
+ ( "channel-1" , "uosmo" , 1000u128 ) ,
89
+ ( "channel-2" , "uatom" , 1000u128 ) ,
90
+ ( "channel-3" , "utia" , 1000u128 ) ,
91
+ ( "channel-0" , "stuosmo" , 1000u128 ) ,
92
+ ( "channel-0" , "stuatom" , 1000u128 ) ,
93
+ ( "channel-0" , "stutia" , 1000u128 ) ,
94
+ ] ;
95
+
96
+ let mut updates = Vec :: new ( ) ;
97
+ // Set IBC token shielded reward precisions
98
+ for ( channel_id, base_token, precision) in IBC_TOKENS {
99
+ let ibc_denom = format ! ( "transfer/{channel_id}/{base_token}" ) ;
100
+ let token_address = ibc_token ( & ibc_denom) . clone ( ) ;
101
+
102
+ // The key holding the shielded reward precision of current token
103
+ let shielded_token_reward_precision_key =
104
+ masp_reward_precision_key :: < Store < ( ) > > ( & token_address) ;
105
+
106
+ updates. push ( migrations:: DbUpdateType :: Add {
107
+ key : shielded_token_reward_precision_key,
108
+ cf : DbColFam :: SUBSPACE ,
109
+ value : precision. into ( ) ,
110
+ force : false ,
111
+ } ) ;
112
+ }
113
+
114
+ let changes = migrations:: DbChanges {
115
+ changes : updates. into_iter ( ) . collect ( ) ,
116
+ } ;
117
+ std:: fs:: write (
118
+ "shielded_reward_precision_migration.json" ,
119
+ serde_json:: to_string ( & changes) . unwrap ( ) ,
120
+ )
121
+ . unwrap ( ) ;
73
122
}
74
123
124
+ // Generate various migrations
75
125
fn main ( ) {
76
- example ( )
126
+ minted_balance_migration ( ) ;
127
+ shielded_reward_precision_migration ( ) ;
77
128
}
0 commit comments