Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicurrency handling updates to support #12951 #823

Merged
merged 10 commits into from
Mar 25, 2024
16 changes: 7 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ethy-gadget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"

[dependencies]
ethabi = { version = "17.1.0" }
ethabi = { version = "18.0.0" }
futures = "0.3.25"
futures-timer = "3.0.1"
hex = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion evm-precompiles/erc1155/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ codec = { version = "3.0.0", package = "parity-scale-codec", default-features =
num_enum = { version = "0.5.3", default-features = false }
precompile-utils = { path = "../utils", default-features = false }
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
ethereum-types = { version = "0.13.1", default-features = false, features = ["serialize", "codec"] }
ethereum-types = { version = "0.14.1", default-features = false }

# Substrate
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }
Expand Down
63 changes: 49 additions & 14 deletions pallet/assets-ext/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ use sp_std::marker::PhantomData;

use frame_support::traits::{
fungible,
fungibles::{self, Inspect, Transfer, Unbalanced},
tokens::{DepositConsequence, WithdrawConsequence},
fungibles::{self, Inspect, Mutate, Unbalanced},
tokens::{
DepositConsequence, Fortitude, Precision, Preservation, Provenance, WithdrawConsequence,
},
};

use seed_primitives::{AssetId, Balance};
Expand All @@ -48,24 +50,41 @@ where
<pallet_assets::Pallet<T>>::total_issuance(U::get())
}

fn active_issuance() -> Self::Balance {
<pallet_assets::Pallet<T>>::active_issuance(U::get())
}

fn minimum_balance() -> Balance {
<pallet_assets::Pallet<T>>::minimum_balance(U::get())
}

fn total_balance(who: &T::AccountId) -> Self::Balance {
<pallet_assets::Pallet<T>>::total_balance(U::get(), who)
}

fn balance(who: &T::AccountId) -> Balance {
<pallet_assets::Pallet<T>>::balance(U::get(), who)
}

fn reducible_balance(who: &T::AccountId, keep_alive: bool) -> Balance {
fn reducible_balance(
who: &T::AccountId,
preservation: Preservation,
force: Fortitude,
) -> Balance {
<pallet_assets::Pallet<T> as fungibles::Inspect<_>>::reducible_balance(
U::get(),
who,
keep_alive,
preservation,
force,
)
}

fn can_deposit(who: &T::AccountId, amount: Balance, mint: bool) -> DepositConsequence {
<pallet_assets::Pallet<T>>::can_deposit(U::get(), who, amount, mint)
fn can_deposit(
who: &T::AccountId,
amount: Balance,
provenance: Provenance,
) -> DepositConsequence {
<pallet_assets::Pallet<T>>::can_deposit(U::get(), who, amount, provenance)
}

fn can_withdraw(who: &T::AccountId, amount: Balance) -> WithdrawConsequence<Balance> {
Expand All @@ -83,7 +102,12 @@ where
type PositiveImbalance = imbalances::PositiveImbalance<T>;

fn free_balance(who: &T::AccountId) -> Self::Balance {
<pallet_assets::Pallet<T>>::reducible_balance(U::get(), who, false)
<pallet_assets::Pallet<T>>::reducible_balance(
U::get(),
who,
Preservation::Expendable,
Fortitude::Polite,
)
}
fn total_issuance() -> Self::Balance {
<pallet_assets::Pallet<T>>::total_issuance(U::get())
Expand All @@ -101,11 +125,11 @@ where
req: ExistenceRequirement,
) -> DispatchResult {
// used by evm
let keep_alive = match req {
ExistenceRequirement::KeepAlive => true,
ExistenceRequirement::AllowDeath => false,
let preservation = match req {
ExistenceRequirement::KeepAlive => Preservation::Preserve,
ExistenceRequirement::AllowDeath => Preservation::Expendable,
};
<Pallet<T> as Transfer<T::AccountId>>::transfer(U::get(), from, to, value, keep_alive)
<Pallet<T> as Mutate<T::AccountId>>::transfer(U::get(), from, to, value, preservation)
.map(|_| ())
}
fn ensure_can_withdraw(
Expand All @@ -128,10 +152,21 @@ where
who: &T::AccountId,
value: Self::Balance,
_reasons: WithdrawReasons,
_req: ExistenceRequirement,
req: ExistenceRequirement,
) -> Result<Self::NegativeImbalance, DispatchError> {
let preservation = match req {
ExistenceRequirement::KeepAlive => Preservation::Preserve,
ExistenceRequirement::AllowDeath => Preservation::Expendable,
};
// used by pallet-transaction payment & pallet-evm
<pallet_assets::Pallet<T>>::decrease_balance(U::get(), who, value)?;
<pallet_assets::Pallet<T>>::decrease_balance(
U::get(),
who,
value,
Precision::Exact,
preservation,
Fortitude::Polite,
)?;

<Pallet<T>>::deposit_event(Event::InternalWithdraw {
asset_id: U::get(),
Expand All @@ -151,7 +186,7 @@ where
if value.is_zero() {
return Ok(PositiveImbalance::new(0, U::get()))
}
<pallet_assets::Pallet<T>>::increase_balance(U::get(), who, value)?;
<pallet_assets::Pallet<T>>::increase_balance(U::get(), who, value, Precision::Exact)?;
<Pallet<T>>::deposit_event(Event::InternalDeposit {
asset_id: U::get(),
who: who.clone(),
Expand Down
Loading