Contracts

In this section, you can find the description of each contract in the system, along with all the external functions and public variables.

This section is intended more for developers to better understand how the system works in detail.

Dotflat

Note

This is a stablecoin token. It is a simple ERC-20 token, which can be minted and burned ONLY by CDP contract and those authorized in the DAO.

contract stableCoin is ERC20
IDAO immutable dao
Notice:

DAO interface.

constructor(address _INTDAOaddress)
ERC20("dot Flat coin", "DFC")
Notice:

Constructor for stableCoin contract.

Parameters:
  • _INTDAOaddress – address of the main DAO contract.

function mint(address to, uint256 amount)
external
Notice:

Minting additional stablecoins. Only an authorized address can execute this function.

Parameters:
  • to – Address to receive newly minted stablecoins.

  • amount – Amount of stablecoins to mint.

function burn(address from, uint256 amount)
external
Notice:

Burning stablecoins. Only an authorized address can execute this function.

Parameters:
  • from – Address to burn stablecoins from.

  • amount – Amount of stablecoins to burn.

CDP

Note

This contract is one of the most important contracts of the DAO. It mints Dotflat coins, holds all the collateral and the stabilization fund in Dotflat coins, and burns Dotflat stablecoins when the position is closed.

Note

Borrowing Dotflat tokens assumes an annual interest, determined by the DAO contract. For now, it is at 9% per annum.

Note

Inside the contract, each debt position is stored as the following structure.

struct Position {
    uint128 coinsMinted;
    uint128 wethAmountLocked;
    uint128 interestAmountRecorded;
    uint32 timeOpened;
    uint32 lastTimeUpdated;
    uint24 interestRate;
    uint32 markedOnLiquidationTimestamp;
    uint24 liquidationStatus;
    uint32 liquidationAuctionID;
    bool restrictInterestWithdrawal;
    address owner;
}
*coinsMinted* - number of minted coins for now.
*wethAmountLocked* - collateral.
*interestAmountRecorded* - the amount of interest to pay until last position update.
*timeOpened* - when the position was opened.
*lastTimeUpdated* - when it was last updated.
*interestRate* - annual percent of the debt.
*markedOnLiquidationTimestamp* - when the position was marked on liquidation.
*liquidationStatus* - 0 - ok, 1- markedOnLiquidation, 2 - onLiquidation, 3 - liquidated, 4 - closed;
*liquidationAuctionID* - ID of the auction, which sells collateral.
*owner* - address of the position owner.
*restrictInterestWithdrawal* - set this flag using *switchRestrictInterestWithdrawal()* method if you don’t want the system to make you pay interest any time it needs money.

By default, the system may ask for your Dotflat (only the interest, not the whole debt) anytime it needs it as a payment for the debt, but you may want to pay it in the end, for example.

Warning

If you use this contract for borrowing dotflat, be aware that you have to constantly monitor the sufficiency of your collateral yourself, as the price of ether changes frequently and significantly. If your collateral becomes insufficient due to a decrease in the Ether price or an increase in commodity prices, your Ether could be sold at auction. A margin call has a 13% fee, set in the DAO contract (liquidationFee).

The system checks the sufficiency of the collateral, and if it is insufficient, it may mark the position for liquidation by setting liquidationStatus as markedOnLiquidation and a liquidationStatusChanged event is fired.

After that, the owner has some time (marginCallTimeLimit regulated by the DAO; for now, it is 1 day) to top up the collateral or reduce the emission of Dotflat by returning some of the tokens.

If nothing happens and the collateral is still insufficient after 1 day, the system liquidates the collateral through auction, and the owner of the position can do nothing about it.

contract CDP is ReentrancyGuard
Title:

Collateral debt position contract

uint32 public numPositions
Notice:

Positions counter

IDAO immutable dao
Notice:

DAO interface.

IBasket basket
Notice:

Cart interface

IERC20MintableAndBurnable coin
Notice:

Stablecoin interface

IAuction auction
Notice:

Auction interface

IERC20MintableAndBurnable rule
Notice:

Governance tokens interface

mapping (uint32 => Position) public positions
Notice:

Struct to store all the positions

event PositionOpened(address indexed owner, uint256 indexed posID)
Notice:

This event is emitted when a new position is opened.

Parameters:
  • owner – Address of the owner of the position.

  • posID – ID of the position.

event PositionUpdated(uint32 indexed posID, uint256 newStableCoinsAmount, uint256 ethLocked)
Notice:

This event is emitted when a position is updated.

Parameters:
  • posID – ID of the position.

  • newStableCoinsAmount – New amount of stablecoins borrowed.

  • ethLocked – Current collateral amount.

