WrapperFactorLeverageVault.sol
Properties
Public
stakedNFT
mapping(uint256 => address)
public
A mapping of the wrapper vault NFT id to the owner address.
snapshotBalance
mapping(uint256 => uint256)
public
A snapshot that maps the positionID with the ERC20Augmented token balances(which represent underlying Leverage Vault tokens).
factorLeverageVaultAddress
address
public
The address of the underlying Leverage Vault which this contract wraps.
allowedAsset
address
public
The address of the Strategy asset which the Wrapper Vault contract supports.
allowedDebt
address
public
The address of the Strategy debt which the Wrapper Vault contract supports.
Events
LeverageAdded()
Emitted when leverage is added to a position.
Arguments
positionStrategy
address
The address of the strategy contract implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
amount
uint256
The amount of asset that was added to the position.
debt
uint256
The amount of debt that was borrowed to open the leverage position.
LeverageRemoved()
Emitted when leverage is removed from a position.
Arguments
positionStrategy
address
The address of the strategy contract implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
amount
uint256
The amount of asset that was removed from the leveraged position and returned to the owner.
LeverageClosed()
Emitted when a leveraged position is closed and all of the related asset and debt is returned to the owner.
Arguments
positionStrategy
address
The address of the strategy contract implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
assetBalance
uint256
The remaining amount of asset in the Strategy contract after the leveraged position is closed.
debtBalance
uint256
The remaining amount of debt in the Strategy contract after the leveraged position is closed.
Stake()
Emitted when underlying vault tokens are staked into the wrapper vault contract.
Arguments
positionId
uint256
The position identifier that uniquely identifies the position from the underlying Leverage Vault that was staked into the Wrapper contract.
CreatePosition()
Emitted when a new position is created on the underlying Leverage Vault contract.
Arguments
positionId
uint256
The position identifier that uniquely identifies the position that was created in underlying Leverage Vault.
vault
address
The address of the Strategy contract implemented for the position.
UnStake()
Emitted when underlying vault tokens are unstaked and removed from the wrapper vault contract.
Arguments
positionId
uint256
The position identifier that uniquely identifies the position from the underlying Leverage Vault that was unstaked from the Wrapper contract.
Withdraw()
Emitted when asset is withdrawn from a position.
Arguments
positionStrategy
address
The address of the strategy contract implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
amount
uint256
The number of asset that is withdrawn from the position.
UpdateBalance()
Emitted when the Wrapper Vault contract balance for a position is updated with the Strategy contract balances.
Arguments
positionStrategy
address
The address of the strategy contract implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
oldBalance
uint256
The previous debt balance of the position on the Wrapper Vault contract.
newBalance
uint256
Thew updated balance of the poisiotn on the Wrapper Vault contract.
Repay()
Emitted when the positionId's debt is repaid.
Arguments
positionStrategy
address
The address of the strategy contract implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
amount
uint256
The amount of debt that was repaid.
Supply()
Emitted when asset is supplied to the Strategy contract.
Arguments
positionStrategy
address
The address of the strategy contract implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
amount
uint256
The amount of asset supplied to the position.
UpgradeStrategy()
Emitted when the Strategy implementation contract for the positionId is upgraded.
Arguments
positionStrategy
address
The address of the strategy contract that was previously implemented by the position.
positionId
uint256
The position identifier that uniquely identifies every position on the underlying Leverage Vault.
upgradeImplementation
address
The address of the new Strategy contract implemented by the position.
Structs
InitParams
A struct that defines the Leverage Vault initalization format.
_name
string
The name of the vault. This will be used as the name of the ERC20Augmented token representing vault shares.
_symbol
string
The symbol of the vault. This will be used as the symbol of the ERC20Augmented token representing vault shares.
_allowedAsset
address
The address of the underlying vault asset that can be facilitated by the wrapper contract.
_allowedDebt
address
The address of the underlying vault debt that can be facilitated by the wrapper contract.
_factorLeverageVaultAddress
address
The address of the underlying Factor vault that is wrapped by this contract (i.e. deployed FactorVault.sol address)
_gaugeController
address
The address of the Factor Gauge Controller contract.
_rewardDuration
uint256
The reward duration which the Factor Boost rewards for this wrapper vault will be initalized with.
Constructor
Factor Vault contracts implements OpenZeppelin's upgradeable contracts design and locks the Vault contract upon initialization to avoid contract takeover by an attacker. More info can be found on OpenZeppelin Docs.
Methods
initialize() - public initializer
public initializer The contract initialization function which initializes the contract with the underlying Leverage Vault configurations as well as the Factor ecosystem contract addresses.
The ERC20 and ERC721 token contracts that respectively represent Wrapper Vault shares and Wrapper Position NFTs are initialized as part of this function. The related Factor Gauge and Factor Boost contracts are also initialized for the Leverage Vault.
Parameters
transferFrom() - public virtual override
public virtual overrideTransfers the position NFT with the specified id from the from address to the to address. The caller of this function must either be the owner of the NFT or have the necessary allowances to spend the owner's NFT.
The underlying debt of the position NFT is also transferred to the to address.
Parameters
from
address
The address of the NFT owner from which to debit the position NFT.
to
address
The address to transfer the position NFT to.
id
uint256
The identifier of the underlying Leverage Vault position NFT to be transferred.
stakePosition() - external nonReentrant
external nonReentrantStakes the provided positionId NFT in the wrapper contract by transferring it from the msg.sender to the Wrapper Vault contract address. Wrapper Vault NFTs representing the underlying Leverage Vault position are minted to the msg.sender.
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT to be staked.
Events
Emits the identifier of the position that was staked.
createPosition() - external nonReentrant returns
external nonReentrant returnsCreates a new position representing the configurations of a depositor's position in the underlying Leverage Vault (only consists of the position structure and not actual liquidity).
To create the position, a new instance of the strategyImplementation contract is initalized with every newly created position ID for this vault.
The underlying Leverage Vault position NFT is minted to the Wrapper Vault contract while a newly created Wrapper Vault position NFT is sent to the Wrapper Vault contract msg.sender.
Returns
uint256
The newly created position ID.
strategy
The address of the newly deployed strategy contract which was implemented for the position.
Events
Emits the newly created position ID and the implemented strategy address.
unstakePosition() - external nonReentrant
external nonReentrantAllows the owner the staked Wrapper Vault position to unstake their position from the Wrapper Vault contract (i.e. underlying Leverage Vault position NFT is transferred back to the staker).
The Wrapper Vault position NFT is burned with the corresponding wrapper virtual debt balance (represented by the `ERC20Augmented) is also destroyed.
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT to be unstaked.
Events
Emits the identifier of the position that was unstaked.
addLeverage() - external nonReentrant
external nonReentrantAllows the position owner to add leverage towards their specified positionId.
Transfers the specified
amountofassetfrommsg.sender(i.e. user) to the Wrapper Vault contractAdds leverage to the provided
positionIdby callingaddLeverage()from the implemented Strategy contractUpdates the Wrapper Vault balances which is being tracked via the
ERC20AugmentedtokenUpdates the the
positionIddebt balance on the Wrapper Vault contract
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT to add leverage to.
amount
uint256
The amount of asset to supply as collateral for the loan.
debt
uint256
The amount of debt to flash loan to increase position leverage.
data
bytes
The Balancer userData which in this context is used for pool-specific instructions needed to do the calculations.
Events
Emits the results of the leverage addition.
supply() - external nonReentrant
external nonReentrantAllows the position owner to supply a specified amount of asset to the Wrapper Vault contract which is then supplied to the Strategy lending pool.
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT to which asset is being supplied.
amount
uint256
The amount of asset to be supplied as collateral for the position.
Events
Emits the result of the supply which includes the address of the corresponding Strategy contract.
removeLeverage() - external nonReentrant
external nonReentrantAllows the position owner to remove leverage from their specified positionId.
Removes the specified
amountofassetby callingremoveLeverage()from the implemented Strategy contractTransfer the removed
assetamount to themsg.sender(i.e. user)Updates the Wrapper Vault balances which is being tracked via the
ERC20AugmentedtokenUpdates the the
positionIddebt balance on the Wrapper Vault contract
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT to remove leverage from.
amount
uint256
The amount of asset being removed.
data
bytes
The Balancer userData which in this context is used for pool-specific instructions needed to do the calculations.
Events
Emits the results of the leverage removal.
_operationAugmented() - internal
internalAn internal function that facilitates the burning and minting of ERC20Augmented tokens representing the number of underlying Leverage Vault tokens in the Wrapper Vault contract.
Parameters
newBalance
uint256
The updated balance maintained by the Wrapper Vault contract.
oldBalance
uint256
The previous virtual balance maintained by the Wrapper Vault contract.
updateBalance() - external nonReentrant
external nonReentrantAllows the position owner to synchronize debt balances between the Wrapper Vault contract and the Strategy contract. The debt balance on the Strategy contract is used to update the Wrapper Vault contract.
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT whose balance is to be synced.
Events
Emits the results of the debt balance update.
closeLeverage() - external onlyOwner
external onlyOwnerAllows the position owner to close their specified positionId and receive the underlying asset and debt. If the asset amount specified is greater than the debt value, the position value will be returned in debt tokens.
Closes the
positionIdby callingcloseLeverage()from the implemented Strategy contractTransfers the
assetanddebtfrom the closed position to themsg.sender(i.e. owner)Updates the Wrapper Vault balances which is being tracked via the
ERC20AugmentedtokenUpdates the the
positionIddebt balance on the Wrapper Vault contract
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT to be closed.
amount
uint256
The amount of asset that will be swapped for debt.
data
bytes
The Balancer userData which in this context is used for pool-specific instructions needed to do the calculations.
Events
Emits the results of the leverage position closure.
withdraw() - external nonReentrant
external nonReentrantAllows the position owner to withdraw a specified amount of their collateralized asset from the Strategy contract . The withdrawn asset is credited to the msg.sender (i.e. user) address.
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT to withdraw from.
amount
uint256
The amount of asset that will be withdrawn.
Events
Emits the withdrawal details.
repay() - external onlyOwner
external onlyOwnerAllows the position owner to repay a specified amount of their positionId's debt on the Strategy contract. The ERC20Augmented balances are burned with the Wrapper Vault contract balances being updated.
Parameters
positionId
uint256
The identifier of the underlying Leverage Vault position NFT whose debt is being repaid.
amount
uint256
The amount of debt to be repaid.
Events
Emits the amount of debt that was repaid as well as the Strategy contract address.
_beforeTokenTransfer() - internal override
internal overrideAn internal function that updates Factor Scale and Factor Boost rewards prior to a related token transfer.
Parameters
from
address
The address of the msg.sender.
to
address
The address of the token receiver.
amount
uint256
The amount of tokens to be transferred.
_afterTokenTransfer() - internal override
internal overrideAn internal function that updates the msg.sender's active balance in the gauge.
Parameters
from
address
The address of the msg.sender.
to
address
The address of the token receiver.
amount
uint256
The amount of tokens to be transferred.
_stakedBalance() - internal view override
internal view overrideReturns the amount of ERC20Augmented tokens (i.e. underlying Leverage Vault tokens) that a user (i.e. staker) has staked into the Wrapper Vault contract.
Parameters
user
address
The address of the user.
Returns
uint256
The amount of underlying Leverage Vault tokens staked.
_totalStaked() - internal view override
internal view overrideReturns the total amount of underlying vault tokens held by (i.e. staked into) the Wrapper Vault contract.
Returns
uint256
The total amount of underlying Leverage Vault tokens held by the wrapper vault contract.
tokenURI() - public view virtual override returns
public view virtual override returnsReturns the encoded Uniform Resource Identifier (URI) of the position id that is being queried.
Parameters
id
uint256
The positionId of the position whose URI data is being queried.
Returns
uint256
The encoded URI for the token representing the position in the leverage vault.
redeemRewards() - public nonReentrant returns
public nonReentrant returnsEnables stakers to claim their accrued Factor Scale rewards.
Parameters
user
address
The address of the user that has accured rewards.
Returns
uint256[]
An array containing the amount of reward tokens redeemed, in the same order as getRewardTokens().
getRewardTokens() - external view returns
external view returnsReturns the ordered list of reward tokens that have accrued to the user.
Returns
address[]
An array containing the amount of reward tokens redeemed.
claimRewards() - external nonReentrant
external nonReentrantAllows the position owner to claim the Strategy rewards which has accrued to their positionId. The reward tokens are transferred to the msg.sender's (i.e. owner) address.
Parameters
positionId
address
The identifier of the underlying Leverage Vault position NFT whose debt is being repaid.
token
address
The address of the token receiver.
upgradeStrategy() - public
publicEnables the position owner to update the underlying Leverage Vault's strategyImplementation with a newly provided upgradeImplemantation address.
Parameters
positionId
address
The identifier of the underlying Leverage Vault position NFT whos estrategy implementation is being updated.
upgradeImplemantation
address
The address of the new Strategy implementation contract.
Events
Emits the address of the newly implemented strategy.
Last updated
Was this helpful?