ERC20 Market

A pair lending market in which a user can borrow dinero by using an ERC20 as collateral.

Open Zeppelin Contracts

treasury

function treasury() external view returns(address);
Summary
It returns the treasury's address.

COLLATERAL

function COLLATERAL() external view returns(address);
Summary
It returns the address of the collateral token supported by this market.

liquidationFee

function liquidationFee() external view returns(uint96);
Summary
It is the penalty a user must pay when liquidated. It is a percentage, 1e18 being 100%.

maxBorrowAmount

function maxBorrowAmount() external view returns(uint128);
Summary
It returns the maximum amount of Dinero this contract can lend out.

maxLTVRatio

function maxLTVRatio() external view returns(uint128);
Summary
It returns the maximum loan-to-value ratio a user can have before being liquidated. It is a percentage, 1e18 being 100%.

loan

function loan() external view returns(
uint128 elastic,
uint128 base
);
Summary
It returns information regarding a loan. The base represents the loan shares, and the elastic is the total amount owed.

loanTerms

function loanTerms() external view returns(
uint128 lastAccrued, // Last block in which we have calculated the total fees owed to the protocol.
uint128 interestRate, // INTEREST_RATE is charged per second and has a base unit of 1e18.
uint128 dnrEarned, // How many fees have the protocol earned since the last time the {owner} has collected the fees.
uint128 collateralEarned
);
Summary
It returns important information about the loan.
  1. 1.
    lastAccrued: The loan has been updated up to this block.
  2. 2.
    interestRate: The cost of borrowing dinero. It is an annual percentage expressed in seconds.
  3. 3.
    dnrEarned: Profit from borrowing Dinero. It represents how much Dinero can be minted to the treasury as profit.
  4. 4.
    collateralEarned: Profit accrued from liquidations.

accountOf

function accountOf(address user) external view returns(
uint128 collateral,
uint128 principal
);
Parameters:
  1. 1.
    The account for this user will be returned.
Summary
It returns how much collateral and principal a user has in this contract.

getDineroEarnings

function getDineroEarnings() external;
Event
event GetDineroEarnings(address indexed treasury, uint256 amount);
Summary
It mints the treasury's profit from lending Dinero.

getCollateralEarnings

function getCollateralEarnings() external;
Event
event GetCollateralEarnings(address indexed treasury, uint256 amount);
Summary
It mints the treasury's profit from lending Dinero.

accrue

function accrue() external;
Event
event Accrue(uint256 accruedAmount);
Summary
It mints the treasury's profit from lending Dinero.

deposit

function deposit(address to, uint256 amount) external;
Parameters
  1. 1.
    Address that will receive the collateral sent by the msg.sender.
  2. 2.
    The number of tokens to deposit.
Restrictions
  • approval: The msg.sender has to give approval to the contract.
  • require: To argument address cannot be the zero address.
  • require: The amount cannot be zero.
Event
event Deposit(address indexed from, address indexed to, uint256 amount);
Summary
It allows a user to deposit an ERC20 as collateral.

withdraw

function withdraw(address to, uint256 amount) external;
Parameters
  1. 1.
    The msg.sender will withdraw his/her tokens to this address.
  2. 2.
    The number of tokens to withdraw.
Restrictions
  • require: The amount cannot withdraw zero tokens.
  • isSolvent modifier: The msg.sender LTV must remain below the contract's maxLTVRatio.
Event
event Withdraw(address indexed from, address indexed to, uint256 amount);
Summary
It allows a user to withdraw collateral from the contract.

borrow

function borrow(address to, uint256 amount) external;
Parameters
  1. 1.
    The address that will receive the borrowed Dinero.
  2. 2.
    The amount of Dinero to borrow.
Restrictions:
  • isSolvent modifier: The msg.sender LTV must remain below the contract's maxLTVRatio.
  • maxBorrowAmount: The total amount lent out must be below this value.
Event
event Borrow(
address indexed borrower,
address indexed receiver,
uint256 principal,
uint256 amount
);
Summary
It allows the msg.sender to borrow Dinero.

repay

function repay(address account, uint256 amount) external;
Parameters
  1. 1.
    The msg.sender will pay the debt of this account.
  2. 2.
    The principal to repay.
Event
event Repay(
address indexed payer,
address indexed payee,
uint256 principal,
uint256 amount
);
The second argument in the function is the principal to repay. The amount of Dinero will be higher as it includes the interest rate cost.
Summary
It allows the msg.sender to repay the debt of an account.

request

function request(uint256[] calldata requests, bytes[] calldata requestArgs)
external;
Parameters
  1. 1.
    A list of requests to process.
    • The number 0 represents a deposit request.
    • The number 1 represents a withdrawal request.
    • The number 2 represents a borrow request.
    • The number 3 represents a repayment request.
  2. 2.
    A list of the arguments to call the requested function with. It is packed as an array of bytes.
The requests and requestArgs must have the same length.
Restrictions:
  • isSolvent modifier: The msg.sender LTV must remain below the contract's maxLTVRatio.
  • maxBorrowAmount: The total amount lent out must be below this value.
Event
event Deposit(address indexed from, address indexed to, uint256 amount);
event Withdraw(address indexed from, address indexed to, uint256 amount);
event Borrow(
address indexed borrower,
address indexed receiver,
uint256 principal,
uint256 amount
);
event Repay(
address indexed payer,
address indexed payee,
uint256 principal,
uint256 amount
);
Summary
It bundles several transactions. Instead of calling the deposit and withdraw functions separately, a user calls the request function with the appropriate data. It supports withdrawing, depositing, borrowing, and repaying. It has the same restrictions as the individual functions.

liquidate

function liquidate(
address[] calldata accounts,
uint256[] calldata principals,
address recipient,
bytes calldata data
) external;
Parameters
  1. 1.
    An array of accounts to be liquidated.
  2. 2.
    An array containing the number of shares to liquidate.
  3. 3.
    The address that will receive the reward for closing underwater positions.
  4. 4.
    Arbitrary data to call the recipient with. If this argument is not empty, the contract will assume this is a contract with the following interface
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.9;
interface ISwap {
function sellOneToken(
bytes calldata data,
address token,
uint256 amount,
uint256 debt
) external;
}
Restrictions:
  • require: The Accounts must have underwater positions.
Event
event Liquidate(
address indexed liquidator,
address indexed debtor,
uint256 principal,
uint256 debt,
uint256 fee,
uint256 collateralPaid
);
It allows third parties to maintain the system afloat by closing underwater positions. They receive a reward fee. By the end of the transaction, the msg.sender has enough Dinero to cover the amount liquidated. The caller will receive the collateral beforehand.
This contract uses the UUPS upgradeable pattern. Therefore, the interfaces and functionalities can change in the future.