Skip to main content

SkyCompounderStrategy

Git Source

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:

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

NameTypeDescription
_stakingaddressSky Protocol staking contract address
_namestringStrategy share token name
_symbolstringStrategy share token symbol
_managementaddressManagement address (can update params)
_keeperaddressKeeper address (calls report)
_emergencyAdminaddressEmergency admin address
_donationAddressaddressDragon router address (receives profit shares)
_enableBurningboolTrue to enable dragon loss protection
_tokenizedStrategyAddressaddressTokenizedStrategy 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

NameTypeDescription
_claimRewardsboolTrue 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

NameTypeDescription
_useUniV3boolTrue to use UniswapV3, false for UniswapV2
_rewardToBaseuint24Uniswap V3 fee for reward→base pool (ppm)
_baseToAssetuint24Uniswap V3 fee for base→asset pool (ppm)

setMinAmountToSell

Set minimum rewardsToken amount to sell (skip small swaps)

function setMinAmountToSell(uint256 _minAmountToSell) external onlyManagement;

Parameters

NameTypeDescription
_minAmountToSelluint256Minimum 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

NameTypeDescription
_baseaddressAddress of USDS, DAI, USDC, or WETH
_useUniV3boolTrue to use UniswapV3, false for UniswapV2
_rewardToBaseuint24Fee for reward→base pool (ppm, only if _useUniV3)
_baseToAssetuint24Fee for base→asset pool (ppm, only if _useUniV3)

setReferral

Set referral code for staking

function setReferral(uint16 _referral) external onlyManagement;

Parameters

NameTypeDescription
_referraluint16Referral 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

NameTypeDescription
_minAmountOutuint256Minimum 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

NameTypeDescription
<none>uint256Available deposit limit in asset base units

balanceOfAsset

Returns strategy's idle asset balance

function balanceOfAsset() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256Asset balance in asset base units

balanceOfStake

Returns strategy's staked balance (staking receipt tokens)

function balanceOfStake() public view returns (uint256 _amount);

Returns

NameTypeDescription
_amountuint256Staked balance in staking token base units

balanceOfRewards

Returns strategy's unclaimed rewards token balance

function balanceOfRewards() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256Rewards balance in rewards token base units

claimableRewards

Returns strategy's earned but unclaimed rewards from staking

function claimableRewards() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256Claimable 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

NameTypeDescription
_amountuint256Amount to stake in asset base units

_freeFunds

Withdraws staked assets from Sky staking

function _freeFunds(uint256 _amount) internal override;

Parameters

NameTypeDescription
_amountuint256Amount 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

NameTypeDescription
_totalAssetsuint256Total 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

NameTypeDescription
_fromaddressToken to swap from
_toaddressToken to swap to
_amountInuint256Amount to swap in _from token base units
_minAmountOutuint256Minimum 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

NameTypeDescription
_amountuint256Amount 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

NameTypeDescription
_tokenInaddressToken to swap from
_tokenOutaddressToken to swap to

Returns

NameTypeDescription
_pathaddress[]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

NameTypeDescription
auint256First value
buint256Second value

Returns

NameTypeDescription
<none>uint256Minimum value