@@ -145,6 +145,9 @@ pub mod pallet {
145
145
/// GHO contract address - EVM address of GHO token contract
146
146
type GhoContractAddress : BoundErc20 < AssetId = Self :: AssetId > ;
147
147
148
+ /// Arbitrage profit receiver
149
+ type ArbitrageProfitReceiver : Get < Self :: AccountId > ;
150
+
148
151
/// Currency - fungible tokens trait to access token transfers
149
152
type Currency : Mutate < Self :: AccountId , Balance = Balance , AssetId = Self :: AssetId > ;
150
153
@@ -243,8 +246,10 @@ pub mod pallet {
243
246
/// - `asset_id`: The collateral asset used in the arbitrage
244
247
/// - `hollar_amount`: Amount of Hollar that was included in the arbitrage operation
245
248
ArbitrageExecuted {
249
+ arbitrage : u8 ,
246
250
asset_id : T :: AssetId ,
247
251
hollar_amount : Balance ,
252
+ profit : Balance ,
248
253
} ,
249
254
250
255
/// Flash minter address set
@@ -860,14 +865,25 @@ pub mod pallet {
860
865
861
866
let ( exit_reason, value) = T :: Evm :: call ( context, data, U256 :: zero ( ) , T :: GasLimit :: get ( ) ) ;
862
867
868
+ let receiver_balance_initial = <T as crate :: pallet:: Config >:: Currency :: total_balance (
869
+ collateral_asset_id,
870
+ & T :: ArbitrageProfitReceiver :: get ( ) ,
871
+ ) ;
863
872
if exit_reason != ExitReason :: Succeed ( ExitSucceed :: Returned ) {
864
873
log:: error!( target: "hsm" , "Flash loan Hollar EVM execution failed - {:?}. Reason: {:?}" , exit_reason, value) ;
865
874
return Err ( Error :: < T > :: InvalidEVMInteraction . into ( ) ) ;
866
875
}
876
+ let receiver_balance_final = <T as crate :: pallet:: Config >:: Currency :: total_balance (
877
+ collateral_asset_id,
878
+ & T :: ArbitrageProfitReceiver :: get ( ) ,
879
+ ) ;
880
+ let profit = receiver_balance_final. saturating_sub ( receiver_balance_initial) ;
867
881
868
882
Self :: deposit_event ( Event :: < T > :: ArbitrageExecuted {
883
+ arbitrage : arb_direction,
869
884
asset_id : collateral_asset_id,
870
885
hollar_amount : flash_loan_amount,
886
+ profit,
871
887
} ) ;
872
888
873
889
Ok ( ( ) )
@@ -1642,11 +1658,10 @@ where
1642
1658
log:: trace!( target: "hsm" , "Collateral remaining : {:?}" , remaining) ;
1643
1659
// In case there is some collateral left after the buy,
1644
1660
// we transfer it to the HSM account
1645
- let hsm_account = Self :: account_id ( ) ;
1646
1661
<T as Config >:: Currency :: transfer (
1647
1662
collateral_asset_id,
1648
1663
& flash_loan_account,
1649
- & hsm_account ,
1664
+ & T :: ArbitrageProfitReceiver :: get ( ) ,
1650
1665
remaining,
1651
1666
Preservation :: Expendable ,
1652
1667
) ?;
@@ -1681,11 +1696,10 @@ where
1681
1696
1682
1697
if remaining > 0 {
1683
1698
log:: trace!( target: "hsm" , "Collateral remaining : {:?}" , remaining) ;
1684
- let hsm_account = Self :: account_id ( ) ;
1685
1699
<T as Config >:: Currency :: transfer (
1686
1700
collateral_asset_id,
1687
1701
& flash_loan_account,
1688
- & hsm_account ,
1702
+ & T :: ArbitrageProfitReceiver :: get ( ) ,
1689
1703
remaining,
1690
1704
Preservation :: Expendable ,
1691
1705
) ?;
@@ -1753,6 +1767,12 @@ where
1753
1767
capacity. saturating_sub ( level)
1754
1768
}
1755
1769
}
1770
+
1771
+ pub fn is_flash_loan_account ( account : & T :: AccountId ) -> bool {
1772
+ GetFlashMinterSupport :: < T > :: get ( ) . map_or ( false , |( _, loan_receiver) | {
1773
+ T :: EvmAccounts :: account_id ( loan_receiver) == * account
1774
+ } )
1775
+ }
1756
1776
}
1757
1777
1758
1778
pub struct GetFlashMinterSupport < T > ( sp_std:: marker:: PhantomData < T > ) ;
0 commit comments