Strategy Contract

Strategy Contracts are the core of FlowDex's yield generation, enabling autocompounding of rewards from various staking protocols. They handle three key steps: (1) staking deposited tokens, (2) harvesting rewards, and (3) reinvesting rewards to maximize yield.

Each Strategy Contract interacts with a Vault Contract to manage user deposits, ensuring risks are isolated from user funds.

Dependencies

  • StratFeeManager Contract: Manages fee distribution.

  • GasOptimizer Contract: Optimizes gas usage for transactions.

Interfaces

  • Router Interface: Facilitates token swaps (e.g., IUniswapRouterETH.sol).

  • Liquidity Pool Interface: Interacts with underlying liquidity pools (e.g., IUniswapV2Pair.sol).

  • Chef Interface: Manages staking farms and rewards (e.g., IMiniChefV2.sol).

View Functions

1. balanceOf()

Returns the total amount of the underlying token (e.g., ETH) stored in the strategy.

function balanceOf() public view returns (uint256) {
    return balanceOfWant() + balanceOfPool();
}

2. balanceOfWant()

Returns the amount of the underlying token held directly by the strategy.

3. balanceOfPool()

Returns the amount of the underlying token staked in the external protocol.

4. rewardsAvailable()

Returns the amount of pending rewards available for harvest.

Write Functions

1. deposit()

Deposits the underlying token into the external staking protocol.

2. withdraw(uint256 _amount)

Withdraws the underlying token from the external protocol and transfers it back to the Vault.

3. harvest()

Harvests rewards, charges fees, and reinvests the remaining rewards.

4. panic()

Withdraws all funds from the external protocol in case of emergencies.

Additional Functions

  • setHarvestOnDeposit(bool _harvestOnDeposit): Toggles harvesting on deposit.

  • beforeDeposit(): Ensures rewards are harvested before new deposits.

  • retireStrat(): Withdraws all funds and transfers them back to the Vault.

Security

  • ReentrancyGuard: Prevents reentrancy attacks.

  • Pausable: Allows pausing of critical functions during emergencies.

  • Fee Management: Ensures fair distribution of fees.

Last updated