Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
3302020
Reorganize XCM configuration
sea212 Jun 4, 2022
2bae5e5
Comment XcmConfig and mark necessary changes
sea212 Jun 4, 2022
f172dc4
Implement and configure AssetTransactor
sea212 Jun 5, 2022
a09a350
Configure and comment XCM Barrier
sea212 Jun 16, 2022
8c5f164
Configure XCM IsReserve
sea212 Jun 16, 2022
47179af
Prepare Trader implementation for XcmConfig
sea212 Jun 16, 2022
829491a
Merge branch 'main' into sea212-integrate-aUSD
sea212 Aug 17, 2022
62c05d9
Rename Asset::Ztg -> Asset::ZTG (merge artifact)
sea212 Aug 17, 2022
a204b9a
Merge artifacts, work on XCM impl
sea212 Aug 19, 2022
c735f24
Use MultiAssetTransactor and latest orml pallets
sea212 Sep 25, 2022
15153e8
Add asset registry and AssetProcessor implementation
sea212 Sep 25, 2022
071e50d
Integrate asset-registry, implement fee structure
sea212 Sep 25, 2022
dd80b26
Finalize: XCM Weight/Fee, Trader, Treasury
sea212 Sep 26, 2022
9f2ef67
Fix key conversion & GenesisConfig
sea212 Sep 26, 2022
28517a8
Comment + Cargo fmt
sea212 Sep 26, 2022
45a887a
Merge branch 'main' into sea212-integrate-aUSD
sea212 Sep 26, 2022
49030cb
Include xTokens
sea212 Oct 11, 2022
4f5ab0f
Add integration test environment & XCM test setup
sea212 Oct 31, 2022
c1e2b96
Finalize simulated network preparation
sea212 Nov 1, 2022
49d468e
Add currency conversion tests
sea212 Nov 1, 2022
31933cd
Finalize CurrencyID<>MultiLocation tests
sea212 Nov 2, 2022
208c862
Add helper functions and sibling currency<>location conversion test
sea212 Nov 2, 2022
78b1018
Add relative view trader for ZTG
sea212 Nov 2, 2022
bb30dfa
Extend XCM transfer tests
sea212 Nov 4, 2022
b28542b
Add ZTG -> Sibling -> ZTG test
sea212 Nov 4, 2022
b6a7d92
Read ParaId from ParachainInfo + fix tests
sea212 Nov 5, 2022
5a079b6
Fix KSM <> ZTG XCM tests
sea212 Nov 5, 2022
4e67549
Fix Fee (off by 2000x)
sea212 Nov 5, 2022
a708fb1
Increase ExistentialDeposit & Add Treasury to dust whitelist
sea212 Nov 5, 2022
b7b665b
Fix custom fee calculation
sea212 Nov 5, 2022
d31dcc6
Add custom fee test
sea212 Nov 5, 2022
6cee15d
Finalize XCM integration tests
sea212 Nov 5, 2022
e914d54
Remove unused modules
sea212 Nov 7, 2022
ec00ef2
Add XCM related pallets to common runtime
sea212 Nov 7, 2022
0d460a1
Cleanup code
sea212 Nov 7, 2022
d990634
Add proper XCM configuration to Zeitgeist runtime
sea212 Nov 7, 2022
3e84785
Use ExistentialDeposit directly in integration test
sea212 Nov 8, 2022
857cf74
Add integration tests to Zeitgeist runtime
sea212 Nov 8, 2022
d6030ac
Allow only Kusama as parent on Zeitgeist + Cleanup
sea212 Nov 8, 2022
0ff4e5f
Remove dead code
sea212 Nov 9, 2022
e170adb
Update changelog_for_devs.md
sea212 Nov 9, 2022
a5ed076
Use correct treasury pallet id (as before)
sea212 Nov 17, 2022
7ebe84a
Use unambiguous names for setters
sea212 Nov 17, 2022
fc6ae19
Convert comment to docstring
sea212 Nov 17, 2022
354de95
Fix wrong comment
sea212 Nov 17, 2022
b2c1e1f
Reset emulated testnet in any case
sea212 Nov 22, 2022
0f59db0
Remove unnecessary commas
sea212 Nov 23, 2022
49b54ac
Improve readability of numbers
sea212 Nov 23, 2022
391fc02
Fix docstring
sea212 Nov 23, 2022
b6ef8cc
Remove invalid initial balance (integration test)
sea212 Nov 23, 2022
dab6d11
Improve style
sea212 Nov 24, 2022
884a32d
Use more descriptive function name
sea212 Nov 24, 2022
fdfa04b
Add additional balance guard to xcm tests
sea212 Nov 24, 2022
54d3889
Use ::parachain_id() instead of ::get()
sea212 Nov 24, 2022
37a1536
Reduce nested match depth
sea212 Nov 24, 2022
b503c34
Update changelog
sea212 Nov 24, 2022
b20e13f
Add missing crates to runtime-benchmarks feature
sea212 Nov 24, 2022
21a76e4
Merge branch 'main' into sea212-integrate-aUSD
sea212 Nov 24, 2022
77495ed
Repair build
sea212 Nov 24, 2022
1d31ae0
Satisfy cargo fmt and taplo
sea212 Nov 24, 2022
e153330
Update XCM weight in tests
sea212 Nov 24, 2022
c003dda
Satisfy Clippy
sea212 Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Comment + Cargo fmt
  • Loading branch information
