Skip to content

Latest commit

 

History

History
127 lines (92 loc) · 10 KB

yip-11.md

File metadata and controls

127 lines (92 loc) · 10 KB
yip title type author discussions-to status created updated
11
DDEX Lending Opportunity
Opportunity
Sam Mitchell @samatstaked, Devan Purhar @dpurhar27
WIP
2020-02-03
2020-08-26

Simple Summary

DDEX is a decentralized margin trading platform built on Ethereum that launched the current version of their protocol in October 2019. It operates similarly to Compound, dYdX and bZx - users can supply funds to a pool and earn interest, and they can borrow off of posted collateral.

Abstract

DDEX must be integrated as an opportunity before RAY can allocate funds. Technically, integrating DDEX will be very similar to the existing lending protocol opportunities in RAY.

Motivation

Expanding the opportunity set to include DDEX will give deposited funds another opportunity to outperform the benchmark rate.

Yield Evaluation

DDEX offers an interest-earning opportunity on ETH, DAI, and USDC. DDEX lending pools size as of the time writing: ETH - 1,548, DAI - 20,000, USDC - 250,000. DDEX therefore offers a substantial opportunity in both ETH and USDC for RAY allocations. According to Loanlist.io, DDEX has an average monthly supply rate of 0.71% on ETH, 5.89% on DAI, and 1.03% on USDC. While the stablecoin yields are relatively unimpressive, the ETH yield is substantially higher than what RAY typically earns.

Risk Evaluation

DDEX offers high leverage to traders, 5x, so the risk of lending on DDEX is higher than other lending platforms with higher collateralization ratios. At 5x, traders start at 125% collateralized, and are only available for liquidation once they reach lower than 110%. For comparison, dYdX begins liquidations at the 115% level.

DDEX had a problem with their liquidation mechanism in Novemember of 2019. The ETH price dropped quickly and borrowing positions became undercollateralized. Need to investigate further here.

Specification

The implementation of each function's signature and responsibilities are defined below:

On-chain

This Opportunity smart contract would follow the current standard Opportunity.sol interface.

function supply(address tokenAddress, uint amount, bool isERC20) external payable;

  • Responsible for supplying the appropriate token to DDEX's lending pool in the amount specified instantly (in same transaction) when being called.

function withdraw(address tokenAddress, address beneficiary, uint amount, bool isERC20) external;

  • Responsible for withdrawing the appropriate token from DDEX's lending pool in the specified amount instantly (in same transaction) when being called, and sending it to the specified beneficiary. If not enough liquidity is available to withdraw funds in the full amount specified instantly, the transaction should fail.

function getBalance(address tokenAddress) external view returns (uint);

  • Responsible for getting the total balance (principal + interest) for the supplied amount in DDEX of the specified token's native base units. Example: Lending ETH, return should be in units of wei. Lending USDC, return should be in units of mWei. In example, if currently have lent 1 ETH, and earnt 0.01 ETH as interest, and queried for the canonical WETH address as tokenAddress, the function should return 1010000000000000000. If currently have lent 1 USDC, and earnt 0.01 USDC as interest, and quereid for the USDC ERC20 address as tokenAddress, the function should return 1010000.

Additional smart contracts such as DDEX-specific interfaces or third-party libraries such as OpenZeppelin can be used to enable clean and secure design. Other contracts need to be approved by the RAY team.

Off-chain

This Opportunity program would follow the current standard interface.

function getSupply();

  • Responsible for getting the total supply (amount supplied) for the specified token. Return the supply as a string.

function getDemand();

  • Responsible for getting the total demand (amount borrowed) for the specified token. Return the demand as a string.

function getLiquidity();

  • Responsible for getting the total available market liquidity for the specified token. Return the liquidity as a string.

function getRate();

  • Responsible for getting the supply rate (APR) net fees for the specified token. Return the supply rate as a number.

function modelRates(string supply);

  • Responsible for modeling how supplying X of the specified token would affect the current rate. Return the new rate as a number.

Note, the modelRates() off-chain spec. method signature is a bit flexible. This is the only function that doesn't need to be completed. Linking to sources that show/explain how the algorithm works, or writing an explanation is sufficient and implementation is not required.

Implementations should be specific to a coin. In example, if run with an environment variable specifying USDC, all data returned should be relevant to USDC only.

Submission Deliverables

  • Smart contract(s) that implements DDEX lending integration following the specification, written in Solidity 0.4.25/0.5.11.
  • Smart contract interface that is used in the on/off-chain files, written in Solidity 0.4.25/0.5.11.
  • Off-chain file(s) that implements DDEX integration following the specification, written in JS.
  • A Truffle migration script with the correct order of operations/parameters required to deploy the DDEX Lending Opportunity contract.
  • Dependency contract address(es) from the DDEX system for Mainnet and if possible, Kovan testnet. If Kovan support is not available, reach out to RAY team and discuss options.
  • Answers to these questions.
  • Add support to this opportunity for ETH, DAI, and USDC.

Guidelines

Each document should have sufficient explanation of the integration specifics, how it maps to the required functionality, and links to relevant sources for acceptance checks to use.

Rationale

Adding DDEX as an opportunity will give RAY another yield-generating lending protocol to choose between. It is similar to existing opportunities, but may have higher rates at any given time. They also support several other assets that RAY could extend to in the future.

Backwards Compatibility

Backwards compatible.

Test Cases

A lot of the Acceptance Testing will be manual and done by the RAY team, and not automated. Any testing on integration to help verify correct implementations are welcome in the submission.

Off-chain implementation

  • Run based on the following commands and configurations:
  1. yarn
  2. truffle compile
  3. yarn run integration - note env. variables WEB3_HTTP_PROVIDER and COIN need to be supplied. Valid values for COIN include: ETH, DAI, and USDC.
  • Manual

On-chain implementation

  • Manual

Migration implementation

  • Manual

Other

  • Manual

To-do.

Implementation

Follow this submission as an example. Directory of the submission should be ./implementations/opportunity-support/ddex/

Security Considerations

To-do.

Copyright

Copyright and related rights waived via CC0.