Stablecoin swaps

Convert stablecoins across different blockchain networks and currencies through crypto-to-crypto transfers. Swap between networks (Polygon to Base) and currencies (USDC to EURC) using blockchain transaction signing.

Overview

Stablecoin swaps enable cross-network and cross-currency conversions between different stablecoins and blockchain networks. These are crypto-to-crypto transfers that require blockchain transaction signing to authorize the source stablecoin transfer and deliver the equivalent value to your destination network.

Common Use Cases:

  • Network optimization - Move funds to networks with lower gas fees
  • DeFi protocol access - Bridge to specific networks for protocol interactions
  • Currency hedging - Convert between USD and EUR stablecoins
  • Liquidity management - Optimize stablecoin positions across multiple networks

Step-by-Step Process

1. Get Available Channels

Discover supported crypto-to-crypto swap combinations.

curl -H "Authorization: Bearer your_api_key" \
-H "Due-Account-Id: your_account_id" \
https://api.due.network/v1/channels

Look for channels where:

  • Source channels: type: "deposit" on crypto rails (ethereum, polygon, arbitrum, base, tron)
  • Destination channels: type: "withdrawal" on crypto rails (ethereum, polygon, arbitrum, base, tron)

2. Create Destination Recipient

Set up the destination crypto address where swapped stablecoins will be delivered.

curl -X POST https://api.due.network/v1/recipients \
-H "Authorization: Bearer your_api_key" \
-H "Due-Account-Id: your_account_id" \
-H "Content-Type: application/json" \
-d '{
  "name": "My Base Wallet",
  "details": {
    "schema": "evm",
    "address": "0x742d35Cc6665C6c175E8c7CaB7CeEf5634123456"
  },
  "isExternal": false
}'

3. Generate Quote

Get real-time pricing for your stablecoin swap with exchange rates and network costs.

curl -X POST https://api.due.network/v1/transfers/quote \
-H "Authorization: Bearer your_api_key" \
-H "Due-Account-Id: your_account_id" \
-H "Content-Type: application/json" \
-d '{
  "source": {
    "rail": "polygon",
    "currency": "USDC",
    "amount": "100.00"
  },
  "destination": {
    "rail": "base",
    "currency": "EURC", 
    "amount": "0"
  }
}'

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "source": {
    "rail": "polygon",
    "currency": "USDC",
    "amount": "100.00",
    "fee": "0.00"
  },
  "destination": {
    "rail": "base", 
    "currency": "EURC",
    "amount": "91.50",
    "fee": "0.00"
  },
  "fxRate": 0.915,
  "fxMarkup": 50,
  "expiresAt": "2024-03-15T10:32:15Z"
}

4. Create Transfer

Initialize the stablecoin swap using your quote and destination recipient.

curl -X POST https://api.due.network/v1/transfers \
-H "Authorization: Bearer your_api_key" \
-H "Due-Account-Id: your_account_id" \
-H "Content-Type: application/json" \
-d '{
  "quote": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "sender": "{wallet_id}",
  "recipient": "{recipient_id}",
  "memo": "USDC to EURC cross-network swap"
}'

Response:

{
  "id": "{transfer_id}",
  "ownerId": "{owner_id}",
  "status": "awaiting_funds",
  "source": {
    "amount": "100.00",
    "fee": "0.00",
    "currency": "USDC",
    "rail": "polygon",
    "id": "{wallet_id}",
    "label": "My Polygon Wallet", 
    "details": {
      "schema": "evm",
      "address": "0x1234567890abcdef1234567890abcdef12345678"
    }
  },
  "destination": {
    "amount": "91.50",
    "fee": "0.00", 
    "currency": "EURC",
    "rail": "base",
    "id": "{recipient_id}",
    "label": "My Base Wallet",
    "details": {
      "schema": "evm", 
      "address": "0x742d35Cc6665C6c175E8c7CaB7CeEf5634123456"
    },
    "memo": "USDC to EURC cross-network swap"
  },
  "fxRate": 0.915,
  "fxMarkup": 50,
  "transferInstructions": {
    "type": "TransferIntent"
  },
  "createdAt": "2024-03-15T10:30:15Z",
  "expiresAt": "2024-03-15T10:35:15Z"
}

5. Create Transfer Intent

Generate blockchain transaction data for signing the source stablecoin transfer.

curl -X POST https://api.due.network/v1/transfers/{transfer_id}/transfer_intent \
-H "Authorization: Bearer your_api_key" \
-H "Due-Account-Id: your_account_id"

Response:

{
  "token": "intent_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "id": "{intent_id}",
  "sender": "0x1234567890abcdef1234567890abcdef12345678",
  "amountIn": "100000000",
  "to": {
    "0x9876543210987654321098765432109876543210": "100000000"
  },
  "tokenIn": "USDC",
  "tokenOut": "EURC",
  "networkIdIn": "polygon", 
  "networkIdOut": "base",
  "gasFee": "0",
  "signables": [
    {
      "hash": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
      "type": "EIP712",
      "data": {
        "types": {
          "Transfer": [
            {"name": "to", "type": "address"},
            {"name": "amount", "type": "uint256"},
            {"name": "nonce", "type": "uint256"}
          ]
        },
        "domain": {
          "name": "DueProtocol",
          "version": "1",
          "chainId": 137
        },
        "message": {
          "to": "0x9876543210987654321098765432109876543210",
          "amount": "100000000",
          "nonce": "456"
        }
      }
    }
  ],
  "expiresAt": "2024-03-15T10:40:15Z",
  "createdAt": "2024-03-15T10:30:45Z"
}

6. Sign Transaction

Use your wallet to sign the Polygon USDC transfer transaction.

Example using ethers.js:

import { ethers } from 'ethers';

// Connect to Polygon network
const provider = new ethers.providers.JsonRpcProvider('https://polygon-rpc.com');
const signer = provider.getSigner();

// Sign the transfer intent transaction
const signable = transferIntent.signables[0];
const signature = await signer._signTypedData(
  signable.data.domain,
  signable.data.types, 
  signable.data.message
);

console.log('Polygon USDC transfer signature:', signature);

7. Submit Signed Transaction

Submit the signed transaction to execute the stablecoin swap.

curl -X POST https://api.due.network/v1/transfer_intents/submit \
-H "Authorization: Bearer your_api_key" \
-H "Due-Account-Id: your_account_id" \
-H "Content-Type: application/json" \
-d '{
  "intentToken": "intent_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "signatures": [
    "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef12345678901c"
  ]
}'

Upon successful submission, your USDC will be transferred from Polygon and EURC will be delivered to your Base network address.