Skip to content

Commit

Permalink
chore: smaller fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifechukwudaniel committed Nov 20, 2024
1 parent 890807d commit ea3a9b3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
69 changes: 43 additions & 26 deletions examples/erc20-flashmint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,64 @@ extern crate alloc;
use alloc::vec::Vec;

use alloy_primitives::{Address, U256};
use openzeppelin_stylus::token::erc20::{extensions::Erc20Flashmint, IErc20};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use openzeppelin_stylus::token::erc20::{
extensions::IERC3156FlashLender, Erc20, IErc20,
};
use stylus_sdk::{
abi::Bytes,
prelude::{entrypoint, public, sol_storage},
};

sol_storage! {
#[entrypoint]
struct Erc20FlashmintExample {
struct Erc20FlashMintExample {
#[borrow]
Erc20Flashmint erc20_flashmint;
Erc20 erc20;
}
}

#[public]
#[inherit(Erc20Flashmint)]
impl Erc20FlashmintExample {
pub fn transfer(
&mut self,
to: Address,
value: U256,
) -> Result<bool, Vec<u8>> {
self.erc20_flashmint.erc20.transfer(to, value).map_err(|e| e.into())
#[inherit(Erc20)]
impl Erc20FlashMintExample {
fn max_flash_loan(&self, token: Address) -> U256 {
self.erc20.max_flash_loan(token)
}

fn flash_fee(&self, token: Address, amount: U256) -> Result<U256, Vec<u8>> {
self.
//self.erc20._flash_fee(token, value);
self.erc20.flash_fee(token, amount).map_err(|e| e.into())
}

pub fn transfer_from(
fn flash_loan(
&mut self,
from: Address,
to: Address,
receiver: Address,
token: Address,
value: U256,
data: Bytes,
) -> Result<bool, Vec<u8>> {
self.erc20_flashmint
.erc20
.transfer_from(from, to, value)
self.erc20
.flash_loan(receiver, token, value, data)
.map_err(|e| e.into())
}
}

// Add token minting feature.
pub fn mint(
&mut self,
account: Address,
value: U256,
) -> Result<(), Vec<u8>> {
self.erc20_flashmint.erc20._mint(account, value)?;
Ok(())
impl Erc20FlashMintExample {
pub fn _flash_fee(&self, token: Address, value: U256) -> U256 {
let _ = token;
let _ = value;
// if self._flash_fee_amount.is_zero() {
return U256::MIN;
//}
//self._flash_fee_amount.get()
}

/// Returns the address of the receiver contract that will receive the flash
/// loan. The default implementation returns `Address::ZERO`.
pub fn _flash_fee_receiver(&self) -> Address {
// if self._flash_fee_receiver_address.eq(&Address::ZERO) {
// return self._flash_fee_receiver_address.get();
// }
Address::ZERO
}
}
7 changes: 2 additions & 5 deletions examples/erc20-flashmint/tests/erc20-flashloan.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#![cfg(feature = "e2e")]

use std::{assert_eq, println};
use std::{assert_eq, println};

use abi::Erc20Flashmint;
use alloy::{
primitives::{address, uint, Address, U256},
sol,
};
use e2e::{
receipt, send, Account, ReceiptExt,
Revert,
};
use e2e::{receipt, send, Account, ReceiptExt, Revert};
use eyre::Result;
// use stylus_sdk::contract::address;
use mock::borrower;
Expand Down
5 changes: 1 addition & 4 deletions examples/erc20-flashmint/tests/mock/borrower.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![allow(dead_code)]
#![cfg(feature = "e2e")]
use alloy::{
primitives:: Address,
sol,
};
use alloy::{primitives::Address, sol};
use e2e::Wallet;

sol! {
Expand Down

0 comments on commit ea3a9b3

Please sign in to comment.