Skip to main content

FEYGMXProductFactory

Git Source

Inherits: IFEYFactory, FEYFactoryConfigurator

Author: Struct Finance

Factory contract that is used to create Fixed and Enhanced Yield 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;

GMX_VAULT

GMX vault address

IGMXVault public constant GMX_VAULT = IGMXVault(0x9ab2De34A33fB459b538c43f251eB825645e8595);

productTokenId

TokenID => Product

mapping(uint256 => address) public productTokenId;

allProducts

List of addresses of all the FEYProducts created

address[] public allProducts;

yieldSource

GLP YieldSource contract

IGMXYieldSource public yieldSource;

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

isMintActive

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

Validate if the initial deposit value is >= the minimumInitialDeposit

If not, then the product creator should be whitelisted.

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

setYieldSource

Sets yield-source contract address for the GMX pool

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

Parameters

NameTypeDescription
_yieldSourceaddressAddress of the yield source contract

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

setTokenStatus

Restrict transfer when the product state is OPEN

Used to update a token status (active/inactive)

function setTokenStatus(address _token, uint256 _status) external override onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_tokenaddressThe token address
_statusuint256The status of the token

setPoolStatus

Used to update the status of pair

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

Parameters

NameTypeDescription
_token0addressThe first token address
_token1addressThe second token address
_statusuint256The status of the pair

_deployProduct

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.

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