dcrdex icon indicating copy to clipboard operation
dcrdex copied to clipboard

multi: Bridging between Ethereum and Polygon PoS

Open martonp opened this issue 9 months ago • 2 comments

    client/eth: Add USDC Bridge Implementation
    
    - Introduce a `bridge` interface in `client/asset/eth` to standardize
      the bridging process, including methods for managing bridge contract
      approvals, initiating bridges, and completing bridge operations.
    
    - Implement the `bridge` interface with a `usdcBridge` type, utilizing
      Circle's CCTP protocol to enable bridging of native USDC between Polygon
      PoS and Ethereum Mainnet.
    client/asset/eth: Add Polygon Bridge Implementation
    
    - Implement the `bridge` interface using Polygon's bridge infrastructure to
      enable bridging of POL, ETH, and mapped ERC20 tokens between Polygon PoS
      and Ethereum Mainnet.
    lexi: Add Support for Optional Indexing
    
    - Modify the index key mapping function to allow returning `ErrNotIndexed`,
      enabling the exclusion of specific key-value pairs from an index when
      desired.
    client/asset/eth: Enable Bridging for ETH and Token Wallets
    
    - Introduce a `Bridger` interface for wallets that support asset bridging.
    - `ETHBridgeWallet` and `TokenBridgeWallet` types implement this interface.
    - The bridging process has the following steps:
      1. Call `InitiateBridge` on the source wallet to start the bridge.
      2. For bridges requiring a completion transaction:
         - If not required, the process ends here.
         - If required, the source wallet periodically checks the destination
           chain’s readiness, fetches the data required by the destination chain,
           and emtits a `WalletNotification` when the bridge can be completed.
      3. Call `CompleteBridge` on the destination wallet to send a transaction
         and claim the funds.
      4. Call `MarkAsComplete` on the source wallet to confirm bridge completion.
    - Updates the transaction database with indexes for efficient lookups of bridge
      initiations and completions.
    {multi}: client/Core and RPC server bridging support
    
    - client/core:
       - Add functions to access `Bridger` wallets' functionality.
       - Manage interactions between source and destination wallets by
         forwarding `WalletNotification`s.
    - client/rpcserver:
       - Implement rpc comments to initiate bridges and check their statuses.

martonp avatar Mar 21 '25 20:03 martonp

This works with eth <-> pol ? Those aren't tokens right. I thought it would just be tokens.

It bridges between ETH on Ethereum and weth on Polygon, and between POL on Polygon and the POL erc20 on Ethereum. Bridging POL from Polygon to Ethereum is not working in this diff, but I'm fixing it now.

martonp avatar Mar 26 '25 16:03 martonp

I've removed support for bridging the POL token. It requires a different type of bridging involving multiple completion transactions when withdrawing to Ethereum. I'll add it in a follow-up.

martonp avatar Mar 27 '25 22:03 martonp

So, if I were to do with the rpc server bridge 60 966002 1 It should transfer 1 eth to weth? I tried on testnet but do not see a change in the weth wallet:

$ bridgehistory 60
[
  {
    "type": 18,
    "id": "0xc3aa14832a1a5a0ee281f182524fdce7f504c50f0fae09305b25b2ffffc89142",
    "amount": 1000000000,
    "fees": 235967,
    "blockNumber": 8047782,
    "timestamp": 1743755412,
    "recipient": "0x34F5A25B627f50Bb3f5cAb72807c4D4F405a9232",
    "additionalData": {
      "Nonce": "4"
    },
    "confirmed": true,
    "bridgeCounterpartTx": {
      "id": "no-completion-required",
      "assetID": 966002,
      "completionTime": 1743755352
    }
  }
]

https://sepolia.etherscan.io/tx/0xc3aa14832a1a5a0ee281f182524fdce7f504c50f0fae09305b25b2ffffc89142

My Polygon and Eth addresses are the same, is that correct?

JoeGruffins avatar Apr 04 '25 09:04 JoeGruffins

So, if I were to do with the rpc server bridge 60 966002 1 It should transfer 1 eth to weth? I tried on testnet but do not see a change in the weth wallet:

Yes it is the same address. The recipient in that response is the bridge contract address. It takes a while to see the balance update. Currently for bridges that do not require a completion transaction (bridging everything other than USDC from ethereum to polygon POS) the completion time is set as soon as the bridge tx is sent. In a future change, for a better UI and to support market making, we will need to track when the funds are actually allocated.

I see the WETH allocated to your account here now: https://amoy.polygonscan.com/address/0x632E3243301Af96E0D19d62a3efFea28A4415fB1

If you export your account and put it into metamask, you can see your past and pending bridges here as well: https://portal.polygon.technology/

martonp avatar Apr 04 '25 19:04 martonp

Yes! I see it today. It must take quite a while?

JoeGruffins avatar Apr 07 '25 03:04 JoeGruffins