SiloLeverageStrategy.sol
Silo Docs: https://devdocs.silo.finance/
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
public
initializer
Initializes the Strategy contract with the __positionId
and initial address configurations.
Parameters
vaultManager() - public
view
returns
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
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
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
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
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
public
view
returns
Returns the address of the Silo lending pool where the _asset
is being collateralized.
Returns
debtPool() - public
view
returns
public
view
returns
Returns the address of the Silo lending pool where the _debtToken
was borrowed from.
Returns
assetBalance() - public
view
returns
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
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
public
view
returns
Returns the address of the owner
of the leveraged position.
Returns
addLeverage() - external
onlyOwner
external
onlyOwner
Adds leverage to a position by executing the following:
Transfer
asset
fromowner
to the Strategy contractSupply
asset
to the Silo poolIf
debt
is specified, executes a flash loan to borrow configureddebt
amount on Balancer vaultBalancer vault calls
receiveFlashLoan()
to trigger flash swap and flash loan debt repayment via_flAddLeverage()
Modifiers
Parameters
Events
_flAddLeverage() - internal
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
forasset
(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 loanRepay the Balancer flash loan
Parameters
removeLeverage() - external
onlyOwner
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 interestExecutes a flash loan to borrow
debt
from the Balancer vault equivalent to the outstandingdebt
on the Silo poolBalancer vault calls
receiveFlashLoan()
to trigger flash swap and flash loan debt repayment via_flRemoveLeverage()
Transfer withdrawn
asset
to theowner
Modifiers
Parameters
Events
_flRemoveLeverage() - internal
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 SiloWithdraws the specified
amount
ofasset
(as perremoveLeverage()
)Swap the withdrawn
asset
fordebt
(via swapBySelf())Calculates the remaining Balancer flash loan
debt
outstandingBorrow the oustanding flash loan
debt
amount (including fees) from Silo lending poolRepay the Balancer flash loan
Parameters
switchAsset() - external
onlyOwner
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 interestExecutes a flash loan to borrow
debt
from the Balancer vault equivalent to the outstanding debt on the Silo lending poolBalancer 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
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 SiloWithdraws all of the
asset
from the existing position on SiloSwaps the specified
amount
(perswitchAsset()
) of the withdrawnasset
fornewAsset
(via swapBySelf())Change the Factor Strategy contract properties to align with the
newAsset
Supply the swapped
newAsset
to thenewAsset
Silo lending poolBorrow the initial
debt
balance from Silo using thenewAsset
as collateralRepay the Balancer flash loan
Parameters
Events
switchDebt() - external
onlyOwner
external
onlyOwner
Switches the debt
of the leverage position for a specified newDebtToken
.
Query the outstanding
debt
on the Silo lending pool including accrued interestExecutes a flash loan to borrow existing
debt
from the Balancer vault equivalent to the outstanding debt on the Silo lending poolBalancer 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
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 SiloChange the Factor Strategy contract properties to align with the
newDebtToken
Borrow the provided
newDebt
amount ofnewDebtToken
from the corresponding Silo pool using the untouched underlyingasset
as collateralSwaps the specified
newDebt
amount (perswitchDebt()
) of thenewDebtToken
for the previousdebt
token (via swapBySelf())Repay the Balancer flash loan using the acquired
debt
Parameters
Events
closeLeverage() - external
onlyOwner
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 interestExecutes a flash loan to borrow existing
debt
from the Balancer vault equivalent to the outstanding debt on the Silo lending poolBalancer vault calls
receiveFlashLoan()
to trigger flash swap and flash loan debt repayment via_flCloseLeverage()
Transfers the remaining
asset
anddebt
tokens to theowner
(i.e. depositor)
Modifiers
Parameters
Events
_flCloseLeverage() - internal
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 SiloWithdraws all of the
asset
from the existing position on SiloSwaps the specified
amount
ofasset
(percloseLeverage()
) fordebt
(via swapBySelf())Repay the Balancer flash loan using the acquired
debt
Parameters
swapBySelf() - public
returns
public
returns
Allows the msg.sender
to conduct a swap via the OpenOcean aggregator.
Parameters
Returns
leverageFeeCharge() - internal
returns
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
internal
view
returns
Returns the total amount of debt
to be repaid with accrued interest.
Parameters
Returns
toAmountRoundUp() - internal
pure
returns
internal
pure
returns
Rounds up the debt
owed to the nearest wei.
Parameters
Returns
supply() - external
onlyOwner
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
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
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
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
internal
view
returns
Returns the address of the Silo asset
lending pool.
Returns
withdrawTokenInCaseStuck() - external
onlyOwner
external
onlyOwner
Enables the owner
to withdraw any tokenAddress
that is stuck in the Strategy contract.
Modifiers
Parameters
Events
claimRewards() - external
onlyOwner
external
onlyOwner
Allows the position owner
to claim Silo rewards based on the provided rewardsToken
.
Modifiers
Parameters
claimRewardsSupply() - external
onlyOwner
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
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
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
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
internal
view
returns
An internal function that returns the fee configurations for the leverage strategy vault.
Returns
_getVaultAnd PoolDetails() - internal
view
returns
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
external
pure
returns
Returns the strategy version which is hardcoded based on contract deployment.
Returns
receiveFlashLoan() - external
override
nonReentrant
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
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