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

Remove call index from the cross-chain interface #961

Merged
merged 131 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
fe22333
Support reserve deposit for control operations
yrong Aug 29, 2023
2d28b2b
Pay as agent_owner
yrong Aug 29, 2023
ffa44a7
Add AgentAccountDescription converter
yrong Aug 31, 2023
80a750c
Merge branch 'main' into ron/oak-sno-624
yrong Aug 31, 2023
33f6ab8
Revamp smoke test config fee for control operations
yrong Aug 31, 2023
6cc82e5
Add SovereignAccountOf to runtime config
yrong Aug 31, 2023
3e5e9ff
Merge branch 'main' into ron/oak-sno-624
yrong Sep 4, 2023
e9be7d4
Fix format
yrong Sep 4, 2023
e2946ee
More refactor
yrong Sep 4, 2023
cb6f6aa
Configurable base fee plus static per-operation fee multiplier
yrong Sep 5, 2023
614e429
Update smoke test accordingly
yrong Sep 5, 2023
ec7814b
Update cumulus
yrong Sep 5, 2023
2f939cd
Merge branch 'main' into ron/oak-sno-624
yrong Sep 7, 2023
e777666
Fix format
yrong Sep 7, 2023
a2ffa5d
Remove call index from the cross-chain interface
yrong Sep 8, 2023
b1854ca
Update test fixture
yrong Sep 8, 2023
b114082
Fix format
yrong Sep 8, 2023
8830961
Merge branch 'main' into ron/oak-sno-624
yrong Sep 11, 2023
3fef8b4
Configurable dispatch_gas
yrong Sep 12, 2023
d02f041
Update relayer
yrong Sep 12, 2023
aac06fc
Merge branch 'ron/oak-23' into ron/oak-sno-624
yrong Sep 12, 2023
353c21e
Refactor to charge fee for outbound commands
yrong Sep 13, 2023
7caed3e
More refactor
yrong Sep 13, 2023
77ebfb6
Update cargo.lock
yrong Sep 13, 2023
1694b38
Chore
yrong Sep 13, 2023
58fa4d7
Fix clippy
yrong Sep 13, 2023
82d2ed5
Chore format
yrong Sep 13, 2023
aca2309
Update cumulus
yrong Sep 13, 2023
0b1d744
Reward message relayer
yrong Sep 13, 2023
6aa80cc
Fix smoke tests
yrong Sep 13, 2023
755d50f
Set default dispatch gas
yrong Sep 14, 2023
63b7221
Fix for origin of control operations & Charge fee without gas cost
yrong Sep 14, 2023
a473f06
Update parachain/pallets/outbound-queue/src/lib.rs
yrong Sep 14, 2023
50a0b79
Update parachain/pallets/outbound-queue/src/lib.rs
yrong Sep 14, 2023
c834c49
Specify the fee for xcm export & upfront charge for create_agent only
yrong Sep 14, 2023
b3522cd
Remove deprecated config
yrong Sep 15, 2023
b6abf68
Fix format
yrong Sep 15, 2023
f976e1e
Set decent default for outbound configs
yrong Sep 15, 2023
16f89d2
Make create-channel upfront charged & start template relayer for othe…
yrong Sep 15, 2023
febc0a1
Disable base fee for sudo operations
yrong Sep 15, 2023
7477cc1
Merge branch 'main' into ron/oak-sno-624
yrong Sep 15, 2023
5fbbfb9
Update gas cost
yrong Sep 18, 2023
86c3ffc
Fix cargo tarpaulin
yrong Sep 18, 2023
488491b
Update RegisterCallIndex as runtime const
yrong Sep 19, 2023
ca06b35
Merge branch 'main' into ron/oak-30
yrong Sep 19, 2023
fdee5c2
Fix cargo tarpaulin
yrong Sep 18, 2023
dc4d898
Update cumulus
yrong Sep 22, 2023
0c4921c
Update cumulus
yrong Sep 22, 2023
3b784b2
Add OutboundFeeConfig
yrong Sep 22, 2023
4399ed0
Fund template sovereign account
yrong Sep 22, 2023
b477887
Rename as agent_location
yrong Sep 22, 2023
8870326
Fix clippy
yrong Sep 22, 2023
460e10d
Validate ticket with gas check
yrong Sep 22, 2023
448963a
Move the charge logic to control pallet & More refactor
yrong Sep 22, 2023
e8308f8
Fix clippy
yrong Sep 22, 2023
9d2594c
Disable format temporarily for less distraction
yrong Sep 22, 2023
f2350c1
Refactor estimate by message
yrong Sep 22, 2023
19e03e7
More refactor
yrong Sep 23, 2023
24e1ec1
Fix clippy
yrong Sep 23, 2023
2bcd6be
Introduce VersionedMessageToXcmConverter
yrong Sep 23, 2023
66fa4aa
Fix clippy
yrong Sep 23, 2023
8fbb705
More cleanup
yrong Sep 26, 2023
f531c71
Fix test & Remove format
yrong Sep 26, 2023
7bfae29
Add estimate rpc
yrong Sep 26, 2023
3175e02
Estimate by command index & Add smoke test accordingly
yrong Sep 27, 2023
0e61abe
Fix upgrade test
yrong Sep 27, 2023
1d160b0
Initialize with more funds & Add script for fund
yrong Sep 27, 2023
8455abc
Update contracts/test/Gateway.t.sol
yrong Sep 27, 2023
b46f889
Rename event as OutboundFeeConfigUpdated
yrong Sep 27, 2023
98aafba
Merge branch 'ron/oak-sno-624' of https://github.com/Snowfork/snowbri…
yrong Sep 27, 2023
6aed8d0
For comment
yrong Sep 27, 2023
c8cd91e
Chore
yrong Sep 27, 2023
309ce5a
Refactor with structured OriginInfo
yrong Sep 27, 2023
4a8730d
Clean derive macros
yrong Sep 27, 2023
dd6a21f
Leave enough space for upgrade
yrong Sep 27, 2023
a6649d8
Runtime api for compute_fee_reward
yrong Sep 27, 2023
6dfe502
Use TreasuryAccount more specific
yrong Sep 28, 2023
aab0ec0
Improve comments
yrong Sep 28, 2023
2db5125
Improve smoke test
yrong Sep 28, 2023
d8ced19
Update smoketest/src/helper.rs
yrong Sep 28, 2023
cde7c8d
Update smoketest/src/helper.rs
yrong Sep 28, 2023
9d99217
Some cleanup
yrong Sep 28, 2023
586b8b8
Update cumulus
yrong Sep 28, 2023
ef3395e
Merge branch 'ron/oak-sno-624' of https://github.com/Snowfork/snowbri…
yrong Sep 28, 2023
378ca74
Test for fee with config changed
yrong Sep 28, 2023
9a905a4
A thin shell wrapper funding agent
yrong Sep 28, 2023
05abc2c
More tests
yrong Sep 28, 2023
a664567
foo
vgeddes Sep 29, 2023
154c906
foo
vgeddes Oct 2, 2023
4a1da14
fix tests
vgeddes Oct 2, 2023
6a93a29
compilation works
vgeddes Oct 3, 2023
7223158
Update cumulus
vgeddes Oct 3, 2023
bf777fd
improve benchmarks
vgeddes Oct 3, 2023
77a0cb3
fix benchmarks
vgeddes Oct 4, 2023
8017f96
update cumulus
vgeddes Oct 4, 2023
d6eeedf
fix clippy errors
vgeddes Oct 4, 2023
3a0ef5b
Update Cargo.lock
vgeddes Oct 4, 2023
cdd5576
update cumulus
vgeddes Oct 4, 2023
f986743
Remove obsolete fee estimation code
vgeddes Oct 4, 2023
dc0d5c9
Use full polkadot repository URL in Cargo.toml
vgeddes Oct 4, 2023
7c6f69a
Update cumulus fix for smoke test
yrong Oct 5, 2023
670632b
Fix format
yrong Oct 5, 2023
f868e29
Merge branch 'vincent/outbound-fees' into ron/oak-30
yrong Oct 5, 2023
8df7f90
Introduce VersionedMessageToXcmConverter
yrong Sep 23, 2023
e09444b
Fix xcm instruction
yrong Oct 5, 2023
6b29295
Chore
yrong Oct 5, 2023
2a9633b
remove relayers for template node
vgeddes Oct 7, 2023
707593d
Improve the implementation of the control pallet
vgeddes Oct 8, 2023
2be28f9
fix broken bindings generator for smoketests
vgeddes Oct 8, 2023
71c1159
update cumulus submodule
vgeddes Oct 8, 2023
2b84f6b
Update benchmarks
vgeddes Oct 8, 2023
41ecd8a
Fix clippy
yrong Oct 9, 2023
8a00986
Cleanup
yrong Oct 9, 2023
84bed37
Revert "remove relayers for template node"
yrong Oct 9, 2023
3365c1b
Fix agent id
yrong Oct 9, 2023
f5f1bd8
Merge branch 'vincent/outbound-fees' of https://github.com/Snowfork/s…
yrong Oct 9, 2023
18a90eb
Update inbound MessageConverter
yrong Oct 9, 2023
3f924b1
Add runtime api for generating agent ids
vgeddes Oct 9, 2023
6e9dfd3
Improve benchmarking code
vgeddes Oct 9, 2023
f0309c9
Fix for smoke test to create agent
yrong Oct 10, 2023
5c80f91
Merge branch 'vincent/outbound-fees' into ron/oak-30
yrong Oct 10, 2023
2526725
Update cumulus
yrong Oct 10, 2023
a0a3ac2
mark some config items as pallet constants
vgeddes Oct 10, 2023
1d75ffc
Some polish
yrong Oct 10, 2023
3904a32
Polish
yrong Oct 10, 2023
12824ba
Minor improvements to reward logic in Gateway
vgeddes Oct 10, 2023
40e60f2
Improve Gateway tests
vgeddes Oct 10, 2023
58558e5
update cumulus submodule
vgeddes Oct 10, 2023
4b5a4b7
Merge branch 'vincent/outbound-fees' into ron/oak-30
yrong Oct 11, 2023
194c7dd
Merge branch 'main' into ron/oak-30
yrong Oct 17, 2023
6d37669
Fix convert
yrong Oct 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/parachain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ jobs:
run: rustup show
- name: run coverage test
run: >
cargo install cargo-tarpaulin &&
cargo install cargo-tarpaulin@0.27.0 &&
cargo tarpaulin
--manifest-path parachain/Cargo.toml
--workspace
--engine llvm
--out Xml
--exclude substrate-call-index
--exclude snowbridge-query-events
--out xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
Expand All @@ -133,7 +131,7 @@ jobs:
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
submodules: "true"
- uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
7 changes: 2 additions & 5 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,14 @@ library Assets {

/// @dev Enqueues a create native token message to substrate.
/// @param token The ERC20 token address.
function registerToken(address token, bytes2 createTokenCallID)
external
returns (bytes memory payload, uint256 extraFee)
{
yrong marked this conversation as resolved.
Show resolved Hide resolved
function registerToken(address token) external returns (bytes memory payload, uint256 extraFee) {
AssetsStorage.Layout storage $ = AssetsStorage.layout();

if (!token.isContract()) {
revert InvalidToken();
}

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

emit TokenRegistrationSent(token);
Expand Down
9 changes: 2 additions & 7 deletions contracts/src/DeployScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,14 @@ contract DeployScript is Script {
Gateway gatewayLogic = new Gateway(
address(beefyClient),
address(executor),
vm.envUint("DISPATCH_GAS"),
bridgeHubParaID,
bridgeHubAgentID,
assetHubParaID,
assetHubAgentID,
bytes2(vm.envBytes("CREATE_CALL_INDEX"))
assetHubAgentID
);

bytes memory initParams = abi.encode(
vm.envUint("DEFAULT_FEE"),
vm.envUint("DEFAULT_REWARD"),
vm.envUint("REGISTER_NATIVE_TOKEN_FEE"),
vm.envUint("SEND_NATIVE_TOKEN_FEE")
vm.envUint("DEFAULT_FEE"), vm.envUint("REGISTER_NATIVE_TOKEN_FEE"), vm.envUint("SEND_NATIVE_TOKEN_FEE")
);

GatewayProxy gateway = new GatewayProxy(address(gatewayLogic), initParams);
Expand Down
46 changes: 46 additions & 0 deletions contracts/src/FundAgent.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
pragma solidity 0.8.20;

import {WETH9} from "canonical-weth/WETH9.sol";
import {Script} from "forge-std/Script.sol";
import {BeefyClient} from "./BeefyClient.sol";

import {IGateway} from "./interfaces/IGateway.sol";
import {GatewayProxy} from "./GatewayProxy.sol";
import {Gateway} from "./Gateway.sol";
import {GatewayUpgradeMock} from "../test/mocks/GatewayUpgradeMock.sol";
import {Agent} from "./Agent.sol";
import {AgentExecutor} from "./AgentExecutor.sol";
import {ParaID, Config} from "./Types.sol";
import {SafeNativeTransfer} from "./utils/SafeTransfer.sol";
import {stdJson} from "forge-std/StdJson.sol";

contract FundAgent is Script {
using SafeNativeTransfer for address payable;
using stdJson for string;

function setUp() public {}

function run() public {
uint256 privateKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.rememberKey(privateKey);
vm.startBroadcast(deployer);

uint256 initialDeposit = vm.envUint("BRIDGE_HUB_INITIAL_DEPOSIT");
address gatewayAddress = vm.envAddress("GATEWAY_PROXY_CONTRACT");

ParaID bridgeHubParaID = ParaID.wrap(vm.envUint("BRIDGE_HUB_PARAID"));
bytes32 bridgeHubAgentID = vm.envBytes32("BRIDGE_HUB_AGENT_ID");
ParaID assetHubParaID = ParaID.wrap(vm.envUint("ASSET_HUB_PARAID"));
bytes32 assetHubAgentID = vm.envBytes32("ASSET_HUB_AGENT_ID");

address bridgeHubAgent = IGateway(gatewayAddress).agentOf(bridgeHubAgentID);
address assetHubAgent = IGateway(gatewayAddress).agentOf(assetHubAgentID);

payable(bridgeHubAgent).safeNativeTransfer(initialDeposit);
payable(assetHubAgent).safeNativeTransfer(initialDeposit);

vm.stopBroadcast();
}
}
101 changes: 57 additions & 44 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ contract Gateway is IGateway, IInitializable {
using SafeNativeTransfer for address payable;

// After message dispatch, there should be some gas left over for post dispatch logic
uint256 internal constant BUFFER_GAS = 32_000;
uint256 internal immutable DISPATCH_GAS;
uint256 internal constant BUFFER_GAS = 48_000;
address internal immutable AGENT_EXECUTOR;

// Verification state
Expand All @@ -40,7 +39,12 @@ contract Gateway is IGateway, IInitializable {
// AssetHub
ParaID internal immutable ASSET_HUB_PARA_ID;
bytes32 internal immutable ASSET_HUB_AGENT_ID;
bytes2 internal immutable CREATE_TOKEN_CALL_ID;

// Fixed amount of gas used outside the gas metering in submitInbound
uint256 BASE_GAS_USED = 31000;

// minimum amount of gas required to transfer eth
uint256 MINIMUM_THRESHOLD_GAS = 21000;

error InvalidProof();
error InvalidNonce();
Expand Down Expand Up @@ -69,30 +73,25 @@ contract Gateway is IGateway, IInitializable {
constructor(
address beefyClient,
address agentExecutor,
uint256 dispatchGas,
ParaID bridgeHubParaID,
bytes32 bridgeHubAgentID,
ParaID assetHubParaID,
bytes32 assetHubAgentID,
bytes2 createTokenCallID
bytes32 assetHubAgentID
) {
if (
dispatchGas == 0 || bridgeHubParaID == ParaID.wrap(0) || bridgeHubAgentID == 0
|| assetHubParaID == ParaID.wrap(0) || assetHubAgentID == 0 || bridgeHubParaID == assetHubParaID
|| bridgeHubAgentID == assetHubAgentID
bridgeHubParaID == ParaID.wrap(0) || bridgeHubAgentID == 0 || assetHubParaID == ParaID.wrap(0)
|| assetHubAgentID == 0 || bridgeHubParaID == assetHubParaID || bridgeHubAgentID == assetHubAgentID
) {
revert InvalidConstructorParams();
}

BEEFY_CLIENT = beefyClient;
AGENT_EXECUTOR = agentExecutor;
DISPATCH_GAS = dispatchGas;
BRIDGE_HUB_PARA_ID_ENCODED = ScaleCodec.encodeU32(uint32(ParaID.unwrap(bridgeHubParaID)));
BRIDGE_HUB_PARA_ID = bridgeHubParaID;
BRIDGE_HUB_AGENT_ID = bridgeHubAgentID;
ASSET_HUB_PARA_ID = assetHubParaID;
ASSET_HUB_AGENT_ID = assetHubAgentID;
CREATE_TOKEN_CALL_ID = createTokenCallID;
}

/// @dev Submit a message from Polkadot for verification and dispatch
Expand All @@ -104,6 +103,8 @@ contract Gateway is IGateway, IInitializable {
bytes32[] calldata leafProof,
Verification.Proof calldata headerProof
) external {
uint256 startGas = gasleft();

Channel storage channel = _ensureChannel(message.origin);

// Ensure this message is not being replayed
Expand All @@ -116,13 +117,6 @@ contract Gateway is IGateway, IInitializable {
// again with the same (message, leafProof, headerProof) arguments.
channel.inboundNonce++;

// Reward the relayer from the agent contract
// Expected to revert if the agent for the message origin does not have enough funds to reward the relayer.
// In that case, the origin should top up the funds of their agent.
if (channel.reward > 0) {
_transferNativeFromAgent(channel.agent, payable(msg.sender), channel.reward);
}

// Produce the commitment (message root) by applying the leaf proof to the message leaf
bytes32 leafHash = keccak256(abi.encode(message));
bytes32 commitment = MerkleProof.processProof(leafProof, leafHash);
Expand All @@ -136,53 +130,81 @@ contract Gateway is IGateway, IInitializable {
// Otherwise malicious relayers can break the bridge by allowing the message handlers below to run out gas and fail silently.
// In this scenario case, the channel's state would have been updated to accept the message (by virtue of the nonce increment), yet the actual message
// dispatch would have failed
if (gasleft() < DISPATCH_GAS + BUFFER_GAS) {
uint256 maxDispatchGas = message.maxDispatchGas;
if (gasleft() < maxDispatchGas + BUFFER_GAS) {
revert NotEnoughGas();
}

bool success = true;

// Dispatch message to a handler
if (message.command == Command.AgentExecute) {
try Gateway(this).agentExecute{gas: DISPATCH_GAS}(message.params) {}
try Gateway(this).agentExecute{gas: maxDispatchGas}(message.params) {}
catch {
success = false;
}
} else if (message.command == Command.CreateAgent) {
try Gateway(this).createAgent{gas: DISPATCH_GAS}(message.params) {}
try Gateway(this).createAgent{gas: maxDispatchGas}(message.params) {}
catch {
success = false;
}
} else if (message.command == Command.CreateChannel) {
try Gateway(this).createChannel{gas: DISPATCH_GAS}(message.params) {}
try Gateway(this).createChannel{gas: maxDispatchGas}(message.params) {}
catch {
success = false;
}
} else if (message.command == Command.UpdateChannel) {
try Gateway(this).updateChannel{gas: DISPATCH_GAS}(message.params) {}
try Gateway(this).updateChannel{gas: maxDispatchGas}(message.params) {}
catch {
success = false;
}
} else if (message.command == Command.SetOperatingMode) {
try Gateway(this).setOperatingMode{gas: DISPATCH_GAS}(message.params) {}
try Gateway(this).setOperatingMode{gas: maxDispatchGas}(message.params) {}
catch {
success = false;
}
} else if (message.command == Command.TransferNativeFromAgent) {
try Gateway(this).transferNativeFromAgent{gas: DISPATCH_GAS}(message.params) {}
try Gateway(this).transferNativeFromAgent{gas: maxDispatchGas}(message.params) {}
catch {
success = false;
}
} else if (message.command == Command.Upgrade) {
try Gateway(this).upgrade{gas: DISPATCH_GAS}(message.params) {}
try Gateway(this).upgrade{gas: maxDispatchGas}(message.params) {}
catch {
success = false;
}
}

// Calculate the remaining funds in the channel agent contract
uint256 agentBalance = channel.agent.balance;
if (channel.agent.balance <= MINIMUM_THRESHOLD_GAS * tx.gasprice) {
agentBalance = 0;
}

// Calculate the gas refund
uint256 gasUsed = startGas - gasleft() + BASE_GAS_USED;
uint256 refund = gasUsed * tx.gasprice;

// Add the reward to the refund amount. If the sum is more than the funds available
// in the channel agent, then reduce the total amount
uint256 amount = _min(refund + message.reward, agentBalance);

// Do the payment if there funds available in the agent
if (amount > 0) {
_transferNativeFromAgent(channel.agent, payable(msg.sender), amount);
}

emit IGateway.InboundMessageDispatched(message.origin, message.nonce, success);
}

function _min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}

function _max(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? b : a;
}

/**
* Getters
*/
Expand All @@ -201,9 +223,9 @@ contract Gateway is IGateway, IInitializable {
return (ch.inboundNonce, ch.outboundNonce);
}

function channelFeeRewardOf(ParaID paraID) external view returns (uint256, uint256) {
function channelFeeOf(ParaID paraID) external view returns (uint256) {
Channel storage ch = _ensureChannel(paraID);
return (ch.fee, ch.reward);
return ch.fee;
}

function agentOf(bytes32 agentID) external view returns (address) {
Expand Down Expand Up @@ -291,7 +313,6 @@ contract Gateway is IGateway, IInitializable {
ch.inboundNonce = 0;
ch.outboundNonce = 0;
ch.fee = $.defaultFee;
ch.reward = $.defaultReward;

emit ChannelCreated(params.paraID);
}
Expand All @@ -313,18 +334,13 @@ contract Gateway is IGateway, IInitializable {

Channel storage ch = _ensureChannel(params.paraID);

// Extra sanity checks when updating the BridgeHub channel. For example, a huge reward could
// effectively brick the bridge permanently.
if (
params.paraID == BRIDGE_HUB_PARA_ID
&& (params.mode != OperatingMode.Normal || params.fee > 1 ether || params.reward > 1 ether)
) {
// Extra sanity checks when updating the BridgeHub channel, which should never be paused.
if (params.paraID == BRIDGE_HUB_PARA_ID && (params.mode != OperatingMode.Normal || params.fee > 1 ether)) {
revert InvalidChannelUpdate();
}

ch.mode = params.mode;
ch.fee = params.fee;
ch.reward = params.reward;

emit ChannelUpdated(params.paraID);
}
Expand Down Expand Up @@ -408,7 +424,7 @@ contract Gateway is IGateway, IInitializable {

// Register a token on AssetHub
function registerToken(address token) external payable {
(bytes memory payload, uint256 extraFee) = Assets.registerToken(token, CREATE_TOKEN_CALL_ID);
(bytes memory payload, uint256 extraFee) = Assets.registerToken(token);

_submitOutbound(ASSET_HUB_PARA_ID, payload, extraFee);
}
Expand Down Expand Up @@ -529,14 +545,13 @@ contract Gateway is IGateway, IInitializable {
revert Unauthorized();
}

(uint256 defaultFee, uint256 defaultReward, uint256 registerTokenFee, uint256 sendTokenFee) =
abi.decode(data, (uint256, uint256, uint256, uint256));
(uint256 defaultFee, uint256 registerTokenFee, uint256 sendTokenFee) =
abi.decode(data, (uint256, uint256, uint256));

CoreStorage.Layout storage $ = CoreStorage.layout();

$.mode = OperatingMode.Normal;
$.defaultFee = defaultFee;
$.defaultReward = defaultReward;

// Initialize an agent & channel for BridgeHub
address bridgeHubAgent = address(new Agent(BRIDGE_HUB_AGENT_ID));
Expand All @@ -546,8 +561,7 @@ contract Gateway is IGateway, IInitializable {
agent: bridgeHubAgent,
inboundNonce: 0,
outboundNonce: 0,
fee: defaultFee,
reward: defaultReward
fee: defaultFee
});

// Initialize an agent & channel for AssetHub
Expand All @@ -558,8 +572,7 @@ contract Gateway is IGateway, IInitializable {
agent: assetHubAgent,
inboundNonce: 0,
outboundNonce: 0,
fee: defaultFee,
reward: defaultReward
fee: defaultFee
});

Assets.initialize(registerTokenFee, sendTokenFee);
Expand Down
9 changes: 2 additions & 7 deletions contracts/src/SubstrateTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,13 @@ library SubstrateTypes {
* `NativeTokensMessage::Create`
*/
// solhint-disable-next-line func-name-mixedcase
function RegisterToken(address gateway, address token, bytes2 createCallIndex)
internal
view
returns (bytes memory)
{
yrong marked this conversation as resolved.
Show resolved Hide resolved
function RegisterToken(address gateway, 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),
createCallIndex
SubstrateTypes.H160(token)
);
}

Expand Down
Loading
Loading