Skip to content

Commit

Permalink
Implement adjusted deposit_asset
Browse files Browse the repository at this point in the history
  • Loading branch information
sea212 committed Jul 21, 2023
1 parent 7139001 commit aa56d29
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions runtime/battery-station/src/xcm_config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,29 @@ pub struct<AssetRegistry, TransactAssetDelegate> AlignedFractionalTransactAsset

impl<AssetRegistry: Inspect, TransactAssetDelegate: TransactAsset> TransactAsset for AlignedFractionalTransactAsset
{
fn deposit_asset(asset: &MultiAsset, location: &MultiLocation, _context: &XcmContext) -> Result {
let decimals = AssetRegistry::metadata_by_location(location)
.ok_or_else(|| XcmError::FailedToTransactAsset(e.into()))?
.decimals
fn deposit_asset(&self, asset: &mut MultiAsset, location: &MultiLocation, context: &XcmContext) -> Result {
if let Fungible(amount) = asset.fun {
let decimals = AssetRegistry::metadata_by_location(location)
.ok_or_else(|| XcmError::FailedToTransactAsset(e.into()))?
.decimals

// TODO adjust places
if decimals > self.frac_dec_places {
let power = decimals.saturating_sub(self.frac_dec_places)
let adjust_factor = 10.saturating_pow(power)
// Floors the adjusted token amount, thus no tokens are generated
amount.saturating_div(adjust_factor)
} else {
let power = self.frac_dec_places.saturating_sub(decimals)
let adjust_factor = 10.saturating_pow(power)
amount.saturating_mul(adjust_factor)
};
}

TransactAssetDelegate::deposit_asset(asset, location, context)
}

fn withdraw_asset(
&self,
asset: &MultiAsset,
location: &MultiLocation,
_maybe_context: Option<&XcmContext>,
Expand All @@ -187,6 +201,7 @@ impl<AssetRegistry: Inspect, TransactAssetDelegate: TransactAsset> TransactAsset
}

fn transfer_asset(
&self,
asset: &MultiAsset,
from: &MultiLocation,
to: &MultiLocation,
Expand Down

0 comments on commit aa56d29

Please sign in to comment.