Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sora-xor/sora2-network in…
Browse files Browse the repository at this point in the history
…to doc
  • Loading branch information
sorabot committed Nov 1, 2024
2 parents 3aa5199 + e9f8055 commit 68746d8
Show file tree
Hide file tree
Showing 42 changed files with 806 additions and 2,295 deletions.
601 changes: 412 additions & 189 deletions common/src/mock.rs

Large diffs are not rendered by default.

139 changes: 17 additions & 122 deletions pallets/apollo-platform/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
use {
crate as apollo_platform,
common::{
balance, fixed, hash,
mock::{ExistentialDeposits, GetTradingPairRestrictedFlag},
balance, hash,
mock::ExistentialDeposits,
mock_assets_config, mock_common_config, mock_currencies_config, mock_dex_api_config,
mock_dex_manager_config, mock_frame_system_config, mock_pallet_balances_config,
mock_pallet_timestamp_config, mock_permissions_config, mock_price_tools_config,
mock_technical_config, mock_tokens_config, mock_trading_pair_config,
mock_vested_rewards_config,
mock_dex_manager_config, mock_frame_system_config, mock_liquidity_proxy_config,
mock_multicollateral_bonding_curve_pool_config, mock_pallet_balances_config,
mock_pallet_timestamp_config, mock_permissions_config, mock_pool_xyk_config,
mock_price_tools_config, mock_pswap_distribution_config, mock_technical_config,
mock_tokens_config, mock_trading_pair_config, mock_vested_rewards_config,
prelude::{Balance, SwapOutcome},
AssetId32, AssetName, AssetSymbol, BalancePrecision, ContentSource,
DEXId::Polkaswap,
DEXInfo, Description, Fixed, FromGenericPair, LiquidityProxyTrait, PriceToolsProvider,
PriceVariant, APOLLO_ASSET_ID, CERES_ASSET_ID, DAI, DOT, KSM, PSWAP, VXOR, XOR, XST,
DEXInfo, Description, FromGenericPair, LiquidityProxyTrait, PriceToolsProvider,
PriceVariant, APOLLO_ASSET_ID, CERES_ASSET_ID, DAI, DOT, KSM, VXOR, XOR, XST,
},
currencies::BasicCurrencyAdapter,
frame_support::{
construct_runtime,
pallet_prelude::Weight,
parameter_types,
traits::{ConstU64, Everything, GenesisBuild, Hooks},
traits::{ConstU32, ConstU64, Everything, GenesisBuild, Hooks},
},
frame_system::{
self, offchain::SendTransactionTypes, pallet_prelude::BlockNumberFor, EnsureRoot, RawOrigin,
self, offchain::SendTransactionTypes, pallet_prelude::BlockNumberFor, RawOrigin,
},
permissions::{Scope, MANAGE_DEX},
sp_core::{ConstU32, H256},
sp_runtime::{
testing::{Header, TestXt},
traits::{BlakeTwo256, IdentityLookup, Zero},
AccountId32, Perbill, Percent, Permill,
},
sp_runtime::{testing::TestXt, traits::Zero, AccountId32, Perbill},
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
Expand Down Expand Up @@ -94,13 +90,17 @@ pub type MockExtrinsic = TestXt<RuntimeCall, ()>;
mock_assets_config!(Runtime);
mock_common_config!(Runtime);
mock_currencies_config!(Runtime);
mock_dex_api_config!(Runtime);
mock_dex_api_config!(Runtime, multicollateral_bonding_curve_pool::Pallet<Runtime>);
mock_dex_manager_config!(Runtime);
mock_frame_system_config!(Runtime);
mock_liquidity_proxy_config!(Runtime);
mock_multicollateral_bonding_curve_pool_config!(Runtime);
mock_pallet_balances_config!(Runtime);
mock_pallet_timestamp_config!(Runtime);
mock_permissions_config!(Runtime);
mock_pool_xyk_config!(Runtime);
mock_price_tools_config!(Runtime);
mock_pswap_distribution_config!(Runtime, PoolXYK);
mock_technical_config!(Runtime, pool_xyk::PolySwapAction<DEXId, AssetId, AccountId, TechAccountId>);
mock_tokens_config!(Runtime);
mock_trading_pair_config!(Runtime);
Expand All @@ -119,9 +119,6 @@ parameter_types! {
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 GetXykMaxIssuanceRatio: Fixed = fixed!(1.5);
pub GetIncentiveAssetId: AssetId = PSWAP;
pub const GetDefaultSubscriptionFrequency: BlockNumber = 10;
pub const GetBurnUpdateFrequency: BlockNumber = 14400;
pub GetParliamentAccountId: AccountId = AccountId32::from([100; 32]);
Expand All @@ -132,47 +129,10 @@ parameter_types! {
pub const GetNumSamples: usize = 40;
pub const GetBaseAssetId: AssetId = APOLLO_ASSET_ID;
pub const GetBuyBackAssetId: AssetId = VXOR;
pub GetLiquidityProxyTechAccountId: TechAccountId = {
TechAccountId::from_generic_pair(
liquidity_proxy::TECH_ACCOUNT_PREFIX.to_vec(),
liquidity_proxy::TECH_ACCOUNT_MAIN.to_vec(),
)
};
pub GetLiquidityProxyAccountId: AccountId = {
let tech_account_id = GetLiquidityProxyTechAccountId::get();
technical::Pallet::<Runtime>::tech_account_id_to_account_id(&tech_account_id)
.expect("Failed to get ordinary account id for technical account id.")
};
pub GetADARAccountId: AccountId = AccountId32::from([14; 32]);
pub GetMarketMakerRewardsAccountId: AccountId = AccountId32::from([9; 32]);
pub GetBondingCurveRewardsAccountId: AccountId = AccountId32::from([10; 32]);
pub GetFarmingRewardsAccountId: AccountId = AccountId32::from([12; 32]);
pub GetTBCBuyBackTBCDPercent: Fixed = fixed!(0.025);
pub GetXykIrreducibleReservePercent: Percent = Percent::from_percent(1);
pub GetTbcIrreducibleReservePercent: Percent = Percent::from_percent(1);
pub GetInternalSlippageTolerancePercent: Permill = Permill::from_rational(1u32, 1000); // 0.1%
}

impl liquidity_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LiquidityRegistry = dex_api::Pallet<Runtime>;
type GetNumSamples = GetNumSamples;
type GetTechnicalAccountId = GetLiquidityProxyAccountId;
type PrimaryMarketTBC = ();
type PrimaryMarketXST = ();
type SecondaryMarket = ();
type VestedRewardsPallet = vested_rewards::Pallet<Runtime>;
type LockedLiquiditySourcesManager = trading_pair::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type GetADARAccountId = GetADARAccountId;
type ADARCommissionRatioUpdateOrigin = EnsureRoot<AccountId>;
type MaxAdditionalDataLengthXorlessTransfer = ConstU32<128>;
type MaxAdditionalDataLengthSwapTransferBatch = ConstU32<2000>;
type GetChameleonPools = common::mock::GetChameleonPools;
type AssetInfoProvider = assets::Pallet<Runtime>;
type InternalSlippageTolerance = GetInternalSlippageTolerancePercent;
type WeightInfo = ();
}

impl ceres_liquidity_locker::Config for Runtime {
Expand All @@ -184,71 +144,6 @@ impl ceres_liquidity_locker::Config for Runtime {
type WeightInfo = ();
}

impl multicollateral_bonding_curve_pool::Config for Runtime {
const RETRY_DISTRIBUTION_FREQUENCY: BlockNumber = 1000;
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 BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent;
type AssetInfoProvider = assets::Pallet<Runtime>;
type IrreducibleReserve = GetTbcIrreducibleReservePercent;
type WeightInfo = ();
}

impl pool_xyk::Config for Runtime {
const MIN_XOR: Balance = balance!(0.0007);
type RuntimeEvent = RuntimeEvent;
type PairSwapAction = pool_xyk::PairSwapAction<DEXId, AssetId, AccountId, TechAccountId>;
type DepositLiquidityAction =
pool_xyk::DepositLiquidityAction<AssetId, AccountId, TechAccountId>;
type WithdrawLiquidityAction =
pool_xyk::WithdrawLiquidityAction<AssetId, AccountId, TechAccountId>;
type PolySwapAction = pool_xyk::PolySwapAction<DEXId, 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 EnabledSourcesManager = trading_pair::Pallet<Runtime>;
type GetFee = GetXykFee;
type GetMaxIssuanceRatio = GetXykMaxIssuanceRatio;
type OnPoolCreated = PswapDistribution;
type OnPoolReservesChanged = ();
type XSTMarketInfo = ();
type GetTradingPairRestrictedFlag = GetTradingPairRestrictedFlag;
type GetChameleonPools = common::mock::GetChameleonPools;
type AssetInfoProvider = assets::Pallet<Runtime>;
type AssetRegulator = ();
type IrreducibleReserve = GetXykIrreducibleReservePercent;
type PoolAdjustPeriod = sp_runtime::traits::ConstU64<1>;
type WeightInfo = ();
}

impl pswap_distribution::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
const PSWAP_BURN_PERCENT: Percent = Percent::from_percent(3);
type GetIncentiveAssetId = GetIncentiveAssetId;
type GetBuyBackAssetId = 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>;
type GetChameleonPools = common::mock::GetChameleonPools;
type AssetInfoProvider = assets::Pallet<Runtime>;
}

pub struct MockPriceTools;

impl PriceToolsProvider<AssetId> for MockPriceTools {
Expand Down
3 changes: 0 additions & 3 deletions pallets/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild};
use frame_support::weights::Weight;
use frame_support::{construct_runtime, parameter_types};
use sp_core::H256;
use sp_runtime::testing::Header;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use sp_runtime::DispatchError;
use sp_runtime::Perbill;

Expand Down
41 changes: 5 additions & 36 deletions pallets/band/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,15 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::{self as band, Config};
use common::{mock_oracle_proxy_config, mock_pallet_timestamp_config};
use common::{mock_frame_system_config, mock_oracle_proxy_config, mock_pallet_timestamp_config};
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU16, ConstU64},
};
use frame_system as system;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
traits::{ConstU16, ConstU32},
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
type AccountId = u64;
type Moment = u64;

