Skip to main content

BaseHarvester

BaseHarvester

SwapPlatform

enum SwapPlatform {
UniswapV2Compatible,
UniswapV3,
Balancer,
Curve
}

SupportedStrategyUpdate

event SupportedStrategyUpdate(address strategyAddress, bool isSupported)

RewardTokenConfigUpdated

event RewardTokenConfigUpdated(address tokenAddress, uint16 allowedSlippageBps, uint16 harvestRewardBps, enum BaseHarvester.SwapPlatform swapPlatform, address swapPlatformAddr, bytes swapData, uint256 liquidationLimit, bool doSwapRewardToken)

RewardTokenSwapped

event RewardTokenSwapped(address rewardToken, address swappedInto, enum BaseHarvester.SwapPlatform swapPlatform, uint256 amountIn, uint256 amountOut)

RewardProceedsTransferred

event RewardProceedsTransferred(address token, address farmer, uint256 protcolYield, uint256 farmerFee)

RewardProceedsAddressChanged

event RewardProceedsAddressChanged(address newProceedsAddress)

EmptyAddress

error EmptyAddress()

InvalidSlippageBps

error InvalidSlippageBps()

InvalidHarvestRewardBps

error InvalidHarvestRewardBps()

InvalidSwapPlatform

error InvalidSwapPlatform(enum BaseHarvester.SwapPlatform swapPlatform)

InvalidUniswapV2PathLength

error InvalidUniswapV2PathLength()

InvalidTokenInSwapPath

error InvalidTokenInSwapPath(address token)

EmptyBalancerPoolId

error EmptyBalancerPoolId()

InvalidCurvePoolAssetIndex

error InvalidCurvePoolAssetIndex(address token)

UnsupportedStrategy

error UnsupportedStrategy(address strategyAddress)

SlippageError

error SlippageError(uint256 actualBalance, uint256 minExpected)

BalanceMismatchAfterSwap

error BalanceMismatchAfterSwap(uint256 actualBalance, uint256 minExpected)

RewardTokenConfig

struct RewardTokenConfig {
uint16 allowedSlippageBps;
uint16 harvestRewardBps;
address swapPlatformAddr;
bool doSwapRewardToken;
enum BaseHarvester.SwapPlatform swapPlatform;
uint256 liquidationLimit;
}

rewardTokenConfigs

mapping(address => struct BaseHarvester.RewardTokenConfig) rewardTokenConfigs

supportedStrategies

mapping(address => bool) supportedStrategies

vaultAddress

address vaultAddress

rewardProceedsAddress

address rewardProceedsAddress

Address receiving rewards proceeds. Initially the Vault contract later will possibly be replaced by another contract that eases out rewards distribution.

baseTokenAddress

address baseTokenAddress

All tokens are swapped to this token before it gets transferred to the rewardProceedsAddress. USDT for OUSD and WETH for OETH.

baseTokenDecimals

uint256 baseTokenDecimals

uniswapV2Path

mapping(address => address[]) uniswapV2Path

uniswapV3Path

mapping(address => bytes) uniswapV3Path

balancerPoolId

mapping(address => bytes32) balancerPoolId

CurvePoolIndices

struct CurvePoolIndices {
uint128 rewardTokenIndex;
uint128 baseTokenIndex;
}

curvePoolIndices

mapping(address => struct BaseHarvester.CurvePoolIndices) curvePoolIndices

constructor

constructor(address _vaultAddress, address _baseTokenAddress) internal

setRewardProceedsAddress

function setRewardProceedsAddress(address _rewardProceedsAddress) external

Set the Address receiving rewards proceeds.

Parameters

NameTypeDescription
_rewardProceedsAddressaddressAddress of the reward token

setRewardTokenConfig

function setRewardTokenConfig(address _tokenAddress, struct BaseHarvester.RewardTokenConfig tokenConfig, bytes swapData) external

Add/update a reward token configuration that holds harvesting config variables

Parameters

NameTypeDescription
_tokenAddressaddressAddress of the reward token
tokenConfigstruct BaseHarvester.RewardTokenConfig
swapDatabytesAdditional data required for swapping

_decodeUniswapV2Path

function _decodeUniswapV2Path(bytes data, address token) internal view returns (address[] path)

Decodes the data passed into Uniswap V2 path and validates it to make sure the path is for token to baseToken

Parameters

NameTypeDescription
databytesEcnoded data passed to the setRewardTokenConfig
tokenaddressThe address of the reward token

Return Values

NameTypeDescription
pathaddress[]The validated Uniswap V2 path

_decodeUniswapV3Path

function _decodeUniswapV3Path(bytes data, address token) internal view returns (bytes path)

Decodes the data passed into Uniswap V3 path and validates it to make sure the path is for token to baseToken

Parameters

NameTypeDescription
databytesEcnoded data passed to the setRewardTokenConfig
tokenaddressThe address of the reward token

Return Values

NameTypeDescription
pathbytesThe validated Uniswap V3 path

_decodeBalancerPoolId

function _decodeBalancerPoolId(bytes data, address balancerVault, address token) internal view returns (bytes32 poolId)

Decodes the data passed to Balancer Pool ID

Parameters

NameTypeDescription
databytesEcnoded data passed to the setRewardTokenConfig
balancerVaultaddress
tokenaddress

Return Values

NameTypeDescription
poolIdbytes32The pool ID

