Skip to content

AngleProtocol/angle-integration-strategies

Repository files navigation

Angle Integration Strategies

Introduction

This repository contains strategies for integrators to use to let their users deposit into the Angle Protocol while taking a performance fee on the accrued yield. The strategies can be any DeFi product that has a yield, such as staking, lending, farming, etc.

BaseStrategy

It is an abstract contract that inherits the ERC4626 interface and that is meant to be a proxy of an underlying strategy contract. This means that instead of depositing in the underlying strategy, users will deposit in the proxy and gain the same yield as if they had deposited in the underlying strategy. The proxy will then deposit the funds in the underlying strategy.

Extra features in this contract includes the ability to take a performance fee on the yield generated by the underlying strategy (split with developperFee which takes a portion of the performance fee), the ability to swap tokens and vest linearly external rewards for a period of time.

It has hooks that needs to be implemented to create a strategy:

  • _beforeWithdraw is called before the user withdraws their funds. It can be used to withdraw from the strategy if needed.
  • _afterDeposit is called after the user deposits their funds. It can be used to deposit in the strategy if needed.
  • _assetsHeld is called to get the amount of assets held by the strategy.

And ERC4626 view functions that needs to be implemented:

  • maxDeposit is called to get the maximum amount of tokens that can be deposited in the strategy.
  • maxWithdraw is called to get the maximum amount of tokens that can be withdrawn from the strategy.
  • maxMint is called to get the maximum amount of tokens that can be minted by the strategy.
  • maxRedeem is called to get the maximum amount of tokens that can be redeemed by the strategy.

A keeper needs to be created to accrue fees if there hasn't been any deposit or withdrawal for a certain period of time. The keeper needs to also harvest external rewards and swap tokens if needed.

ERC4626Strategy

It is an contract that inherits the BaseStrategy contract and implements the hooks needed to create a strategy for an underlying 4626 strategy.

One of the limitation of the contract is that the underlying strategy needs to have infinite minting such as stUSD or metamorpho.

Role Recaps

There are three roles in the contract:

  • KEEPER_ROLE: The role that can swap tokens and vest rewards.
  • DEVELOPER_ROLE: The role that can set developer fees, developer fee recipient, vesting period and swap parameters (swap router and transfer token address).
  • INTEGRATOR_ROLE: The role that can set integrator fees, integrator fee recipient.

The Integrator role is its own admin meaning that the initial integrator can add a new integrator and remove themselves from the role. The Developer role is its own admin meaning that the initial developer can add a new developer and remove themselves from the role. The Keeper role has developer role as admin meaning that the initial developer can add a new keeper and remove initialKeeper from the role. (It is designed as such because the developer is the one that should be operating the keeper).

Payloads Scripts

These scripts automate the process of depositing and withdrawing tokens into/from the strategy using the Angle API.

Installation

Make the scripts executable:

chmod +x utils/Deposit.sh utils/Withdraw.sh

Make sure to add in your .env file ARBITRUM_ETHERSCAN_API_KEY and ETH_NODE_URI_ARBITRUM.

Usage

Run the scripts with the desired parameters:

./utils/Deposit.sh [OPTIONS]
./utils/Withdraw.sh [OPTIONS]

Options

Option Description Default
-e Api Env (local, dev) http://localhost:5001 (local)
-c Chain ID 42161 (Arbitrum)
-i Token amount to deposit/withdraw 100000000
-s Strategy address 0xC0077E921C30c39cDD8b693E25Af572C10E82a05
-r Router address 0x9A33e690AA78A4c346e72f7A5e16e5d7278BE835 (Arbitrum)
-l Slippage 0.1
-u User address -
-t Token to swap (usdc, usdt) or to directly deposit (usda) -

Examples

Deposit

./utils/Deposit.sh -c 42161 -i 100000000 -s 0xC0077E921C30c39cDD8b693E25Af572C10E82a05 -r 0x9A33e690AA78A4c346e72f7A5e16e5d7278BE835 -l 0.1 -u 0x25681Ab599B4E2CEea31F8B498052c53FC2D74db -t usdc -e dev

Withdraw

./utils/Withdraw.sh -c 42161 -i 10000000000 -s 0xC0077E921C30c39cDD8b693E25Af572C10E82a05 -r 0x9A33e690AA78A4c346e72f7A5e16e5d7278BE835 -l 0.1 -u 0x25681Ab599B4E2CEea31F8B498052c53FC2D74db -t usdc -e dev

Notes

  • Ensure you have the correct user address for the token you're depositing or withdrawing.
  • The scripts require an active local node running if used in local. You can use anvil --auto-impersonate --fork-url $FORK_URL in order to simulate transactions on a forked network.
  • If you want to broadcast transactions on Arbitrum mainnet, you can get rid of --unlocked options in forge scripts and use -i 1 for example to input sender private key.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published