Skip to content

Latest commit

 

History

History
279 lines (197 loc) · 6.73 KB

CFD.md

File metadata and controls

279 lines (197 loc) · 6.73 KB

CFD - take a 20x leveraged position on the future price of DAI.. or provide

liquidity to the market and earn staking rewards. Liquidation prices at 20x are 0.95<>1.05 (CFD.sol)

View Source: contracts/CFD.sol

CFD

Check out all this sweet code!

Structs

Stake

struct Stake {
 uint256 upLP,
 uint256 downLP,
 uint256 mintVolume,
 bool liquidated
}

Contract Members

Constants & Variables

address public makerMedianizer;
address public uniswapFactory;
address public daiToken;
contract UpDai public upDai;
contract DownDai public downDai;
contract IUniswapExchange public uniswapUpDaiExchange;
contract IUniswapExchange public uniswapDownDaiExchange;
uint256 public leverage;
uint256 public feeRate;
uint256 public settlementDate;
bool public inSettlementPeriod;
uint256 public daiPriceAtSettlement;
uint256 public upDaiRateAtSettlement;
uint256 public downDaiRateAtSettlement;
uint256 public totalMintVolumeInDai;
mapping(address => struct CFD.Stake) public stakes;

Events

event NeededEthCollateral(address indexed depositor, address indexed cfd, uint256 indexed amount, uint256  upDaiPoolEth, uint256  downDaiPoolEth);

Modifiers

notInSettlementPeriod

modifier notInSettlementPeriod() internal

Arguments

Name Type Description

onlyInSettlementPeriod

modifier onlyInSettlementPeriod() internal

Arguments

Name Type Description

Functions

constructor

function (address _makerMedianizer, address _uniswapFactory, address _daiToken, uint256 _leverage, uint256 _fee, uint256 _settlementDate, uint256 _version) public nonpayable

Arguments

Name Type Description
_makerMedianizer address maker medianizer address
_uniswapFactory address uniswap factory address
_daiToken address maker medianizer address
_leverage uint256 leverage (1000000000000000x) (1x == 1e18)
_fee uint256 payout fee (1% == 1e16)
_settlementDate uint256 maker medianizer address
_version uint256 which tranche are we on?

mint

mint UP and DOWN DAI tokens

function mint(uint256 _daiDeposit) external payable notInSettlementPeriod 

Arguments

Name Type Description
_daiDeposit uint256 amount of DAI to deposit

getETHCollateralRequirements

get the amount of ETH required to create a uniswap exchange

function getETHCollateralRequirements(uint256 _daiDeposit) public nonpayable
returns(uint256, uint256)

Returns

the amount of ETH needed for UPDAI pool and DOWNDAI pool

Arguments

Name Type Description
_daiDeposit uint256 the total amount of underlying to deposit (UP/DOWN DAI = _daiDeposit/2)

claimRewards

Claims all rewards that a staker is eligable for

function claimRewards() external nonpayable onlyInSettlementPeriod 

Arguments

Name Type Description

redeem

redeem a pair of UPDAI and DOWNDAI

function redeem(uint256 _redeemAmount) public nonpayable notInSettlementPeriod 

Arguments

Name Type Description
_redeemAmount uint256 Pair count where 1 real token == 1e18 base units

redeemFinal

redeem UPDAI or DOWNDAI token

function redeemFinal() public nonpayable onlyInSettlementPeriod 

Arguments

Name Type Description

_payout

$ payout function $

function _payout(address redeemer, uint256 upDaiUnits, uint256 downDaiUnits, uint256 upDaiRate, uint256 downDaiRate) internal nonpayable

Arguments

Name Type Description
redeemer address redeemer address
upDaiUnits uint256 units of UpDai
downDaiUnits uint256 units of DownDai
upDaiRate uint256 Rate of uDAI<>DAI
downDaiRate uint256 units of downDAI<>DAI

_getCurrentDaiRates

Based on the price of DAI, what are the current exchange rates for upDai and downDai?

function _getCurrentDaiRates(uint256 daiUsdPrice) public nonpayable
returns(upDaiRate uint256, downDaiRate uint256)

Returns

upDaiRate where 1:1 == 1e18

Arguments

Name Type Description
daiUsdPrice uint256 Dai price in USD where $1 == 1e18

GetDaiPriceUSD

get DAI price in USD

function GetDaiPriceUSD() public view
returns(relativePrice uint256)

Returns

relativePrice of DAI with regards to USD peg, where 1:1 == 1e18

Arguments

Name Type Description

GetETHUSDPriceFromMedianizer

Parses the bytes32 price from Makers Medianizer into uint

function GetETHUSDPriceFromMedianizer() public view
returns(uint256)

Returns

uint256 Medianised price where $1 == 1e18

Arguments

Name Type Description

Contracts