Factor Docs
  • 🏭Introduction to Factor
  • Getting Started
    • đŸ•šī¸Quickstart
    • 🔗Supported Protocols
    • 🔐Strategy Cheatsheet
      • Swaps Cheatsheet
        • Conditional Market Order
        • Automated Market Order
        • Multi Swap
        • Automated Swap & Earn
        • Automated Scale Order
        • Scale Order Partial Fill Yield
        • Interest On Pending Trades
        • Leverage Trade
        • Leverage DCA
      • Lending Cheatsheet
        • Lending Pool Zap
        • Multi Lend
        • Market Making To Lending Switch
        • Earn Negative Interest
        • Carry Trade
        • Leveraged Staking Yields
        • Leveraged Fixed Yields
      • Borrowing Cheatsheet
        • Collateralized Borrow
        • Collateralized Borrow Zap
        • Multi Borrow
        • Debt Switching
        • Automated Debt Readjustments
        • Debt Refinancing
        • Asset Switching
      • Liquidity Provision Cheatsheet
        • Liquidity Pool Zap
        • Yield Farm Zap
        • Automated LP Adjustments
        • Yield Farm Adjustments
      • Flash Loan Cheatsheet
    • 🧠Strategy Explainers
      • Leverage
        • Leverage Performance Modelling
        • Leverage Long Simulation
        • Leverage Short Simulation
      • Yield
        • Yield Performance Modelling
      • PT Strategies
        • Leverage Long PT Simulation
      • Delta Neutral Yields
        • Levered USD & ETH Carry
    • 📖Glossary
  • Factor Discover
    • 🔍Factor Discover
      • Public Strategies User Guides
        • Deposit Into User Created Strategies
        • Withdraw From User Created Strategies
      • Leverage User Guides
        • Create A Leveraged Position
        • Adjust Position Leverage
        • Add Collateral To Position
        • Withdraw Collateral From Position
        • Repay Position Debt
      • Yield User Guides
        • Auto-compound Your Yields
      • PT User Guides
        • Redeem Your PT
      • APY Calculations
    • âš™ī¸Factor Operated Strategies
      • Yield Type Strategies
        • Additional rETH Yields On USDC Lend
        • Amplified rETH Yields On USDC Lend
        • Additional Liquid Staked ETH Yields On USDC Lend
        • Additional Liquid Restaked ETH Yields On USDC Lend
      • Trading Type Strategies
        • WBTC Base Switch On rETH For ETH & USDC Yields
      • Delta Neutral Type Strategies
        • Delta Neutral ETH With rETH & USDC Yields
  • Factor Studio
    • 🎨Factor Studio
      • Automated Strategies
      • Conditional Strategies
    • 🏠Private Strategies
      • User Guide
        • Private Strategy Creation
    • đŸ‘ĨPublic Strategies
      • User Guide
        • Public Strategy Creation
        • Create An Exit Strategy
        • Making Your Strategy Public
        • Strategy Execution
      • Security
      • Exit Strategy
    • đŸ—ī¸Strategy Builder
      • Building Blocks User Guide
        • Lend
        • Borrow
        • Swap
        • Flash Loan
    • 📜Studio Contracts
      • Leverage
        • FactorLeverageDescriptor.sol
        • FactorLeverageVault.sol
        • WrapperFactorLeverageVault.sol
      • LP Management
        • FactorLPVault.sol
        • FactorLPDescriptor.sol
  • Factor SDK
    • đŸ“ĻFactor SDK
    • â†”ī¸REST APIs
      • Utility APIs
        • Pricing
        • Stats
  • Factor Building Blocks
    • 🧱Factor Building Blocks
    • âžĄī¸Lend
    • âŦ…ī¸Borrow
    • 🔄Leverage
      • Concepts
        • Collateralized Lending & Borrowing
        • Looping
      • Leverage Dev Guides
        • Create Leveraged Position
        • Add Leverage To Position
      • Strategy Contracts
        • AAVEV3LeverageStrategy.sol
        • CompoundLeverageStrategy.sol
        • LodeStarLeverageStrategy.sol
        • RadiantLeverageStrategy.sol
        • SiloLeverageStrategy.sol
        • SiloYieldTokenStrategy.sol
        • TenderLeverageStrategy.sol
      • FAQ - Leverage Building Block
    • 💰Yield
      • Concepts
        • Yield Farming
        • Yield Aggregators
      • ⚡Zap
    • 🌊LP Management
      • Concepts
        • Automated Market Maker
        • Concentrated Liquidity
    • đŸĨŠStake
    • 🔀Swap
      • Concepts
        • Market Orders
        • DEX Aggregators
    • đŸĒ„Flash Loan
      • Concepts
        • Uncollateralized Lending & Borrowing
        • Flash Loan
  • Factor Adapters
    • 🔌Factor Adapters
    • 📜Adapter Contracts
      • Leverage
      • Yield
      • Swap
      • Flash Loan
  • Governance
    • đŸ›ī¸FactorDAO
      • Factor Flywheel
      • Factor Participants
      • Governance Incentive Calculations
        • FactorDAO Incentives Model (LTIPP)
      • User Guides
        • Stake FCTR
        • Governance Migration
      • Contracts
        • FactorDAO Contract Addresses
      • FactorDAO Multisig Addresses
      • Platform Fees
    • đŸĒ™FCTR Token
      • Staking and Governance
      • Tokenomics
      • Contract Addresses
      • FAQ - Tokenomics
    • âš–ī¸Factor Scale
      • Arbitrum Foundation LTIPP
      • Emission Multiplier Calculations
        • Emissions Multiplier Model
      • User Guides
        • Stake FCTR
        • Vote On Emissions Distribution
      • Contracts
        • Factor Scale Contract Addresses
      • ❔FAQ - Factor Scale
    • 🚀Factor Boost
      • Contracts
        • Factor Boost Contract Addresses
    • đŸ’ŧFactor Bribes
      • Contracts
        • Factor Bribes Contracts
  • Security
    • đŸ›Ąī¸Security
    • 📋Audits
      • PeckShield
        • Leverage Vault Wrapper
        • Silo Yield
        • Silo Leverage
        • Penpie
        • Factor Boost
      • SourceHat
        • FactorDAO Vaults
        • FCTR & Voting Escrow
  • Reference
    • Discover Pro dApp
    • Studio dApp
    • Discover dApp
    • Official Website
    • Press Kit
    • Partnership Form
    • Media Kit
    • Geo Restrictions
  • Community
    • Factor Contributors
    • X
    • Discord
    • Telegram
    • Medium
    • Email Enquiries
