WrapperFactorLeverageVault.sol
Contract Overview
WrapperFactorLeverageVault.sol
functions as a wrapper contract for FactorLeverageVault.sol
thereby enabling vault depositors to benefit from various Factor reward distribution mechanisms such as Factor Scale and Factor Boost.
By implementing a wrapper, users can stake their liquidity by locking underlying Leverage Vault (i.e. ERC20Augmented
) shares in the wrapper contract. This staked amount will then dictate their gauge voting power as well as accrued rewards.
The vault implements OpenZeppelin's upgradeable proxy pattern.
Properties
Public
Property | Type | Modifier | Description |
---|---|---|---|
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 |
factorLeverageVaultAddress | address | public | The address of the underlying Leverage Vault which this contract wraps. |
allowedAsset | address | public | The address of the Strategy |
allowedDebt | address | public | The address of the Strategy |
Events
LeverageAdded()
Emitted when leverage is added to a position.
Arguments
Argument | Type | Description |
---|---|---|
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 | uint256 | The amount of |
LeverageRemoved()
Emitted when leverage is removed from a position.
Arguments
Argument | Type | Description |
---|---|---|
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 |
LeverageClosed()
Emitted when a leveraged position is closed and all of the related asset
and debt
is returned to the owner.
Arguments
Argument | Type | Description |
---|---|---|
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 |
debtBalance | uint256 | The remaining amount of |
Stake()
Emitted when underlying vault tokens are staked into the wrapper vault contract.
Arguments
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
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 |
UpdateBalance()
Emitted when the Wrapper Vault contract balance for a position is updated with the Strategy contract balances.
Arguments
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
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 |
Supply()
Emitted when asset
is supplied to the Strategy contract.
Arguments
Argument | Type | Description |
---|---|---|
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 |
UpgradeStrategy()
Emitted when the Strategy implementation contract for the positionId
is upgraded.
Arguments
Argument | Type | Description |
---|---|---|
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.
Variables | Type | Description |
---|---|---|
_name | string | The name of the vault. This will be used as the name of the |
_symbol | string | The symbol of the vault. This will be used as the symbol of the |
_allowedAsset | address | The address of the underlying vault |
_allowedDebt | address | The address of the underlying vault |
_factorLeverageVaultAddress | address | The address of the underlying Factor vault that is wrapped by this contract (i.e. deployed |
_veFctr | address | The address of the veFCTR contract. |
_gaugeController | address | The address of the Factor Gauge Controller contract. |
_boostController | address | The address of the Factor Boost 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
Params | Type | Description |
---|---|---|
initParams | Memory data that contains the initialization data for the wrapper vault. |
transferFrom() - public
virtual
override
public
virtual
override
Transfers 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
Params | Type | Description |
---|---|---|
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
nonReentrant
Stakes 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
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT to be staked. |
Events
Events | Description |
---|---|
Emits the identifier of the position that was staked. |
createPosition() - external
nonReentrant
returns
external
nonReentrant
returns
Creates 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
Type | Description |
---|---|
uint256 | The newly created position ID. |
strategy | The address of the newly deployed strategy contract which was implemented for the position. |
Events
Events | Description |
---|---|
Emits the newly created position ID and the implemented strategy address. |
unstakePosition() - external
nonReentrant
external
nonReentrant
Allows 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
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT to be unstaked. |
Events
Events | Description |
---|---|
Emits the identifier of the position that was unstaked. |
addLeverage() - external
nonReentrant
external
nonReentrant
Allows the position owner
to add leverage towards their specified positionId
.
Transfers the specified
amount
ofasset
frommsg.sender
(i.e. user) to the Wrapper Vault contractAdds leverage to the provided
positionId
by callingaddLeverage()
from the implemented Strategy contractUpdates the Wrapper Vault balances which is being tracked via the
ERC20Augmented
tokenUpdates the the
positionId
debt balance on the Wrapper Vault contract
Parameters
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT to add leverage to. |
amount | uint256 | The amount of |
debt | uint256 | The amount of |
data | bytes | The Balancer |
Events
Events | Description |
---|---|
Emits the results of the leverage addition. |
supply() - external
nonReentrant
external
nonReentrant
Allows 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
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT to which |
amount | uint256 | The amount of |
Events
Events | Description |
---|---|
Emits the result of the supply which includes the address of the corresponding Strategy contract. |
removeLeverage() - external
nonReentrant
external
nonReentrant
Allows the position owner
to remove leverage from their specified positionId
.
Removes the specified
amount
ofasset
by callingremoveLeverage()
from the implemented Strategy contractTransfer the removed
asset
amount to themsg.sender
(i.e. user)Updates the Wrapper Vault balances which is being tracked via the
ERC20Augmented
tokenUpdates the the
positionId
debt balance on the Wrapper Vault contract
Parameters
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT to remove leverage from. |
amount | uint256 | The amount of |
data | bytes | The Balancer |
Events
Events | Description |
---|---|
Emits the results of the leverage removal. |
_operationAugmented() - internal
internal
An 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
Params | Type | Description |
---|---|---|
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
nonReentrant
Allows 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
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT whose balance is to be synced. |
Events
Events | Description |
---|---|
Emits the results of the debt balance update. |
closeLeverage() - external
onlyOwner
external
onlyOwner
Allows 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
positionId
by callingcloseLeverage()
from the implemented Strategy contractTransfers the
asset
anddebt
from the closed position to themsg.sender
(i.e. owner)Updates the Wrapper Vault balances which is being tracked via the
ERC20Augmented
tokenUpdates the the
positionId
debt balance on the Wrapper Vault contract
Parameters
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT to be closed. |
amount | uint256 | The amount of |
data | bytes | The Balancer |
Events
Events | Description |
---|---|
Emits the results of the leverage position closure. |
withdraw() - external
nonReentrant
external
nonReentrant
Allows 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
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT to withdraw from. |
amount | uint256 | The amount of |
Events
Events | Description |
---|---|
Emits the withdrawal details. |
repay() - external
onlyOwner
external
onlyOwner
Allows 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
Params | Type | Description |
---|---|---|
positionId | uint256 | The identifier of the underlying Leverage Vault position NFT whose debt is being repaid. |
amount | uint256 | The amount of |
Events
Events | Description |
---|---|
Emits the amount of |
_beforeTokenTransfer() - internal
override
internal
override
An internal function that updates Factor Scale and Factor Boost rewards prior to a related token transfer.
Parameters
Params | Type | Description |
---|---|---|
from | address | The address of the |
to | address | The address of the token receiver. |
amount | uint256 | The amount of tokens to be transferred. |
_afterTokenTransfer() - internal
override
internal
override
An internal function that updates the msg.sender
's active balance in the gauge.
Parameters
Params | Type | Description |
---|---|---|
from | address | The address of the |
to | address | The address of the token receiver. |
amount | uint256 | The amount of tokens to be transferred. |
_stakedBalance() - internal
view
override
internal
view
override
Returns 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
Params | Type | Description |
---|---|---|
user | address | The address of the |
Returns
Type | Description |
---|---|
uint256 | The amount of underlying Leverage Vault tokens staked. |
_totalStaked() - internal
view
override
internal
view
override
Returns the total amount of underlying vault tokens held by (i.e. staked into) the Wrapper Vault contract.
Returns
Type | Description |
---|---|
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
returns
Returns the encoded Uniform Resource Identifier (URI) of the position id
that is being queried.
Parameters
Params | Type | Description |
---|---|---|
id | uint256 | The |
Returns
Type | Description |
---|---|
uint256 | The encoded URI for the token representing the position in the leverage vault. |
redeemRewards() - public
nonReentrant
returns
public
nonReentrant
returns
Enables stakers to claim their accrued Factor Scale rewards.
Parameters
Params | Type | Description |
---|---|---|
user | address | The address of the user that has accured rewards. |
Returns
Type | Description |
---|---|
uint256[] | An array containing the amount of reward tokens redeemed, in the same order as |
getRewardTokens() - external
view
returns
external
view
returns
Returns the ordered list of reward tokens that have accrued to the user.
Returns
Type | Description |
---|---|
address[] | An array containing the amount of reward tokens redeemed. |
claimRewards() - external
nonReentrant
external
nonReentrant
Allows 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
Params | Type | Description |
---|---|---|
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
public
Enables the position owner
to update the underlying Leverage Vault's strategyImplementation
with a newly provided upgradeImplemantation
address.
Parameters
Params | Type | Description |
---|---|---|
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
Events | Description |
---|---|
Emits the address of the newly implemented strategy. |
Last updated