Skip to content

Commit 671d244

Browse files
committed
Update docs and project structure
1 parent fbb4ab2 commit 671d244

20 files changed

+89
-1053
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
pragma solidity >=0.7.0;
3+
pragma solidity >=0.7.0 <0.8.0;
44

55
interface IUnifiedStableFarming {
66
function percentage() external view returns (uint256[] memory);
@@ -24,7 +24,7 @@ interface IUnifiedStableFarming {
2424
uint256 amountBMin,
2525
address tokenAddress,
2626
uint256 tokenValue
27-
) external;
27+
) external payable;
2828

2929
/**
3030
* @dev Earn by dumping $uSD: Mint stablecoins obtaining $usd then swap it back for caller choice of
@@ -51,73 +51,3 @@ interface IUnifiedStableFarming {
5151
uint256[] calldata stableCoinAmounts
5252
) external;
5353
}
54-
55-
interface IStableCoin {
56-
function allowedPairs() external view returns (address[] memory);
57-
58-
function fromTokenToStable(address tokenAddress, uint256 amount)
59-
external
60-
view
61-
returns (uint256);
62-
63-
function mint(
64-
uint256 pairIndex,
65-
uint256 amount0,
66-
uint256 amount1,
67-
uint256 amount0Min,
68-
uint256 amount1Min
69-
) external returns (uint256);
70-
71-
function burn(
72-
uint256 pairIndex,
73-
uint256 pairAmount,
74-
uint256 amount0,
75-
uint256 amount1
76-
) external returns (uint256, uint256);
77-
}
78-
79-
interface IUniswapV2Pair {
80-
function token0() external view returns (address);
81-
82-
function token1() external view returns (address);
83-
}
84-
85-
interface IUniswapV2Router {
86-
function WETH() external pure returns (address);
87-
88-
function getAmountsOut(uint256 amountIn, address[] calldata path)
89-
external
90-
view
91-
returns (uint256[] memory amounts);
92-
93-
function swapExactTokensForTokens(
94-
uint256 amountIn,
95-
uint256 amountOutMin,
96-
address[] calldata path,
97-
address to,
98-
uint256 deadline
99-
) external returns (uint256[] memory amounts);
100-
101-
function swapExactETHForTokens(
102-
uint256 amountOutMin,
103-
address[] calldata path,
104-
address to,
105-
uint256 deadline
106-
) external payable returns (uint256[] memory amounts);
107-
}
108-
109-
interface IERC20 {
110-
function balanceOf(address account) external view returns (uint256);
111-
112-
function transfer(address recipient, uint256 amount) external returns (bool);
113-
114-
function allowance(address owner, address spender) external view returns (uint256);
115-
116-
function approve(address spender, uint256 amount) external returns (bool);
117-
118-
function transferFrom(
119-
address sender,
120-
address recipient,
121-
uint256 amount
122-
) external returns (bool);
123-
}

contracts/stableCoin/farming/UnifiedStableFarming.sol

+15-30
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// SPDX-License-Identifier: MIT
22

3-
pragma solidity ^0.6.0;
3+
pragma solidity >=0.7.0 <0.8.0;
44

55
import "./IUnifiedStableFarming.sol";
6+
import "../standalone/IStableCoin.sol";
7+
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
8+
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
69

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

1215
uint256[] private _percentage;
1316

14-
constructor(uint256[] memory percentage) {
15-
WETH_ADDRESS = IUniswapV2Router(UNISWAP_V2_ROUTER).WETH();
17+
constructor(uint256[] memory percentage) public {
18+
WETH_ADDRESS = IUniswapV2Router02(UNISWAP_V2_ROUTER).WETH();
1619
assert(percentage.length == 2);
1720
_percentage = percentage;
1821
}
@@ -33,35 +36,18 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
3336
address tokenAddress,
3437
uint256 tokenValue
3538
) public override payable {
36-
if(tokenAddress != WETH_ADDRESS) {
37-
_transferToMeAndCheckAllowance(
38-
tokenAddress,
39-
tokenValue,
40-
UNISWAP_V2_ROUTER
41-
);
39+
if (tokenAddress != WETH_ADDRESS) {
40+
_transferToMeAndCheckAllowance(tokenAddress, tokenValue, UNISWAP_V2_ROUTER);
4241
}
43-
uint256 realTokenValue = tokenAddress == WETH_ADDRESS
44-
? msg.value
45-
: tokenValue;
46-
uint256 stableCoinAmount = _swap(
47-
tokenAddress,
48-
stableCoinAddress,
49-
realTokenValue,
50-
address(this)
51-
);
42+
uint256 realTokenValue = tokenAddress == WETH_ADDRESS ? msg.value : tokenValue;
43+
_swap(tokenAddress, stableCoinAddress, realTokenValue, address(this));
5244
// Swap stablecoin for $uSD
53-
(uint256 returnA, uint256 returnB) = IStableCoin(stableCoinAddress).burn(
54-
pairIndex,
55-
pairAmount,
56-
amountAMin,
57-
amountBMin
58-
);
45+
IStableCoin(stableCoinAddress).burn(pairIndex, pairAmount, amountAMin, amountBMin);
5946
(address tokenA, address tokenB, ) = _getPairData(stableCoinAddress, pairIndex);
6047
// Send the tokens back to their owner
61-
_flushToSender(tokenA, tokenB, stableCoinAddress);
48+
_flushToSender(tokenA, tokenB, stableCoinAddress, address(0));
6249
}
6350

64-
6551
/**
6652
* @inheritdoc IUnifiedStableFarming
6753
*/
@@ -170,13 +156,12 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
170156
address tokenA,
171157
address tokenB,
172158
address tokenC,
173-
address tokenD,
159+
address tokenD
174160
) private {
175161
_flushToSender(tokenA);
176162
_flushToSender(tokenB);
177163
_flushToSender(tokenC);
178164
_flushToSender(tokenD);
179-
180165
}
181166

