UMA Controller Factory
The UMAControllerFactory
deploys an automated controller contract, which triggers the safety module if the UMA Optimistic Oracle answers "YES" to a YES-OR-NO query, e.g., "Was protocol ABCD hacked on or after block 42." Since queries are user-provided, UMA controllers can offer protection for any arbitrary event.
Determine Controller Parameters
The UMAControllerFactory's deployController
function can be used to deploy a new UMA controller:
struct ControllerMetadata {
// The name that should be used for SafetyModules that use the controller
string name;
// A human-readable description of the controller.
string description;
// The URI of a logo image to represent the controller.
string logoURI;
// Any extra data that should be included in the controller's metadata.
string extraData;
}
/// @notice Call this function to deploy a UMAController.
/// @param _query The query that the controller will send to the UMA Optimistic
/// Oracle for evaluation.
/// @param _rewardToken The token used to pay the reward to users that propose
/// answers to the query. The reward token must be approved by UMA governance.
/// Approved tokens can be found with the UMA AddressWhitelist contract on each
/// chain supported by UMA.
/// @param _rewardAmount The amount of rewardToken that will be paid as a
/// reward to anyone who proposes an answer to the query.
/// @param _refundRecipient Default address that will recieve any leftover
/// rewards at UMA query settlement time.
/// @param _bondAmount The amount of `rewardToken` that must be staked by a
/// user wanting to propose or dispute an answer to the query. See UMA's price
/// dispute workflow for more information. It's recommended that the bond
/// amount be a significant value to deter addresses from proposing malicious,
/// false, or otherwise self-interested answers to the query.
/// @param _proposalDisputeWindow The window of time in seconds within which a
/// proposed answer may be disputed. See UMA's "customLiveness" setting for
/// more information. It's recommended that the dispute window be fairly long
/// (12-24 hours), given the difficulty of assessing expected queries (e.g.
/// "Was protocol ABCD hacked") and the amount of funds potentially at stake.
/// @param _metadata See ControllerMetadata for more info.
function deployController(
string memory _query,
IERC20 _rewardToken,
uint256 _rewardAmount,
address _refundRecipient,
uint256 _bondAmount,
uint256 _proposalDisputeWindow,
ControllerMetadata memory _metadata
) external returns (UMAController);
For more information on the expected format/structure of query strings, see the official UMIP-107 documentation.
If you're looking for inspiration or examples, existing queries can be viewed here.
Deploy Controller
Once you've decided on the parameters for the controller, you can deploy it as follows:
// Define your parameters.
string memory _query;
IERC20 _rewardToken;
uint256 _rewardAmount;
address _refundRecipient;
uint256 _bondAmount;
uint256 _proposalDisputeWindow;
string _name;
string _description;
string _logoURI;
string _extraData;
address _umaControllerFactoryAddress;
// Instantiate the controller factory.
UMAControllerFactory _factory = UMAControllerFactory(_umaControllerFactoryAddress);
// Check to see if a controller has already been deployed with your desired configs.
address _availableController = _factory.findAvailableController(
_query,
_rewardToken,
_rewardAmount,
_refundRecipient,
_bondAmount,
_proposalDisputeWindow
);
if (_availableController == address(0)) {
// There is no available controller with your desired configuration. We will
// have to deploy a new one! First, we approve the factory to transfer the
// reward for us.
rewardToken.approve(address(_factory), _rewardAmount);
// Then we deploy the controller.
_availableController = address(
_factory.deployController(
_query,
_rewardToken,
_rewardAmount,
_refundRecipient,
_bondAmount,
_proposalDisputeWindow,
ControllerMetadata(_name, _description, _logoURI, _extraData)
)
);
emit log("New controller deployed \o/");
} else {
// A controller exactly like the one you wanted already exists!
// Since controllers can be re-used, there's no need to deploy a new one.
emit log("Found existing controller with specified configs");
}
emit log_named_address(
"Your controller is available at this address:",
_availableController
);
Note:
The reward token is used to incentivize users to answer the query correctly. The reward token must be whitelisted by UMA; attempts to deploy a controller with an unsupported token will revert.
The reward amount must be pre-approved for the factory to spend; otherwise, the deploy will revert.
For the addresses of factories deployed to various chains, see Contracts Deployment Registry.
Last updated