_decodeCurvePoolIndices

function _decodeCurvePoolIndices(bytes data, address poolAddress, address token) internal view returns (struct BaseHarvester.CurvePoolIndices indices)

Decodes the data passed to get the pool indices and checks it against the Curve Pool to make sure it's not misconfigured. The indices are packed into a single uint256 for gas savings

Parameters

NameTypeDescription
databytesEcnoded data passed to the setRewardTokenConfig
poolAddressaddressCurve pool address
tokenaddressThe address of the reward token

Return Values

NameTypeDescription
indicesstruct BaseHarvester.CurvePoolIndicesPacked pool asset indices

setSupportedStrategy

function setSupportedStrategy(address _strategyAddress, bool _isSupported) external

Flags a strategy as supported or not supported one

Parameters

NameTypeDescription
_strategyAddressaddressAddress of the strategy
_isSupportedboolBool marking strategy as supported or not supported

transferToken

function transferToken(address _asset, uint256 _amount) external

Transfer token to governor. Intended for recovering tokens stuck in contract, i.e. mistaken sends.

Parameters

NameTypeDescription
_assetaddressAddress for the asset
_amountuint256Amount of the asset to transfer

harvestAndSwap

function harvestAndSwap(address _strategyAddr) external

Collect reward tokens from a specific strategy and swap them for base token on the configured swap platform. Can be called by anyone. Rewards incentivizing the caller are sent to the caller of this function.

Parameters

NameTypeDescription
_strategyAddraddressAddress of the strategy to collect rewards from

harvestAndSwap

function harvestAndSwap(address _strategyAddr, address _rewardTo) external

Collect reward tokens from a specific strategy and swap them for base token on the configured swap platform. Can be called by anyone

Parameters

NameTypeDescription
_strategyAddraddressAddress of the strategy to collect rewards from
_rewardToaddressAddress where to send a share of harvest rewards to as an incentive for executing this function

_harvestAndSwap

function _harvestAndSwap(address _strategyAddr, address _rewardTo) internal

Collect reward tokens from a specific strategy and swap them for base token on the configured swap platform

Parameters

NameTypeDescription
_strategyAddraddressAddress of the strategy to collect rewards from
_rewardToaddressAddress where to send a share of harvest rewards to as an incentive for executing this function

_harvest

function _harvest(address _strategyAddr) internal

Collect reward tokens from a specific strategy and swap them for base token on the configured swap platform

Parameters

NameTypeDescription
_strategyAddraddressAddress of the strategy to collect rewards from.

_swap

function _swap(address _swapToken, address _rewardTo, contract IOracle _priceProvider) internal virtual

Swap a reward token for the base token on the configured swap platform. The token must have a registered price feed with the price provider

Parameters

NameTypeDescription
_swapTokenaddressAddress of the token to swap
_rewardToaddressAddress where to send the share of harvest rewards to
_priceProvidercontract IOracleOracle to get prices of the swap token

_doSwap

function _doSwap(enum BaseHarvester.SwapPlatform swapPlatform, address routerAddress, address rewardTokenAddress, uint256 amountIn, uint256 minAmountOut) internal returns (uint256 amountOut)

_swapWithUniswapV2

function _swapWithUniswapV2(address routerAddress, address swapToken, uint256 amountIn, uint256 minAmountOut) internal returns (uint256 amountOut)

Swaps the token to baseToken with Uniswap V2

Parameters

NameTypeDescription
routerAddressaddressUniswap V2 Router address
swapTokenaddressAddress of the tokenIn
amountInuint256Amount of swapToken to swap
minAmountOutuint256Minimum expected amount of baseToken

Return Values

NameTypeDescription
amountOutuint256Amount of baseToken received after the swap

_swapWithUniswapV3

function _swapWithUniswapV3(address routerAddress, address swapToken, uint256 amountIn, uint256 minAmountOut) internal returns (uint256 amountOut)

Swaps the token to baseToken with Uniswap V3

Parameters

NameTypeDescription
routerAddressaddressUniswap V3 Router address
swapTokenaddressAddress of the tokenIn
amountInuint256Amount of swapToken to swap
minAmountOutuint256Minimum expected amount of baseToken

Return Values

NameTypeDescription
amountOutuint256Amount of baseToken received after the swap

_swapWithBalancer

function _swapWithBalancer(address balancerVaultAddress, address swapToken, uint256 amountIn, uint256 minAmountOut) internal returns (uint256 amountOut)

Swaps the token to baseToken on Balancer

Parameters

NameTypeDescription
balancerVaultAddressaddressBalancerVaultAddress
swapTokenaddressAddress of the tokenIn
amountInuint256Amount of swapToken to swap
minAmountOutuint256Minimum expected amount of baseToken

Return Values

NameTypeDescription
amountOutuint256Amount of baseToken received after the swap

_swapWithCurve

function _swapWithCurve(address poolAddress, address swapToken, uint256 amountIn, uint256 minAmountOut) internal returns (uint256 amountOut)

Swaps the token to baseToken on Curve

Parameters

NameTypeDescription
poolAddressaddressCurve Pool Address
swapTokenaddressAddress of the tokenIn
amountInuint256Amount of swapToken to swap
minAmountOutuint256Minimum expected amount of baseToken

Return Values

NameTypeDescription
amountOutuint256Amount of baseToken received after the swap