SiloLeverageStrategy.sol
Last updated
Last updated
Silo Docs: https://devdocs.silo.finance/
Property | Type | Modifier | Description |
---|---|---|---|
Emitted when leverage is added to the position (i.e. this Leverage Strategy contract).
Emitted when leverage is removed from the leveraged position (i.e. this Leverage Strategy contract).
Emitted when the leveraged position is closed (i.e. fully repaid).
Emitted when the underlying collateral asset for the leveraged position is switched.
Emitted when the debt token for the leveraged position is switched.
Emitted when asset
is withdrawn from the Silo lending pool.
Emitted when the Silo lending pool debt
is repaid.
Emitted when asset
is supplied to the Silo lending pool.
Emitted when debt
is borrowed from the Silo lending pool (which collateralizes the provided asset
).
Emitted when stuck tokens are withdrawn from the Strategy contract.
Emitted when Silo rewards are claimed token
and transferred to the msg.sender
(i.e. user).
Emitted when Silo rewards are claimed as token
and supplied as collateral to the asset
lending pool.
Emitted when Silo rewards are claimed as token
and repaid as debt
to the debt
lending pool.
Emitted when a leverage fee is charged.
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.
Checks if the msg.sender
address is equal to the owner
of the position as maintained by the Leverage Vault contract.
public
initializer
Initializes the Strategy contract with the __positionId
and initial address configurations.
public
view
returns
Returns the address of the Factor Vault Manager contract which contains vault admin functions (e.g. upgrade strategy, set fees, etc.).
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
.
public
view
returns
Returns the address of the token configured as the main asset for this leverage Strategy contract (i.e. collateralized asset).
public
view
returns
Returns all asset tokens associated with the Silo lending pool, including both collateral and debt tokens (calls Silo's getAssetsWithState()).
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.
public
view
returns
Returns the address of the Silo lending pool where the _asset
is being collateralized.
public
view
returns
Returns the address of the Silo lending pool where the _debtToken
was borrowed from.
public
view
returns
Returns the total collateralized balance (i.e. _asset
supplied) of the Strategy contract that is held by the Silo lending pool.
public
view
returns
Returns the outstanding debt balance (i.e. _debtToken
borrowed) which the Strategy contract owes to the Silo lending contract.
public
view
returns
Returns the address of the owner
of the leveraged position.
external
onlyOwner
Adds leverage to a position by executing the following:
Transfer asset
from owner
to the Strategy contract
Supply asset
to the Silo pool
If debt
is specified, executes a flash loan to borrow configured debt
amount on Balancer vault
Balancer vault calls receiveFlashLoan()
to trigger flash swap and flash loan debt repayment via _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.
Swap debt
for asset
(via swapBySelf())
Supply newly acquired asset
to the Silo pool (i.e. increase total collateral value)
Borrow _debtToken
from the Silo pool to repay Balancer flash loan
Repay the Balancer flash loan
external
onlyOwner
Removes a specified amount of leverage from the Strategy contract by executing the following:
Query the outstanding debt
on the Silo lending pool including accrued interest
Executes a flash loan to borrow debt
from the Balancer vault equivalent to the outstanding debt
on the Silo pool
Balancer vault calls receiveFlashLoan()
to trigger flash swap and flash loan debt repayment via _flRemoveLeverage()
Transfer withdrawn asset
to the owner
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.
Repays all of the outstanding debt
on Silo
Withdraws the specified amount
of asset
(as per removeLeverage()
)
Swap the withdrawn asset
for debt
(via swapBySelf())
Calculates the remaining Balancer flash loan debt
outstanding
Borrow the oustanding flash loan debt
amount (including fees) from Silo lending pool
Repay the Balancer flash loan
external
onlyOwner
Switches the position's underlying asset
to a newly specified newAsset
token.
Query the outstanding debt
on the Silo lending pool including accrued interest
Executes a flash loan to borrow debt
from the Balancer vault equivalent to the outstanding debt on the Silo lending pool
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.
internal
An internal function which is meant to be called by the Balancer vault contract which switches the asset
collateralizing the leveraged position.
Repays all of the outstanding debt
on Silo
Withdraws all of the asset
from the existing position on Silo
Swaps the specified amount
(per switchAsset()
) of the withdrawn asset
for newAsset
(via swapBySelf())
Change the Factor Strategy contract properties to align with the newAsset
Supply the swapped newAsset
to the newAsset
Silo lending pool
Borrow the initial debt
balance from Silo using the newAsset
as collateral
Repay the Balancer flash loan
external
onlyOwner
Switches the debt
of the leverage position for a specified newDebtToken
.
Query the outstanding debt
on the Silo lending pool including accrued interest
Executes a flash loan to borrow existing debt
from the Balancer vault equivalent to the outstanding debt on the Silo lending pool
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.
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
.
Repays all of the outstanding debt
on Silo
Change the Factor Strategy contract properties to align with the newDebtToken
Borrow the provided newDebt
amount of newDebtToken
from the corresponding Silo pool using the untouched underlying asset
as collateral
Swaps the specified newDebt
amount (per switchDebt()
) of the newDebtToken
for the previous debt
token (via swapBySelf())
Repay the Balancer flash loan using the acquired debt
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.
Query the outstanding debt
on the Silo lending pool including accrued interest
Executes a flash loan to borrow existing debt
from the Balancer vault equivalent to the outstanding debt on the Silo lending pool
Balancer vault calls receiveFlashLoan()
to trigger flash swap and flash loan debt repayment via _flCloseLeverage()
Transfers the remaining asset
and debt
tokens to the owner
(i.e. depositor)
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
.
Repays all of the outstanding debt
on Silo
Withdraws all of the asset
from the existing position on Silo
Swaps the specified amount
of asset
(per closeLeverage()
) for debt
(via swapBySelf())
Repay the Balancer flash loan using the acquired debt
public
returns
Allows the msg.sender
to conduct a swap via the OpenOcean aggregator.
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.
internal
view
returns
Returns the total amount of debt
to be repaid with accrued interest.
internal
pure
returns
Rounds up the debt
owed to the nearest wei.
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
.
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
.
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.
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.
internal
view
returns
Returns the address of the Silo asset
lending pool.
external
onlyOwner
Enables the owner
to withdraw any tokenAddress
that is stuck in the Strategy contract.
external
onlyOwner
Allows the position owner
to claim Silo rewards based on the provided rewardsToken
.
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.
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.
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).
internal
pure
returns
An internal function that returns the address of the Silo incentive contract (normal Silo incentives or STIP).
internal
view
returns
An internal function that returns the fee configurations for the leverage strategy vault.
internal
view
returns
An internal function that returns the fee configurations for the leverage strategy as well as the Silo asset
lending pool address.
external
pure
returns
Returns the strategy version which is hardcoded based on contract deployment.
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.
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.