sea212 committed Sep 26, 2022
commit 28517a811a15492d12eb161b4328d214f5647629
8 changes: 4 additions & 4 deletions node/src/chain_spec/battery_station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use zeitgeist_primitives::{
ztg::{LIQUIDITY_MINING, LIQUIDITY_MINING_PTD},
BASE,
},
types::{Asset::ForeignAsset, AccountId}
types::{AccountId, Asset::ForeignAsset},
};

#[cfg(feature = "parachain")]
Expand Down Expand Up @@ -115,11 +115,11 @@ pub(super) fn get_wasm() -> Result<&'static [u8], String> {

generate_generic_genesis_function!(
battery_station_runtime,
asset_registry: battery_station_runtime::AssetRegistryConfig {
assets: vec![],
asset_registry: battery_station_runtime::AssetRegistryConfig {
assets: vec![],
last_asset_id: ForeignAsset(0),
},
sudo: battery_station_runtime::SudoConfig {
sudo: battery_station_runtime::SudoConfig {
key: Some(root_key_staging_battery_station()),
},
);
Expand Down
6 changes: 3 additions & 3 deletions node/src/chain_spec/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ fn authority_keys_from_seed(

generate_generic_genesis_function! {
battery_station_runtime,
asset_registry: battery_station_runtime::AssetRegistryConfig {
assets: vec![],
asset_registry: battery_station_runtime::AssetRegistryConfig {
assets: vec![],
last_asset_id: ForeignAsset(0),
},
sudo: battery_station_runtime::SudoConfig {
sudo: battery_station_runtime::SudoConfig {
key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
},
}
Expand Down
17 changes: 14 additions & 3 deletions primitives/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,29 @@ use scale_info::TypeInfo;
#[cfg_attr(feature = "std", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[derive(
Clone, Copy, Debug, Decode, Default, Eq, Encode, MaxEncodedLen, Ord, PartialEq, PartialOrd, TypeInfo,
Clone,
Copy,
Debug,
Decode,
Default,
Eq,
Encode,
MaxEncodedLen,
Ord,
PartialEq,
PartialOrd,
TypeInfo,
)]
pub enum Asset<MI: MaxEncodedLen> {
CategoricalOutcome(MI, CategoryIndex),
ScalarOutcome(MI, ScalarPosition),
CombinatorialOutcome,
PoolShare(SerdeWrapper<PoolId>),
#[default] Ztg,
#[default]
Ztg,
ForeignAsset(u32),
}


/// In a scalar market, users can either choose a `Long` position,
/// meaning that they think the outcome will be closer to the upper bound
/// or a `Short` position meaning that they think the outcome will be closer
Expand Down
20 changes: 11 additions & 9 deletions runtime/battery-station/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ use {
frame_support::traits::{AsEnsureOriginWithArg, Everything, Nothing},
frame_system::EnsureSigned,
xcm_builder::{EnsureXcmOrigin, FixedWeightBounds, LocationInverter},
xcm_config::{asset_registry::{CustomAssetProcessor, CustomMetadata}, config::{LocalOriginToLocation, XcmConfig, XcmOriginToTransactDispatchOrigin, XcmRouter}},
xcm_config::{
asset_registry::{CustomAssetProcessor, CustomMetadata},
config::{LocalOriginToLocation, XcmConfig, XcmOriginToTransactDispatchOrigin, XcmRouter},
},
};

use frame_support::construct_runtime;
Expand Down Expand Up @@ -142,21 +145,20 @@ create_runtime_with_additional_pallets!(
UnknownTokens: orml_unknown_tokens::{Pallet, Storage, Event} = 152,
);


impl pallet_sudo::Config for Runtime {
type Call = Call;
type Event = Event;
}

#[cfg(feature = "parachain")]
impl orml_asset_registry::Config for Runtime {
type AssetId = CurrencyId;
type AssetProcessor = CustomAssetProcessor;
type AuthorityOrigin = AsEnsureOriginWithArg<EnsureRootOrTwoThirdsCouncil>;
type Balance = Balance;
type CustomMetadata = CustomMetadata;
type Event = Event;
type WeightInfo = ();
type AssetId = CurrencyId;
type AssetProcessor = CustomAssetProcessor;
type AuthorityOrigin = AsEnsureOriginWithArg<EnsureRootOrTwoThirdsCouncil>;
type Balance = Balance;
type CustomMetadata = CustomMetadata;
type Event = Event;
type WeightInfo = ();
}

#[cfg(feature = "parachain")]
Expand Down
2 changes: 1 addition & 1 deletion runtime/battery-station/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
pub mod asset_registry;
pub mod config;
pub mod fees;
pub mod parachains;
pub mod parachains;
64 changes: 32 additions & 32 deletions runtime/battery-station/src/xcm_config/asset_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use crate::{Balance, CurrencyId};
use orml_traits::asset_registry::{AssetMetadata, AssetProcessor};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_runtime::DispatchError;
use scale_info::TypeInfo;
use sp_runtime::DispatchError;

#[derive(
Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
Expand Down Expand Up @@ -48,47 +48,47 @@ impl AssetProcessor<CurrencyId, AssetMetadata<Balance, CustomMetadata>> for Cust
}

#[derive(
Clone,
Copy,
Default,
PartialOrd,
Ord,
PartialEq,
Eq,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
Clone,
Copy,
Default,
PartialOrd,
Ord,
PartialEq,
Eq,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
/// Custom XC asset metadata
pub struct CustomMetadata {
/// XCM-related metadata.
pub xcm: XcmMetadata,
/// XCM-related metadata.
pub xcm: XcmMetadata,

/// Whether an asset can be used in pools.
pub allow_in_pool: bool,
/// Whether an asset can be used in pools.
pub allow_in_pool: bool,
}

#[derive(
Clone,
Copy,
Default,
PartialOrd,
Ord,
PartialEq,
Eq,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
Clone,
Copy,
Default,
PartialOrd,
Ord,
PartialEq,
Eq,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
pub struct XcmMetadata {
/// The factor used to determine the fee.
/// The factor used to determine the fee.
/// It is multiplied by the fee that would have been paind in native currency, so it represents
/// the ratio `native_price / other_asset_price`. It is a fixed point decimal number containing
/// as many fractional decimals as the asset it is used for contains.
/// Should be updated regularly.
pub fee_factor: Option<Balance>,
}
pub fee_factor: Option<Balance>,
}
89 changes: 44 additions & 45 deletions runtime/battery-station/src/xcm_config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,41 @@
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

use super::{
fees::{native_per_second, FixedConversionRateProvider},
parachains::zeitgeist::ZTG_KEY,
};
use crate::{
AssetManager, AccountId, Ancestry, Balance, Call, CurrencyId, MaxInstructions, Origin,
ParachainSystem, PolkadotXcm, RelayChainOrigin, RelayNetwork,
UnitWeightCost, UnknownTokens, XcmpQueue, ZeitgeistTreasuryAccount, AssetRegistry
AccountId, Ancestry, AssetManager, AssetRegistry, Balance, Call, CurrencyId, MaxInstructions,
Origin, ParachainSystem, PolkadotXcm, RelayChainOrigin, RelayNetwork, UnitWeightCost,
UnknownTokens, XcmpQueue, ZeitgeistTreasuryAccount,
};
use super::{fees::{native_per_second, FixedConversionRateProvider}, parachains::zeitgeist::ZTG_KEY};

use alloc::vec::Vec;
use frame_support::{match_types, parameter_types, traits::Everything};
use orml_asset_registry::{AssetRegistryTrader, FixedRateAssetRegistryTrader};
use orml_traits::{MultiCurrency, location::AbsoluteReserveProvider};
use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset, UnknownAsset};
use orml_traits::{location::AbsoluteReserveProvider, MultiCurrency};
use orml_xcm_support::{
DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset, UnknownAsset,
};
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::Convert;
use xcm::latest::{
prelude::{GeneralKey, X1, AssetId, Concrete, MultiAsset},
BodyId, Junction, Junctions, MultiLocation,
use xcm::{
latest::{
prelude::{AssetId, Concrete, GeneralKey, MultiAsset, X1},
BodyId, Junction, Junctions, MultiLocation,
},
opaque::latest::Fungibility::Fungible,
};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, FixedWeightBounds, FixedRateOfFungible, LocationInverter,
AllowTopLevelPaidExecutionFrom, FixedRateOfFungible, FixedWeightBounds, LocationInverter,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TakeRevenue,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue,
TakeWeightCredit,
};
use xcm_executor::Config;
use xcm::opaque::latest::Fungibility::Fungible;
use zeitgeist_primitives::types::Asset;

