Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pallet-asset-rewards #3926

Open
wants to merge 191 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
c2cd9ea
wip staking rewards
liamaharon Mar 22, 2024
a02d843
write brief overview
liamaharon Mar 25, 2024
0ed5f8d
seperate reward pots per pool
liamaharon Mar 25, 2024
5582a73
unused imports
liamaharon Mar 25, 2024
c208636
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Mar 26, 2024
9eeebd5
add pool admins
liamaharon Mar 26, 2024
19cd1d2
create_pool implementation, mock and test set up
liamaharon Mar 28, 2024
b0cd831
update tests
liamaharon Mar 28, 2024
d1bf78f
add check for asset existence
liamaharon Mar 28, 2024
bf1f5c8
wip logic
liamaharon Apr 1, 2024
b921166
unstake tests
liamaharon Apr 1, 2024
60191d5
rename pallet-asset-rewards
liamaharon Apr 1, 2024
31a3c89
stake unstake events
liamaharon Apr 1, 2024
7a15551
add integration test
liamaharon Apr 2, 2024
3742869
add expiry block and improve pool admin calls
liamaharon Apr 2, 2024
13cccba
test reward and expiry adjustment
liamaharon Apr 2, 2024
5f39774
check harvesting in integration test
liamaharon Apr 2, 2024
cd65a37
remove redundant comment
liamaharon Apr 2, 2024
155fde7
add assets to mock
liamaharon Apr 3, 2024
5b47b1d
clean up test
liamaharon Apr 3, 2024
81aeb0c
pure internal functions
liamaharon Apr 3, 2024
90463a8
harvest tests
liamaharon Apr 3, 2024
3660369
add dedicated set_pool_reward_rate_per_block tests
liamaharon Apr 3, 2024
16bc43b
set up pool 0 account with rewards
liamaharon Apr 3, 2024
d5c4659
improve expiry block tests
liamaharon Apr 3, 2024
3b47813
rearrange test
liamaharon Apr 3, 2024
aef1b4b
add deposit extrinsic tests
liamaharon Apr 3, 2024
a4c6067
clean up mock
liamaharon Apr 3, 2024
b8344a3
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 3, 2024
cfb3dfa
update docs
liamaharon Apr 3, 2024
ab8ae7d
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 3, 2024
9f2c4fa
test withdraw reward token method
liamaharon Apr 3, 2024
1a22048
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 5, 2024
7078d03
update comment
liamaharon Apr 5, 2024
80c28b8
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 5, 2024
679724d
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 5, 2024
740a749
wip benchmarks
liamaharon Apr 5, 2024
a243b05
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 5, 2024
1dfde3f
remove stub
liamaharon Apr 6, 2024
138fdbb
stake benchmark
liamaharon Apr 6, 2024
159f63f
unstake benchmark
liamaharon Apr 6, 2024
2fc9c04
harvest rewards benchmark
liamaharon Apr 6, 2024
d6cc5c2
set pool reward rate per block benchmark
liamaharon Apr 6, 2024
b532b50
set pool admin benchmark
liamaharon Apr 6, 2024
898852c
benchmark set pool expiry block
liamaharon Apr 6, 2024
96ac58b
deposit reward tokens benchmark
liamaharon Apr 6, 2024
d2ef188
withdraw reward tokens benchmark
liamaharon Apr 6, 2024
5c8185a
remove unused import
liamaharon Apr 6, 2024
15ced21
reduce code duplication
liamaharon Apr 6, 2024
12257da
commit empty weights file
liamaharon Apr 6, 2024
e1eb1d6
integration into kitchensink
liamaharon Apr 7, 2024
da39270
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 9, 2024
0c807d1
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 10, 2024
48a70eb
remove unnecesary bound
liamaharon Apr 10, 2024
b190e47
rococo set up reward pallet assets
liamaharon Apr 10, 2024
2d196c2
configure permissioned pool creator origin
liamaharon Apr 10, 2024
57b1727
refactor origin success accountid
liamaharon Apr 10, 2024
8d0476b
update pallet benchmarks
liamaharon Apr 10, 2024
9389c47
benchmarks finally working for node-template
liamaharon Apr 11, 2024
ce23c68
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Apr 11, 2024
c3ab001
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_asset…
Apr 11, 2024
6c17137
wip asset-hub-rococo benchmarks
liamaharon Apr 11, 2024
e2f09c8
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 11, 2024
7900c4b
asset-hub-rococo benchmarks!
liamaharon Apr 11, 2024
5869590
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 11, 2024
7b3209d
use correct relay treasury location
liamaharon Apr 11, 2024
b1c3668
add to asset-hub-westend
liamaharon Apr 11, 2024
77bd1bc
cleanup
liamaharon Apr 11, 2024
0ef2eaa
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 11, 2024
4a65a38
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 11, 2024
29b59d7
cleaner benchmarkhelper
liamaharon Apr 12, 2024
3d7fc42
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 12, 2024
8513adb
feature gate
liamaharon Apr 12, 2024
936bc34
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 12, 2024
ffefda8
update docs
liamaharon Apr 12, 2024
531d766
tidy up
liamaharon Apr 12, 2024
c7e8999
Update substrate/frame/asset-rewards/src/mock.rs
liamaharon Apr 12, 2024
36e1e7d
Update substrate/frame/asset-rewards/src/tests.rs
liamaharon Apr 12, 2024
ae17649
Update substrate/frame/asset-rewards/src/tests.rs
liamaharon Apr 12, 2024
b56af27
kitchensink weightinfo
liamaharon Apr 12, 2024
b46d609
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 12, 2024
eaa7fdf
".git/.scripts/commands/fmt/fmt.sh"
Apr 12, 2024
1c1646e
fix doc build
liamaharon Apr 12, 2024
2ec6039
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 12, 2024
767af86
address comment
liamaharon Apr 12, 2024
4419133
pure fns
liamaharon Apr 12, 2024
f903ea2
is_zero()
liamaharon Apr 12, 2024
cd77fb3
update doc
liamaharon Apr 12, 2024
a2ec1ee
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 15, 2024
67b23fa
finish merging location refactor
liamaharon Apr 15, 2024
9851b31
Update substrate/frame/asset-rewards/src/lib.rs
liamaharon Apr 15, 2024
7e05c06
Update substrate/frame/asset-rewards/src/lib.rs
liamaharon Apr 15, 2024
a162052
Update substrate/frame/asset-rewards/src/lib.rs
liamaharon Apr 15, 2024
be25a9e
Update substrate/frame/asset-rewards/src/lib.rs
liamaharon Apr 15, 2024
9c9da9a
update comment
liamaharon Apr 15, 2024
c3276cf
Merge branch 'liam-staking-rewards-pallet' of github.com:paritytech/p…
liamaharon Apr 15, 2024
446ae58
wip emulated test
liamaharon Apr 16, 2024
488bcf7
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 16, 2024
bf04e6d
wip emulated test
liamaharon Apr 16, 2024
3a851c8
emulated tests
liamaharon Apr 17, 2024
a4eb51f
use poolinfofor
liamaharon Apr 17, 2024
36a6526
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 17, 2024
1ecc7e2
update comment
liamaharon Apr 17, 2024
af92541
improve call docs
liamaharon Apr 17, 2024
905e102
update call comment
liamaharon Apr 17, 2024
ed9e0dc
simplify core logic
liamaharon Apr 17, 2024
c3434eb
reduce scaling factor
liamaharon Apr 17, 2024
700ec32
add disambiguation comment
liamaharon Apr 17, 2024
21c21ae
add test for same staking and reward asset
liamaharon Apr 17, 2024
8c72832
make admin Option
liamaharon Apr 17, 2024
bb21536
rename createpoolorigin
liamaharon Apr 17, 2024
78f642b
rename who to caller
liamaharon Apr 17, 2024
cfabe6f
create_pool take lifetime
liamaharon Apr 17, 2024
10f9bfc
handle overflow
liamaharon Apr 17, 2024
a307dc5
transfer expendable
liamaharon Apr 17, 2024
9767838
integrity test
liamaharon Apr 17, 2024
653cce7
merge
liamaharon Apr 17, 2024
e8e5088
clippy
liamaharon Apr 19, 2024
34df83f
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 19, 2024
98d705d
clippy
liamaharon Apr 19, 2024
d82175c
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 19, 2024
dc08086
fmt
liamaharon Apr 19, 2024
4edc618
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Apr 24, 2024
1872bc2
merge
liamaharon May 7, 2024
fa5c860
remove unused struct
liamaharon May 7, 2024
d64071e
restore tempfile
liamaharon May 7, 2024
abaecea
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon May 7, 2024
b560be7
merge
liamaharon Jun 26, 2024
819f89b
taplo
liamaharon Jun 26, 2024
6d5554f
apply umbrella patch
liamaharon Jun 26, 2024
de5577e
add freezing
liamaharon Jul 1, 2024
9e56945
merge
liamaharon Jul 1, 2024
a466a49
Merge branch 'master' into liam-staking-rewards-pallet
liamaharon Jul 2, 2024
22e90b1
Merge remote-tracking branch 'origin/master' into liam-staking-reward…
muharem Jul 25, 2024
6dadb7a
Merge remote-tracking branch 'origin/master' into liam-staking-reward…
muharem Jul 29, 2024
d6c61c8
cargo lock, cargo ubmrella
muharem Jul 29, 2024
8ec56f4
make benchmarks more generic
muharem Jul 29, 2024
872e4bd
fix broken imports
muharem Jul 31, 2024
5459c97
ensure_successful for Consideration types
muharem Jul 31, 2024
eb956c1
add Consideration for pool creation
muharem Jul 31, 2024
3e0fba2
fix integration tests
muharem Jul 31, 2024
9250133
remove unused imports
muharem Jul 31, 2024
656d501
remove duplication from wrokspace members list
muharem Jul 31, 2024
5fcee69
taplo format
muharem Jul 31, 2024
196e6c4
remove unused imports
muharem Jul 31, 2024
dec45b3
fix umbrella crate inclusion order
muharem Jul 31, 2024
78fa44e
mock: fund root account for pool deposit
muharem Aug 1, 2024
c4ff420
pool admin is not optional
muharem Aug 7, 2024
cf8fdf3
checked add on pool id increment
muharem Aug 7, 2024
264bcb4
use fungible::increase_frozen
muharem Aug 7, 2024
3d9b058
runtime api to query the pool creation cost
muharem Aug 7, 2024
d233e35
prdoc
muharem Aug 7, 2024
41d6e44
update cargo toml
muharem Aug 7, 2024
99ec6ba
propogate std feature for pallet-assets-freezer
muharem Aug 7, 2024
94c66ff
Merge remote-tracking branch 'origin/master' into liam-staking-reward…
muharem Aug 15, 2024
1cb2428
not optional consideration
muharem Aug 15, 2024
00a17f6
Apply suggestions from code review
muharem Aug 28, 2024
5677471
only staker can harvest rewards
muharem Aug 28, 2024
f0e05ec
optional admin
muharem Aug 28, 2024
672d3e5
admin tests
muharem Aug 28, 2024
cf6197a
Merge remote-tracking branch 'origin/master' into liam-staking-reward…
muharem Aug 28, 2024
8f138dd
store pool account id
muharem Aug 28, 2024
65c82f9
fix
muharem Aug 28, 2024
6342783
use checked instead saturating
muharem Aug 28, 2024
e1d3327
update prdoc
muharem Aug 29, 2024
0980aba
fix umbrella
muharem Aug 29, 2024
20e4e49
fix umbrella
muharem Aug 29, 2024
97996e1
remove withdraw_reward_tokens
muharem Aug 29, 2024
4dfa197
restrict pool altering
muharem Aug 29, 2024
ad922e0
docs
muharem Aug 29, 2024
a8240f2
clippy
muharem Aug 29, 2024
021bc9c
use dispatch_time type for expiry parameter
muharem Aug 30, 2024
3a82f5e
Apply suggestions from code review
muharem Sep 12, 2024
8cccdb8
RuntimeFreezeReason config parameter
muharem Sep 12, 2024
ecfc903
review fixes
muharem Sep 12, 2024
eef21d7
remove pool_stakers storage item when it is empty
muharem Sep 12, 2024
0c1cff6
cleanup call
muharem Sep 13, 2024
a6183a5
make admin non optional
muharem Sep 13, 2024
04423f4
Merge remote-tracking branch 'origin/master' into liam-staking-reward…
muharem Sep 13, 2024
55ed586
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Sep 13, 2024
8ec81e4
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Sep 13, 2024
0562679
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Sep 13, 2024
949760e
westend send xcm origin includes signed origin
muharem Sep 17, 2024
5611441
unstake and harvest calls permissionless when a pool is expired
muharem Sep 17, 2024
0f72302
Merge remote-tracking branch 'origin/master' into liam-staking-reward…
muharem Sep 17, 2024
3035d6a
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_asset…
Sep 17, 2024
1fb27c4
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_asset…
Sep 17, 2024
ecac4b5
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_asset…
Sep 17, 2024
5f8fd33
Merge remote-tracking branch 'origin/master' into liam-staking-reward…
muharem Dec 22, 2024
7ffe9d1
fmt
muharem Dec 22, 2024
8b85949
add missing config type
muharem Dec 23, 2024
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
27 changes: 27 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ members = [
"substrate/frame/asset-conversion",
"substrate/frame/asset-conversion/ops",
"substrate/frame/asset-rate",
"substrate/frame/asset-rewards",
"substrate/frame/assets",
"substrate/frame/assets-freezer",
"substrate/frame/atomic-swap",
Expand Down Expand Up @@ -891,6 +892,7 @@ pallet-asset-conversion = { path = "substrate/frame/asset-conversion", default-f
pallet-asset-conversion-ops = { path = "substrate/frame/asset-conversion/ops", default-features = false }
pallet-asset-conversion-tx-payment = { path = "substrate/frame/transaction-payment/asset-conversion-tx-payment", default-features = false }
pallet-asset-rate = { path = "substrate/frame/asset-rate", default-features = false }
pallet-asset-rewards = { path = "substrate/frame/asset-rewards", default-features = false }
pallet-asset-tx-payment = { path = "substrate/frame/transaction-payment/asset-tx-payment", default-features = false }
pallet-assets = { path = "substrate/frame/assets", default-features = false }
pallet-assets-freezer = { path = "substrate/frame/assets-freezer", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workspace = true

# Substrate
frame-support = { workspace = true }
pallet-asset-rewards = { workspace = true }
sp-core = { workspace = true }
sp-keyring = { workspace = true }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub const USDT_ID: u32 = 1984;

pub const PENPAL_A_ID: u32 = 2000;
pub const PENPAL_B_ID: u32 = 2001;
pub const ASSET_HUB_ROCOCO_ID: u32 = 1000;
pub const ASSET_HUB_WESTEND_ID: u32 = 1000;
pub const ASSETS_PALLET_ID: u8 = 50;

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ codec = { workspace = true }
# Substrate
frame-support = { workspace = true }
pallet-asset-conversion = { workspace = true }
pallet-asset-rewards = { workspace = true }
pallet-assets = { workspace = true }
pallet-balances = { workspace = true }
pallet-message-queue = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mod imports {
genesis::ED as ROCOCO_ED,
rococo_runtime::{
governance as rococo_governance,
governance::pallet_custom_origins::Origin::Treasurer,
xcm_config::{
UniversalLocation as RococoUniversalLocation, XcmConfig as RococoXcmConfig,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
mod claim_assets;
mod hybrid_transfers;
mod reserve_transfer;
mod reward_pool;
mod send;
mod set_xcm_versions;
mod swap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::imports::*;
use codec::Encode;
use frame_support::{assert_ok, sp_runtime::traits::Dispatchable, traits::schedule::DispatchTime};
use xcm_executor::traits::ConvertLocation;

#[test]
fn treasury_creates_asset_reward_pool() {
AssetHubRococo::execute_with(|| {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
type Balances = <AssetHubRococo as AssetHubRococoPallet>::Balances;

let treasurer =
Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]);
let treasurer_account =
ahr_xcm_config::LocationToAccountId::convert_location(&treasurer).unwrap();

assert_ok!(Balances::force_set_balance(
<AssetHubRococo as Chain>::RuntimeOrigin::root(),
treasurer_account.clone().into(),
ASSET_HUB_ROCOCO_ED * 100_000,
));

let events = AssetHubRococo::events();
match events.iter().last() {
Some(RuntimeEvent::Balances(pallet_balances::Event::BalanceSet { who, .. })) =>
assert_eq!(*who, treasurer_account),
_ => panic!("Expected Balances::BalanceSet event"),
}
});

Rococo::execute_with(|| {
type AssetHubRococoRuntimeCall = <AssetHubRococo as Chain>::RuntimeCall;
type AssetHubRococoRuntime = <AssetHubRococo as Chain>::Runtime;
type RococoRuntimeCall = <Rococo as Chain>::RuntimeCall;
type RococoRuntime = <Rococo as Chain>::Runtime;
type RococoRuntimeEvent = <Rococo as Chain>::RuntimeEvent;
type RococoRuntimeOrigin = <Rococo as Chain>::RuntimeOrigin;

let staked_asset_id = bx!(RelayLocation::get());
let reward_asset_id = bx!(RelayLocation::get());

let reward_rate_per_block = 1_000_000_000;
let lifetime = 1_000_000_000;
let admin = None;

let create_pool_call =
RococoRuntimeCall::XcmPallet(pallet_xcm::Call::<RococoRuntime>::send {
dest: bx!(VersionedLocation::V4(
xcm::v4::Junction::Parachain(AssetHubRococo::para_id().into()).into()
)),
message: bx!(VersionedXcm::V5(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::SovereignAccount,
fallback_max_weight: None,
call: AssetHubRococoRuntimeCall::AssetRewards(
pallet_asset_rewards::Call::<AssetHubRococoRuntime>::create_pool {
staked_asset_id,
reward_asset_id,
reward_rate_per_block,
expiry: DispatchTime::After(lifetime),
admin
}
)
.encode()
.into(),
}
]))),
});

let treasury_origin: RococoRuntimeOrigin = Treasurer.into();
assert_ok!(create_pool_call.dispatch(treasury_origin));

assert_expected_events!(
Rococo,
vec![
RococoRuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
]
);
});

AssetHubRococo::execute_with(|| {
type Runtime = <AssetHubRococo as Chain>::Runtime;
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;

assert_eq!(1, pallet_asset_rewards::Pools::<Runtime>::iter().count());

let events = AssetHubRococo::events();
match events.iter().last() {
Some(RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed {
success: true,
..
})) => (),
_ => panic!("Expected MessageQueue::Processed event"),
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ frame-metadata-hash-extension = { workspace = true, default-features = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-asset-conversion = { workspace = true }
pallet-asset-rewards = { workspace = true }
pallet-asset-tx-payment = { workspace = true }
pallet-assets = { workspace = true }
pallet-balances = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ mod imports {
},
westend_emulated_chain::{
genesis::ED as WESTEND_ED,
westend_runtime::xcm_config::{
UniversalLocation as WestendUniversalLocation, XcmConfig as WestendXcmConfig,
westend_runtime::{
governance::pallet_custom_origins::Origin::Treasurer,
xcm_config::{
UniversalLocation as WestendUniversalLocation, XcmConfig as WestendXcmConfig,
},
},
WestendRelayPallet as WestendPallet,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod claim_assets;
mod fellowship_treasury;
mod hybrid_transfers;
mod reserve_transfer;
mod reward_pool;
mod send;
mod set_asset_claimer;
mod set_xcm_versions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::imports::*;
use codec::Encode;
use frame_support::{assert_ok, sp_runtime::traits::Dispatchable, traits::schedule::DispatchTime};
use xcm_executor::traits::ConvertLocation;

#[test]
fn treasury_creates_asset_reward_pool() {
AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
type Balances = <AssetHubWestend as AssetHubWestendPallet>::Balances;

let treasurer =
Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]);
let treasurer_account =
ahw_xcm_config::LocationToAccountId::convert_location(&treasurer).unwrap();

assert_ok!(Balances::force_set_balance(
<AssetHubWestend as Chain>::RuntimeOrigin::root(),
treasurer_account.clone().into(),
ASSET_HUB_WESTEND_ED * 100_000,
));

let events = AssetHubWestend::events();
match events.iter().last() {
Some(RuntimeEvent::Balances(pallet_balances::Event::BalanceSet { who, .. })) =>
assert_eq!(*who, treasurer_account),
_ => panic!("Expected Balances::BalanceSet event"),
}
});
Westend::execute_with(|| {
type AssetHubWestendRuntimeCall = <AssetHubWestend as Chain>::RuntimeCall;
type AssetHubWestendRuntime = <AssetHubWestend as Chain>::Runtime;
type WestendRuntimeCall = <Westend as Chain>::RuntimeCall;
type WestendRuntime = <Westend as Chain>::Runtime;
type WestendRuntimeEvent = <Westend as Chain>::RuntimeEvent;
type WestendRuntimeOrigin = <Westend as Chain>::RuntimeOrigin;

let staked_asset_id = bx!(RelayLocation::get());
let reward_asset_id = bx!(RelayLocation::get());

let reward_rate_per_block = 1_000_000_000;
let lifetime = 1_000_000_000;
let admin = None;

let create_pool_call =
WestendRuntimeCall::XcmPallet(pallet_xcm::Call::<WestendRuntime>::send {
dest: bx!(VersionedLocation::V4(
xcm::v4::Junction::Parachain(AssetHubWestend::para_id().into()).into()
)),
message: bx!(VersionedXcm::V5(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Transact {
origin_kind: OriginKind::SovereignAccount,
fallback_max_weight: None,
call: AssetHubWestendRuntimeCall::AssetRewards(
pallet_asset_rewards::Call::<AssetHubWestendRuntime>::create_pool {
staked_asset_id,
reward_asset_id,
reward_rate_per_block,
expiry: DispatchTime::After(lifetime),
admin
}
)
.encode()
.into(),
}
]))),
});

let treasury_origin: WestendRuntimeOrigin = Treasurer.into();
assert_ok!(create_pool_call.dispatch(treasury_origin));

assert_expected_events!(
Westend,
vec![
WestendRuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
]
);
});

AssetHubWestend::execute_with(|| {
type Runtime = <AssetHubWestend as Chain>::Runtime;
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;

assert_eq!(1, pallet_asset_rewards::Pools::<Runtime>::iter().count());

let events = AssetHubWestend::events();
match events.iter().last() {
Some(RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed {
success: true,
..
})) => (),
_ => panic!("Expected MessageQueue::Processed event"),
}
});
}
Loading
Loading