Skip to content

Commit

Permalink
add convenience DEX (#273)
Browse files Browse the repository at this point in the history
* add pallet-asset-conversion and PoolAssets instance
* bump versions
  • Loading branch information
brenzi authored Feb 19, 2024
1 parent e578170 commit bcf6180
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 47 deletions.
18 changes: 16 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0"
smallvec = "1.11.0"
# num-traits feature needed for dex integer sq root:
primitive-types = { version = "0.12.1", default-features = false, features = ["codec", "num-traits", "scale-info"] }

# integritee pallets
pallet-asset-registry = { default-features = false, git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v1.6.0" }
Expand Down Expand Up @@ -55,6 +57,7 @@ orml-traits = { version = "0.7", default-features = false }
orml-xcm = { version = "0.7", default-features = false }
orml-xcm-support = { version = "0.7", default-features = false }
orml-xtokens = { version = "0.7", default-features = false }
pallet-asset-conversion = { version = "10.0.0", default-features = false }
pallet-assets = { version = "29.0.0", default-features = false }
pallet-aura = { version = "27.0.0", default-features = false }
pallet-authorship = { version = "28.0.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion polkadot-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "integritee-collator"
description = "The Integritee parachain collator binary"
# align major.minor revision with the runtimes. bump patch revision ad lib. make this the github release tag
version = "1.9.1"
version = "1.9.2"
authors = ["Integritee AG <hello@integritee.network>"]
homepage = "https://integritee.network/"
repository = "https://github.com/integritee-network/parachain"
Expand Down
11 changes: 8 additions & 3 deletions polkadot-parachains/integritee-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
name = "integritee-runtime"
description = "The Integritee parachain runtime"
# patch revision must match runtime spec_version
version = "1.9.48"
version = "1.9.49"
authors = ["Integritee AG <hello@integritee.network>"]
homepage = "https://integritee.network/"
repository = "https://github.com/integritee-network/parachain"
edition = "2021"

[dependencies]
integritee-parachains-common = { path = "../common", default-features = false }
log = { workspace = true }
parity-scale-codec = { workspace = true }
primitive-types = { workspace = true }
scale-info = { workspace = true }

integritee-parachains-common = { path = "../common", default-features = false }

# Substrate dependencies

# pallets
Expand All @@ -36,6 +36,7 @@ orml-traits = { workspace = true }
orml-xcm = { workspace = true }
orml-xcm-support = { workspace = true }
orml-xtokens = { workspace = true }
pallet-asset-conversion = { workspace = true }
pallet-asset-registry = { workspace = true }
pallet-assets = { workspace = true }
pallet-aura = { workspace = true }
Expand Down Expand Up @@ -127,6 +128,7 @@ std = [
"orml-xcm/std",
"orml-xtokens/std",
"pallet-assets/std",
"pallet-asset-conversion/std",
"pallet-asset-registry/std",
"pallet-aura/std",
"pallet-balances/std",
Expand Down Expand Up @@ -156,6 +158,7 @@ std = [
"parity-scale-codec/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"primitive-types/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
Expand Down Expand Up @@ -190,6 +193,7 @@ runtime-benchmarks = [
"hex-literal",
"orml-xtokens/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-asset-registry/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bounties/runtime-benchmarks",
Expand Down Expand Up @@ -232,6 +236,7 @@ try-runtime = [
"orml-xcm/try-runtime",
"orml-xtokens/try-runtime",
"pallet-assets/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-asset-registry/try-runtime",
"pallet-aura/try-runtime",
"pallet-balances/try-runtime",
Expand Down
145 changes: 110 additions & 35 deletions polkadot-parachains/integritee-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use frame_support::traits::{
fungible::HoldConsideration, tokens::PayFromAccount, ConstBool, EnsureOriginWithArg,
EqualPrivilegeOnly, Imbalance, InstanceFilter, LinearStoragePrice, OnUnbalanced,
};
use pallet_collective;
use parachains_common::AssetIdForTrustBackedAssets;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, ConstU32, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, ConvertInto, IdentityLookup},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
// A few exports that help ease life for downstream crates.
use cumulus_primitives_core::AggregateMessageOrigin;
pub use frame_support::{
construct_runtime,
Expand All @@ -63,12 +43,18 @@ pub use frame_support::{
use frame_support::{
derive_impl,
genesis_builder_helper::{build_config, create_default_config},
traits::tokens::ConversionFromAssetBalance,
ord_parameter_types,
traits::{
fungible::{HoldConsideration, NativeFromLeft, NativeOrWithId, UnionOf},
tokens::{imbalance::ResolveAssetTo, ConversionFromAssetBalance, PayFromAccount},
AsEnsureOriginWithArg, ConstBool, EnsureOriginWithArg, EqualPrivilegeOnly, Imbalance,
InstanceFilter, LinearStoragePrice, OnUnbalanced,
},
weights::ConstantMultiplier,
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureWithSuccess,
EnsureRoot, EnsureSignedBy, EnsureWithSuccess,
};
use integritee_parachains_common::{
fee::{SlowAdjustingFeeUpdate, WeightToFee},
Expand All @@ -79,22 +65,33 @@ use integritee_parachains_common::{
pub use integritee_parachains_common::{
AccountId, Address, Balance, BlockNumber, Hash, Header, Nonce, Signature, MILLISECS_PER_BLOCK,
};
use pallet_asset_conversion::{Ascending, Chain, WithFirstAsset};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
use parachains_common::message_queue::NarrowOriginToSibling;
use scale_info::TypeInfo;
use sp_core::ConstU128;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::RuntimeDebug;
pub use sp_runtime::{Perbill, Permill};

// TEE
pub use pallet_claims;
use pallet_collective;
pub use pallet_enclave_bridge;
pub use pallet_sidechain;
pub use pallet_teeracle;
pub use pallet_teerex::Call as TeerexCall;
pub use pallet_timestamp::Call as TimestampCall;
use parachains_common::{message_queue::NarrowOriginToSibling, AssetIdForTrustBackedAssets};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, ConstU128, ConstU32, OpaqueMetadata};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, ConvertInto, IdentityLookup},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, RuntimeDebug,
};
pub use sp_runtime::{Perbill, Permill};
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

mod helpers;
mod weights;
Expand Down Expand Up @@ -122,7 +119,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("integritee-parachain"),
impl_name: create_runtime_str!("integritee-full"),
authoring_version: 2,
spec_version: 48,
spec_version: 49,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 6,
Expand Down Expand Up @@ -814,7 +811,8 @@ impl EnsureOriginWithArg<RuntimeOrigin, AssetIdForTrustBackedAssets> for NoAsset
}
}

impl pallet_assets::Config for Runtime {
pub type MainAssetsInstance = pallet_assets::Instance1;
impl pallet_assets::Config<MainAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = AssetBalance;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
Expand Down Expand Up @@ -865,6 +863,78 @@ impl pallet_asset_registry::Config for Runtime {
type BenchmarkHelper = AssetRegistryBenchmarkHelper;
}

pub type NativeAndAssets = UnionOf<
Balances,
Assets,
NativeFromLeft,
NativeOrWithId<AssetIdForTrustBackedAssets>,
AccountId,
>;
pub type AscendingLocator = Ascending<AccountId, NativeOrWithId<AssetIdForTrustBackedAssets>>;
pub type WithFirstAssetLocator =
WithFirstAsset<Native, AccountId, NativeOrWithId<AssetIdForTrustBackedAssets>>;

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type HigherPrecisionBalance = sp_core::U256;
type AssetKind = NativeOrWithId<AssetIdForTrustBackedAssets>;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator = Chain<WithFirstAssetLocator, AscendingLocator>;
type PoolAssetId = u32;
type PoolAssets = PoolAssets;
type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
type PoolSetupFeeAsset = Native;
type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
type LPFee = ConstU32<3>; // 0.3% swap fee
type PalletId = AssetConversionPalletId;
type MaxSwapPathLength = ConstU32<3>;
type MintMinLiquidity = ConstU128<100>;
type WeightInfo = weights::pallet_asset_conversion::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

parameter_types! {
pub AssetsPalletIndex: u32 = <Assets as PalletInfoAccess>::index() as u32;
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const Native: NativeOrWithId<u32> = NativeOrWithId::Native;
// we charge no fee for liquidity withdrawal
pub const LiquidityWithdrawalFee: Permill = Permill::from_perthousand(0);
}

ord_parameter_types! {
pub const AssetConversionOrigin: sp_runtime::AccountId32 =
AccountIdConversion::<sp_runtime::AccountId32>::into_account_truncating(&AssetConversionPalletId::get());
}
pub type PoolAssetsInstance = pallet_assets::Instance2;
impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type RemoveItemsLimit = ConstU32<1000>;
type AssetId = u32;
type AssetIdParameter = u32;
type Currency = Balances;
type CreateOrigin =
AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
type ForceOrigin = EnsureRoot<AccountId>;
// Deposits are zero because creation/admin is limited to Asset Conversion pallet.
type AssetDeposit = ConstU128<0>;
type AssetAccountDeposit = ConstU128<0>;
type MetadataDepositBase = ConstU128<0>;
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = ConstU32<50>;
type Freezer = ();
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type CallbackHandle = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

construct_runtime!(
pub enum Runtime
{
Expand Down Expand Up @@ -906,8 +976,12 @@ construct_runtime!(
XTokens: orml_xtokens = 34,
OrmlXcm: orml_xcm = 35,
XcmTransactor: pallet_xcm_transactor = 36,
Assets: pallet_assets = 41,

// fungibles
Assets: pallet_assets::<Instance1> = 41,
AssetRegistry: pallet_asset_registry = 42,
AssetConversion: pallet_asset_conversion = 43,
PoolAssets: pallet_assets::<Instance2> = 44,

// Integritee pallets.
Teerex: pallet_teerex = 50,
Expand Down Expand Up @@ -962,6 +1036,7 @@ extern crate frame_benchmarking;
mod benches {
define_benchmarks!(
[frame_system, SystemBench::<Runtime>]
[pallet_asset_conversion, AssetConversion]
[pallet_asset_registry, AssetRegistry]
[pallet_assets, Assets]
[pallet_balances, Balances]
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachains/integritee-runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

pub mod cumulus_pallet_parachain_system;
pub mod frame_system;
pub mod pallet_asset_conversion;
pub mod pallet_asset_registry;
pub mod pallet_assets;
pub mod pallet_balances;
Expand Down
Loading

0 comments on commit bcf6180

Please sign in to comment.