RadiantLeverageStrategy.sol
Last updated
Last updated
Radiant Docs: https://docs.radiant.capital/radiant
Property | Type | Modifier | Description |
---|---|---|---|
Emitted when leverage is added to the position (i.e. this Leverage Strategy contract).
Argument | Type | Description |
---|---|---|
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 Radiant lending pool.
Emitted when the Radiant lending pool debt
is repaid.
Emitted when asset
is supplied to the Radiant lending pool.
Emitted when debt
is borrowed from the Radiant lending pool (which collateralizes the provided asset
).
Emitted when stuck tokens are withdrawn from the Strategy contract.
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 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 Radiant lending pool where the _asset
is being collateralized.
Returns
public
view
returns
Returns the address of the Radiant 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 Radiant lending pool.
public
view
returns
Returns the outstanding debt balance (i.e. _debtToken
borrowed) which the Strategy contract owes to the Radiant 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 Radiant 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 Radiant.
Swap debt
for asset
(via swapBySelf())
Supply newly acquired asset
to the Radiant pool (i.e. increase total collateral value)
Borrow _debtToken
from the Radiant 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 Radiant lending pool
Executes a flash loan to borrow debt
from the Balancer vault equivalent to the outstanding debt
on the Radiant 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 Radiant lending pool.
Queries the outstanding debt
on the Radiant lending pool
Repays all of the outstanding debt
on Radiant
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 Radiant 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 Radiant lending pool
Executes a flash loan to borrow debt
from the Balancer vault equivalent to the outstanding debt on the Radiant vault
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.
Queries the outstanding debt
on the Radiant lending pool
Repays all of the outstanding debt
on Radiant
Withdraws all of the asset
from the existing position on Radiant
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
Radiant lending pool
Borrow the initial debt
balance from Radiant using the newAsset
as collateral
Repay the Balancer flash loan
external
onlyOwner
Switches the debt
of the leverage position for a specified newDebtToken
.
Executes a flash loan to borrow existing debt
from the Balancer vault equivalent to the outstanding debt on the Radiant 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
.
Queries the outstanding debt
on the Radiant lending pool
Repays all of the outstanding debt
on Radiant
Change the Factor Strategy contract properties to align with the newDebtToken
Borrow the provided newDebt
amount of newDebtToken
from the corresponding Radiant 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.
Executes a flash loan to borrow existing debt
from the Balancer vault equivalent to the outstanding debt on the Radiant 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
.
Queries the outstanding debt
on the Radiant lending pool
Repays all of the outstanding debt
on Radiant
Withdraws all of the asset
from the existing position on Radiant
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.
external
onlyOwner
Enables the owner
to transfer strategy asset
from the msg.sender
(i.e. depositor) to the Strategy contract which is then supplied to the Radiant lending pool. The Strategy contract will hold the rTokens representing collateralized assets) on behalf of the owner
.
external
onlyOwner
Enables the owner
to utilize the collateralized asset
in the Compound lending pool to borrow the specified amount
of debt
. The debt
is transferred to the msg.owner
(i.e. owner
) with the Strategy contract 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 Radiant 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 Radiant lending pool. The Strategy contract executes the withdrawal as it holds the rTokens on behalf of the owner
. The corresponding amount
of asset
is transferred to the owner
address.
external
onlyOwner
Enables the owner
to withdraw any tokenAddress
that is stuck in the Strategy contract.
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.
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Argument | Type | Description |
---|---|---|
Params | Type | Description |
---|---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Params | Type | Description |
---|---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Params | Type | Description |
---|---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Params | Type | Description |
---|---|---|
Params | Type | Description |
---|---|---|
Type | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Type | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Events | Description |
---|---|
Type | Description |
---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|
Modifier | Description |
---|---|
Params | Type | Description |
---|---|---|