Skip to content

Commit af6ad88

Browse files
committed
Merge branch 'master' into docs
2 parents 44aba83 + 4f3b59a commit af6ad88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1667
-237
lines changed

CNAME

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
switch.dfohub.com
1+
www.unifihub.com

README.md

+276-5
Large diffs are not rendered by default.

assets/css/style.css

+197-18
Large diffs are not rendered by default.

assets/img/eth-logo.png

189 KB
Loading

assets/plugins/react/react.module.manager.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ var ReactModuleManager = function() {
105105
if (rendered.props === undefined || rendered.props === null) {
106106
rendered.props = {};
107107
}
108-
rendered.props.className = loader ? rendered.props.defaultClassName : rendered.props.className;
108+
rendered.props.className = loader && rendered.props.defaultClassName ? rendered.props.defaultClassName : rendered.props.className;
109109
if (rendered.props.className === undefined || rendered.props.className === null) {
110110
rendered.props.className = '';
111111
}
112-
if (!rendered.props.className.containsAloneWord(lowerCaseViewName)) {
112+
if (rendered.props.className && !rendered.props.className.containsAloneWord(lowerCaseViewName)) {
113113
if (rendered.props.className !== '') {
114114
lowerCaseViewName += ' '
115115
}
@@ -247,7 +247,7 @@ var ReactModuleManager = function() {
247247
var element;
248248
var involveLoadedModules = true
249249

250-
if (typeof viewName !== 'string' || window[viewName] === undefined || window[viewName] instanceof HTMLCollection) {
250+
if (typeof viewName !== 'string' || window[viewName] === undefined || window[viewName] instanceof HTMLCollection || window[viewName] instanceof HTMLElement) {
251251
element = React.createElement2.apply(React, callerArguments)
252252
involveLoadedModules = typeof viewName !== 'string'
253253
if (elementName !== undefined) {

assets/scripts/script.js

+94-20
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,33 @@ window.loadDFO = async function loadDFO(address, allAddresses) {
2929
var votingToken = window.voidEthereumAddress;
3030

3131
try {
32-
votingToken = (await window.blockchainCall(dfo.methods.getDelegates))[0];
33-
} catch (e) {}
32+
var delegates = await window.web3.eth.call({
33+
to: element.dFO.options.address,
34+
data: element.dFO.methods.getDelegates().encodeABI()
35+
});
36+
try {
37+
delegates = window.web3.eth.abi.decodeParameter("address[]", delegates);
38+
} catch (e) {
39+
delegates = window.web3.eth.abi.decodeParameters(["address", "address", "address", "address", "address", "address"], delegates);
40+
}
41+
votingToken = delegates[0];
42+
} catch (e) {
43+
votingToken = undefined;
44+
}
3445

35-
if (votingToken === window.voidEthereumAddress) {
46+
if (!votingToken || votingToken === window.voidEthereumAddress) {
3647
try {
3748
votingToken = await window.blockchainCall(dfo.methods.getToken);
3849
} catch (e) {}
3950
}
4051

41-
if (votingToken === window.voidEthereumAddress) {
52+
try {
53+
await window.blockchainCall(window.newContract(window.context.votingTokenAbi, votingToken).methods.name);
54+
} catch (e) {
55+
votingToken = undefined;
56+
}
57+
58+
if (!votingToken || votingToken === window.voidEthereumAddress) {
4259
var logs = await window.getLogs({
4360
address,
4461
topics: [
@@ -92,14 +109,6 @@ window.onEthereumUpdate = function onEthereumUpdate(millis) {
92109
window.ethereum && window.ethereum.on && window.ethereum.on('networkChanged', () => window.onEthereumUpdate(window.web3.currentProvider));
93110
window.ethereum && window.ethereum.on && window.ethereum.on('accountsChanged', () => window.onEthereumUpdate(window.web3.currentProvider));
94111
window.DFOHub(window.web3);
95-
window.stableCoin = window.newContract(window.context.StableCoinAbi, window.getNetworkElement("stableCoinAddress"));
96-
window.doubleProxy = window.newContract(window.context.DoubleProxyAbi, await window.blockchainCall(window.stableCoin.methods.doubleProxy))
97-
window.dfo = window.web3.eth.dfoHub.load(await window.blockchainCall(window.doubleProxy.methods.proxy));
98-
window.uniswapV2Router = window.newContract(window.context.UniswapV2RouterAbi, window.context.uniswapV2RouterAddress);
99-
window.wethToken = window.newContract(window.context.votingTokenAbi, window.wethAddress = window.web3.utils.toChecksumAddress(await window.blockchainCall(window.uniswapV2Router.methods.WETH)));
100-
window.uniswapV2Factory = window.newContract(window.context.UniswapV2FactoryAbi, window.context.uniswapV2FactoryAddress);
101-
window.stableCoin = await window.loadTokenInfos(stableCoin.options.address, window.wethToken.options.address, window.context.StableCoinAbi);
102-
window.votingToken = await window.loadTokenInfos((await (window.dfo = await window.dfo).votingToken).options.address, window.wethToken.options.address);
103112
update = true;
104113
}
105114
delete window.walletAddress;
@@ -117,6 +126,20 @@ window.onEthereumUpdate = function onEthereumUpdate(millis) {
117126
});
118127
};
119128

129+
window.loadEthereumStuff = async function loadEthereumStuff(oldStableCoin) {
130+
window.uniswapV2Router = window.newContract(window.context.UniswapV2RouterAbi, window.context.uniswapV2RouterAddress);
131+
window.wethToken = window.newContract(window.context.votingTokenAbi, window.wethAddress = window.web3.utils.toChecksumAddress(await window.blockchainCall(window.uniswapV2Router.methods.WETH)));
132+
window.uniswapV2Factory = window.newContract(window.context.UniswapV2FactoryAbi, window.context.uniswapV2FactoryAddress);
133+
try {
134+
window.stableCoin = window.newContract(window.context.StableCoinAbi, window.getNetworkElement(oldStableCoin ? "oldStableCoinAddress" : "stableCoinAddress"));
135+
window.doubleProxy = window.newContract(window.context.DoubleProxyAbi, await window.blockchainCall(window.stableCoin.methods.doubleProxy))
136+
window.dfo = window.web3.eth.dfoHub.load(await window.blockchainCall(window.doubleProxy.methods.proxy));
137+
window.stableCoin = await window.loadTokenInfos(window.stableCoin.options.address, window.context.StableCoinAbi);
138+
window.votingToken = await window.loadTokenInfos((await (window.dfo = await window.dfo).votingToken).options.address);
139+
} catch(e) {
140+
}
141+
};
142+
120143
window.getNetworkElement = function getNetworkElement(element) {
121144
var network = window.context.ethereumNetwork[window.networkId];
122145
if (network === undefined || network === null) {
@@ -212,6 +235,12 @@ window.getAddress = async function getAddress() {
212235
return (window.walletAddress = (await window.web3.eth.getAccounts())[0]);
213236
};
214237

238+
window.consumeAddressBarParam = function consumeAddressBarParam(paramName) {
239+
var param = window.addressBarParams[paramName];
240+
delete window.addressBarParams[paramName];
241+
return param;
242+
};
243+
215244
window.getSendingOptions = function getSendingOptions(transaction) {
216245
return new Promise(async function(ok, ko) {
217246
if (transaction) {
@@ -1200,22 +1229,21 @@ window.eliminateFloatingFinalZeroes = function eliminateFloatingFinalZeroes(valu
12001229
return split[1].length === 0 ? split[0] : split.join(decSeparator);
12011230
};
12021231

1203-
window.loadTokenInfos = async function loadTokenInfos(addresses, wethAddress, abi) {
1204-
wethAddress = wethAddress || await window.blockchainCall(window.newContract(window.context.uniSwapV2RouterAbi, window.context.uniSwapV2RouterAddress).methods.WETH);
1205-
wethAddress = window.web3.utils.toChecksumAddress(wethAddress);
1232+
window.loadTokenInfos = async function loadTokenInfos(addresses, abi, noLogo) {
12061233
var single = (typeof addresses).toLowerCase() === 'string';
12071234
addresses = single ? [addresses] : addresses;
12081235
var tokens = [];
1236+
window.tokenInfosCache = window.tokenInfosCache || {};
12091237
for (var address of addresses) {
12101238
address = window.web3.utils.toChecksumAddress(address);
12111239
var token = window.newContract(abi || window.context.votingTokenAbi, address);
1212-
tokens.push({
1240+
tokens.push(window.tokenInfosCache[address] = window.tokenInfosCache[address] || {
12131241
address,
12141242
token,
1215-
name: address === wethAddress ? 'Ethereum' : await window.blockchainCall(token.methods.name),
1216-
symbol: address === wethAddress ? 'ETH' : await window.blockchainCall(token.methods.symbol),
1217-
decimals: address === wethAddress ? '18' : await window.blockchainCall(token.methods.decimals),
1218-
logo: await window.loadLogo(address === wethAddress ? window.voidEthereumAddress : address)
1243+
name: address === window.wethAddress ? 'Ethereum' : await window.blockchainCall(token.methods.name),
1244+
symbol: address === window.wethAddress ? 'ETH' : await window.blockchainCall(token.methods.symbol),
1245+
decimals: address === window.wethAddress ? '18' : await window.blockchainCall(token.methods.decimals),
1246+
logo: noLogo ? undefined : await window.loadLogo(address === window.wethAddress ? window.voidEthereumAddress : address)
12191247
});
12201248
}
12211249
return single ? tokens[0] : tokens;
@@ -1272,4 +1300,50 @@ window.getEthereumPrice = async function getEthereumPrice() {
12721300
price,
12731301
requestExpires: new Date().getTime() + window.context.coingeckoEthereumPriceRequestInterval
12741302
}).price;
1303+
};
1304+
1305+
window.loadUniswapPairs = async function loadUniswapPairs(token, indexes) {
1306+
window.pairCreatedTopic = window.pairCreatedTopic || window.web3.utils.sha3('PairCreated(address,address,address,uint256)');
1307+
var address = window.web3.utils.toChecksumAddress(token.address);
1308+
if (address === window.voidEthereumAddress) {
1309+
address = window.wethAddress;
1310+
}
1311+
var myToken = window.web3.eth.abi.encodeParameter('address', address);
1312+
var logs = await window.getLogs({
1313+
address: window.context.uniSwapV2FactoryAddress,
1314+
fromBlock: '0',
1315+
topics: [
1316+
window.pairCreatedTopic, [myToken]
1317+
]
1318+
});
1319+
logs.push(...(await window.getLogs({
1320+
address: window.context.uniSwapV2FactoryAddress,
1321+
fromBlock: '0',
1322+
topics: [
1323+
window.pairCreatedTopic, [],
1324+
[myToken]
1325+
]
1326+
})));
1327+
var uniswapPairs = [];
1328+
var alreadyAdded = {};
1329+
for (var log of logs) {
1330+
for (var topic of log.topics) {
1331+
if (topic === window.pairCreatedTopic || topic.toLowerCase() === myToken.toLowerCase()) {
1332+
continue;
1333+
}
1334+
var pairTokenAddress = window.web3.utils.toChecksumAddress(window.web3.eth.abi.decodeParameters(['address', 'uint256'], log.data)[0]);
1335+
if (alreadyAdded[pairTokenAddress]) {
1336+
continue;
1337+
}
1338+
alreadyAdded[pairTokenAddress] = true;
1339+
var pairToken = await window.loadTokenInfos(pairTokenAddress, window.context.UniswapV2PairAbi, true);
1340+
var token0 = window.web3.utils.toChecksumAddress(await window.blockchainCall(pairToken.token.methods.token0));
1341+
var token1 = window.web3.utils.toChecksumAddress(await window.blockchainCall(pairToken.token.methods.token1));
1342+
pairToken.token0 = token0 === address ? token : await window.loadTokenInfos(token0, undefined, true);
1343+
pairToken.token1 = token1 === address ? token : await window.loadTokenInfos(token1, undefined, true);
1344+
pairToken.key = `${token0}_${token1}-${token1}_${token0}`;
1345+
uniswapPairs.push(indexes[pairToken.key] = pairToken);
1346+
}
1347+
}
1348+
return uniswapPairs;
12751349
};

contracts/stableCoin/microservices/IERC20.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
interface IERC20 {
44
function mint(uint256 amount) external;

contracts/stableCoin/microservices/IMVDFunctionalitiesManager.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
interface IMVDFunctionalitiesManager {
44
function isAuthorizedFunctionality(address functionality) external view returns (bool);

contracts/stableCoin/microservices/IMVDProxy.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
interface IMVDProxy {
44
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.7.0;
3+
pragma solidity ^0.6.0;
44

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

contracts/stableCoin/microservices/MintNewVotingTokensForStableCoinFunctionality.sol

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1+
/* Discussion:
2+
* https://github.com/b-u-i-d-l/unifi
3+
*/
4+
/* 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+
*
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:
8+
*
9+
* 1 - A stablecoin collateralized by uSD loses value or fails altogether.
10+
*
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.
12+
*
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.
14+
*
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.
16+
*/
117
// SPDX-License-Identifier: MIT
218

3-
pragma solidity ^0.7.0;
19+
pragma solidity ^0.6.0;
420

521
import "./IERC20.sol";
622
import "./IMVDFunctionalitiesManager.sol";
@@ -14,7 +30,7 @@ import "./IStateHolder.sol";
1430
contract MintNewVotingTokensForStableCoinFunctionality {
1531
function onStart(address, address) public {
1632
IStateHolder stateHolder = IStateHolder(IMVDProxy(msg.sender).getStateHolderAddress());
17-
address stablecoinauthorized = 0x9f4c43A51C9a67F432E5C8BcBFa55312110BCD3A;
33+
address stablecoinauthorized = 0x44086035439E676c02D411880FcCb9837CE37c57;
1834
stateHolder.setBool(
1935
_toStateHolderKey("stablecoin.authorized", _toString(stablecoinauthorized)),
2036
true
@@ -23,7 +39,7 @@ contract MintNewVotingTokensForStableCoinFunctionality {
2339

2440
function onStop(address) public {
2541
IStateHolder stateHolder = IStateHolder(IMVDProxy(msg.sender).getStateHolderAddress());
26-
address stablecoinauthorized = 0x9f4c43A51C9a67F432E5C8BcBFa55312110BCD3A;
42+
address stablecoinauthorized = 0x44086035439E676c02D411880FcCb9837CE37c57;
2743
stateHolder.clear(
2844
_toStateHolderKey("stablecoin.authorized", _toString(stablecoinauthorized))
2945
);
@@ -37,7 +53,6 @@ contract MintNewVotingTokensForStableCoinFunctionality {
3753
) public {
3854
IMVDProxy proxy = IMVDProxy(msg.sender);
3955

40-
// NOTE: Use DFO Protocol to check for authorization
4156
require(
4257
IStateHolder(proxy.getStateHolderAddress()).getBool(
4358
_toStateHolderKey("stablecoin.authorized", _toString(sender))

contracts/stableCoin/standalone/Address.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.7.0;
3+
pragma solidity ^0.6.0;
44

55
/**
66
* @dev Collection of functions related to the address type

contracts/stableCoin/standalone/Context.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.7.0;
3+
pragma solidity ^0.6.0;
44

55
/**
66
* @dev Provides information about the current execution context, including the

contracts/stableCoin/standalone/ERC20.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.7.0;
3+
pragma solidity ^0.6.0;
44

55
import "./Context.sol";
66
import "./IERC20.sol";

contracts/stableCoin/standalone/IDoubleProxy.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
// DOCUMENT
44
interface IDoubleProxy {

contracts/stableCoin/standalone/IERC20.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.7.0;
3+
pragma solidity ^0.6.0;
44

55
/**
66
* @dev Interface of the ERC20 standard as defined in the EIP.

contracts/stableCoin/standalone/IMVDFunctionalitiesManager.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
// DOCUMENT
44
interface IMVDFunctionalitiesManager {

contracts/stableCoin/standalone/IMVDProxy.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
// DOCUMENT
44
interface IMVDProxy {

contracts/stableCoin/standalone/IStableCoin.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.7.0;
3+
pragma solidity ^0.6.0;
44

55
/**
66
* @title Interface for the $uSD aka unified Stable Dollar.

contracts/stableCoin/standalone/IStateHolder.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
// DOCUMENT
44
interface IStateHolder {

contracts/stableCoin/standalone/IUniswapV2Pair.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
// DOCUMENT
44
/**

contracts/stableCoin/standalone/IUniswapV2Router.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.7.0;
1+
pragma solidity ^0.6.0;
22

33
/**
44
* @title Uniswap V2 Router

contracts/stableCoin/standalone/SafeMath.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.7.0;
3+
pragma solidity ^0.6.0;
44

55
/**
66
* @dev Wrappers over Solidity's arithmetic operations with added overflow

contracts/stableCoin/standalone/StableCoin.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.7.0;
3+
pragma solidity ^0.6.0;
44

55
import "./ERC20.sol";
66
import "./IStableCoin.sol";

0 commit comments

Comments
 (0)