-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
358 handle delegation of brz token to automation pallet in xcm config (…
…#365) * Update LICENSE (#354) * second iteration on xcm intercept * listen to ReserveAssetDeposited instruction instead of WithdrawAsset. Mock Moonbeam transfer of asset. Implement custom barrier for other runtimes * fixes, format * move integration test BRZ from moonbeam into pendulum * remove mock BRZ asset moonriver, moonbase * re-add test macro * extracting a fee from handled asset * use custom asset transactor to handle automation pallet call * use if let with tuple * refactor to use MultiCurrencyAdapter as a wrapped AssetTransactor
- Loading branch information
Showing
11 changed files
with
264 additions
and
17 deletions.
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 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 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,74 @@ | ||
use sp_runtime::{ | ||
codec::FullCodec, | ||
traits::{Convert, MaybeSerializeDeserialize, SaturatedConversion}, | ||
}; | ||
use sp_std::{ | ||
cmp::{Eq, PartialEq}, | ||
fmt::Debug, | ||
marker::PhantomData, | ||
prelude::*, | ||
result, | ||
}; | ||
|
||
use orml_xcm_support::{OnDepositFail, UnknownAsset as UnknownAssetT}; | ||
use xcm::v3::{prelude::*, Error as XcmError, MultiAsset, MultiLocation, Result}; | ||
use xcm_executor::{ | ||
traits::{Convert as MoreConvert, MatchesFungible, TransactAsset}, | ||
Assets, | ||
}; | ||
|
||
pub struct AssetData { | ||
pub length: u8, | ||
pub data: [u8; 32], | ||
} | ||
|
||
pub trait AutomationPalletConfig { | ||
fn matches_asset(asset: &MultiAsset) -> Option<u128>; | ||
fn matches_beneficiary(beneficiary_location: &MultiLocation) -> Option<AssetData>; | ||
fn callback(length: u8, data: [u8; 32], amount: u128) -> Result; | ||
} | ||
|
||
pub struct CustomTransactorInterceptor<WrappedTransactor, AutomationPalletConfigT>( | ||
PhantomData<(WrappedTransactor, AutomationPalletConfigT)>, | ||
); | ||
|
||
impl<WrappedTransactor: TransactAsset, AutomationPalletConfigT: AutomationPalletConfig> | ||
TransactAsset for CustomTransactorInterceptor<WrappedTransactor, AutomationPalletConfigT> | ||
{ | ||
fn deposit_asset( | ||
asset: &MultiAsset, | ||
location: &MultiLocation, | ||
_context: &XcmContext, | ||
) -> Result { | ||
if let (Some(amount_deposited), Some(asset_data)) = ( | ||
AutomationPalletConfigT::matches_asset(asset), | ||
AutomationPalletConfigT::matches_beneficiary(location), | ||
) { | ||
AutomationPalletConfigT::callback( | ||
asset_data.length, | ||
asset_data.data, | ||
amount_deposited, | ||
)?; | ||
return Ok(()) | ||
} | ||
|
||
WrappedTransactor::deposit_asset(asset, location, _context) | ||
} | ||
|
||
fn withdraw_asset( | ||
asset: &MultiAsset, | ||
location: &MultiLocation, | ||
_maybe_context: Option<&XcmContext>, | ||
) -> result::Result<Assets, XcmError> { | ||
WrappedTransactor::withdraw_asset(asset, location, _maybe_context) | ||
} | ||
|
||
fn transfer_asset( | ||
asset: &MultiAsset, | ||
from: &MultiLocation, | ||
to: &MultiLocation, | ||
_context: &XcmContext, | ||
) -> result::Result<Assets, XcmError> { | ||
WrappedTransactor::transfer_asset(asset, from, to, _context) | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.