Skip to content

Commit

Permalink
Update docs and project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-ubik committed Sep 6, 2020
1 parent fbb4ab2 commit 671d244
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 1,053 deletions.
74 changes: 2 additions & 72 deletions contracts/stableCoin/farming/IUnifiedStableFarming.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0;
pragma solidity >=0.7.0 <0.8.0;

interface IUnifiedStableFarming {
function percentage() external view returns (uint256[] memory);
Expand All @@ -24,7 +24,7 @@ interface IUnifiedStableFarming {
uint256 amountBMin,
address tokenAddress,
uint256 tokenValue
) external;
) external payable;

/**
* @dev Earn by dumping $uSD: Mint stablecoins obtaining $usd then swap it back for caller choice of
Expand All @@ -51,73 +51,3 @@ interface IUnifiedStableFarming {
uint256[] calldata stableCoinAmounts
) external;
}

interface IStableCoin {
function allowedPairs() external view returns (address[] memory);

function fromTokenToStable(address tokenAddress, uint256 amount)
external
view
returns (uint256);

function mint(
uint256 pairIndex,
uint256 amount0,
uint256 amount1,
uint256 amount0Min,
uint256 amount1Min
) external returns (uint256);

function burn(
uint256 pairIndex,
uint256 pairAmount,
uint256 amount0,
uint256 amount1
) external returns (uint256, uint256);
}

interface IUniswapV2Pair {
function token0() external view returns (address);

function token1() external view returns (address);
}

interface IUniswapV2Router {
function WETH() external pure returns (address);

function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);

function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);

function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
}

interface IERC20 {
function balanceOf(address account) external view returns (uint256);

function transfer(address recipient, uint256 amount) external returns (bool);

function allowance(address owner, address spender) external view returns (uint256);

function approve(address spender, uint256 amount) external returns (bool);

function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
}
45 changes: 15 additions & 30 deletions contracts/stableCoin/farming/UnifiedStableFarming.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;
pragma solidity >=0.7.0 <0.8.0;

import "./IUnifiedStableFarming.sol";
import "../standalone/IStableCoin.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

contract UnifiedStableFarming is IUnifiedStableFarming {
address private constant UNISWAP_V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
Expand All @@ -11,8 +14,8 @@ contract UnifiedStableFarming is IUnifiedStableFarming {

uint256[] private _percentage;

constructor(uint256[] memory percentage) {
WETH_ADDRESS = IUniswapV2Router(UNISWAP_V2_ROUTER).WETH();
constructor(uint256[] memory percentage) public {
WETH_ADDRESS = IUniswapV2Router02(UNISWAP_V2_ROUTER).WETH();
assert(percentage.length == 2);
_percentage = percentage;
}
Expand All @@ -33,35 +36,18 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
address tokenAddress,
uint256 tokenValue
) public override payable {
if(tokenAddress != WETH_ADDRESS) {
_transferToMeAndCheckAllowance(
tokenAddress,
tokenValue,
UNISWAP_V2_ROUTER
);
if (tokenAddress != WETH_ADDRESS) {
_transferToMeAndCheckAllowance(tokenAddress, tokenValue, UNISWAP_V2_ROUTER);
}
uint256 realTokenValue = tokenAddress == WETH_ADDRESS
? msg.value
: tokenValue;
uint256 stableCoinAmount = _swap(
tokenAddress,
stableCoinAddress,
realTokenValue,
address(this)
);
uint256 realTokenValue = tokenAddress == WETH_ADDRESS ? msg.value : tokenValue;
_swap(tokenAddress, stableCoinAddress, realTokenValue, address(this));
// Swap stablecoin for $uSD
(uint256 returnA, uint256 returnB) = IStableCoin(stableCoinAddress).burn(
pairIndex,
pairAmount,
amountAMin,
amountBMin
);
IStableCoin(stableCoinAddress).burn(pairIndex, pairAmount, amountAMin, amountBMin);
(address tokenA, address tokenB, ) = _getPairData(stableCoinAddress, pairIndex);
// Send the tokens back to their owner
_flushToSender(tokenA, tokenB, stableCoinAddress);
_flushToSender(tokenA, tokenB, stableCoinAddress, address(0));
}


/**
* @inheritdoc IUnifiedStableFarming
*/
Expand Down Expand Up @@ -170,13 +156,12 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
address tokenA,
address tokenB,
address tokenC,
address tokenD,
address tokenD
) private {
_flushToSender(tokenA);
_flushToSender(tokenB);
_flushToSender(tokenC);
_flushToSender(tokenD);

}

