Skip to content

Commit

Permalink
local test&some log improvement (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong authored Sep 29, 2022
1 parent 4caba5f commit b7f8a90
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
57 changes: 48 additions & 9 deletions pallets/traits/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,20 @@ impl<
match Matcher::matches_fungibles(&revenue) {
Ok((asset_id, amount)) => {
if !amount.is_zero() {
let ok = Assets::mint_into(asset_id, &ReceiverAccount::get(), amount).is_ok();
debug_assert!(ok, "`mint_into` cannot generally fail; qed");
Assets::mint_into(asset_id, &ReceiverAccount::get(), amount).unwrap_or_else(
|e| {
log::error!(
target: "xcm::take_revenue",
"currency_id: {:?}, amount: {:?}, err: {:?}",
asset_id,
amount,
e
)
},
);
}
}
Err(_) => log::debug!(
Err(_) => log::error!(
target: "xcm",
"take revenue failed matching fungible"
),
Expand Down Expand Up @@ -457,8 +466,17 @@ impl<
}
}

MultiCurrency::mint_into(currency_id, &who, amount)
.map_err(|e| XcmError::FailedToTransactAsset(e.into()))
MultiCurrency::mint_into(currency_id, &who, amount).map_err(|e| {
log::error!(
target: "xcm::deposit_asset",
"who: {:?}, currency_id: {:?}, amount: {:?}, err: {:?}",
who,
currency_id,
amount,
e
);
XcmError::FailedToTransactAsset(e.into())
})
}
_ => Err(XcmError::AssetNotFound),
}
Expand All @@ -476,8 +494,17 @@ impl<
.map_err(|_| XcmError::from(Error::AccountIdConversionFailed))?;
let currency_id = CurrencyIdConvert::convert(asset.clone())
.ok_or_else(|| XcmError::from(Error::CurrencyIdConversionFailed))?;
MultiCurrency::burn_from(currency_id, &who, amount)
.map_err(|e| XcmError::FailedToTransactAsset(e.into()))?;
MultiCurrency::burn_from(currency_id, &who, amount).map_err(|e| {
log::error!(
target: "xcm::withdraw_asset",
"who: {:?}, currency_id: {:?}, amount: {:?}, err: {:?}",
who,
currency_id,
amount,
e
);
XcmError::FailedToTransactAsset(e.into())
})?;

Ok(asset.clone().into())
}
Expand All @@ -496,8 +523,20 @@ impl<
let amount: MultiCurrency::Balance = Match::matches_fungible(asset)
.ok_or(XcmError::AssetNotFound)?
.saturated_into();
MultiCurrency::transfer(currency_id, &from_account, &to_account, amount, true)
.map_err(|e| XcmError::FailedToTransactAsset(e.into()))?;
MultiCurrency::transfer(currency_id, &from_account, &to_account, amount, true).map_err(
|e| {
log::error!(
target: "xcm::internal_transfer_asset",
"currency_id: {:?}, source: {:?}, dest: {:?}, amount: {:?}, err: {:?}",
currency_id,
from_account,
to_account,
amount,
e
);
XcmError::FailedToTransactAsset(e.into())
},
)?;

Ok(asset.clone().into())
}
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub const EQ: CurrencyId = 124;
pub const TUR: CurrencyId = 125;
pub const LIT: CurrencyId = 127;
pub const CLV: CurrencyId = 130;
//local asset from moonbeam
pub const POOP: CurrencyId = 132;

// Ethereum ecosystem
pub const EUSDT: CurrencyId = 201;
Expand Down
4 changes: 1 addition & 3 deletions scripts/helper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ export const calcWeightPerSecond = (precision: number, price: number): number =>
/// max_fee = (weight_per_second * weight)/WEIGHT_PER_SECOND/(10**precision) * price
/// so weight_per_second = max_fee*WEIGHT_PER_SECOND*(10**precision)/weight/price
const weight_per_second = (((max_fee * WEIGHT_PER_SECOND) / weight) * 10 ** precision) / price
/// to avoid price sharply increased later so that we charge too much
/// just add some soft limit here
return Math.min(1000 * WEIGHT_PER_SECOND, Math.floor(weight_per_second))
return Math.floor(weight_per_second)
}

export const getDefaultRelayChainWsUrl = (): string => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/polkadot-launch

0 comments on commit b7f8a90

Please sign in to comment.