Skip to content

Commit

Permalink
Mangata dev v0.9.40 (#29)
Browse files Browse the repository at this point in the history
* run CI for release branch

* Upgrade polkadot-v0.9.31 (open-web3-stack#830)

* Upgrade polkadot-v0.9.31

* Update authority/src/lib.rs

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>

* fix tests

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>

* add CODECOV_TOKEN (open-web3-stack#836)

* claim_rewards should not create empty records (open-web3-stack#835)

* Update Readme (open-web3-stack#837)

* Update Readme

Plasm Network rebranded last year to Astar Network
Source: https://medium.com/astar-network/plasm-rebrands-to-astar-network-in-pursuit-of-becoming-a-polkadot-native-dapp-hub-6db3121c4f13

* Update README.md

Change order

* Token hook refactoring; Posthooks for deposit and transfer (open-web3-stack#834)

* feat(tokens): Refactor hooks into single trait

* feat(tokens): Add post-hooks for Transfer and Deposit

* chore(tokens): improve mutation hook naming

* fix(tokens): PostDeposit hook (open-web3-stack#839)

* fix(tokens): PostDeposit hook

* test(tokens): posthook correctness

* fix(tokens): use `assert` instead of `ensure` in mock posthooks

* Add Centrifuge to users of orml (open-web3-stack#842)

* Add Crust to ORML (open-web3-stack#843)

* refactor: make weight argument in xtokens transfers optional (open-web3-stack#841)

* refactor: make weight argument in xtokens be of type WeightLimit

* refactor: rename dest_weight -> dest_weight_limit

* Update weight-gen template.hbs (open-web3-stack#844)

* prevent nested DelayedOrigin (open-web3-stack#845)

* prevent nested DelayedOrigin

* fix deps

* Update authority/src/tests.rs

Co-authored-by: zjb0807 <zjb0807@qq.com>

* allow nested DelayedOrigin

* update docstring

* typo fix

Co-authored-by: zjb0807 <zjb0807@qq.com>

* Add try-runtime feature for orml-payments (open-web3-stack#846)

* Add try-runtime feature for orml-payments

* Add features

* Update to Polkadot v0.9.32 (open-web3-stack#848)

* Add new for DelayedOrigin (open-web3-stack#849)

* Update README.md (open-web3-stack#851)

* Update README.md

Update modules description

* Update README.md

Further updates on description.

* #xcm polishing #xtokens  README.md (open-web3-stack#856)

* Update github actions (open-web3-stack#855)

* Update github actions

* trigger GitHub actions

* Changed `vested_transfer` extrinsic behavior. (open-web3-stack#857)

* Changed `vested_transfer` extrinsic behavior.
Fixed self-vesting case (`from` == `to`) when it was possible to self-freeze funds above the current account balance.

* added test for self-vesting case

* Upgrade polkadot-v0.9.33 (open-web3-stack#858)

* use explicit call index (open-web3-stack#865)

* Upgrade to polkadot v0.9.36 (open-web3-stack#864)

* build: upgrade to polkadot v0.9.36

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* style: fix formatting

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* fix: polkadot dependency references

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* build: use released cumulus

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* fix: make asset_exists return false

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* update asset_exists (open-web3-stack#866)

* Fix payments on-idle (open-web3-stack#868)

* fix payments on-idle

* update comment

* Switch to Rust-1.66 (open-web3-stack#869)

* feat: derive MEL for Value enum (open-web3-stack#867)

* feat: impl MEL for Value enum

* fmt: fix

* feat:Make the XcmTransfer trait support transfer_multiasset_with_fee (open-web3-stack#870)

* update bencher deps (open-web3-stack#872)

* add BenchmarkError::Weightless (open-web3-stack#873)

* add BenchmarkError::Weightless

* Update benchmarking/src/lib.rs

Co-authored-by: zjb0807 <zjb0807@qq.com>

Co-authored-by: zjb0807 <zjb0807@qq.com>

* Update jsonrpsee 0.16.2 (open-web3-stack#876)

* Update jsonrpsee 0.16.2

* fix clippy

* fix clippy

* Update README.md (open-web3-stack#879)

Added Mangata and Parallel Finance

* Update README.md (open-web3-stack#880)

Added Moonbeam

* Upgrade polkadot-v0.9.37 (open-web3-stack#882)

* Add lock events to tokens pallet (open-web3-stack#883)

* Implement lock events in update_locks(...)

* Implement lock tests

* Replace depracted clippy rule name

* Move tests into correct test file

* Use correct Event type

* Update xtokens docs (open-web3-stack#885)

* added ajuna network (open-web3-stack#887)

using mainly the orml-vesting ...

* Upgrade polkadot-v0.9.38 (open-web3-stack#886)

* Upgrade polkadot-v0.9.38

* use `as_bounded_slice`

* `latest` instead explicit version

* use `AllCounted` for asset deposit

* Update `asset-registry` tests

* Update `benchmarking` tests

* Update `traits` tests

* Update `unknown-tokens` tests

* Update `xcm-support` tests

* Update `xtokens` tests

* Update `Cargo.dev.toml` pin

* clippy

* Specific version instead `latest`

* Add test `MultiLocation` encoding

* Remove `sp-authorship`

* Update `sp-weights` pin

* Fix runtime-benchmarks

* Add `asset-registry` migration

* clippy

* Assert `StorageVersion`

* Assert multiple migration calls

* AddImpl `OnRuntimeUpgrade`

* Add `unknown-tokens` migration

* Use xcm::v3 instead of latest (open-web3-stack#889)

* max weight fix (open-web3-stack#891)

* XcmTransfer Trait (open-web3-stack#892)

* Add more methods on XcmTransfer trait

* Add Transferred for XcmTransfer

* fix tests

* fix clippy

* fix migration and tests (open-web3-stack#893)

* build: upgrade polkadot to v0.9.39 (open-web3-stack#897)

* Add & clean deprecated (open-web3-stack#895)

* clean deprecated

* add dependencies on RPC

* add deprecated on RPC

* fix clippy

* remove tests

* Expose Xtokens pallet weight (open-web3-stack#898)

* fix unknown-tokens migration (open-web3-stack#899)

* fix unknown-tokens migration

* remove debug print

* Upgrade polkadot to v0.9.40 (open-web3-stack#902)

* Upgrade polkadot to v0.9.40

* add import for Hasher

* replace from_ref_time to from_parts

* fix CI

* remove unnecessary workspace word

* update branch ref

---------

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
Co-authored-by: Bryan Chen <xlchen1291@gmail.com>
Co-authored-by: zjb0807 <zjb0807@qq.com>
Co-authored-by: wangjj9219 <183318287@qq.com>
Co-authored-by: Maarten <36227274+fiexer@users.noreply.github.com>
Co-authored-by: Daniel Savu <savudani04@yahoo.ro>
Co-authored-by: Miguel Hervas <miguel.hervas.lazaro@gmail.com>
Co-authored-by: Myron <49134743+mmyyrroonn@users.noreply.github.com>
Co-authored-by: sander2 <sanderbosma@gmail.com>
Co-authored-by: Nuno Alexandre <hi@nunoalexandre.com>
Co-authored-by: Lawrence Law - Acala <97002769+Lawrence-Acala@users.noreply.github.com>
Co-authored-by: Dzmitry Lahoda <dzmitry@lahoda.pro>
Co-authored-by: Pavel Orlov <45266194+PraetorP@users.noreply.github.com>
Co-authored-by: Daniel Shiposha <dshiposha@usetech.com>
Co-authored-by: Yaroslav Bolyukin <iam@lach.pw>
Co-authored-by: William Freudenberger <w.freude@icloud.com>
Co-authored-by: NingBo Wang <2536935847@qq.com>
Co-authored-by: Ermal Kaleci <ermalkaleci@gmail.com>
Co-authored-by: Andrew Plaza <aplaza@liquidthink.net>
Co-authored-by: Joshua Cheong <jrc96@cantab.ac.uk>
Co-authored-by: Harald Heckmann <mail@haraldheckmann.de>
Co-authored-by: Cedric Decoster <darkfriend77@users.noreply.github.com>
Co-authored-by: tgmichel <telmo@purestake.com>
  • Loading branch information
1 parent 1d6fbd1 commit 82fa856
Show file tree
Hide file tree
Showing 95 changed files with 1,660 additions and 1,128 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mangata-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
with:
toolchain: nightly
default: true
- name: Install nightly-2020-10-01 with wasm
- name: Install nightly-2022-11-11 with wasm
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2020-10-01
toolchain: nightly-2022-11-11
target: wasm32-unknown-unknown
- name: Check Cargo version
run: |
Expand Down
19 changes: 10 additions & 9 deletions Cargo.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ members = [
"build-script-utils",
"weight-gen",
"weight-meter",
"payments"
]

exclude = ["bencher/test"]
Expand Down Expand Up @@ -60,7 +61,7 @@ pallet-assets = { git = "https://github.com/mangata-finance//substrate", branch
pallet-tips = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-election-provider-multi-phase = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-beefy-mmr = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
beefy-merkle-tree = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
#beefy-merkle-tree = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-scheduler = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-multisig = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
frame-executive = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
Expand Down Expand Up @@ -93,10 +94,10 @@ pallet-elections-phragmen = { git = "https://github.com/mangata-finance//substra
pallet-proxy = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
pallet-vesting = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-informant = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-finality-grandpa-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
beefy-gadget-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
beefy-gadget = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
#sc-finality-grandpa-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
#sc-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
#beefy-gadget-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
#beefy-gadget = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-executor-wasmtime = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-executor-common = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-executor-wasmi = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
Expand Down Expand Up @@ -129,7 +130,7 @@ sc-state-db = { git = "https://github.com/mangata-finance//substrate", branch =
sc-allocator = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus-aura = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus-uncles = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
#sc-consensus-uncles = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus-epochs = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus-slots = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sc-consensus-babe-rpc = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
Expand All @@ -153,9 +154,9 @@ sp-inherents = { git = "https://github.com/mangata-finance//substrate", branch =
sp-authorship = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sp-storage = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sp-std = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sp-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
beefy-primitives = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev", package = "sp-beefy" }
remote-externalities = { git = "https://github.com/mangata-finance//substrate" }
#sp-finality-grandpa = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
#beefy-primitives = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev", package = "sp-beefy" }
#remote-externalities = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev"}
sp-version-proc-macro = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sp-version = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
sp-transaction-pool = { git = "https://github.com/mangata-finance//substrate", branch = "mangata-dev" }
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ ORML is part of the bigger `Open-Web3-Stack` initiative, that is currently under
_In alphabetical order_

- [Acala Network](https://github.com/AcalaNetwork/Acala)
- [Ajuna Network](https://github.com/ajuna-network/Ajuna)
- [Astar Network](https://github.com/AstarNetwork)
- [Bifrost Finance](https://github.com/bifrost-finance/bifrost)
- [Bit.Country](https://github.com/bit-country/Bit-Country-Blockchain)
Expand All @@ -102,8 +103,11 @@ _In alphabetical order_
- [Libra](https://github.com/atscaletech/libra)
- [Listen](https://github.com/listenofficial)
- [Manta Network](https://github.com/Manta-Network)
- [Mangata Finance](https://github.com/mangata-finance)
- [Minterest](https://github.com/minterest-finance/minterest-chain-node)
- [Moonbeam](https://github.com/PureStake/moonbeam/)
- [OAK](https://github.com/OAK-Foundation/OAK-blockchain)
- [Parallel Finance](https://github.com/parallel-finance/)
- [PolkaFoundry Network](https://github.com/PolkaFoundry)
- [Setheum Network](https://github.com/Setheum-Labs/Setheum)
- [Valiu Liquidity Network](https://github.com/valibre-org/vln-node)
Expand Down
38 changes: 19 additions & 19 deletions asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ serde = { version = "1.0.136", optional = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["max-encoded-len"] }

# substrate
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false , optional = true }

# polkadot
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.36" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "release-v0.9.40" }

# orml
orml-traits = { path = "../traits", version = "0.4.1-dev", default-features = false }
Expand All @@ -34,21 +34,21 @@ mangata-types = { git = "https://github.com/mangata-finance/substrate", default-

[dev-dependencies]
# substrate
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.40" }

# cumulus
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40" }

# polkadot
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" }
xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" }
xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" }

# orml
orml-tokens = { path = "../tokens" }
Expand Down
23 changes: 9 additions & 14 deletions asset-registry/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use crate::module::*;
use frame_support::{log, pallet_prelude::*, weights::constants::{WEIGHT_REF_TIME_PER_SECOND}};
use frame_support::{log, pallet_prelude::*, weights::constants::WEIGHT_REF_TIME_PER_SECOND};
use orml_traits::{
asset_registry::{AssetMetadata, FixedConversionRateProvider, Inspect, Mutate, WeightToFeeConverter},
GetByKey,
};
use sp_runtime::FixedPointNumber;
use sp_runtime::{traits::Bounded, FixedU128};
use sp_std::prelude::*;
use xcm::latest::{prelude::*, Weight as XcmWeight};
use xcm::v3::{prelude::*, Weight as XcmWeight};
use xcm::VersionedMultiLocation;
use xcm_builder::TakeRevenue;
use xcm_executor::{traits::WeightTrader, Assets};

use crate::module::*;

/*
/// Alias for AssetMetadata to improve readability (and to placate clippy)
pub type DefaultAssetMetadata<T> = AssetMetadata<<T as Config>::Balance, <T as Config>::CustomMetadata>;
Expand Down Expand Up @@ -103,26 +100,24 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
continue;
}

if let Some(fee_increase) = W::convert_weight_to_fee(location, Weight::from_ref_time(weight)) {
if let Some(fee_increase) = W::convert_weight_to_fee(location, weight) {
if fee_increase == 0 {
// if the fee is set very low it could lead to zero fees, in which case
// constructing the fee asset item to subtract from payment would fail.
// Therefore, provide early exit
return Ok(payment);
}

if let Ok(unused) = payment.clone().checked_sub((asset.clone(), fee_increase).into()) {
if let Ok(unused) = payment.clone().checked_sub((*asset, fee_increase).into()) {
let (existing_weight, existing_fee) = match self.bought_weight {
Some(ref x) => (x.weight, x.amount),
None => (Weight::zero(), 0),
};

self.bought_weight = Some(BoughtWeight {
amount: existing_fee.checked_add(fee_increase).ok_or(XcmError::Overflow)?,
weight: existing_weight
.checked_add(&Weight::from_ref_time(weight))
.ok_or(XcmError::Overflow)?,
asset_location: location.clone(),
weight: existing_weight.checked_add(&weight).ok_or(XcmError::Overflow)?,
asset_location: *location,
});
return Ok(unused);
}
Expand All @@ -137,14 +132,14 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad

match self.bought_weight {
Some(ref mut bought) => {
let new_weight = bought.weight.saturating_sub(Weight::from_ref_time(weight));
let new_weight = bought.weight.saturating_sub(weight);
let new_amount = W::convert_weight_to_fee(&bought.asset_location, new_weight)?;
let refunded_amount = bought.amount.saturating_sub(new_amount);

bought.weight = new_weight;
bought.amount = new_amount;

Some((AssetId::Concrete(bought.asset_location.clone()), refunded_amount).into())
Some((AssetId::Concrete(bought.asset_location), refunded_amount).into())
}
None => None, // nothing to refund
}
Expand All @@ -154,7 +149,7 @@ impl<W: WeightToFeeConverter, R: TakeRevenue> WeightTrader for AssetRegistryTrad
impl<W: WeightToFeeConverter, R: TakeRevenue> Drop for AssetRegistryTrader<W, R> {
fn drop(&mut self) {
if let Some(ref bought) = self.bought_weight {
R::take_revenue((AssetId::Concrete(bought.asset_location.clone()), bought.amount).into());
R::take_revenue((AssetId::Concrete(bought.asset_location), bought.amount).into());
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sp_runtime::{
DispatchResult,
};
use sp_std::prelude::*;
use xcm::{v2::prelude::*, VersionedMultiLocation};
use xcm::{v3::prelude::*, VersionedMultiLocation};

pub use impls::*;
pub use module::*;
Expand All @@ -29,6 +29,9 @@ mod mock;
#[cfg(test)]
mod tests;

mod migrations;
pub use migrations::Migration;

#[frame_support::pallet]
pub mod module {
use super::*;
Expand Down Expand Up @@ -121,8 +124,10 @@ pub mod module {
}
}

const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

Expand Down
44 changes: 44 additions & 0 deletions asset-registry/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::{Config, LocationToAssetId, Pallet, Weight};
use frame_support::pallet_prelude::*;
use frame_support::{migration::storage_key_iter, traits::OnRuntimeUpgrade, StoragePrefixedMap};

use xcm::v3::prelude::*;

pub struct Migration<T>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> Weight {
let mut weight: Weight = Weight::zero();
let onchain_version = Pallet::<T>::on_chain_storage_version();
if onchain_version < 2 {
let inner_weight = v2::migrate::<T>();
weight.saturating_accrue(inner_weight);
}
weight
}
}

mod v2 {
use super::*;

pub(crate) fn migrate<T: Config>() -> Weight {
let mut weight: Weight = Weight::zero();
let module_prefix = LocationToAssetId::<T>::module_prefix();
let storage_prefix = LocationToAssetId::<T>::storage_prefix();

weight.saturating_accrue(T::DbWeight::get().reads(1));
let old_data =
storage_key_iter::<xcm::v2::MultiLocation, T::AssetId, Twox64Concat>(module_prefix, storage_prefix)
.drain()
.collect::<sp_std::vec::Vec<_>>();

for (old_key, value) in old_data {
weight.saturating_accrue(T::DbWeight::get().writes(1));
let new_key: MultiLocation = old_key.try_into().expect("Stored xcm::v2::MultiLocation");
LocationToAssetId::<T>::insert(new_key, value);
}

StorageVersion::new(2).put::<Pallet<T>>();
weight.saturating_accrue(T::DbWeight::get().writes(1));
weight
}
}
6 changes: 5 additions & 1 deletion asset-registry/src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
use super::*;

use mock::para::AssetRegistry;
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::bounded::BoundedVec;
use sp_io::TestExternalities;
use sp_runtime::{traits::Convert, AccountId32};
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};
Expand Down Expand Up @@ -35,6 +38,7 @@ impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
return Some(asset_id);
}
None

}
}
impl Convert<MultiAsset, Option<CurrencyId>> for CurrencyIdConvert {
Expand Down Expand Up @@ -159,7 +163,7 @@ pub fn para_ext(para_id: u32, asset_data: Option<(Vec<(u32, Vec<u8>)>, u32)>) ->
.unwrap();

if let Some((assets, _)) = asset_data {
GenesisConfig::<Runtime> { assets: assets }
GenesisConfig::<Runtime> { assets }
.assimilate_storage(&mut t)
.unwrap();
}
Expand Down
Loading

0 comments on commit 82fa856

Please sign in to comment.