LoopingHook
Looping Hook contract, which uses the same implementation as MarginTradingHook contract.
View Functions
swapHelper
Get the swap helper contract that this contract swaps between quote and base assets.
lastOrderId
Last running order (take profit or stop loss) id.
getBaseAssetAndQuoteAsset
Get a unique base and quote assets from a pair of tokens.
getMarginPos
Get a looping position.
External Functions
openPos
Open a new looping position by swapping borrPool
's underlying token into collPool
's underlying token via swap data _data
.
The fucntion perform multicall
to InitCore:
borrow tokens
callback (perform swap from borrow token to collateral token)
deposit collateral tokens to lending pool
collateralize inTokens
The swap callback is routed back to this contract's coreCallback
which performs a swap using _data
on swapHelper
contract with slippage control amtOut
.
NOTE: _tokenIn
must be either _borrPool
's underlying token or _collPool
's underlying token.
Name | Type | Description |
---|---|---|
|
| mode to open a looping position |
|
| viewer address that represents the actual position owner |
|
| token to take from position owner |
|
| amount of |
|
| lending pool to borrow |
|
| amount of |
|
| lending pool to use as collateral |
|
| swap data to be used in InitCore's |
|
| min amount out from swap as slippage control |
Returns:
Name | Type | Description |
---|---|---|
|
| running position id for position owner |
|
| InitCore's position id |
|
| amount of token received from swap using |
increasePos
Increase an existing position's size by taking token from position owner and/or borrow more tokens.
_collPool
and borrPool
are fixed from the existing position.
Name | Type | Description |
---|---|---|
|
| owner's position id on this hook to increase position size |
|
| token to take from position owner |
|
| amount of |
|
| amount of |
|
| swap data to be used in InitCore's |
|
| min amount out from swap as slippage control |
Returns:
Name | Type | Description |
---|---|---|
|
| amount of token received from swap using |
addCollateral
Decrease position's leverage by adding more collateral token.
Parameters:
Name | Type | Description |
---|---|---|
|
| owner's position id on this hook |
|
| amount of collateral token's underlying token to take from owner |
removeCollateral
Increase position's leverage by removing collateral token.
Parameters:
Name | Type | Description |
---|---|---|
|
| owner's position id on this hook |
|
| amount of shares to remove collateral token |
|
| whether to unwrap wrapped native token to native token to return to position owner |
repayDebt
Decrease position's leverage by repaying borrow token.
Parameters:
Name | Type | Description |
---|---|---|
|
| owner's position id on this hook |
|
| amount of shares to repay borrow token to borrow lending pool |
Returns:
Name | Type | Description |
---|---|---|
|
| amount of underlying token of borrow lending pool repaid |
reducePos
Reduce an existing position's size by withdrawing collateral and repaying borrow token. The withdrawn collateral token can be swapped to repay borrow token using _data
. The user can specify which token to receive, if there is still left after swap.
Parameters:
Name | Type | Description |
---|---|---|
|
| owner's position id on this hook |
|
| collateral amount to reduce from position |
|
| amount of shares to repay borrow token to borrow lending pool |
|
| token to receive from reducing position (either collalteral's underlying token or borrow's underlying token) |
|
| min amount out from swap as slippage control |
|
| whether to unwrap wrapped native token to native token to return to position owner |
|
| swap data to be used in InitCore's |
Returns:
Name | Type | Description |
---|---|---|
|
| amount of token received from swap using |
Last updated