Set Documentation
Search…
⌃K

PerpV2LeverageStrategy

Strategy smart contract that, when deployed, transform a SetToken into an on-chain leverage token that uses USDC as collateral. This extension is paired with the PerpV2LeverageModule from Set Protocol where module interactions are invoked via the IBaseManager contract. Any leveraged token can be constructed as long as the market is listed on Perp V2. This extension contract also allows the operator to set an ETH reward to incentivize keepers calling the rebalance function at different leverage thresholds.

Select Methods

engage()

function engage()
Operator only: Engage to target leverage ratio for the first time. SetToken will open a new base token position on PerpV2. Under the hood, perp would mint virtual quote assets (vUSDC) for SetToken and swap them for base token. If target leverage ratio is above max trade size, then TWAP is kicked off. To complete engage if TWAP, any valid caller must call iterateRebalance until target is met.
Note: Engage should be called after collateral has been deposited to PerpV2 using deposit().

rebalance()

function rebalance()
Allowed caller and EOA only: Rebalance product. If |min leverage ratio| < |current leverage ratio| < |max leverage ratio|, then rebalance can only be called once the rebalance interval has elapsed since last timestamp. If outside the max and min, rebalance can be called anytime to bring leverage ratio back to the max or min bounds. The methodology will determine whether to delever or lever.
Note: If the calculated current leverage ratio is above the incentivized leverage ratio or in TWAP then rebalance cannot be called. Instead, you must call ripcord() which is incentivized with a reward in Ether or iterateRebalance().

iterateRebalance()

function iterateRebalance()
Allowed caller and EOA only: Iterate a rebalance when in TWAP. TWAP cooldown period must have elapsed. If price moves advantageously, then exit without rebalancing and clear TWAP state. This function can only be called when |current leverage ratio| < |incentivized leverage ratio| and in TWAP state.

ripcord()

function ripcord()
EOA only: In case |current leverage ratio| > |incentivized leverage ratio|, the ripcord function can be called by anyone to return leverage ratio back to the max leverage ratio. This function typically would only be called during times of high downside/upside volatility and / or normal keeper malfunctions. The caller of ripcord() will receive a reward in Ether. The ripcord function uses its own TWAP cooldown period, slippage tolerance and TWAP max trade size which are typically looser than in regular rebalances.

deposit()

function deposit()
Operator only: Deposits specified units of current USDC tokens not already being used as collateral into Perpetual Protocol.
Parameter Name
Type
Description
_collateralUnits
uint256
Collateral to deposit in position units

withdraw()

function withdraw()
Operator only: Withdraws specified units of USDC tokens from Perpetual Protocol and adds it as default position on the SetToken
Parameter Name
Type
Description
_collateralUnits
uint256
Collateral to withdraw in position units

setMethodologySettings()

function setMethodologySettings()
Operator only: Set methodology settings and check new settings are valid. Note: Need to pass in existing parameters if only changing a few settings. Must not be in a rebalance.
Parameter Name
Type
Description
_newMethodologySettings
MethodologySettings
New Struct containing methodology parameters address

setExecutionSettings()

function setExecutionSettings()
Operator only: Set execution settings and check new settings are valid. Note: Need to pass in existing parameters if only changing a few settings. Must not be in a rebalance.
Parameter Name
Type
Description
_newExecutionSettings
ExecutionSettings
New Struct containing execution parameters

setIncentiveSettings()

function setIncentiveSettings()
Operator only: Set incentive settings and check new settings are valid. Note: Need to pass in existing parameters if only changing a few settings. Must not be in a rebalance.
Parameter Name
Type
Description
_newIncentiveSettings
IncentiveSettings
New Struct containing incentive parameters

setExchangeSettings()

function setExchangeSettings()
Operator only: Set exchange settings and check new settings are valid.Updating exchange settings during rebalances is allowed, as it is not possible to enter an unexpected state while doing so.
Note: Need to pass in existing parameters if only changing a few settings.
Parameter Name
Type
Description
_newExchangeSettings
ExchangeSettings
New Struct containing exchange settings

Select View Methods

getCurrentLeverageRatio()

function getCurrentLeverageRatio() view returns (int256)
Get current leverage ratio. Current leverage ratio is defined as the sum of USD values of all SetToken open positions on Perp V2 divided by its account value on PerpV2. Prices for base and quote asset are retrieved from the Chainlink Price Oracle.
Parameter Name
Type
Description
currentLeverageRatio
int256
Current leverage ratio in precise units (10e18)

shouldRebalance()

function shouldRebalance() view returns (ShouldRebalance)
Helper that checks if conditions are met for rebalance or ripcord.
Returns an enum with 0 = no rebalance, 1 = call rebalance(), 2 = call iterateRebalance(), 3 = call ripcord()
Return Name
Type
Description
shouldRebalance
ShouldRebalance
Enum representing whether should rebalance

shouldRebalanceWithBounds()

function shouldRebalance() view returns (ShouldRebalance)
Helper that checks if conditions are met for rebalance or ripcord with custom max and min bounds specified by caller. This function simplifies the logic for off-chain keeper bots to determine what threshold to call rebalance when leverage exceeds max or drops below min.
Returns an enum with 0 = no rebalance, 1 = call rebalance(), 2 = call iterateRebalance(), 3 = call ripcord()
Parameter Name
Type
Description
_customMinLeverageRatio
int256
Min leverage ratio passed in by caller
_customMaxLeverageRatio
int256
Max leverage ratio passed in by caller
Return Name
Type
Description
shouldRebalance
ShouldRebalance
Enum representing whether should rebalance