event liquidationStatusChanged(uint32 indexed posID, uint24 liquidationStatus)
Notice:

This event is emitted when the position’s liquidation status is updated.

Parameters:
  • posID – ID of the position.

  • liquidationStatus – Current status.

event liquidateCollateral(uint32 indexed auctionID, uint32 indexed posID, uint256 collateral)
Notice:

This event is emitted when a position is set for liquidation.

Parameters:
  • auctionID – ID of the corresponding auction.

  • posID – ID of the position.

  • collateral – Amount of collateral to sell.

constructor(address _INTDAOaddress)
Notice:

Constructor for the CDP contract.

Parameters:
  • _INTDAOaddress – Address of the main DAO contract.

function renewContracts()
external
Notice:

This method is used to reinitialize the needed interfaces when the addresses of contracts are changed by voting or to initialize interfaces just after deployment.

function openCDP(uint256 stableCoinsToMint)
nonReentrant
external
payable
returns (uint256)
Notice:

Use this method to borrow stablecoins. To use it, you must provide sufficient collateral in Ether. The collateral is converted to WETH (wrapped ether) and stored as a wrapped Ether token in the contract address. The newly minted stablecoins will be sent to the caller’s account.

Parameters:
  • stableCoinsToMint – Number of stablecoins to mint.

Return:

The ID of your collateral debt position is returned.

function interestAmountUnrecorded(uint32 posID)
public
view
returns (uint256 interestAmount)
Notice:

Interest that has not yet been recorded for the debt position. It depends on the debt, the rate, and the time since the last position update.

Parameters:
  • posID – ID of the position.

Return:

interestAmount The amount of unrecorded interest.

function totalCurrentFee(uint32 posID)
public
view
returns (uint256 fee)
Notice:

Shows the overall interest of the debt position (both stored and unrecorded).

Parameters:
  • posID – ID of the position.

Return:

fee The total interest to pay.

function getMaxStableCoinsToMint(uint256 ethValue)
public
view
returns (uint256 amount)
Notice:

Shows how many coins can be minted with a given Ether collateral according to the current prices and collateral discount.

Parameters:
  • ethValue – Amount of collateral.

Return:

amount The maximum amount of stablecoins one can mint with a given collateral.

function getMaxStableCoinsToMintForPos(uint32 posID)
public
view
returns (uint256 maxAmount)
Notice:

Shows how many coins can be minted for a specific position considering changes in collateral amount or price. It accounts for the accumulated fee for the debt.

Parameters:
  • posID – ID of the position.

Return:

maxAmount The maximum amount of stablecoins one can mint for this position.

function claimInterest(uint256 amount, address beneficiary)
nonReentrant
external
Notice:

This method is for contracts authorized by the DAO only. For example, a Deposit contract may claim interest for the deposit owner, and the interest will be transferred from the stabilization fund. If there are not enough funds, all available funds are transferred, and an allowance is given for the remaining amount for future spending.

Parameters:
  • amount – Amount of interest to transfer.

  • beneficiary – Address of the beneficiary.

function claimEmission(uint256 amount, address beneficiary)
nonReentrant
external
Notice:

This method is for authorized contracts by the DAO only. For example, a new contract may claim emission according to its terms.

Parameters:
  • amount – Amount of stablecoins to mint.

  • beneficiary – Address of the beneficiary.

function closeCDP(uint32 posID)
nonReentrant
external
Notice:

This method is used to return collateral to the owner if they return the total debt and interest. It is for the position owner only.

Parameters:
  • posID – ID of the position.

function transferInterest(uint32 posID)
nonReentrant
external
Notice:

This method is used to pay the interest on the position if restrictInterestWithdrawal is not set by the owner. The earned interest is transferred to the CDP contract.

Parameters:
  • posID – ID of the position.

function switchRestrictInterestWithdrawal(uint32 posID)
external
Notice:

This method allows or disallows paying interest for a position by the owner only. By default, it is set to false, meaning that any user can force the owner to pay the current interest for their debt at any time on call.

Parameters:
  • posID – ID of the position.

function allowSurplusToAuction()
nonReentrant
external
Notice:

If the stabilization fund exceeds a certain percentage (stabilizationFundPercent DAO param) of the total Dotflat stablecoin emission, anyone can allow spending to the Auction contract for further governance token buyouts.

function claimMarginCall(uint32 posID)
nonReentrant
external
Notice:

If a debt position lacks collateral and is marked for liquidation, anyone may claim a margin call for it and sell the collateral through the auction.

Parameters:
  • posID – ID of the position.

