Here is my scenario: One account will maintain 3 balances of Token A, Token B, Token C. When Alice sends x Token A to Bob, it should deposit to Bob's balance for the same kind of token, means Token A. Similarly for Token C, but Token B is not transferable.
Inside the same about, It is possible to convert Token A into Token C with a conversion rate. So, how should I implement them? and What I did so far is?
#[frame_support::pallet]
pub mod pallet {
use frame_system::pallet_prelude::*;
use frame_support::traits::Currency;
use frame_support::serde::{Deserialize, Serialize};
#[pallet::pallet]
pub struct Pallet<T>(_);
//#[cfg(feature = "std")]
type TokenABalanceOf<T> = <<T as Config>::Token as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type TokenBBalanceOf<T> = <<T as Config>::TokenB as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type TokenCBalanceOf<T> = <<T as Config>::TokenC as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub trait TokenAManagement<T:Config> {
// fn convert_to_TokenC(from: T::&AccountId, amount: TokenBalanceOf<T>) -> DispatchResult;
fn withdraw(owner: T::AccountId, amount: TokenBalanceOf<T>) -> DispatchResult;
// fn transfer(from: &T::AccountId, to: &AccountId, value: TokenBalanceOf<T>) -> DispatchResult;
fn deposit(owner: T::AccountId, amount: u32) -> DispatchResult;
}
pub trait TokenBManagement<T:Config> {
fn deposit(owner: T::AccountId, amount: u32) -> DispatchResult;
// fn lock(owner: T::AccountId, amount: TokenCBalanceOf<T>) -> DispatchResult;
// fn burn(owner: T::AccountId, amount: TokenCBalanceOf<T>) -> DispatchResult;
}
pub trait TokenBManagement<T:Config> {
fn withdraw(owner: T::AccountId, amount: u32) -> DispatchResult;
fn deposit(owner: T::AccountId, amount: u32) -> DispatchResult;
}
#[pallet::config]
pub trait Config: frame_system::Config + pallet_transaction_payment::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type TokenA : Currency<Self::AccountId>;
type TokenB : Currency<Self::AccountId>;
type TokenC : Currency<Self::AccountId>;
type TokenAManagement: TokenAManagement<Self>;
type TokenBManagement: TokenBManagement<Self>;
type TokenCManagement: TokenCManagement<Self>;
}
}
My code is a mess. Could you please give me some idea to implement them more efficiently?