AgentSkillsCN

Bridge Stablecoins

通过Bridge.xyz API管理USDB稳定币,并支持自定义稳定币的发行。提供储备透明度保障、稳定币兑换服务,以及收益奖励机制。适用场景包括:USDB业务运营、储备金查询、自定义稳定币的发行,以及稳定币间的互换交易。

SKILL.md
--- frontmatter
name: Bridge Stablecoins
description: USDB stablecoin management and custom stablecoin issuance with Bridge.xyz API. Reserve transparency, stablecoin swapping, rewards earning. Use for: USDB operations, checking reserves, custom stablecoins, and stablecoin conversion.

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

  1. Reserve transparency - Always verify reserves before large transactions
  2. Rewards optimization - Hold USDB for rewards
  3. Chain selection - Choose low-fee chains for transfers
  4. Diversification - Maintain balances across stablecoins