Skip to content

Latest commit

 

History

History
273 lines (234 loc) · 7.97 KB

FakeCompoundDaiDelegator.md

File metadata and controls

273 lines (234 loc) · 7.97 KB

FakeCompoundDaiDelegator.sol

View Source: contracts/fakes/FakeCompoundDaiDelegator.sol

↗ Extends: ICompoundERC20DelegatorLike, ERC20

FakeCompoundDaiDelegator

Contract Members

Constants & Variables

contract FakeToken public dai;
contract FakeToken public cDai;

Functions

function (FakeToken _dai, FakeToken _cDai) public nonpayable ERC20 

Arguments

Name Type Description
_dai FakeToken
_cDai FakeToken
Source Code
constructor(FakeToken _dai, FakeToken _cDai) ERC20("cDAI", "cDAI") {
    dai = _dai;
    cDai = _cDai;
  }

mint

Sender supplies assets into the market and receives cTokens in exchange

function mint(uint256 mintAmount) external nonpayable
returns(uint256)

Arguments

Name Type Description
mintAmount uint256 The amount of the underlying asset to supply

Returns

uint 0=success, otherwise a failure (see ErrorReporter.sol for details)

Source Code
function mint(uint256 mintAmount) external override returns (uint256) {
    dai.transferFrom(msg.sender, address(this), mintAmount);

    cDai.mint(mintAmount);
    cDai.transfer(msg.sender, mintAmount);

    return 0;
  }

redeem

Sender redeems cTokens in exchange for the underlying asset

function redeem(uint256 redeemTokens) external nonpayable
returns(uint256)

Arguments

Name Type Description
redeemTokens uint256 The number of cTokens to redeem into underlying

Returns

uint 0=success, otherwise a failure (see ErrorReporter.sol for details)

Source Code
function redeem(uint256 redeemTokens) external override returns (uint256) {
    cDai.transferFrom(msg.sender, address(this), redeemTokens);

    uint256 interest = (redeemTokens * 3) / 100;
    dai.mint(interest);

    dai.transfer(msg.sender, redeemTokens + interest);

    return 0;
  }

Contracts