Skip to content

Commit

Permalink
Merge branch 'open-web3-stack:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hqwangningbo authored Jan 12, 2025
2 parents 02b28d7 + 8285019 commit 01c4ee6
Show file tree
Hide file tree
Showing 41 changed files with 288 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
tar -zxvf cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz -C $HOME/.cargo/bin
make Cargo.toml
cargo update
cargo update -p frame-support-procedural --precise 30.0.2
cargo update -p xcm-procedural --precise 10.1.0
cargo tarpaulin --verbose --no-fail-fast --workspace --timeout 300 --out Xml
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Update
run: |
cargo update
cargo update -p frame-support-procedural --precise 30.0.2
cargo update -p xcm-procedural --precise 10.1.0
- name: Run clippy
run: cargo clippy -- -D warnings
- name: Check for Wasm
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/zepter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
- name: Install Zepter
run: cargo install zepter --version 0.15.0 --locked -q -f --no-default-features && zepter --version
- run: make Cargo.toml
- run: |
cargo update
cargo update -p frame-support-procedural --precise 30.0.2
- run: cargo update
- name: Check Rust features
run: make dev-features-check
44 changes: 22 additions & 22 deletions Cargo.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,35 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive
serde = { version = "1.0.189" }
parity-scale-codec = { version = "3.6.5", default-features = false, features = ["max-encoded-len"] }

cumulus-pallet-xcm = { version = "0.16.0", default-features = false }
cumulus-primitives-core = { version = "0.15.0", default-features = false }
frame-benchmarking = { version = "37.0.0", default-features = false }
frame-support = { version = "37.0.0", default-features = false }
frame-system = { version = "37.0.0", default-features = false }
pallet-balances = { version = "38.0.0", default-features = false }
pallet-elections-phragmen = { version = "38.0.0", default-features = false }
pallet-message-queue = { version = "40.0.0", default-features = false }
pallet-preimage = { version = "37.0.0", default-features = false }
pallet-root-testing = { version = "13.0.0", default-features = false }
pallet-scheduler = { version = "38.0.0", default-features = false }
pallet-timestamp = { version = "36.0.0", default-features = false }
pallet-treasury = { version = "36.0.0", default-features = false }
pallet-xcm = { version = "16.0.0", default-features = false }
cumulus-pallet-xcm = { version = "0.17.0", default-features = false }
cumulus-primitives-core = { version = "0.16.0", default-features = false }
frame-benchmarking = { version = "38.0.0", default-features = false }
frame-support = { version = "38.0.0", default-features = false }
frame-system = { version = "38.0.0", default-features = false }
pallet-balances = { version = "39.0.0", default-features = false }
pallet-elections-phragmen = { version = "39.0.0", default-features = false }
pallet-message-queue = { version = "41.0.1", default-features = false }
pallet-preimage = { version = "38.0.0", default-features = false }
pallet-root-testing = { version = "14.0.0", default-features = false }
pallet-scheduler = { version = "39.0.0", default-features = false }
pallet-timestamp = { version = "37.0.0", default-features = false }
pallet-treasury = { version = "37.0.0", default-features = false }
pallet-xcm = { version = "17.0.0", default-features = false }
polkadot-parachain-primitives = { version = "14.0.0", default-features = false }
polkadot-runtime-common = { version = "16.0.0", default-features = false }
polkadot-runtime-parachains = { version = "16.0.0", default-features = false }
polkadot-runtime-common = { version = "17.0.0", default-features = false }
polkadot-runtime-parachains = { version = "17.0.1", default-features = false }
sp-api = { version = "34.0.0", default-features = false }
sp-application-crypto = { version = "38.0.0", default-features = false }
sp-arithmetic = { version = "26.0.0", default-features = false }
sp-core = { version = "34.0.0", default-features = false }
sp-io = { version = "38.0.0", default-features = false }
sp-runtime = { version = "39.0.0", default-features = false }
sp-runtime = { version = "39.0.1", default-features = false }
sp-runtime-interface = { version = "28.0.0", default-features = false }
sp-staking = { version = "34.0.0", default-features = false }
sp-staking = { version = "36.0.0", default-features = false }
sp-std = { version = "14.0.0", default-features = false }
sp-storage = { version = "21.0.0", default-features = false }
xcm = { version = "14.1.0", package = "staging-xcm", default-features = false }
xcm-builder = { version = "16.0.0", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "16.0.0", package = "staging-xcm-executor", default-features = false }
xcm = { version = "14.2.0", package = "staging-xcm", default-features = false }
xcm-builder = { version = "17.0.1", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "17.0.0", package = "staging-xcm-executor", default-features = false }

