Add and Remove Collateral
Adding & Removing collaterals to/from an existing position.
Add Collateral
To add collateral to a position, users must already create the position and specify the position ID. The collateral token must be an inToken from lending pools.
The above 2 steps must be performed in a single transaction (atomically) to avoid potential front-run attack.
// Example add collateral function
function addCollateral(uint256 posId, address lendingPool, uint256 shares) external {
// 0. .. pull in lending pool tokens from the caller ..
// 1. transfer inToken to PosManager
IERC20(lendingPool).safeTransfer(POS_MANAGER, shares);
// 2. add collateral to position
IInitCore(INIT_CORE).collateralize(posId, lendingPool);
}
Remove Collateral
To remove collateral, specify the position ID to remove from, shares of collateral to remove, and also the receiver address. The caller must be the position owner or approved party to modify the position.
// Example remove collateral function
function removeCollateral(uint256 posId, address lendingPool, uint256 shares, address receiver) external {
// 1. remove collateral from position
IInitCore(INIT_CORE).decollateralize(posId, lendingPool, shares, receiver);
}
Last updated