Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaGamingArcade committed Dec 3, 2024
1 parent 12f34a6 commit d094d2a
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 98 deletions.
147 changes: 78 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "node-template"
name = "aga-node"
description = "A solochain node template built with Substrate, part of Polkadot Sdk."
version = "0.0.0"
license = "MIT-0"
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ fn testnet_genesis(
"key": Some(root_key),
},
})
}
}
4 changes: 2 additions & 2 deletions pallets/bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "po
]}
# For bridges
aga-access-segregator = { path = "../access-segregator", default-features = false }
aga-traits = { path = "../../traits", default-features = false }
aga-primitives = { path = "../../primitives/aga", default-features = false }

[dev-dependencies]
sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0" }
Expand Down Expand Up @@ -61,7 +61,7 @@ std = [
"sp-std/std",
"primitive-types/std",
"aga-access-segregator/std",
"aga-traits/std",
"aga-primitives/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
2 changes: 1 addition & 1 deletion pallets/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod benchmarking;
pub mod weights;
pub use weights::*;

use aga_traits::{
use aga_primitives::{
ChainID, DomainID, DepositNonce
};

Expand Down
2 changes: 1 addition & 1 deletion traits/Cargo.toml → primitives/aga/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "aga-traits"
name = "aga-primitives"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "node-template-runtime"
name = "aga-runtime"
description = "A solochain runtime template built with Substrate, part of Polkadot Sdk."
version = "0.0.0"
license = "MIT-0"
Expand Down Expand Up @@ -91,7 +91,7 @@ pallet-template = { path = "../pallets/template", default-features = false }
aga-access-segregator = { path = "../pallets/access-segregator", default-features = false }
aga-bridge = { path = "../pallets/bridge", default-features = false}
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false }
aga-traits = { path = "../traits", default-features = false }
aga-primitives = { path = "../primitives/aga", default-features = false }

[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", optional = true }
Expand Down Expand Up @@ -129,6 +129,7 @@ std = [

"aga-access-segregator/std",
"aga-bridge/std",
"aga-primitives/std",

"sp-api/std",
"sp-block-builder/std",
Expand Down
20 changes: 11 additions & 9 deletions runtime/src/assets_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AccountId, Balance, Balances, Runtime, RuntimeEvent, PoolAssets, Assets, NativeAndAssetId};
use crate::{AccountId, Balance, Balances, Runtime, RuntimeEvent, PoolAssets, Assets, NativeOrWithIdOf};
use frame_support::{
parameter_types, ord_parameter_types,
traits::{
Expand All @@ -15,8 +15,12 @@ use frame_system::{EnsureRoot, EnsureSigned, EnsureSignedBy};
pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;
use sp_runtime::Permill;
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::{
traits::AccountIdConversion,
Permill
};

use pallet_asset_conversion::WithFirstAsset;

/// We allow root to execute privileged asset operations.
pub type AssetsForceOrigin = EnsureRoot<AccountId>;
Expand Down Expand Up @@ -54,7 +58,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {

parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const Native: NativeAndAssetId = NativeOrWithId::Native;
pub const Native: NativeOrWithIdOf = NativeOrWithId::Native;
pub storage LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
}

Expand Down Expand Up @@ -89,18 +93,16 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type BenchmarkHelper = ();
}

pub type NativeAndAssets = UnionOf<Balances, Assets, NativeFromLeft, NativeAndAssetId, AccountId>;
pub type AscendingLocator = pallet_asset_conversion::Ascending<AccountId, NativeAndAssetId>;
pub type WithFirstAssetLocator = pallet_asset_conversion::WithFirstAsset<Native, AccountId, NativeAndAssetId>;
pub type NativeAndAssets = UnionOf<Balances, Assets, NativeFromLeft, NativeOrWithIdOf, AccountId>;

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = <Self as pallet_balances::Config>::Balance;
type HigherPrecisionBalance = u128;
type AssetKind = NativeAndAssetId;
type AssetKind = NativeOrWithIdOf;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator = pallet_asset_conversion::Chain<WithFirstAssetLocator, AscendingLocator>;
type PoolLocator = WithFirstAsset<Native, AccountId, Self::AssetKind>;
type PoolAssetId = u32;
type PoolAssets = PoolAssets;
type PoolSetupFee = ConstU128<100>; // should be more or equal to the existential deposit
Expand Down
55 changes: 43 additions & 12 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
mod assets_config;
mod contract_config;

use aga_traits::{DepositNonce, DomainID};
use aga_primitives::{DepositNonce, DomainID};
use pallet_grandpa::AuthorityId as GrandpaId;
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand All @@ -26,7 +26,11 @@ use sp_version::RuntimeVersion;

use frame_support::{
dispatch::DispatchClass,
traits::tokens::fungible::NativeOrWithId,
traits::{
OnUnbalanced,
Currency,
tokens::fungible::NativeOrWithId
},
genesis_builder_helper::{build_config, create_default_config},
};
use frame_system::limits::{BlockLength, BlockWeights};
Expand Down Expand Up @@ -75,7 +79,7 @@ pub type Nonce = u32;
pub type Hash = sp_core::H256;

// This includes the native and assets type
pub type NativeAndAssetId = NativeOrWithId<u32>;
pub type NativeOrWithIdOf = NativeOrWithId<u32>;

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
Expand Down Expand Up @@ -105,15 +109,15 @@ pub mod opaque {
// https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("aga"),
impl_name: create_runtime_str!("aga"),
spec_name: create_runtime_str!("aga-testnet"),
impl_name: create_runtime_str!("aga-testnet"),
authoring_version: 1,
// The version of the runtime specification. A full node will not attempt to use its native
// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 112,
spec_version: 100,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -254,8 +258,19 @@ impl pallet_grandpa::Config for Runtime {
type EquivocationReportSystem = ();
}

pub struct AuraAccountAdapter;
impl frame_support::traits::FindAuthor<AccountId> for AuraAccountAdapter {
fn find_author<'a, I>(digests: I) -> Option<AccountId>
where I: 'a + IntoIterator<Item=(frame_support::ConsensusEngineId, &'a [u8])>
{
pallet_aura::AuraAuthorId::<Runtime>::find_author(digests).and_then(|k| {
AccountId::try_from(k.as_ref()).ok()
})
}
}

impl pallet_authorship::Config for Runtime {
type FindAuthor = ();
type FindAuthor = AuraAccountAdapter;
type EventHandler = ();
}

Expand Down Expand Up @@ -290,13 +305,29 @@ impl pallet_balances::Config for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
}

/// Logic for the author to get a portion of fees.
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId,>>::NegativeImbalance;
pub struct ToAuthor<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for ToAuthor<R>
where
R: pallet_balances::Config + pallet_authorship::Config,
<R as frame_system::Config>::AccountId: From<AccountId>,
<R as frame_system::Config>::AccountId: Into<AccountId>,
{
fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
if let Some(author) = <pallet_authorship::Pallet<R>>::author() {
<pallet_balances::Pallet<R>>::resolve_creating(&author, amount);
}
}
}

parameter_types! {
pub FeeMultiplier: Multiplier = Multiplier::one();
}

impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type OnChargeTransaction = CurrencyAdapter<Balances, ToAuthor<Runtime>>;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = IdentityFee<Balance>;
type LengthToFee = IdentityFee<Balance>;
Expand Down Expand Up @@ -700,18 +731,18 @@ impl_runtime_apis! {
impl pallet_asset_conversion::AssetConversionApi<
Block,
Balance,
NativeAndAssetId,
NativeOrWithIdOf,
> for Runtime
{
fn quote_price_exact_tokens_for_tokens(asset1: NativeAndAssetId, asset2: NativeAndAssetId, amount: Balance, include_fee: bool) -> Option<Balance> {
fn quote_price_exact_tokens_for_tokens(asset1: NativeOrWithIdOf, asset2: NativeOrWithIdOf, amount: Balance, include_fee: bool) -> Option<Balance> {
AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee)
}

fn quote_price_tokens_for_exact_tokens(asset1: NativeAndAssetId, asset2: NativeAndAssetId, amount: Balance, include_fee: bool) -> Option<Balance> {
fn quote_price_tokens_for_exact_tokens(asset1: NativeOrWithIdOf, asset2: NativeOrWithIdOf, amount: Balance, include_fee: bool) -> Option<Balance> {
AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
}

fn get_reserves(asset1: NativeAndAssetId, asset2: NativeAndAssetId) -> Option<(Balance, Balance)> {
fn get_reserves(asset1: NativeOrWithIdOf, asset2: NativeOrWithIdOf) -> Option<(Balance, Balance)> {
AssetConversion::get_reserves(asset1, asset2).ok()
}
}
Expand Down

0 comments on commit d094d2a

Please sign in to comment.