3

I am developing a pallet, that has a prize pot and has to distribute it with different accounts that has won. Kind of similar to the Lottery pallet.

My issue is with the Existential Deposit is when transferring the pot.

For example the pot has 10 UNITS, and has to distribute 9 UNITS to A and 1 to B. And the Existential Deposit is 2 UNITS.

To do the transfer from the pallet Account I have to options:

-Using the option KeepAlive which fails if the transfer will make the balance go below the Existential Deposit:

T::Currency::transfer(
    &T::account_id(),
    &winner,
    amount_won,
    KeepAlive,
)?;

In that scenario, if is trying to send the funds to player A first (9 UNITS) it will already fail.

-Or use AllowDeath which send the funds anyway the balance goes below the Existential Deposit.

T::Currency::transfer(
    &T::account_id(),
    &winner,
    amount_won,
    AllowDeath,
)?;

In that scenario, if is trying to send the fund to player A first (9 UNITS) it will success but the account will be reaped and the second will fail.

What is the best strategy here?

Have some business logic to send first to the account with less funds? In the example above will be sending with the flag AllowDeath first to the player B (1 UNIT) and then to the player A (9 UNITS)?

Or It makes sense to fund the pallet in the genesis with the minimum Existential Deposit? or have an extrinsic to fund it?

3
  • 1
    How about adding a constant with minimum reward and requiring it to be no less than existential deposit? Dec 21, 2022 at 10:40
  • This can be a good way to solve it. However this is not a change in the pallet itself no? Requiring it to be no less than existential deposit is something that has to be done in the parachain node when integrating the pallet?
    – Alex Bean
    Dec 21, 2022 at 10:48
  • Yes, I believe the requirement should apply to how the pallet is configured in the runtime. Dec 21, 2022 at 11:17

1 Answer 1

1

Why do you want to keep it alive?

If it is unnecessary, why just let it die?

Usually, I follow the Substrate's spec.

Bounty account example: https://github.com/paritytech/substrate/blob/ee316317b85b2f65fc022b27bbfefcd42b6560ae/frame/bounties/src/lib.rs#L645


You could write something like this in your genesis.

#[pallet::genesis_config]
   pub struct GenesisConfig<T: Config> {
       pub existential_deposit:  BalanceOf<T>,
   }

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
    fn build(&self) {
        T::Currency::deposit_creating(&pallet_account(), self.existential_deposit);
        T::Currency::reserve(&pallet_account(), self.existential_deposit);
    }
}

And when implement your pallet in your node add the existential deposit in the testnet_genesis:

betting: parachain_template_runtime::BettingConfig {
            existential_deposit: EXISTENTIAL_DEPOSIT,
        }
7
  • But in my example, 10UNITS in the pot and 2 UNITS the ED, if is trying to send the prize to player A first (9 UNITS) it will success but the account will be reaped and the second will fail, no?.
    – Alex Bean
    Dec 22, 2022 at 8:10
  • I see. You can reserve 2 UNIT for it. IIRC, Acala or Phala did that in this way before. Dec 22, 2022 at 10:25
  • Exactly! This was my original question how I can fund the pallet with this 2 UNITS? .
    – Alex Bean
    Dec 22, 2022 at 10:50
  • I updated my answer, please check. Dec 24, 2022 at 2:17
  • 1
    It is just an example. You could pass the value to genesis config. T::Currency::reserve(&pallet_account(), self.ed); Dec 28, 2022 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.