Skip to content

Commit 02d08af

Browse files
committed
Prepare for py-solidity-docgen integration
1 parent 671d244 commit 02d08af

21 files changed

+1095
-163
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/**/spa/**/style.css
33

44
docs/md-build
5+
docs/tmp
56

67
# Created by https://www.toptal.com/developers/gitignore/api/python,solidity,visualstudiocode,react
78
# Edit at https://www.toptal.com/developers/gitignore?templates=python,solidity,visualstudiocode,react

CONTRIBUTING.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
New addition to the codebase must be fully documented.
2929

3030
- JavaScript portions of the code should be annotated using JSDoc style docstrings.
31-
- Solidity portions of the code should be fully annotated using [NatSpec] and [Solidity Domain for Sphinx].
31+
- Solidity portions of the code should be fully annotated using [NatSpec].
3232

33-
Documentation is generated using [solidity-docgen] and rendered via [mkdocs].
34-
[solidity-docgen] parses NatSpec and outputs `.md` files inside `docs/md-build` according
35-
to an Handlebars template located at `docs/solidity-docgen-templates/contract.hbs`.
33+
Documentation is generated using [py-solidity-docgen] and rendered via [mkdocs].
34+
[py-solidity-docgen] parses NatSpec and outputs `.md` files inside `docs/md-build` according
35+
to a pre-specified Jinja2 template.
3636

3737
**NOTE:** Each `.sol` file should contain only one `Interface` or `Contract`.
3838

@@ -50,7 +50,7 @@ yarn docs:serve
5050

5151
### mkdocs
5252

53-
To install [mkdocs] Python must be installed in the system.
53+
To install [mkdocs] and [py-solidity-docgen] Python must be installed in the system.
5454

