diff --git a/pallets/leverage-staking/src/lib.rs b/pallets/leverage-staking/src/lib.rs index 6522cb1d9..50b50756f 100644 --- a/pallets/leverage-staking/src/lib.rs +++ b/pallets/leverage-staking/src/lib.rs @@ -87,23 +87,36 @@ pub mod pallet { #[pallet::error] pub enum Error { + /// Arguments error, old rate is equal to new rate ArgumentsError, + /// Not support token type NotSupportTokenType, } #[pallet::event] #[pallet::generate_deposit(pub (crate) fn deposit_event)] pub enum Event { + /// User's leverage rate has been changed. FlashLoanDeposited { + /// Account who change the leverage rate. who: AccountIdOf, + /// The asset id of the token. asset_id: AssetIdOf, + /// The old leverage rate. old_rate: Rate, + /// The new leverage rate. new_rate: Rate, }, } #[pallet::call] impl Pallet { + /// Deposit flash loan + /// + /// Using borrowed funds to increase the amount of liquid staking (yield-bearing) assets. + /// + /// - `asset_id`: The asset id of the token + /// - `rate`: Leverage rate #[pallet::call_index(0)] #[pallet::weight(::WeightInfo::flash_loan_deposit())] pub fn flash_loan_deposit( @@ -111,7 +124,9 @@ pub mod pallet { asset_id: AssetIdOf, rate: Rate, ) -> DispatchResult { - Pallet::::flash_loan_deposit_inner(origin, asset_id, rate) + let who = ensure_signed(origin)?; + + Pallet::::flash_loan_deposit_inner(who, asset_id, rate) } } } @@ -119,12 +134,10 @@ pub mod pallet { impl Pallet { #[transactional] pub fn flash_loan_deposit_inner( - origin: OriginFor, + who: AccountIdOf, asset_id: AssetIdOf, rate: Rate, ) -> DispatchResult { - let who = ensure_signed(origin)?; - let vtoken_id = T::CurrencyIdConversion::convert_to_vtoken(asset_id) .map_err(|_| Error::::NotSupportTokenType)?; @@ -182,7 +195,7 @@ impl Pallet { ) -> DispatchResult { let (pool_id, currency_id_in, currency_id_out) = T::StablePoolHandler::get_pool_id(&vtoken_id, &asset_id) - .ok_or(Error::::ArgumentsError)?; + .ok_or(Error::::NotSupportTokenType)?; ::Assets::mint_into(asset_id, &who, reduce_amount)?;