Skip to main content

Smart Contracts Overview

The smart contracts are the on-chain foundation of Stablecoin Studio. They define every rule that governs a stablecoin: who can mint, who can freeze accounts, how reserves are verified, and how logic can be upgraded.

Each stablecoin is a decorator around a standard Hedera Token. The token itself is created through the Hedera Token Service (HTS) for native speed and low fees, while the smart contracts add programmable compliance, role-based access control, and upgradeability on top.


How It Works

When a new stablecoin is created, the StableCoinFactoryFacet deploys several contracts and creates an HTS token in a single transaction:

  1. A ResolverProxy (lightweight diamond clone) is deployed for the stablecoin.
  2. The proxy is linked to the BusinessLogicResolver, which maps function selectors to the correct facet addresses.
  3. An HTS token is created and associated with the proxy.
  4. Roles and initial configuration (supply, decimals, reserve, KYC) are applied.

From that point on, every call to the stablecoin is routed through the proxy to the appropriate facet.


Facets

Facets are modular contracts, each responsible for one domain of stablecoin functionality. They are registered in the BusinessLogicResolver and shared across all stablecoins.

FacetResponsibility
HederaTokenManagerFacetCore initialization, ERC-20-like reads (name, symbol, decimals, totalSupply, balanceOf), token metadata updates
CashInFacetMint new tokens and transfer them to an account (increases total supply)
BurnableFacetBurn tokens from the treasury account (decreases total supply)
WipeableFacetBurn tokens from any account for compliance enforcement (decreases total supply)
FreezableFacetFreeze and unfreeze individual accounts (frozen accounts cannot transact)
KYCFacetGrant and revoke KYC status for accounts
PausableFacetPause and unpause all token transfers globally
RescuableFacetRecover tokens and HBAR from the treasury to another account
DeletableFacetPermanently delete the underlying HTS token (irreversible)
ReserveFacetCheck reserves before minting, update the reserve data feed address
RolesFacetDefine and query the roles that can be assigned to a stablecoin
RoleManagementFacetGrant and revoke multiple roles to multiple accounts in a single transaction
SupplierAdminFacetManage the cash-in role: assign, remove, set/increase/decrease minting allowance
TokenOwnerFacetStore the HTS precompile address and the underlying token address
HoldManagementFacetTemporarily lock tokens under an escrow address for secondary market or compliance scenarios
CustomFeesFacetManage custom fee schedules on the token

Key Contracts

StableCoinFactoryFacet

The entry point for creating new stablecoins. It orchestrates the full deployment flow (proxy, resolver link, HTS token creation, initial configuration) in a single transaction.

A default factory is deployed and maintained by the project on testnet and mainnet. Users can also deploy their own factory.

BusinessLogicResolver

The central registry that maps function selectors to facet contract addresses. All stablecoin proxies delegate selector resolution to this contract.

Updating the resolver upgrades the logic for every stablecoin that points to it, in a single transaction. Individual stablecoins can opt out by pointing to a different resolver.

ResolverProxy

A lightweight diamond clone deployed per stablecoin. It receives calls and delegates them to the correct facet by querying the BusinessLogicResolver.

HederaReserveFacet

Implements the Chainlink AggregatorV3Interface to provide reserve data for a stablecoin. Three modes are supported:

ModeReserve AddressBehavior
No reserve0.0.0 (zero address)Minting is unrestricted
Demo reserveDeployed at creationAdmin can update the reserve amount manually
External reserveExisting data feedReads from a Chainlink-compatible oracle

Roles

Each stablecoin supports fine-grained, multi-account role assignment:

RoleWhat It Controls
AdminFull management: configuration, role assignment, upgrades
Cash-inMint tokens (with optional supply allowance limit)
BurnBurn tokens from the treasury
WipeBurn tokens from any account
PausePause/unpause all transfers
FreezeFreeze/unfreeze individual accounts
KYCGrant/revoke KYC for accounts
RescueRecover tokens and HBAR from treasury
DeleteDelete the underlying token (irreversible)

HTS Precompile Integration

The contracts interact with the Hedera Token Service through the HTS precompiled smart contract. Two Hedera-provided contracts are used:

  • IHederaTokenService.sol — Interface to the HTS precompile. All token operations (create, mint, burn, freeze, etc.) go through this interface.
  • HederaResponseCodes.sol — Response codes returned by HTS operations.

Technologies

  • Solidity 0.8.16+
  • Hardhat development environment
  • Node.js 16+ and npm
  • TypeChain for generating TypeScript bindings from contract ABIs