relayer-registry/contracts/Proposal.sol

111 lines
3.9 KiB
Solidity
Raw Normal View History

2021-08-13 16:06:29 +02:00
/*
This proposal introduces a registery for relayers where anyone can stake TORN and become relayer.
More info: https://torn.community/t/
*/
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "./TornadoProxyV3.sol";
import "./RelayerRegistry.sol";
2021-08-23 11:59:28 +02:00
import "./AdminUpgradeableProxy.sol";
2021-08-13 16:06:29 +02:00
interface IProposal4 {
function getInstances() external view returns (TornadoProxy.Tornado[] memory instances);
}
2021-08-20 11:30:44 +02:00
interface ITornadoProxy {
function updateInstance(TornadoProxy.Tornado calldata) external;
2021-08-23 11:59:28 +02:00
function tornadoTrees() external view returns (address);
function governance() external view returns (address);
function instances(ITornadoInstance)
external
view
returns (
bool,
IERC20,
TornadoProxy.InstanceState
);
2021-08-20 11:30:44 +02:00
}
2021-08-13 16:06:29 +02:00
interface TornadoTrees is ITornadoTrees {
function setTornadoProxyContract(address _tornadoProxy) external;
}
contract Proposal {
2021-08-20 11:30:44 +02:00
ITornadoProxy public constant tornadoProxyV2 = ITornadoProxy(0x722122dF12D4e14e13Ac3b6895a86e84145b6967);
2021-08-13 16:06:29 +02:00
TornadoTrees public constant tornadoTrees = TornadoTrees(0x527653eA119F3E6a1F5BD18fbF4714081D7B31ce);
IProposal4 public constant proposal4 = IProposal4(0x4B6C07B8940a7602fE4332AFa915b366e56eAce5);
address public constant governance = 0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce;
2021-08-23 11:59:28 +02:00
address public constant registryImpl = 0xE9c171C583115282fe1ed6e93E7b1b8aE758Ed51;
2021-08-13 19:42:57 +02:00
uint256 public constant txFee = 0.1 ether;
2021-08-13 16:06:29 +02:00
uint256 public constant minStake = 500 ether;
2021-08-20 11:30:44 +02:00
uint256 public constant govFeeSplitPercent = 95;
2021-08-13 16:06:29 +02:00
event DeploymentOf(string name, address addr);
function executeProposal() public {
TornadoProxy.Tornado[] memory instances = getInstances();
// disabling all instances on current tornadoProxy
for (uint256 i = 0; i < instances.length; i++) {
2021-08-23 11:59:28 +02:00
tornadoProxyV2.updateInstance(
TornadoProxy.Tornado({
addr: instances[i].addr,
instance: TornadoProxy.Instance({ isERC20: false, token: IERC20(0), state: TornadoProxy.InstanceState.DISABLED })
2021-08-13 16:06:29 +02:00
})
2021-08-23 11:59:28 +02:00
);
2021-08-13 16:06:29 +02:00
}
2021-08-23 11:59:28 +02:00
require(isContract(registryImpl), "Relayer registry implementation not deployed");
2021-08-13 19:42:57 +02:00
2021-08-23 11:59:28 +02:00
AdminUpgradeableProxy registryProxy = new AdminUpgradeableProxy(registryImpl, governance, "");
2021-08-13 19:42:57 +02:00
emit DeploymentOf("Relayer Registry proxy", address(registryProxy));
2021-08-13 16:06:29 +02:00
// deploying the new tornadoProxy
TornadoProxyV3 tornadoProxyV3 = new TornadoProxyV3(
address(tornadoProxyV2.tornadoTrees()),
tornadoProxyV2.governance(),
instances,
address(registryProxy)
);
2021-08-13 19:42:57 +02:00
emit DeploymentOf("Tornado Proxy V3", address(tornadoProxyV3));
2021-08-13 16:06:29 +02:00
// initializing Relayer registry
2021-08-13 19:42:57 +02:00
RelayerRegistry registry = RelayerRegistry(address(registryProxy));
2021-08-20 11:30:44 +02:00
registry.initialize(address(tornadoProxyV3), txFee, minStake, govFeeSplitPercent);
2021-08-13 16:06:29 +02:00
// registering the new tornadoProxy contract in tornadoTrees
tornadoTrees.setTornadoProxyContract(address(tornadoProxyV3));
}
/// @dev Returns actuall all supported instances with actual state
function getInstances() public view returns (TornadoProxy.Tornado[] memory instances) {
instances = proposal4.getInstances();
2021-08-23 11:59:28 +02:00
for (uint256 i = 0; i < instances.length; i++) {
2021-08-13 16:06:29 +02:00
(bool isERC20, IERC20 token, TornadoProxy.InstanceState state) = tornadoProxyV2.instances(instances[i].addr);
require(instances[i].instance.isERC20 == isERC20, "Incorrect instance state (isERC20)");
require(instances[i].instance.token == token, "Incorrect instance token");
instances[i].instance.state = state;
}
}
2021-08-23 11:59:28 +02:00
function isContract(address account) public view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly {
size := extcodesize(account)
}
return size > 0;
}
2021-08-13 16:06:29 +02:00
}