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
  • LeverageAdded()
  • LeverageRemoved()
  • LeverageClosed()
  • Stake()
  • CreatePosition()
  • UnStake()
  • Withdraw()
  • UpdateBalance()
  • Repay()
  • Supply()
  • UpgradeStrategy()
  • Structs
  • InitParams
  • Constructor
  • Methods
  • initialize() - public initializer
  • transferFrom() - public virtual override
  • stakePosition() - external nonReentrant
  • createPosition() - external nonReentrant returns
  • unstakePosition() - external nonReentrant
  • addLeverage() - external nonReentrant
  • supply() - external nonReentrant
  • removeLeverage() - external nonReentrant
  • _operationAugmented() - internal
  • updateBalance() - external nonReentrant
  • closeLeverage() - external onlyOwner
  • withdraw() - external nonReentrant
  • repay() - external onlyOwner
  • _beforeTokenTransfer() - internal override
  • _afterTokenTransfer() - internal override
  • _stakedBalance() - internal view override
  • _totalStaked() - internal view override
  • tokenURI() - public view virtual override returns
  • redeemRewards() - public nonReentrant returns
  • getRewardTokens() - external view returns
  • claimRewards() - external nonReentrant
  • upgradeStrategy() - public

Was this helpful?

  1. Factor Studio
  2. Studio Contracts
  3. Leverage

WrapperFactorLeverageVault.sol

PreviousFactorLeverageVault.solNextLP Management

Last updated 1 year ago

Was this helpful?

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

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 .

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

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

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

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

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

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 debt that was repaid.

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 asset supplied to the position.

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

_veFctr

address

_gaugeController

address

The address of the Factor Gauge Controller contract.

_boostController

address

_rewardDuration

uint256

Constructor

Methods

initialize() - public initializer

The contract initialization function which initializes the contract with the underlying Leverage Vault configurations as well as the Factor ecosystem contract addresses.

Parameters

Params
Type
Description

initParams

Memory data that contains the initialization data for the wrapper vault.

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

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

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

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

Allows the position owner to add leverage towards their specified positionId.

  • Transfers the specified amount of asset from msg.sender (i.e. user) to the Wrapper Vault contract

  • Adds leverage to the provided positionId by calling addLeverage() from the implemented Strategy contract

  • Updates the Wrapper Vault balances which is being tracked via the ERC20Augmented token

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

Events
Description

Emits the results of the leverage addition.

supply() - 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 asset is being supplied.

amount

uint256

The amount of asset to be supplied as collateral for the position.

Events

Events
Description

Emits the result of the supply which includes the address of the corresponding Strategy contract.

removeLeverage() - external nonReentrant

Allows the position owner to remove leverage from their specified positionId.

  • Removes the specified amount of asset by calling removeLeverage() from the implemented Strategy contract

  • Transfer the removed asset amount to the msg.sender (i.e. user)

  • Updates the Wrapper Vault balances which is being tracked via the ERC20Augmented token

  • Updates 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 asset being removed.

data

bytes

The Balancer userData which in this context is used for pool-specific instructions needed to do the calculations.

Events

Events
Description

Emits the results of the leverage removal.

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

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

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 calling closeLeverage() from the implemented Strategy contract

  • Transfers the asset and debt from the closed position to the msg.sender (i.e. owner)

  • Updates the Wrapper Vault balances which is being tracked via the ERC20Augmented token

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

Events
Description

Emits the results of the leverage position closure.

withdraw() - 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 asset that will be withdrawn.

Events

Events
Description

Emits the withdrawal details.

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 debt to be repaid.

Events

Events
Description

Emits the amount of debt that was repaid as well as the Strategy contract address.

_beforeTokenTransfer() - internal override

Parameters

Params
Type
Description

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

An internal function that updates the msg.sender's active balance in the gauge.

Parameters

Params
Type
Description

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

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

Returns

Type
Description

uint256

The amount of underlying Leverage Vault tokens staked.

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

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

uint256

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

redeemRewards() - public nonReentrant returns

Parameters

Params
Type
Description

user

address

The address of the user that has accured rewards.

Returns

Type
Description

uint256[]

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

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

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.

The address of the underlying Factor vault that is wrapped by this contract (i.e. deployed address)

The address of the contract.

The address of the Controller contract.

The reward duration which the rewards for this wrapper vault will be initalized with.

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 .

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 contracts are also initialized for the Leverage Vault.

repay() - external

An internal function that updates and rewards prior to a related token transfer.

Enables stakers to claim their accrued rewards.

An array containing the amount of reward tokens redeemed, in the same order as .

📜
Factor Scale
Factor Boost
OpenZeppelin's upgradeable proxy pattern
OpenZeppelin Docs
Factor Boost
Factor Scale
Factor Boost
Factor Scale
onlyOwner
FactorVault.sol
Factor Boost
Factor Boost
InitParams
Stake()
CreatePosition()
UnStake()
LeverageAdded()
Supply()
LeverageRemoved()
UpdateBalance()
LeverageClosed()
Withdraw()
Repay()
getRewardTokens()
UpgradeStrategy()
veFCTR