Skip to main content

FEYProduct

Git Source

Inherits: IFEYProduct, CustomReentrancyGuard, GACManaged

Author: Struct Finance

Main point of interaction with the FEY product contracts.

Users can:

  • Deposit
  • Withdraw
  • Claim Excess

This is a base contract to be inherited by Autopool and GMX product contracts.

State Variables

currentState

Helps to identify the current state of the product

DataTypes.State internal currentState;

productConfig

Configuration for the current product

DataTypes.ProductConfig internal productConfig;

nativeToken

Address of the Native token

address payable public nativeToken;

productFactory

Address of the Product Factory contract

address public productFactory;

isInitialized

Initializer flag

bool internal isInitialized;

feeTotalSr

Total Fee Senior

uint256 public feeTotalSr;

feeTotalJr

Total Fee Junior

uint256 public feeTotalJr;

distributionManager

DistributionManager Interface

IDistributionManager public distributionManager;

structPriceOracle

StructPriceOracle Interface

IStructPriceOracle public structPriceOracle;

spToken

The address of the Struct SP Token

ISPToken public spToken;

investors

Tranche id => user address => deposits

mapping(DataTypes.Tranche => mapping(address => DataTypes.Investor)) internal investors;

trancheInfo

Contains the info specific to senior and junior tranches

mapping(DataTypes.Tranche => DataTypes.TrancheInfo) internal trancheInfo;

trancheConfig

Contains the specifications of senior and junior tranches

mapping(DataTypes.Tranche => DataTypes.TrancheConfig) internal trancheConfig;

_srDecimals

uint256 internal _srDecimals;

_jrDecimals

uint256 internal _jrDecimals;

Functions

deposit

Allows users to deposit their funds into the tranche.

Assets will be held by the contract until the predetermined investment start time.

function deposit(DataTypes.Tranche _tranche, uint256 _amount) external payable override nonReentrant gacPausable;

Parameters

NameTypeDescription
_trancheDataTypes.TrancheThe tranche into which the assets should be deposited
_amountuint256The amount of tokens that needs to be deposited into the tranche

depositFor

Allows users to deposit their funds into the tranche.

Assets will be held by the contract until the predetermined investment start time.

function depositFor(DataTypes.Tranche _tranche, uint256 _amount, address _onBehalfOf)
external
payable
override
nonReentrant
gacPausable
onlyRole(FACTORY);

Parameters

NameTypeDescription
_trancheDataTypes.TrancheThe tranche into which the assets should be deposited
_amountuint256The amount of tokens that needs to be deposited into the tranche
_onBehalfOfaddressThe address of the beneficiary wallet that should recieve StructSPToken

claimExcess

Allows users to claim any excess tokens, and returns their corresponding amount of tokens in return for their SP tokens.

function claimExcess(DataTypes.Tranche _tranche) external override nonReentrant gacPausable;

Parameters

NameTypeDescription
_trancheDataTypes.TrancheThe tranche from which the excess tokens to be claimed

withdraw

Allows a user to withdraw the investment from the product once the tranche is matured

function withdraw(DataTypes.Tranche _tranche) external override nonReentrant gacPausable;

Parameters

NameTypeDescription
_trancheDataTypes.TrancheThe tranche id from which the investment should be withdrawn

rescueTokens

Used to withdraw any funds thats left in the contract

It can be called only by the Governance in case of emergency

function rescueTokens(IERC20Metadata _token, address _recipient) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_tokenIERC20MetadataThe address of the token to be withdrawn
_recipientaddressThe address of the recipient who receives the tokens

forceUpdateStatusToWithdrawn

Used to withdraw any funds thats left in the contract

Anyone can call this function if the product is not invested after 24 hours from the tranche start time.

function forceUpdateStatusToWithdrawn() public;

getUserInvestmentAndExcess

used to find the user investment and excess for the given tranche if any

function getUserInvestmentAndExcess(DataTypes.Tranche _tranche, address _investor)
external
view
override
returns (uint256, uint256);

Parameters

