DYDX - How to bridge your rewards

How to bridge your rewards using Kiln Connect, regardless of your custody solution.

Rewards earned on DYDX are DYDX-USDC. In this tutorial we will present how to bridge these rewards to Ethereum or to Osmosis using the Kiln SDK. These flows can be done directly from Kiln Dashboard if you are using Fireblocks.

Bridge to Ethereum

The goal of this bridge is to bring your dYdX rewards in USDC on your ETH address so that you can use them for other purposes like depositing them on a centralized exchange to get some dYdX back.

To convert your DYDX-USDC to USDC on Ethereum, we will use the Noble bridge developed by Circle, which is the recommended on-chain approach.

There is 3 steps to this flow:

1) Transfer the USDC from DYDX to the Noble chain

2) Burn the USDC on Noble

3) Mint the USDC on Ethereum

Here is a TypeScript code snippet that you can use:

import { Kiln } from "@kilnfi/sdk";
import axios from 'axios';

const f = async () => {
  const k = new Kiln({
    apiToken: 'YOUR_KILN_API_TOKEN',
  });

  /**
   * Send dydx-usdc rewards to noble
   */
  // Craft IBC transfer transaction
  const transferTx = await k.dydx.craftNobleIbcTransfer('YOUR_WALLET_PUBKEY', 1);
  // Sign the transaction with your custody solution
  const signature = '...';
  // Add signature to the transaction
  const { data: data1 } = await axios.post("https://api.kiln.fi/v1/dydx/transaction/prepare", {
    pubkey: transferTx.data.pubkey,
    tx_body: transferTx.data.tx_body,
    tx_auth_info: transferTx.data.tx_auth_info,
    signature: signature,
  });
  // Broadcast the transaction
  const transferTxHash = await k.dydx.broadcast(data1.data);


  /**
   * Burn the usdc on noble for eth address recipient
   */
  // Craft burn transaction
  const burnTx = await k.noble.craftBurnUsdc('YOUR_WALLET_PUBKEY','ETH_RECIPIENT', 1);
  // Sign the transaction with your custody solution
  const signature2 = '...';
  // Add signature to the transaction
  const { data: data2 } = await axios.post("https://api.kiln.fi/v1/noble/transaction/prepare", {
    pubkey: burnTx.data.pubkey,
    tx_body: burnTx.data.tx_body,
    tx_auth_info: burnTx.data.tx_auth_info,
    signature: signature,
  });
  // Broadcast the transaction
  const burnTxHash = await k.noble.broadcast(data2.data);

  /**
   * Mint the USDC on Ethereum to the recipient
   */

  // Fetch the attestation from circle's API (https://developers.circle.com/stablecoins/reference/getattestation)
  const { data: attestation } = await axios.get(`https://iris-api-sandbox.circle.com/v1/messages/4/${burnTxHash}`);

  // Craft the ethereum mint transaction
  // todo: Kiln to add this part to the sdk
  const mintTx;
  // Sign the transaction with your custody solution
  const signature3 = '...';
  // Add signature to the transaction
  const { data: data3 } = await axios.post("https://api.kiln.fi/v1/eth/transaction/prepare", {
    pubkey: mintTx.data.pubkey,
    tx_body: mintTx.data.tx_body,
    tx_auth_info: mintTx.data.tx_auth_info,
    signature: signature,
  });
  // Broadcast the transaction
  const mintTxHash = await k.eth.broadcast(data3.data);
};

f();

Bridge to Osmosis

The goal of this bridge is to bring your dYdX rewards in USDC on another cosmos address here on Osmosis so that you can use them for other purposes like depositing them on a centralized exchange or a Swap on Osmosis to get some dYdX back.

This flow follows two steps:

1) Transfer the DYDX-USDC to the Noble chain

2) Transfer the USDC on Noble to Osmosis

Here is a TypeScript code snippet that you can use:

import { Kiln } from "@kilnfi/sdk";
import axios from 'axios';

const f = async () => {
  const k = new Kiln({
    apiToken: 'YOUR_KILN_API_TOKEN',
  });

  /**
   * Send dydx-usdc rewards to noble
   */
  // Craft IBC transfer transaction
  const transferTx = await k.dydx.craftNobleIbcTransfer('YOUR_WALLET_PUBKEY', 1);
  // Sign the transaction with your custody solution
  const signature = '...';
  // Add signature to the transaction
  const { data: data1 } = await axios.post("https://api.kiln.fi/v1/dydx/transaction/prepare", {
    pubkey: transferTx.data.pubkey,
    tx_body: transferTx.data.tx_body,
    tx_auth_info: transferTx.data.tx_auth_info,
    signature: signature,
  });
  // Broadcast the transaction
  const transferTxHash = await k.dydx.broadcast(data1.data);


  /**
   * Send usdc from noble to osmosis
   */
  // Craft IBC transfer transaction
  const transferTx2 = await k.noble.craftOsmoIbcTransfer('YOUR_WALLET_PUBKEY', 'OSMO_RECIPIENT_ADDRESS', 1);
  // Sign the transaction with your custody solution
  const signature2 = '...';
  // Add signature to the transaction
  const { data: data2 } = await axios.post("https://api.kiln.fi/v1/noble/transaction/prepare", {
    pubkey: transferTx2.data.pubkey,
    tx_body: transferTx2.data.tx_body,
    tx_auth_info: transferTx2.data.tx_auth_info,
    signature: signature2,
  });
  // Broadcast the transaction
  const transferTxHash2 = await k.noble.broadcast(data2.data);
};

f();

Last updated