GMXYieldSource
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
Name | Type | Description |
---|---|---|
_feyFactory | address | Address of the FEYFactory contract |
_globalAccessControl | IGAC | Address 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
Name | Type | Description |
---|---|---|
_amountAIn | uint256 | |
_amountBIn | uint256 |
Returns
Name | Type | Description |
---|---|---|
_amountAInWei | uint256 | The amount of token A actually supplied to GLP |
_amountBInWei | uint256 | The 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
Name | Type | Description |
---|---|---|
_expectedSrAmount | uint256 |
Returns
Name | Type | Description |
---|---|---|
_amountARedeemed | uint256 | The amount of token A received from the GLP |
_amountBRedeemed | uint256 |
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
Name | Type | Description |
---|---|---|
_products | address[] | Array of product addresses that we wanna distrubute rewards to |
_amount | uint256 | The 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
Name | Type | Description |
---|---|---|
_amountA | uint256 | The amount to be supplied for tokenA in 18 decimals |
_amountB | uint256 | The amount to be supplied for tokenB in 18 decimals |
_productInfo | DataTypes.FEYGMXProductInfo | The 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
Name | Type | Description |
---|---|---|
_tokens | uint256 | Amount of tokens |
_fsGlpTotal | uint256 | Total fsGLP tokens in this contract |
Returns
Name | Type | Description |
---|---|---|
_shares | uint256 | Number 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
Name | Type | Description |
---|---|---|
_shares | uint256 | Amount of shares for given no.of tokens |
_fsGlpTotal | uint256 | Total fsGLP tokens in the yield source |
Returns
Name | Type | Description |
---|---|---|
_tokens | uint256 | Number 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
Name | Type | Description |
---|---|---|
_amount | uint256 | The token amount used to purchase the GLP tokens |
_tokenPriceUSD | uint256 | The price of the token in USD |
_maximize | bool | Flag indicating buy or sell action |
Returns
Name | Type | Description |
---|---|---|
amountOut | uint256 | The 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
Name | Type | Description |
---|---|---|
_amountfsGlp | uint256 | The amount of fsGlp tokens to be redeemed |
_token | address | The address of the token |
_tokenDecimals | uint256 |
Returns
Name | Type | Description |
---|---|---|
amountOut | uint256 | The 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
Name | Type | Description |
---|---|---|
_amountfsGLP | uint256 | The amount of fsGLP tokens to be sold |
_maximize | bool | A flag indicating if we are gonna buy or sell |
_token | address | Address of the token to be bought with or sold for |
Returns
Name | Type | Description |
---|---|---|
feeBps | uint256 | The 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);