Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes committed Oct 27, 2024
1 parent c0bab8a commit eae219e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 26 deletions.
24 changes: 17 additions & 7 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -500,21 +500,31 @@ contract Gateway is IGateway, IInitializable, IUpgradable {
return true;
}

function v2_isDispatched(uint64 nonce) external view returns (bool) {
CoreStorage.Layout storage $ = CoreStorage.layout();
return $.inboundNonce.get(nonce);
}

// See docs for `IGateway.sendMessage`
function sendMessage(bytes calldata xcm, bytes[] calldata assets) external payable {
CallsV2.sendMessage(xcm, assets);
function v2_sendMessage(
bytes calldata xcm,
bytes[] calldata assets,
bytes calldata claimer
) external payable {
CallsV2.sendMessage(xcm, assets, claimer);
}

// See docs for `IGateway.registerToken`
function registerToken(address token, uint128 xcmFeeAHP) external payable {
function v2_registerToken(address token, uint128 xcmFeeAHP) external payable {
CallsV2.registerToken(token, xcmFeeAHP);
}

// See docs for `IGateway.registerTokenOnKusama`
function registerTokenOnKusama(address token, uint128 xcmFeeAHP, uint128 xcmFeeAHK)
external
payable
{
function v2_registerTokenOnKusama(
address token,
uint128 xcmFeeAHP,
uint128 xcmFeeAHK
) external payable {
CallsV2.registerTokenOnKusama(token, xcmFeeAHP, xcmFeeAHK);
}

Expand Down
28 changes: 22 additions & 6 deletions contracts/src/SubstrateTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ library SubstrateTypes {
}
}

// solhint-disable-next-line func-name-mixedcase
function OptionVecU8(bytes memory v) internal pure returns (bytes memory) {
if (v.length == 0) {
return hex"00";
} else {
return bytes.concat(bytes1(0x01), VecU8(v));
}
}

/**
* @dev SCALE-encodes `router_primitives::inbound::VersionedMessage` containing payload
* `NativeTokensMessage::Create`
Expand Down Expand Up @@ -213,14 +222,21 @@ library SubstrateTypes {
// origin: H160,
// assets: Vec<Asset>
// xcm: Vec<u8>
// claimer: Option<Vec<u8>>
// }
// ```
//
function encodePayloadV2(address origin, bytes[] memory assets, bytes memory xcm)
internal
pure
returns (bytes memory)
{
return bytes.concat(abi.encodePacked(origin), VecAsset(assets), VecU8(xcm));
//
//
function encodePayloadV2(
address origin,
bytes[] memory assets,
bytes memory xcm,
bytes memory claimer
) internal pure returns (bytes memory) {
return bytes.concat(
abi.encodePacked(origin), VecAsset(assets), VecU8(xcm), OptionVecU8(claimer)
);
}

// Encode `Vec<Asset>`
Expand Down
19 changes: 14 additions & 5 deletions contracts/src/interfaces/IGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,24 @@ interface IGateway {
// at least cover the total cost of delivery to Polkadot. This ether be sent across
// the bridge as WETH, and given to the relayer as compensation and incentivization.
//
function sendMessage(bytes calldata xcm, bytes[] calldata assets) external payable;
function v2_sendMessage(
bytes calldata xcm,
bytes[] calldata assets,
bytes calldata claimer
) external payable;

// Register Ethereum-native token on AHP, using `xcmFeeAHP` of `msg.value`
// to pay for execution on AHP.
function registerToken(address token, uint128 xcmFeeAHP) external payable;
function v2_registerToken(address token, uint128 xcmFeeAHP) external payable;

// Register Ethereum-native token on AHK, using `xcmFeeAHP` and `xcmFeeAHK`
// of `msg.value` to pay for execution on AHP and AHK respectively.
function registerTokenOnKusama(address token, uint128 xcmFeeAHP, uint128 xcmFeeAHK)
external
payable;
function v2_registerTokenOnKusama(
address token,
uint128 xcmFeeAHP,
uint128 xcmFeeAHK
) external payable;

// Check if an inbound message was previously accepted and dispatched
function v2_isDispatched(uint64 nonce) external returns (bool);
}
25 changes: 18 additions & 7 deletions contracts/src/v2/Calls.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ library CallsV2 {
// 2. Handle the assets in holding, either depositing them into
// some account, or forwarding them to another destination.
//
function sendMessage(bytes calldata xcm, bytes[] calldata assets) external {
_sendMessage(msg.sender, xcm, assets, msg.value);
function sendMessage(
bytes calldata xcm,
bytes[] calldata assets,
bytes calldata claimer
) external {
_sendMessage(msg.sender, xcm, assets, claimer, msg.value);
}

// Register Ethereum-native token on AHP, using `xcmFeeAHP` of `msg.value`
Expand All @@ -96,6 +100,7 @@ library CallsV2 {
address origin,
bytes memory xcm,
bytes[] memory assets,
bytes memory claimer,
uint256 reward
) internal {
if (assets.length > MAX_ASSETS) {
Expand All @@ -106,8 +111,13 @@ library CallsV2 {
for (uint256 i = 0; i < assets.length; i++) {
encodedAssets[i] = _handleAsset(assets[i]);
}
Ticket memory ticket =
Ticket({origin: origin, assets: encodedAssets, xcm: xcm, reward: reward});
Ticket memory ticket = Ticket({
origin: origin,
assets: encodedAssets,
xcm: xcm,
claimer: claimer,
reward: reward
});
_submitOutbound(ticket);
}

Expand Down Expand Up @@ -138,7 +148,7 @@ library CallsV2 {
bytes[] memory assets = new bytes[](1);
assets[0] = abi.encode(0, WETH_ADDRESS, xcmFee);

_sendMessage(address(this), xcm, assets, msg.value - xcmFee);
_sendMessage(address(this), xcm, assets, "", msg.value - xcmFee);
}

// Submit an outbound message to Polkadot, after taking fees
Expand All @@ -153,8 +163,9 @@ library CallsV2 {

$.outboundNonce = $.outboundNonce + 1;

bytes memory payload =
SubstrateTypes.encodePayloadV2(ticket.origin, ticket.assets, ticket.xcm);
bytes memory payload = SubstrateTypes.encodePayloadV2(
ticket.origin, ticket.assets, ticket.xcm, ticket.claimer
);

emit IGateway.OutboundMessageAccepted($.outboundNonce, ticket.reward, payload);
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/v2/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct InboundMessage {

struct Command {
uint8 kind;
uint256 gas;
uint64 gas;
bytes payload;
}

Expand All @@ -34,6 +34,7 @@ struct Ticket {
address origin;
bytes[] assets;
bytes xcm;
bytes claimer;
uint256 reward;
}

Expand Down

0 comments on commit eae219e

Please sign in to comment.