Skip to content

Commit

Permalink
Skip CDD check on contract's 'deposit_account', which is only used to…
Browse files Browse the repository at this point in the history
… hold storage deposits.

Signed-off-by: Robert G. Jakabosky <rjakabosky+neopallium@neoawareness.com>
  • Loading branch information
Neopallium committed Sep 30, 2024
1 parent f947a6c commit 5057819
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion substrate/frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,10 @@ impl<T: Config> Pallet<T> {

/// Return the existential deposit of [`Config::Currency`].
fn min_balance() -> BalanceOf<T> {
<T::Currency as Inspect<AccountIdOf<T>>>::minimum_balance()
// POLYMESH: Need to make sure the contract's account is created.
// So we need to return a non-zero amount here.
//<T::Currency as Inspect<AccountIdOf<T>>>::minimum_balance()
1u32.into()
}

/// Convert gas_limit from 1D Weight to a 2D Weight.
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/contracts/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,9 @@ impl<T: Config> Ext<T> for ReservingExt {
terminated: bool,
) -> Result<(), DispatchError> {
match amount {
Deposit::Charge(amount) => T::Currency::transfer(
// POLYMESH: Use `transfer_no_cdd` instead of `transfer`, to avoid CDD check on
// `deposit_account`.
Deposit::Charge(amount) => T::Currency::transfer_no_cdd(
origin,
deposit_account,
*amount,
Expand Down
14 changes: 14 additions & 0 deletions substrate/frame/support/src/traits/tokens/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ pub trait Currency<AccountId> {
existence_requirement: ExistenceRequirement,
) -> DispatchResult;

/// Transfer some liquid free balance to another staker. Without CDD check on `dest`.
///
/// This is a very high-level function. It will ensure all appropriate fees are paid
/// and no imbalance in the system remains.
/// POLYMESH: Added for `pallet_contracts`.
fn transfer_no_cdd(
source: &AccountId,
dest: &AccountId,
value: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
Self::transfer(source, dest, value, existence_requirement)
}

/// Deducts up to `value` from the combined balance of `who`, preferring to deduct from the
/// free balance. This function cannot fail.
///
Expand Down

0 comments on commit 5057819

Please sign in to comment.