This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 367
Collectives: teleport slashed assets #1433
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5bbccab
Collectives: teleport slashed assets
muharem 1d26137
fmt
muharem bb55906
Cargo.lock > polkadot-parachain 0.9.25
muharem f3f8690
create temp account for imbalance
muharem f20fac2
treasury acc id from pallet id
muharem 1b1366e
move accounts into constants, use here junction for assets
muharem 527ed39
Merge branch 'joe-alliance' into collectives-slash-assets-handler
muharem 9a51a54
assets location is relay chain, accounts as parameters
muharem 70fb49e
fix typos
muharem 98ee2e3
fix typo
muharem 44fef0a
Update parachains/runtimes/collectives/collectives-polkadot/src/const…
joepetrowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
parachains/runtimes/collectives/collectives-polkadot/src/impls.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (C) 2021 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use frame_support::{ | ||
| log, | ||
| traits::{Currency, Get, Imbalance, OnUnbalanced, OriginTrait}, | ||
| }; | ||
| use sp_std::{boxed::Box, marker::PhantomData}; | ||
| use xcm::latest::{Fungibility, Junction, NetworkId, Parent}; | ||
|
|
||
| type AccountIdOf<T> = <T as frame_system::Config>::AccountId; | ||
|
|
||
| type NegativeImbalanceOf<T, I> = <<T as pallet_alliance::Config<I>>::Currency as Currency< | ||
| <T as frame_system::Config>::AccountId, | ||
| >>::NegativeImbalance; | ||
|
|
||
| type CurrencyOf<T, I> = <T as pallet_alliance::Config<I>>::Currency; | ||
|
|
||
| type BalanceOf<T, I> = <<T as pallet_alliance::Config<I>>::Currency as Currency< | ||
| <T as frame_system::Config>::AccountId, | ||
| >>::Balance; | ||
|
|
||
| pub struct ToParentTreasury<TreasuryAcc, TempAcc, T, I = ()>( | ||
| PhantomData<(TreasuryAcc, TempAcc, T, I)>, | ||
| ); | ||
|
|
||
| impl<TreasuryAcc, TempAcc, T, I: 'static> OnUnbalanced<NegativeImbalanceOf<T, I>> | ||
| for ToParentTreasury<TreasuryAcc, TempAcc, T, I> | ||
| where | ||
| TreasuryAcc: Get<AccountIdOf<T>>, | ||
| TempAcc: Get<AccountIdOf<T>>, | ||
| T: pallet_xcm::Config + frame_system::Config + pallet_alliance::Config<I>, | ||
| [u8; 32]: From<AccountIdOf<T>>, | ||
| BalanceOf<T, I>: Into<Fungibility>, | ||
| <<T as frame_system::Config>::Origin as OriginTrait>::AccountId: From<AccountIdOf<T>>, | ||
| { | ||
| fn on_unbalanced(amount: NegativeImbalanceOf<T, I>) { | ||
| let temp_account: AccountIdOf<T> = TempAcc::get(); | ||
| let treasury_acc: AccountIdOf<T> = TreasuryAcc::get(); | ||
| let imbalance = amount.peek(); | ||
|
|
||
| <CurrencyOf<T, I>>::resolve_creating(&temp_account, amount); | ||
|
|
||
| let result = pallet_xcm::Pallet::<T>::teleport_assets( | ||
| <T as frame_system::Config>::Origin::signed(temp_account.into()), | ||
| Box::new(Parent.into()), | ||
| Box::new( | ||
| Junction::AccountId32 { network: NetworkId::Any, id: treasury_acc.into() } | ||
| .into() | ||
| .into(), | ||
| ), | ||
| Box::new((Parent, imbalance).into()), | ||
| 0, | ||
| ); | ||
|
|
||
| match result { | ||
| Err(err) => log::warn!("Failed to teleport slashed assets: {:?}", err), | ||
| _ => (), | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.