Skip to main content

FEYAutoPoolProductFactory

Git Source

Inherits: FEYFactoryConfigurator, IFEYFactory

Author: Struct Finance

Factory contract that is used to create Fixed and Enhanced Yield AutoPool Products

State Variables

latestSpTokenId

Keeps track of the latest SP token ID

uint256 public latestSpTokenId;

spTokenAddress

Address of the StructSP Token

ISPToken public spTokenAddress;

wAVAX

Address of the Native token

IERC20Metadata public immutable wAVAX;

isProductActive

Active products

mapping(address => uint256) public isProductActive;

isPoolActive

Active pairs

mapping(address => mapping(address => uint256)) public isPoolActive;

autoPoolVaults

Vaults mapping for reverse loopup

mapping(address => mapping(address => address)) public autoPoolVaults;

productTokenId

TokenID => Product

mapping(uint256 => address) public productTokenId;

allProducts

List of addresses of all the FEYProducts created

address[] public allProducts;

yieldSources

AutoPoool vault => YieldSource

mapping(address => IAutoPoolYieldSource) public yieldSources;

Functions

constructor

Initializes the Factory based on the given parameter

constructor(
ISPToken _spTokenAddress,
address _feyProductImpl,
IGAC _globalAccessControl,
IStructPriceOracle _priceOracle,
IERC20Metadata _wAVAX,
IDistributionManager _distributionManager
);

Parameters

NameTypeDescription
_spTokenAddressISPTokenAddress of the Struct SP Token
_feyProductImpladdressAddress for FEYProduct implementation
_globalAccessControlIGACAddress of the StructGAC contract
_priceOracleIStructPriceOracleThe address of the struct price oracle
_wAVAXIERC20MetadatawAVAX address
_distributionManagerIDistributionManagerAddress of the distribution manager contract

totalProducts

Returns the total number of products created

function totalProducts() external view returns (uint256);

createProduct

Creates new FEY Products based on the given specifications

If the caller is not WHITELISTED, an initial deposit should be made.

The contract should not be in the PAUSED state

function createProduct(
DataTypes.TrancheConfig memory _configTrancheSr,
DataTypes.TrancheConfig memory _configTrancheJr,
DataTypes.ProductConfigUserInput memory _productConfigUserInput,
DataTypes.Tranche _tranche,
uint256 _initialDepositAmount
) external payable gacPausable;

Parameters

NameTypeDescription
_configTrancheSrDataTypes.TrancheConfigConfiguration of the senior tranche
_configTrancheJrDataTypes.TrancheConfigConfiguration of the junior tranche
_productConfigUserInputDataTypes.ProductConfigUserInputUser-set configuration of the Product
_trancheDataTypes.TrancheThe tranche into which the creater makes the initial deposit
_initialDepositAmountuint256The initial deposit amount

setPoolStatus

Used to update the status of pair

Validate if the initial deposit value is >= the minimumInitialDeposit

If not, then the product creator should be whitelisted.

function setPoolStatus(address _autoPoolVault, uint256 _status) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_autoPoolVaultaddressThe addresss of the autopool vault contract
_statusuint256The status of the pair

setYieldSource

Sets yield-source contract address for the AutoPool vault

function setYieldSource(address _autoPoolVault, address _yieldSource) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_autoPoolVaultaddressAddress of the AutoPool Vault contract
_yieldSourceaddressAddress of the yield source contract

isMintActive

Checks if spToken can still be minted for the given product.

SPTokens should be minted only for the products with OPEN state

function isMintActive(uint256 _spTokenId) external view returns (bool);

Parameters

NameTypeDescription
_spTokenIduint256The SPTokenId associated with the product (senior/junior tranche)

Returns

NameTypeDescription
<none>boolA flag indicating if SPTokens can be minted

isTransferEnabled

Checks if the SPToken with the given ID can be transferred.

function isTransferEnabled(uint256 _spTokenId, address _user) external view returns (bool);

Parameters

NameTypeDescription
_spTokenIduint256The SPToken Id
_useraddressAddress of the SPToken holder

Returns

NameTypeDescription
<none>boolA flag indicating if transfers are allowed or not

_deployProduct

Restrict transfer when the product state is OPEN

Deploys the FEY Product based on the given config

function _deployProduct(
DataTypes.TrancheConfig memory _configTrancheSr,
DataTypes.TrancheConfig memory _configTrancheJr,
DataTypes.ProductConfig memory _productConfig
) private returns (address);

Parameters

NameTypeDescription
_configTrancheSrDataTypes.TrancheConfig- The configuration for the Senior Tranche
_configTrancheJrDataTypes.TrancheConfig- The configuration for the Junior Tranche
_productConfigDataTypes.ProductConfig- The configuration for the new product

Returns

NameTypeDescription
<none>addressThe address of the new product

_makeInitialDeposit

Used to increase allowance and deposit on behalf of the product creator

function _makeInitialDeposit(
DataTypes.Tranche _tranche,
uint256 _amount,
IERC20Metadata _trancheToken,
IFEYProduct _productAddress
) private;

Parameters

NameTypeDescription
_trancheDataTypes.TrancheTranche id to make the initial deposit
_amountuint256Amount of tokens to be deposited
_trancheTokenIERC20MetadataTranche token address
_productAddressIFEYProductFEYProduct address that's recently deployed

_validateProductConfig

Validates the Product configuration

function _validateProductConfig(DataTypes.ProductConfig memory _productConfig) private view;

Parameters

NameTypeDescription
_productConfigDataTypes.ProductConfigProduct configuration

_validatePool

Validates if pool exists for the given set of tokens and the autopool vault is not paused.

function _validatePool(address _token0, address _token1) private view;

Parameters

NameTypeDescription
_token0addressAddress for token0
_token1addressAddress for token1

_getTrancheCapacityValues

Returns the tranche capacity values in USD.

function _getTrancheCapacityValues(address _trancheTokenSenior, address _trancheTokenJunior)
private
view
returns (uint256 _trancheCapacityValueSenior, uint256 _trancheCapacityValueJunior);

Parameters

NameTypeDescription
_trancheTokenSenioraddressSenior tranche token address
_trancheTokenJunioraddressJunior tranche token address

Returns

NameTypeDescription
_trancheCapacityValueSenioruint256Value of Senior tranche capacity in USD
_trancheCapacityValueJunioruint256Value of Junior tranche capacity in USD

_getInitialDepositValueUSD

Returns the initial deposit amount value in USD

function _getInitialDepositValueUSD(
DataTypes.Tranche _tranche,
uint256 _amount,
address _trancheTokenSenior,
address _trancheTokenJunior
) private view returns (uint256 _valueUSD, address _trancheToken);

Parameters

NameTypeDescription
_trancheDataTypes.TrancheTranche for initial deposit
_amountuint256The initial deposit amount
_trancheTokenSenioraddressSenior tranche token address
_trancheTokenJunioraddressJunior tranche token address

Returns

NameTypeDescription
_valueUSDuint256Value of initial deposit amount in USD
_trancheTokenaddressAddress of the tranche token