Skip to main content

GMXYieldSource

Git Source

Inherits: IGMXYieldSource, GACManaged, CustomReentrancyGuard

Yield source for the FEYGMXProduct that generates yield via GMX protocol

This contract inherits GACManaged which extends Pausable also uses the GAC for access control

State Variables

GLP_REWARD_ROUTERV2

IGMXRewardRouterV2 public constant GLP_REWARD_ROUTERV2 = IGMXRewardRouterV2(0xB70B91CE0771d3f4c81D87660f71Da31d48eB3B3);

GLP_MANAGER

IGLPManager public constant GLP_MANAGER = IGLPManager(0xD152c7F25db7F4B95b7658323c5F33d176818EE4);

GMX_REWARD_ROUTER

This is used for Harvesting rewards

IGMXRewardRouterV2 public constant GMX_REWARD_ROUTER = IGMXRewardRouterV2(0x82147C5A7E850eA4E28155DF107F2590fD4ba327);

VAULT

IGMXVault public constant VAULT = IGMXVault(0x9ab2De34A33fB459b538c43f251eB825645e8595);

FSGLP

IERC20Metadata public constant FSGLP = IERC20Metadata(0x9e295B5B976a184B14aD8cd72413aD846C299660);

BPS_MAX

uint256 public constant BPS_MAX = 10000;

productInfo

Used to map the product address with the related info

mapping(address => DataTypes.FEYGMXProductInfo) public productInfo;

feyFactory

Address of the FEYGMXFactory

address public immutable feyFactory;

WAVAX

IERC20Metadata public constant WAVAX = IERC20Metadata(0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7);

INITIAL_SHARES

This will be the shares allocated to the first product

Required to prevent share manipulation.

uint256 public constant INITIAL_SHARES = 10 ** 8;

slippage

The maximum amount of slippage allowed when buying/selling GLP tokens

uint256 public slippage = 30;

totalShares

the total shares owned by all products that use this contract

uint256 public totalShares;

fsGlpTokensTotal

the aggregated sum of fsGLP tokens in this contract

we track it manually to avoid inflation attacks.

uint256 public fsGlpTokensTotal;

Functions

constructor

constructor(address _feyFactory, IGAC _globalAccessControl);

Parameters

NameTypeDescription
_feyFactoryaddressAddress of the FEYFactory contract
_globalAccessControlIGACAddress of the GlobalAccessControl contract

supplyTokens

Supplies liquidity to the GLP index (Buying GLP)

Only PRODUCT contracts can call this method

function supplyTokens(uint256 _amountAIn, uint256 _amountBIn)
external
override
gacPausable
nonReentrant
onlyRole(PRODUCT)
returns (uint256 _amountAInWei, uint256 _amountBInWei);

Parameters

NameTypeDescription
_amountAInuint256
_amountBInuint256

Returns

NameTypeDescription
_amountAInWeiuint256The amount of token A actually supplied to GLP
_amountBInWeiuint256The amount of token B actually supplied to GLP

redeemTokens

Record the product's share of the LP Token Update total shares Update fsGLPTotal

Only PRODUCT contracts can call this method

function redeemTokens(uint256 _expectedSrAmount)
external
override
gacPausable
nonReentrant
onlyRole(PRODUCT)
returns (uint256 _amountARedeemed, uint256 _amountBRedeemed);

Parameters

NameTypeDescription
_expectedSrAmountuint256

Returns

NameTypeDescription
_amountARedeemeduint256The amount of token A received from the GLP
_amountBRedeemeduint256

recompoundRewards

Junior tranche (TokenB) should absorb the withdrawal fee

function recompoundRewards() public override gacPausable onlyRole(KEEPER);

addRewards

Used by the Governance to incentivize products by distributing WAVAX as rewards

Any wAVAX that is in the balance of the contract before this function is called, will be converted into GLP tokens and assigned as new shares to the product that we would like to incentivize or subsidize

function addRewards(address[] memory _products, uint256 _amount) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_productsaddress[]Array of product addresses that we wanna distrubute rewards to
_amountuint256The amount of wAVAX to be distributed.