function finishMarginCall(uint32 posID)
nonReentrant
external
Notice:

If the auction for the margin call has finished, the contract may proceed with the remaining actions.

Parameters:
  • posID – ID of the position.

function markToLiquidate(uint32 posID)
external
Notice:

If a debt position lacks collateral, anyone may mark it for liquidation.

Parameters:
  • posID – ID of the position.

function eraseMarkToLiquidate(uint32 posID)
public
Notice:

If a debt position has enough collateral but was previously marked for liquidation, anyone may remove this mark.

Parameters:
  • posID – ID of the position.

function updateCDP(uint32 posID, uint newStableCoinsAmount)
nonReentrant
external
payable
returns (bool success)
Notice:

Change the amount of minted stablecoins or increase the amount of collateral. To withdraw collateral, use the withdrawEther function.

Parameters:
  • posID – ID of the position.

  • newStableCoinsAmount – New amount of stablecoins.

Return:

success Whether or not the operation succeeded.

function withdrawEther(uint32 posID, uint128 etherToWithdraw)
nonReentrant
external
Notice:

Withdraw Ether from a position if it exceeds the minimum collateral value due to Ether price changes, for example.

Parameters:
  • posID – ID of the position.

  • etherToWithdraw – Amount of ether to withdraw.

function burnRule()
external
Notice:

Anyone can burn (eliminate) all Rule tokens held by the CDP contract. If not done accidentally, ule tokens can only be on the contract’s balance after a Rule buyout auction.

function mintRule(address to, uint256 amount)
external
returns (bool success)
Notice:

If the stabilization fund lacks sufficient funds, one may initiate an auction to top it up with dotflat stablecoins. The auction winner receives their reward in Rule tokens minted by the CDP contract.

Auction

Note

This contract is used for initiating and managing auctions and bids. Inside the contract each auction is stored as the following structure.

struct auctionEntity {
        bool initialized;
        bool finalized;
        address lotToken;
        uint lotAmount;
        address paymentToken;
        uint256 paymentAmount;
        uint256 initTime;
        uint256 lastTimeUpdated;
        uint32 bestBidID;
    }
*initialized* - .
*finalized* - .
*lotToken* - .
*lotAmount* -
*paymentToken* -
*paymentAmount* -
*initTime* -
*lastTimeUpdated* -
*bestBidID* -
And the bid stored as follows:
struct Bid {
    address owner;
    uint32 auctionID;
    uint256 bidAmount;
    uint256 time;
    bool canceled;
}
*owner* - address of the owner.
*auctionID* - .
*bidAmount* - .
*time* -
*canceled* - .

Note

There are 3 types of auctions, that may be created: - Selling the collateral of debt position if the holder of the position has not provided sufficient collateral for the stablecoins he has minted. - Rule tokens buyout if the stabilization fund exceeds its limit to reduce Rule total supply. - Dotflat buyout to top up stabilization fund with newly Rule token minted as a reward.

contract Auction is ReentrancyGuard
Title:

A Contract for Different Types of Auctions

uint32 public auctionNum
Notice:

Auctions counter

uint32 public bidsNum
Notice:

Bids counter

IERC20 coin
Notice:

Stablecoin interface

IDAO immutable dao
Notice:

DAO contract interface

ICDP cdp
Notice:

CDP contract interface

IERC20 rule
Notice:

Governance token interface

bool isCoinsBuyOutForStabilization
Notice:

Flag indicating that there is an active auction to top up the stabilization fund.

bool ruleBuyOut
Notice:

Flag indicating that there is an active auction for governance token buyout.

mapping (uint32 => auctionEntity) public auctions
Notice:

Mapping storing all existing auctions.

mapping (uint32 => Bid) public bids
Notice:

Mapping storing all existing bids.

event newAuction(uint8 auctionType, uint32 indexed auctionID, uint256 lotAmount, address lotAddress, uint256 paymentAmount)

You can catch this event to participate in auction automatically.

Notice:

This event is emitted when a new auction is created. Follow this event to participate in auctions.

Parameters:
  • auctionType – Type of the auction 1 - Rule buyout, 2 - stablecoins buyout, 3 - collateral liquidation

  • auctionID – The ID of the new auction.

  • lotAmount – The amount of the asset that the winner will receive.

  • lotAddress – Token address of the asset.

  • paymentAmount – The minimum amount of payment required for the lot. This is non-zero only if topping up the stabilization fund with a certain amount of stablecoins.

event auctionFinished(uint32 indexed auctionID, uint256 lotAmount, uint32 bestBidID)
Notice:

This event is emitted when an auction finishes.