5555
```
5656
pip install docs/requirements.in
@@ -63,5 +63,5 @@ pip install docs/requirements.in
6363
[Solidity Styleguide]: https://solidity.readthedocs.io/en/v0.7.0/style-guide.html
6464
[NatSpec]: https://solidity.readthedocs.io/en/v0.7.0/style-guide.html#natspec
6565
[Write the Docs!]: docs/source/write_the_docs.rst
66-
[solidity-docgen]: https://github.com/OpenZeppelin/solidity-docgen
66+
[py-solidity-docgen]: https://github.com/b-u-i-d-l/py-solidity-docgen
6767
[mkdocs]: https://www.mkdocs.org/

contracts/stableCoin/farming/IUnifiedStableFarming.sol

+74
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
pragma solidity >=0.7.0 <0.8.0;
44

5+
/**
6+
* @title UnifiedStableFarming
7+
* @dev Arbitrage helper
8+
*/
59
interface IUnifiedStableFarming {
610
function percentage() external view returns (uint256[] memory);
711

@@ -51,3 +55,73 @@ interface IUnifiedStableFarming {
5155
uint256[] calldata stableCoinAmounts
5256
) external;
5357
}
58+
59+
interface IStableCoin {
60+
function allowedPairs() external view returns (address[] memory);
61+
62+
function fromTokenToStable(address tokenAddress, uint256 amount)
63+
external
64+
view
65+
returns (uint256);
66+
67+
function mint(
68+
uint256 pairIndex,
69+
uint256 amount0,
70+
uint256 amount1,
71+
uint256 amount0Min,
72+
uint256 amount1Min
73+
) external returns (uint256);
74+
75+
function burn(
76+
uint256 pairIndex,
77+
uint256 pairAmount,
78+
uint256 amount0,
79+
uint256 amount1
80+
) external returns (uint256, uint256);
81+
}
82+
83+
interface IUniswapV2Pair {
84+
function token0() external view returns (address);
85+
86+
function token1() external view returns (address);
87+
}
88+
89+
interface IUniswapV2Router02 {
90+
function WETH() external pure returns (address);
91+
92+
function getAmountsOut(uint256 amountIn, address[] calldata path)
93+
external
94+
view
95+
returns (uint256[] memory amounts);
96+
97+
function swapExactTokensForTokens(
98+
uint256 amountIn,
99+
uint256 amountOutMin,
100+
address[] calldata path,
101+
address to,
102+
uint256 deadline
103+
) external returns (uint256[] memory amounts);
104+
105+
function swapExactETHForTokens(
106+
uint256 amountOutMin,
107+
address[] calldata path,
108+
address to,
109+
uint256 deadline
110+
) external payable returns (uint256[] memory amounts);
111+
}
112+
113+
interface IERC20 {
114+
function balanceOf(address account) external view returns (uint256);
115+
116+
function transfer(address recipient, uint256 amount) external returns (bool);
117+
118+
function allowance(address owner, address spender) external view returns (uint256);
119+
120+
function approve(address spender, uint256 amount) external returns (bool);
121+
122+
function transferFrom(
123+
address sender,
124+
address recipient,
125+
uint256 amount
126+
) external returns (bool);
127+
}

contracts/stableCoin/farming/UnifiedStableFarming.sol

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

3-
pragma solidity >=0.7.0 <0.8.0;
3+
pragma solidity ^0.7.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";
96

107
contract UnifiedStableFarming is IUnifiedStableFarming {
11-
address private constant UNISWAP_V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
8+
address
9+
private constant UNISWAP_V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
1210

1311
address private WETH_ADDRESS;
1412

1513
uint256[] private _percentage;
1614

17-
constructor(uint256[] memory percentage) public {
15+
constructor(uint256[] memory percentage) {
1816
WETH_ADDRESS = IUniswapV2Router02(UNISWAP_V2_ROUTER).WETH();
1917
assert(percentage.length == 2);
2018
_percentage = percentage;
@@ -42,7 +40,12 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
4240
uint256 realTokenValue = tokenAddress == WETH_ADDRESS ? msg.value : tokenValue;
4341
_swap(tokenAddress, stableCoinAddress, realTokenValue, address(this));
4442
// Swap stablecoin for $uSD
45-
IStableCoin(stableCoinAddress).burn(pairIndex, pairAmount, amountAMin, amountBMin);
43+
IStableCoin(stableCoinAddress).burn(
44+
pairIndex,
45+
pairAmount,
46+
amountAMin,
47+
amountBMin
48+
);
4649
(address tokenA, address tokenB, ) = _getPairData(stableCoinAddress, pairIndex);
4750
// Send the tokens back to their owner
4851
_flushToSender(tokenA, tokenB, stableCoinAddress, address(0));
@@ -77,7 +80,13 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
7780
amountB
7881
);
7982
// Mint $uSD
80-
IStableCoin(stableCoinAddress).mint(pairIndex, amountA, amountB, amountAMin, amountBMin);
83+
IStableCoin(stableCoinAddress).mint(
84+
pairIndex,
85+
amountA,
86+
amountB,
87+
amountAMin,
88+
amountBMin
89+
);
8190
// For each of the chosen output pair swap $uSD to obtain the desired amount of stablecoin
8291
for (uint256 i = 0; i < tokenIndices.length; i++) {
8392
_swap(
@@ -204,7 +213,7 @@ contract UnifiedStableFarming is IUnifiedStableFarming {
204213
path[1] = tokenOut;
205214
if (path[0] == WETH_ADDRESS) {
206215
return
207-
uniswapV2Router.swapExactETHForTokens{value: amountIn}(
216+
uniswapV2Router.swapExactETHForTokens{ value: amountIn }(
208217
uniswapV2Router.getAmountsOut(amountIn, path)[1],
209218
path,
210219
receiver,

contracts/stableCoin/microservices/IMVDFunctionalitiesManager.sol

-5
This file was deleted.

contracts/stableCoin/microservices/IMVDProxy.sol

-22
This file was deleted.

contracts/stableCoin/microservices/IStateHolder.sol

-13
This file was deleted.

contracts/stableCoin/microservices/MintNewVotingTokensForStableCoinFunctionality.sol

+59-25
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
1-
/* Discussion:
2-
* https://github.com/b-u-i-d-l/unifi
3-
*/
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.7.0 <0.8.0;
43

54
/* Description:
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.
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.
86
*
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:
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:
118
*
129
* 1 - A stablecoin collateralized by uSD loses value or fails altogether.
1310
*
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.
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.
1612
*
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.
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.
1914
*
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.
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.
2216
*/
23-
// SPDX-License-Identifier: MIT
24-
25-
pragma solidity >=0.7.0 <0.8.0;
26-
27-
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
28-
29-
import "./IMVDFunctionalitiesManager.sol";
30-
import "./IMVDProxy.sol";
31-
import "./IStateHolder.sol";
3217

3318
/**
3419
* @title Mint Voting Tokens ($unifi) by burning Stable Coin ($uSD)
3520
* @dev This contract adds unifi minting capabilities to uSD
3621
*/
3722
contract MintNewVotingTokensForStableCoinFunctionality {
3823
function onStart(address, address) public {
39-
IStateHolder stateHolder = IStateHolder(IMVDProxy(msg.sender).getStateHolderAddress());
24+
IStateHolder stateHolder = IStateHolder(
25+
IMVDProxy(msg.sender).getStateHolderAddress()
26+
);
4027
address stablecoinauthorized = 0x44086035439E676c02D411880FcCb9837CE37c57;
4128
stateHolder.setBool(
4229
_toStateHolderKey("stablecoin.authorized", _toString(stablecoinauthorized)),
@@ -45,7 +32,9 @@ contract MintNewVotingTokensForStableCoinFunctionality {
4532
}
4633

4734
function onStop(address) public {
48-
IStateHolder stateHolder = IStateHolder(IMVDProxy(msg.sender).getStateHolderAddress());
35+
IStateHolder stateHolder = IStateHolder(
36+
IMVDProxy(msg.sender).getStateHolderAddress()
37+
);
4938
address stablecoinauthorized = 0x44086035439E676c02D411880FcCb9837CE37c57;
5039
stateHolder.clear(
5140
_toStateHolderKey("stablecoin.authorized", _toString(stablecoinauthorized))
@@ -105,8 +94,53 @@ contract MintNewVotingTokensForStableCoinFunctionality {
10594
function _toLowerCase(string memory str) private pure returns (string memory) {
10695
bytes memory bStr = bytes(str);
10796
for (uint256 i = 0; i < bStr.length; i++) {
108-
bStr[i] = bStr[i] >= 0x41 && bStr[i] <= 0x5A ? bytes1(uint8(bStr[i]) + 0x20) : bStr[i];
97+
bStr[i] = bStr[i] >= 0x41 && bStr[i] <= 0x5A
98+
? bytes1(uint8(bStr[i]) + 0x20)
99+
: bStr[i];
109100
}
110101
return string(bStr);
111102
}
112103
}
104+
105+
interface IMVDProxy {
106+
function getToken() external view returns (address);
107+
108+
function getStateHolderAddress() external view returns (address);
109+
110+
function getMVDFunctionalitiesManagerAddress() external view returns (address);
111+
112+
function transfer(
113+
address receiver,
114+
uint256 value,
115+
address token
116+
) external;
117+
118+
function flushToWallet(
119+
address tokenAddress,
120+
bool is721,
121+
uint256 tokenId
122+
) external;
123+
}
124+
125+
interface IMVDFunctionalitiesManager {
126+
function isAuthorizedFunctionality(address functionality)
127+
external
128+
view
129+
returns (bool);
130+
}
131+
132+
interface IStateHolder {
133+
function clear(string calldata varName)
134+
external
135+
returns (string memory oldDataType, bytes memory oldVal);
136+
137+
function setBool(string calldata varName, bool val) external returns (bool);
138+
139+
function getBool(string calldata varName) external view returns (bool);
140+
}
141+
142+
interface IERC20 {
143+
function mint(uint256 amount) external;
144+
145+
function balanceOf(address account) external view returns (uint256);
146+
}

0 commit comments

Comments
 (0)