// Configure a mock runtime to test the pallet.
Expand All @@ -64,33 +59,6 @@ parameter_types! {
pub const GetRateStaleBlockPeriod: u64 = 600;
}

impl system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

impl Config for Runtime {
type Symbol = String;
type RuntimeEvent = RuntimeEvent;
Expand All @@ -103,12 +71,13 @@ impl Config for Runtime {
type MaxRelaySymbols = frame_support::traits::ConstU32<100>;
}

mock_frame_system_config!(Runtime, ConstU16<42>, ConstU32<16>, ());
mock_oracle_proxy_config!(Runtime);
mock_pallet_timestamp_config!(Runtime);

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
system::GenesisConfig::default()
frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap()
.into()
Expand Down
53 changes: 9 additions & 44 deletions pallets/bridge-proxy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,16 @@ use bridge_types::{GenericNetworkId, H160};
use common::mock::ExistentialDeposits;
use common::{
balance, mock_assets_config, mock_common_config, mock_currencies_config,
mock_pallet_balances_config, mock_pallet_timestamp_config, mock_permissions_config,
mock_technical_config, mock_tokens_config, Amount, AssetId32, AssetName, AssetSymbol, Balance,
DEXId, FromGenericPair, PredefinedAssetId, DAI, ETH, XOR, XST,
mock_frame_system_config, mock_pallet_balances_config, mock_pallet_timestamp_config,
mock_permissions_config, mock_technical_config, mock_tokens_config, Amount, AssetId32,
AssetName, AssetSymbol, Balance, DEXId, FromGenericPair, PredefinedAssetId, DAI, ETH, XOR, XST,
};
use frame_support::parameter_types;
use frame_support::traits::{Everything, GenesisBuild};
use frame_system as system;
use sp_core::{ConstU128, ConstU64};
use frame_support::traits::{ConstU128, ConstU32, ConstU64, Everything, GenesisBuild};
use frame_system::{self, EnsureRoot};
use sp_keyring::sr25519::Keyring;
use sp_runtime::testing::Header;
use sp_runtime::traits::{
BlakeTwo256, Convert, IdentifyAccount, IdentityLookup, Keccak256, Verify,
};
use sp_runtime::traits::{Convert, IdentifyAccount, Keccak256, Verify};
use sp_runtime::{AccountId32, DispatchResult, MultiSignature};
use system::EnsureRoot;

use crate as proxy;

Expand Down Expand Up @@ -85,14 +80,13 @@ frame_support::construct_runtime!(
);

pub type Signature = MultiSignature;

pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

pub const BASE_EVM_NETWORK_ID: EVMChainId = EVMChainId::zero();

mock_assets_config!(Test);
mock_common_config!(Test);
mock_currencies_config!(Test);
mock_frame_system_config!(Test, (), ConstU32<65536>);
mock_pallet_balances_config!(Test);
mock_pallet_timestamp_config!(Test);
mock_permissions_config!(Test);
Expand All @@ -101,36 +95,6 @@ mock_tokens_config!(Test);

parameter_types! {
pub const BlockHashCount: u64 = 250;
}

impl system::Config for Test {
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>;
}

parameter_types! {
pub const GetBaseAssetId: AssetId = XOR;
pub const GetBuyBackAssetId: AssetId = XST;
}
Expand All @@ -155,6 +119,7 @@ parameter_types! {
pub const Decimals: u32 = 12;
}
pub struct FeeConverter;

impl Convert<U256, Balance> for FeeConverter {
fn convert(amount: U256) -> Balance {
common::eth::unwrap_balance(amount, Decimals::get())
Expand Down Expand Up @@ -295,7 +260,7 @@ impl proxy::Config for Test {
}

pub fn new_tester() -> sp_io::TestExternalities {
let mut storage = system::GenesisConfig::default()
let mut storage = frame_system::GenesisConfig::default()
.build_storage::<Test>()
.unwrap();

Expand Down
Loading

0 comments on commit 68746d8

Please sign in to comment.