Parameters:
  • auctionID – The ID of the finished auction.

  • lotAmount – The amount of the asset that the winner will receive.

  • bestBidID – The ID of the best bid.

event newBid(uint32 indexed auctionID, uint32 indexed bidID, uint256 bidAmount, address owner)
Notice:

This event is emitted when a new bid is created or an existing bid is improved. Follow this event to improve your bids.

Parameters:
  • auctionID – The ID of the auction.

  • bidID – The ID of the bid.

  • bidAmount – The amount of the bid.

  • owner – Address of the bidder.

event bidCanceled(uint256 indexed bidID)
Notice:

This event is emitted when a bid is canceled. You cannot cancel your bid if it is currently the best one.

Parameters:
  • bidID – The ID of the bid.

constructor(address _INTDAOaddress)
Notice:

Constructor for the auction contract.

Parameters:
  • _INTDAOaddress – The address of the main DAO contract.

function renewContracts()
external
Notice:

Reinitialize the needed interfaces when the addresses of contracts are changed by voting or initialize interfaces after deployment.

function initRuleBuyOut()
nonReentrant
external
returns (uint32 auctionID)
Notice:

Initiates an auction for Rule buyout when the stabilization fund on the CDP contract exceeds its limit.

Return:

auctionID New auction ID.

function initCoinsBuyOutForStabilization(uint256 coinsAmountNeeded)
nonReentrant
external
returns (uint32 auctionID)
Notice:

Initiates a stablecoin buyout for the stabilization fund if it is low. The stabilization fund should always be a certain percentage of the total stablecoin supply (as defined by the stabilizationFundPercent parameter in the DAO contract). The maximum stablecoins per auction is regulated by the maxCoinsForStabilization parameter in the DAO contract.

Parameters:
  • coinsAmountNeeded – The amount of stablecoins needed.

Return:

auctionID New auction ID.

function initCoinsBuyOut()
nonReentrant
payable
external
returns (uint32 auctionID)
Notice:

Initiates an auction if a margin call occurs and the system needs to sell the collateral.

Return:

auctionID New auction ID.

function makeBid(uint32 auctionID, uint256 bidAmount)
nonReentrant
external
returns (uint32 bidID)
Notice:

Use this method to place a new bid. Ensure you have allowed the needed amount for the Auction contract address. The minAuctionPriceMove percentage (from the DAO contract) means you must improve the previous best bid by a certain percentage.

Parameters:
  • auctionID – The ID of the auction to participate in.

  • bidAmount – The amount of the bid.

Return:

bidID New bid ID.

function improveBid(uint32 bidID, uint256 newBidAmount)
nonReentrant
external
Notice:

Use this method to improve your own bid.

Parameters:
  • bidID – The ID of your bid.

  • newBidAmount – The new bid amount.

function cancelBid(uint32 bidID)
nonReentrant
external
Notice:

Use this method to cancel your own bid. Note that you cannot cancel your bid if it is currently the best one.

Parameters:
  • bidID – The ID of your bid.

function claimToFinalizeAuction(uint32 auctionID)
nonReentrant
external
returns (bool success)
Notice:

If there are no more bids and the timeout has expired, you can claim to finalize the auction. For auctions involving collateral, use the finishMarginCall method from the CDP contract.

Parameters:
  • auctionID – The ID of the auction to finalize.

function isFinalized(uint32 auctionID)
external
view
returns (bool finalized)
Notice:

Shows whether a certain auction is finished or not.

Parameters:
  • auctionID – The ID of the auction.

function getPaymentAmount(uint32 auctionID)
external
view
returns (uint256)
Notice:

Shows the payment amount required for an auction. This is mainly used when collateral is sold.

Parameters:
  • auctionID – The ID of the auction.

function getBestBidAmount(uint32 auctionID)
external
view
returns (uint256)
Notice:

Shows the current best bid amount for an auction.

Parameters:
  • auctionID – The ID of the auction.

Deposit

Note

This contract is used for depositing stablecoins and earning annual interest. The amount of interest is renewed every block. Inside the contract each deposit is stored as the following structure.

struct Deposit {
    address owner;
    uint256 coinsDeposited;
    uint256 timeOpened;
    uint256 period;
    uint256 currentInterestRate;
    uint256 lastTimeUpdated;
    uint256 accumulatedInterest;
    bool closed;
}
*owner* - address of the owner.
*coinsDeposited* - amount of funds deposited.
*timeOpened* - when the deposit was opened.
*period* - the period of the deposit. It is set as *timeOpened* plus *defaultDepositPeriod* from DAO contract. It is used for the situations, when interest rate may be changed, but the current deposit should be effected by the change.
*currentInterestRate* - interest rate of the deposit.
*lastTimeUpdated* - when deposit was updated.
*accumulatedInterest* - as owner may top up deposit or withdraw funds, we should remember the interest, accumulated before the change.
*closed* - if the deposit already closed;
contract DepositContract is ReentrancyGuard
Title:

Deposit contract

IDAO immutable dao
Notice:

DAO interface.

IERC20 coin
Notice:

stablecoin interface.

ICDP cdp
Notice:

CDP interface.

uint32 public depositsCounter
Notice:

Counter for deposits.

mapping (uint32 => Deposit) public deposits
Notice:

Mapping storing all deposits.

event DepositOpened(uint32 indexed id, uint256 amount, uint256 rate, address indexed owner)
Notice:

Emitted when a new deposit is opened.

Parameters:
  • id – ID of the deposit.

  • amount – Amount of stablecoins deposited.

  • rate – Annual interest rate on the deposit.

  • owner – Address of the deposit owner.

constructor(address _INTDAOaddress)
Notice:

Constructor for the Deposit contract.

Parameters:
  • _INTDAOaddress – Address of the main DAO contract.

function renewContracts()
external
Notice:

Reinitialize the needed interfaces when the addresses of contracts are changed by voting or initialize interfaces just after deployment.

function deposit()
nonReentrant
external
Notice:

Deposits stablecoins into the contract. Ensure that spending is allowed for this contract address before calling this function. A DepositOpened event is emitted with the owner and other relevant parameters.

function withdraw(uint32 id, uint256 amount)
nonReentrant
external
Notice:

Withdraws stablecoins from the deposit. Only the owner of the deposit can withdraw funds. If the deposit balance reaches zero, it is considered closed.

Parameters:
  • id – The ID of the deposit.

  • amount – The amount of funds to withdraw.

function topUp(uint32 id)
nonReentrant
external
Notice:

Tops up an existing deposit if it is not closed. Ensure that you are the owner of the deposit and that you have allowed spending for the contract. You may accidentally top up someone else’s deposit, so verify the deposit ID carefully.

Parameters:
  • id – The ID of the deposit.

function overallInterest(uint32 id)
public
view
returns (uint256 interest)
Notice:

Returns the overall accumulated interest for a given deposit.

Parameters:
  • id – The ID of the deposit.

Return:

interest Overall accumulated interest.

function updateInterest(uint32 id)
public
returns (uint256 accumulated)
Notice:

Updates the stored interest to reflect the current rate. Users generally do not need to invoke this unless they want to update their interest rate to the current one if it has changed.

Parameters:
  • id – The ID of the deposit.

Return:

accumulated Overall accumulated interest.

function claimInterest(uint32 id)
nonReentrant
external
Notice:

Claims the accumulated interest while keeping the principal funds in the deposit. The owner’s earnings will be transferred from the stabilization fund (CDP balance of stablecoins) if available. If the CDP balance is insufficient, the contract will transfer all available funds to the user and provide an allowance to spend the remaining amount. To top up the stabilization fund, one can initiate an auction using the initCoinsBuyOutForStabilization function in the Auction contract.

Parameters:
  • id – The ID of the deposit.

function getInterest(uint32 id)
internal

DAO

Note

This contract is the main contract of the system. It stores all the valuable parameters of the system as well as all the addresses of contracts participating in the system. Also, this contract is responsible for managing voting for Rule holders.

If any user has enough Rules to initiate voting (minRuleTokensToInitVotingPercent; for now, it is set to 1%), he or she may propose a vote for the change of any parameter of the system or a significant address, to pause/unpause or authorize contracts.

To participate in a vote after it is initialized, a user has to pool tokens in the DAO contract address to prove ownership and to avoid passing tokens to other users until the voting is over.

If there is a quorum (quorum is now set to 60% of the total Rule supply), a decision can be made. A vote has a 1-day duration (votingDuration), but this is an optional parameter that can be changed by another vote.

The decision affects the system if it has the majority of positive votes. For now, the majority is 50% (optional parameter).

If there is an absolute majority of positive votes (absoluteMajority is 80% of the total Rule supply), the vote may be finished immediately.

After the vote is finished, the user can return pooled Rule tokens from the DAO contract. If the user returns tokens before the vote is finished, the vote will not be taken into consideration.

Each vote is stored as the following structure:

struct Voting {
    uint256 totalPositive;
    uint8 votingType;
    string name;
    uint256 value;
    address addr;
    uint256 startTime;
    bool decision;
}
*totalPositive* - total positive votes on voting.
*votingType* - type of the vote: 1 - set the parameter value, 2 - set the address, 3 - pause/unpause a contract, 4 - authorize/deauthorize a contract.
*name* - name of the parameter or contract.
*value* - value for the parameter (type 1 voting).
*addr* - value for the address (type 2 voting).
*startTime* - start time of the voting;
*decision* - bool decision for 3 and 4 type voting; If it is set to false and the vote has a majority of positive votes, the contract will be set to unpause/unauthorize correspondingly.

Initial parameters are as follows:

params["interestRate"] = 9;
params["depositRate"]=8;
params["liquidationFee"] = 13;
params["collateralDiscount"] = 30;
params["stabilizationFundPercent"] = 5;
params["quorum"] = 60;
params["majority"] = 50;
params["minCDPBalanceToInitBuyOut"] = 10**19;
params["absoluteMajority"] = 80;
params["minRuleTokensToInitVotingPercent"] = 1;
params["votingDuration"] = 1 days;
params["auctionTurnDuration"] = 15 minutes;
params["minAuctionPriceMove"] = 5;
params["marginCallTimeLimit"] = 1 days;
params["defaultDepositPeriod"] = 91 days;
params["maxCoinsForStabilization"] = 50*10**18;
params["maxRuleEmissionPercent"] = 1;
params["highVolatilityEventBarrierPercent"] = 5;
params["minCoinsToMint"] = 1;
contract INTDAO is ReentrancyGuard
Title:

Interest DAO

IERC20 ruleToken
Notice:

Rule token interface

mapping (uint32 => mapping (address => uint256)) votes
Notice:

Storage of votes

mapping (uint32 => Voting) public votings
Notice:

Storage of votings

uint32 public votingID
Notice:

Voting counter

bool public activeVoting
Notice:

Active voting presence flag, as there can be only one active voting.

mapping (string => uint256) public params
Notice:

Storage for parameters

mapping (string => address) public addresses
Notice:

Storage for addresses

mapping (address => bool) public paused
Notice:

Storage for paused contracts

mapping (address => bool) public isAuthorized
Notice:

Storage for authorized contracts

mapping (address => uint256) public pooled
Notice:

Storage for pooled Rule tokens for each holder

uint256 public totalPooled
Notice:

Total pooled tokens

event NewVoting(uint32 indexed id, string name, string indexed indexedName)
Notice:

Event emitted when new voting is created

Parameters:
  • id – ID of the voting

  • name – Name of the parameter or address

  • indexedName – The same as name, introduced for dapp usage

event VotingSucceed(uint32 indexed id)
Notice:

Event emitted when voting succeeds

Parameters:
  • id – ID of the voting

event VotingFailed(uint32 indexed id)
Notice:

Event emitted when voting finishes but fails

Parameters:
  • id – ID of the voting

constructor(address[] memory _addresses)
Notice:

Constructor of the Interest DAO contract, where all the parameters of the system are initialized

Parameters:
  • _addresses – Initial addresses of each contract in the DAO

function renewContracts()
public
Notice:

This method is used to change the Rule token address if it was changed during voting for some reason

function addVoting(uint8 votingType, string memory name, uint value, address addr, bool decision)
external
Notice:

Method to initiate a new voting

Parameters:
  • votingType – Type of the voting

  • name – Name of the parameter or address

  • value – Value of the parameter (for type 1 voting)

  • addr – Address value (for type 2 voting)

  • decision – True/False for type 3 and 4 voting

function poolTokens()
nonReentrant
external
returns (bool success)
Notice:

Pool tokens on the contract to participate in voting

Return:

success True if successful

function returnTokens()
nonReentrant
external
returns (bool)
Notice:

Return tokens from the contract after voting is finished

Return:

True if successful

function vote(bool _vote)
nonReentrant
external
Notice:

Vote on the current voting

Parameters:
  • _vote – True/False for For/Against the proposal

function claimToFinalizeCurrentVoting()
nonReentrant
external
Notice:

Claim to finish voting

Basket

Note

This contract is used to store all the commodities with initial prices and the share of each commodity. It also has a *getEthereumVSCommoditiesPriceChange* method to calculate the number of Dotflat coins per 1 ether according to the current prices.

Item are stored it in the structure .. code-block:

struct basketItem {
    string symbol;
    uint16 share;
    uint256 initialPrice;
}
*symbol* - symbol of the basket item.
*share* - share of an item in the basket.
*initialPrice* - price of the item when it was first added.
contract basketContract
IDAO immutable dao
Notice:

DAO interface to interact with (initializes in constructor)

