Skip to content

Commit

Permalink
Treasury can pay out assets from the pallet-assets (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb authored Nov 7, 2024
1 parent e778bd7 commit 0db1c38
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

15 changes: 13 additions & 2 deletions chopsticks/ajuna.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
endpoint:
- wss://ajuna.api.onfinality.io/public-ws
- wss://ajuna.public.curie.radiumblock.co/ws
- wss://ajuna.ibp.network
- wss://ajuna.dotters.network

mock-signature-host: true
block: ${env.AJUNA_PARACHAIN_BLOCK_NUMBER}
db: ./chopsticks/ajuna-parachain.db.sqlite
runtime-log-level: 5
#wasm-override: target/release/wbuild/ajuna-runtime/ajuna_runtime.compact.compressed.wasm
wasm-override: target/release/wbuild/ajuna-runtime/ajuna_runtime.compact.compressed.wasm

# Once we have governance we want to make Alice single councillor and technical committee member.
import-storage:
Expand All @@ -30,4 +33,12 @@ import-storage:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
TechnicalCommittee:
Members:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
Assets:
Account:
- [ [ 1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY ], { balance: 10000000000000 } ]
# Treasury account
- [ [ 1984, aUrrXg7ByxW6YbyEQYcKEqigFtmB5D9YVEw9auYVej8xsxWtw ], { balance: 10000000000000 } ]
- [ [ 1337, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY ], { balance: 10000000000000 } ]
- [ [ 1337, aUrrXg7ByxW6YbyEQYcKEqigFtmB5D9YVEw9auYVej8xsxWtw ], { balance: 10000000000000 } ]
Asset: [[[1984], { supply: 20000000000000 }], [[1337], { supply: 20000000000000 }]]
40 changes: 40 additions & 0 deletions runtime/ajuna/src/benchmark_helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Ajuna Node
// Copyright (C) 2022 BlogaTech AG

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.

// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pub mod treasury {
use crate::AccountId;
use frame_support::traits::fungible::NativeOrWithId;
use pallet_treasury::ArgumentsFactory as TreasuryArgumentsFactory;
use parachains_common::AssetIdForTrustBackedAssets;

pub type AssetKind = NativeOrWithId<AssetIdForTrustBackedAssets>;

/// Provide factory methods for the [`NativeOrWithId<AssetIdForTrustBackedAssets>`] and
/// the `Beneficiary` for [`AccountId`].
///
/// This is slightly different from Polkadot's implementation, which uses a
/// [`VersionedLocatableAsset`] for the AssetId, as the asset lives on another chain.
pub struct TreasuryArguments;

impl TreasuryArgumentsFactory<AssetKind, AccountId> for TreasuryArguments {
fn create_asset_kind(seed: u32) -> AssetKind {
AssetKind::WithId(seed)
}
fn create_beneficiary(seed: [u8; 32]) -> AccountId {
AccountId::from(seed)
}
}
}
25 changes: 18 additions & 7 deletions runtime/ajuna/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ mod tx_payment;
mod weights;
pub mod xcm_config;

#[cfg(feature = "runtime-benchmarks")]
mod benchmark_helpers;

use crate::{
assets::{Native, NativeAndAssets},
gov::EnsureRootOrMoreThanHalfCouncil,
Expand All @@ -42,8 +45,10 @@ use frame_support::{
pallet_prelude::ConstU32,
parameter_types,
traits::{
fungible::HoldConsideration,
tokens::{imbalance::ResolveAssetTo, PayFromAccount, UnityAssetBalanceConversion},
fungible::{HoldConsideration, NativeOrWithId},
tokens::{
imbalance::ResolveAssetTo, pay::PayAssetFromAccount, UnityAssetBalanceConversion,
},
AsEnsureOriginWithArg, ConstBool, Contains, LinearStoragePrice,
},
weights::{
Expand Down Expand Up @@ -91,7 +96,9 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
// XCM Imports
use staging_xcm::latest::prelude::BodyId;

use parachains_common::{message_queue::NarrowOriginToSibling, BlockNumber, Hash, Header};
use parachains_common::{
message_queue::NarrowOriginToSibling, AssetIdForTrustBackedAssets, BlockNumber, Hash, Header,
};

parameter_types! {
pub const OneDay: BlockNumber = DAYS;
Expand Down Expand Up @@ -511,14 +518,18 @@ impl pallet_treasury::Config for Runtime {
type SpendFunds = ();
type MaxApprovals = frame_support::traits::ConstU32<100>;
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
type AssetKind = ();
type AssetKind = NativeOrWithId<AssetIdForTrustBackedAssets>;
type Beneficiary = Self::AccountId;
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type Paymaster = PayAssetFromAccount<NativeAndAssets, TreasuryAccount>;
// The balance conversion to the native balance is only needed to check if the proposed spend
// is not too high for a given origin's track. As we use Gov1, we have no notion of those
// tracks, and their associated maximum balance. Hence, this check will always return true,
// which implies that we can use the simple unity conversion.
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = SpendPayoutPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = benchmark_helpers::treasury::TreasuryArguments;
}

parameter_types! {
Expand Down Expand Up @@ -1000,7 +1011,7 @@ mod benches {
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_timestamp, Timestamp]
// [pallet_treasury, Treasury] // treasury config is broken, needs fixes
[pallet_treasury, Treasury]
[pallet_utility, Utility]
);
// Use this section if you want to benchmark individual pallets
Expand Down

0 comments on commit 0db1c38

Please sign in to comment.