Skip to content

Commit

Permalink
Merge pull request #157 from Brushfam/oz/l-01
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemka374 committed Sep 19, 2023
2 parents 0fda946 + dcf5843 commit fa69377
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 22 additions & 2 deletions contracts/src/token/psp22/extensions/flashmint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ pub use crate::{
pub use flashmint::Internal as _;
use ink::{
env::CallFlags,
prelude::vec::Vec,
prelude::{
vec,
vec::Vec,
},
};
use openbrush::traits::{
AccountId,
Expand Down Expand Up @@ -76,7 +79,18 @@ pub trait FlashLenderImpl: Storage<psp22::Data> + psp22::Internal + PSP22 + Inte
return Err(FlashLenderError::AllowanceDoesNotAllowRefund)
}
psp22::Internal::_approve_from_to(self, receiver_account, this, current_allowance - amount - fee)?;
psp22::Internal::_burn_from(self, receiver_account, amount + fee)?;

let flash_fee_receiver = self._flash_fee_receiver();

if let Some(fee_receiver) = flash_fee_receiver {
if fee == 0 {
psp22::Internal::_burn_from(self, receiver_account, amount + fee)?;
} else {
psp22::Internal::_burn_from(self, receiver_account, amount)?;
psp22::Internal::_transfer_from_to(self, receiver_account, fee_receiver, fee, vec![])?;
}
}

Ok(())
}
}
Expand All @@ -92,6 +106,8 @@ pub trait Internal {
amount: Balance,
data: Vec<u8>,
) -> Result<(), FlashLenderError>;

fn _flash_fee_receiver(&self) -> Option<AccountId>;
}

pub trait InternalImpl: Storage<psp22::Data> + Internal {
Expand Down Expand Up @@ -128,4 +144,8 @@ pub trait InternalImpl: Storage<psp22::Data> + Internal {

result
}

fn _flash_fee_receiver(&self) -> Option<AccountId> {
None
}
}
4 changes: 4 additions & 0 deletions lang/codegen/src/implementations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ pub(crate) fn impl_flashmint(impl_args: &mut ImplArgs) {
) -> Result<(), FlashLenderError> {
flashmint::InternalImpl::_on_flashloan(self, receiver_account, token, fee, amount, data)
}

fn _flash_fee_receiver(&self) -> Option<AccountId> {
flashmint::InternalImpl::_flash_fee_receiver(self)
}
}
))
.expect("Should parse");
Expand Down

0 comments on commit fa69377

Please sign in to comment.