Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,11 @@ fp-self-contained = { git = "https://github.com/humanode-network/frontier", tag
fp-storage = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-ethereum = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-balances = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-precompile-blake2 = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-precompile-bn128 = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-precompile-modexp = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-system = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }
pallet-evm-test-vector-support = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false }

[profile.release]
Expand Down
4 changes: 2 additions & 2 deletions crates/humanode-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pallet-dummy-precompiles-code = { path = "../pallet-dummy-precompiles-code", def
pallet-erc20-support = { path = "../pallet-erc20-support", default-features = false }
pallet-ethereum-chain-id = { path = "../pallet-ethereum-chain-id", default-features = false }
pallet-evm-accounts-mapping = { path = "../pallet-evm-accounts-mapping", default-features = false }
pallet-evm-balances = { path = "../pallet-evm-balances", default-features = false }
pallet-evm-system = { path = "../pallet-evm-system", default-features = false }
pallet-humanode-offences = { path = "../pallet-humanode-offences", default-features = false }
pallet-humanode-session = { path = "../pallet-humanode-session", default-features = false }
pallet-pot = { path = "../pallet-pot", default-features = false }
Expand Down Expand Up @@ -64,13 +66,11 @@ pallet-babe = { workspace = true }
pallet-balances = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-balances = { workspace = true }
pallet-evm-precompile-blake2 = { workspace = true }
pallet-evm-precompile-bn128 = { workspace = true }
pallet-evm-precompile-modexp = { workspace = true }
pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }
pallet-evm-system = { workspace = true }
pallet-grandpa = { workspace = true }
pallet-im-online = { workspace = true }
pallet-multisig = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/pallet-currency-swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ sp-runtime = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
pallet-evm-balances = { path = "../pallet-evm-balances", features = ["default"] }
pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] }

mockall = { workspace = true }
pallet-balances = { workspace = true, features = ["default"] }
pallet-evm-balances = { workspace = true, features = ["default"] }
pallet-evm-system = { workspace = true, features = ["default"] }
sp-core = { workspace = true }

[features]
Expand Down
5 changes: 3 additions & 2 deletions crates/pallet-dummy-precompiles-code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ sp-core = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
pallet-evm-balances = { path = "../pallet-evm-balances", features = ["default"] }
pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] }

fp-evm = { workspace = true }
hex-literal = { workspace = true }
pallet-balances = { workspace = true, features = ["default"] }
pallet-evm-balances = { workspace = true, features = ["default"] }
pallet-evm-system = { workspace = true, features = ["default"] }
pallet-timestamp = { workspace = true, features = ["default"] }

[features]
Expand Down
53 changes: 25 additions & 28 deletions crates/pallet-evm-balances/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
[package]
name = "pallet-evm-balances"
version = "1.0.0-dev"
license = "Apache-2.0"
description = "FRAME EVM BALANCES pallet."
edition = { workspace = true }
repository = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
log = { workspace = true, default-features = false }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
# Substrate
codec = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
scale-info = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] }

fp-evm = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-system = { workspace = true }
pallet-timestamp = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }

[features]
default = ["std"]
std = [
"log/std",
"scale-codec/std",
"scale-info/std",
# Substrate
"frame-support/std",
"frame-system/std",
"pallet-timestamp/std",
"sp-runtime/std",
"sp-std/std",
# Frontier
"fp-evm/std",
"pallet-evm/std",
"pallet-evm-system/std",
"codec/std",
"fp-evm/std",
"frame-support/std",
"frame-system/std",
"pallet-evm-system/std",
"pallet-evm/std",
"pallet-timestamp/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-evm-system/try-runtime",
"pallet-evm/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
]
26 changes: 20 additions & 6 deletions crates/pallet-evm-balances/src/imbalances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl<T: Config<I>, I: 'static> Imbalance<T::Balance> for PositiveImbalance<T, I>

