-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add command to update registerTokenFee and sendTokenFee #991
Changes from all commits
222214f
a2d7617
9cdaf0f
0989f98
f98004c
32cbb27
0a2cb16
3d92648
b622902
b432657
22013e2
eb0735b
4539dad
84cfa15
9fe0175
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,8 @@ pub mod pallet { | |
SetOperatingMode { mode: OperatingMode }, | ||
/// An TransferNativeFromAgent message was sent to the Gateway | ||
TransferNativeFromAgent { agent_id: AgentId, recipient: H160, amount: u128 }, | ||
/// A SetTokenTransferFees message was sent to the Gateway | ||
SetTokenTransferFees { register: u128, send: u128 }, | ||
} | ||
|
||
#[pallet::error] | ||
|
@@ -188,6 +190,7 @@ pub mod pallet { | |
UnsupportedLocationVersion, | ||
InvalidLocation, | ||
Send(SendError), | ||
InvalidTokenTransferFees, | ||
} | ||
|
||
/// The set of registered agents | ||
|
@@ -424,6 +427,33 @@ 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 set token transfer fees | ||
/// | ||
/// Privileged. Can only be called by root. | ||
/// | ||
/// Fee required: No | ||
/// | ||
/// - `origin`: Must be root | ||
/// - `register`: The fee for register token | ||
/// - `send`: The fee for send token to parachain | ||
#[pallet::call_index(8)] | ||
#[pallet::weight(T::WeightInfo::set_token_transfer_fees())] | ||
pub fn set_token_transfer_fees( | ||
origin: OriginFor<T>, | ||
register: u128, | ||
send: u128, | ||
Comment on lines
+444
to
+445
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets validate these to make sure they are non-zero, and if not, return an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) -> DispatchResult { | ||
ensure_root(origin)?; | ||
|
||
ensure!(register > 0 && send > 0, Error::<T>::InvalidTokenTransferFees); | ||
|
||
let command = Command::SetTokenTransferFees { register, send }; | ||
Self::send(T::OwnParaId::get(), command, PaysFee::<T>::No)?; | ||
|
||
Self::deposit_event(Event::<T>::SetTokenTransferFees { register, send }); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<T: Config> Pallet<T> { | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use ethers::prelude::Address; | ||
use snowbridge_smoketest::{ | ||
constants::*, | ||
contracts::{i_gateway, i_gateway::SetTokenTransferFeesFilter}, | ||
helper::*, | ||
parachains::bridgehub::api::{ | ||
ethereum_control::events::SetTokenTransferFees, | ||
runtime_types::{self, bridge_hub_rococo_runtime::RuntimeCall as BHRuntimeCall}, | ||
}, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn set_token_transfer_fees() { | ||
let test_clients = initial_clients().await.expect("initialize clients"); | ||
|
||
let gateway_addr: Address = GATEWAY_PROXY_CONTRACT.into(); | ||
let ethereum_client = *(test_clients.ethereum_client.clone()); | ||
let gateway = i_gateway::IGateway::new(gateway_addr, ethereum_client.clone()); | ||
let fees = gateway.token_transfer_fees().await.expect("get fees"); | ||
println!("asset fees {:?}", fees); | ||
|
||
let set_token_fees_call = BHRuntimeCall::EthereumControl( | ||
runtime_types::snowbridge_control::pallet::Call::set_token_transfer_fees { | ||
register: 10_000_000_000_000, | ||
send: 20_000_000_000, | ||
}, | ||
); | ||
|
||
governance_bridgehub_call_from_relay_chain(vec![set_token_fees_call]) | ||
.await | ||
.expect("set token fees"); | ||
|
||
wait_for_bridgehub_event::<SetTokenTransferFees>(&test_clients.bridge_hub_client).await; | ||
|
||
wait_for_ethereum_event::<SetTokenTransferFeesFilter>(&test_clients.ethereum_client).await; | ||
|
||
let fees = gateway.token_transfer_fees().await.expect("get fees"); | ||
println!("asset fees {:?}", fees); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default fees are already (1, 1), so this test could pass even if the command failed somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the default are 1(ether) not 1(wei), anyway check fee before and after set and make sure change as expected.
0a2cb16