Skip to content

Commit

Permalink
Improve for the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Nov 7, 2023
1 parent 32cbb27 commit 0a2cb16
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/interfaces/IGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 6 additions & 4 deletions parachain/pallets/control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub mod pallet {
UnsupportedLocationVersion,
InvalidLocation,
Send(SendError),
InvalidTokenFees,
}

/// The set of registered agents
Expand Down Expand Up @@ -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(
Expand All @@ -446,6 +446,8 @@ pub mod pallet {
) -> DispatchResult {
ensure_root(origin)?;

ensure!(register > 0 && send > 0, Error::<T>::InvalidTokenFees);

let command = Command::SetTokenTransferFees { register, send };
Self::send(T::OwnParaId::get(), command, PaysFee::<T>::No)?;

Expand Down

0 comments on commit 0a2cb16

Please sign in to comment.