fn split(self, amount: T::Balance) -> (Self, Self) {
let first = self.0.min(amount);
let second = self.0 - first;
let second = self
.0
.checked_sub(&first)
.expect("valid operation due to the check before; qed.");

mem::forget(self);
(Self(first), Self(second))
Expand All @@ -83,8 +86,12 @@ impl<T: Config<I>, I: 'static> Imbalance<T::Balance> for PositiveImbalance<T, I>
mem::forget((self, other));

match a.cmp(&b) {
Ordering::Greater => SameOrOther::Same(Self(a - b)),
Ordering::Less => SameOrOther::Other(NegativeImbalance::new(b - a)),
Ordering::Greater => {
SameOrOther::Same(Self(a.checked_sub(&b).expect("a is greater than b; qed.")))
}
Ordering::Less => SameOrOther::Other(NegativeImbalance::new(
b.checked_sub(&a).expect("b is greater than a; qed."),
)),
Ordering::Equal => SameOrOther::None,
}
}
Expand Down Expand Up @@ -123,7 +130,10 @@ impl<T: Config<I>, I: 'static> Imbalance<T::Balance> for NegativeImbalance<T, I>

fn split(self, amount: T::Balance) -> (Self, Self) {
let first = self.0.min(amount);
let second = self.0 - first;
let second = self
.0
.checked_sub(&first)
.expect("valid operation due to the check before; qed.");

mem::forget(self);
(Self(first), Self(second))
Expand All @@ -146,8 +156,12 @@ impl<T: Config<I>, I: 'static> Imbalance<T::Balance> for NegativeImbalance<T, I>
mem::forget((self, other));

match a.cmp(&b) {
Ordering::Greater => SameOrOther::Same(Self(a - b)),
Ordering::Less => SameOrOther::Other(PositiveImbalance::new(b - a)),
Ordering::Greater => {
SameOrOther::Same(Self(a.checked_sub(&b).expect("a is greater than b; qed.")))
}
Ordering::Less => SameOrOther::Other(PositiveImbalance::new(
b.checked_sub(&a).expect("b is greater than a; qed."),
)),
Ordering::Equal => SameOrOther::None,
}
}
Expand Down
25 changes: 18 additions & 7 deletions crates/pallet-evm-balances/src/impl_currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ where
}
<TotalIssuance<T, I>>::mutate(|issued| {
*issued = issued.checked_add(&amount).unwrap_or_else(|| {
amount = Self::Balance::max_value() - *issued;
amount = Self::Balance::max_value()
.checked_sub(issued)
.expect("valid operation; qed.");
Self::Balance::max_value()
})
});
Expand Down Expand Up @@ -129,7 +131,7 @@ where
return (NegativeImbalance::zero(), value);
}

let result = match Self::try_mutate_account_handling_dust(
let result = Self::try_mutate_account_handling_dust(
who,
|account, _is_new| -> Result<(Self::NegativeImbalance, Self::Balance), DispatchError> {
// Best value is the most amount we can slash following liveness rules.
Expand All @@ -138,7 +140,9 @@ where
let remaining = value.saturating_sub(actual);
Ok((NegativeImbalance::new(actual), remaining))
},
) {
);

match result {
Ok((imbalance, remaining)) => {
Self::deposit_event(Event::Slashed {
who: who.clone(),
Expand All @@ -147,8 +151,7 @@ where
(imbalance, remaining)
}
Err(_) => (Self::NegativeImbalance::zero(), value),
};
result
}
}

/// Deposit some `value` into the free balance of an existing target account `who`.
Expand Down Expand Up @@ -283,9 +286,17 @@ where
ensure!(value >= ed || !is_new, Error::<T, I>::ExistentialDeposit);

let imbalance = if account.free <= value {
SignedImbalance::Positive(PositiveImbalance::new(value - account.free))
SignedImbalance::Positive(PositiveImbalance::new(
value
.checked_sub(&account.free)
.expect("valid operation due to the check before; qed.")
))
} else {
SignedImbalance::Negative(NegativeImbalance::new(account.free - value))
SignedImbalance::Negative(NegativeImbalance::new(
account.free
.checked_sub(&value)
.expect("valid operation due to the check before; qed.")
))
};
account.free = value;
Self::deposit_event(Event::BalanceSet {
Expand Down
Loading