FEYAutoPoolProduct
Inherits: FEYProduct, TraderJoeLPAdapter
Author: Struct Finance
State Variables
yieldSource
The address of the AutoPoolYieldSource contract
IAutoPoolYieldSource public yieldSource;
seniorTokenToJuniorTokenSwapPath
Swap paths
address[] public seniorTokenToJuniorTokenSwapPath;
juniorTokenToSeniorTokenSwapPath
address[] public juniorTokenToSeniorTokenSwapPath;
seniorTokenToNativeSwapPath
address[] public seniorTokenToNativeSwapPath;
juniorTokenToNativeSwapPath
address[] public juniorTokenToNativeSwapPath;
isQueuedForWithdrawal
Flag to indicate if the product is queued for redemption
uint256 public isQueuedForWithdrawal = 2;
Functions
initialize
Initializes the Product based on the given parameters
It should be called only once
function initialize(
DataTypes.InitConfigParam calldata _initConfig,
IStructPriceOracle _structPriceOracle,
ISPToken _spToken,
IGAC _globalAccessControl,
IDistributionManager _distributionManager,
address _yieldSource,
address payable _nativeToken
) external override;
Parameters
Name | Type | Description |
---|---|---|
_initConfig | DataTypes.InitConfigParam | Configuration of the tranches and product config |
_structPriceOracle | IStructPriceOracle | The address of the struct price oracle |
_spToken | ISPToken | Address of the Struct SP Token |
_globalAccessControl | IGAC | Address of the StructGAC contract |
_distributionManager | IDistributionManager | Address of the distribution manager contract |
_yieldSource | address | Address of the YieldSource contract |
_nativeToken | address payable |
invest
Method used to invest funds into Autopool to accrue yield
This method calls the supplyToken()
method on {AutoPoolYieldSource} contract
function invest() external override nonReentrant gacPausable;
_checkAndUpdateRemoveFundsState
function _checkAndUpdateRemoveFundsState() private;
removeFundsFromLP
Method used to queue for redemption from the AutoPool
function removeFundsFromLP() external override nonReentrant gacPausable;
processRedemption
Process the redeemed tokens from the AutoPool
function processRedemption(uint256 _receivedAmountTokenA, uint256 _receivedAmountTokenB)
external
nonReentrant
gacPausable;
Parameters
Name | Type | Description |
---|---|---|
_receivedAmountTokenA | uint256 | Amount of TokenA received from the AutoPool |
_receivedAmountTokenB | uint256 | Amount of TokenB recieved from the AutoPool |
setSlippage
Capture tokens at maturity
Used to update the slippage
function setSlippage(uint256 _newSlippage) external onlyRole(GOVERNANCE);
Parameters
Name | Type | Description |
---|---|---|
_newSlippage | uint256 | The new slippage value to be updated |
setSwapPath
Used to update the swap path
function setSwapPath(DataTypes.SwapPathType _swapPath, address[] memory _newPath) external onlyRole(GOVERNANCE);
Parameters
Name | Type | Description |
---|---|---|
_swapPath | DataTypes.SwapPathType | The swap path to be updated |
_newPath | address[] | The new swap path |
getTokenRate
Returns the rate of the tranche token
function getTokenRate(DataTypes.Tranche _tranche, uint256 _amountOut)
public
view
returns (bool, uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | The tranche id for which the token rate should be fetched. |
_amountOut | uint256 |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool - Indicates if the price is valid (within max deviation) |
<none> | uint256 | uint256 - AMM rate of the given tranche token against the other tranche token |
<none> | uint256 | uint256 - Price of the given tranche token (Chainlink price) |
<none> | uint256 | uint256 - Price of the other tranche token (Chainlink price) |
_depositToLP
Adds liquidity to the AMM pool
function _depositToLP(uint256 _tokensInvestableSr, uint256 _tokensInvestableJr)
private
returns (uint256 _seniorTokensSupplied, uint256 _juniorTokensSupplied);
Parameters
Name | Type | Description |
---|---|---|
_tokensInvestableSr | uint256 | Senior tokens eligible for investment to the pool |
_tokensInvestableJr | uint256 | Junior tokens eligible for investment to the pool |
Returns
Name | Type | Description |
---|---|---|
_seniorTokensSupplied | uint256 | Senior tranche tokens invested |
_juniorTokensSupplied | uint256 | Junior tranche tokens invested |
_chargeFee
Increase allowance
Used to transfer fee when the product is matured
function _chargeFee(uint256 _receivedSr, uint256 _receivedJr) private;
Parameters
Name | Type | Description |
---|---|---|
_receivedSr | uint256 | Senior tokens received from pool |
_receivedJr | uint256 | Junior tokens received from pool |
_allocateToTranches
Get nativeToken balance of receiver before sending it fees Get nativeToken balance of receiver after sending it fees Set the difference as the _feeToQueue
Reallocate the matured tokens to the tranches
function _allocateToTranches(uint256 _receivedSr, uint256 _receivedJr, uint256 _srFrFactor) private;
Parameters
Name | Type | Description |
---|---|---|
_receivedSr | uint256 | Amount of senior tokens received from the liquidity pool |
_receivedJr | uint256 | Amount of junior tokens received from the liquidity pool |
_srFrFactor | uint256 | Amount of senior tokens the senior tranche investors expect at maturity |
getSrFrFactor
Calculate the amount of senior tokens owed to the senior tranche for the given tranche duration
function getSrFrFactor(bool _isProrated) public view returns (uint256 _srFrFactor);
Parameters
Name | Type | Description |
---|---|---|
_isProrated | bool | Whether the the term duration is prorated |
Returns
Name | Type | Description |
---|---|---|
_srFrFactor | uint256 | The amount of senior tokens owed to the senior tranche for the given tranche duration |
Events
SwapPathUpdated
Emitted when the swap path is updated
event SwapPathUpdated(DataTypes.SwapPathType _swapPath, address[] _path);