Skip to content

Commit

Permalink
Fix token types (#187)
Browse files Browse the repository at this point in the history
* fix token types

* fix

* ♻️ ($PALLET) Finish salp

* remove assets from Cargo.toml

Co-authored-by: Allen Pocket <AllenPocketGamer@Gmail.com>
  • Loading branch information
ark930 and AllenPocketGamer authored Jul 19, 2021
1 parent 46d3234 commit 09a4fba
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 129 deletions.
75 changes: 23 additions & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ members = [
"node/primitives",
"node/rpc",
"node/service",
"pallets/assets",
"pallets/bancor",
"pallets/bid",
"pallets/flexible-fee",
Expand Down Expand Up @@ -182,6 +181,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-
sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }

zenlink-protocol = { git = "ssh://git@github.com/bifrost-finance/Zenlink-DEX-Module", branch = "polkadot-v0.9.8" }
Expand Down
17 changes: 8 additions & 9 deletions pallets/bancor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ pub mod weights;
pub use pallet::*;

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type BalanceOf<T> =
<<T as Config>::MultiCurrenciesHandler as MultiCurrency<AccountIdOf<T>>>::Balance;
type BalanceOf<T> = <<T as Config>::MultiCurrency as MultiCurrency<AccountIdOf<T>>>::Balance;

const BILLION: u128 = 1_000_000_000;

Expand All @@ -59,7 +58,7 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type MultiCurrenciesHandler: MultiCurrency<AccountIdOf<Self>, CurrencyId = CurrencyId>;
type MultiCurrency: MultiCurrency<AccountIdOf<Self>, CurrencyId = CurrencyId>;

#[pallet::constant]
type InterventionPercentage: Get<Percent>;
Expand Down Expand Up @@ -164,7 +163,7 @@ pub mod pallet {
let vstoken_id = currency_id.to_vstoken().map_err(|_| Error::<T>::ConversionError)?;

// Get exchanger's vstoken balance
let vstoken_balance = T::MultiCurrenciesHandler::free_balance(vstoken_id, &exchanger);
let vstoken_balance = T::MultiCurrency::free_balance(vstoken_id, &exchanger);
ensure!(vstoken_balance >= vstoken_amount, Error::<T>::NotEnoughBalance);

// make changes in the bancor pool
Expand All @@ -175,8 +174,8 @@ pub mod pallet {
Self::revise_bancor_pool_vstoken_buy_token(currency_id, token_amount, vstoken_amount)?;

// make changes in account balance
T::MultiCurrenciesHandler::withdraw(vstoken_id, &exchanger, vstoken_amount)?;
T::MultiCurrenciesHandler::deposit(currency_id, &exchanger, token_amount)?;
T::MultiCurrency::withdraw(vstoken_id, &exchanger, vstoken_amount)?;
T::MultiCurrency::deposit(currency_id, &exchanger, token_amount)?;

Self::deposit_event(Event::TokenSold(
exchanger,
Expand All @@ -202,7 +201,7 @@ pub mod pallet {
let vstoken_id = currency_id.to_vstoken().map_err(|_| Error::<T>::ConversionError)?;

// Get exchanger's token balance
let token_balance = T::MultiCurrenciesHandler::free_balance(currency_id, &exchanger);
let token_balance = T::MultiCurrency::free_balance(currency_id, &exchanger);
ensure!(token_balance >= token_amount, Error::<T>::NotEnoughBalance);

// make changes in the bancor pool
Expand All @@ -213,8 +212,8 @@ pub mod pallet {
Self::revise_bancor_pool_token_buy_vstoken(currency_id, token_amount, vstoken_amount)?;

// make changes in account balance
T::MultiCurrenciesHandler::withdraw(currency_id, &exchanger, token_amount)?;
T::MultiCurrenciesHandler::deposit(vstoken_id, &exchanger, vstoken_amount)?;
T::MultiCurrency::withdraw(currency_id, &exchanger, token_amount)?;
T::MultiCurrency::deposit(vstoken_id, &exchanger, vstoken_amount)?;

Self::deposit_event(Event::VSTokenSold(
exchanger,
Expand Down
4 changes: 2 additions & 2 deletions pallets/bancor/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Assets: orml_tokens::{Pallet, Call, Config<T>, Storage, Event<T>},
Tokens: orml_tokens::{Pallet, Call, Config<T>, Storage, Event<T>},
Bancor: bancor::{Pallet, Call, Config<T>, Storage, Event<T>},
}
);
Expand Down Expand Up @@ -114,7 +114,7 @@ parameter_types! {
impl bancor::Config for Test {
type Event = Event;
type InterventionPercentage = InterventionPercentage;
type MultiCurrenciesHandler = Assets;
type MultiCurrency = Tokens;
type WeightInfo = ();
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/bancor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ fn exchange_for_token_should_work() {
);

// check ALICE's account balances. ALICE should have 1000-50 VSDOT, and 1000+49 DOT.
assert_eq!(Assets::free_balance(DOT, &ALICE), 1049);
assert_eq!(Assets::free_balance(VSDOT, &ALICE), 950);
assert_eq!(Tokens::free_balance(DOT, &ALICE), 1049);
assert_eq!(Tokens::free_balance(VSDOT, &ALICE), 950);
});
}

Expand Down Expand Up @@ -181,8 +181,8 @@ fn exchange_for_vstoken_should_work() {
);

// check ALICE's account balances. ALICE should have 1000-49 DOT, and 1000+49 VSDOT.
assert_eq!(Assets::free_balance(DOT, &ALICE), 951);
assert_eq!(Assets::free_balance(VSDOT, &ALICE), 1049);
assert_eq!(Tokens::free_balance(DOT, &ALICE), 951);
assert_eq!(Tokens::free_balance(VSDOT, &ALICE), 1049);
});
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ frame_support::construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Event<T>},
Assets: orml_tokens::{Pallet, Storage, Event<T>},
Tokens: orml_tokens::{Pallet, Storage, Event<T>},
Balances: balances::{Pallet, Call, Storage, Event<T>},
// TransactionPayment: pallet_transaction_payment::{Module, Storage},
FlexibleFee: flexible_fee::{Pallet, Call, Storage,Event<T>},
Expand Down Expand Up @@ -189,7 +189,7 @@ pub type AdaptedBasicCurrency =
impl orml_currencies::Config for Test {
type Event = Event;
type GetNativeCurrencyId = GetNativeCurrencyId;
type MultiCurrency = Assets;
type MultiCurrency = Tokens;
type NativeCurrency = AdaptedBasicCurrency;
type WeightInfo = ();
}
Expand Down
Loading

0 comments on commit 09a4fba

Please sign in to comment.