Skip to content

Automatic token distribution pallet #229

@arrudagates

Description

@arrudagates

Pallet

enum List {
  Simple(Vec<AccountId>),
  Weighted(Vec<(AccountId, u32)>)
}

trait ListSourceTrait {
  fn get_list(&self) -> List;
}

trait config {
  type ListSource: ListSourceTrait
}

storages {
  CustomLists: Hash -> List;

  RegisteredAddresses: AccountId -> T::ListSource;
}

calls {
  fn distribute_to_list(list: T::ListSource, amount: Balance);

  fn register_address_to_list(list: T::ListSource); // Creates a pure proxy

  fn distribute_to_address(address: AccountId); // search RegisteredAddresses for the list
}

struct CustomListSource(Hash);

impl CustomListSource {
  fn get(hash: Hash) -> List { Self(hash).get_list() }
}

impl ListSourceTrait for CustomListSource {
  fn get_list(&self) -> List { CustomLists::get(self.0) }
}

Runtime

enum ListSource {
  CoreMembers(CoreId),
  CoreMembersWeighted(CoreId),
  OcifCoreStakers(CoreId),
  OcifCoreStakersWeighted(CoreId),
  CustomList(Hash)
}

impl ListSourceTrait for ListSource {
  fn get_list(&self) -> List {
    match self {
      CoreMembers => // get core members and return List::Simple
      CoreMembersWeighted => // get core members and return List::Weighted
      OcifCoreStakers => // get core stakers and return List::Simple
      OcifCoreStakersWeighted => // get core stakers and return List::Weighted
      CustomList(hash) => // pallet::CustomListSource::get(hash)
    }
  }
}

impl Pallet {
  type ListSource = ListSource;
}

Research

How can we have pallet_balances transfers automatically distribute through this pallet if the address lookup returns a list (without modifying pallet_balances as it's a foundational pallet of the network).

It would need to return proper weights, as these lists can be massive and would definitely use more weight than the amount allocated to a simple balance transfer.

This would definitely be really interesting, but if we decide not to hook into pallet_balances then we also don't need to have the RegisteredAccounts storage and we don't have to generate accounts that map to lists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions