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({
    baseUrl: 'https://api.kiln.fi',
    apiToken: 'YOUR_KILN_API_TOKEN',
  });

  /**
   * Send dydx-usdc rewards to noble
   */
  // Craft IBC transfer transaction
  const transferTx = await k.client.POST(
    '/v1/dydx/transaction/noble-ibc-transfer',
    {
      body: {
        pubkey: '02d92b48d3e9ef34f2016eac7857a02768c88e30aea7a2366bc5ba032a22eceb8b',
        amount_uusdc: '1000000',
      }
    }
  );
  // Sign the transaction with Fireblocks or your custody solution
  const signResponse = await k.fireblocks.signDydxTx(vault, tx.data.data);
  // Broadcast the transaction on DYDX
  const broadcastedTx = await k.client.POST("/v1/dydx/transaction/broadcast", {
    body: {
      tx_serialized: signResponse.signed_tx.data.tx_serialized,
    }
  });


  /**
   * Burn the usdc on noble for eth address recipient
   */
  // Craft burn transaction
  const txburn = await k.client.POST(
    '/v1/noble/transaction/burn-usdc',
    {
      body: {
        pubkey: '02d92b48d3e9ef34f2016eac7857a02768c88e30aea7a2366bc5ba032a22eceb8b',
        amount_usdc: '1000000',
        recipient: '0xBC86717BaD3F8CcF86d2882a6bC351C94580A994',
      }
    }
  );
  // Sign the transaction with Fireblocks or your custody solution
  const signResponseBurn = await k.fireblocks.signDydxTx(vault, txburn.data.data);
  // Broadcast the transaction on Noble
  const broadcastedTxBurn = await k.client.POST("/v1/noble/transaction/broadcast", {
    body: {
      tx_serialized: signResponseBurn.signed_tx.data.tx_serialized,
    }
  });

  /**
   * 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 and broadcast the transaction with Fireblocks on Ethereum
  const txHash = await k.fireblocks.signAndBroadcastEthTx(vault, mintTx);
};

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.client.POST(
    '/v1/dydx/transaction/noble-ibc-transfer',
    {
      body: {
        pubkey: '02d92b48d3e9ef34f2016eac7857a02768c88e30aea7a2366bc5ba032a22eceb8b',
        amount_uusdc: '1000000',
      }
    }
  );
  // Sign the transaction with Fireblocks or your custody solution
  const signResponse = await k.fireblocks.signDydxTx(vault, tx.data.data);
  // Broadcast the transaction on DYDX
  const broadcastedTx = await k.client.POST("/v1/dydx/transaction/broadcast", {
    body: {
      tx_serialized: signResponse.signed_tx.data.tx_serialized,
    }
  });


  /**
   * Send usdc from noble to osmosis
   */
  // Craft IBC transfer transaction
  const tx = await k.client.POST(
      '/v1/noble/transaction/osmo-ibc-transfer',
      {
        body: {
          pubkey: '02d92b48d3e9ef34f2016eac7857a02768c88e30aea7a2366bc5ba032a22eceb8b',
          recipient: 'osmo1qz0jvz6v3v7z2zg3z2zg3z2zg3z2zg3z2zg3z2',
          amount_uusdc: '1000000',
        }
      }
    );
  // Sign the transaction with Fireblocks or your custody solution
  const signResponse = await k.fireblocks.signDydxTx(vault, tx.data.data);
  // Broadcast the transaction on Noble
  const broadcastedTx = await k.client.POST("/v1/noble/transaction/broadcast", {
    body: {
      tx_serialized: signResponse.signed_tx.data.tx_serialized,
    }
  });
};

f();

Last updated