Skip to content

Add free fees quotas for accounts with a validated identity

We should create our how implementation of the trait pallet_transaction_payment::CurrencyAdapter, probably in our pallet duniter_account.

The idea is to add a new field to AccountData, named fees_quotas for instance. Because the account is already read by CheckNonce before, the AccountData should be in the memory cache.

At the same time here, we can check the consumers, and if consumers == 0 AND if call is transfer, transfer_all or transfer_ud, we can withdraw with ExistenceRequirement::AllowDeath instead of ExistenceRequirement::KeepAlive.

In withdraw_fee We can do something like that:

if fee.is_zero() {
  return Ok(None)
}

let mut account = frame_system::Account::<T>::get(who);

if account.data.fees_quotas >= fee {
  account.data.fees_quotas -= fee;
  frame_system::Account::<T>::insert(who, account);
} else {
  fee -= account.data.fees_quotas;
  account.data.fees_quotas = 0;
  
  let withdraw_reason = if tip.is_zero() {
	WithdrawReasons::TRANSACTION_PAYMENT
  } else {
	WithdrawReasons::TRANSACTION_PAYMENT | WithdrawReasons::TIP
  };

  let existence_requirement = if account.consumers.is_zero() && can_deed_account(call) {
    ExistenceRequirement::AllowDeath
  } else {
    ExistenceRequirement::KeepAlive
  };

  match C::withdraw(who, fee, withdraw_reason, existence_requirement) {
	Ok(imbalance) => Ok(Some(imbalance)),
	Err(_) => Err(InvalidTransaction::Payment.into()),
  }
}

About providing the quotas, i think this should be done in a similar way than the Universal Dividend. We can add a handler OnUdClaimed in pallet universal_dividend, then impl this handler in pallet duniter_account :)

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information