Powered by GitBook
On this page
  • Properties
  • Public
  • Events
  • PositionCreated()
  • AssetChanged()
  • DebtChanged()
  • UpgradeRegistered()
  • UpgradeRemoved()
  • DescriptorChanged()
  • Constructor
  • Methods
  • initialize() - public initializer
  • createPosition() - external returns
  • updateAsset() - external onlyOwner
  • updateDebt() - external onlyOwner
  • burnPosition() - external
  • tokenURI() - public view override returns
  • setDescriptor() - external onlyOwner
  • isRegisteredUpgrade() - external view returns
  • registerUpgrade() - external onlyOwner
  • removeUpgrade() - external onlyOwner
  • updateImplementation() - external onlyOwner
  • setFeeRecipient() - external onlyOwner
  • setLeverageFee() - external onlyOwner
  • setClaimRewardFee() - external onlyOwner
  • version() - external pure returns
  • _increaseBalance() - internal virtual override
  • _update() - internal virtual override returns
  • supportsInterface() - public view override returns

Was this helpful?

  1. Factor Studio
  2. Studio Contracts
  3. Leverage

FactorLeverageVault.sol

PreviousFactorLeverageDescriptor.solNextWrapperFactorLeverageVault.sol

Last updated 1 year ago

Was this helpful?

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 . 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 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

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 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

Argument
Type
Description

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

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 msg.sender (i.e. depositor) that deposited into the vault.

Constructor

Methods

initialize() - 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

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 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

Events
Description

Emits the currentPositionId and the implemented strategy address.

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 asset lending pool to be changed to.

Events

Events
Description

Emits the address of the newly configured lending pool tied to the Leverage Vault's asset.

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 debt lending pool to be changed to.

Events

Events
Description

Emits the address of the newly configured lending pool tied to the Leverage Vault's debt.

burnPosition() - 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

Returns the encoded Uniform Resource Identifier (URI) of the position id that is being queried.

Parameters

Params
Type
Description

id

uint256

The positionId of the position whose URI data is being queried.

Returns

Type
Description

string

The encoded URI for the token representing the position in the leverage vault.

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

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

true = Proposed strategy has been registered by owner. false = Proposed strategy has not been registered by owner.

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.

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.

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.

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.

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.

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

Returns the Leverage Vault version which is hardcoded based on contract deployment.

Returns

Type
Description

string

The Leverage Vault version.

_increaseBalance() - internal virtual override

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 account balances.

_update() - internal virtual override returns

Parameters

Params
Type
Description

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

Type
Description

address

The address of the LP Vault NFT (representing the position) before the update.

supportsInterface() - public view override returns

Parameters

Params
Type
Description

interfaceId

bytes4

The encoded bytes data representing the interface being queried.

Returns

Type
Description

bool

true = interfaceId is supported by the Leverage Vault contract false = interfaceId is not supported by the Leverage Vault contract

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 .

updateAsset() - external

updateDebt() - external

setDescriptor() - external

registerUpgrade() - external

removeUpgrade() - external

updateImplementation() - external

setFeeRecipient() - external

setLeverageFee() - external

setClaimRewardFee() - external

An internal function that overrides the ERC721 function meant to increase the number of NFT collection tokens held by the account.

An internal function that overrides the ERC721 function meant to update the owner of the tokenId.

An internal function that overrides the ERC721 function that returns true if this Leverage Vault contract implements the interface defined by interfaceId.

📜
OpenZeppelin's upgradeable proxy pattern
OpenZeppelin Docs
onlyOwner
onlyOwner
onlyOwner
onlyOwner
onlyOwner
onlyOwner
onlyOwner
onlyOwner
onlyOwner
_increaseBalance()
_update()
supportsInterface()
PositionCreated()
AssetChaged()
DebtChanged()
DescriptorChanged()
UpgradeRegistered()
UpgradeRemoved()