FEYProduct
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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | The tranche into which the assets should be deposited |
_amount | uint256 | The 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | The tranche into which the assets should be deposited |
_amount | uint256 | The amount of tokens that needs to be deposited into the tranche |
_onBehalfOf | address | The 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | The 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | The 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
Name | Type | Description |
---|---|---|
_token | IERC20Metadata | The address of the token to be withdrawn |
_recipient | address | The 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | id of the senior/junior tranche |
_investor | address | address of the investor |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | userInvested - the share of the user invested that accounts for total investment to the pool |
<none> | uint256 | excess - 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | id of the senior/junior tranche |
_investor | address | address of the investor |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | userDeposited 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | ID of the tranche |
_user | address | Address of the user |
Returns
Name | Type | Description |
---|---|---|
<none> | DataTypes.Investor | The investor info |
getCurrentState
Used to get the current status of the Product
function getCurrentState() external view override returns (DataTypes.State);
Returns
Name | Type | Description |
---|---|---|
<none> | DataTypes.State | The 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | ID of the tranche |
Returns
Name | Type | Description |
---|---|---|
<none> | DataTypes.TrancheInfo | Tranche 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | ID of the tranche |
Returns
Name | Type | Description |
---|---|---|
<none> | DataTypes.TrancheConfig | Tranche 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | Senior/Junior Tranche |
_amount | uint256 | The Amount of tokens to be deposited |
_investor | address | The 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | The tranche id (senior/junior) |
_userInvested | uint256 | The amount the user has invested |
_excess | uint256 | The 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
Name | Type | Description |
---|---|---|
_trancheConfig | DataTypes.TrancheConfig | the configuration of the tranche |
_tranche | DataTypes.Tranche | The tranche id (senior/junior) |
_amount | uint256 | The 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
Name | Type | Description |
---|---|---|
_tranche | DataTypes.Tranche | The 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
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
Abstract
function invest() external virtual override;
removeFundsFromLP
Abstract
function removeFundsFromLP() external virtual override;