xcm-simulator = { version = "16.0.0" }
xcm-simulator = { version = "17.0.0" }
4 changes: 2 additions & 2 deletions asset-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "orml-asset-registry"
description = "Registry for (foreign) assets"
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/asset-registry"
license = "Apache-2.0"
version = "1.0.0"
version = "1.1.0"
authors = ["Interlay Ltd, etc"]
edition = "2021"

Expand All @@ -27,7 +27,7 @@ xcm-builder = { workspace = true }
xcm-executor = { workspace = true }

# orml
orml-traits = { path = "../traits", version = "1.0.0", default-features = false }
orml-traits = { path = "../traits", version = "1.1.0", default-features = false }

# for runtime-benchmarks
polkadot-runtime-common = { workspace = true, optional = true }
Expand Down
4 changes: 2 additions & 2 deletions auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "orml-auction"
description = "Auction module that implements `Auction` trait."
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/auction"
license = "Apache-2.0"
version = "1.0.0"
version = "1.1.0"
authors = ["Acala Developers"]
edition = "2021"

Expand All @@ -17,7 +17,7 @@ frame-system = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

orml-traits = { path = "../traits", version = "1.0.0", default-features = false }
orml-traits = { path = "../traits", version = "1.1.0", default-features = false }

[dev-dependencies]
sp-core = { workspace = true, features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion authority/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "orml-authority"
description = "Utility pallet to perform ROOT calls in a PoA network"
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/auction"
license = "Apache-2.0"
version = "1.0.0"
version = "1.1.0"
authors = ["Acala Developers"]
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "orml-benchmarking"
description = "Provide macro to benchmark Substrate runtime."
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/benchmarking"
license = "Apache-2.0"
version = "1.0.0"
version = "1.1.0"
authors = ["Laminar Developers <hello@laminar.one>"]
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion build-script-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "orml-build-script-utils"
description = "Crate with utility functions for `build.rs` scripts."
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/build-script-utils"
license = "Apache-2.0"
version = "1.0.0"
version = "1.1.0"
authors = ["Parity Technologies <admin@parity.io>", "Laminar Developers <hello@laminar.one>"]
edition = "2021"

Expand Down
6 changes: 3 additions & 3 deletions currencies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "orml-currencies"
description = "Provide `MultiCurrency` implementation using `pallet-balances` and `orml-tokens` module."
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/currencies"
license = "Apache-2.0"
version = "1.0.0"
version = "1.1.0"
authors = ["Laminar Developers <hello@laminar.one>"]
edition = "2021"

Expand All @@ -18,8 +18,8 @@ sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

orml-traits = { path = "../traits", version = "1.0.0", default-features = false }
orml-utilities = { path = "../utilities", version = "1.0.0", default-features = false }
orml-traits = { path = "../traits", version = "1.1.0", default-features = false }
orml-utilities = { path = "../utilities", version = "1.1.0", default-features = false }

[dev-dependencies]
pallet-balances = { workspace = true, features = ["std"] }
Expand Down
71 changes: 54 additions & 17 deletions currencies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ pub mod module {
) -> DispatchResult {
let from = ensure_signed(origin)?;
let to = T::Lookup::lookup(dest)?;
<Self as MultiCurrency<T::AccountId>>::transfer(currency_id, &from, &to, amount)
<Self as MultiCurrency<T::AccountId>>::transfer(
currency_id,
&from,
&to,
amount,
ExistenceRequirement::AllowDeath,
)
}

/// Transfer some native currency to another account.
Expand All @@ -150,7 +156,7 @@ pub mod module {
) -> DispatchResult {
let from = ensure_signed(origin)?;
let to = T::Lookup::lookup(dest)?;
T::NativeCurrency::transfer(&from, &to, amount)
T::NativeCurrency::transfer(&from, &to, amount, ExistenceRequirement::AllowDeath)
}

/// update amount of account `who` under `currency_id`.
Expand Down Expand Up @@ -220,14 +226,15 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
from: &T::AccountId,
to: &T::AccountId,
amount: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
if amount.is_zero() || from == to {
return Ok(());
}
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::transfer(from, to, amount)
T::NativeCurrency::transfer(from, to, amount, existence_requirement)
} else {
T::MultiCurrency::transfer(currency_id, from, to, amount)
T::MultiCurrency::transfer(currency_id, from, to, amount, existence_requirement)
}
}

