Bridge Stablecoins
Overview
typescript
type StablecoinCurrency = 'usdb' | 'usdc'; type AssetClass = 'cash' | 'managed_money_market' | 'treasuries';
USDB Stablecoin
Check USDB Reserves
typescript
interface ReserveAccount {
asset_class: AssetClass;
currency: string;
amount: string;
}
interface ReserveInfo {
accounts: ReserveAccount[];
}
async function getUSDBReserves(): Promise<ReserveInfo> {
const response = await fetch(`${BRIDGE_API_URL}/transparency/xUSD/reserves`, {
headers: {
'Api-Key': API_KEY,
},
});
if (!response.ok) {
throw new Error('Failed to get reserves');
}
return response.json();
}
// Usage
const reserves = await getUSDBReserves();
console.log('USDB Reserve Breakdown:');
reserves.accounts.forEach(account => {
console.log(`${account.asset_class}: ${account.amount} ${account.currency}`);
});
Stablecoin Conversion
typescript
interface SwapRequest {
amount: string;
on_behalf_of: string;
source: {
payment_rail: 'ethereum' | 'solana' | 'polygon' | 'base' | 'arbitrum';
currency: StablecoinCurrency;
from_address: string;
};
destination: {
payment_rail: 'bridge_wallet';
currency: StablecoinCurrency;
bridge_wallet_id: string;
};
}
async function swapStablecoins(request: SwapRequest): Promise<Transfer> {
const response = await fetch(`${BRIDGE_API_URL}/transfers`, {
method: 'POST',
headers: {
'Api-Key': API_KEY,
'Idempotency-Key': crypto.randomUUID(),
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
});
if (!response.ok) {
const error = await response.json();
throw new Error(`Swap failed: ${error.message}`);
}
return response.json();
}
USDC to USDB Swap
typescript
async function swapUSDCToUSDB(
customerId: string,
amount: string,
usdcAddress: string,
usdbWalletId: string
): Promise<Transfer> {
return swapStablecoins({
amount,
on_behalf_of: customerId,
source: {
payment_rail: 'ethereum',
currency: 'usdc',
from_address: usdcAddress,
},
destination: {
payment_rail: 'bridge_wallet',
currency: 'usdb',
bridge_wallet_id: usdbWalletId,
},
});
}
Custom Stablecoin Issuance (Open Issuance)
typescript
interface CustomStablecoinConfig {
name: string;
symbol: string;
decimals: number;
initial_supply: string;
reserve_percentage: number;
}
async function issueCustomStablecoin(
config: CustomStablecoinConfig
): Promise<{ contract_address: string; tx_hash: string }> {
// Custom stablecoin issuance would be handled via Bridge's Open Issuance platform
// This typically involves a separate onboarding process
console.log('Custom stablecoin issuance requires Bridge Open Issuance setup');
return {
contract_address: '0x...', // Would be provided by Bridge
tx_hash: '0x...',
};
}
Rewards Program
typescript
interface RewardsInfo {
balance: string;
rate: string; // APY percentage
currency: string;
last_updated: string;
}
async function getRewardsBalance(walletId: string): Promise<RewardsInfo> {
const response = await fetch(`${BRIDGE_API_URL}/wallets/${walletId}/rewards`, {
headers: { 'Api-Key': API_KEY },
});
if (!response.ok) {
throw new Error('Failed to get rewards');
}
return response.json();
}
// Track rewards over time
class RewardsTracker {
private walletId: string;
private history: { date: string; balance: string }[] = [];
constructor(walletId: string) {
this.walletId = walletId;
}
async snapshot(): Promise<void> {
const rewards = await getRewardsBalance(this.walletId);
this.history.push({
date: new Date().toISOString(),
balance: rewards.balance,
});
}
getGrowth(): { start: string; end: string; growth: string } {
if (this.history.length < 2) {
throw new Error('Need at least 2 snapshots');
}
const start = parseFloat(this.history[0].balance);
const end = parseFloat(this.history[this.history.length - 1].balance);
const growth = ((end - start) / start * 100).toFixed(2);
return {
start: this.history[0].balance,
end: this.history[this.history.length - 1].balance,
growth: `${growth}%`,
};
}
}
Stablecoin Portfolio
typescript
interface PortfolioItem {
currency: StablecoinCurrency;
chain: string;
balance: string;
value_usd: string;
rewards_apy: string;
}
async function getPortfolio(
customerId: string
): Promise<{ total_value_usd: string; items: PortfolioItem[] }> {
const wallets = await listWallets(customerId);
const items: PortfolioItem[] = [];
for (const wallet of wallets) {
const balance = await getWalletBalance(wallet.id);
const rewards = await getRewardsBalance(wallet.id);
items.push({
currency: 'usdb', // or detect from balance
chain: wallet.chain,
balance: balance.available.amount,
value_usd: balance.available.amount, // 1:1 pegged
rewards_apy: rewards.rate,
});
}
const total = items.reduce((sum, item) => sum + parseFloat(item.value_usd), 0);
return {
total_value_usd: total.toFixed(2),
items,
};
}
Best Practices
- •Reserve transparency - Always verify reserves before large transactions
- •Rewards optimization - Hold USDB for rewards
- •Chain selection - Choose low-fee chains for transfers
- •Diversification - Maintain balances across stablecoins