NameTypeDescription
_trancheDataTypes.Trancheid of the senior/junior tranche
_investoraddressaddress of the investor

Returns

NameTypeDescription
<none>uint256userInvested - the share of the user invested that accounts for total investment to the pool
<none>uint256excess - the share of the user's deposit that was not invested into the pool

getUserTotalDeposited

Used to get the total amount of tokens deposited by the user into a given tranche

function getUserTotalDeposited(DataTypes.Tranche _tranche, address _investor) external view returns (uint256);

Parameters

NameTypeDescription
_trancheDataTypes.Trancheid of the senior/junior tranche
_investoraddressaddress of the investor

Returns

NameTypeDescription
<none>uint256userDeposited the total amount of tokens deposited by the user into a given tranche

getInvestorDetails

Used to get the details of the investor for the given tranche

function getInvestorDetails(DataTypes.Tranche _tranche, address _user)
external
view
override
returns (DataTypes.Investor memory);

Parameters

NameTypeDescription
_trancheDataTypes.TrancheID of the tranche
_useraddressAddress of the user

Returns

NameTypeDescription
<none>DataTypes.InvestorThe investor info

getCurrentState

Used to get the current status of the Product

function getCurrentState() external view override returns (DataTypes.State);

Returns

NameTypeDescription
<none>DataTypes.StateThe current state of the product

getTrancheInfo

Used to get the details of the given tranche

function getTrancheInfo(DataTypes.Tranche _tranche) external view override returns (DataTypes.TrancheInfo memory);

Parameters

NameTypeDescription
_trancheDataTypes.TrancheID of the tranche

Returns

NameTypeDescription
<none>DataTypes.TrancheInfoTranche info for the given tranche

getTrancheConfig

Used to get the config of the given tranche

function getTrancheConfig(DataTypes.Tranche _tranche) external view override returns (DataTypes.TrancheConfig memory);

Parameters

NameTypeDescription
_trancheDataTypes.TrancheID of the tranche

Returns

NameTypeDescription
<none>DataTypes.TrancheConfigTranche config for the given tranche

getProductConfig

Used to get the configuration of the product

function getProductConfig() external view returns (DataTypes.ProductConfig memory);

_deposit

Deposits the _amount to the given tranche

function _deposit(DataTypes.Tranche _tranche, uint256 _amount, address _investor) internal;

Parameters

NameTypeDescription
_trancheDataTypes.TrancheSenior/Junior Tranche
_amountuint256The Amount of tokens to be deposited
_investoraddressThe Address under which the deposit has to be recorded

_claimExcess

Allows users to claim any excess tokens, and returns their corresponding amount of tokens in return for their SP tokens.

function _claimExcess(DataTypes.Tranche _tranche, uint256 _userInvested, uint256 _excess) private;

Parameters

NameTypeDescription
_trancheDataTypes.TrancheThe tranche id (senior/junior)
_userInvesteduint256The amount the user has invested
_excessuint256The excess amount the user can claim

_transferTokens

Transfers either ERC20 or native token to the depositor

function _transferTokens(DataTypes.TrancheConfig storage _trancheConfig, DataTypes.Tranche _tranche, uint256 _amount)
private;

Parameters

NameTypeDescription
_trancheConfigDataTypes.TrancheConfigthe configuration of the tranche
_trancheDataTypes.TrancheThe tranche id (senior/junior)
_amountuint256The amount to transfer to the user

_calculateUserShareAndTransfer

Calculate the user share from the matured tranche token and transfer to them.

function _calculateUserShareAndTransfer(DataTypes.Tranche _tranche) internal;

Parameters

NameTypeDescription
_trancheDataTypes.TrancheThe tranche id (senior/junior)

_forceUpdateStatusToWithdrawn

function _forceUpdateStatusToWithdrawn() internal;

receive

To receive native token transfers

Events to transition product state in the subgraph

receive() external payable;

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 virtual 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

Abstract

function invest() external virtual override;

removeFundsFromLP

Abstract

function removeFundsFromLP() external virtual override;