Skip to content

Commit

Permalink
remove gateway from inbound channel
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Nov 1, 2023
1 parent 5080f1e commit 96afc11
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 195 deletions.
6 changes: 3 additions & 3 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ library Assets {

_transferToAgent(assetHubAgent, token, sender, amount);
if (destinationChain == assetHubParaID) {
payload = SubstrateTypes.SendToken(address(this), token, destinationAddress, amount);
payload = SubstrateTypes.SendToken(token, destinationAddress, amount);
} else {
payload = SubstrateTypes.SendToken(address(this), token, destinationChain, destinationAddress, amount);
payload = SubstrateTypes.SendToken(token, destinationChain, destinationAddress, amount);
}
extraFee = $.sendTokenFee;

Expand Down Expand Up @@ -102,7 +102,7 @@ library Assets {
revert InvalidToken();
}

payload = SubstrateTypes.RegisterToken(address(this), token);
payload = SubstrateTypes.RegisterToken(token);
extraFee = $.registerTokenFee;

emit TokenRegistrationSent(token);
Expand Down
18 changes: 4 additions & 14 deletions contracts/src/SubstrateTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ library SubstrateTypes {
* `NativeTokensMessage::Create`
*/
// solhint-disable-next-line func-name-mixedcase
function RegisterToken(address gateway, address token) internal view returns (bytes memory) {
function RegisterToken(address token) internal view returns (bytes memory) {
return bytes.concat(
bytes1(0x00),
ScaleCodec.encodeU64(uint64(block.chainid)),
bytes1(0x00),
SubstrateTypes.H160(gateway),
SubstrateTypes.H160(token)
bytes1(0x00), ScaleCodec.encodeU64(uint64(block.chainid)), bytes1(0x00), SubstrateTypes.H160(token)
);
}

Expand All @@ -71,24 +67,19 @@ library SubstrateTypes {
* `NativeTokensMessage::Mint`
*/
// solhint-disable-next-line func-name-mixedcase
function SendToken(address gateway, address token, bytes32 recipient, uint128 amount)
internal
view
returns (bytes memory)
{
function SendToken(address token, bytes32 recipient, uint128 amount) internal view returns (bytes memory) {
return bytes.concat(
bytes1(0x00),
ScaleCodec.encodeU64(uint64(block.chainid)),
bytes1(0x01),
SubstrateTypes.H160(gateway),
SubstrateTypes.H160(token),
bytes1(0x00),
recipient,
ScaleCodec.encodeU128(amount)
);
}

function SendToken(address gateway, address token, ParaID paraID, bytes32 recipient, uint128 amount)
function SendToken(address token, ParaID paraID, bytes32 recipient, uint128 amount)
internal
view
returns (bytes memory)
Expand All @@ -97,7 +88,6 @@ library SubstrateTypes {
bytes1(0x00),
ScaleCodec.encodeU64(uint64(block.chainid)),
bytes1(0x01),
SubstrateTypes.H160(gateway),
SubstrateTypes.H160(token),
bytes1(0x01),
ScaleCodec.encodeU32(uint32(ParaID.unwrap(paraID))),
Expand Down
10 changes: 4 additions & 6 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ contract GatewayTest is Test {
emit TokenRegistrationSent(address(token));

vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token)));
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(token)));

IGateway(address(gateway)).registerToken{value: 2 ether}(address(token));
}
Expand All @@ -542,7 +542,7 @@ contract GatewayTest is Test {
emit TokenRegistrationSent(address(token));

vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(gateway), address(token)));
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.RegisterToken(address(token)));

uint256 totalFee = baseFee + registerNativeTokenFee;
uint256 balanceBefore = address(this).balance;
Expand All @@ -569,7 +569,7 @@ contract GatewayTest is Test {
// Expect the gateway to emit `OutboundMessageAccepted`
vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(
assetHubParaID, 1, SubstrateTypes.SendToken(address(gateway), address(token), destPara, destAddress, 1)
assetHubParaID, 1, SubstrateTypes.SendToken(address(token), destPara, destAddress, 1)
);

IGateway(address(gateway)).sendToken{value: 2 ether}(address(token), destPara, destAddress, 1);
Expand All @@ -588,9 +588,7 @@ contract GatewayTest is Test {

// Expect the gateway to emit `OutboundMessageAccepted`
vm.expectEmit(true, false, false, false);
emit OutboundMessageAccepted(
assetHubParaID, 1, SubstrateTypes.SendToken(address(gateway), address(token), destAddress, 1)
);
emit OutboundMessageAccepted(assetHubParaID, 1, SubstrateTypes.SendToken(address(token), destAddress, 1));

IGateway(address(gateway)).sendToken{value: 2 ether}(address(token), destPara, destAddress, 1);
}
Expand Down
12 changes: 6 additions & 6 deletions parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ fn parse_dest(message: Message) -> ParaId {
}

// dest para is 1000
const OUTBOUND_QUEUE_EVENT_LOG: [u8; 253] = hex!(
const OUTBOUND_QUEUE_EVENT_LOG: [u8; 221] = hex!(
"
f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032000f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000
f8db94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000
"
);

Expand All @@ -238,18 +238,18 @@ const OUTBOUND_QUEUE_EVENT_LOG_INVALID_DEST: [u8; 253] = hex!(
);

// gateway in message does not match configured gateway in runtime
const BAD_OUTBOUND_QUEUE_EVENT_LOG: [u8; 253] = hex!(
const BAD_OUTBOUND_QUEUE_EVENT_LOG: [u8; 221] = hex!(
"
f8fb940000000000000000000000000000000000000000f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e9b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032000f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000
f8db940000000000000000000000000000000000000000f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b88000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001e000f000000000000000087d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000
"
);

// invalid payload with unsupported version
const BAD_OUTBOUND_QUEUE_LOG_UNSUPPORTED_VERSION: [u8; 253] = hex!("f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000032010f0000000000000000eda338e4dc46038493b885327842fd3e301cab3987d1f7fdfee7f651fabc8bfcb6e086c278b77a7d0000000000000000000000000000");

const XCM_HASH: [u8; 32] = [
232, 213, 62, 94, 48, 47, 152, 37, 168, 162, 89, 100, 6, 74, 63, 95, 211, 11, 222, 210, 1, 209,
126, 44, 164, 122, 166, 156, 208, 228, 209, 9,
186, 27, 67, 39, 117, 164, 224, 191, 202, 232, 218, 108, 34, 65, 36, 199, 247, 19, 150, 198,
182, 180, 39, 112, 150, 64, 84, 15, 174, 213, 183, 207,
];
const ASSET_HUB_PARAID: u32 = 1000u32;

Expand Down
Loading

0 comments on commit 96afc11

Please sign in to comment.