/**
Expand All @@ -186,7 +171,7 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
if (tokenAddress == address(0)) {
return;
}
if(tokenAddress == WETH_ADDRESS) {
if (tokenAddress == WETH_ADDRESS) {
payable(msg.sender).transfer(address(this).balance);
return;
}
Expand All @@ -212,7 +197,7 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
) private returns (uint256) {
_checkAllowance(tokenIn, amountIn, UNISWAP_V2_ROUTER);

IUniswapV2Router uniswapV2Router = IUniswapV2Router(UNISWAP_V2_ROUTER);
IUniswapV2Router02 uniswapV2Router = IUniswapV2Router02(UNISWAP_V2_ROUTER);

address[] memory path = new address[](2);
path[0] = tokenIn;
Expand Down
7 changes: 0 additions & 7 deletions contracts/stableCoin/microservices/IERC20.sol

This file was deleted.

3 changes: 2 additions & 1 deletion contracts/stableCoin/microservices/IMVDProxy.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.6.0;
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.8.0;

interface IMVDProxy {
function getToken() external view returns (address);
Expand Down
2 changes: 1 addition & 1 deletion contracts/stableCoin/microservices/IStateHolder.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;
pragma solidity >=0.7.0 <0.8.0;

interface IStateHolder {
function clear(string calldata varName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
/* Discussion:
* https://github.com/b-u-i-d-l/unifi
*/

/* Description:
* When a stablecoin loses value, the Uniswap Tier pools rebalance to an uneven disparity (≠ 50/50). If the stablecoin totally fails, the other stablecoins effectively pump in correlation.
* When a stablecoin loses value, the Uniswap Tier pools rebalance to an uneven disparity (≠ 50/50).
* If the stablecoin totally fails, the other stablecoins effectively pump in correlation.
*
* DFO Debit resolves this issue on-chain by rebalancing uSD, creating debt which the UniFi DFO then pays off by minting UniFi. Let’s look at how this plays out, step by step:
* DFO Debit resolves this issue on-chain by rebalancing uSD, creating debt which the UniFi DFO
* then pays off by minting UniFi. Let’s look at how this plays out, step by step:
*
* 1 - A stablecoin collateralized by uSD loses value or fails altogether.
*
* 2 - $UniFi holders vote to remove the tiers containing the failed stablecoin from the whitelist.The uSD supply becomes grater than the supply of the collateralized pooled stablecoins.
* 2 - $UniFi holders vote to remove the tiers containing the failed stablecoin from the whitelist.
* The uSD supply becomes grater than the supply of the collateralized pooled stablecoins.
*
* 3 - To restore 1:1 equilibrium, anyone holding uSD can burn it to receive new UniFi, minted at a 50% discount of the uSD/UniFi Uniswap pool mid-price ratio.
* 3 - To restore 1:1 equilibrium, anyone holding uSD can burn it to receive new UniFi, minted at a
* 50% discount of the uSD/UniFi Uniswap pool mid-price ratio.
*
* The goal of $UniFi holders, which aligns with their self-interest, is to ensure uSD’s security. Thus there is an economic disincentive to whitelist insecure stablecoins.
* The goal of $UniFi holders, which aligns with their self-interest, is to ensure uSD's security.
* Thus there is an economic disincentive to whitelist insecure stablecoins.
*/
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;
pragma solidity >=0.7.0 <0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "./IERC20.sol";
import "./IMVDFunctionalitiesManager.sol";
import "./IMVDProxy.sol";
import "./IStateHolder.sol";

/**
* @title Mint Voting Tokens ($unifi) by burning Stable Coin ($uSD)
* @dev This contract adds unifi minting capabilies to uSD
* @dev This contract adds unifi minting capabilities to uSD
*/
contract MintNewVotingTokensForStableCoinFunctionality {
function onStart(address, address) public {
Expand Down
Loading

0 comments on commit 671d244

Please sign in to comment.