UPD — Universal Private Dollar

SDK Quickstart

Install the UPD SDK, get a price quote, mint UPD, and burn UPD.

Testnet Only

UPD is currently deployed on Sepolia testnet. Do not use with real funds.

Installation

npm install @permissionless-technologies/upd-sdk viem

Setup

import { createUPDClient } from '@permissionless-technologies/upd-sdk'
import { createPublicClient, createWalletClient, http } from 'viem'
import { sepolia } from 'viem/chains'

const publicClient = createPublicClient({ chain: sepolia, transport: http() })
const walletClient = createWalletClient({ chain: sepolia, transport: http() })

const client = createUPDClient({
  publicClient,
  walletClient,
  chainId: sepolia.id,
})

Get a Quote

Compute how much UPD you'll receive — pure math, no network call:

import { quoteMintUPD } from '@permissionless-technologies/upd-sdk/core'
import { parseEther, formatUnits } from 'viem'

const ethPrice = 2000n * 10n ** 18n  // $2000
const updAmount = quoteMintUPD(parseEther('1'), ethPrice)
console.log(`1 ETH → ${formatUnits(updAmount, 18)} UPD`)
// → "1 ETH → 2000 UPD"

Or fetch the live price from the oracle:

import { createOracleClient } from '@permissionless-technologies/upd-sdk/oracle'

const oracle = createOracleClient() // defaults to oracle.upd.io
const { price } = await oracle.getEthUsdPrice()
const updAmount = quoteMintUPD(parseEther('1'), price)

Mint UPD

Deposit ETH to mint UPD. The simplest way uses the auto-oracle convenience method:

const txHash = await client.mintWithOracle({
  to: myAddress,
  ethAmount: parseEther('1'),
})

Or with an explicit attestation (more control):

const attestation = await oracle.getEthUsdAttestation()

const txHash = await client.mint({
  to: myAddress,
  ethAmount: parseEther('1'),
  priceAttestation: attestation,
})

Burn UPD

Redeem UPD to receive stETH:

import { parseUnits } from 'viem'

const txHash = await client.burnWithOracle({
  updAmount: parseUnits('1000', 18),
})

Check Balances & Health

const balance = await client.getUPDBalance(myAddress)
const health = await client.getSystemHealth()

console.log('UPD balance:', formatUnits(balance, 18))
console.log('System healthy:', health.isHealthy)
console.log('Collateral ratio:', Number(health.systemCollateralRatioBps) / 100, '%')

React Integration

import {
  useEthUsdPrice,
  useMintQuote,
  useMintUPD,
  useSystemHealth,
} from '@permissionless-technologies/upd-sdk/react'

function MintPanel({ deployment }) {
  const { attestation, priceFormatted } = useEthUsdPrice()
  const { updAmount, isLoading } = useMintQuote(parseEther('1'))
  const { mint, isPending, isConfirmed } = useMintUPD({
    stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
  })
  const { health } = useSystemHealth({
    reporterAddress: deployment.contracts.OvercollateralizationReporter,
    tokenAddress: deployment.contracts.UPDToken,
  })

  return (
    <div>
      <p>ETH/USD: {priceFormatted}</p>
      <p>You'll receive: {updAmount ? formatUnits(updAmount, 18) : '...'} UPD</p>
      {health && <p>System ratio: {Number(health.systemCollateralRatioBps) / 100}%</p>}
      <button
        disabled={isPending || !attestation}
        onClick={() => mint({ to: myAddress, ethAmount: parseEther('1'), attestation: attestation! })}
      >
        {isPending ? 'Minting...' : 'Mint UPD'}
      </button>
      {isConfirmed && <p>Minted successfully!</p>}
    </div>
  )
}

Next Steps

On this page