From 44f90ae9a0962bc15da6116ad6c6da493a788a53 Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Tue, 8 Apr 2025 21:10:08 +0200 Subject: [PATCH 1/2] fix call indexes --- .../snowbridge/pallets/system-v2/src/lib.rs | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/bridges/snowbridge/pallets/system-v2/src/lib.rs b/bridges/snowbridge/pallets/system-v2/src/lib.rs index f56cb17ef6149..9d40da71486de 100644 --- a/bridges/snowbridge/pallets/system-v2/src/lib.rs +++ b/bridges/snowbridge/pallets/system-v2/src/lib.rs @@ -116,6 +116,56 @@ pub mod pallet { #[pallet::call] impl Pallet { + /// Registers a Polkadot-native token as a wrapped ERC20 token on Ethereum. + /// + /// The system frontend pallet on AH proxies this call to BH. + /// + /// - `sender`: The original sender initiating the call on AH + /// - `asset_id`: Location of the asset (relative to this chain) + /// - `metadata`: Metadata to include in the instantiated ERC20 contract on Ethereum + /// - `fee`: Ether to pay for the execution cost on Ethereum + #[pallet::call_index(0)] + #[pallet::weight(::WeightInfo::register_token())] + pub fn register_token( + origin: OriginFor, + sender: Box, + asset_id: Box, + metadata: AssetMetadata, + ) -> DispatchResult { + T::FrontendOrigin::ensure_origin(origin)?; + + let sender_location: Location = + (*sender).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; + let asset_location: Location = + (*asset_id).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; + + let location = Self::reanchor(asset_location)?; + let token_id = TokenIdOf::convert_location(&location) + .ok_or(Error::::LocationConversionFailed)?; + + if !ForeignToNativeId::::contains_key(token_id) { + NativeToForeignId::::insert(location.clone(), token_id); + ForeignToNativeId::::insert(token_id, location.clone()); + } + + let command = Command::RegisterForeignToken { + token_id, + name: metadata.name.into_inner(), + symbol: metadata.symbol.into_inner(), + decimals: metadata.decimals, + }; + + let message_origin = Self::location_to_message_origin(sender_location)?; + Self::send(message_origin, command, 0)?; + + Self::deposit_event(Event::::RegisterToken { + location: location.into(), + foreign_token_id: token_id, + }); + + Ok(()) + } + /// Sends command to the Gateway contract to upgrade itself with a new implementation /// contract /// @@ -125,7 +175,7 @@ pub mod pallet { /// - `impl_address`: The address of the implementation contract. /// - `impl_code_hash`: The codehash of the implementation contract. /// - `initializer`: Optionally call an initializer on the implementation contract. - #[pallet::call_index(3)] + #[pallet::call_index(1)] #[pallet::weight((::WeightInfo::upgrade(), DispatchClass::Operational))] pub fn upgrade( origin: OriginFor, @@ -159,7 +209,7 @@ pub mod pallet { /// Fee required: No /// /// - `origin`: Must be `GovernanceOrigin` - #[pallet::call_index(4)] + #[pallet::call_index(2)] #[pallet::weight((::WeightInfo::set_operating_mode(), DispatchClass::Operational))] pub fn set_operating_mode(origin: OriginFor, mode: OperatingMode) -> DispatchResult { let origin_location = T::GovernanceOrigin::ensure_origin(origin)?; @@ -171,56 +221,6 @@ pub mod pallet { Self::deposit_event(Event::::SetOperatingMode { mode }); Ok(()) } - - /// Registers a Polkadot-native token as a wrapped ERC20 token on Ethereum. - /// - /// The system frontend pallet on AH proxies this call to BH. - /// - /// - `sender`: The original sender initiating the call on AH - /// - `asset_id`: Location of the asset (relative to this chain) - /// - `metadata`: Metadata to include in the instantiated ERC20 contract on Ethereum - /// - `fee`: Ether to pay for the execution cost on Ethereum - #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::register_token())] - pub fn register_token( - origin: OriginFor, - sender: Box, - asset_id: Box, - metadata: AssetMetadata, - ) -> DispatchResult { - T::FrontendOrigin::ensure_origin(origin)?; - - let sender_location: Location = - (*sender).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; - let asset_location: Location = - (*asset_id).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; - - let location = Self::reanchor(asset_location)?; - let token_id = TokenIdOf::convert_location(&location) - .ok_or(Error::::LocationConversionFailed)?; - - if !ForeignToNativeId::::contains_key(token_id) { - NativeToForeignId::::insert(location.clone(), token_id); - ForeignToNativeId::::insert(token_id, location.clone()); - } - - let command = Command::RegisterForeignToken { - token_id, - name: metadata.name.into_inner(), - symbol: metadata.symbol.into_inner(), - decimals: metadata.decimals, - }; - - let message_origin = Self::location_to_message_origin(sender_location)?; - Self::send(message_origin, command, 0)?; - - Self::deposit_event(Event::::RegisterToken { - location: location.into(), - foreign_token_id: token_id, - }); - - Ok(()) - } } impl Pallet { From 74e5e3b6651dec6d7491031afd27e94f42e64a55 Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Mon, 14 Apr 2025 14:00:10 +0200 Subject: [PATCH 2/2] update call indexes --- .../snowbridge/pallets/system-v2/src/lib.rs | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/bridges/snowbridge/pallets/system-v2/src/lib.rs b/bridges/snowbridge/pallets/system-v2/src/lib.rs index 9d40da71486de..41065fcb006e1 100644 --- a/bridges/snowbridge/pallets/system-v2/src/lib.rs +++ b/bridges/snowbridge/pallets/system-v2/src/lib.rs @@ -116,56 +116,6 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// Registers a Polkadot-native token as a wrapped ERC20 token on Ethereum. - /// - /// The system frontend pallet on AH proxies this call to BH. - /// - /// - `sender`: The original sender initiating the call on AH - /// - `asset_id`: Location of the asset (relative to this chain) - /// - `metadata`: Metadata to include in the instantiated ERC20 contract on Ethereum - /// - `fee`: Ether to pay for the execution cost on Ethereum - #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::register_token())] - pub fn register_token( - origin: OriginFor, - sender: Box, - asset_id: Box, - metadata: AssetMetadata, - ) -> DispatchResult { - T::FrontendOrigin::ensure_origin(origin)?; - - let sender_location: Location = - (*sender).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; - let asset_location: Location = - (*asset_id).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; - - let location = Self::reanchor(asset_location)?; - let token_id = TokenIdOf::convert_location(&location) - .ok_or(Error::::LocationConversionFailed)?; - - if !ForeignToNativeId::::contains_key(token_id) { - NativeToForeignId::::insert(location.clone(), token_id); - ForeignToNativeId::::insert(token_id, location.clone()); - } - - let command = Command::RegisterForeignToken { - token_id, - name: metadata.name.into_inner(), - symbol: metadata.symbol.into_inner(), - decimals: metadata.decimals, - }; - - let message_origin = Self::location_to_message_origin(sender_location)?; - Self::send(message_origin, command, 0)?; - - Self::deposit_event(Event::::RegisterToken { - location: location.into(), - foreign_token_id: token_id, - }); - - Ok(()) - } - /// Sends command to the Gateway contract to upgrade itself with a new implementation /// contract /// @@ -175,7 +125,7 @@ pub mod pallet { /// - `impl_address`: The address of the implementation contract. /// - `impl_code_hash`: The codehash of the implementation contract. /// - `initializer`: Optionally call an initializer on the implementation contract. - #[pallet::call_index(1)] + #[pallet::call_index(0)] #[pallet::weight((::WeightInfo::upgrade(), DispatchClass::Operational))] pub fn upgrade( origin: OriginFor, @@ -209,7 +159,7 @@ pub mod pallet { /// Fee required: No /// /// - `origin`: Must be `GovernanceOrigin` - #[pallet::call_index(2)] + #[pallet::call_index(1)] #[pallet::weight((::WeightInfo::set_operating_mode(), DispatchClass::Operational))] pub fn set_operating_mode(origin: OriginFor, mode: OperatingMode) -> DispatchResult { let origin_location = T::GovernanceOrigin::ensure_origin(origin)?; @@ -221,6 +171,56 @@ pub mod pallet { Self::deposit_event(Event::::SetOperatingMode { mode }); Ok(()) } + + /// Registers a Polkadot-native token as a wrapped ERC20 token on Ethereum. + /// + /// The system frontend pallet on AH proxies this call to BH. + /// + /// - `sender`: The original sender initiating the call on AH + /// - `asset_id`: Location of the asset (relative to this chain) + /// - `metadata`: Metadata to include in the instantiated ERC20 contract on Ethereum + /// - `fee`: Ether to pay for the execution cost on Ethereum + #[pallet::call_index(2)] + #[pallet::weight(::WeightInfo::register_token())] + pub fn register_token( + origin: OriginFor, + sender: Box, + asset_id: Box, + metadata: AssetMetadata, + ) -> DispatchResult { + T::FrontendOrigin::ensure_origin(origin)?; + + let sender_location: Location = + (*sender).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; + let asset_location: Location = + (*asset_id).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; + + let location = Self::reanchor(asset_location)?; + let token_id = TokenIdOf::convert_location(&location) + .ok_or(Error::::LocationConversionFailed)?; + + if !ForeignToNativeId::::contains_key(token_id) { + NativeToForeignId::::insert(location.clone(), token_id); + ForeignToNativeId::::insert(token_id, location.clone()); + } + + let command = Command::RegisterForeignToken { + token_id, + name: metadata.name.into_inner(), + symbol: metadata.symbol.into_inner(), + decimals: metadata.decimals, + }; + + let message_origin = Self::location_to_message_origin(sender_location)?; + Self::send(message_origin, command, 0)?; + + Self::deposit_event(Event::::RegisterToken { + location: location.into(), + foreign_token_id: token_id, + }); + + Ok(()) + } } impl Pallet {