Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-ubik committed Aug 29, 2020
2 parents 44aba83 + 4f3b59a commit 70b955e
Show file tree
Hide file tree
Showing 29 changed files with 1,650 additions and 220 deletions.
2 changes: 1 addition & 1 deletion CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
switch.dfohub.com
www.unifihub.com
281 changes: 276 additions & 5 deletions README.md

Large diffs are not rendered by default.

215 changes: 197 additions & 18 deletions assets/css/style.css

Large diffs are not rendered by default.

Binary file added assets/img/eth-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions assets/plugins/react/react.module.manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ var ReactModuleManager = function() {
if (rendered.props === undefined || rendered.props === null) {
rendered.props = {};
}
rendered.props.className = loader ? rendered.props.defaultClassName : rendered.props.className;
rendered.props.className = loader && rendered.props.defaultClassName ? rendered.props.defaultClassName : rendered.props.className;
if (rendered.props.className === undefined || rendered.props.className === null) {
rendered.props.className = '';
}
if (!rendered.props.className.containsAloneWord(lowerCaseViewName)) {
if (rendered.props.className && !rendered.props.className.containsAloneWord(lowerCaseViewName)) {
if (rendered.props.className !== '') {
lowerCaseViewName += ' '
}
Expand Down Expand Up @@ -247,7 +247,7 @@ var ReactModuleManager = function() {
var element;
var involveLoadedModules = true

if (typeof viewName !== 'string' || window[viewName] === undefined || window[viewName] instanceof HTMLCollection) {
if (typeof viewName !== 'string' || window[viewName] === undefined || window[viewName] instanceof HTMLCollection || window[viewName] instanceof HTMLElement) {
element = React.createElement2.apply(React, callerArguments)
involveLoadedModules = typeof viewName !== 'string'
if (elementName !== undefined) {
Expand Down
114 changes: 94 additions & 20 deletions assets/scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,33 @@ window.loadDFO = async function loadDFO(address, allAddresses) {
var votingToken = window.voidEthereumAddress;

try {
votingToken = (await window.blockchainCall(dfo.methods.getDelegates))[0];
} catch (e) {}
var delegates = await window.web3.eth.call({
to: element.dFO.options.address,
data: element.dFO.methods.getDelegates().encodeABI()
});
try {
delegates = window.web3.eth.abi.decodeParameter("address[]", delegates);
} catch (e) {
delegates = window.web3.eth.abi.decodeParameters(["address", "address", "address", "address", "address", "address"], delegates);
}
votingToken = delegates[0];
} catch (e) {
votingToken = undefined;
}

if (votingToken === window.voidEthereumAddress) {
if (!votingToken || votingToken === window.voidEthereumAddress) {
try {
votingToken = await window.blockchainCall(dfo.methods.getToken);
} catch (e) {}
}

if (votingToken === window.voidEthereumAddress) {
try {
await window.blockchainCall(window.newContract(window.context.votingTokenAbi, votingToken).methods.name);
} catch (e) {
votingToken = undefined;
}

if (!votingToken || votingToken === window.voidEthereumAddress) {
var logs = await window.getLogs({
address,
topics: [
Expand Down Expand Up @@ -92,14 +109,6 @@ window.onEthereumUpdate = function onEthereumUpdate(millis) {
window.ethereum && window.ethereum.on && window.ethereum.on('networkChanged', () => window.onEthereumUpdate(window.web3.currentProvider));
window.ethereum && window.ethereum.on && window.ethereum.on('accountsChanged', () => window.onEthereumUpdate(window.web3.currentProvider));
window.DFOHub(window.web3);
window.stableCoin = window.newContract(window.context.StableCoinAbi, window.getNetworkElement("stableCoinAddress"));
window.doubleProxy = window.newContract(window.context.DoubleProxyAbi, await window.blockchainCall(window.stableCoin.methods.doubleProxy))
window.dfo = window.web3.eth.dfoHub.load(await window.blockchainCall(window.doubleProxy.methods.proxy));
window.uniswapV2Router = window.newContract(window.context.UniswapV2RouterAbi, window.context.uniswapV2RouterAddress);
window.wethToken = window.newContract(window.context.votingTokenAbi, window.wethAddress = window.web3.utils.toChecksumAddress(await window.blockchainCall(window.uniswapV2Router.methods.WETH)));
window.uniswapV2Factory = window.newContract(window.context.UniswapV2FactoryAbi, window.context.uniswapV2FactoryAddress);
window.stableCoin = await window.loadTokenInfos(stableCoin.options.address, window.wethToken.options.address, window.context.StableCoinAbi);
window.votingToken = await window.loadTokenInfos((await (window.dfo = await window.dfo).votingToken).options.address, window.wethToken.options.address);
update = true;
}
delete window.walletAddress;
Expand All @@ -117,6 +126,20 @@ window.onEthereumUpdate = function onEthereumUpdate(millis) {
});
};

window.loadEthereumStuff = async function loadEthereumStuff(oldStableCoin) {
window.uniswapV2Router = window.newContract(window.context.UniswapV2RouterAbi, window.context.uniswapV2RouterAddress);
window.wethToken = window.newContract(window.context.votingTokenAbi, window.wethAddress = window.web3.utils.toChecksumAddress(await window.blockchainCall(window.uniswapV2Router.methods.WETH)));
window.uniswapV2Factory = window.newContract(window.context.UniswapV2FactoryAbi, window.context.uniswapV2FactoryAddress);
try {
window.stableCoin = window.newContract(window.context.StableCoinAbi, window.getNetworkElement(oldStableCoin ? "oldStableCoinAddress" : "stableCoinAddress"));
window.doubleProxy = window.newContract(window.context.DoubleProxyAbi, await window.blockchainCall(window.stableCoin.methods.doubleProxy))
window.dfo = window.web3.eth.dfoHub.load(await window.blockchainCall(window.doubleProxy.methods.proxy));
window.stableCoin = await window.loadTokenInfos(window.stableCoin.options.address, window.context.StableCoinAbi);
window.votingToken = await window.loadTokenInfos((await (window.dfo = await window.dfo).votingToken).options.address);
} catch(e) {
}
};

window.getNetworkElement = function getNetworkElement(element) {
var network = window.context.ethereumNetwork[window.networkId];
if (network === undefined || network === null) {
Expand Down Expand Up @@ -212,6 +235,12 @@ window.getAddress = async function getAddress() {
return (window.walletAddress = (await window.web3.eth.getAccounts())[0]);
};

window.consumeAddressBarParam = function consumeAddressBarParam(paramName) {
var param = window.addressBarParams[paramName];
delete window.addressBarParams[paramName];
return param;
};

window.getSendingOptions = function getSendingOptions(transaction) {
return new Promise(async function(ok, ko) {
if (transaction) {
Expand Down Expand Up @@ -1200,22 +1229,21 @@ window.eliminateFloatingFinalZeroes = function eliminateFloatingFinalZeroes(valu
return split[1].length === 0 ? split[0] : split.join(decSeparator);
};

window.loadTokenInfos = async function loadTokenInfos(addresses, wethAddress, abi) {
wethAddress = wethAddress || await window.blockchainCall(window.newContract(window.context.uniSwapV2RouterAbi, window.context.uniSwapV2RouterAddress).methods.WETH);
wethAddress = window.web3.utils.toChecksumAddress(wethAddress);
window.loadTokenInfos = async function loadTokenInfos(addresses, abi, noLogo) {
var single = (typeof addresses).toLowerCase() === 'string';
addresses = single ? [addresses] : addresses;
var tokens = [];
window.tokenInfosCache = window.tokenInfosCache || {};
for (var address of addresses) {
address = window.web3.utils.toChecksumAddress(address);
var token = window.newContract(abi || window.context.votingTokenAbi, address);
tokens.push({
tokens.push(window.tokenInfosCache[address] = window.tokenInfosCache[address] || {
address,
token,
name: address === wethAddress ? 'Ethereum' : await window.blockchainCall(token.methods.name),
symbol: address === wethAddress ? 'ETH' : await window.blockchainCall(token.methods.symbol),
decimals: address === wethAddress ? '18' : await window.blockchainCall(token.methods.decimals),
logo: await window.loadLogo(address === wethAddress ? window.voidEthereumAddress : address)
name: address === window.wethAddress ? 'Ethereum' : await window.blockchainCall(token.methods.name),
symbol: address === window.wethAddress ? 'ETH' : await window.blockchainCall(token.methods.symbol),
decimals: address === window.wethAddress ? '18' : await window.blockchainCall(token.methods.decimals),
logo: noLogo ? undefined : await window.loadLogo(address === window.wethAddress ? window.voidEthereumAddress : address)
});
}
return single ? tokens[0] : tokens;
Expand Down Expand Up @@ -1272,4 +1300,50 @@ window.getEthereumPrice = async function getEthereumPrice() {
price,
requestExpires: new Date().getTime() + window.context.coingeckoEthereumPriceRequestInterval
}).price;
};

window.loadUniswapPairs = async function loadUniswapPairs(token, indexes) {
window.pairCreatedTopic = window.pairCreatedTopic || window.web3.utils.sha3('PairCreated(address,address,address,uint256)');
var address = window.web3.utils.toChecksumAddress(token.address);
if (address === window.voidEthereumAddress) {
address = window.wethAddress;
}
var myToken = window.web3.eth.abi.encodeParameter('address', address);
var logs = await window.getLogs({
address: window.context.uniSwapV2FactoryAddress,
fromBlock: '0',
topics: [
window.pairCreatedTopic, [myToken]
]
});
logs.push(...(await window.getLogs({
address: window.context.uniSwapV2FactoryAddress,
fromBlock: '0',
topics: [
window.pairCreatedTopic, [],
[myToken]
]
})));
var uniswapPairs = [];
var alreadyAdded = {};
for (var log of logs) {
for (var topic of log.topics) {
if (topic === window.pairCreatedTopic || topic.toLowerCase() === myToken.toLowerCase()) {
continue;
}
var pairTokenAddress = window.web3.utils.toChecksumAddress(window.web3.eth.abi.decodeParameters(['address', 'uint256'], log.data)[0]);
if (alreadyAdded[pairTokenAddress]) {
continue;
}
alreadyAdded[pairTokenAddress] = true;
var pairToken = await window.loadTokenInfos(pairTokenAddress, window.context.UniswapV2PairAbi, true);
var token0 = window.web3.utils.toChecksumAddress(await window.blockchainCall(pairToken.token.methods.token0));
var token1 = window.web3.utils.toChecksumAddress(await window.blockchainCall(pairToken.token.methods.token1));
pairToken.token0 = token0 === address ? token : await window.loadTokenInfos(token0, undefined, true);
pairToken.token1 = token1 === address ? token : await window.loadTokenInfos(token1, undefined, true);
pairToken.key = `${token0}_${token1}-${token1}_${token0}`;
uniswapPairs.push(indexes[pairToken.key] = pairToken);
}
}
return uniswapPairs;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
/* 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.
*
* 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.
*
* 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.
*/
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;
pragma solidity 0.7.0;

import "./IERC20.sol";
import "./IMVDFunctionalitiesManager.sol";
Expand All @@ -14,7 +30,7 @@ import "./IStateHolder.sol";
contract MintNewVotingTokensForStableCoinFunctionality {
function onStart(address, address) public {
IStateHolder stateHolder = IStateHolder(IMVDProxy(msg.sender).getStateHolderAddress());
address stablecoinauthorized = 0x9f4c43A51C9a67F432E5C8BcBFa55312110BCD3A;
address stablecoinauthorized = 0x44086035439E676c02D411880FcCb9837CE37c57;
stateHolder.setBool(
_toStateHolderKey("stablecoin.authorized", _toString(stablecoinauthorized)),
true
Expand All @@ -23,7 +39,7 @@ contract MintNewVotingTokensForStableCoinFunctionality {

function onStop(address) public {
IStateHolder stateHolder = IStateHolder(IMVDProxy(msg.sender).getStateHolderAddress());
address stablecoinauthorized = 0x9f4c43A51C9a67F432E5C8BcBFa55312110BCD3A;
address stablecoinauthorized = 0x44086035439E676c02D411880FcCb9837CE37c57;
stateHolder.clear(
_toStateHolderKey("stablecoin.authorized", _toString(stablecoinauthorized))
);
Expand All @@ -37,7 +53,6 @@ contract MintNewVotingTokensForStableCoinFunctionality {
) public {
IMVDProxy proxy = IMVDProxy(msg.sender);

// NOTE: Use DFO Protocol to check for authorization
require(
IStateHolder(proxy.getStateHolderAddress()).getBool(
_toStateHolderKey("stablecoin.authorized", _toString(sender))
Expand Down
Loading

0 comments on commit 70b955e

Please sign in to comment.