Expand All @@ -242,14 +249,19 @@ impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
}
}

fn withdraw(currency_id: Self::CurrencyId, who: &T::AccountId, amount: Self::Balance) -> DispatchResult {
fn withdraw(
currency_id: Self::CurrencyId,
who: &T::AccountId,
amount: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
if amount.is_zero() {
return Ok(());
}
if currency_id == T::GetNativeCurrencyId::get() {
T::NativeCurrency::withdraw(who, amount)
T::NativeCurrency::withdraw(who, amount, existence_requirement)
} else {
T::MultiCurrency::withdraw(currency_id, who, amount)
T::MultiCurrency::withdraw(currency_id, who, amount, existence_requirement)
}
}

Expand Down Expand Up @@ -475,16 +487,31 @@ where
<Pallet<T>>::ensure_can_withdraw(GetCurrencyId::get(), who, amount)
}

fn transfer(from: &T::AccountId, to: &T::AccountId, amount: Self::Balance) -> DispatchResult {
<Pallet<T> as MultiCurrency<T::AccountId>>::transfer(GetCurrencyId::get(), from, to, amount)
fn transfer(
from: &T::AccountId,
to: &T::AccountId,
amount: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
<Pallet<T> as MultiCurrency<T::AccountId>>::transfer(
GetCurrencyId::get(),
from,
to,
amount,
existence_requirement,
)
}

fn deposit(who: &T::AccountId, amount: Self::Balance) -> DispatchResult {
<Pallet<T>>::deposit(GetCurrencyId::get(), who, amount)
}

fn withdraw(who: &T::AccountId, amount: Self::Balance) -> DispatchResult {
<Pallet<T>>::withdraw(GetCurrencyId::get(), who, amount)
fn withdraw(
who: &T::AccountId,
amount: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
<Pallet<T>>::withdraw(GetCurrencyId::get(), who, amount, existence_requirement)
}

fn can_slash(who: &T::AccountId, amount: Self::Balance) -> bool {
Expand Down Expand Up @@ -653,8 +680,13 @@ where
Currency::ensure_can_withdraw(who, amount, WithdrawReasons::all(), new_balance)
}

fn transfer(from: &AccountId, to: &AccountId, amount: Self::Balance) -> DispatchResult {
Currency::transfer(from, to, amount, ExistenceRequirement::AllowDeath)
fn transfer(
from: &AccountId,
to: &AccountId,
amount: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
Currency::transfer(from, to, amount, existence_requirement)
}

fn deposit(who: &AccountId, amount: Self::Balance) -> DispatchResult {
Expand All @@ -666,8 +698,8 @@ where
Ok(())
}

fn withdraw(who: &AccountId, amount: Self::Balance) -> DispatchResult {
Currency::withdraw(who, amount, WithdrawReasons::all(), ExistenceRequirement::AllowDeath).map(|_| ())
fn withdraw(who: &AccountId, amount: Self::Balance, existence_requirement: ExistenceRequirement) -> DispatchResult {
Currency::withdraw(who, amount, WithdrawReasons::all(), existence_requirement).map(|_| ())
}

fn can_slash(who: &AccountId, amount: Self::Balance) -> bool {
Expand Down Expand Up @@ -707,7 +739,7 @@ where
if by_amount.is_positive() {
Self::deposit(who, by_balance)
} else {
Self::withdraw(who, by_balance)
Self::withdraw(who, by_balance, ExistenceRequirement::AllowDeath)
}
}
}
Expand Down Expand Up @@ -817,7 +849,12 @@ impl<T: Config> TransferAll<T::AccountId> for Pallet<T> {
T::MultiCurrency::transfer_all(source, dest)?;

// transfer all free to dest
T::NativeCurrency::transfer(source, dest, T::NativeCurrency::free_balance(source))
T::NativeCurrency::transfer(
source,
dest,
T::NativeCurrency::free_balance(source),
ExistenceRequirement::AllowDeath,
)
})
}
}
38 changes: 32 additions & 6 deletions currencies/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ fn native_currency_should_work() {
assert_eq!(NativeCurrency::free_balance(&ALICE), 50);
assert_eq!(NativeCurrency::free_balance(&BOB), 150);

assert_ok!(NativeCurrency::transfer(&ALICE, &BOB, 10));
assert_ok!(NativeCurrency::transfer(
&ALICE,
&BOB,
10,
ExistenceRequirement::AllowDeath
));
assert_eq!(NativeCurrency::free_balance(&ALICE), 40);
assert_eq!(NativeCurrency::free_balance(&BOB), 160);

Expand Down Expand Up @@ -251,12 +256,22 @@ fn basic_currency_adapting_pallet_balances_transfer() {
.one_hundred_for_alice_n_bob()
.build()
.execute_with(|| {
assert_ok!(AdaptedBasicCurrency::transfer(&ALICE, &BOB, 50));
assert_ok!(AdaptedBasicCurrency::transfer(
&ALICE,
&BOB,
50,
ExistenceRequirement::AllowDeath
));
assert_eq!(PalletBalances::total_balance(&ALICE), 50);
assert_eq!(PalletBalances::total_balance(&BOB), 150);

// creation fee
assert_ok!(AdaptedBasicCurrency::transfer(&ALICE, &EVA, 10));
assert_ok!(AdaptedBasicCurrency::transfer(
&ALICE,
&EVA,
10,
ExistenceRequirement::AllowDeath
));
assert_eq!(PalletBalances::total_balance(&ALICE), 40);
assert_eq!(PalletBalances::total_balance(&EVA), 10);
});
Expand Down Expand Up @@ -297,7 +312,11 @@ fn basic_currency_adapting_pallet_balances_withdraw() {
.one_hundred_for_alice_n_bob()
.build()
.execute_with(|| {
assert_ok!(AdaptedBasicCurrency::withdraw(&ALICE, 100));
assert_ok!(AdaptedBasicCurrency::withdraw(
&ALICE,
100,
ExistenceRequirement::AllowDeath
));
assert_eq!(PalletBalances::total_balance(&ALICE), 0);
assert_eq!(PalletBalances::total_issuance(), 100);
});
Expand Down Expand Up @@ -375,7 +394,11 @@ fn call_event_should_work() {
}));

assert_ok!(<Currencies as MultiCurrency<AccountId>>::transfer(
X_TOKEN_ID, &ALICE, &BOB, 10
X_TOKEN_ID,
&ALICE,
&BOB,
10,
ExistenceRequirement::AllowDeath
));
assert_eq!(Currencies::free_balance(X_TOKEN_ID, &ALICE), 40);
assert_eq!(Currencies::free_balance(X_TOKEN_ID, &BOB), 160);
Expand All @@ -397,7 +420,10 @@ fn call_event_should_work() {
}));

assert_ok!(<Currencies as MultiCurrency<AccountId>>::withdraw(
X_TOKEN_ID, &ALICE, 20
X_TOKEN_ID,
&ALICE,
20,
ExistenceRequirement::AllowDeath
));
assert_eq!(Currencies::free_balance(X_TOKEN_ID, &ALICE), 120);
System::assert_last_event(RuntimeEvent::Tokens(orml_tokens::Event::Withdrawn {
Expand Down
Loading

0 comments on commit 01c4ee6

Please sign in to comment.