Execute Operation

The execute function must be used to perform an Inflation operation. This function is public as it can be called by the host or anyone else with an interest in doing so, and requires that the linked extension is active:

function execute(bool earnByAmounts) public activeExtensionOnly returns(bool executed)

The function uses, as input, only the earnByAmounts parameter, which is a boolean value representing if the executor's reward is calculated and transferred before (true) or after (false) a swap operation. In the first case, the reward is expressed as input token; in the second, as output token.

The execute function requests from the extension the tokens needed to perform the operation(s) by calling, internally, the _ensureExecute function:

try IFixedInflationExtension(extension).receiveTokens(_tokensToTransfer, _tokenAmounts, _tokenMintAmounts)

At this moment, the extension receiveTokens function is used (see the Inflation Extension section for more details).

If the contract does not successfully receive the tokens from the extension, the operation is not performed and the extension is automatically deactivated by calling the deactivationByFailure function on the extension contract. This means that if the extension is not subsequently reactivated by the host, no more operations can be performed in the contract.

If the contract does successfully receive the tokens from the extension, the Entry lastBlock is updated (set as the execution block) and performs the operation by internally calling the _execute function:

_entry.lastBlock = block.number;
_execute(earnByAmounts, msg.sender);

The _execute facilitator function takes as input the earnByAmounts value (called EarnByInput in this case) and the execute msg.sender:

function _execute(bool earnByInput, address rewardReceiver) private

The _execute function handles the type of operation being performed and calculates the token amount operation through the _calculateTokenAmount function. So, depending on whether the operation is a transfer or a swap, it calls the appropriate function that takes care of it:

 if(operation.ammPlugin == address(0)) {
    _transferTo(operation.inputTokenAddress, amountIn, rewardReceiver, _entry.callerRewardPercentage, operation.receivers, operation.receiversPercentages);
 } else {
    _swap(operation, amountIn, rewardReceiver, _entry.callerRewardPercentage, earnByInput);
 }

Last updated