1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![cfg(feature = "runtime-benchmarks")]

pub mod currencies;
pub mod duster;
pub mod marketplace;
pub mod multi_payment;
pub mod route_executor;
pub mod tokens;
pub mod vesting;

use crate::AssetRegistry;
use crate::XYK;

use crate::Currencies;

use frame_support::assert_ok;
use frame_system::RawOrigin;

use common_runtime::AccountId;
use primitives::{AssetId, Balance};
use sp_std::vec::Vec;

use orml_traits::MultiCurrencyExtended;
use sp_runtime::traits::SaturatedConversion;

pub const BSX: Balance = primitives::constants::currency::UNITS;

pub fn register_asset(name: Vec<u8>, deposit: Balance) -> Result<AssetId, ()> {
	AssetRegistry::register_asset(
		AssetRegistry::to_bounded_name(name).map_err(|_| ())?,
		pallet_asset_registry::AssetType::<AssetId>::Token,
		deposit,
		None,
	)
	.map_err(|_| ())
}

pub fn update_balance(currency_id: AssetId, who: &AccountId, balance: Balance) {
	assert_ok!(<Currencies as MultiCurrencyExtended<_>>::update_balance(
		currency_id,
		who,
		balance.saturated_into()
	));
}

pub fn update_asset(asset_id: AssetId, name: Vec<u8>, deposit: Balance) -> Result<(), ()> {
	AssetRegistry::update(
		RawOrigin::Root.into(),
		asset_id,
		name,
		pallet_asset_registry::AssetType::<AssetId>::Token,
		Some(deposit),
	)
	.map_err(|_| ())
}

pub fn create_pool(who: AccountId, asset_a: AssetId, amount_a: Balance, asset_b: AssetId, amount_b: Balance) {
	assert_ok!(XYK::create_pool(
		RawOrigin::Signed(who).into(),
		asset_a,
		amount_a,
		asset_b,
		amount_b,
	));
}