Skip to main content

FEYAutoPoolProduct

Git Source

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

NameTypeDescription
_initConfigDataTypes.InitConfigParamConfiguration of the tranches and product config
_structPriceOracleIStructPriceOracleThe address of the struct price oracle
_spTokenISPTokenAddress of the Struct SP Token
_globalAccessControlIGACAddress of the StructGAC contract
_distributionManagerIDistributionManagerAddress of the distribution manager contract
_yieldSourceaddressAddress of the YieldSource contract
_nativeTokenaddress 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

NameTypeDescription
_receivedAmountTokenAuint256Amount of TokenA received from the AutoPool
_receivedAmountTokenBuint256Amount of TokenB recieved from the AutoPool

setSlippage

Capture tokens at maturity

Used to update the slippage

function setSlippage(uint256 _newSlippage) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_newSlippageuint256The 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

NameTypeDescription
_swapPathDataTypes.SwapPathTypeThe swap path to be updated
_newPathaddress[]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

NameTypeDescription
_trancheDataTypes.TrancheThe tranche id for which the token rate should be fetched.
_amountOutuint256

Returns

NameTypeDescription
<none>boolbool - Indicates if the price is valid (within max deviation)
<none>uint256uint256 - AMM rate of the given tranche token against the other tranche token
<none>uint256uint256 - Price of the given tranche token (Chainlink price)
<none>uint256uint256 - 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

NameTypeDescription
_tokensInvestableSruint256Senior tokens eligible for investment to the pool
_tokensInvestableJruint256Junior tokens eligible for investment to the pool

Returns

NameTypeDescription
_seniorTokensSupplieduint256Senior tranche tokens invested
_juniorTokensSupplieduint256Junior tranche tokens invested

_chargeFee

Increase allowance

Used to transfer fee when the product is matured

function _chargeFee(uint256 _receivedSr, uint256 _receivedJr) private;

Parameters

NameTypeDescription
_receivedSruint256Senior tokens received from pool
_receivedJruint256Junior 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

NameTypeDescription
_receivedSruint256Amount of senior tokens received from the liquidity pool
_receivedJruint256Amount of junior tokens received from the liquidity pool
_srFrFactoruint256Amount 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

NameTypeDescription
_isProratedboolWhether the the term duration is prorated

Returns

NameTypeDescription
_srFrFactoruint256The 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);