Skip to content

Commit

Permalink
Remove destination parachain transfer from PNA (#1284)
Browse files Browse the repository at this point in the history
* remove destination fee from PNA

* fmt
  • Loading branch information
alistair-singh committed Sep 11, 2024
1 parent c2af15e commit 77b4c04
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 59 deletions.
12 changes: 10 additions & 2 deletions contracts/scripts/DeployBeefyClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 6 additions & 36 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/BeefyClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ contract BeefyClient {
validatorSetLen: uint32(vset.length),
numRequiredSignatures: uint32(
computeNumRequiredSignatures(vset.length, signatureUsageCount, minNumRequiredSignatures)
),
),
prevRandao: 0,
bitfieldHash: keccak256(abi.encodePacked(bitfield))
});
Expand Down
44 changes: 43 additions & 1 deletion contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions contracts/test/mocks/BitfieldWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions smoketest/tests/create_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CreateAgent>(&test_clients.bridge_hub_client).await;
Expand Down
3 changes: 1 addition & 2 deletions smoketest/tests/create_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CreateChannel>(&test_clients.bridge_hub_client).await;
Expand Down
8 changes: 2 additions & 6 deletions smoketest/tests/register_polkadot_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
};
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions smoketest/tests/transfer_native_from_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TransferNativeFromAgent>(&test_clients.bridge_hub_client).await;
Expand Down
5 changes: 1 addition & 4 deletions smoketest/tests/upgrade_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion web/packages/test/scripts/xcm-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 77b4c04

Please sign in to comment.