From 77b4c04e3663e0fabfb66b0a5c261e271fe9d2ec Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 11 Sep 2024 11:33:44 +0200 Subject: [PATCH] Remove destination parachain transfer from PNA (#1284) * remove destination fee from PNA * fmt --- contracts/scripts/DeployBeefyClient.sol | 12 ++++- contracts/src/Assets.sol | 42 +++--------------- contracts/src/BeefyClient.sol | 2 +- contracts/test/Gateway.t.sol | 44 ++++++++++++++++++- contracts/test/mocks/BitfieldWrapper.sol | 7 ++- smoketest/tests/create_agent.rs | 3 +- smoketest/tests/create_channel.rs | 3 +- smoketest/tests/register_polkadot_token.rs | 8 +--- smoketest/tests/transfer_native_from_agent.rs | 3 +- smoketest/tests/upgrade_gateway.rs | 5 +-- web/packages/test/scripts/xcm-helper.sh | 3 +- 11 files changed, 73 insertions(+), 59 deletions(-) diff --git a/contracts/scripts/DeployBeefyClient.sol b/contracts/scripts/DeployBeefyClient.sol index 85a3b5001e..a8ef395926 100644 --- a/contracts/scripts/DeployBeefyClient.sol +++ b/contracts/scripts/DeployBeefyClient.sol @@ -19,8 +19,16 @@ contract DeployBeefyClient is Script { // Checkpoint generated using the script `./beefy-checkpoint.js` script in Polkadot-JS. config = Config({ startBlock: 21087413, - current: BeefyClient.ValidatorSet({id: 644, length: 297, root: 0x3db19e57e6a7deaec1204d4fb8295cab4e24f8902f54e70d25f273abfe346ada}), - next: BeefyClient.ValidatorSet({id: 645, length: 297, root: 0x3db19e57e6a7deaec1204d4fb8295cab4e24f8902f54e70d25f273abfe346ada}), + current: BeefyClient.ValidatorSet({ + id: 644, + length: 297, + root: 0x3db19e57e6a7deaec1204d4fb8295cab4e24f8902f54e70d25f273abfe346ada + }), + next: BeefyClient.ValidatorSet({ + id: 645, + length: 297, + root: 0x3db19e57e6a7deaec1204d4fb8295cab4e24f8902f54e70d25f273abfe346ada + }), randaoCommitDelay: 128, randaoCommitExpiration: 24, minimumSignatures: 17 diff --git a/contracts/src/Assets.sol b/contracts/src/Assets.sol index c88ead8846..f2320e5772 100644 --- a/contracts/src/Assets.sol +++ b/contracts/src/Assets.sol @@ -243,44 +243,14 @@ library Assets { ticket.costs = _sendForeignTokenCosts(destinationChain, destinationChainFee, maxDestinationChainFee); // Construct a message payload - if (destinationChain == $.assetHubParaID) { + if (destinationChain == $.assetHubParaID && destinationAddress.isAddress32()) { // The funds will be minted into the receiver's account on AssetHub - if (destinationAddress.isAddress32()) { - // The receiver has a 32-byte account ID - ticket.payload = SubstrateTypes.SendForeignTokenToAssetHubAddress32( - foreignID, destinationAddress.asAddress32(), $.assetHubReserveTransferFee, amount - ); - } else { - // AssetHub does not support 20-byte account IDs - revert Unsupported(); - } + // The receiver has a 32-byte account ID + ticket.payload = SubstrateTypes.SendForeignTokenToAssetHubAddress32( + foreignID, destinationAddress.asAddress32(), $.assetHubReserveTransferFee, amount + ); } else { - if (destinationChainFee == 0) { - revert InvalidDestinationFee(); - } - if (destinationAddress.isAddress32()) { - // The receiver has a 32-byte account ID - ticket.payload = SubstrateTypes.SendForeignTokenToAddress32( - foreignID, - destinationChain, - destinationAddress.asAddress32(), - $.assetHubReserveTransferFee, - destinationChainFee, - amount - ); - } else if (destinationAddress.isAddress20()) { - // The receiver has a 20-byte account ID - ticket.payload = SubstrateTypes.SendForeignTokenToAddress20( - foreignID, - destinationChain, - destinationAddress.asAddress20(), - $.assetHubReserveTransferFee, - destinationChainFee, - amount - ); - } else { - revert Unsupported(); - } + revert Unsupported(); } emit IGateway.TokenSent(token, sender, destinationChain, destinationAddress, amount); diff --git a/contracts/src/BeefyClient.sol b/contracts/src/BeefyClient.sol index fd036939b0..adde28830b 100644 --- a/contracts/src/BeefyClient.sol +++ b/contracts/src/BeefyClient.sol @@ -292,7 +292,7 @@ contract BeefyClient { validatorSetLen: uint32(vset.length), numRequiredSignatures: uint32( computeNumRequiredSignatures(vset.length, signatureUsageCount, minNumRequiredSignatures) - ), + ), prevRandao: 0, bitfieldHash: keccak256(abi.encodePacked(bitfield)) }); diff --git a/contracts/test/Gateway.t.sol b/contracts/test/Gateway.t.sol index 22776dc47e..e17c7df1a9 100644 --- a/contracts/test/Gateway.t.sol +++ b/contracts/test/Gateway.t.sol @@ -919,7 +919,7 @@ contract GatewayTest is Test { MockGateway(address(gateway)).mintForeignTokenPublic(abi.encode(params)); } - function testSendRelayTokenToAssetHub() public { + function testSendRelayTokenToAssetHubWithAddress32() public { // Register and then mint some DOT to account1 testMintForeignToken(); @@ -939,6 +939,48 @@ contract GatewayTest is Test { IGateway(address(gateway)).sendToken{value: 0.1 ether}(address(dotToken), destPara, recipientAddress32, 1, 1); } + function testSendRelayTokenToAssetHubWithAddress20() public { + // Register and then mint some DOT to account1 + testMintForeignToken(); + + address dotToken = MockGateway(address(gateway)).tokenAddressOf(dotTokenID); + + ParaID destPara = assetHubParaID; + + vm.prank(account1); + + vm.expectRevert(Assets.Unsupported.selector); + IGateway(address(gateway)).sendToken{value: 0.1 ether}(address(dotToken), destPara, recipientAddress20, 1, 1); + } + + function testSendRelayTokenToDestinationChainWithAddress32() public { + // Register and then mint some DOT to account1 + testMintForeignToken(); + + address dotToken = MockGateway(address(gateway)).tokenAddressOf(dotTokenID); + + ParaID destPara = ParaID.wrap(2043); + + vm.prank(account1); + + vm.expectRevert(Assets.Unsupported.selector); + IGateway(address(gateway)).sendToken{value: 0.1 ether}(address(dotToken), destPara, recipientAddress32, 1, 1); + } + + function testSendRelayTokenToDestinationChainWithAddress20() public { + // Register and then mint some DOT to account1 + testMintForeignToken(); + + address dotToken = MockGateway(address(gateway)).tokenAddressOf(dotTokenID); + + ParaID destPara = ParaID.wrap(2043); + + vm.prank(account1); + + vm.expectRevert(Assets.Unsupported.selector); + IGateway(address(gateway)).sendToken{value: 0.1 ether}(address(dotToken), destPara, recipientAddress20, 1, 1); + } + function testSendNotRegisteredTokenWillFail() public { ParaID destPara = assetHubParaID; diff --git a/contracts/test/mocks/BitfieldWrapper.sol b/contracts/test/mocks/BitfieldWrapper.sol index 7748608994..3ae5e839e7 100644 --- a/contracts/test/mocks/BitfieldWrapper.sol +++ b/contracts/test/mocks/BitfieldWrapper.sol @@ -5,14 +5,17 @@ import {Bitfield} from "../../src/utils/Bitfield.sol"; contract BitfieldWrapper { function createBitfield(uint256[] calldata bitsToSet, uint256 length) - pure public + pure returns (uint256[] memory bitfield) { return Bitfield.createBitfield(bitsToSet, length); } - function subsample(uint256 seed, uint256[] memory prior, uint256 n, uint256 length) public returns (uint256[] memory bitfield) { + function subsample(uint256 seed, uint256[] memory prior, uint256 n, uint256 length) + public + returns (uint256[] memory bitfield) + { return Bitfield.subsample(seed, prior, n, length); } } diff --git a/smoketest/tests/create_agent.rs b/smoketest/tests/create_agent.rs index a5fbe4e68e..19159e2cc1 100644 --- a/smoketest/tests/create_agent.rs +++ b/smoketest/tests/create_agent.rs @@ -20,8 +20,7 @@ async fn create_agent() { println!( "xcm call issued at block hash {:?}, transaction hash {:?}", - result.block_hash, - result.extrinsic_hash + result.block_hash, result.extrinsic_hash ); wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; diff --git a/smoketest/tests/create_channel.rs b/smoketest/tests/create_channel.rs index 66abaa321f..795847be43 100644 --- a/smoketest/tests/create_channel.rs +++ b/smoketest/tests/create_channel.rs @@ -20,8 +20,7 @@ async fn create_channel() { println!( "xcm call issued at block hash {:?}, transaction hash {:?}", - result.block_hash, - result.extrinsic_hash + result.block_hash, result.extrinsic_hash ); wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; diff --git a/smoketest/tests/register_polkadot_token.rs b/smoketest/tests/register_polkadot_token.rs index 48271c83fd..9c59347e64 100644 --- a/smoketest/tests/register_polkadot_token.rs +++ b/smoketest/tests/register_polkadot_token.rs @@ -6,10 +6,7 @@ use snowbridge_smoketest::{ bridgehub::api::{ ethereum_system::events::RegisterToken, runtime_types, - runtime_types::{ - bounded_collections::bounded_vec::BoundedVec, staging_xcm::v4::junction::NetworkId, - xcm::VersionedLocation, - }, + runtime_types::{bounded_collections::bounded_vec::BoundedVec, xcm::VersionedLocation}, }, }, }; @@ -20,10 +17,9 @@ async fn register_polkadot_token() { let test_clients = initial_clients().await.expect("initialize clients"); type Junctions = runtime_types::staging_xcm::v4::junctions::Junctions; - type Junction = runtime_types::staging_xcm::v4::junction::Junction; let asset = VersionedLocation::V4(runtime_types::staging_xcm::v4::location::Location { parents: 1, - interior: Junctions::X1([Junction::GlobalConsensus(NetworkId::Westend)]), + interior: Junctions::Here, }); let metadata = runtime_types::snowbridge_core::AssetMetadata { name: BoundedVec( diff --git a/smoketest/tests/transfer_native_from_agent.rs b/smoketest/tests/transfer_native_from_agent.rs index 61fa8732ab..f45c01f375 100644 --- a/smoketest/tests/transfer_native_from_agent.rs +++ b/smoketest/tests/transfer_native_from_agent.rs @@ -46,8 +46,7 @@ async fn transfer_native_from_agent() { println!( "xcm call issued at block hash {:?}, transaction hash {:?}", - result.block_hash, - result.extrinsic_hash + result.block_hash, result.extrinsic_hash ); wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; diff --git a/smoketest/tests/upgrade_gateway.rs b/smoketest/tests/upgrade_gateway.rs index 6c2d20a738..2ddd5ff91d 100644 --- a/smoketest/tests/upgrade_gateway.rs +++ b/smoketest/tests/upgrade_gateway.rs @@ -119,10 +119,7 @@ async fn upgrade_gateway() { println!("Sudo call issued at relaychain block hash {:?}", result.block_hash()); - result - .wait_for_success() - .await - .expect("sudo call success"); + result.wait_for_success().await.expect("sudo call success"); let wait_for_blocks = 5; let mut blocks = bridgehub diff --git a/web/packages/test/scripts/xcm-helper.sh b/web/packages/test/scripts/xcm-helper.sh index 6ca946f144..4d82bdca82 100644 --- a/web/packages/test/scripts/xcm-helper.sh +++ b/web/packages/test/scripts/xcm-helper.sh @@ -145,5 +145,6 @@ function call_polkadot_js_api() { # With it, it just submits it to the tx pool and exits. # --nonce -1: means to compute transaction nonce using `system_accountNextIndex` RPC, which includes all # transaction that are in the tx pool. - npx polkadot-js-api --noWait --nonce -1 "$@" || true + # TODO: add back nowait and nonce: npx polkadot-js-api --noWait --nonce -1 "$@" || true + npx polkadot-js-api "$@" || true }