tornado-instances/contracts/InstanceAdditionProposal.sol

65 lines
2.0 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
pragma abicoder v2;
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
import "./interfaces/IInstanceRegistry.sol";
import "./interfaces/IInstanceFactory.sol";
contract InstanceAdditionProposal {
using SafeMath for uint256;
IInstanceFactory public immutable instanceFactory;
IInstanceRegistry public immutable instanceRegistry;
struct InstanceAdditionData {
address tokenAddress;
uint40 smallDenomination;
uint16 base10Exponent;
uint24 uniPoolSwappingFee;
uint16 protocolFee;
}
InstanceAdditionData[] public toAdd;
event AddInstanceForRegistry(address instance, address token, uint256 denomination);
constructor(address _instanceFactory, address _instanceRegistry, InstanceAdditionData[] memory _toAdd) {
instanceFactory = IInstanceFactory(_instanceFactory);
instanceRegistry = IInstanceRegistry(_instanceRegistry);
// Copying structs is not implemented
for (uint256 i = 0; i < _toAdd.length; i++) {
toAdd.push(_toAdd[i]);
}
}
function executeProposal() external {
uint256 howMany = toAdd.length;
for (uint256 i = 0; i < howMany; i++) {
InstanceAdditionData memory data = toAdd[i];
uint256 denomination = uint256(data.smallDenomination).mul(10 ** uint256(data.base10Exponent));
address instance = instanceFactory.createInstanceClone(denomination, data.tokenAddress);
IInstanceRegistry.Instance memory newInstanceData = IInstanceRegistry.Instance(
data.tokenAddress != address(0),
IERC20(data.tokenAddress),
IInstanceRegistry.InstanceState.ENABLED,
data.uniPoolSwappingFee,
data.protocolFee
);
IInstanceRegistry.Tornado memory tornadoForUpdate = IInstanceRegistry.Tornado(instance, newInstanceData);
instanceRegistry.updateInstance(tornadoForUpdate);
emit AddInstanceForRegistry(address(instance), data.tokenAddress, denomination);
}
}
}