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
Property | Type | Modifier | Description |
---|---|---|---|
FEE_SCALE | uint256 | public; constant | The scale denominator for the fees. Default is |
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 |
debts | mapping(address => address) | public | Maps the |
isUpgrade | mapping(address => mapping(address => bool)) | internal | A nested mapping of strategy contracts which have been registered as eligible by the Vault Manager |
Events
PositionCreated()
Emitted when a new position is created on the Leverage Vault.
Arguments
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
token | address | The address of the Leverage Vault |
pool | address | The address of the newly configured lending pool tied to the Leverage Vault's |
DebtChanged()
Emitted when the lending pool tied to the Leverage Vault debt
is changed by the owner
of the vault.
Arguments
Argument | Type | Description |
---|---|---|
token | address | The address of the Leverage Vault |
pool | address | The address of the newly configured lending pool tied to the Leverage Vault's |
UpgradeRegistered()
Emitted when a proposed strategy implementation address is registered by the Leverage Vault owner
.
Arguments
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
descriptor | address | The address of the |
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
Params | Type | Description |
---|---|---|
_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
Params | Type | Description |
---|---|---|
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
Type | Description |
---|---|
uint256 | The new |
address | The address of the newly deployed strategy contract which was implemented for the position. |
Events
Events | Description |
---|---|
Emits the |
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
Params | Type | Description |
---|---|---|
asset | address | The address of the token used to collateralize the position. |
pool | address | The address of the |
Events
Events | Description |
---|---|
Emits the address of the newly configured lending pool tied to the Leverage Vault's |
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
Params | Type | Description |
---|---|---|
debt | address | The address of the debt token to be borrowed for leverage purposes. |
pool | address | The address of the |
Events
Events | Description |
---|---|
Emits the address of the newly configured lending pool tied to the Leverage Vault's |
burnPosition() - external
external
Allows the owner of the position to burn (i.e. removes) their zero balance positions.
Returns
Type | Description |
---|---|
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
Params | Type | Description |
---|---|---|
id | uint256 | The |
Returns
Type | Description |
---|---|
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
Events | Description |
---|---|
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
Params | Type | Description |
---|---|---|
baseImplementation | address | The address of the previous strategy contract. |
upgradeImplementation | address | The address of the proposed updated strategy contract. |
Returns
Type | Description |
---|---|
bool |
|
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
Params | Type | Description |
---|---|---|
baseImplementation | address | The address of the previous strategy contract. |
upgradeImplementation | address | The address of the proposed updated strategy contract. |
Events
Events | Description |
---|---|
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
Params | Type | Description |
---|---|---|
baseImplementation | address | The address of the previous strategy contract. |
upgradeImplementation | address | The address of the proposed updated strategy contract. |
Events
Events | Description |
---|---|
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
Params | Type | Description |
---|---|---|
_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
Params | Type | Description |
---|---|---|
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
Params | Type | Description |
---|---|---|
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
Params | Type | Description |
---|---|---|
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
Type | Description |
---|---|
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
Params | Type | Description |
---|---|---|
account | address | The address of the position holder. |
amount | uint128 | The amount of Leverage Vault token count to be added to the existing |
_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
Params | Type | Description |
---|---|---|
to | address | The address to transfer ownership of |
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
Type | Description |
---|---|
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
Params | Type | Description |
---|---|---|
interfaceId | bytes4 | The encoded bytes data representing the interface being queried. |
Returns
Type | Description |
---|---|
bool |
|
Last updated