SiloYieldTokenStrategy.sol

Properties

PropertyTypeModifierDescription

provider

address

public; constant

The address of the Silo Repository contract.

siloIncentive

address

public; constant

The address of the Silo Rewards contract.

siloToken

address

public; constant

The address of the SILO token.

siloLens

address

public; constant

The address of the Silo Lens contract.

ptweETH

address

public; constant

The address of ether.fi's wrapped eETH PT token on Pendle.

pendleRouterV3

address

public; constant

The address of Pendle's Router contract.

weETH

address

public; constant

balancerVault

address

public; constant

The address of the Balancer Vault contract (to facilitate flash loans).

uniswapV3Pool

address

public; constant

The address of the UniswapV3 Pool contract.

weth

address

public; constant

The address of the WETH token.

_positionId

uint256

private

The identifier for the strategy position that is maintained by the Factor Leverage Vault.

_vaultManager

IERC721

private

The address of the Vault Manager contract which facilitates vault admin operations (the underlying Leverage Vault contract in this instance).

_asset

IERC20

private

The address of the asset token (i.e. collateral and token being levered).

_debtToken

IERC20

private

The address of the debt token (i.e. borrow asset for flash loan).

_assetPool

IERC20

public

The address of the asset lending pool.

_debtPool

IERC20

public

The address of the debt lending pool.

flMode

uint8

private

The flash loan mode used to determine the relevant operations to receive the flash loan:

1 = addLeverage 2 = removeLeverage 3 = switchAsset 4 = switchDebt 5 = closeLeverage

Events

LeverageAdded()

Emitted when leverage is added to the position (i.e. this Leverage Strategy contract).

Arguments

ArgumentTypeDescription

amount

uint256

The amount of asset that was supplied to the lending pool.

debt

uint256

The amount of debt that was taken out as a flash loan denominated in _debtToken.

LeverageRemoved()

Emitted when leverage is removed from the leveraged position (i.e. this Leverage Strategy contract).

Arguments

ArgumentTypeDescription

debt

uint256

The amount of debt that was repaid.

LeverageClosed()

Emitted when the leveraged position is closed (i.e. fully repaid).

Arguments

ArgumentTypeDescription

amount

uint256

The amount of asset that was returned after closing the position.

debt

uint256

The amount of debt that was returned after closing the position.

Withdraw()

Emitted when asset is withdrawn from the Silo lending pool.

Arguments

ArgumentTypeDescription

amount

uint256

The amount of asset withdrawn from the Silo lending pool.

Repay()

Emitted when the Silo lending pool debt is repaid.

Arguments

ArgumentTypeDescription

amount

uint256

The amount of debt that was repaid.

Supply()

Emitted when asset is supplied to the Silo lending pool.

Arguments

ArgumentTypeDescription

amount

uint256

The amount of asset supplied to the Silo lending pool.

Borrow()

Emitted when debt is borrowed from the Silo lending pool (which collateralizes the provided asset).

Arguments

ArgumentTypeDescription

amount

uint256

The amount of debt that was borrowed from the Silo lending pool.

WithdrawTokenInCaseStuck()

Emitted when stuck tokens are withdrawn from the Strategy contract.

Arguments

ArgumentTypeDescription

tokenAddress

address

The address of the token to be withdrawn.

amount

uint256

The amount of asset withdrawn from the Silo lending pool.

RewardClaimed()

Emitted when Silo rewards are claimed token and transferred to the msg.sender (i.e. user).

Arguments

ArgumentTypeDescription

amount

uint256

The amount of rewards claimed denominated in token.

token

address

The address of the token which was claimed.

RewardClaimedSupply()

Emitted when Silo rewards are claimed as token and supplied as collateral to the asset lending pool.

Arguments

ArgumentTypeDescription

amount

uint256

The amount of rewards claimed denominated in token.

token

address

The address of the token which was claimed.

RewardClaimedRepay()

Emitted when Silo rewards are claimed as token and repaid as debt to the debt lending pool.

Arguments

ArgumentTypeDescription

amount

uint256

The amount of rewards claimed denominated in token.

token