_supplyLiquidity

Update product shares Update total shares

Returns the amounts in the token decimals to be passed to the addLiquidity()

function _supplyLiquidity(uint256 _amountA, uint256 _amountB, DataTypes.FEYGMXProductInfo storage _productInfo)
internal
returns (uint256 _amountAInWei, uint256 _amountBInWei);

Parameters

NameTypeDescription
_amountAuint256The amount to be supplied for tokenA in 18 decimals
_amountBuint256The amount to be supplied for tokenB in 18 decimals
_productInfoDataTypes.FEYGMXProductInfoThe product info

_recompoundRewards

Pull the tokens from the product contract Increase allowance for the GLP_MANAGER contract Buy GLP with TokenA Buy GLP with TokenB

function _recompoundRewards() internal;

_tokenToShares

Harvest only wAVAX rewards as there'll be neither esGMX nor GMX rewards.

Calculates the number of shares that should be mint or burned when a product deposit or withdraw

function _tokenToShares(uint256 _tokens, uint256 _fsGlpTotal) internal view returns (uint256 _shares);

Parameters

NameTypeDescription
_tokensuint256Amount of tokens
_fsGlpTotaluint256Total fsGLP tokens in this contract

Returns

NameTypeDescription
_sharesuint256Number of shares

_sharesToTokens

Calculates the number of tokens that should be mint or burned when a product deposit or withdraw

function _sharesToTokens(uint256 _shares, uint256 _fsGlpTotal) internal view returns (uint256 _tokens);

Parameters

NameTypeDescription
_sharesuint256Amount of shares for given no.of tokens
_fsGlpTotaluint256Total fsGLP tokens in the yield source

Returns

NameTypeDescription
_tokensuint256Number of tokens

_fsGlpTokenBalance

Returns the total balance of fsGLP tokens of this contract

function _fsGlpTokenBalance() internal view returns (uint256);

_getGLPPrice

Returns the GLP buy price

function _getGLPPrice(bool _maximize) public view returns (uint256 price);

_calculateGLPAmountOutForToken

Returns the minOut value for buying GLP with the given token

function _calculateGLPAmountOutForToken(uint256 _amount, uint256 _tokenPriceUSD, bool _maximize)
internal
view
returns (uint256 amountOut);

Parameters

NameTypeDescription
_amountuint256The token amount used to purchase the GLP tokens
_tokenPriceUSDuint256The price of the token in USD
_maximizeboolFlag indicating buy or sell action

Returns

NameTypeDescription
amountOutuint256The expected fsGLP to be recieved

_calculateTokenAmountOutForFsGLP

Returns the minOut value for selling GLP for the given token

function _calculateTokenAmountOutForFsGLP(uint256 _amountfsGlp, address _token, uint256 _tokenDecimals)
internal
view
returns (uint256 amountOut);

Parameters

NameTypeDescription
_amountfsGlpuint256The amount of fsGlp tokens to be redeemed
_tokenaddressThe address of the token
_tokenDecimalsuint256

Returns

NameTypeDescription
amountOutuint256The expected tokens to be recieved

_getFeeBps

Returns the feeBps to buy/sell GLP tokens

function _getFeeBps(uint256 _amountfsGLP, bool _maximize, address _token) internal view returns (uint256 feeBps);

Parameters

NameTypeDescription
_amountfsGLPuint256The amount of fsGLP tokens to be sold
_maximizeboolA flag indicating if we are gonna buy or sell
_tokenaddressAddress of the token to be bought with or sold for

Returns

NameTypeDescription
feeBpsuint256The buy/sell fee in basis points

getFEYGMXProductInfo

function getFEYGMXProductInfo(address _productAddress) public view returns (DataTypes.FEYGMXProductInfo memory);

setFEYGMXProductInfo

function setFEYGMXProductInfo(address _productAddress, DataTypes.FEYGMXProductInfo memory _productInfo)
external
onlyRole(FACTORY);