Mimic Docs
Search
⌃K

Develop your own strategy

As explained in the architecture section, Mimic offers a Strategy concept to cover any integration with DeFi protocols to provide different investment strategies for a Smart Vault. In order to make sure your Strategy can be integrated with your Smart Vault, it simply needs to comply the following interface, let's go step by step:

Accounting

Accounting is a hard feature to implement via smart contracts. Tracking gains is not an easy task. This is because it can represent anything, it can be the yield earned out of a DeFi protocol, liquidity mining returns, the growth ratio between two assets (eg. ETH vs USDC), or a combination of all of them. Summing up, gains can be anything that the owner and the manager agree upon.
This is why, once again, Mimic design decisions regarding accounting were mostly focused on making sure it was flexible enough. The protocol allows the strategy creator to define what do gains mean. To do that, it uses an abstract concept called "value" to keep track of the strategy gains. By comparing how the value grows, it can determine how gains grow.
gainGrowth=currentTotalValue/previousTotalValuegainGrowth = currentTotalValue / previousTotalValue
To make sure Mimic Smart Vaults can do a proper accounting, strategies need to implement the following methods:
/**
* @dev Tokens accepted to join the strategy
*/
function joinTokens() external view returns (address[] memory);
/**
* @dev Tokens accepted to exit the strategy
*/
function exitTokens() external view returns (address[] memory);
/**
* @dev Tells the last stored value the strategy has over time. Note this value could be outdated.
* For example, if a strategy has a value of 100 in T0, and then it has a value of 120 in T1,
* it means it gained a 20% between T0 and T1.
* @param account Address of the account querying the last value of
*/
function lastValue(address account) external view returns (uint256);
/**
* @dev Tells how much a value unit means expressed in the strategy token.
* For example, if a strategy has a value of 100 in T0, and then it has a value of 120 in T1,
* and the value rate is 1.5, it means the strategy has earned 30 strategy tokens between T0 and T1.
*/
function valueRate() external view returns (uint256);

Join

This process is triggered from the Smart Vault to the Strategy every time a user wants to join a Strategy with a certain amount of tokens. Here is where the Strategy is expected to allocate these assets into the DeFi protocol it is interfacing with. As a result, it is expected to tell how much value the given amount of assets represents after the join and how many tokens it received in return.
/**
* @dev Join the interfaced DeFi protocol
* @param tokensIn List of token addresses to join with
* @param amountsIn List of token amounts to join with
* @param slippage Slippage value to join with
* @param data Arbitrary extra data
* @return tokensOut List of token addresses received after the join
* @return amountsOut List of token amounts received after the join
* @return value Value represented by the joined amount
*/
function join(address[] memory tokensIn, uint256[] memory amountsIn, uint256 slippage, bytes memory data)
external
returns (address[] memory tokensOut, uint256[] memory amountsOut, uint256 value);

Exit

This process is triggered from the Smart Vault to the Strategy every time a user wants to exit a position from it. Strategies are agnostic to user allocations, that's why strategies should simply handle the amounts being exited. Here is where the Strategy is expected to remove the corresponding allocation from the DeFi protocol it is interfacing with. As a result, it is expected to tell how many tokens it received in return and what's the final value left in the strategy after the exit.
/**
* @dev Exit the interfaced DeFi protocol
* @param tokensIn List of token addresses to exit with
* @param amountsIn List of token amounts to exit with
* @param slippage Slippage value to exit with
* @param data Arbitrary extra data
* @return tokensOut List of token addresses received after the exit
* @return amountsOut List of token amounts received after the exit
* @return value Value represented by the exited amount
*/
function exit(address[] memory tokensIn, uint256[] memory amountsIn, uint256 slippage, bytes memory data)
external
returns (address[] memory tokensOut, uint256[] memory amountsOut, uint256 value);

Claim

This is process is triggered from the Smart Vault to the Strategy every time a user wants to claim the accrued rewards. Here is where the Strategy is expected to claim these rewards to the DeFi protocol it is interfacing with and transfer these to the Smart Vault.
/**
* @dev Claim any existing rewards
* @param data Arbitrary extra data
* @return tokens Addresses of the tokens received as rewards
* @return amounts Amounts of the tokens received as rewards
*/
function claim(bytes memory data)
external
returns (address[] memory tokens, uint256[] memory amounts);