33use crate :: storage_types:: { INSTANCE_BUMP_AMOUNT , INSTANCE_LIFETIME_THRESHOLD } ;
44use crate :: { admin, allowance, balance, metadata} ;
55use soroban_sdk:: token:: { self , Interface as _} ;
6- use soroban_sdk:: { contract, contractimpl, Address , Env , String } ;
6+ use soroban_sdk:: { contract, contractevent , contractimpl, Address , Env , MuxedAddress , String } ;
77use soroban_token_sdk:: metadata:: TokenMetadata ;
8- use soroban_token_sdk:: TokenUtils ;
8+ use soroban_token_sdk:: events:: { TransferWithAmountOnly , Approve , Burn , MintWithAmountOnly } ;
9+
10+ #[ contractevent( data_format = "single-value" ) ]
11+ pub struct SetAdmin {
12+ #[ topic]
13+ admin : Address ,
14+ new_admin : Address ,
15+ }
916
1017fn check_nonnegative_amount ( amount : i128 ) {
1118 assert ! ( amount >= 0 , "negative amount is not allowed: {amount}" ) ;
@@ -41,7 +48,10 @@ impl Token {
4148 . extend_ttl ( INSTANCE_LIFETIME_THRESHOLD , INSTANCE_BUMP_AMOUNT ) ;
4249
4350 balance:: receive ( & e, to. clone ( ) , amount) ;
44- TokenUtils :: new ( & e) . events ( ) . mint ( admin, to, amount) ;
51+ MintWithAmountOnly {
52+ to : to. clone ( ) ,
53+ amount,
54+ } . publish ( & e) ;
4555 }
4656
4757 pub fn set_admin ( e : Env , new_admin : Address ) {
@@ -53,7 +63,10 @@ impl Token {
5363 . extend_ttl ( INSTANCE_LIFETIME_THRESHOLD , INSTANCE_BUMP_AMOUNT ) ;
5464
5565 admin:: write_administrator ( & e, & new_admin) ;
56- TokenUtils :: new ( & e) . events ( ) . set_admin ( admin, new_admin) ;
66+ SetAdmin {
67+ admin : admin. clone ( ) ,
68+ new_admin : new_admin. clone ( ) ,
69+ } . publish ( & e) ;
5770 }
5871}
5972
@@ -76,9 +89,12 @@ impl token::Interface for Token {
7689 . extend_ttl ( INSTANCE_LIFETIME_THRESHOLD , INSTANCE_BUMP_AMOUNT ) ;
7790
7891 allowance:: write ( & e, from. clone ( ) , spender. clone ( ) , amount, expiration_ledger) ;
79- TokenUtils :: new ( & e)
80- . events ( )
81- . approve ( from, spender, amount, expiration_ledger) ;
92+ Approve {
93+ from : from. clone ( ) ,
94+ spender : spender. clone ( ) ,
95+ amount,
96+ expiration_ledger,
97+ } . publish ( & e) ;
8298 }
8399
84100 fn balance ( e : Env , id : Address ) -> i128 {
@@ -88,7 +104,7 @@ impl token::Interface for Token {
88104 balance:: read ( & e, id)
89105 }
90106
91- fn transfer ( e : Env , from : Address , to : Address , amount : i128 ) {
107+ fn transfer ( e : Env , from : Address , to : MuxedAddress , amount : i128 ) {
92108 from. require_auth ( ) ;
93109
94110 check_nonnegative_amount ( amount) ;
@@ -97,9 +113,14 @@ impl token::Interface for Token {
97113 . instance ( )
98114 . extend_ttl ( INSTANCE_LIFETIME_THRESHOLD , INSTANCE_BUMP_AMOUNT ) ;
99115
116+ let to_address = to. address ( ) ;
100117 balance:: spend ( & e, from. clone ( ) , amount) ;
101- balance:: receive ( & e, to. clone ( ) , amount) ;
102- TokenUtils :: new ( & e) . events ( ) . transfer ( from, to, amount) ;
118+ balance:: receive ( & e, to_address. clone ( ) , amount) ;
119+ TransferWithAmountOnly {
120+ from : from. clone ( ) ,
121+ to : to_address,
122+ amount,
123+ } . publish ( & e) ;
103124 }
104125
105126 fn transfer_from ( e : Env , spender : Address , from : Address , to : Address , amount : i128 ) {
@@ -114,7 +135,11 @@ impl token::Interface for Token {
114135 allowance:: spend ( & e, from. clone ( ) , spender, amount) ;
115136 balance:: spend ( & e, from. clone ( ) , amount) ;
116137 balance:: receive ( & e, to. clone ( ) , amount) ;
117- TokenUtils :: new ( & e) . events ( ) . transfer ( from, to, amount) ;
138+ TransferWithAmountOnly {
139+ from : from. clone ( ) ,
140+ to : to. clone ( ) ,
141+ amount,
142+ } . publish ( & e) ;
118143 }
119144
120145 fn burn ( e : Env , from : Address , amount : i128 ) {
@@ -127,7 +152,10 @@ impl token::Interface for Token {
127152 . extend_ttl ( INSTANCE_LIFETIME_THRESHOLD , INSTANCE_BUMP_AMOUNT ) ;
128153
129154 balance:: spend ( & e, from. clone ( ) , amount) ;
130- TokenUtils :: new ( & e) . events ( ) . burn ( from, amount) ;
155+ Burn {
156+ from : from. clone ( ) ,
157+ amount,
158+ } . publish ( & e) ;
131159 }
132160
133161 fn burn_from ( e : Env , spender : Address , from : Address , amount : i128 ) {
@@ -141,7 +169,10 @@ impl token::Interface for Token {
141169
142170 allowance:: spend ( & e, from. clone ( ) , spender, amount) ;
143171 balance:: spend ( & e, from. clone ( ) , amount) ;
144- TokenUtils :: new ( & e) . events ( ) . burn ( from, amount) ;
172+ Burn {
173+ from : from. clone ( ) ,
174+ amount,
175+ } . publish ( & e) ;
145176 }
146177
147178 fn decimals ( e : Env ) -> u32 {
0 commit comments