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';constf=async () => {constk=newKiln({ apiToken:'YOUR_KILN_API_TOKEN', });/** * Send dydx-usdc rewards to noble */// Craft IBC transfer transactionconsttransferTx=awaitk.dydx.craftNobleIbcTransfer('YOUR_WALLET_PUBKEY',1);// Sign the transaction with your custody solutionconstsignature='...';// Add signature to the transactionconst { data: data1 } =awaitaxios.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 transactionconsttransferTxHash=awaitk.dydx.broadcast(data1.data);/** * Burn the usdc on noble for eth address recipient */// Craft burn transactionconstburnTx=awaitk.noble.craftBurnUsdc('YOUR_WALLET_PUBKEY','ETH_RECIPIENT',1);// Sign the transaction with your custody solutionconstsignature2='...';// Add signature to the transactionconst { data: data2 } =awaitaxios.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 transactionconstburnTxHash=awaitk.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 } =awaitaxios.get(`https://iris-api-sandbox.circle.com/v1/messages/4/${burnTxHash}`);// Craft the ethereum mint transaction// todo: Kiln to add this part to the sdkconstmintTx;// Sign the transaction with your custody solutionconstsignature3='...';// Add signature to the transactionconst { data: data3 } =awaitaxios.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 transactionconstmintTxHash=awaitk.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';constf=async () => {constk=newKiln({ apiToken:'YOUR_KILN_API_TOKEN', });/** * Send dydx-usdc rewards to noble */// Craft IBC transfer transactionconsttransferTx=awaitk.dydx.craftNobleIbcTransfer('YOUR_WALLET_PUBKEY',1);// Sign the transaction with your custody solutionconstsignature='...';// Add signature to the transactionconst { data: data1 } =awaitaxios.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 transactionconsttransferTxHash=awaitk.dydx.broadcast(data1.data);/** * Send usdc from noble to osmosis */// Craft IBC transfer transactionconsttransferTx2=awaitk.noble.craftOsmoIbcTransfer('YOUR_WALLET_PUBKEY','OSMO_RECIPIENT_ADDRESS',1);// Sign the transaction with your custody solutionconstsignature2='...';// Add signature to the transactionconst { data: data2 } =awaitaxios.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 transactionconsttransferTxHash2=awaitk.noble.broadcast(data2.data);};f();