182167
/**
@@ -186,7 +171,7 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
186171
if (tokenAddress == address(0)) {
187172
return;
188173
}
189-
if(tokenAddress == WETH_ADDRESS) {
174+
if (tokenAddress == WETH_ADDRESS) {
190175
payable(msg.sender).transfer(address(this).balance);
191176
return;
192177
}
@@ -212,7 +197,7 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
212197
) private returns (uint256) {
213198
_checkAllowance(tokenIn, amountIn, UNISWAP_V2_ROUTER);
214199

215-
IUniswapV2Router uniswapV2Router = IUniswapV2Router(UNISWAP_V2_ROUTER);
200+
IUniswapV2Router02 uniswapV2Router = IUniswapV2Router02(UNISWAP_V2_ROUTER);
216201

217202
address[] memory path = new address[](2);
218203
path[0] = tokenIn;

contracts/stableCoin/microservices/IERC20.sol

-7
This file was deleted.

contracts/stableCoin/microservices/IMVDProxy.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pragma solidity ^0.6.0;
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.7.0 <0.8.0;
23

34
interface IMVDProxy {
45
function getToken() external view returns (address);

contracts/stableCoin/microservices/IStateHolder.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
pragma solidity ^0.6.0;
3+
pragma solidity >=0.7.0 <0.8.0;
44

55
interface IStateHolder {
66
function clear(string calldata varName)

contracts/stableCoin/microservices/MintNewVotingTokensForStableCoinFunctionality.sol

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
/* Discussion:
22
* https://github.com/b-u-i-d-l/unifi
33
*/
4+
45
/* Description:
5-
* 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.
6+
* When a stablecoin loses value, the Uniswap Tier pools rebalance to an uneven disparity (≠ 50/50).
7+
* If the stablecoin totally fails, the other stablecoins effectively pump in correlation.
68
*
7-
* 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:
9+
* DFO Debit resolves this issue on-chain by rebalancing uSD, creating debt which the UniFi DFO
10+
* then pays off by minting UniFi. Let’s look at how this plays out, step by step:
811
*
912
* 1 - A stablecoin collateralized by uSD loses value or fails altogether.
1013
*
11-
* 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.
14+
* 2 - $UniFi holders vote to remove the tiers containing the failed stablecoin from the whitelist.
15+
* The uSD supply becomes grater than the supply of the collateralized pooled stablecoins.
1216
*
13-
* 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.
17+
* 3 - To restore 1:1 equilibrium, anyone holding uSD can burn it to receive new UniFi, minted at a
18+
* 50% discount of the uSD/UniFi Uniswap pool mid-price ratio.
1419
*
15-
* 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.
20+
* The goal of $UniFi holders, which aligns with their self-interest, is to ensure uSD's security.
21+
* Thus there is an economic disincentive to whitelist insecure stablecoins.
1622
*/
1723
// SPDX-License-Identifier: MIT
1824

19-
pragma solidity ^0.6.0;
25+
pragma solidity >=0.7.0 <0.8.0;
26+
27+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
2028

21-
import "./IERC20.sol";
2229
import "./IMVDFunctionalitiesManager.sol";
2330
import "./IMVDProxy.sol";
2431
import "./IStateHolder.sol";
2532

2633
/**
2734
* @title Mint Voting Tokens ($unifi) by burning Stable Coin ($uSD)
28-
* @dev This contract adds unifi minting capabilies to uSD
35+
* @dev This contract adds unifi minting capabilities to uSD
2936
*/
3037
contract MintNewVotingTokensForStableCoinFunctionality {
3138
function onStart(address, address) public {

0 commit comments

Comments
 (0)