diff --git a/fuso-support/src/traits.rs b/fuso-support/src/traits.rs index 32f333e..c3a3a5f 100644 --- a/fuso-support/src/traits.rs +++ b/fuso-support/src/traits.rs @@ -48,6 +48,13 @@ pub trait Token { fn total_issuance(token: &Self::TokenId) -> Self::Balance; + fn transfer( + token: &Self::TokenId, + from: &AccountId, + to: &AccountId, + amount: Balance, + ) -> Result<(), DispatchError>; + fn try_mutate_account( token: &Self::TokenId, who: &AccountId, diff --git a/pallet-fuso-dao/src/lib.rs b/pallet-fuso-dao/src/lib.rs index 61a4c4f..9b58b69 100644 --- a/pallet-fuso-dao/src/lib.rs +++ b/pallet-fuso-dao/src/lib.rs @@ -58,8 +58,8 @@ pub mod pallet { pub logo: Vec, pub lang: Vec, pub gov_token: TokenId, - pub mintable: bool, - pub mint_by: TokenId, + pub swapable: bool, + pub swap_by: TokenId, pub treasury: AccountId, pub originator: AccountId, pub rule: DAORule, @@ -99,7 +99,7 @@ pub mod pallet { Existing(TokenId), New { token_symbol: Vec, - mint_by: TokenId, + swap_by: TokenId, max_supply: Balance, }, } @@ -191,7 +191,7 @@ pub mod pallet { Ok(().into()) } - // TODO + #[tranactional] #[pallet::weight(1_000_000_000_000)] pub fn purchase( origin: OriginFor, @@ -202,17 +202,18 @@ pub mod pallet { Orgs::::try_mutate_exists(&treasury, |dao| -> DispatchResult { ensure!(dao.is_some(), Error::::DaoNotExists); let dao = dao.unwrap(); - ensure!(dao.mintable, Error::::GovTokenIsNotMintable); + ensure!(dao.swapable, Error::::GovTokenIsNotMintable); ensure!(amount >= dao.entry_threshold, Error::::MinimalRequired); ensure!( - T::Asset::free_balance(&dao.mint_by, &origin) >= amount, + T::Asset::free_balance(&dao.swap_by, &origin) >= amount, Error::::InsufficientBalance ); ensure!( T::Asset::free_balance(&dao.gov_token, &treasury) >= amount, Error::::GovTokenBeyondMaximum, ); - // TODO transfer + T::Asset::transfer(&dao.swap_by, origin, treasury, amount)?; + T::Asset::transfer(&dao.gov_token, treasury, origin, amount)?; })?; Ok(().into()) } @@ -234,16 +235,16 @@ pub mod pallet { !Orgs::::contains_key(&treasury), Error::::DaoNameAlreadyExisted ); - let (gov_token, mintable, mint_by) = match gov_token { + let (gov_token, swapable, mint_by) = match gov_token { Existing(token_id) => (token_id, false, token_id), New { token_symbol, - mint_by, + swap_by, max_supply, } => { let token_info = XToken::FND10(token_symbol.clone(), max_supply); let token_id = T::Token::create(token_info)?; - (token_id, true, mint_by) + (token_id, true, swap_by) } }; // TODO params check @@ -254,7 +255,7 @@ pub mod pallet { logo, lang, gov_token, - mintable, + swapable, mint_by, treasury, originator,