-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmock.rs
More file actions
450 lines (414 loc) · 15.5 KB
/
mock.rs
File metadata and controls
450 lines (414 loc) · 15.5 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
use crate::{self as ceres_launchpad};
pub use common::mock::*;
use common::mock::{ExistentialDeposits, GetTradingPairRestrictedFlag};
use common::prelude::Balance;
use common::AssetSymbol;
use common::BalancePrecision;
use common::ContentSource;
use common::Description;
pub use common::TechAssetId as Tas;
pub use common::TechPurpose::*;
use common::{balance, fixed, hash, DEXId, DEXInfo, Fixed, CERES_ASSET_ID, PSWAP, VAL, XOR, XST};
use common::{AssetName, XSTUSD};
use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild, Hooks};
use frame_support::weights::Weight;
use frame_support::{construct_runtime, parameter_types};
use frame_system::pallet_prelude::BlockNumberFor;
use permissions::{Scope, MANAGE_DEX};
use sp_core::H256;
use sp_runtime::testing::Header;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_runtime::{Perbill, Percent};
pub type BlockNumber = u64;
pub type AccountId = u128;
pub type Amount = i128;
pub type AssetId = common::AssetId32<common::PredefinedAssetId>;
pub type TechAssetId = common::TechAssetId<common::PredefinedAssetId>;
pub type TechAccountId = common::TechAccountId<AccountId, TechAssetId, DEXId>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Assets: assets::{Pallet, Call, Config<T>, Storage, Event<T>},
Tokens: tokens::{Pallet, Call, Config<T>, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Currencies: currencies::{Pallet, Call, Storage},
Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},
DexManager: dex_manager::{Pallet, Call, Config<T>, Storage},
TradingPair: trading_pair::{Pallet, Call, Config<T>, Storage, Event<T>},
Permissions: permissions::{Pallet, Call, Config<T>, Storage, Event<T>},
Technical: technical::{Pallet, Call, Config<T>, Storage, Event<T>},
PoolXYK: pool_xyk::{Pallet, Call, Storage, Event<T>},
PswapDistribution: pswap_distribution::{Pallet, Call, Config<T>, Storage, Event<T>},
MBCPool: multicollateral_bonding_curve_pool::{Pallet, Call, Config<T>, Storage, Event<T>},
VestedRewards: vested_rewards::{Pallet, Call, Storage, Event<T>},
CeresTokenLocker: ceres_token_locker::{Pallet, Call, Storage, Event<T>},
CeresLiquidityLocker: ceres_liquidity_locker::{Pallet, Call, Storage, Event<T>},
CeresLaunchpad: ceres_launchpad::{Pallet, Call, Storage, Event<T>},
DemeterFarmingPlatform: demeter_farming_platform::{Pallet, Call, Storage, Event<T>},
}
}
pub const ALICE: AccountId = 1;
pub const BOB: AccountId = 2;
pub const CHARLES: AccountId = 3;
pub const BUY_BACK_ACCOUNT: AccountId = 23;
pub const DAN: AccountId = 4;
pub const EMILY: AccountId = 5;
pub const DEX_A_ID: DEXId = DEXId::Polkaswap;
pub const DEX_B_ID: DEXId = DEXId::PolkaswapXSTUSD;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = Weight::from_parts(1024, 0);
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub GetXykFee: Fixed = fixed!(0.003);
pub GetIncentiveAssetId: AssetId = common::PSWAP;
pub const GetDefaultSubscriptionFrequency: BlockNumber = 10;
pub const GetBurnUpdateFrequency: BlockNumber = 14400;
pub GetParliamentAccountId: AccountId = 100;
pub GetPswapDistributionAccountId: AccountId = 101;
pub GetMarketMakerRewardsAccountId: AccountId = 102;
pub GetBondingCurveRewardsAccountId: AccountId = 103;
pub GetFarmingRewardsAccountId: AccountId = 104;
pub GetCrowdloanRewardsAccountId: AccountId = 105;
pub const MinimumPeriod: u64 = 5;
}
impl frame_system::Config for Runtime {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<65536>;
}
impl crate::Config for Runtime {
const MILLISECONDS_PER_DAY: Self::Moment = 86_400_000;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
parameter_types! {
pub const GetBaseAssetId: AssetId = XOR;
pub const GetBuyBackAssetId: AssetId = XST;
pub GetBuyBackSupplyAssets: Vec<AssetId> = vec![VAL, PSWAP];
pub const GetBuyBackPercentage: u8 = 10;
pub const GetBuyBackAccountId: AccountId = BUY_BACK_ACCOUNT;
pub const GetBuyBackDexId: DEXId = DEXId::Polkaswap;
pub GetTBCBuyBackXSTPercent: Fixed = fixed!(0.025);
}
impl assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ExtraAccountId = AccountId;
type ExtraAssetRecordArg =
common::AssetIdExtraAssetRecordArg<DEXId, common::LiquiditySourceType, AccountId>;
type AssetId = AssetId;
type GetBaseAssetId = GetBaseAssetId;
type GetBuyBackAssetId = GetBuyBackAssetId;
type GetBuyBackSupplyAssets = GetBuyBackSupplyAssets;
type GetBuyBackPercentage = GetBuyBackPercentage;
type GetBuyBackAccountId = GetBuyBackAccountId;
type GetBuyBackDexId = GetBuyBackDexId;
type BuyBackLiquidityProxy = ();
type Currency = currencies::Pallet<Runtime>;
type GetTotalBalance = ();
type WeightInfo = ();
}
impl common::Config for Runtime {
type DEXId = DEXId;
type LstId = common::LiquiditySourceType;
}
impl permissions::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl dex_manager::Config for Runtime {}
impl trading_pair::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type WeightInfo = ();
}
impl demeter_farming_platform::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type DemeterAssetId = ();
const BLOCKS_PER_HOUR_AND_A_HALF: BlockNumberFor<Self> = 900;
type WeightInfo = ();
}
impl pool_xyk::Config for Runtime {
const MIN_XOR: Balance = balance!(0.0007);
type RuntimeEvent = RuntimeEvent;
type PairSwapAction = pool_xyk::PairSwapAction<AssetId, AccountId, TechAccountId>;
type DepositLiquidityAction =
pool_xyk::DepositLiquidityAction<AssetId, AccountId, TechAccountId>;
type WithdrawLiquidityAction =
pool_xyk::WithdrawLiquidityAction<AssetId, AccountId, TechAccountId>;
type PolySwapAction = pool_xyk::PolySwapAction<AssetId, AccountId, TechAccountId>;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type EnsureTradingPairExists = trading_pair::Pallet<Runtime>;
type GetFee = GetXykFee;
type OnPoolCreated = PswapDistribution;
type OnPoolReservesChanged = ();
type WeightInfo = ();
type XSTMarketInfo = ();
type GetTradingPairRestrictedFlag = GetTradingPairRestrictedFlag;
}
impl multicollateral_bonding_curve_pool::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LiquidityProxy = ();
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type EnsureTradingPairExists = trading_pair::Pallet<Runtime>;
type PriceToolsPallet = ();
type VestedRewardsPallet = VestedRewards;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type BuyBackHandler = ();
type BuyBackXSTPercent = GetTBCBuyBackXSTPercent;
type WeightInfo = ();
}
impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
}
parameter_types! {
pub const CeresAssetId: AssetId = CERES_ASSET_ID;
}
impl ceres_token_locker::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CeresAssetId = CeresAssetId;
type WeightInfo = ();
}
impl pallet_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
impl ceres_liquidity_locker::Config for Runtime {
const BLOCKS_PER_ONE_DAY: BlockNumberFor<Self> = 14_440;
type RuntimeEvent = RuntimeEvent;
type XYKPool = PoolXYK;
type DemeterFarmingPlatform = DemeterFarmingPlatform;
type CeresAssetId = CeresAssetId;
type WeightInfo = ();
}
impl pswap_distribution::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
const PSWAP_BURN_PERCENT: Percent = Percent::from_percent(3);
type GetIncentiveAssetId = GetIncentiveAssetId;
type GetXSTAssetId = GetBuyBackAssetId;
type LiquidityProxy = ();
type CompatBalance = Balance;
type GetDefaultSubscriptionFrequency = GetDefaultSubscriptionFrequency;
type GetBurnUpdateFrequency = GetBurnUpdateFrequency;
type GetTechnicalAccountId = GetPswapDistributionAccountId;
type EnsureDEXManager = ();
type OnPswapBurnedAggregator = ();
type WeightInfo = ();
type GetParliamentAccountId = GetParliamentAccountId;
type PoolXykPallet = PoolXYK;
type BuyBackHandler = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;
}
impl technical::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type TechAssetId = TechAssetId;
type TechAccountId = TechAccountId;
type Trigger = ();
type Condition = ();
type SwapAction = pool_xyk::PolySwapAction<AssetId, AccountId, TechAccountId>;
}
impl tokens::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type Amount = Amount;
type CurrencyId = AssetId;
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type CurrencyHooks = ();
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = ();
type DustRemovalWhitelist = Everything;
}
impl currencies::Config for Runtime {
type MultiCurrency = Tokens;
type NativeCurrency = BasicCurrencyAdapter<Runtime, Balances, Amount, BlockNumber>;
type GetNativeCurrencyId = <Runtime as assets::Config>::GetBaseAssetId;
type WeightInfo = ();
}
parameter_types! {
pub const ExistentialDeposit: u128 = 0;
pub const TransferFee: u128 = 0;
pub const CreationFee: u128 = 0;
pub const TransactionByteFee: u128 = 1;
}
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type DustRemoval = ();
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = ();
}
#[allow(clippy::type_complexity)]
pub struct ExtBuilder {
pub endowed_assets: Vec<(
AssetId,
AccountId,
AssetSymbol,
AssetName,
BalancePrecision,
Balance,
bool,
Option<ContentSource>,
Option<Description>,
)>,
initial_dex_list: Vec<(DEXId, DEXInfo<AssetId>)>,
endowed_accounts: Vec<(AccountId, AssetId, Balance)>,
initial_permission_owners: Vec<(u32, Scope, Vec<AccountId>)>,
initial_permissions: Vec<(AccountId, Scope, Vec<u32>)>,
}
impl Default for ExtBuilder {
fn default() -> Self {
Self {
endowed_assets: vec![],
initial_dex_list: vec![
(
DEX_A_ID,
DEXInfo {
base_asset_id: XOR,
synthetic_base_asset_id: XST,
is_public: true,
},
),
(
DEX_B_ID,
DEXInfo {
base_asset_id: XSTUSD,
synthetic_base_asset_id: XST,
is_public: true,
},
),
],
endowed_accounts: vec![
(ALICE, CERES_ASSET_ID, balance!(15000)),
(BOB, CERES_ASSET_ID, balance!(5)),
(CHARLES, CERES_ASSET_ID, balance!(3000)),
],
initial_permission_owners: vec![
(MANAGE_DEX, Scope::Limited(hash(&DEX_A_ID)), vec![BOB]),
(MANAGE_DEX, Scope::Limited(hash(&DEX_B_ID)), vec![BOB]),
],
initial_permissions: vec![
(ALICE, Scope::Limited(hash(&DEX_A_ID)), vec![MANAGE_DEX]),
(ALICE, Scope::Limited(hash(&DEX_B_ID)), vec![MANAGE_DEX]),
],
}
}
}
impl ExtBuilder {
#[cfg(feature = "runtime-benchmarks")]
pub fn benchmarking() -> Self {
Self {
endowed_assets: vec![
(
CERES_ASSET_ID,
ALICE,
AssetSymbol(b"CERES".to_vec()),
AssetName(b"Ceres".to_vec()),
18,
0,
true,
None,
None,
),
(
XOR,
ALICE,
AssetSymbol(b"XOR".to_vec()),
AssetName(b"XOR".to_vec()),
18,
0,
true,
None,
None,
),
(
PSWAP,
ALICE,
AssetSymbol(b"PSWAP".to_vec()),
AssetName(b"PSWAP".to_vec()),
18,
0,
true,
None,
None,
),
],
..Default::default()
}
}
pub fn build(self) -> sp_io::TestExternalities {
let mut t = SystemConfig::default().build_storage::<Runtime>().unwrap();
dex_manager::GenesisConfig::<Runtime> {
dex_list: self.initial_dex_list,
}
.assimilate_storage(&mut t)
.unwrap();
TokensConfig {
balances: self.endowed_accounts,
}
.assimilate_storage(&mut t)
.unwrap();
permissions::GenesisConfig::<Runtime> {
initial_permission_owners: self.initial_permission_owners,
initial_permissions: self.initial_permissions,
}
.assimilate_storage(&mut t)
.unwrap();
assets::GenesisConfig::<Runtime> {
endowed_assets: self.endowed_assets,
}
.assimilate_storage(&mut t)
.unwrap();
t.into()
}
}
pub fn run_to_block(n: u64) {
while System::block_number() < n {
System::on_finalize(System::block_number());
System::set_block_number(System::block_number() + 1);
System::on_initialize(System::block_number());
CeresLaunchpad::on_initialize(System::block_number());
}
}