pub struct XcmConfig;
Expand Down Expand Up @@ -77,7 +84,9 @@ impl Config for XcmConfig {
type SubscriptionService = PolkadotXcm;
/// The means of purchasing weight credit for XCM execution.
type Trader = Trader;
/// TODO: The means of determining an XCM message's weight.
/// The means of determining an XCM message's weight.
// Adds UnitWeightCost per instruction plus the weight of each instruction.
// The total number of instructions are bounded by MaxInstructions
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
/// How to send an onward XCM message.
type XcmSender = XcmRouter;
Expand All @@ -100,49 +109,45 @@ pub type Barrier = (
pub type Trader = (
// In case the asset in question is the native currency, it will charge
// the default base fee per second and deposits them into treasury
FixedRateOfFungible<ZtgPerSecond, ToTreasury>,
FixedRateOfFungible<ZtgPerSecond, ToTreasury>,
// For all other assets the base fee per second will tried to be derived
// through the `fee_factor` entry in the asset registry. If the asset is
// not present in the asset registry, the default base fee per second is used.
// Deposits all fees into the treasury.
AssetRegistryTrader<
FixedRateAssetRegistryTrader<FixedConversionRateProvider<AssetRegistry>>,
ToTreasury,
>,
AssetRegistryTrader<
FixedRateAssetRegistryTrader<FixedConversionRateProvider<AssetRegistry>>,
ToTreasury,
>,
);

pub struct ToTreasury;
impl TakeRevenue for ToTreasury {
fn take_revenue(revenue: MultiAsset) {
fn take_revenue(revenue: MultiAsset) {
use xcm_executor::traits::Convert;

if let MultiAsset {
id: Concrete(location),
fun: Fungible(amount),
} = revenue.clone()
{
if let Ok(asset_id) =
<AssetConvert as Convert<MultiLocation, CurrencyId>>::convert(location.clone())
{
let _ = AssetManager::deposit(asset_id, &ZeitgeistTreasuryAccount::get(), amount);
} else {
if let MultiAsset { id: Concrete(location), fun: Fungible(amount) } = revenue.clone() {
if let Ok(asset_id) =
<AssetConvert as Convert<MultiLocation, CurrencyId>>::convert(location.clone())
{
let _ = AssetManager::deposit(asset_id, &ZeitgeistTreasuryAccount::get(), amount);
} else {
// TODO this is wrong, use target as second parameter
let _ = UnknownTokens::deposit(&revenue, &location);
}
}
}
}
}
}

parameter_types! {
pub CheckAccount: AccountId = PolkadotXcm::check_account();
/// The amount of ZTG charged per second of execution.
pub ZtgPerSecond: (AssetId, u128) = (
MultiLocation::new(
pub ZtgPerSecond: (AssetId, u128) = (
MultiLocation::new(
0,
X1(general_key(ZTG_KEY)),
).into(),
native_per_second(),
);
native_per_second(),
);
}

/// Means for transacting assets on this chain.
Expand Down Expand Up @@ -178,10 +183,7 @@ pub struct AssetConvert;
impl Convert<CurrencyId, Option<MultiLocation>> for AssetConvert {
fn convert(id: CurrencyId) -> Option<MultiLocation> {
match id {
Asset::Ztg => Some(MultiLocation::new(
0,
X1(general_key(ZTG_KEY)),
).into()),
Asset::Ztg => Some(MultiLocation::new(0, X1(general_key(ZTG_KEY))).into()),
Asset::ForeignAsset(_) => AssetRegistry::multilocation(&id).ok()?,
_ => None,
}
Expand All @@ -194,13 +196,10 @@ impl Convert<CurrencyId, Option<MultiLocation>> for AssetConvert {
impl xcm_executor::traits::Convert<MultiLocation, CurrencyId> for AssetConvert {
fn convert(location: MultiLocation) -> Result<CurrencyId, MultiLocation> {
match location.clone() {
MultiLocation {
parents: 0,
interior: X1(GeneralKey(key)),
} => match &key[..] {
MultiLocation { parents: 0, interior: X1(GeneralKey(key)) } => match &key[..] {
ZTG_KEY => Ok(CurrencyId::Ztg),
_ => AssetRegistry::location_to_asset_id(location.clone()).ok_or(location),
}
},
_ => AssetRegistry::location_to_asset_id(location.clone()).ok_or(location),
}
}
Expand Down
Loading