From 0a2cb1682245675f5189147702a126583eccc1c2 Mon Sep 17 00:00:00 2001 From: ron Date: Tue, 7 Nov 2023 11:25:23 +0800 Subject: [PATCH] Improve for the comments --- contracts/src/Gateway.sol | 2 +- contracts/src/interfaces/IGateway.sol | 4 ++-- contracts/test/Gateway.t.sol | 5 ++++- parachain/pallets/control/src/lib.rs | 10 ++++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/contracts/src/Gateway.sol b/contracts/src/Gateway.sol index 2cf49bd918..281304e73c 100644 --- a/contracts/src/Gateway.sol +++ b/contracts/src/Gateway.sol @@ -434,7 +434,7 @@ contract Gateway is IGateway, IInitializable { SetTokenTransferFeesParams memory params = abi.decode(data, (SetTokenTransferFeesParams)); $.registerTokenFee = params.register; $.sendTokenFee = params.send; - emit SetTokenTransferFees(params.register, params.send); + emit TokenTransferFeesChanged(params.register, params.send); } /** diff --git a/contracts/src/interfaces/IGateway.sol b/contracts/src/interfaces/IGateway.sol index 3dc568112f..9230a29e5d 100644 --- a/contracts/src/interfaces/IGateway.sol +++ b/contracts/src/interfaces/IGateway.sol @@ -35,7 +35,7 @@ interface IGateway { event AgentFundsWithdrawn(bytes32 indexed agentID, address indexed recipient, uint256 amount); // Emitted when the fees updated - event SetTokenTransferFees(uint256 register, uint256 send); + event TokenTransferFeesChanged(uint256 register, uint256 send); /// @dev Emitted once the funds are locked and a message is successfully queued. event TokenSent( address indexed token, address indexed sender, ParaID destinationChain, bytes destinationAddress, uint128 amount @@ -52,7 +52,6 @@ interface IGateway { function channelNoncesOf(ParaID paraID) external view returns (uint64, uint64); function agentOf(bytes32 agentID) external view returns (address); function implementation() external view returns (address); - function tokenTransferFees() external view returns (uint256, uint256); /** * Messaging @@ -68,6 +67,7 @@ interface IGateway { /** * Token Transfers */ + function tokenTransferFees() external view returns (uint256, uint256); /// @dev Send a message to the AssetHub parachain to register a new fungible asset /// in the `ForeignAssets` pallet. diff --git a/contracts/test/Gateway.t.sol b/contracts/test/Gateway.t.sol index e0ec6db150..2b1bcb573b 100644 --- a/contracts/test/Gateway.t.sol +++ b/contracts/test/Gateway.t.sol @@ -751,10 +751,13 @@ contract GatewayTest is Test { } function testSetTokenFees() public { + (uint256 register, uint256 send) = IGateway(address(gateway)).tokenTransferFees(); + assertEq(register, 1 ether); + assertEq(send, 1 ether); GatewayMock(address(gateway)).setTokenTransferFeesPublic( abi.encode(Gateway.SetTokenTransferFeesParams({register: 1, send: 1})) ); - (uint256 register, uint256 send) = IGateway(address(gateway)).tokenTransferFees(); + (register, send) = IGateway(address(gateway)).tokenTransferFees(); assertEq(register, 1); assertEq(send, 1); } diff --git a/parachain/pallets/control/src/lib.rs b/parachain/pallets/control/src/lib.rs index 62e7e266c4..313732509c 100644 --- a/parachain/pallets/control/src/lib.rs +++ b/parachain/pallets/control/src/lib.rs @@ -190,6 +190,7 @@ pub mod pallet { UnsupportedLocationVersion, InvalidLocation, Send(SendError), + InvalidTokenFees, } /// The set of registered agents @@ -427,16 +428,15 @@ pub mod pallet { Self::do_transfer_native_from_agent(agent_id, para_id, recipient, amount, pays_fee) } - /// Sends a message to the Gateway contract to update fees + /// Sends a message to the Gateway contract to set token transfer fees /// /// Privileged. Can only be called by root. /// /// Fee required: No /// /// - `origin`: Must be root - /// - `location`: Location used to resolve the agent - /// - `recipient`: Recipient of funds - /// - `amount`: Amount to transfer + /// - `register`: The fee for register token + /// - `send`: The fee for send token to para chain #[pallet::call_index(8)] #[pallet::weight(T::WeightInfo::set_token_transfer_fees())] pub fn set_token_transfer_fees( @@ -446,6 +446,8 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; + ensure!(register > 0 && send > 0, Error::::InvalidTokenFees); + let command = Command::SetTokenTransferFees { register, send }; Self::send(T::OwnParaId::get(), command, PaysFee::::No)?;