Skip to content

Latest commit

 

History

History
340 lines (292 loc) · 9.48 KB

MockFlashBorrower.md

File metadata and controls

340 lines (292 loc) · 9.48 KB

MockFlashBorrower.sol

View Source: contracts/mock/MockFlashBorrower.sol

↗ Extends: IERC3156FlashBorrower

MockFlashBorrower

Contract Members

Constants & Variables

contract IERC20 private _stablecoin;
contract IERC3156FlashLender private _provider;
bytes32 private _returnValue;
bool private _createsApproval;

Functions

function (IERC20 stablecoin, IERC3156FlashLender provider) public nonpayable

Arguments

Name Type Description
stablecoin IERC20
provider IERC3156FlashLender
Source Code
constructor(IERC20 stablecoin, IERC3156FlashLender provider) {
    _stablecoin = stablecoin;
    _provider = provider;
  }

setStablecoin

function setStablecoin(IERC20 value) external nonpayable

Arguments

Name Type Description
value IERC20
Source Code
function setStablecoin(IERC20 value) external {
    _stablecoin = value;
  }

setReturnValue

function setReturnValue(bytes32 value) external nonpayable

Arguments

Name Type Description
value bytes32
Source Code
function setReturnValue(bytes32 value) external {
    _returnValue = value;
  }

setCreateApproval

function setCreateApproval(bool value) external nonpayable

Arguments

Name Type Description
value bool
Source Code
function setCreateApproval(bool value) external {
    _createsApproval = value;
  }

borrow

function borrow(uint256 amount, bytes data) external nonpayable

Arguments

Name Type Description
amount uint256
data bytes
Source Code
function borrow(uint256 amount, bytes calldata data) external {
    uint256 allowance = _stablecoin.allowance(address(this), address(_provider));
    uint256 fee = _provider.flashFee(address(_stablecoin), amount);
    uint256 repayment = amount + fee;

    if (_createsApproval) {
      _stablecoin.approve(address(_provider), allowance + repayment);
    }

    _provider.flashLoan(this, address(_stablecoin), amount, data);
  }

onFlashLoan

function onFlashLoan(address initiator, address , uint256 , uint256 , bytes ) external view
returns(bytes32)

Arguments

Name Type Description
initiator address
address
uint256
uint256
bytes
Source Code
function onFlashLoan(
    address initiator,
    address, /*token*/
    uint256, /*amount*/
    uint256, /*fee*/
    bytes calldata /*data*/
  ) external view override returns (bytes32) {
    require(msg.sender == address(_provider), "FlashBorrower: Untrusted lender");
    require(initiator == address(this), "FlashBorrower: Untrusted loan initiator"); // solhint-disable-line
    return _returnValue;
  }

Contracts