Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loans #38

Open
elicharlese opened this issue Feb 6, 2023 · 0 comments
Open

Loans #38

elicharlese opened this issue Feb 6, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@elicharlese
Copy link
Member

elicharlese commented Feb 6, 2023

use near_sdk::{env, near_bindgen, ext_contract, Promise};
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::collections::Vector;

#[ext_contract(ext_erc20)]
trait ExtERC20 {
    fn transfer(&mut self, receiver_id: AccountId, amount: u128) -> Promise;
    fn approve(&mut self, spender_id: AccountId, amount: u128) -> Promise;
    fn transfer_from(&mut self, owner_id: AccountId, new_owner_id: AccountId, amount: u128) -> Promise;
}

#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
struct Flashloan {
    erc20_contract: AccountId,
    amount: u128,
    data: String,
}

#[near_bindgen]
impl Flashloan {
    pub fn flashloan(&mut self, amount: u128, data: String) -> Promise {
        self.amount = amount;
        self.data = data;
        ext_erc20::approve(self.erc20_contract.clone(), amount);
        ext_erc20::transfer(self.erc20_contract.clone(), amount);
        ext_erc20::transfer_from(env::predecessor_account_id(), self.erc20_contract.clone(), amount);
        Promise::new(env::predecessor_account_id()).then(ext_erc20::transfer_from(
            self.erc20_contract.clone(),
            env::predecessor_account_id(),
            amount,
            1,
            &env::current_account_id(),
            0,
            env::prepaid_gas() - 10,
        ))
    }
}
@elicharlese elicharlese added the bug Something isn't working label Feb 6, 2023
@elicharlese elicharlese added this to the Front-End base for all dapps in Framer milestone Feb 6, 2023
@elicharlese elicharlese self-assigned this Feb 6, 2023
@elicharlese elicharlese removed this from the Front-End base for all dapps in Framer milestone Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant