2023-04-13 14:51:43 +03:00
|
|
|
// 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";
|
|
|
|
|
2023-04-14 22:16:26 +03:00
|
|
|
struct InstanceAdditionData {
|
|
|
|
address tokenAddress;
|
|
|
|
uint40 smallDenomination;
|
|
|
|
uint16 base10Exponent;
|
|
|
|
uint24 uniPoolSwappingFee;
|
|
|
|
uint16 protocolFee;
|
|
|
|
}
|
|
|
|
|
|
|
|
contract InstanceAdditionDataProvider {
|
|
|
|
InstanceAdditionData[] public toAddData;
|
|
|
|
|
|
|
|
constructor(InstanceAdditionData[] memory _toAdd) {
|
|
|
|
for (uint256 i = 0; i < _toAdd.length; i++) {
|
|
|
|
toAddData.push(_toAdd[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllDataToAdd() external view returns (InstanceAdditionData[] memory) {
|
|
|
|
return toAddData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-13 14:51:43 +03:00
|
|
|
contract InstanceAdditionProposal {
|
|
|
|
using SafeMath for uint256;
|
|
|
|
|
2023-04-14 22:16:26 +03:00
|
|
|
InstanceAdditionDataProvider public immutable provider;
|
2023-04-13 14:51:43 +03:00
|
|
|
IInstanceFactory public immutable instanceFactory;
|
|
|
|
IInstanceRegistry public immutable instanceRegistry;
|
|
|
|
|
|
|
|
event AddInstanceForRegistry(address instance, address token, uint256 denomination);
|
|
|
|
|
|
|
|
constructor(address _instanceFactory, address _instanceRegistry, InstanceAdditionData[] memory _toAdd) {
|
2023-04-14 22:16:26 +03:00
|
|
|
provider = new InstanceAdditionDataProvider(_toAdd);
|
2023-04-13 14:51:43 +03:00
|
|
|
instanceFactory = IInstanceFactory(_instanceFactory);
|
|
|
|
instanceRegistry = IInstanceRegistry(_instanceRegistry);
|
|
|
|
}
|
|
|
|
|
|
|
|
function executeProposal() external {
|
2023-04-14 22:16:26 +03:00
|
|
|
InstanceAdditionData[] memory _toAddData = provider.getAllDataToAdd();
|
|
|
|
|
|
|
|
uint256 howMany = _toAddData.length;
|
2023-04-13 14:51:43 +03:00
|
|
|
|
|
|
|
for (uint256 i = 0; i < howMany; i++) {
|
2023-04-13 23:03:12 +03:00
|
|
|
// Read out the data for the new instance
|
2023-04-14 22:16:26 +03:00
|
|
|
InstanceAdditionData memory data = _toAddData[i];
|
2023-04-13 14:51:43 +03:00
|
|
|
|
2023-04-13 23:03:12 +03:00
|
|
|
// Safely calculate the denomination
|
2023-04-13 14:51:43 +03:00
|
|
|
uint256 denomination = uint256(data.smallDenomination).mul(10 ** uint256(data.base10Exponent));
|
|
|
|
|
2023-04-13 23:03:12 +03:00
|
|
|
// Create the instance
|
2023-04-13 14:51:43 +03:00
|
|
|
address instance = instanceFactory.createInstanceClone(denomination, data.tokenAddress);
|
|
|
|
|
2023-04-13 23:03:12 +03:00
|
|
|
// Prepare the data for the registry.
|
2023-04-13 14:51:43 +03:00
|
|
|
IInstanceRegistry.Instance memory newInstanceData = IInstanceRegistry.Instance(
|
|
|
|
data.tokenAddress != address(0),
|
|
|
|
IERC20(data.tokenAddress),
|
|
|
|
IInstanceRegistry.InstanceState.ENABLED,
|
|
|
|
data.uniPoolSwappingFee,
|
|
|
|
data.protocolFee
|
|
|
|
);
|
|
|
|
|
2023-04-13 23:03:12 +03:00
|
|
|
// Convert the data.
|
2023-06-12 18:50:25 +03:00
|
|
|
IInstanceRegistry.Tornado memory tornadoForUpdate = IInstanceRegistry.Tornado(
|
|
|
|
instance,
|
|
|
|
newInstanceData
|
|
|
|
);
|
2023-04-13 14:51:43 +03:00
|
|
|
|
2023-04-13 23:03:12 +03:00
|
|
|
// Update the instance data in the registry.
|
2023-04-13 14:51:43 +03:00
|
|
|
instanceRegistry.updateInstance(tornadoForUpdate);
|
|
|
|
|
|
|
|
emit AddInstanceForRegistry(address(instance), data.tokenAddress, denomination);
|
|
|
|
}
|
|
|
|
}
|
2023-04-14 22:16:26 +03:00
|
|
|
|
|
|
|
function getDataToAddByIndex(uint256 index) external view returns (InstanceAdditionData memory data) {
|
|
|
|
// The compiler is behaving weird here. Something to do with struct type inference.
|
|
|
|
return (provider.getAllDataToAdd())[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllDataToAdd() external view returns (InstanceAdditionData[] memory) {
|
|
|
|
return provider.getAllDataToAdd();
|
|
|
|
}
|
2023-04-13 14:51:43 +03:00
|
|
|
}
|