address

The address of the token which was claimed.

LeverageChargeFee()

Emitted when a leverage fee is charged.

Arguments

ArgumentTypeDescription

amount

uint256

The leverage fee charged denominated in token.

Constructor

Factor Strategy contracts implements OpenZeppelin's upgradeable contracts design and locks the strategy contract upon initialization to avoid contract takeover by an attacker. More info can be found on OpenZeppelin Docs.

Modifiers

onlyOwner()

Checks if the msg.sender address is equal to the owner of the position as maintained by the Leverage Vault contract.

Methods

initialize() - public initializer

Initializes the Strategy contract with the __positionId and initial address configurations.

Parameters

ParamsTypeDescription

__positionId

uint256

The identifier of the leveraged position as maintained by the underlying Leverage Vault contract.

_vaultManagerAddress

address

The address of the Vault Manager contract (the underlying Leverage Vault contract in this instance).

_assetAddress

address

The address of the Strategy's asset token (i.e. collateral and token being levered).

_debtAddress

address

The address of the Strategy's debt token (i.e. borrow asset for flash loan).

_assetPoolAddress

address

The address of the asset lending pool.

_debtPoolAddress

address

The address of the debt lending pool.

vaultManager() - public view returns

Returns the address of the Factor Vault Manager contract which contains vault admin functions (e.g. upgrade strategy, set fees, etc.).

Returns

TypeDescription

address

The address of the Factor Vault Manager.

positionId() - public view returns

Returns the position identifier maintained by the underlying Leverage Vault contract. Each strategy implementation (such as this contract) is tied to a positionId.

Returns

TypeDescription

uint256

The identifier of the position on the underlying Leverage Vault contract.

asset() - public view returns

Returns the address of the token configured as the main asset for this leverage Strategy contract(i.e. collateralized asset).

Returns

TypeDescription

address

The address of the Strategy's _asset.

getAssetTokens() - public view returns