IOracle oracle
Notice:

Oracle interface to interact with (initializes in renewContracts).

uint16 public itemsCount
Notice:

Items counter.

uint16 public sharesCount
Notice:

Total shares counter.

uint8 public constant decimals
Notice:

Number of decimals for each item.

mapping (uint16 => basketItem) public items
Notice:

Mapping to store all the items. Each basketItem is a struct of (symbol, share, initialPrice).

mapping (string => uint16) public dictionary
Notice:

Mapping to store pairs (symbol, itemID).

event instrumentAdded(uint16 id)
Notice:

Emitted when a new instrument is added.

Parameters:
  • id – Item ID.

event shareChanged(uint16 id)
Notice:

Emitted when the share of a certain instrument is changed.

Parameters:
  • id – Item ID.

constructor(addresspayable _INTDAOaddress)
Notice:

Constructor for the basket contract.

Parameters:
  • _INTDAOaddress – The address of the main DAO contract.

function renewContracts()
external
Notice:

This method is used when the addresses of contracts to use are changed by voting or just after deployment.

function addItem(string memory symbol, uint16 share, uint256 initialPrice)
external
Notice:

This method is to add an additional commodity to the basket by the authorized address only. An event with a new item ID is emitted.

Parameters:
  • symbol – The symbol of the new item. For example, ‘Copper’.

  • share – The share of the new item. The share is used to estimate the weight of a certain item in the basket, so the price change of gold may be more significant for the whole basket than the orange juice price change.

  • initialPrice – Initial price of an item. For instance, 2500 USD for gold.

function setShare(uint16 id, uint16 share)
external
Notice:

This method is used to change the share (or weight) of a particular item in the basket.

Parameters:
  • id – Item ID.

  • share – New share of the item in the basket. To delete a particular item from the basket, you may set a 0 share.

function getCurrentSharePriceChange()
public
view
returns (uint256 priceChange)
Notice:

Method is used to calculate the price change of 1 share of the basket. The total shares of all items are stored in sharesCount. For each item in the basket, the method multiplies the share of an item by its price change (current item price - initial item price) and then sums it to get the overallBasketPrice.

Return:

priceChange The method returns the overallBasketPrice divided by sharesCount. Thus, we can estimate the change of one basket share price according to the price change of each item in the basket and its share in it.

function getEthereumVSCommoditiesPriceChange()
external
view
returns (uint256)
Notice:

Returns the actual price of Ethereum versus basket share price change.

function getPrice(string memory symbol)
public
view
returns (uint256)
Notice:

Returns the actual price of the given commodity.

Parameters:
  • symbol – The symbol of the item in the basket. For example, ‘GLD’.

function getDecimals(string memory symbol)
public
view
returns (uint8 _decimals)
Notice:

getDecimals returns the precision (the number of decimals) for each item in the basket as the price is stored as an integer. For example, if a price is 460000 and an item has 5 decimals, it means the price is 4.6 per one quote of an item.

exchangeRate

Note

This contract is created to receive and store quotes of all needed instruments from the oracle. Quotes are taken from exchanges. The oracle has its own schedule to write down fresh quotes. A user may invoke one of the methods with a list of instruments if he wants them to be updated out of schedule.

To save gas, instruments are stored in two structures.

struct Instrument {
    uint256 price;
    uint128 timeStamp;
}

struct InstrumentDescription {
    uint16 id;
    string name;
    uint8 decimals;
}
contract exchangeRateContract
Title:

exchange rate - the contract to receive quotes from oracle.

IDAO immutable dao
Notice:

DAO interface.

uint16 public instrumentsCount
Notice:

Counter for instruments.

uint256 constant public updOnePriceGasCost
Notice:

Gas price to pay if someone wants the oracle to send a quote update out of schedule for one instrument.

uint256 constant public updSeveralPricesCost
Notice:

Gas price to pay if someone wants the oracle to send a quote update out of schedule for several instruments.

uint256 constant public updAdditionalPrice
Notice:

Gas price to pay if someone wants the oracle to send a quote update out of schedule for every additional instrument in a bundle.

address public author
Notice:

Address of the author of this contract.

address public beneficiary
Notice:

Address to receive profit gained by this contract from out-of-schedule updates.

address public updater
Notice:

Authorized address to send updates.

bool public finalized
Notice:

The contract may be finalized, which means the beneficiary address cannot be changed anymore.

mapping (uint16 => Instrument) public instruments
Notice:

Instrument storage.

mapping (string => InstrumentDescription) public dictionary
Notice:

InstrumentDescription dictionary.

constructor(address _INTDAOaddress)
payable
Notice:

Constructor for the exchangeRateContract contract.

Parameters:
  • _INTDAOaddress – The address of the main DAO contract.

event priceUpdateRequest(uint16 id)
Notice:

Emitted when someone requests to update a single quote.

Parameters:
  • id – ID of the instrument.

event severalPricesUpdateRequest(uint16[] ids)
Notice:

Emitted when someone requests to update several quotes.

Parameters:
  • ids – Array of IDs.

event priceUpdated(uint16 id)
Notice:

Emitted when the price of a certain instrument is updated.

Parameters:
  • id – ID of the instrument.

event profit(uint256 profit)
Notice:

Event for transferring the profit of the contract.

Parameters:
  • profit – Amount of profit obtained.

event highVolatility(uint16 id)
Notice:

Event emitted when the price of a given instrument changes more than the highVolatilityEventBarrierPercent from DAO.

Parameters:
  • id – ID of the instrument.

function changeBeneficiaryAddress(addresspayable newAddress)
external
onlyAuthor
Notice:

Change the address to receive profit.

Parameters:
  • newAddress – New address.

function finalize()
external
onlyAuthor
Notice:

Make the change of the beneficiary address impossible.

function changeUpdaterAddress(addresspayable newAddress)
external
onlyAuthor
Notice:

Change the address to receive transactions with quotes.

Parameters:
  • newAddress – New address

function requestPriceUpdate(uint16 id)
external
payable
Notice:

Request a price update. A payable function.

Parameters:
  • id – ID of the instrument.

function requestMultiplePricesUpdate(uint16[] memory ids)
external
payable
Notice:

Request multiple prices update.

Parameters:
  • ids – Array of IDs.

function updateSeveralPrices(uint16[] memory ids, uint256[] memory prices)
external
onlyUpdater
Notice:

Update several prices. Only the updater address may invoke it.

Parameters:
  • ids – Array of IDs

  • ids – Array of prices

function transferProfit()
external
Notice:

Method to transfer profit.

function updateSinglePrice(uint16 id, uint256 newPrice)
external
onlyUpdater
Notice:

Method to update a single price.

Parameters:
  • id – ID of the instrument.

  • newPrice – New price.

function updPrice(uint16 id, uint256 newPrice)
internal
function addInstrument(string memory symbol, string memory name, uint8 decimals)
external
onlyUpdater
returns (uint16 id)
Notice:

Method to add an instrument to storage. It is for updater only.

Parameters:
  • symbol – Symbol of the instrument.

  • name – Name of the instrument.

  • decimals – Number of decimals in the price.

Return:

id ID of the new instrument.

function updateInstrument(string memory symbol, string memory name, uint8 decimals)
external
onlyUpdater
Notice:

Method to update the name and decimals of the instrument. For updater only.

Parameters:
  • symbol – Symbol of the instrument.

  • name – Name of the instrument.

  • decimals – Number of decimals in the price.

function getPrice(string memory symbol)
external
view
returns (uint256)
Notice:

Getter of the current price of the instrument.

Parameters:
  • symbol – Symbol of the instrument.

Return:

Price.

function timeStamp(string memory symbol)
external
view
returns (uint256)
Notice:

Getter of the last time the price was updated for the given instrument.

Parameters:
  • symbol – Symbol of the instrument

Return:

timeStamp

function getDecimals(string memory symbol)
external
view
returns (uint8)
Notice:

Getter of decimals for the given instrument.

Parameters:
  • symbol – Symbol of the instrument

Return:

decimals

Rule

Note

This is a governance token, a simple ERC-20 contract, which can be minted and burned *ONLY* by the CDP contract. It is minted when the CDP contract lacks funds in the stabilization fund to refill it, and burned when the stabilization fund exceeds its limit. As there is a difference between debt and deposit rates, sooner or later the Rule tokens will be in demand, and thus their price should grow.

contract Rule is ERC20
IDAO immutable dao
Notice:

DAO interface.

constructor(address _INTDAOaddress)
ERC20("Rule token", "RLE")
Notice:

Constructor for the Rule contract. It mints the initial Rule supply to the creator.

Parameters:
  • _INTDAOaddress – Address of the main DAO contract.

function mint(address to, uint256 amount)
public
Notice:

Mint additional Rule tokens. Only an authorized address can execute it.

Parameters:
  • to – Address to receive newly minted tokens.

  • amount – Amount of tokens to mint.

function burn(address from, uint256 amount)
public
Notice:

Burn Rule tokens. Only an authorized address can execute it.

Parameters:
  • from – Address to burn tokens from.

  • amount – Amount of tokens to burn.