How Routines Contracts and Operations Work
The Routines protocol is built using the Covenants AMM Aggregator, so that it supports multiple AMMs and Uniswap v3.
This protocol is Factory based, which means that anyone can deploy its own customized Inflation contract interacting with the Covenants Inflation Factory.
Learn what a factory is here.
The Inflation contract can be hosted by any Organization, DAO wallet and smart contract using Extension. The Extension is a contract, linked to the main contract, that allows interacting with the Inflation contract itself. In this way, all the specific integration code can be written in the Extension and not in the general purpose contract.

How Routines contract works

Each Covenants Routines contract is composed of one or more executable operations. Each operation can only circulate one token; to manage the inflation of two different tokens, two different operations are required.
An operation can involve any combination of the following:
  • The minting of the input token.
  • The transferral of the input token from one address to one or more others.
  • The swapping of the input token for one or more other tokens in one AMM.
  • The burning of the input token or the burning of the output token after a swap.
If an operation involves a swap, the input token is the token being swapped, and the output token is the token the input token is being swapped for. So, for example, if the operation will swap USDC for OS, USDC is the input token and OS is the output token. If the operation involves a transfer, we have only one token, so the input-output dichotomy does not apply.
Each contract, which can involve multiple and different operations, has one Entry.
The Entry is represented by the following struct in the contract:
1
struct FixedInflationEntry {
2
string name;
3
uint256 blockInterval;
4
uint256 lastBlock;
5
uint256 callerRewardPercentage;
6
}
Copied!
  • name -> represents the name of the contract.
  • blockInterval -> the interval of time (expressed in blocks) that must pass between each execution of an operation.
  • lastBlock -> It can be populated to program a delayed operation start. In this way the first Operation cannot be executed until the lastBlock+blockInterval is reached. If it is set as 0 the first Operation can be performed at any time. In both cases, all subsequent operations can be executed every blockInterval.
  • callerRewardPercentage -> the reward the executor will receive. Allows the creation of an incentive for executing the operation with a public call, not only the call by the internal hosting of the contract. The executor can freely choose to be rewarded with either input or output tokens; for example, if the operation swaps OS (input token) for ETH (output token), he can choose to be rewarded in either.

Operation

Every Routines Operation has the following parameters:
1
struct FixedInflationOperation {
2
3
address inputTokenAddress;
4
uint256 inputTokenAmount;
5
bool inputTokenAmountIsPercentage;
6
bool inputTokenAmountIsByMint;
7
8
address ammPlugin;
9
address[] liquidityPoolAddresses;
10
address[] swapPath;
11
bool enterInETH;
12
bool exitInETH;
13
14
address[] receivers;
15
uint256[] receiversPercentages;
16
}
Copied!
  • inputTokenAddress -> address of the operations' input token.
  • inputTokenAmount -> amount of the input token.
  • inputTokenAmountIsPercentage -> boolean value that expresses whether the amount of the input token (previous field) is expressed as a percentage value (true) or not (false). If the InputTokenAmountIsPercentage value is true, the percentage is expressed in reference to the total supply of the input token. If the value is false , only the amount is expressed.
  • ammPlugin -> address of the AMM chosen to be used for possible token swap operations. If the ammPlugin address is passed as the Uniswap v3 swap router address, Uniswap v3 is used to perform the Operation. This field is equal to address(0) if the operation is a transfer.
  • liquidityPoolAddresses -> array containing the liquidity pool token addresses of a swap operation (so this field is only populated if a swap operation is involved). The first element of the array must necessarily contain the input token.
  • swapPath -> This array contains the path that the swap operation must follow (so this field is only populated if a swap operation is involved). So for example, if you have an operation that swaps OS to ETH and then to USDC, you'll have the liquidityPoolAddresses containing OS/ETH LP address in the fist position and ETH/USDC LP address in the second place. The swapPath array will contain ETH in the first position and USDC in the second one.
  • enterInEth -> expresses whether the input token is ETH (true) or not (false).
  • exitInEth -> expresses whether the output token is ETH (true) or not (false).
  • receivers -> array that contains the addresses of the various receivers in case of a transfer operation. If it is passed as address(0), a burn operation is performed.
  • receiversPercentages -> array that contains the percentages of the various receivers in case of a transfer operation. The length of this array must be equal to receivers array length -1, the last percentage is in fact calculated automatically.
The logic to mint the tokens to be used in a swap or transfer must be written in the Extension logic. Look at here for an example.