Returns all asset tokens associated with the Silo lending pool, including both collateral and debt tokens (calls Silo's getAssetsWithState()).

Returns

TypeDescription

address[]

An array of addresses associated with the pool, where the first half contains collateral tokens and the second half contains debt tokens.

debtToken() - public view returns

Returns the address of the debt token which is used for taking out a flash loan (i.e. borrow token) for this Strategy contract.

Returns

TypeDescription

address

The address of the Strategy's _debtToken .

assetPool() - public view returns

Returns the address of the Silo lending pool where the _asset is being collateralized.

Returns

TypeDescription

address

The address of the Strategy's _assetPool.

debtPool() - public view returns

Returns the address of the Silo lending pool where the _debtToken was borrowed from.

Returns

TypeDescription

address

The address of the Strategy's _debtPool.

assetBalance() - public view returns

Returns the total collateralized balance (i.e. _asset supplied) of the Strategy contract that is held by the Silo lending pool.

Returns

TypeDescription

uint256

The total _asset supplied to the Silo lending pool.

debtBalance() - public view returns

Returns the outstanding debt balance (i.e. _debtToken borrowed) which the Strategy contract owes to the Silo lending contract.

Returns

TypeDescription

uint256

The total _debtToken that needs to be repaid to the Silo lending pool.

owner() - public view returns

Returns the address of the owner of the leveraged position.

Returns

TypeDescription

address

The address of the owner of the position.

addLeverage() - external onlyOwner

Adds leverage to a position by executing the following:

  1. Transfer asset from owner to the Strategy contract

  2. Supply asset to the Silo pool

  3. If debt is specified, executes a flash loan to borrow configured debt amount on Balancer vault

  4. Balancer vault calls receiveFlashLoan() to trigger flash swap and flash loan debt repayment via _flAddLeverage()

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

amount

uint256

The amount of _asset being supplied.

debt

uint256

The amount of _debtToken to be flash loaned.

data

bytes

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

Events

EventsDescription

Emits the results of the leverage addition.

_flAddLeverage() - internal

An internal function which is meant to be called by the Balancer vault contract which repays the flash loan on Balancer by borrowing debt against the new asset collateralized amount on Silo.

  1. If asset is ptweETH

    1. Swap debt to weETH

    2. Deposit weETH into Pendle Earn and get ptweETH

  2. Else swap debt for asset (via swapBySelf())

  3. Supply asset to the Silo pool (i.e. increase total collateral value)

  4. Borrow _debtToken from the Silo pool to repay Balancer flash loan

  5. Repay the Balancer flash loan

Parameters

ParamsTypeDescription

params

bytes

Encoded bytes data which consists of: amount = The number of _debtToken that was flash loaned. poolAddress = The address of the corresponding Silo lending pool. data = The Balancer userData.

feeAmount

uint256

The flash loan fee amount to be repaid denominated in _debtToken.

removeLeverage() - external onlyOwner

Removes a specified amount of leverage from the Strategy contract by executing the following:

  1. Query the outstanding debt on the Silo lending pool including accrued interest

  2. Executes a flash loan to borrow debt from the Balancer vault equivalent to the outstanding debt on the Silo pool

  3. Balancer vault calls receiveFlashLoan() to trigger flash swap and flash loan debt repayment via _flRemoveLeverage()

  4. Transfer withdrawn asset to the owner

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

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

EventsDescription

Emits the results of the leverage removal.

_flRemoveLeverage() - internal

An internal function which is meant to be called by the Balancer vault contract which repays the flash loan on Balancer by withdrawing asset from the Silo lending pool.

  1. Repays all of the outstanding debt on Silo

  2. Withdraws the specified amount of asset (as per removeLeverage())

  3. If asset is ptweETH

    1. Withdraw ptweETH to get weETH

    2. Swap weETH for debt

  4. Else swap the withdrawn asset for debt (via swapBySelf())

  5. Calculates the remaining Balancer flash loan debt outstanding

  6. Borrow the oustanding flash loan debt amount (including fees) from Silo lending pool

  7. Repay the Balancer flash loan

Parameters

ParamsTypeDescription

params

bytes

Encoded bytes data which consists of: amount = The number of _asset that is being removed from the Strategy contract. repayAmount = The number of _debt that is being repaid to the Silo lending pool (includes accrued interest) poolAddress = The address of the corresponding Silo lending pool. data = The Balancer userData.

feeAmount

uint256

The flash loan fee amount to be repaid denominated in _debtToken.

closeLeverage() - external onlyOwner

Closes the leveraged position and transfers the remaining asset and debt amounts to the owner. If the asset amount specified is greater than the debt value, the position value will be returned in debt tokens.

  1. Query the outstanding debt on the Silo lending pool including accrued interest

  2. Executes a flash loan to borrow existing debt from the Balancer vault equivalent to the outstanding debt on the Silo lending pool

  3. Balancer vault calls receiveFlashLoan() to trigger flash swap and flash loan debt repayment via _flCloseLeverage()

  4. Transfers the remaining asset and debt tokens to the owner (i.e. depositor)

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

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

EventsDescription

Emits the results of the leverage position closure.

_flCloseLeverage() - internal

An internal function which is meant to be called by the Balancer vault contract which switches the debt of the leveraged position with a provided newDebtToken.

  1. Repays all of the outstanding debt on Silo

  2. Withdraws all of the asset from the existing position on Silo

  3. If asset is ptweETH

    1. Withdraw ptweETH on Pendle for weETH

    2. Swap weETH for debt

  4. Else swap the specified amount of asset (per closeLeverage()) for debt (via swapBySelf())

  5. Repay the Balancer flash loan using the acquired debt

Parameters

ParamsTypeDescription

params

bytes

Encoded bytes data which consists of: amount = The number of asset that is swapped for debt repayAmount = The number of _debt that is being repaid to the Silo lending pool (includes accrued interest) poolAddress = The address of the corresponding Silo lending pool. data = The Balancer userData.

feeAmount

uint256

The flash loan fee amount to be repaid denominated in the old debt.

swapBySelf() - public returns

Allows the msg.sender to conduct a swap via the OpenOcean aggregator.

Parameters

ParamsTypeDescription

tokenIn

address

The address of the token being swapped from.

tokenOut

address

The address of the token being swapped to.

amount

uint256

The amount of tokenIn being swapped.

data

bytes

The bytes data which consists of the swap method and params.

Returns

TypeDescription

uint256

The amount of tokenOut resulting from the swap minus the leverage strategy fees.

swapUniswap() - public returns

Allows the msg.sender to conduct a swap via the the UniswapV3 router.

Parameters

ParamsTypeDescription

tokenIn

address

The address of the token being swapped from.

tokenOut

address

The address of the token being swapped to.

amount

uint256

The amount of tokenIn being swapped.

amountOutMinimum

uint256

The minimum of tokenOut from the swap else the transaction reverts.

Returns

TypeDescription

uint256

The amount of tokenOut resulting from the swap minus the leverage strategy fees.

leverageFeeCharge() - internal returns

Charges the fee for the leverage strategy and transfers the fee to the fee recipient. The fee configs are maintained by the Vault Manager contract.

Parameters

ParamsTypeDescription

amount

uint256

The amount of token that was used for leverage.

token

address

The token which will be collected as fees (i.e. the tokenOut from swapBySelf()).

Events

EventsDescription

Emits the leverage fee that was charged.

Returns

TypeDescription

uint256

The leverage fee charged denominated in token.

_getRepayAmount() - internal view returns

Returns the total amount of debt to be repaid with accrued interest.

Parameters

ParamsTypeDescription

poolAddress

address

The address of the corresponding Silo lending pool where debt was borrowed.

Returns

TypeDescription

uint256

The debt owed rounded up to the nearest wei.

toAmountRoundUp() - internal pure returns

Rounds up the debt owed to the nearest wei.

Parameters

ParamsTypeDescription

share

uint256

The number of debt pool tokens (representing debt shares) owned by the Strategy contract.

totalAmount

uint256

The total debt borrowed from the Silo lending pool.

totalShares

uint256

The total number of debt pool tokens.

Returns

TypeDescription

uint256

The debt owed rounded up to the nearest wei.

getPoolAddress() - internal view returns

Returns the address of the Silo asset lending pool.

Returns

TypeDescription

uint256

The address of the Silo asset lending pool.

withdrawTokenInCaseStuck() - external onlyOwner

Enables the owner to withdraw any tokenAddress that is stuck in the Strategy contract.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

tokenAddress

address

The address of the token to withdraw.

amount

uint256

The amount of tokenAddress to be withdrawn.

Events

EventsDescription

Emits the amount of tokenAddress that was withdrawn as well as the tokenAddress.

supply() - external onlyOwner

Enables the owner to transfer strategy asset to the Silo reward pool. The Strategy contract will hold the ShareCollateralToken (representing collateralized assets) on behalf of the owner.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

amount

uint256

The amount of asset that was used for leverage.

Events

EventsDescription

Emits the amount of asset that was supplied.

borrow() - external onlyOwner

Enables the owner to utilize the collateralized asset in the Silo lending pool to borrow the specified amount of debt. The debt is transferred to the Strategy contract which is holding the debt on behalf of the owner.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

amount

uint256

The amount of debt to be borrowed.

Events

EventsDescription

Emits the amount of debt that was borrowed.

repay() - external onlyOwner

Enables the owner to repay a specified amount of the debt for a borrow position on the Silo lending pool. The debt is repaid on behalf of the Strategy contract which holds the owner's debt obligations.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

amount

uint256

The amount of debt to be repaid.

Events

EventsDescription

Emits the amount of debt that was repaid.

withdraw() - external onlyOwner

Enables the owner to withdraw a specified amount of asset from the Silo lending pool. The Strategy contract executes the withdrawal as it holds the ShareCollateralToken on behalf of the owner. The corresponding amount of asset is transferred to the owner address.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

amount

uint256

The amount of asset to be withdrawn.

Events

EventsDescription

Emits the amount of asset that was withdrawn.

claimRewards() - external onlyOwner

Allows the position owner to claim Silo rewards based on the provided rewardsToken.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

rewardsToken

address

The address of the Silo reward token.

Events

EventsDescription

Emits the reward token address and the amount of tokens transferred.

claimRewardsSupply() - external onlyOwner

Allows the position owner to claim Silo rewards based on the provided rewardsToken. The claimed rewards are then supplied as asset tokens to the relevant Silo lending pool.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

rewardsToken

address

The address of the Silo reward token.

amountOutMin

uint256

The minimum amount of asset received from swapping the claim rewards else the transaction reverts.

Events

EventsDescription

Emits the reward token address and the amount of tokens transferred.

claimRewardsRepay() - external onlyOwner

Allows the position owner to claim Silo rewards based on the provided rewardsToken. The claimed rewards are then supplied as debt tokens to the relevant Silo lending pool.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

rewardsToken

address

The address of the Silo reward token.

amountOutMin

uint256

The minimum amount of debt received from swapping the claim rewards else the transaction reverts.

Events

EventsDescription

Emits the reward token address and the amount of tokens transferred.

_claimRewards() - internal returns

An internal function which facilitates the claiming of Silo rewards and the conversion of reward value into asset (to increase collateral) or debt (to repay debt).

Parameters

ParamsTypeDescription

rewardsToken

address

The address of the Silo reward token.

assetTokens

address[]

The array of asset tokens associated with the lending pool

fee

uint256

The amount of fees to be charged. Scaled by feeScale.

feeScale

uint256

The scale used to calculate the actual fee amount.

feeRecipient

uint256

The address that receives the leverage strategy fees.

amountOutMin

uint256

The minimum amount of tokenOut received from the swap else the transaction reverts.

poolAddress

address

The address of the lending pool where asset/debt` will be supplied/repaid.

isRepay

bool

true = Claims rewards and repay debt false = Claims rewards and supply asset

_getIncentiveAddress() - internal pure returns

An internal function that returns the address of the Silo incentive contract (normal Silo incentives or STIP).

Parameters

ParamsTypeDescription

rewardsToken

address

The address of the Silo reward token.

Returns

TypeDescription

address

The address of the Silo incentive contract.

_getVaultDetails() - internal view returns

An internal function that returns the fee configurations for the leverage strategy vault.

Returns

TypeDescription

uint256

The amount of fees to be charged. Scaled by feeScale.

uint256

The scale used to calculate the actual fee amount.

address

The address that receives the leverage strategy fees.

_getVaultAnd PoolDetails() - internal view returns

An internal function that returns the fee configurations for the leverage strategy as well as the Silo asset lending pool address.

Returns

TypeDescription

uint256

The amount of fees to be charged. Scaled by feeScale.

uint256

The scale used to calculate the actual fee amount.

address

The address that receives the leverage strategy fees.

address

The Silo asset lending pool address.

version() - external pure returns

Returns the strategy version which is hardcoded based on contract deployment.

Returns

TypeDescription

string

The Strategy contract version.

receiveFlashLoan() - external override nonReentrant

An external function meant to be called by the Balancer vault contract to check the validity of the vault receiving the flash loan (i.e. can the flash loan be repaid). Reads the configured flMode at the time of execution to determine the correct operation to call.

Modifiers

ModifierDescription

nonReentrant

Ensures that there are no nested (reentrant calls). More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

tokens

address[]

The list of token addresses associated with the flash loan operations.

amounts

uint256[]

The amount of each token in tokens to be used for the flash loan operation. The order of each token amount must correspond with the order of the token address in tokens.

feeAmounts

uint256[]

The flash loan fee amount of each token in tokens to be used for the flash loan operation. The order of each token amount must correspond with the order of the token address in tokens.

params

bytes

The Balancer userData passed in as calldata.

_authorizeUpgrade() - internal view override onlyOnwer

An internal function that is meant to be called by the UUPSUpgradeable contract that checks if the new implementation is registered by the Factor Vault Manager.

Modifiers

ModifierDescription

onlyOwner

Ensures that only the specified owner of the contract is able to execute administrative tasks. More info on OpenZeppelin Docs.

Parameters

ParamsTypeDescription

newImplementation

address

The address of the proposed Strategy contract.

Last updated