Skip to main content

Modifying Positions

The Position manager comes equipped with several functions that help perform actions on the position. These actions enable positions interactions between the core protocol and exogenous contracts.

Processing Actions

Operation List

This is a predetermined list of actions that can be used to mutate position composition. It is an exhaustive list that has end to end coverage for all position actions.

enum Operation {
NewPosition, // create2 a new position with a given type, no auth needed
// the following operations require msg.sender to be authorized
Exec, // execute arbitrary calldata on a position
Deposit, // Add collateral to a given position
Transfer, // transfer assets from the position to a external address
Approve, // allow a spender to transfer assets from a position
Repay, // decrease position debt
Borrow, // increase position debt
AddToken, // upsert collateral asset to position storage
RemoveToken // remove collateral asset from position storage

}

Operation Processing function

function processBatch(address position, Action[] calldata actions) external nonReentrant whenNotPaused 

Details

  • allows for multiple actions to be called sequentially on a position
  • ensures the position is healthy after all actions are committed, reverting if position is not healthy
ParameterstypeDescription
positionaddressposition to process actions on
actionscalldatalist of actions calldata

Utility Operations

Exec

  function exec(address position, bytes calldata data) internal

Details

  • Operate on a position by interaction with external contracts using arbitrary calldata
  • exec data is encodePacked (address, uint256, bytes)
  • target -> [0:20] contract address to be called by the position
  • value -> [20:52] the ether amount to be sent with the call
  • function selector -> [52:56] function selector to be called on the target
  • calldata -> [52:] represents the calldata including the func selector
ParameterstypeDescription
positionaddressposition to process actions on
datacalldataarbitrary data to operate on a position

Transfer

function transfer(address position, bytes calldata data) internal 

Details

  • data -> abi.encodePacked(address, address, uint256)
  • recipient -> [0:20] address that will receive the transferred tokens
  • asset -> [20:40] address of token to be transferred
  • amt -> [40:72] amount of asset to be transferred
ParameterstypeDescription
positionaddressposition to process actions on
datacalldatatransfer details

Deposit

function deposit(address position, bytes calldata data) internal 

Details

  • data -> abi.encodePacked(address, uint256)
  • asset -> [0:20] address of token to be deposited
  • amt -> [20: 52] amount of asset to be deposited
ParameterstypeDescription
positionaddressposition to process actions on
datacalldatadeposit details

Approve

function approve(address position, bytes calldata data) internal

Details

  • data -> abi.encodePacked(address, address, uint256)
  • spender -> [0:20] address to be approved
  • asset -> [20:40] address of token to be approves
  • amt -> [40:72] amount of asset to be approved
ParameterstypeDescription
positionaddressposition to process actions on
datacalldataapprove details

Repay

function repay(address position, bytes calldata data) internal

Details

  • data -> abi.encodePacked(uint256, uint256)
  • poolId -> [0:32] pool that recieves the repaid debt
  • amt -> [32: 64] notional amount to be repaid
ParameterstypeDescription
positionaddressposition to process actions on
datacalldataRepay details

Borrow

function borrow(address position, bytes calldata data) internal 

Details

  • data -> abi.encodePacked(uint256, uint256)
  • poolId -> [0:32] pool to borrow from
  • amt -> [32:64] notional amount to be borrowed
ParameterstypeDescription
positionaddressposition to process actions on
datacalldataBorrow details

AddToken

function addToken(address position, bytes calldata data) internal

Details

  • Every borrow and deposit should call this function for a new asset. This is how the risk manager keeps track of collateral assets
  • data -> abi.encodePacked(address)
  • asset -> [0:20] address of asset to be registered as collateral
ParameterstypeDescription
positionaddressposition to process actions on
datacalldataToken details

Remove Token

function removeToken(address position, bytes calldata data) internal

Details

  • Every repay, liquidation or transfer should call this function for an asset that is being completely paid off or removed.
  • data -> abi.encodePacked(address)
  • asset -> [0:20] address of asset to be deregistered as collateral
ParameterstypeDescription
positionaddressposition to process actions on
datacalldataToken details