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: support relay to bridge tx construction #409

Merged
merged 48 commits into from
Jun 12, 2024

Conversation

marshacb
Copy link
Contributor

@marshacb marshacb commented May 24, 2024

Description

This PR introduces the RelayToBridge tx direction for constructing BridgeHub transactions from the Relay Chain.

Changes

  • adds RelayToBridge direction.
  • Adds error validation checks for RelayToBridge direction
  • Adds unit and integration tests for RelayToBridge direction

BridgeHub P<>K Bridge: (Rococo ROC -> Westend AssetHub)

Example of constructing a transferAssetsUsingTypeAndThen call sending ROC to Westend AssetHub from Rococo:

const { api, specName, safeXcmVersion } = await constructApiPromise('wss://rococo-rpc.polkadot.io');
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo: TxResult<'call'>;
try {
	callInfo = await assetApi.createTransferTransaction(
		`{"parents":"1","interior":{"X2":[{"GlobalConsensus":"Westend"},{"Parachain":"1000"}]}}`,
		'13EoPU88424tufnjevEYbbvZ7sGV3q1uhuN4ZbUaoTsnLHYt',
		[`{"parents":"0","interior":{"Here":""}}`],
		['1000000000000'],
	        {
	          format: 'call',
	          xcmVersion: 4,
	          paysWithFeeDest: `{"parents":"0","interior":{"Here":""}}`,
	          assetTransferType: 'RemoteReserve',
	          remoteReserveAssetTransferTypeLocation: '{"parents":"0","interior":{"X1":{"Parachain":"1000"}}}',
	          feesTransferType: 'RemoteReserve',
	          remoteReserveFeesTransferTypeLocation: '{"parents":"0","interior":{"X1":{"Parachain":"1000"}}}',
                }
);

console.log(callInfo);

Expected output:

{
  origin: 'rococo',
  dest: 'westend',
  direction: 'RelayToBridge',
  xcmVersion: 4,
  method: 'transferAssetsUsingTypeAndThen',
  format: 'call',
  tx: '0x630d040102090400a10f0404000000070010a5d4e80304000100a10f0400000304000100a10f04040d0102040001010062fecf9c60d8d49d400bd86804558401ec7151fecd440041ca6bf5fd5782517700'
}

The following decoded tx:
 {
    "args": {
        "dest": {
            "V4": {
                "parents": "1",
                "interior": {
                    "X2": [
                        {
                            "GlobalConsensus": "Westend"
                        },
                        {
                            "Parachain": "1,000"
                        }
                    ]
                }
            }
        },
        "assets": {
            "V4": [
                {
                    "id": {
                        "parents": "0",
                        "interior": "Here"
                    },
                    "fun": {
                        "Fungible": "1,000,000,000,000"
                    }
                }
            ]
        },
        "assets_transfer_type": {
            "RemoteReserve": {
                "V4": {
                    "parents": "0",
                    "interior": {
                        "X1": [
                            {
                                "Parachain": "1,000"
                            }
                        ]
                    }
                }
            }
        },
        "remote_fees_id": {
            "V4": {
                "parents": "0",
                "interior": "Here"
            }
        },
        "fees_transfer_type": {
            "RemoteReserve": {
                "V4": {
                    "parents": "0",
                    "interior": {
                        "X1": [
                            {
                                "Parachain": "1,000"
                            }
                        ]
                    }
                }
            }
        },
        "custom_xcm_on_dest": {
            "V4": [
                {
                    "DepositAsset": {
                        "assets": {
                            "Wild": {
                                "AllCounted": "1"
                            }
                        },
                        "beneficiary": {
                            "parents": "0",
                            "interior": {
                                "X1": [
                                    {
                                        "AccountId32": {
                                            "network": null,
                                            "id": "0x62fecf9c60d8d49d400bd86804558401ec7151fecd440041ca6bf5fd57825177"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            ]
        },
        "weight_limit": "Unlimited"
    },
    "method": "transferAssetsUsingTypeAndThen",
    "section": "xcmPallet"
}

marshacb added 30 commits March 7, 2024 09:18
add unit tests
add util functions for determining direction based on asset and dest locations
…ocations

add SystemToBridge integration tests
updated getGlobalConsensusSystemName to check X1 junction rather than entire string for valid consensus name
added consensus name check to xcm tx input checks for system to bridge direction
add AssetTransferType and resolveTransferType util func
add util function for constructing beneficiary
add util to construct versioned xcm asset id
add ability to explicitly construct transferAssetsUsingTypeAndThen by providing transferAssetsType
update resolveCall to use assetTransferType
update resolveAssetTransferType and createXcmVersionedAssetId
update integration tests
add unit tests
@marshacb marshacb changed the title feat: support relay to bridge tx construction[WIP] feat: support relay to bridge tx construction Jun 12, 2024
@marshacb marshacb requested review from TarikGul and bee344 June 12, 2024 13:41
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!

Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

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

Overall, lgmt! Just one nit

@marshacb marshacb merged commit 436d78b into main Jun 12, 2024
6 checks passed
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