Skip to content

Documentation

themandalore edited this page Jan 22, 2018 · 7 revisions

Documentation is noted for acting as the operator (DDA's role) and also entering both sides of the contract. Specific contract details are laid out for ease of use regardless of dev environment.

If you wish to simply enter a contract without a deep dive into the underlying solidity, you can use our DApp at drct.decentralizedderivatives.org and follow our video tutorial here: https://www.youtube.com/watch?v=NdBqfzAeHFg


For ease of use, an 'everything' flat file has been created containing all contracts in the DRCT_standard library.

    https://github.com/DecentralizedDerivatives/DRCT_standard/everything.sol

Setting up the environment

If one is accessing the contracts via the DApp or by way of an already deployed Factory contract, these steps will have been done for you.

Create the Oracle

Oracle Contracts provide the reference rates for the contract. Our oracle contract uses daily UNIX timestamp values as keys for specific values.

    create Oracle();

DDA will grab values for contract dates, however parties can also initiate the contract call(and must do so on private instances of the oracle). This function stores the daily value of the API in the Oracle.

    oracle.PushData();

For testing, you can use the Test_Oracle which allows you to store custom values in the contract.

    create Test_Oracle(); //as oracle hereafter if testing
    oracle.StoreDocument(1543881600, 1000);
    oracle.StoreDocument(1544486400,1200);

Create the Base Tokens

A DRCT contract is structured as trading one token for another at some future date, based upon the change in the underlying reference rate. We need to set the two tokens we are trading (aka our base tokens). For ease of use, one can use two separate wrapped Ether contracts (this is what the DApp uses).

 create WrappedEther();
 create WrappedEther():

Create Factory Contract

The factory contract is the base of the system. It holds the standardized variables and is called to create new contracts and create new DRCT tokens for the user.

create Factory();

Create Deployer and TokenDeployer

Due to gas limits on the network, the Factory contract could not hold all functionality. For this reason, the Deployer contract holds the task of deploying a new swap and is called by the factory contract. The TokenDeployer contract deploys DRCT tokens and is also used solely by the factory contract.

   create Deployer(factory.address);
   create Tokendeployer(factor._address);

Create UserContract

For wrapped Ether contracts, when creating a contract, it is required to deploy a contract from the Factory, wrap your Ether, enter specific details of the contract, and then transfer your wrapped Ether to the contract. In order to reduce the number of execution steps, the user contract reduces this step to: deploy contract and then enter using the User Contract.

create UserContract();
UserContract.setFactory(factory.address);

Set Factory Variables

 factory.setVariables(1000000000000000,1000000000000000,7,1); //token ratios, duration (days), multiplier (this is current DApp settings)
 factory.setBaseTokens(base1.address,base2.address);
 factory.setUserContract(userContract.address);
 factory.setDeployer(deployer.address);
 factory.settokenDeployer(tokenDeployer.address);
 factory.setOracleAddress(oracle.address);

The token ratio's simplify the number of DRCT tokens per base token. For wrapped Ether, one Ether gets you 1e18 tokens. To simplify this, we create a token ratio of 1e15 which means that for every one Ether worth of wrapped Ether, the party gets 1000 DRCT tokens. The duration is the number of days the contract lasts (from the start date onward). The multiplier is the number by which the reference rate is multiplied by. Note that this also limits the contract in terms of potential upside/downside. A multiplier of 10 means that if the underlying rate moves by 5%, the contract pays out based on a 50% change in the reference rate. Since contracts are capped at a 100% move in either direction, a multiplier of 10 will be capped at moves of 10%.

Create DRCT Tokens

The DRCT tokens are the ERC20 tokens that represent the specific shares in a contract. Since the contracts are standardized at the factory level, the DRCT tokens are interchangeable within the same DRCT token address (it does not matter what specific contract the DRCT token maps to). The token contract is expanded from normal ERC20 tokens to track the number and address of holders for use by the operator when paying out the contracts. If you are the first party to do a contract on a given start date, you will need to create the DRCT tokens.

 factory.deployTokenContract( 1516492800, true) ; 
 factory.deployTokenContract( 1516492800, false) ;

Creating and Entering contracts

 factory.deployContract();

Parties can now either enter the contract manually by going to the swap on their own, or they can use the userContract. If a party enters manually, they will be required to transfer the base tokens to the contract before DRCT tokens can be issued. The UserContract simplifies this process. The variables one needs to enter are: the contract address from the previous step, the amount of baseTokens for each side (they can be different), the amount of premium (in wei)(this is just a payment to the other side to incentivize liquidity), and then whether or not you are long or short (true is long, false is short).

UserContract.Initiate(contractAddress,baseToken_amountA,baseToken_amountB,premium,isLong);  //eg ("0x4c40e94a0f53747a4323cadeba4c995327fdee3b","10000000000000000000","10000000000000000000",0,true)

Once entered, a party must enter the other side. They can either do this manually via the TokentoTokenSwap contract, or they can use the UserContract as below. If done manually, one of the parties must manually 'createTokens()' in the contracts in order to use the DRCT_tokens and send the base tokens to the contracts. Note the variables for amount of base tokens must match the Initiating party's and the isLong must be opposite the initiating party's choice. Note that the entering party cannot be same address as the original party.

UserCotnract.Enter(baseToken_amountA,baseToken_amountB,isLong,contractAddress)

The users now have DRCT_tokens in the addresses specified for the long/short tokens in the Factory contract.

If the contract is not tokenized, parties may exit the contract (assuming both approve or only one in) using the method:

  TokenToTokenSwap.Exit();

Contract completion and redemption

The swap must be manually paid out after the end date. The contract loops through all token holders in the DRCT_token and then pays out the swap based upon who is holding the tokens. Once the tokens are paid out, the parties can then cash out or redeem their wrapped Ether (or they are now holding the base Token).

  TokentoTokenSwap.forcePay();


 WrappedEther.withdraw(amount);  //enter amount in wei