Routines Extension
The Extension plays a fundamental role in Covenants Routines. Its implementation makes it possible to customize and extend a contract to achieve an extremely high level of security. Indeed, a contract has no choice but to have an extension, as it sets the parameters for both basic and advanced functionalities.
In particular, the Extension sends the token required by the specific Operation of the Routines contract. The Extension has also the right to mint tokens and send them to the Inflation contract if a mint is required by the Operation.
There are two types of Routines extensions:
The default extension is developed to be used by individual wallets or projects that do not require special integration and/or custom methods or features. It is cloned and deployed by the Routines Factory (the address of which was passed in Factory
Constructor
), in case you choose to use it:function cloneFixedInflationDefaultExtension() external returns(address clonedExtension);
The Extension has a status, i.e. it is active or it is inactive. By default, the extension is inactive, and must be activated by the host. The
setactive
function is used to change the status of the Extension. The active status allows the Extension to perform contract operations. The state of the Extension also represents whether it correctly contains the amount of tokens needed to perform operations. When it is active and you try to perform an operation, this will only succeed if the extension has enough tokens. If it doesn't and the operation accordingly fails, the extension automatically becomes inactive and no more operations can be performed until the Extension returns to the active state.
The default Extension provides a set of basic and general purpose functionalities designed for wallets or hosts that do not require a level of customization in functionality to interact with farming contracts.
Its main functions are:
Init
function
function init(address host) override public {
sets the input address as the host
address
setHost
function setHost(address host) public virtual override hostOnly {
updates the extension host
setActive
function setActive(bool _active) public override virtual hostOnly { active = _active; }
changes the extension status
setEntry
function setEntry(FixedInflationEntry memory newEntry, FixedInflationOperation[] memory newOperations) public override hostOnly {
IFixedInflation(_fixedInflationContract).setEntry(newEntry, newOperations); }
Calls internally the
setEntry
of the contract to create/update a contract directly from the extensionreceiveTokens
function receiveTokens(address[] memory tokenAddresses, uint256[] memory transferAmounts, uint256[] memory amountsToMint) public override fixedInflationOnly {
Function used by the FI contract to request tokens from the extension to perform operations
If the tokens come from reserve (so
amountsToMint []=0
), the function calls internally the safeTransfer
to transfer the tokens to the extension. If they are minted ( so amountsToMint [] >0
), the function calls internally the _mintAndTransfer
to mint the required amount and sends them to the contract.flushBack
function flushBack(address[] memory tokenAddresses) public override hostOnly {
send back tokens from the contract to the extension address passing the token
address(es)
deactivationByFailure
function deactivationByFailure() public override fixedInflationOnly {
called by the contract to automatically disable the extension if there aren't enough tokens to perform operations
_mintAndTransfer
function _mintAndTransfer(address erc20TokenAddress, address recipient, uint256 value) internal virtual {
calls the classic
IERC20 mint
method on the ERC20 token address
passed.To perform this operation, the Extension contract must have minting rights of the token.
- burnToken
function burnToken(address erc20TokenAddress, uint256 value) external override fixedInflationOnly
This function, callable only by the FI contract itself, is used to perform a burn operation on an ERC20 calling the
_burn
function. This function is used when a burn operation is performed (address receiver passed as address(0
) in the FixedInflationOperation
.- _burn
function _burn(address erc20TokenAddress, uint256 value) internal virtual
calls the classic
IERC20 burn
method on the ERC20
input/output token address
passed.
The use of a custom extension allows for the external integration of different projects (such as Organization / DAOs / custom smart contracts) with Covenants Inflation contracts. The extension is the de facto integration mode.
Last modified 1yr ago