frame_support/traits/rewards.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Traits for managing reward pools.
19
20use crate::traits::schedule::DispatchTime;
21use sp_runtime::{DispatchError, DispatchResult};
22
23/// A trait for managing a rewards pool.
24pub trait RewardsPool<AccountId> {
25 type AssetId;
26 type BlockNumber;
27 type PoolId;
28 type Balance;
29
30 /// Create a new reward pool.
31 ///
32 /// Parameters:
33 /// - `creator`: The account to pay for on-chain stroage deposit;
34 /// - `staked_asset_id`: the asset to be staked in the pool;
35 /// - `reward_asset_id`: the asset to be distributed as rewards;
36 /// - `reward_rate_per_block`: the amount of reward tokens distributed per block;
37 /// - `expiry`: the block number at which the pool will cease to accumulate rewards. The
38 /// [`DispatchTime::After`] variant evaluated at the execution time.
39 /// - `admin`: the account allowed to extend the pool expiration, increase the rewards rate and
40 /// receive the unutilized reward tokens back after the pool completion.
41 fn create_pool(
42 creator: &AccountId,
43 staked_asset_id: Self::AssetId,
44 reward_asset_id: Self::AssetId,
45 reward_rate_per_block: Self::Balance,
46 expiry: DispatchTime<Self::BlockNumber>,
47 admin: &AccountId,
48 ) -> Result<Self::PoolId, DispatchError>;
49
50 /// Modify a pool reward rate.
51 ///
52 /// The reward rate can only be increased.
53 ///
54 /// Only the pool admin may perform this operation.
55 fn set_pool_reward_rate_per_block(
56 admin: &AccountId,
57 pool_id: Self::PoolId,
58 new_reward_rate_per_block: Self::Balance,
59 ) -> DispatchResult;
60
61 /// Modify a pool admin.
62 ///
63 /// Only the pool admin may perform this operation.
64 fn set_pool_admin(
65 admin: &AccountId,
66 pool_id: Self::PoolId,
67 new_admin: AccountId,
68 ) -> DispatchResult;
69
70 /// Set when the pool should expire.
71 ///
72 /// The expiry block can only be extended.
73 ///
74 /// Only the pool admin may perform this operation.
75 fn set_pool_expiry_block(
76 admin: &AccountId,
77 pool_id: Self::PoolId,
78 new_expiry: DispatchTime<Self::BlockNumber>,
79 ) -> DispatchResult;
80}