BaseStrategy

Git Source

Inherits: Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable

Author: Sperax Foundation

Contract acts as a single interface for implementing specific yield-earning strategies.

State Variables

vault

address public vault;

withdrawSlippage

uint16 public withdrawSlippage;

depositSlippage

uint16 public depositSlippage;

harvestIncentiveRate

uint16 public harvestIncentiveRate;

assetsMapped

address[] internal assetsMapped;

rewardTokenAddress

address[] public rewardTokenAddress;

assetToPToken

mapping(address => address) public assetToPToken;

gap

uint256[40] private __gap__;

Functions

onlyVault

modifier onlyVault();

onlyVaultOrOwner

modifier onlyVaultOrOwner();

constructor

constructor();

updateVault

Update the linked vault contract.

function updateVault(address _newVault) external onlyOwner;

Parameters

updateHarvestIncentiveRate

Updates the HarvestIncentive rate for the user.

function updateHarvestIncentiveRate(uint16 _newRate) external onlyOwner;

Parameters

recoverERC20

A function to recover any erc20 token sent to this strategy mistakenly.

Only callable by owner.

reverts if amount > balance.

function recoverERC20(address token, address receiver, uint256 amount) external onlyOwner;

Parameters

deposit

Deposit an amount of asset into the platform.

function deposit(address _asset, uint256 _amount) external virtual;

Parameters

withdraw

Withdraw an amount of asset from the platform.

function withdraw(address _recipient, address _asset, uint256 _amount)
    external
    virtual
    returns (uint256 amountReceived);

Parameters

Returns

withdrawToVault

Withdraw an amount of asset from the platform to vault.

function withdrawToVault(address _asset, uint256 _amount) external virtual returns (uint256 amount);

Parameters

collectInterest

Withdraw the interest earned of asset from the platform.

function collectInterest(address _asset) external virtual;

Parameters

collectReward

Collect accumulated reward token and send to Vault.

function collectReward() external virtual;

checkBalance

Get the amount of a specific asset held in the strategy, excluding the interest.

Curve: assuming balanced withdrawal.

function checkBalance(address _asset) external view virtual returns (uint256);

Parameters

Returns

checkAvailableBalance

Get the amount of a specific asset held in the strategy, excluding the interest and any locked liquidity that is not available for instant withdrawal.

Curve: assuming balanced withdrawal.

function checkAvailableBalance(address _asset) external view virtual returns (uint256);

Parameters

Returns

checkInterestEarned

AAVE: Get the interest earned on a specific asset. Curve: Get the total interest earned.

Curve: to avoid double-counting, _asset has to be of index 'entryTokenIndex'.

function checkInterestEarned(address _asset) external view virtual returns (uint256);

Parameters

Returns

checkRewardEarned

Get the amount of claimable reward.

function checkRewardEarned() external view virtual returns (RewardData[] memory);

Returns

checkLPTokenBalance

Get the total LP token balance for a asset.

function checkLPTokenBalance(address _asset) external view virtual returns (uint256);

Parameters

supportsCollateral

Check if an asset/collateral is supported.

function supportsCollateral(address _asset) external view virtual returns (bool);

Parameters

Returns

updateSlippage

Change to a new depositSlippage & withdrawSlippage.

function updateSlippage(uint16 _depositSlippage, uint16 _withdrawSlippage) public onlyOwner;

Parameters

_initialize

Initialize the base properties of the strategy.

function _initialize(address _vault, uint16 _depositSlippage, uint16 _withdrawSlippage) internal;

Parameters

_setPTokenAddress

Provide support for asset by passing its pToken address. Add to internal mappings and execute the platform specific, abstract method _abstractSetPToken.

function _setPTokenAddress(address _asset, address _pToken) internal;

Parameters

_removePTokenAddress

Remove a supported asset by passing its index. This method can only be called by the system owner.

function _removePTokenAddress(uint256 _assetIndex) internal returns (address asset);

Parameters

Returns

_splitAndSendReward

Splits and sends the accumulated rewards to harvestor and yield receiver.

Sends the amount to harvestor as per harvestIncentiveRate and sends the rest to yield receiver.

function _splitAndSendReward(address _token, address _yieldReceiver, address _harvestor, uint256 _amount)
    internal
    returns (uint256);

Parameters

Returns

_abstractSetPToken

Call the necessary approvals for the underlying strategy.

function _abstractSetPToken(address _asset, address _pToken) internal virtual;

Parameters

Events

VaultUpdated

event VaultUpdated(address newVaultAddr);

YieldReceiverUpdated

event YieldReceiverUpdated(address newYieldReceiver);

PTokenAdded

event PTokenAdded(address indexed asset, address pToken);

PTokenRemoved

event PTokenRemoved(address indexed asset, address pToken);

Deposit

event Deposit(address indexed asset, uint256 amount);

Withdrawal

event Withdrawal(address indexed asset, uint256 amount);

SlippageUpdated

event SlippageUpdated(uint16 depositSlippage, uint16 withdrawSlippage);

HarvestIncentiveCollected

event HarvestIncentiveCollected(address indexed token, address indexed harvestor, uint256 amount);

HarvestIncentiveRateUpdated

event HarvestIncentiveRateUpdated(uint16 newRate);

InterestCollected

event InterestCollected(address indexed asset, address indexed recipient, uint256 amount);

RewardTokenCollected

event RewardTokenCollected(address indexed rwdToken, address indexed recipient, uint256 amount);

Errors

CallerNotVault

error CallerNotVault(address caller);

CallerNotVaultOrOwner

error CallerNotVaultOrOwner(address caller);

PTokenAlreadySet

error PTokenAlreadySet(address collateral, address pToken);

InvalidIndex

error InvalidIndex();

CollateralNotSupported

error CollateralNotSupported(address asset);

InvalidAssetLpPair

error InvalidAssetLpPair(address asset, address lpToken);

CollateralAllocated

error CollateralAllocated(address asset);

Structs

RewardData

struct RewardData {
    address token;
    uint256 amount;
}