SkyCompounderStrategy
Inherits: BaseHealthCheck, UniswapV3Swapper, ISkyCompounder
Title: Sky Compounder Strategy
Author: mil0x; modified by Golem Foundation
Yearn v3 Strategy that autocompounds staking rewards and donates per BaseHealthCheck rules
Integrates with Sky staking; supports UniswapV2/V3 for reward swaps, referral code, and MEV protection
Notes:
-
security-contact: [email protected]
Constants
staking
Sky Protocol staking contract address
address public immutable staking
rewardsToken
Rewards token address distributed by staking contract
address public immutable rewardsToken
UNIV2ROUTER
address private constant UNIV2ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
USDS
address private constant USDS = 0xdC035D45d973E3EC169d2276DDab16f1e407384F
DAI
address private constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F
USDC
address private constant USDC = USDC_MAINNET
WETH
address private constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
ASSET_DUST
Minimum asset balance threshold to skip dust amounts (100 base units)
uint256 private constant ASSET_DUST = 100
State Variables
claimRewards
Whether rewards should be claimed during harvest
bool public claimRewards = true
useUniV3
Use UniswapV3 (true) or UniswapV2 (false) to sell rewards
bool public useUniV3
referral
Yearn referral code used by staking protocol
uint16 public referral = 13425
minAmountOut
Minimum amount out for swaps (absolute units) for MEV protection
uint256 public minAmountOut
Functions
constructor
Constructs the Sky Compounder Strategy
Validates staking contract is not paused and uses USDS as staking token
constructor(
address _staking,
string memory _name,
string memory _symbol,
address _management,
address _keeper,
address _emergencyAdmin,
address _donationAddress,
bool _enableBurning,
address _tokenizedStrategyAddress
)
BaseHealthCheck(
USDS,
_name,
_symbol,
_management,
_keeper,
_emergencyAdmin,
_donationAddress,
_enableBurning,
_tokenizedStrategyAddress
);
Parameters
| Name | Type | Description |
|---|---|---|
_staking | address | Sky Protocol staking contract address |
_name | string | Strategy share token name |
_symbol | string | Strategy share token symbol |
_management | address | Management address (can update params) |
_keeper | address | Keeper address (calls report) |
_emergencyAdmin | address | Emergency admin address |
_donationAddress | address | Dragon router address (receives profit shares) |
_enableBurning | bool | True to enable dragon loss protection |
_tokenizedStrategyAddress | address | TokenizedStrategy implementation address |
setClaimRewards
Enable/disable reward claiming during harvest
Can be disabled if rewards are paused or issues are detected upstream
function setClaimRewards(bool _claimRewards) external onlyManagement;
Parameters
| Name | Type | Description |
|---|---|---|
_claimRewards | bool | True to claim rewards on harvest, false to skip |
setUseUniV3andFees
Configure UniswapV3 usage and pool fees for reward swaps
function setUseUniV3andFees(bool _useUniV3, uint24 _rewardToBase, uint24 _baseToAsset) external onlyManagement;
Parameters
| Name | Type | Description |
|---|---|---|
_useUniV3 | bool | True to use UniswapV3, false for UniswapV2 |
_rewardToBase | uint24 | Uniswap V3 fee for reward→base pool (ppm) |
_baseToAsset | uint24 | Uniswap V3 fee for base→asset pool (ppm) |
setMinAmountToSell
Set minimum rewardsToken amount to sell (skip small swaps)
function setMinAmountToSell(uint256 _minAmountToSell) external onlyManagement;
Parameters
| Name | Type | Description |
|---|---|---|
_minAmountToSell | uint256 | Minimum amount to sell in asset base units |
setBase
Set base token and optionally UniswapV3 usage/fees
When enabling UniswapV3, fee params must be set to avoid failed swaps during harvest
function setBase(address _base, bool _useUniV3, uint24 _rewardToBase, uint24 _baseToAsset) external onlyManagement;
Parameters
| Name | Type | Description |
|---|---|---|
_base | address | Address of USDS, DAI, USDC, or WETH |
_useUniV3 | bool | True to use UniswapV3, false for UniswapV2 |
_rewardToBase | uint24 | Fee for reward→base pool (ppm, only if _useUniV3) |
_baseToAsset | uint24 | Fee for base→asset pool (ppm, only if _useUniV3) |
setReferral
Set referral code for staking
function setReferral(uint16 _referral) external onlyManagement;
Parameters
| Name | Type | Description |
|---|---|---|
_referral | uint16 | Referral code (uint16) |
setMinAmountOut
Set minimum amount out for swaps (slippage/MEV protection)
Use private RPC and set conservative thresholds to mitigate sandwich attacks
function setMinAmountOut(uint256 _minAmountOut) external onlyManagement;
Parameters
| Name | Type | Description |
|---|---|---|
_minAmountOut | uint256 | Minimum output amount in asset base units |
availableDepositLimit
Returns available deposit limit for owner
Returns 0 if staking is paused, otherwise unlimited (type(uint256).max)
function availableDepositLimit(
address /*_owner*/
)
public
view
override
returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Available deposit limit in asset base units |
balanceOfAsset
Returns strategy's idle asset balance
function balanceOfAsset() public view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Asset balance in asset base units |
balanceOfStake
Returns strategy's staked balance (staking receipt tokens)
function balanceOfStake() public view returns (uint256 _amount);
Returns
| Name | Type | Description |
|---|---|---|
_amount | uint256 | Staked balance in staking token base units |
balanceOfRewards
Returns strategy's unclaimed rewards token balance
function balanceOfRewards() public view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Rewards balance in rewards token base units |
claimableRewards
Returns strategy's earned but unclaimed rewards from staking
function claimableRewards() public view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Claimable rewards in rewards token base units |
_deployFunds
Deploys idle assets into Sky staking
Checks allowance and stakes with referral code
function _deployFunds(uint256 _amount) internal override;
Parameters
| Name | Type | Description |
|---|---|---|
_amount | uint256 | Amount to stake in asset base units |
_freeFunds
Withdraws staked assets from Sky staking
function _freeFunds(uint256 _amount) internal override;
Parameters
| Name | Type | Description |
|---|---|---|
_amount | uint256 | Amount to withdraw in asset base units |
_harvestAndReport
Harvests rewards, swaps to asset, and reports total assets
Claims rewards if enabled, swaps via UniV2/V3, redeploys idle funds
function _harvestAndReport() internal override returns (uint256 _totalAssets);
Returns
| Name | Type | Description |
|---|---|---|
_totalAssets | uint256 | Total strategy assets (idle + staked) in asset base units |
_uniV2swapFrom
Executes UniswapV2 swap from one token to another
Only swaps if _amountIn >= minAmountToSell
function _uniV2swapFrom(address _from, address _to, uint256 _amountIn, uint256 _minAmountOut) internal;
Parameters
| Name | Type | Description |
|---|---|---|
_from | address | Token to swap from |
_to | address | Token to swap to |
_amountIn | uint256 | Amount to swap in _from token base units |
_minAmountOut | uint256 | Minimum output amount for slippage protection in _to token base units |
_emergencyWithdraw
Emergency withdrawal from staking (called during shutdown)
Withdraws min of requested amount or staked balance
function _emergencyWithdraw(uint256 _amount) internal override;
Parameters
| Name | Type | Description |
|---|---|---|
_amount | uint256 | Amount to attempt to withdraw in asset base units |
_getTokenOutPath
Constructs UniswapV2 swap path (direct or via base token)
Returns 2-hop path if _tokenIn or _tokenOut is base, otherwise 3-hop via base
function _getTokenOutPath(address _tokenIn, address _tokenOut)
internal
view
virtual
returns (address[] memory _path);
Parameters
| Name | Type | Description |
|---|---|---|
_tokenIn | address | Token to swap from |
_tokenOut | address | Token to swap to |
Returns
| Name | Type | Description |
|---|---|---|
_path | address[] | Array of token addresses for swap route |
_min
Returns minimum of two uint256 values
function _min(uint256 a, uint256 b) internal pure returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
a | uint256 | First value |
b | uint256 | Second value |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Minimum value |