Skip to content

Latest commit

 

History

History
273 lines (234 loc) · 8.18 KB

File metadata and controls

273 lines (234 loc) · 8.18 KB

FakeCompoundStablecoinDelegator.sol

View Source: contracts/fakes/FakeCompoundStablecoinDelegator.sol

↗ Extends: ICompoundERC20DelegatorLike, ERC20

FakeCompoundStablecoinDelegator

Contract Members

Constants & Variables

contract FakeToken public stablecoin;
contract FakeToken public cStablecoin;

Functions

function (FakeToken _stablecoin, FakeToken _cStablecoin) public nonpayable ERC20 

Arguments

Name Type Description
_stablecoin FakeToken
_cStablecoin FakeToken
Source Code
constructor(FakeToken _stablecoin, FakeToken _cStablecoin) ERC20("cStablecoin", "cStablecoin") {
    stablecoin = _stablecoin;
    cStablecoin = _cStablecoin;
  }

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) {
    stablecoin.transferFrom(msg.sender, address(this), mintAmount);

    cStablecoin.mint(mintAmount);
    cStablecoin.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) {
    cStablecoin.transferFrom(msg.sender, address(this), redeemTokens);

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

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

    return 0;
  }

Contracts