Unstable Protocol
  • Introduction
  • Users
    • Mint nUSD
    • Repay nUSD
    • Interest and Fees
    • Collateralization and Liquidation
    • Redemption
  • Developers
    • Architecture
    • Position Management
    • Interest and Fees
    • Price Oracle
    • Liquidation System
    • Redemption System
    • Emergency Controls
    • Deployments
    • Security & Audits
Powered by GitBook
On this page
  • Example: Deposit and Mint
  • Example: Withdraw After Repaying
Export as PDF
  1. Developers

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);
PreviousArchitectureNextInterest and Fees

Last updated 2 months ago