FactorLeverageVault.sol
Contract Overview
FactorLeverageVault.sol
manages the Leverage Vault configurations as well as the positions created via this vault. Positions in the vault are represented via a ERC721 NFT which is uniquely identified via the positionId
.
All positions created on this vault share the same configurations such as asset
and debt
tokens/pools as well as fee configurations. Each positionId
will implement strategy logic via a Strategy contract that is tied to the specific position NFT.
The vault implements OpenZeppelin's upgradeable proxy pattern. The vault owner
is able to propose a new strategy contract implementation for the vault and upgrade the vault's strategy implementation if the strategy has been registered.
Properties
Public
FEE_SCALE
uint256
public; constant
The scale denominator for the fees. Default is 1e18
.
leverageFee
uint256
public
The fee that is charged on the leverage portion whenever a position's leverage is changed.
claimRewardFee
uint256
public
The fee that is charged on the harvested rewards whenever the accrued position rewards are claimed.
feeRecipient
address
public
The address of the fee recipient.
strategyImplementation
address
public
The address of the strategy contract that is implemented for this leverage vault.
factorLeverageDescriptor
address
public
The address of the leverage vault descriptor which facilitates sharing of encoded leverage vault token data (i.e. URI).
currentPositionId
uint256
public
An integer which is used to track the positions created via this Leverage Vault. Incremented by 1 with every new position created (i.e. always 1 more than the last created positionId).
positions
mapping(uint256 => address)
public
Maps the position to their implemented strategy contract address.
assets
mapping(address => address)
public
Maps the asset
to the corresponding lending pool contract address.
debts
mapping(address => address)
public
Maps the debt
to the corresponding lending pool contract address.
isUpgrade
mapping(address => mapping(address => bool))
internal
A nested mapping of strategy contracts which have been registered as eligible by the Vault Manager owner
. Enables registered proposed strategies to be implemented.
Events
PositionCreated()
Emitted when a new position is created on the Leverage Vault.
Arguments
id
uint256
The identifier of the new position that was created.
vault
address
The address of the strategy implementation that was deployed with the newly created position.
AssetChanged()
Emitted when the lending pool tied to the Leverage Vault asset
is changed by the owner
of the vault.
Arguments
token
address
The address of the Leverage Vault asset
.
pool
address
The address of the newly configured lending pool tied to the Leverage Vault's asset
.
DebtChanged()
Emitted when the lending pool tied to the Leverage Vault debt
is changed by the owner
of the vault.
Arguments
token
address
The address of the Leverage Vault debt
.
pool
address
The address of the newly configured lending pool tied to the Leverage Vault's debt
.
UpgradeRegistered()
Emitted when a proposed strategy implementation address is registered by the Leverage Vault owner
.
Arguments
baseImpl
address
The address of the existing strategy contract that is implemented by the vault.
upgradeImpl
address
The address of the proposed strategy contract to be implemented.
UpgradeRemoved()
Emitted when a proposed strategy implementation is removed (i.e. deregistered) from isUpgrade
by the Leverage Vault owner
.
Arguments
baseImpl
address
The address of the existing strategy contract that is implemented by the vault.
upgradeImpl
address
The address of the proposed strategy contract to be implemented.
DescriptorChanged()
Emitted when the leverage descriptor contract address is changed by the Leverage Vault owner.
Arguments
descriptor
address
The address of the msg.sender
(i.e. depositor) that deposited into the vault.
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 vault params and initial fee scale. Defaults the fee recipient to the msg.sender
(i.e. leverage vault creator).
Parameters
_strategyImplementation
address
The address of the strategy contract to be implemented for this leverage vault.
_factorLeverageDescriptor
address
The address of the leverage vault descriptor that will describe the leverage vault token.
_name
string
The name of the leverage vault collection. Used as the NFT collection name.
_symbol
string
The symbol of the leverage vault collection. Used as the NFT collection symbol.
createPosition() - external
returns
external
returns
Creates a new position representing the configurations of a depositor's position in the 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 newly created position NFT is sent to the msg.sender
.
Parameters
asset
address
The address of the token used to collateralize the position.
debt
address
The address of the debt token to be borrowed for leverage purposes.
Returns
uint256
The new currentPositionId
after a position is created (i.e. newly created position ID plus 1).
address
The address of the newly deployed strategy contract which was implemented for the position.
Events
Emits the currentPositionId
and the implemented strategy address.
updateAsset() - external
onlyOwner
external
onlyOwner
Allows the owner
of the leverage vault contract to change the address of the lending pool tied to the vault's asset
.
Parameters
asset
address
The address of the token used to collateralize the position.
pool
address
The address of the asset
lending pool to be changed to.
Events
Emits the address of the newly configured lending pool tied to the Leverage Vault's asset
.
updateDebt() - external
onlyOwner
external
onlyOwner
Allows the owner
of the leverage vault contract to change the address of the lending pool tied to the vault's debt
.
Parameters
debt
address
The address of the debt token to be borrowed for leverage purposes.
pool
address
The address of the debt
lending pool to be changed to.
Events
Emits the address of the newly configured lending pool tied to the Leverage Vault's debt
.
burnPosition() - external
external
Allows the owner of the position to burn (i.e. removes) their zero balance positions.
Returns
positionId
The ID of the position to be burned.
tokenURI() - public
view
override
returns
public
view
override
returns
Returns 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
string
The encoded URI for the token representing the position in the leverage vault.
setDescriptor() - external
onlyOwner
external
onlyOwner
Allows the owner of the leverage vault to change the address of the factorLeverageDescriptor
.
Events
Emits the address of the new leverage vault descriptor.
isRegisteredUpgrade() - external
view
returns
external
view
returns
Checks whether the upgrade from baseImplementation
to upgradeImplementation
has been registered by the Leverage Vault owner
.
Parameters
baseImplementation
address
The address of the previous strategy contract.
upgradeImplementation
address
The address of the proposed updated strategy contract.
Returns
bool
true
= Proposed strategy has been registered by owner
.
false
= Proposed strategy has not been registered by owner
.
registerUpgrade() - external
onlyOwner
external
onlyOwner
Allows the Leverage Vault owner
to register a strategy upgrade from baseImplementation
to upgradeImplementation
. Proposed strategies must be registered before it can be implemented.
Parameters
baseImplementation
address
The address of the previous strategy contract.
upgradeImplementation
address
The address of the proposed updated strategy contract.
Events
Emits the registered strategy upgrade proposal.
removeUpgrade() - external
onlyOwner
external
onlyOwner
Allows the Leverage Vault owner
to remove a previously registered strategy upgrade proposal from isUpgrade
.
Parameters
baseImplementation
address
The address of the previous strategy contract.
upgradeImplementation
address
The address of the proposed updated strategy contract.
Events
Emits the strategy upgrade proposal that was removed.
updateImplementation() - external
onlyOwner
external
onlyOwner
Allows the Leverage Vault owner
to update the strategyImplementation
with a newly provided address.
Parameters
_strategyImplementation
address
The address of the new strategy implementation contract.
setFeeRecipient() - external
onlyOwner
external
onlyOwner
Allows the Leverage Vault owner
to update the feeRecipient
with a newly provided address.
Parameters
recipient
address
The address that receives the leverage fees.
setLeverageFee() - external
onlyOwner
external
onlyOwner
Allows the Leverage Vault owner
to update the leverageFee
that is charged on the leverage portion whenever a position's leverage is changed.
The newFee
provided is scaled by the Leverage Vault contract's FEE_SCALE
which is defaulted to 1e18
on vault initialization. That is, a newFee
of 1e16
is equivalent to 1% fee (i.e. 1e16
/1e18
).
Parameters
newFee
uint256
The amount of leverage fee to charge.
setClaimRewardFee() - external
onlyOwner
external
onlyOwner
Allows the Leverage Vault owner
to update the claimRewardFee
that is charged on the harvested rewards whenever the accrued position rewards are claimed.
The newFee
provided is scaled by the Leverage Vault contract's FEE_SCALE
which is defaulted to 1e18
on vault initialization. That is, a newFee
of 1e16
is equivalent to 1% fee (i.e. 1e16
/1e18
).
Parameters
newFee
uint256
The amount of claim reward fee to charge.
version() - external
pure
returns
external
pure
returns
Returns the Leverage Vault version which is hardcoded based on contract deployment.
Returns
string
The Leverage Vault version.
_increaseBalance() - internal
virtual
override
internal
virtual
override
An internal function that overrides the ERC721 _increaseBalance() function meant to increase the number of NFT collection tokens held by the account
.
Parameters
account
address
The address of the position holder.
amount
uint128
The amount of Leverage Vault token count to be added to the existing account
balances.
_update() - internal
virtual
override
returns
internal
virtual
override
returns
An internal function that overrides the ERC721 _update() function meant to update the owner of the tokenId
.
Parameters
to
address
The address to transfer ownership of tokenId
to. Mints (or burns) the position NFT if the current owner (or to) is the zero address.
tokenId
uint128
The identifier for the Leverage Vault NFT to be updated.
auth
address
An optional params where passing in a non-zero value checks if the provided address has the rights to transfer the token (i.e. owner or approved).
Returns
address
The address of the LP Vault NFT (representing the position) before the update.
supportsInterface() - public
view
override
returns
public
view
override
returns
An internal function that overrides the ERC721 supportsInterface() function that returns true
if this Leverage Vault contract implements the interface defined by interfaceId
.
Parameters
interfaceId
bytes4
The encoded bytes data representing the interface being queried.
Returns
bool
true
= interfaceId
is supported by the Leverage Vault contract
false
= interfaceId
is not supported by the Leverage Vault contract
Last updated
Was this helpful?