forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
pallet-asset-rewards
(paritytech#3926)
Closes paritytech#3149 ## Description This PR introduces `pallet-asset-rewards`, which allows accounts to be rewarded for freezing `fungible` tokens. The motivation for creating this pallet is to allow incentivising LPs. See the pallet docs for more info about the pallet. ## Runtime changes The pallet has been added to - `asset-hub-rococo` - `asset-hub-westend` The `NativeAndAssets` `fungibles` Union did not contain `PoolAssets`, so it has been renamed `NativeAndNonPoolAssets` A new `fungibles` Union `NativeAndAllAssets` was created to encompass all assets and the native token. ## TODO - [x] Emulation tests - [x] Fill in Freeze logic (blocked paritytech#3342) and re-run benchmarks --------- Co-authored-by: command-bot <> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: muharem <[email protected]> Co-authored-by: Guillaume Thiolliere <[email protected]>
- Loading branch information
1 parent
2db0193
commit d854fd7
Showing
37 changed files
with
4,517 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...achains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reward_pool.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// 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; | ||
|
||
Dmp::make_parachain_reachable(AssetHubRococo::para_id()); | ||
|
||
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"), | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...chains/integration-tests/emulated/tests/assets/asset-hub-westend/src/tests/reward_pool.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// 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; | ||
|
||
Dmp::make_parachain_reachable(AssetHubWestend::para_id()); | ||
|
||
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"), | ||
} | ||
}); | ||
} |
Oops, something went wrong.