SiloLeverageStrategy.sol

Properties

Events

LeverageAdded()

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

Arguments

LeverageRemoved()

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

Arguments

LeverageClosed()

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

Arguments

AssetSwitched()

Emitted when the underlying collateral asset for the leveraged position is switched.

Arguments

DebtSwitched()

Emitted when the debt token for the leveraged position is switched.

Arguments

Withdraw()

Emitted when asset is withdrawn from the Silo lending pool.

Arguments

Repay()

Emitted when the Silo lending pool debt is repaid.

Arguments

Supply()

Emitted when asset is supplied to the Silo lending pool.

Arguments

Borrow()

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

Arguments

WithdrawTokenInCaseStuck()

Emitted when stuck tokens are withdrawn from the Strategy contract.

Arguments

RewardClaimed()

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

Arguments

RewardClaimedSupply()

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

Arguments

RewardClaimedRepay()

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

Arguments

LeverageChargeFee()

Emitted when a leverage fee is charged.

Arguments

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

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

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

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

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

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

assetPool() - public view returns

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

Returns

debtPool() - public view returns

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

Returns

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

debtBalance() - public view returns

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

Returns

owner() - public view returns

Returns the address of the owner of the leveraged position.

Returns

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

Parameters

Events

_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. Swap debt for asset (via swapBySelf())

  2. Supply newly acquired asset to the Silo pool (i.e. increase total collateral value)

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

  4. Repay the Balancer flash loan

Parameters

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

Parameters

Events

_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. Swap the withdrawn asset for debt (via swapBySelf())

  4. Calculates the remaining Balancer flash loan debt outstanding

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

  6. Repay the Balancer flash loan

Parameters

switchAsset() - external onlyOwner

Switches the position's underlying asset to a newly specified newAsset token.

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

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

Allowed New Asset Tokens

The newAsset address must have been registered by the Vault Manager. The list of approved debt tokens is maintained by the Leverage Vault contract.

Amount Validation

The Factor SDK provides convenience functions for the safe handling of the specified amount. By utilizing the Factor SDK, you can avoid spending gas on misconfigured amounts and minimize dust amounts from swaps.

Modifiers

Parameters

_flSwitchAsset() - internal

An internal function which is meant to be called by the Balancer vault contract which switches the asset collateralizing the leveraged position.

  1. Repays all of the outstanding debt on Silo

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

  3. Swaps the specified amount (per switchAsset()) of the withdrawn asset for newAsset (via swapBySelf())

  4. Change the Factor Strategy contract properties to align with the newAsset

  5. Supply the swapped newAsset to the newAsset Silo lending pool

  6. Borrow the initial debt balance from Silo using the newAsset as collateral

  7. Repay the Balancer flash loan

Parameters

Events

switchDebt() - external onlyOwner

Switches the debt of the leverage position for a specified newDebtToken.

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

Allowed New Debt Tokens

The newDebtToken address must have been registered by the Vault Manager. The list of approved debt tokens is maintained by the Leverage Vault contract.

Modifiers

Parameters

_flSwitchDebt() - internal

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

  1. Repays all of the outstanding debt on Silo

  2. Change the Factor Strategy contract properties to align with the newDebtToken

  3. Borrow the provided newDebt amount of newDebtToken from the corresponding Silo pool using the untouched underlying asset as collateral

  4. Swaps the specified newDebt amount (per switchDebt()) of the newDebtToken for the previous debt token (via swapBySelf())

  5. Repay the Balancer flash loan using the acquired debt

Parameters

Events

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

Parameters

Events

_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. Swaps the specified amount of asset (per closeLeverage()) for debt (via swapBySelf())

  4. Repay the Balancer flash loan using the acquired debt

Parameters

swapBySelf() - public returns

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

Parameters

Returns

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

Events

Returns

_getRepayAmount() - internal view returns

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

Parameters

Returns

toAmountRoundUp() - internal pure returns

Rounds up the debt owed to the nearest wei.

Parameters

Returns

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

Parameters

Events

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

Parameters

Events

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

Parameters

Events

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

Parameters

Events

getPoolAddress() - internal view returns

Returns the address of the Silo asset lending pool.

Returns

withdrawTokenInCaseStuck() - external onlyOwner

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

Modifiers

Parameters

Events

claimRewards() - external onlyOwner

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

Modifiers

Parameters

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

Parameters

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.

Parameters

_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

_getIncentiveAddress() - internal pure returns

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

Parameters

Returns

_getVaultDetails() - internal view returns

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

Returns

_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

version() - external pure returns

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

Returns

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

Parameters

_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

Parameters

Last updated