The Digital Token Issuance Contract is a robust Clarity smart contract that enables the creation and management of collateral-backed digital tokens on the Stacks blockchain. Users can mint digital tokens by locking STX as collateral, with built-in liquidation mechanisms to maintain system solvency.
- Collateralized Token Minting: Create digital tokens backed by STX collateral
- Multiple Token Support: Issue and manage various digital token types
- Oracle Price Feeds: Integrate external price data for accurate valuations
- Liquidation Protection: Automatic liquidation of under-collateralized positions
- Emergency Controls: Admin functions to pause/resume the system
- Minimum Ratio: 150% (users must deposit $1.50 worth of STX for every $1.00 of tokens minted)
- Liquidation Threshold: 120% (positions below this ratio can be liquidated)
- Liquidation Penalty: 10% of collateral goes to the liquidator
- Admin: Contract owner who can create tokens, authorize oracles, and manage system state
- Oracle: Authorized addresses that can update token prices
- Users: Anyone can open positions, mint tokens, and participate in liquidations
Creates a new digital token with specified name, symbol, and initial price.
(register-digital-token "Bitcoin Synthetic" "sBTC" u50000)Parameters:
name: Token name (max 32 characters)symbol: Token symbol (max 10 characters)initial-price: Starting price in base units
Returns: Token ID (uint)
Authorizes an oracle address to update token prices.
(authorize-price-feed 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7)Emergency controls to pause or resume all contract operations.
Updates the price of a specific token (oracle-only).
(modify-price u1 u51000)Parameters:
token-id: ID of the token to updatenew-price: New price value
Opens a new collateralized position and mints digital tokens.
(establish-holding u1 u15000 u100)Parameters:
token-id: ID of the token to mintcollateral-amount: Amount of STX to lock as collateralsynthetic-amount: Amount of digital tokens to mint
Requirements:
- Collateral ratio must be ≥ 150%
- System must not be frozen
- Sufficient STX balance
Closes an existing position and returns collateral.
(terminate-holding u1)Returns: All locked STX collateral to the user
Adds additional STX collateral to an existing position.
(deposit-collateral u1 u5000)Use Case: Increase collateral ratio to avoid liquidation
Liquidates an under-collateralized position (anyone can call).
(execute-liquidation 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7 u1)Parameters:
user: Address of the position ownertoken-id: ID of the token
Rewards: Liquidator receives 10% of the collateral as a penalty fee
Retrieves information about a specific digital token.
Returns a user's position details for a given token.
Gets the digital token balance for a user.
Checks if a position is eligible for liquidation.
Returns overall system statistics (total supply, paused status, liquidation penalty).
| Code | Constant | Description |
|---|---|---|
| u100 | ERROR_NOT_AUTHORIZED | Caller lacks required permissions |
| u101 | ERROR_COLLATERAL_TOO_LOW | Insufficient collateral for operation |
| u102 | ERROR_HOLDING_NOT_FOUND | Position does not exist |
| u103 | ERROR_INVALID_VALUE | Invalid amount or parameter |
| u104 | ERROR_LIQUIDATION_LIMIT | Position not eligible for liquidation |
| u105 | ERROR_PRICE_FEED_FAILURE | Oracle price update failed |
| u106 | ERROR_TOKEN_NOT_FOUND | Token ID does not exist |
| u107 | ERROR_INVALID_PARAMETER | Invalid input parameter |
| u108 | ERROR_EMPTY_TEXT | Empty string provided |
- Admin creates a token:
(contract-call? .digital-token-contract register-digital-token "Gold Synthetic" "sGOLD" u200000)
;; Returns: (ok u1)- Admin authorizes an oracle:
(contract-call? .digital-token-contract authorize-price-feed 'SP2ORACLE...)- User opens a position:
(contract-call? .digital-token-contract establish-holding u1 u300000 u1000)
;; Locks 300,000 STX to mint 1,000 sGOLD tokens
;; Collateral ratio: (300,000 / (1,000 * 200,000)) * 100 = 150%- Oracle updates price:
(contract-call? .digital-token-contract modify-price u1 u250000)
;; Gold price increases to 250,000
;; Collateral ratio drops to 120% (liquidation threshold)- Liquidator executes liquidation:
(contract-call? .digital-token-contract execute-liquidation 'SPUSER... u1)
;; Liquidator receives 10% penalty, user gets remaining collateral- Price Oracle Risk: System depends on accurate price feeds from authorized oracles
- Collateral Volatility: STX price fluctuations can affect position health
- Front-Running: Liquidations are first-come-first-served and may be front-run
- Admin Control: Contract owner has significant control over system parameters
Before deploying to mainnet:
- Test all functions with various collateral ratios
- Simulate liquidation scenarios
- Verify oracle price update mechanisms
- Test emergency pause/resume functionality
- Audit for potential reentrancy or overflow issues