React Hooks
Wagmi-based hooks for UPD — price feeds, minting, burning, staking, and system health.
React Hooks
npm install @permissionless-technologies/upd-sdk viem wagmi @tanstack/react-queryAll hooks are wagmi-based and require your app to be wrapped in WagmiProvider + QueryClientProvider. No UPD-specific provider is needed.
import { useEthUsdPrice, useMintUPD, useSystemHealth } from '@permissionless-technologies/upd-sdk/react'Price & Quotes
useEthUsdPrice
Fetches live ETH/USD price from the oracle service. Returns a signed attestation ready for mint/burn.
const {
price, // bigint | undefined — raw 18-decimal price
priceFormatted, // string — "$2,000.00"
attestation, // PriceAttestationQuery | undefined — pass to mint/burn
isLoading,
error,
refetch,
} = useEthUsdPrice({
oracleUrl?: string, // default: oracle.upd.io
refetchInterval?: number, // default: 10000 (10s)
})useMintQuote
Real-time quote composing oracle price + pure math.
const { updAmount, ethUsdPrice, isLoading } = useMintQuote(parseEther('1'))
// updAmount ≈ 2000e18 at $2000/ETHuseBurnQuote
const { stEthAmount, ethUsdPrice, isLoading } = useBurnQuote(parseUnits('2000', 18))
// stEthAmount ≈ 1e18 at $2000/ETHUPD Token
useUPD
Read UPD balance and total supply.
const { balance, totalSupply, isLoading } = useUPD({
tokenAddress: deployment.contracts.UPDToken,
userAddress: account.address, // optional
})useCollateral
Read system collateral metrics.
const { totalStEthCollateral, totalUPDSupply, isLoading } = useCollateral({
reporterAddress: deployment.contracts.OvercollateralizationReporter,
tokenAddress: deployment.contracts.UPDToken,
})useSystemHealth
Composes useCollateral + useEthUsdPrice + computeSystemHealth.
const { health, isLoading } = useSystemHealth({
reporterAddress: deployment.contracts.OvercollateralizationReporter,
tokenAddress: deployment.contracts.UPDToken,
})
if (health) {
console.log(`Ratio: ${health.systemCollateralRatioBps} bps`)
console.log(`Healthy: ${health.isHealthy}`)
console.log(`Buffer: ${formatUnits(health.bufferUsd, 18)} USD`)
}Mint & Burn
useMintUPD
Write hook for depositing ETH to mint UPD.
const { mint, isPending, txHash, isConfirming, isConfirmed, error, reset } = useMintUPD({
stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
})
// Use with useEthUsdPrice to get the attestation
const { attestation } = useEthUsdPrice()
<button
disabled={isPending || !attestation}
onClick={() => mint({ to: address, ethAmount: parseEther('1'), attestation: attestation! })}
>
{isPending ? 'Confirming...' : 'Mint UPD'}
</button>useBurnUPD
Write hook for burning UPD to receive stETH.
const { burn, isPending, isConfirmed, error } = useBurnUPD({
stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
})
<button onClick={() => burn({ updAmount: parseUnits('1000', 18), attestation: attestation! })}>
Burn 1000 UPD
</button>Stabilizer
useStabilizer
Read stabilizer position data.
const { positionEscrowAddress, stabilizerEscrowAddress, isLoading } = useStabilizer({
stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
tokenId: 1n, // optional
})sUPD Staking
useSUPD
Read sUPD share value, APY, balance, and total liability.
const {
balance, // user's sUPD shares
totalSupply,
shareValue, // current value per share (18 decimals)
annualYieldBps, // e.g. 800 = 8% APY
totalLiabilityUSD,
isLoading,
} = useSUPD({
supdAddress: deployment.contracts.sUPD,
userAddress: account.address,
})useStakeUPD
Stake UPD to receive sUPD shares. User must approve sUPD contract to spend UPD first.
const { stake, isPending, isConfirmed } = useStakeUPD({
supdAddress: deployment.contracts.sUPD,
})
<button onClick={() => stake({ updAmount: parseUnits('1000', 18), attestation: attestation! })}>
Stake 1000 UPD
</button>useUnstakeUPD
Unstake sUPD shares to receive UPD. Calls unstakeToUPD (full redemption).
const { unstake, isPending, isConfirmed } = useUnstakeUPD({
supdAddress: deployment.contracts.sUPD,
})
<button onClick={() => unstake({ shares: myShares, attestation: attestation! })}>
Unstake
</button>Hook Summary
| Hook | Type | Purpose |
|---|---|---|
useEthUsdPrice | Read (HTTP) | Live ETH/USD price from oracle |
useMintQuote | Read (derived) | Real-time UPD amount for ETH input |
useBurnQuote | Read (derived) | Real-time stETH amount for UPD input |
useUPD | Read (contract) | UPD balance and supply |
useCollateral | Read (contract) | System collateral metrics |
useSystemHealth | Read (composed) | Collateral ratio, health status |
useStabilizer | Read (contract) | Stabilizer position addresses |
useSUPD | Read (contract) | sUPD share value, APY, balance |
useMintUPD | Write | Deposit ETH, mint UPD |
useBurnUPD | Write | Burn UPD, receive stETH |
useStakeUPD | Write | Stake UPD, receive sUPD |
useUnstakeUPD | Write | Unstake sUPD, receive UPD |