Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ParaToEthereum #487

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

feat: ParaToEthereum #487

wants to merge 16 commits into from

Conversation

marshacb
Copy link
Contributor

Description

This PR adds support for constructing txs sending Snowbridge ERC20 tokens from a parachain origin back to Ethereum via Snowbridge.

Example usage:

const xcmVersion = 4;
const { api, specName } = await constructApiPromise('wss://hydradx-rpc.dwellir.com');
const assetApi = new AssetTransferApi(api, specName, xcmVersion, {
  injectedRegistry: {
	  polkadot: {
		  2034: {
			  xcAssetsData: [
				  {
					  symbol: 'WETH.snow',
					  xcmV1MultiLocation:
						  '{"v1":{"parents":2,"interior":{"x2":[{"globalConsensus":{"ethereum":{"chainId":1}}},{"accountKey20":{"network":null,"key":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}}]}}}',
				  },
			  ],
		  },
	  },
  },
});

let callInfo: TxResult<'call'>;
try {
callInfo = await assetApi.createTransferTransaction(
	`{"parents":"2","interior":{"X1":{"GlobalConsensus":{"Ethereum":{"chainId":"1"}}}}}`,
	'0x6E733286C3Dc52C67b8DAdFDd634eD9c3Fb05B5B',
	['DOT', 'WETH.snow'],
	['70000000000', '75000000000000'],
	{
		sendersAddr: '7KqMfyEXGMAgkNGxiTf3PNgKqSH1WNghbAGLKezYyLLW4Zp1',
		format: 'call',
		xcmVersion,
		paysWithFeeDest: 'DOT', // Asset to be used to pay for fees on destination chain
	},
);

console.log(callInfo);

Expected output:

{
  origin: 'hydradx',
  dest: 'ethereum',
  direction: 'ParaToEthereum',
  xcmVersion: 4,
  method: 'transferAssetsUsingTypeAndThen',
  format: 'call',
  tx: '0x6b0d04010100a10f040801000007003c534c1002020907040300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000b00b05b4c36440204010002040c16040d01000001010062fecf9c60d8d49d400bd86804558401ec7151fecd440041ca6bf5fd5782517710010102020907040300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20002010907040c1300010300c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20004000d010204000103006e733286c3dc52c67b8dadfdd634ed9c3fb05b5b2c00000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000000000'
}

The following decoded tx:
 {
    "args": {
        "dest": {
            "V4": {
                "parents": "1",
                "interior": {
                    "X1": [
                        {
                            "Parachain": "1,000"
                        }
                    ]
                }
            }
        },
        "assets": {
            "V4": [
                {
                    "id": {
                        "parents": "1",
                        "interior": "Here"
                    },
                    "fun": {
                        "Fungible": "70,000,000,000"
                    }
                },
                {
                    "id": {
                        "parents": "2",
                        "interior": {
                            "X2": [
                                {
                                    "GlobalConsensus": {
                                        "Ethereum": {
                                            "chainId": "1"
                                        }
                                    }
                                },
                                {
                                    "AccountKey20": {
                                        "network": null,
                                        "key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
                                    }
                                }
                            ]
                        }
                    },
                    "fun": {
                        "Fungible": "75,000,000,000,000"
                    }
                }
            ]
        },
        "assets_transfer_type": "DestinationReserve",
        "remote_fees_id": {
            "V4": {
                "parents": "1",
                "interior": "Here"
            }
        },
        "fees_transfer_type": "DestinationReserve",
        "custom_xcm_on_dest": {
            "V4": [
                {
                    "SetAppendix": [
                        {
                            "DepositAsset": {
                                "assets": {
                                    "Wild": "All"
                                },
                                "beneficiary": {
                                    "parents": "0",
                                    "interior": {
                                        "X1": [
                                            {
                                                "AccountId32": {
                                                    "network": null,
                                                    "id": "0x62fecf9c60d8d49d400bd86804558401ec7151fecd440041ca6bf5fd57825177"
                                                }
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "InitiateReserveWithdraw": {
                        "assets": {
                            "Wild": {
                                "AllOf": {
                                    "id": {
                                        "parents": "2",
                                        "interior": {
                                            "X2": [
                                                {
                                                    "GlobalConsensus": {
                                                        "Ethereum": {
                                                            "chainId": "1"
                                                        }
                                                    }
                                                },
                                                {
                                                    "AccountKey20": {
                                                        "network": null,
                                                        "key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
                                                    }
                                                }
                                            ]
                                        }
                                    },
                                    "fun": "Fungible"
                                }
                            }
                        },
                        "reserve": {
                            "parents": "2",
                            "interior": {
                                "X1": [
                                    {
                                        "GlobalConsensus": {
                                            "Ethereum": {
                                                "chainId": "1"
                                            }
                                        }
                                    }
                                ]
                            }
                        },
                        "xcm": [
                            {
                                "BuyExecution": {
                                    "fees": {
                                        "id": {
                                            "parents": "0",
                                            "interior": {
                                                "X1": [
                                                    {
                                                        "AccountKey20": {
                                                            "network": null,
                                                            "key": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
                                                        }
                                                    }
                                                ]
                                            }
                                        },
                                        "fun": {
                                            "Fungible": "1"
                                        }
                                    },
                                    "weightLimit": "Unlimited"
                                }
                            },
                            {
                                "DepositAsset": {
                                    "assets": {
                                        "Wild": {
                                            "AllCounted": "1"
                                        }
                                    },
                                    "beneficiary": {
                                        "parents": "0",
                                        "interior": {
                                            "X1": [
                                                {
                                                    "AccountKey20": {
                                                        "network": null,
                                                        "key": "0x6e733286c3dc52c67b8dadfdd634ed9c3fb05b5b"
                                                    }
                                                }
                                            ]
                                        }
                                    }
                                }
                            },
                            {
                                "SetTopic": "0x0000000000000000000000000000000000000000000000000000000000000000"
                            }
                        ]
                    }
                },
                {
                    "SetTopic": "0x0000000000000000000000000000000000000000000000000000000000000000"
                }
            ]
        },
        "weight_limit": "Unlimited"
    },
    "method": "transferAssetsUsingTypeAndThen",
    "section": "polkadotXcm"
}

@marshacb marshacb changed the title feat: ParaToEthereum feat: ParaToEthereum[WIP] Dec 17, 2024
@marshacb marshacb changed the title feat: ParaToEthereum[WIP] feat: ParaToEthereum Dec 17, 2024
@marshacb marshacb requested review from TarikGul and bee344 December 17, 2024 20:55
Copy link
Contributor

@bee344 bee344 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants