Position Management
The Position Management component handles user collateral positions, deposits, and nUSD minting/burning operations.
Action
Description
Function
Deposit and Mint
Deposit collateral and mint nUSD
depositAssetToMint(uint256 assetAmount, uint256 mintAmount)
Withdraw
Withdraw collateral after repaying
withdraw(address onBehalfOf, uint256 amount)
Deposit Only
Deposit collateral without minting
depositAssetToMint(uint256 assetAmount, 0)
Mint Only
Mint nUSD against existing collateral
mint(address onBehalfOf, uint256 amount)
Repay
Burn nUSD without withdrawing
burn(address onBehalfOf, uint256 amount)
Example: Deposit and Mint
// Approve collateral for deposit
IERC20(collateralToken).approve(vaultAddress, collateralAmount);
// Deposit collateral and mint nUSD in one transaction
IVault(vaultAddress).depositAssetToMint(collateralAmount, nusdAmount);
// Check updated position
(uint256 collateral, uint256 debt) = IVault(vaultAddress).positions(userAddress);
Example: Withdraw After Repaying
// Approve nUSD for burning
IERC20(nUSDAddress).approve(vaultAddress, debtAmount);
// Burn nUSD to reduce debt
IVault(vaultAddress).burn(userAddress, debtAmount);
// Withdraw collateral
IVault(vaultAddress).withdraw(userAddress, collateralAmount);
Last updated