ERGO
Token Mechanics
Intermediate
1-2 hours

Token Supply & Burning Pattern (Lifecycle Control)

Design mint/burn rules, capped supply and admin-controlled burn functions

문제

You need fine-grained control over token supply: capped minting, burn mechanisms, or governance-controlled supply changes.

솔루션

Combine a minting contract with burn capabilities. Use a state box to track total supply, enforce caps, and require authorization for supply changes.

작동 방식

  1. 1Deploy a state box holding the minting authority (NFT or special token)
  2. 2Minting contract checks current supply against cap before allowing new mints
  3. 3Burns can happen by omission (not including tokens in outputs) or sending to unspendable address
  4. 4Governance can control mint/burn through multi-sig or DAO voting
  5. 5State box tracks total minted and total burned for transparency

코드 예제

These snippets are educational references. Before using them with real funds, pin the exact SDK/compiler versions, validate register encodings, add collection-size guards before indexing arrays, publish test vectors, and keep production deployment behind an explicit review/audit gate.

{
  // State box with minting authority
  val mintingNFT = fromBase64("MINTING_AUTHORITY_NFT")

  // Guard expected shape before reading indexed outputs/registers.
  if (CONTEXT.dataInputs.size > 0 &&
      OUTPUTS.size > 0 &&
      OUTPUTS(0).tokens.size > 0) {
    val stateBox = CONTEXT.dataInputs(0)
    val safeRegisters =
      stateBox.R4[Long].isDefined &&
      stateBox.R5[Long].isDefined

    if (safeRegisters) {
      // Verify authority
      val hasAuthority = stateBox.tokens.exists(t => t._1 == mintingNFT)

      // Supply tracking in state box registers
      val currentSupply = stateBox.R4[Long].get
      val maxSupply = stateBox.R5[Long].get
      val mintAmount = OUTPUTS(0).tokens(0)._2

      // Check cap
      val withinCap = currentSupply + mintAmount <= maxSupply

      // Governance approval (multi-sig)
      val governanceApproved = atLeast(2, Coll(
        proveDlog(admin1PK),
        proveDlog(admin2PK),
        proveDlog(admin3PK)
      ))

      hasAuthority && withinCap && governanceApproved
    } else {
      false
    }
  } else {
    false
  }
}

Minting contract with hard cap enforcement. State box tracks supply, governance multi-sig controls minting authority.

사용 사례

  • Deflationary tokenomics (buyback-and-burn)
  • Capped supply governance tokens
  • Fee burning for protocol revenue
  • Proof-of-burn for cross-chain bridges
  • Elastic supply stablecoins

보안 고려사항

  • !Burns are irreversible - double-check amounts
  • !Use multi-sig for governance-controlled burns
  • !Log burn events for off-chain tracking
  • !Ensure state box cannot be destroyed accidentally

실제 구현 사례

SigmaUSD

Reserve-backed stablecoin with dynamic supply

리소스

수수료 고려사항

Standard transaction fees. State box updates require additional transaction.

ErgoScript 실력을 향상시키세요

새로운 패턴, 튜토리얼, 개발자 리소스 알림을 받으세요.

Follow for daily updates