11// stellar_registry::import_asset!("xlm");
2-
32#[ cfg( test) ]
4- const XLM_KEY : & soroban_sdk:: Symbol = & soroban_sdk:: symbol_short!( "XLM" ) ;
3+ mod xlm {
4+ use super :: * ;
5+ const XLM_KEY : & soroban_sdk:: Symbol = & soroban_sdk:: symbol_short!( "XLM" ) ;
56
6- #[ cfg( test) ]
7- pub fn contract_id ( env : & soroban_sdk:: Env ) -> soroban_sdk:: Address {
8- env. storage ( )
9- . instance ( )
10- . get :: < _ , soroban_sdk:: Address > ( XLM_KEY )
11- . expect ( "XLM contract not initialized. Please deploy the XLM contract first." )
12- }
7+ pub fn contract_id ( env : & soroban_sdk:: Env ) -> soroban_sdk:: Address {
8+ env. storage ( )
9+ . instance ( )
10+ . get :: < _ , soroban_sdk:: Address > ( XLM_KEY )
11+ . expect ( "XLM contract not initialized. Please deploy the XLM contract first." )
12+ }
1313
14- #[ cfg( test) ]
15- pub fn register (
16- env : & soroban_sdk:: Env ,
17- admin : & soroban_sdk:: Address ,
18- ) -> soroban_sdk:: testutils:: StellarAssetContract {
19- let sac = env. register_stellar_asset_contract_v2 ( admin. clone ( ) ) ;
20- env. storage ( ) . instance ( ) . set ( XLM_KEY , & sac. address ( ) ) ;
21- stellar_asset_client ( env) . mint ( admin, & to_stroops ( 10_000 ) ) ;
22- sac
23- }
24- #[ cfg( not( test) ) ]
25- pub fn contract_id ( env : & soroban_sdk:: Env ) -> soroban_sdk:: Address {
26- env. deployer ( )
27- . with_stellar_asset ( SERIALIZED_ASSET )
28- . deployed_address ( )
29- }
30- #[ cfg( not( test) ) ]
31- pub const SERIALIZED_ASSET : [ u8 ; 4 ] = [ 0 , 0 , 0 , 0 ] ;
32- /// Contract id for the Stellar Asset Contract
33- /// Create a Stellar Asset Client for the asset which provides an admin interface
34- #[ allow( unused) ]
35- pub fn stellar_asset_client < ' a > (
36- env : & soroban_sdk:: Env ,
37- ) -> soroban_sdk:: token:: StellarAssetClient < ' a > {
38- soroban_sdk:: token:: StellarAssetClient :: new ( & env, & contract_id ( env) )
39- }
40- /// Create a Stellar Asset Client for the asset which provides an admin interface
41- pub fn token_client < ' a > ( env : & soroban_sdk:: Env ) -> soroban_sdk:: token:: TokenClient < ' a > {
42- soroban_sdk:: token:: TokenClient :: new ( & env, & contract_id ( env) )
43- }
14+ pub fn register (
15+ env : & soroban_sdk:: Env ,
16+ admin : & soroban_sdk:: Address ,
17+ ) -> soroban_sdk:: testutils:: StellarAssetContract {
18+ let sac = env. register_stellar_asset_contract_v2 ( admin. clone ( ) ) ;
19+ env. storage ( ) . instance ( ) . set ( XLM_KEY , & sac. address ( ) ) ;
20+ stellar_asset_client ( env) . mint ( admin, & to_stroops ( 10_000 ) ) ;
21+ sac
22+ }
4423
24+ #[ allow( unused) ]
25+ pub fn stellar_asset_client < ' a > (
26+ env : & soroban_sdk:: Env ,
27+ ) -> soroban_sdk:: token:: StellarAssetClient < ' a > {
28+ soroban_sdk:: token:: StellarAssetClient :: new ( & env, & contract_id ( env) )
29+ }
30+ /// Create a Stellar Asset Client for the asset which provides an admin interface
31+ pub fn token_client < ' a > ( env : & soroban_sdk:: Env ) -> soroban_sdk:: token:: TokenClient < ' a > {
32+ soroban_sdk:: token:: TokenClient :: new ( & env, & contract_id ( env) )
33+ }
34+
35+ }
4536const ONE_XLM : i128 = 1_000_000_0 ; // 1 XLM in stroops;
4637
4738pub const fn to_stroops ( num : u64 ) -> i128 {
4839 ( num as i128 ) * ONE_XLM
49- }
40+ }
41+
42+ #[ cfg( not( test) ) ]
43+ stellar_registry:: import_asset!( "xlm" ) ;
44+
45+ pub use xlm:: * ;
0 commit comments