@@ -17,7 +17,7 @@ use soroban_sdk::{
1717 contract, contracterror, contractimpl, panic_with_error, symbol_short, token:: TokenInterface ,
1818 Address , Env , String , Symbol ,
1919} ;
20- use stellar_fungible:: { self as fungible , mintable :: FungibleMintable } ;
20+ use stellar_fungible:: Base ;
2121use stellar_pausable:: { self as pausable, Pausable } ;
2222use stellar_pausable_macros:: when_not_paused;
2323
@@ -36,20 +36,26 @@ pub enum ExampleContractError {
3636#[ contractimpl]
3737impl ExampleContract {
3838 pub fn __constructor ( e : & Env , owner : Address , initial_supply : i128 ) {
39- fungible:: metadata:: set_metadata (
40- e,
41- 18 ,
42- String :: from_str ( e, "My Token" ) ,
43- String :: from_str ( e, "TKN" ) ,
44- ) ;
45- fungible:: mintable:: mint ( e, & owner, initial_supply) ;
39+ Base :: set_metadata ( e, 18 , String :: from_str ( e, "My Token" ) , String :: from_str ( e, "TKN" ) ) ;
40+ Base :: mint ( e, & owner, initial_supply) ;
4641 e. storage ( ) . instance ( ) . set ( & OWNER , & owner) ;
4742 }
4843
4944 /// `TokenInterface` doesn't require implementing `total_supply()` because
5045 /// of the need for backwards compatibility with Stellar classic assets.
5146 pub fn total_supply ( e : & Env ) -> i128 {
52- fungible:: total_supply ( e)
47+ Base :: total_supply ( e)
48+ }
49+
50+ #[ when_not_paused]
51+ pub fn mint ( e : & Env , account : Address , amount : i128 ) {
52+ // When `ownable` module is available,
53+ // the following checks should be equivalent to:
54+ // `ownable::only_owner(&e);`
55+ let owner: Address = e. storage ( ) . instance ( ) . get ( & OWNER ) . expect ( "owner should be set" ) ;
56+ owner. require_auth ( ) ;
57+
58+ Base :: mint ( e, & account, amount) ;
5359 }
5460}
5561
@@ -63,84 +69,72 @@ impl Pausable for ExampleContract {
6369 // When `ownable` module is available,
6470 // the following checks should be equivalent to:
6571 // `ownable::only_owner(&e);`
72+ caller. require_auth ( ) ;
6673 let owner: Address = e. storage ( ) . instance ( ) . get ( & OWNER ) . expect ( "owner should be set" ) ;
6774 if owner != caller {
6875 panic_with_error ! ( e, ExampleContractError :: Unauthorized ) ;
6976 }
7077
71- pausable:: pause ( e, & caller ) ;
78+ pausable:: pause ( e) ;
7279 }
7380
7481 fn unpause ( e : & Env , caller : Address ) {
7582 // When `ownable` module is available,
7683 // the following checks should be equivalent to:
7784 // `ownable::only_owner(&e);`
85+ caller. require_auth ( ) ;
7886 let owner: Address = e. storage ( ) . instance ( ) . get ( & OWNER ) . expect ( "owner should be set" ) ;
7987 if owner != caller {
8088 panic_with_error ! ( e, ExampleContractError :: Unauthorized ) ;
8189 }
8290
83- pausable:: unpause ( e, & caller ) ;
91+ pausable:: unpause ( e) ;
8492 }
8593}
8694
8795#[ contractimpl]
8896impl TokenInterface for ExampleContract {
8997 fn balance ( e : Env , account : Address ) -> i128 {
90- fungible :: balance ( & e, & account)
98+ Base :: balance ( & e, & account)
9199 }
92100
93101 fn allowance ( e : Env , owner : Address , spender : Address ) -> i128 {
94- fungible :: allowance ( & e, & owner, & spender)
102+ Base :: allowance ( & e, & owner, & spender)
95103 }
96104
97105 #[ when_not_paused]
98106 fn transfer ( e : Env , from : Address , to : Address , amount : i128 ) {
99- fungible :: transfer ( & e, & from, & to, amount) ;
107+ Base :: transfer ( & e, & from, & to, amount) ;
100108 }
101109
102110 #[ when_not_paused]
103111 fn transfer_from ( e : Env , spender : Address , from : Address , to : Address , amount : i128 ) {
104- fungible :: transfer_from ( & e, & spender, & from, & to, amount) ;
112+ Base :: transfer_from ( & e, & spender, & from, & to, amount) ;
105113 }
106114
107115 fn approve ( e : Env , owner : Address , spender : Address , amount : i128 , live_until_ledger : u32 ) {
108- fungible :: approve ( & e, & owner, & spender, amount, live_until_ledger) ;
116+ Base :: approve ( & e, & owner, & spender, amount, live_until_ledger) ;
109117 }
110118
111119 #[ when_not_paused]
112120 fn burn ( e : Env , from : Address , amount : i128 ) {
113- fungible :: burnable :: burn ( & e, & from, amount)
121+ Base :: burn ( & e, & from, amount)
114122 }
115123
116124 #[ when_not_paused]
117125 fn burn_from ( e : Env , spender : Address , from : Address , amount : i128 ) {
118- fungible :: burnable :: burn_from ( & e, & spender, & from, amount)
126+ Base :: burn_from ( & e, & spender, & from, amount)
119127 }
120128
121129 fn decimals ( e : Env ) -> u32 {
122- fungible :: metadata :: decimals ( & e)
130+ Base :: decimals ( & e)
123131 }
124132
125133 fn name ( e : Env ) -> String {
126- fungible :: metadata :: name ( & e)
134+ Base :: name ( & e)
127135 }
128136
129137 fn symbol ( e : Env ) -> String {
130- fungible:: metadata:: symbol ( & e)
131- }
132- }
133-
134- #[ contractimpl]
135- impl FungibleMintable for ExampleContract {
136- #[ when_not_paused]
137- fn mint ( e : & Env , account : Address , amount : i128 ) {
138- // When `ownable` module is available,
139- // the following checks should be equivalent to:
140- // `ownable::only_owner(&e);`
141- let owner: Address = e. storage ( ) . instance ( ) . get ( & OWNER ) . expect ( "owner should be set" ) ;
142- owner. require_auth ( ) ;
143-
144- fungible:: mintable:: mint ( e, & account, amount) ;
138+ Base :: symbol ( & e)
145139 }
146140}
0 commit comments