Comment on page

Stablecoin mint/burn management

If you operate a stablecoin and onramp/offramp for your coin, you need to mint and burn tokens when a user exchanges their fiat for your token. Supercool makes this automation easy for you.

Onramping with fiat

When a user buys your stablecoins using fiat, you must deliver stablecoins to their wallet. This assumes that you have a payment provider that can accept fiat payment and send you a webhook request after a user pays in fiat. The steps go:
  1. 1.
    User makes a fiat payment of, for example, $50
  2. 2.
    You receive a webhook request notifying you of the payment
  3. 3.
    You make an API request to the Supercool relayer to mint and send $50 of stablecoins to the user's on-chain wallet
If you don't want to deal with processing payment webhooks, you can use Supercool's Automation Engine and set Supercool as the destination for webhook requests from your payment provider.

Offramping to fiat

When a user wants to convert their stablecoins back to fiat, Supercool has infra that makes it easy for you to receive tokens from users and to get notified when they initiate an offramp. This uses Supercool's Offramp Deposit Accounts module, which are on-chain smart contracts that users can deposit their funds into. You can either automatically burn these tokens or you can sweep them to your treasury.
The steps for a user deposit and offramp are:
  1. 1.
    A user sends the tokens to their deposit account
  2. 2.
    You either burn the tokens or sweep them to your treasury
  3. 3.
    Supercool sends you a webhook notification about the user deposit
  4. 4.
    You make a fiat payout to the user
You can trigger fiat payouts in real time using the webhook notification, or you can payout on a fixed schedule. See the Offramp Deposit Accounts module page for more info on the deposit system, which can be used with any token, not just stablecoins.

Code examples

Onramp and minting code example

Here's a basic code example using an Express web server to receive fiat onramp webhooks and then mint stablecoins to a wallet.
import express from 'express'
import {supercool} from '@supercoolxyz/relayer-client'
import {ethers} from 'ethers'
const app = express()
const port = 3000
const apiKey = '...'
const apiSecret = '...'
const provider = new SupercoolRelayerProvider({apiKey, apiSecret})
const signer = new SupercoolRelayerSigner(provider)
const stablecoinContractAddress = '0x...'
const abi = '{...}'
const contract = new ethers.Contract(stablecoinContractAddress, abi, signer)'/fiat-webhook', (req, res) => {
// You can use any request format you want, but this example expects
// a request with JSON like:
// {
// mintTo: "0x...",
// amount: "10050"
// }
// Note that we use a string for the numerical amount for compatibility
// with Javascript implementations that don't support BigInt.
await contract.mintTo(mintTo, amount)
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)

Some considerations for stablecoin design

Users could send stablecoin tokens directly back to your stablecoin contract and you could burn those tokens when received.
Supercool uses the upmost security for its relayer accounts, utilizing hardware security modules (HSM) and key management services (KMS) to store and work with your relayers' private keys. However, you might consider an alternative security model where you have two roles that administer your stablecoin:
  1. 1.
    A minter/burner role, that can mint and burn tokens in tranches
  2. 2.
    A transmitter role, which can send minted tokens to users or receive deposited tokens and prepare them for burning
In this case, you can use Supercool's relayers for the transmitter role and use another method of creating mint/burn transactions, such as a multi-sig wallet.