Skip to content

Commit d53002f

Browse files
eric-stacksgitbook-bot
authored andcommitted
GITBOOK-58: updates to USDCx bridge guide
1 parent 40d0768 commit d53002f

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

docs/build/more-guides/bridging-usdcx.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Current work is underway to abstract this entire flow via Circle's Bridge Kit SD
66

77
## Intro
88

9-
[USDCx](https://app.gitbook.com/s/H74xqoobupBWwBsVMJhK/bridging/usdcx) bridges USDC into Stacks, integrating a stablecoin into its decentralized ecosystem via Circle's xReserve protocol. This enables asset transfer from Ethereum and enhances Stacks' DeFi offerings. Users access Stacks' DeFi, maintaining stable assets, increasing liquidity, and providing a reliable option for transactions and investments.
9+
[USDCx](https://app.gitbook.com/s/H74xqoobupBWwBsVMJhK/bridging/usdcx) on Stacks opens up stablecoin liquidity into its decentralized ecosystem via Circle's xReserve protocol. This enables asset transfers from Ethereum and enhances Stacks' DeFi offerings. Users access Stacks' DeFi, maintaining stable assets, increasing liquidity, and providing a reliable option for transactions and investments.
1010

1111
### tl;dr
1212

@@ -18,26 +18,26 @@ Current work is underway to abstract this entire flow via Circle's Bridge Kit SD
1818

1919
**Deposit**
2020

21-
1. Setup contract ABIs
22-
2. Setup wallet and public clients
23-
3. Check native ETH and USDC balance
24-
4. Prepare deposit params
25-
5. Approve xReserve to spend 
26-
6. Execute deposit to remote chain
21+
1. Setup USDC and xReserve's Solidity contract ABIs
22+
2. Setup wallet and public clients to communicate with the Ethereum network
23+
3. Check native ETH and USDC balances on a user's wallet.
24+
4. Prepare deposit params before initiating deposit request.
25+
5. Approve xReserve as a spender of your USDC.
26+
6. Execute deposit to the remote chain Stacks.
2727

2828
### Key Tools To Use
2929

30-
* viem
31-
* @stacks/transactions
30+
* [viem](https://viem.sh/) - A Typescript-first library that interfaces with Ethereum.
31+
* [stacks.js](/broken/pages/dH5waQhE6Vb7rhcrUG7z) - A js library that helps developers build Stacks apps by handling transactions, wallet authentication, and smart contract interactions.
3232

3333
***
3434

3535
## Complete Code
3636

37-
#### Deposit
38-
3937
If you want to jump straight to the full implementation, the complete working code used in this guide is shown below.
4038

39+
#### Deposit
40+
4141
{% tabs %}
4242
{% tab title="index.ts" %}
4343
This script bridges USDC from Ethereum Sepolia testnet to Stacks testnet by first approving the xReserve contract to spend USDC, then calling `depositToRemote` to initiate the cross-chain transfer. It encodes the Stacks recipient address into the bytes32 format required by the Ethereum contract and submits both transactions to the Sepolia network. The Stacks attestation service will receive this event and mint the equivalent amount to the specified Stacks address.
@@ -271,9 +271,10 @@ PRIVATE_KEY=<YOUR_PRIVATE_KEY>
271271

272272
## Walkthrough (Deposit)
273273

274-
Before beginning, make sure you've:
274+
Before beginning, make sure you:
275275

276-
* Created a wallet on Ethereum Sepolia.
276+
* Create a wallet on Ethereum Sepolia.
277+
* Create a Stacks testnet wallet.
277278
* Get testnet USDC from the [Circle Faucet](https://faucet.circle.com/).
278279
* Get testnet ETH from a public [Ethereum Sepolia faucet](https://cloud.google.com/application/web3/faucet/ethereum/sepolia).
279280

@@ -325,12 +326,10 @@ You can examine the USDC, xReserve, and the other contracts related to USDCx on
325326
Replace `YOUR_STACKS_TESTNET_ADDRESS` with the wallet that should receive minted USDCx on Stacks testnet.
326327

327328
{% hint style="success" %}
328-
Stacks' domain id of `10003` is constant for all networks.
329+
Stacks' domain id, used for the xReserve protocol, of `10003` is constant for all networks.
329330
{% endhint %}
330331

331-
{% code title="index.ts" expandable="true" %}
332-
```typescript
333-
// --snip--
332+
<pre class="language-typescript" data-title="index.ts" data-expandable="true"><code class="lang-typescript">// --snip--
334333

335334
// ============ Configuration constants ============
336335
const config = {
@@ -344,12 +343,11 @@ const config = {
344343

345344
// Deposit parameters for Stacks
346345
STACKS_DOMAIN: 10003, // Stacks domain ID
347-
STACKS_RECIPIENT: "YOUR_STACKS_TESTNET_ADDRESS", // Address to receive minted USDCx on Stacks
348-
DEPOSIT_AMOUNT: "1.00",
346+
<strong> STACKS_RECIPIENT: "YOUR_STACKS_TESTNET_ADDRESS", // Address to receive minted USDCx on Stacks
347+
</strong> DEPOSIT_AMOUNT: "1.00",
349348
MAX_FEE: "0",
350349
};
351-
```
352-
{% endcode %}
350+
</code></pre>
353351
{% endstep %}
354352

355353
{% step %}
@@ -456,17 +454,20 @@ if (nativeBalance === 0n)
456454

457455
Prepares the deposit parameters by converting USDC amounts to the correct decimal format (6 decimals), encoding the Stacks recipient address into bytes32 format, and setting empty hookData for the cross-chain transaction.
458456

457+
{% hint style="info" %}
458+
Stacks addresses need to be reformatted and encoded to bytes32 on the Ethereum side. Special helper methods are needed for this encoding.
459+
{% endhint %}
460+
459461
{% tabs %}
460462
{% tab title="index.ts" %}
461-
```typescript
462-
// --snip--
463+
<pre class="language-typescript"><code class="lang-typescript">// --snip--
463464

464465
// Prepare deposit params (USDC has 6 decimals)
465466
const value = parseUnits(config.DEPOSIT_AMOUNT, 6);
466467
const maxFee = parseUnits(config.MAX_FEE, 6);
467-
const remoteRecipient = bytes32FromBytes(remoteRecipientCoder.encode(config.STACKS_RECIPIENT));
468-
const hookData = "0x";
469-
```
468+
<strong>const remoteRecipient = bytes32FromBytes(remoteRecipientCoder.encode(config.STACKS_RECIPIENT));
469+
</strong>const hookData = "0x";
470+
</code></pre>
470471
{% endtab %}
471472

472473
{% tab title="helpers.ts" %}
@@ -550,9 +551,7 @@ if (usdcBalance < value) {
550551

551552
Executes two sequential transactions: first approves the xReserve contract to spend the specified USDC amount and waits for confirmation, then calls the `depositToRemote` function to initiate the cross-chain bridge transfer to the Stacks recipient.
552553

553-
{% code title="index.ts" expandable="true" %}
554-
```typescript
555-
// --snip--
554+
<pre class="language-typescript" data-title="index.ts" data-expandable="true"><code class="lang-typescript">// --snip--
556555

557556
// Approve xReserve to spend USDC
558557
const approveTxHash = await client.writeContract({
@@ -571,8 +570,8 @@ console.log("✅ Approval confirmed");
571570
const depositTxHash = await client.writeContract({
572571
address: `0x${config.X_RESERVE_CONTRACT}`,
573572
abi: X_RESERVE_ABI,
574-
functionName: "depositToRemote",
575-
args: [
573+
<strong> functionName: "depositToRemote",
574+
</strong> args: [
576575
value,
577576
config.STACKS_DOMAIN,
578577
remoteRecipient,
@@ -581,8 +580,9 @@ const depositTxHash = await client.writeContract({
581580
hookData,
582581
],
583582
});
584-
```
585-
{% endcode %}
583+
</code></pre>
584+
585+
After some time, Stacks attestation service should receive the request and mint the equivalent value in USDCx on Stacks.
586586

587587
These are example transactions on testnet:
588588

0 commit comments

Comments
 (0)