IRebalancer
Inherits: IBaseRebalancer, IRebalancerErrors, IRebalancerEvents, IRebalancerTypes
Functions
MULTIPLIER_FACTOR
Gets the value of the multiplier at 1x.
Also helps to normalize the result of multiplier calculations.
function MULTIPLIER_FACTOR() external view returns (uint256 factor_);
Returns
Name | Type | Description |
---|---|---|
factor_ | uint256 | The multiplier factor. |
MAX_ACTION_COOLDOWN
The maximum cooldown time between actions.
function MAX_ACTION_COOLDOWN() external view returns (uint256 cooldown_);
Returns
Name | Type | Description |
---|---|---|
cooldown_ | uint256 | The maximum cooldown time between actions. |
INITIATE_CLOSE_TYPEHASH
The EIP712 initiateClosePosition typehash.
By including this hash into the EIP712 message for this domain, this can be used together with ECDSA-recover to obtain the signer of a message.
function INITIATE_CLOSE_TYPEHASH() external view returns (bytes32 typehash_);
Returns
Name | Type | Description |
---|---|---|
typehash_ | bytes32 | The EIP712 initiateClosePosition typehash. |
MAX_CLOSE_DELAY
Gets the maximum amount of seconds to wait to execute a initiateClosePosition since a new rebalancer long position has been created.
function MAX_CLOSE_DELAY() external view returns (uint256 closeDelay_);
Returns
Name | Type | Description |
---|---|---|
closeDelay_ | uint256 | The max close delay value. |
getAsset
Returns the address of the asset used by the USDN protocol.
function getAsset() external view returns (IERC20Metadata asset_);
Returns
Name | Type | Description |
---|---|---|
asset_ | IERC20Metadata | The address of the asset used by the USDN protocol. |
getUsdnProtocol
Returns the address of the USDN protocol.
function getUsdnProtocol() external view returns (IUsdnProtocol protocol_);
Returns
Name | Type | Description |
---|---|---|
protocol_ | IUsdnProtocol | The address of the USDN protocol. |
getPositionVersion
Returns the version of the current position (0 means no position open).
function getPositionVersion() external view returns (uint128 version_);
Returns
Name | Type | Description |
---|---|---|
version_ | uint128 | The version of the current position. |
getPositionMaxLeverage
Returns the maximum leverage the rebalancer position can have.
In some edge cases during the calculation of the rebalancer position's tick, this value might be exceeded by a slight margin.
Returns the max leverage of the USDN Protocol if it's lower than the rebalancer's.
function getPositionMaxLeverage() external view returns (uint256 maxLeverage_);
Returns
Name | Type | Description |
---|---|---|
maxLeverage_ | uint256 | The maximum leverage. |
getPendingAssetsAmount
Returns the amount of assets deposited and waiting for the next version to be opened.
function getPendingAssetsAmount() external view returns (uint128 pendingAssetsAmount_);
Returns
Name | Type | Description |
---|---|---|
pendingAssetsAmount_ | uint128 | The amount of pending assets. |
getPositionData
Returns the data of the provided version of the position.
function getPositionData(uint128 version) external view returns (PositionData memory positionData_);
Parameters
Name | Type | Description |
---|---|---|
version | uint128 | The version of the position. |
Returns
Name | Type | Description |
---|---|---|
positionData_ | PositionData | The data for the provided version of the position. |
getTimeLimits
Gets the time limits for the action validation process.
function getTimeLimits() external view returns (TimeLimits memory timeLimits_);
Returns
Name | Type | Description |
---|---|---|
timeLimits_ | TimeLimits | The time limits. |
increaseAssetAllowance
Increases the allowance of assets for the USDN protocol spender by addAllowance
.
function increaseAssetAllowance(uint256 addAllowance) external;
Parameters
Name | Type | Description |
---|---|---|
addAllowance | uint256 | Amount to add to the allowance of the USDN Protocol. |
getLastLiquidatedVersion
Returns the version of the last position that got liquidated.
0 means no liquidated version yet.
function getLastLiquidatedVersion() external view returns (uint128 version_);
Returns
Name | Type | Description |
---|---|---|
version_ | uint128 | The version of the last position that got liquidated. |
getNonce
Gets the nonce a user can use to generate a delegation signature.
This is to prevent replay attacks when using an EIP712 delegation signature.
function getNonce(address user) external view returns (uint256 nonce_);
Parameters
Name | Type | Description |
---|---|---|
user | address | The user address of the deposited amount in the rebalancer. |
Returns
Name | Type | Description |
---|---|---|
nonce_ | uint256 | The user's nonce. |
domainSeparatorV4
Gets the domain separator v4 used for EIP-712 signatures.
function domainSeparatorV4() external view returns (bytes32 domainSeparator_);
Returns
Name | Type | Description |
---|---|---|
domainSeparator_ | bytes32 | The domain separator v4. |
getCloseLockedUntil
Gets the timestamp by which a user must wait to perform a initiateClosePosition.
function getCloseLockedUntil() external view returns (uint256 timestamp_);
Returns
Name | Type | Description |
---|---|---|
timestamp_ | uint256 | The timestamp until which the position cannot be closed. |
initiateDepositAssets
Deposits assets into this contract to be included in the next position after validation
The user must call validateDepositAssets between _timeLimits.validationDelay
and.
_timeLimits.validationDeadline
seconds after this action.
function initiateDepositAssets(uint88 amount, address to) external;
Parameters
Name | Type | Description |
---|---|---|
amount | uint88 | The amount in assets that will be deposited into the rebalancer. |
to | address | The address which will need to validate and which will own the position. |
validateDepositAssets
Validates a deposit to be included in the next position version.
The to
from the initiateDepositAssets
must call this function between _timeLimits.validationDelay
and
_timeLimits.validationDeadline
seconds after the initiate action. After that, the user must wait until
_timeLimits.actionCooldown
seconds has elapsed, and then can call resetDepositAssets
to retrieve their
assets.
function validateDepositAssets() external;
resetDepositAssets
Retrieves the assets for a failed deposit due to waiting too long before calling validateDepositAssets.
The user must wait _timeLimits.actionCooldown
since the initiateDepositAssets before calling this
function.
function resetDepositAssets() external;
initiateWithdrawAssets
Withdraws assets that were not yet included in a position.
The user must call validateWithdrawAssets between _timeLimits.validationDelay
and
_timeLimits.validationDeadline
seconds after this action.
function initiateWithdrawAssets() external;
validateWithdrawAssets
Validates a withdrawal of assets that were not yet included in a position.
The user must call this function between _timeLimits.validationDelay
and _timeLimits.validationDeadline
seconds after initiateWithdrawAssets. After that, the user must wait until the cooldown has elapsed, and then
can call initiateWithdrawAssets again or wait to be included in the next position.
function validateWithdrawAssets(uint88 amount, address to) external;
Parameters
Name | Type | Description |
---|---|---|
amount | uint88 | The amount of assets to withdraw. |
to | address | The recipient of the assets. |
initiateClosePosition
Closes the provided amount from the current rebalancer's position.
The rebalancer allows partially closing its position to withdraw the user's assets + PnL.
The remaining amount needs to be above _minAssetDeposit
. The validator is always the msg.sender
, which means
the user must call validateClosePosition
on the protocol side after calling this function.
function initiateClosePosition(
uint88 amount,
address to,
address payable validator,
uint256 userMinPrice,
uint256 deadline,
bytes calldata currentPriceData,
Types.PreviousActionsData calldata previousActionsData,
bytes calldata delegationData
) external payable returns (Types.LongActionOutcome outcome_);
Parameters
Name | Type | Description |
---|---|---|
amount | uint88 | The amount to close relative to the amount deposited. |
to | address | The recipient of the assets. |
validator | address payable | The address that should validate the open position. |
userMinPrice | uint256 | The minimum price at which the position can be closed. |
deadline | uint256 | The deadline of the close position to be initiated. |
currentPriceData | bytes | The current price data. |
previousActionsData | Types.PreviousActionsData | The data needed to validate actionable pending actions. |
delegationData | bytes | An optional delegation data that include the depositOwner and an EIP712 signature to provide when closing a position on the owner's behalf. If used, it needs to be encoded with abi.encode(depositOwner, abi.encodePacked(r, s, v)) . |
Returns
Name | Type | Description |
---|---|---|
outcome_ | Types.LongActionOutcome | The outcome of the UsdnProtocol's initiateClosePosition call, check initiateClosePosition for more details. |
setPositionMaxLeverage
Updates the max leverage a position can have.
newMaxLeverage
must be between the min and max leverage of the USDN protocol.
This function can only be called by the owner of the contract.
function setPositionMaxLeverage(uint256 newMaxLeverage) external;
Parameters
Name | Type | Description |
---|---|---|
newMaxLeverage | uint256 | The new max leverage. |
setTimeLimits
Sets the various time limits in seconds.
This function can only be called by the owner of the contract.
function setTimeLimits(uint64 validationDelay, uint64 validationDeadline, uint64 actionCooldown, uint64 closeDelay)
external;
Parameters
Name | Type | Description |
---|---|---|
validationDelay | uint64 | The amount of time to wait before an initiate can be validated. |
validationDeadline | uint64 | The amount of time a user has to validate an initiate. |
actionCooldown | uint64 | The amount of time to wait after the deadline has passed before trying again. |
closeDelay | uint64 | The close delay that will be applied to the next long position opening. |