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

Optimistic Project Funding #5162

Draft
wants to merge 283 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
283 commits
Select commit Hold shift + click to select a range
ad4d675
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 1, 2024
114e430
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 2, 2024
245cf90
New constant added
ndkazu Aug 2, 2024
617ee5e
Helper for rewards calculation & distribution
ndkazu Aug 3, 2024
93e3b31
Updated pallet-distribution tests
ndkazu Aug 3, 2024
5fc4beb
In-code documention, extrinsics, and a few corrections
ndkazu Aug 4, 2024
27524ed
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 4, 2024
3ba0121
Documentation for pallet distribution
ndkazu Aug 4, 2024
82bf13d
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Aug 4, 2024
f21ba3c
Documentation edit
ndkazu Aug 4, 2024
8cedc42
Restricted some storages visibility
ndkazu Aug 4, 2024
f95b070
Used checked_add instead of saturating_add
ndkazu Aug 4, 2024
2699fd2
Some corrections
ndkazu Aug 4, 2024
843f558
Logic to be used in pallet-opf hook added
ndkazu Aug 5, 2024
b69cfff
Distribution pallet README
ndkazu Aug 5, 2024
9faf586
README corrections
ndkazu Aug 5, 2024
758e681
README corrections
ndkazu Aug 5, 2024
00fe62b
Remove unfunded projects from whitelist
ndkazu Aug 6, 2024
46ea061
Use on_idle hook in OPF Pallet
ndkazu Aug 6, 2024
876db00
Correction
ndkazu Aug 6, 2024
7445d0f
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 7, 2024
442df1e
Update README.md
ndkazu Aug 7, 2024
238bae5
Update lib.rs
ndkazu Aug 7, 2024
76f31b3
Create README.md
ndkazu Aug 7, 2024
fa8f9c2
User's funds release after rewards calculation
ndkazu Aug 7, 2024
145858c
Benchmarking_begin
ndkazu Aug 8, 2024
1db8e95
Changed Sepnding(s) to Spend(s)
ndkazu Aug 8, 2024
c3ba04e
Changed VotingRoundsNumber to VotingRoundNumber
ndkazu Aug 8, 2024
92eabcd
Correction
ndkazu Aug 8, 2024
6216b5e
Preparing OPF testing
ndkazu Aug 9, 2024
b5c02ab
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 9, 2024
fb76ceb
Stopped using the system block number
ndkazu Aug 10, 2024
945fbb2
corrected block numbers for tests
ndkazu Aug 10, 2024
04c0646
Added events
ndkazu Aug 11, 2024
bdd88c1
First tests and corresponding corrections
ndkazu Aug 11, 2024
6742a58
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 11, 2024
0eb2e5c
Rewards distribution test
ndkazu Aug 11, 2024
d1fac2f
Tests and corrections
ndkazu Aug 11, 2024
7bf608a
Removed dev-mode and some warnings
ndkazu Aug 12, 2024
ba869d6
More OPF testing
ndkazu Aug 12, 2024
bc4c6de
Added benchmarking test suite
ndkazu Aug 12, 2024
32a2296
Extrinsic call not executed in benchmark???
ndkazu Aug 12, 2024
065039e
some corrections
ndkazu Aug 12, 2024
48d5d62
Tests are passing
ndkazu Aug 12, 2024
08c7518
Removed dev mode + clippy & fmt
ndkazu Aug 13, 2024
7b874a1
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 13, 2024
3389e6a
Benchmarking is now working for pallet distribution
ndkazu Aug 13, 2024
0592915
Pallet distribution ready for review
ndkazu Aug 13, 2024
e7956af
Re-wrote distribution benchmark and started opf benchmark
ndkazu Aug 14, 2024
5c25742
Benchmarking done
ndkazu Aug 15, 2024
a8f6d0c
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 15, 2024
ec08801
Fixing CLI errors
ndkazu Aug 15, 2024
d723478
Fixing errors
ndkazu Aug 15, 2024
67ddbb8
Fixing errors
ndkazu Aug 15, 2024
b960b3c
PRdoc
ndkazu Aug 15, 2024
53c31aa
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 15, 2024
ca65abb
Editing the prdoc
ndkazu Aug 15, 2024
b94e3f9
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Aug 15, 2024
6a918ad
Editing the prdoc
ndkazu Aug 15, 2024
8ed0b87
Editing the prdoc
ndkazu Aug 15, 2024
2878e5e
Editing the prdoc
ndkazu Aug 15, 2024
ab2ab73
Editing the prdoc->patch instead of minor
ndkazu Aug 15, 2024
40bdd68
Editing the prdoc
ndkazu Aug 15, 2024
d0dac4b
Editing the prdoc
ndkazu Aug 15, 2024
eb1ba63
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 15, 2024
a3be78b
Update prdoc/pr_5162.prdoc
ndkazu Aug 15, 2024
a5f0018
Fix prdoc
ndkazu Aug 15, 2024
39214cc
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Aug 15, 2024
fd40298
Fix semver
ndkazu Aug 15, 2024
79a29cc
Fix semver
ndkazu Aug 15, 2024
0c24a47
Corrected README
ndkazu Aug 16, 2024
b5c86d6
Use take instead of get & remove
ndkazu Aug 16, 2024
a3a59a2
Some suggested changes implemented.
ndkazu Aug 16, 2024
1a2139c
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 16, 2024
6bab58b
More OPF tests
ndkazu Aug 17, 2024
bf22c86
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 17, 2024
18fce0f
More tests and some in-code comments
ndkazu Aug 19, 2024
9718231
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Aug 19, 2024
1546392
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 19, 2024
8e76dd7
Merge branch 'master' into Optimist
Ank4n Aug 21, 2024
704c2fe
Conviction implemented, and funds unlock extrinsic added. New extrins…
ndkazu Aug 23, 2024
5695675
License added
ndkazu Aug 23, 2024
24cd606
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 23, 2024
7d80bfb
Review related corrections
ndkazu Aug 23, 2024
d9fc656
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Aug 23, 2024
baedd94
fix failing benchmark
ndkazu Aug 23, 2024
0d4a587
cargo fmt
ndkazu Aug 23, 2024
0cd321a
New extrinsic benchmark added
ndkazu Aug 23, 2024
73d0f5f
update
ndkazu Aug 23, 2024
1e38a51
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 24, 2024
4bec5f4
Type miss in ReadMe
ndkazu Aug 24, 2024
e1580cd
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 25, 2024
df41d42
Merge branch 'paritytech:master' into Optimist
ndkazu Aug 26, 2024
304a76d
Corrected Distribution pallet based on reviews
ndkazu Aug 27, 2024
bf8ba94
Error handling correction in Distribution pallet
ndkazu Aug 27, 2024
19dc1d9
added some corrections to the OPF pallet
ndkazu Aug 27, 2024
a2ff644
Removed unbounded map iter
ndkazu Aug 27, 2024
980226e
Further improvements in Distribution pallet
ndkazu Aug 27, 2024
ecbf739
Removing use of iter()
ndkazu Aug 28, 2024
b7ab820
Refactored try_vote function and removed iter()
ndkazu Aug 29, 2024
c29ffe8
cargo fmt
ndkazu Aug 29, 2024
c9dcc86
resolving conflict
ndkazu Aug 30, 2024
492a0d3
Merge branch 'master' into Optimist
ndkazu Aug 30, 2024
87d1c1e
Merge branch 'master' into Optimist
ndkazu Aug 31, 2024
8d4657d
Merge branch 'master' into Optimist
ndkazu Sep 3, 2024
5c5b8ad
opf-test correction
ndkazu Sep 3, 2024
98a0ae4
Merge branch 'paritytech:master' into Optimist
ndkazu Sep 5, 2024
98217d9
Renamed variable & removed some unecessary code
ndkazu Sep 6, 2024
77ae32e
Renamed some variables in pallet-opf
ndkazu Sep 6, 2024
8cb1b18
Updates vote_removal and corresponding tests
ndkazu Sep 6, 2024
ed56b2e
Clearing storages after a voting round ended in pallet-opf
ndkazu Sep 6, 2024
47fe97f
Debugging and additional tests
ndkazu Sep 6, 2024
3e2f2a1
cargo +nightly fmt
ndkazu Sep 6, 2024
8dfbcf3
Merge branch 'master' into Optimist
ndkazu Sep 6, 2024
556551d
Merge branch 'master' into Optimist
ndkazu Sep 7, 2024
effa3d9
Merge branch 'master' into Optimist
ndkazu Sep 8, 2024
2b5e0cd
Comments correction
ndkazu Sep 8, 2024
6942a86
Merge branch 'master' into Optimist
ndkazu Sep 9, 2024
1849512
Merge branch 'master' into Optimist
ndkazu Sep 11, 2024
72a8085
Merge branch 'master' into Optimist
ndkazu Sep 12, 2024
bb82af4
Merge branch 'master' into Optimist
ndkazu Sep 13, 2024
d2804b7
Merge branch 'master' into Optimist
ndkazu Sep 13, 2024
c847381
Reverted unwanted changes from cargo fmt
ndkazu Sep 13, 2024
2c0aa9b
Removed last unwanted format change
ndkazu Sep 13, 2024
511e8bc
Merge branch 'master' into Optimist
ndkazu Sep 13, 2024
bddabc8
Merge branch 'master' into Optimist
ndkazu Sep 14, 2024
5a13c98
Merge branch 'master' into Optimist
ndkazu Sep 16, 2024
e02fe4b
Correct import
ndkazu Sep 17, 2024
576a5b3
Merge branch 'master' into Optimist
ndkazu Sep 18, 2024
5760f9b
Merge branch 'master' into Optimist
ndkazu Sep 18, 2024
6e1c9ab
Merge branch 'master' into Optimist
ndkazu Sep 18, 2024
989be08
Corrected the respectives README's
ndkazu Sep 18, 2024
c62e265
toml format
ndkazu Sep 18, 2024
56e8676
rust-feature-propagation
ndkazu Sep 18, 2024
db2506b
Merge branch 'master' into Optimist
ndkazu Sep 18, 2024
12fbf3c
Rust features propagation
ndkazu Sep 18, 2024
c59b159
Merge branch 'master' into Optimist
ndkazu Sep 18, 2024
7412d46
Rust features propagation
ndkazu Sep 18, 2024
18f92fc
toml format
ndkazu Sep 19, 2024
840d64a
toml format
ndkazu Sep 19, 2024
cac2449
format toml
ndkazu Sep 19, 2024
8f0fd86
format toml
ndkazu Sep 19, 2024
4507209
fix umbrella error
ndkazu Sep 19, 2024
fb51be2
Fix Wasm error
ndkazu Sep 19, 2024
eef451c
Merge branch 'master' into Optimist
ndkazu Sep 19, 2024
f38806c
Merge branch 'master' into Optimist
ndkazu Sep 20, 2024
d21f4d8
Update Cargo.toml
ndkazu Sep 20, 2024
936cfd7
Update Cargo.toml
ndkazu Sep 20, 2024
7728824
Update Cargo.toml
ndkazu Sep 20, 2024
38718e5
Update cargo.toml
ndkazu Sep 20, 2024
99b3be4
Merge branch 'master' into Optimist
ndkazu Sep 20, 2024
f079db6
First round of corrections
ndkazu Sep 20, 2024
b61ddc6
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Sep 20, 2024
a4edbac
Second round of corrections
ndkazu Sep 20, 2024
635526e
Fix umbrella
ndkazu Sep 20, 2024
fa30adb
Revert some modifications
ndkazu Sep 20, 2024
2cf44db
changed max_weight in opf
ndkazu Sep 20, 2024
fa6a553
Fix format
ndkazu Sep 20, 2024
44fa41a
pallet-distribution corrections
ndkazu Sep 22, 2024
1ea2682
Merge branch 'master' into Optimist
ndkazu Sep 22, 2024
c1014fa
Removed unnecessary condition
ndkazu Sep 22, 2024
94496d1
cargo fmt
ndkazu Sep 23, 2024
e11002a
Merge branch 'master' into Optimist
ndkazu Sep 23, 2024
03b59e0
Updated weight.rs files
ndkazu Sep 23, 2024
b26a798
licenses
ndkazu Sep 23, 2024
37d1bca
Merge branch 'master' into Optimist
ndkazu Sep 23, 2024
96d1731
Merge branch 'master' into Optimist
ndkazu Sep 23, 2024
80cc666
Merge branch 'master' into Optimist
ndkazu Sep 25, 2024
10e9df8
Update substrate/frame/opf/src/lib.rs
ndkazu Sep 25, 2024
064b177
Merge branch 'master' into Optimist
ndkazu Sep 25, 2024
8586c18
Merge branch 'master' into Optimist
ndkazu Sep 26, 2024
93a9e9f
Merge branch 'master' into Optimist
ndkazu Sep 26, 2024
3ea2749
Merge branch 'master' into Optimist
ndkazu Sep 28, 2024
2d17a4e
cargo fmt
ndkazu Sep 28, 2024
5be0c9e
Merge branch 'master' into Optimist
ndkazu Sep 28, 2024
5b9f059
Merge branch 'master' into Optimist
ndkazu Sep 29, 2024
8cb632f
Merge branch 'master' into Optimist
ndkazu Oct 1, 2024
2b5d0e2
Merge branch 'master' into Optimist
ndkazu Oct 2, 2024
9b0a5f4
try to Fix failing benchmark test
ndkazu Oct 3, 2024
e201c53
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Oct 3, 2024
228da0a
Use calculated weight instead of max weight in on_idle_function
ndkazu Oct 3, 2024
e8ebcfc
Revert weight changes & limit block consumption to 1/10th
ndkazu Oct 3, 2024
f26d01c
cargo fmt
ndkazu Oct 3, 2024
0aa2708
Merge branch 'master' into Optimist
ndkazu Oct 4, 2024
0dbe4c9
Merge branch 'master' into Optimist
ndkazu Oct 5, 2024
25a3716
Merge branch 'master' into Optimist
ndkazu Oct 6, 2024
7821c10
Merge branch 'master' into Optimist
ndkazu Oct 8, 2024
d8934ad
Merge branch 'master' into Optimist
ndkazu Oct 8, 2024
3816547
Merge branch 'master' into Optimist
ndkazu Oct 9, 2024
8bddb52
Merge branch 'master' into Optimist
ndkazu Oct 10, 2024
48c58ad
Merge branch 'master' into Optimist
ndkazu Oct 13, 2024
65654a5
Merge branch 'master' into Optimist
ndkazu Oct 16, 2024
742544e
Merge branch 'master' into Optimist
ndkazu Oct 18, 2024
63b7eb4
Merge branch 'master' into Optimist
ndkazu Oct 20, 2024
d06fd28
cargo fmt
ndkazu Oct 20, 2024
b2cfb12
License
ndkazu Oct 20, 2024
6babd82
Weights & benchmarking
ndkazu Oct 20, 2024
1572c9a
Merge branch 'master' into Optimist
ndkazu Oct 22, 2024
4b94347
weights
ndkazu Oct 22, 2024
d4f865c
Merge branch 'master' into Optimist
ndkazu Oct 23, 2024
b8f19f2
try to fix feature-propagation error
ndkazu Oct 23, 2024
576c530
Merge branch 'master' into Optimist
ndkazu Oct 24, 2024
aea7890
fix CI errors
ndkazu Oct 24, 2024
0b9977c
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Oct 24, 2024
673e991
Merge branch 'master' into Optimist
ndkazu Oct 25, 2024
597d6b5
Update substrate/frame/distribution/src/functions.rs
ndkazu Oct 26, 2024
4d177b3
Preparation for scheduler use instead of on_initialize
ndkazu Oct 27, 2024
78848a1
Added RuntimeCall to distribution Config
ndkazu Oct 29, 2024
76175ab
Replaced on_initialize, need to re-write tests
ndkazu Oct 29, 2024
75dda7b
Some code clean up
ndkazu Oct 29, 2024
7678a81
Merge branch 'master' into Optimist
ndkazu Oct 29, 2024
4f3962a
Fixing tests
ndkazu Oct 31, 2024
5d11ffe
2 more tests to fix
ndkazu Oct 31, 2024
e494e5a
Merge branch 'master' into Optimist
ndkazu Oct 31, 2024
1ee6123
Merge branch 'master' into Optimist
ndkazu Nov 1, 2024
895e4c1
Revert "Merge branch 'master' into Optimist"
ndkazu Nov 1, 2024
170fe2b
Reapply "Merge branch 'master' into Optimist"
ndkazu Nov 1, 2024
99fd93e
Revert "Reapply "Merge branch 'master' into Optimist""
ndkazu Nov 1, 2024
d90ac79
Revert "Merge branch 'master' into Optimist"
ndkazu Nov 1, 2024
1fbd622
Use .retain instead of .filter
ndkazu Nov 1, 2024
86853df
corrected tests
ndkazu Nov 3, 2024
1dfcee6
Need to fix bad_origin error in the scheduler
ndkazu Nov 3, 2024
8323d0a
All tests fixed
ndkazu Nov 3, 2024
ffc4288
cargo fmt
ndkazu Nov 3, 2024
21ce8bd
unused variable
ndkazu Nov 3, 2024
a1ae424
pallet-distribution benchmarking
ndkazu Nov 10, 2024
696bfdc
Merge branch 'master' into Optimist
ndkazu Nov 11, 2024
dc83b95
Revert "pallet-distribution benchmarking"
ndkazu Nov 12, 2024
eb3ec0e
Merge branch 'master' into Optimist
ndkazu Nov 12, 2024
e21c957
Merge branch 'Optimist' of github.com:ndkazu/polkadot-sdk into Optimist
ndkazu Nov 12, 2024
2357b95
trying to fix merge
ndkazu Nov 12, 2024
079980e
Solviong conflicts
ndkazu Nov 12, 2024
d69110c
Solviong conflicts_1
ndkazu Nov 12, 2024
e6beacf
Solviong conflicts_2
ndkazu Nov 12, 2024
f6c1a5a
Solviong conflicts_2
ndkazu Nov 12, 2024
9bde46a
Solviong conflicts_3
ndkazu Nov 12, 2024
15df82b
Merge branch 'master' into Optimist
ndkazu Nov 14, 2024
cf8f39a
Add missing files
ndkazu Nov 14, 2024
e95a7e5
Solve conflicts
ndkazu Nov 14, 2024
fc21a43
weights fix
ndkazu Nov 14, 2024
ff6f2f4
Formatting
ndkazu Nov 14, 2024
fb9c69e
solve last conflicts
ndkazu Nov 14, 2024
b639444
missing file
ndkazu Nov 14, 2024
177c237
regenerate cargo.lock
ndkazu Nov 14, 2024
ffe6909
Merge branch 'master' into Optimist
ndkazu Nov 14, 2024
d0a870b
Add pallets to workspace
ndkazu Nov 14, 2024
2bce8ad
cargo fmt
ndkazu Nov 15, 2024
abe15dc
Merge branch 'master' into Optimist
ndkazu Nov 15, 2024
3e689f1
cargo.lock
ndkazu Nov 15, 2024
b579978
cargo.toml format
ndkazu Nov 15, 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
3,794 changes: 2,075 additions & 1,719 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ members = [
"substrate/frame/core-fellowship",
"substrate/frame/delegated-staking",
"substrate/frame/democracy",
"substrate/frame/distribution",
ndkazu marked this conversation as resolved.
Show resolved Hide resolved
"substrate/frame/election-provider-multi-phase",
"substrate/frame/election-provider-multi-phase/test-staking-e2e",
"substrate/frame/election-provider-support",
Expand Down Expand Up @@ -389,6 +390,7 @@ members = [
"substrate/frame/nomination-pools/test-transfer-stake",
"substrate/frame/offences",
"substrate/frame/offences/benchmarking",
"substrate/frame/opf",
"substrate/frame/paged-list",
"substrate/frame/paged-list/fuzzer",
"substrate/frame/parameters",
Expand Down Expand Up @@ -925,6 +927,7 @@ pallet-default-config-example = { path = "substrate/frame/examples/default-confi
pallet-delegated-staking = { path = "substrate/frame/delegated-staking", default-features = false }
pallet-democracy = { path = "substrate/frame/democracy", default-features = false }
pallet-dev-mode = { path = "substrate/frame/examples/dev-mode", default-features = false }
pallet-distribution = { path = "substrate/frame/distribution", default-features = false }
pallet-election-provider-multi-phase = { path = "substrate/frame/election-provider-multi-phase", default-features = false }
pallet-election-provider-support-benchmarking = { path = "substrate/frame/election-provider-support/benchmarking", default-features = false }
pallet-elections-phragmen = { path = "substrate/frame/elections-phragmen", default-features = false }
Expand Down Expand Up @@ -963,6 +966,7 @@ pallet-nomination-pools-benchmarking = { path = "substrate/frame/nomination-pool
pallet-nomination-pools-runtime-api = { path = "substrate/frame/nomination-pools/runtime-api", default-features = false }
pallet-offences = { path = "substrate/frame/offences", default-features = false }
pallet-offences-benchmarking = { path = "substrate/frame/offences/benchmarking", default-features = false }
pallet-opf = { path = "substrate/frame/opf", default-features = false }
pallet-paged-list = { path = "substrate/frame/paged-list", default-features = false }
pallet-parachain-template = { path = "templates/parachain/pallets/template", default-features = false }
pallet-parameters = { path = "substrate/frame/parameters", default-features = false }
Expand Down
Empty file modified docker/scripts/polkadot-omni-node/build-injected.sh
100755 → 100644
Empty file.
23 changes: 23 additions & 0 deletions prdoc/pr_5162.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "Optimistic Project Funding"

doc:
- audience: Runtime Dev
description: |
the combination of the OPF pallet and the DISTRIBUTION pallet handles the Optimistic Project Funding.
It allows users to nominate projects (whitelisted in OpenGov) with their DOT. This mechanism will be funded with a constant stream of DOT taken directly from inflation and distributed to projects based on the proportion of DOT that has nominated them.
The project rewards distribution is handled by the **Distribution Pallet**

crates:
- name: pallet-distribution
bump: patch
- name: pallet-opf
bump: patch
- name: frame-support
bump: none
- name: polkadot-sdk
bump: patch
- name: polkadot
bump: none
89 changes: 89 additions & 0 deletions substrate/frame/distribution/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[package]
authors.workspace = true
description = "FRAME pallet to distribute funds to whitelisted projects"
edition.workspace = true
homepage = "https://substrate.io"
license = "Apache-2.0"
name = "pallet-distribution"
readme = "README.md"
repository.workspace = true
version = "0.1.0"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true, default-features = false }
frame-benchmarking = { optional = true, workspace = true, default-features = false }
frame-support = { workspace = true, default-features = false }
frame-system = { workspace = true, default-features = false }
log = { workspace = true }
pallet-scheduler = { workspace = true, default-features = false }
scale-info = { features = [
"derive",
], workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false }
sp-io = { workspace = true, default-features = false }
sp-runtime = { workspace = true, default-features = false }
sp-std = { workspace = true, default-features = false }

[dev-dependencies]
pallet-assets = { workspace = true, default-features = true }
pallet-balances = { workspace = true, default-features = true }
pallet-preimage = { workspace = true, default-features = true }
pallet-scheduler = { workspace = true, default-features = true }
pallet-sudo = { workspace = true, default-features = true }
pallet-timestamp = { workspace = true, default-features = true }
pallet-transaction-payment = { workspace = true, default-features = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }

[features]
default = ["std"]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-preimage/std",
"pallet-scheduler/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"pallet-preimage/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"sp-runtime/try-runtime",
]
32 changes: 32 additions & 0 deletions substrate/frame/distribution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Distribution Pallet
## Overview

The **Distribution Pallet** handles the distribution of whitelisted projects rewards.

For now only one reward distribution pattern has been implemented, but the pallet could be extended
to offer to the user claiming rewards for a project, a choice between more than one distribution pattern.

The **Distribution Pallet** receives a list of Whitelisted/Nominated Projects with
their respective calculated rewards. For each project, it will create a corresponding
spend that will be stored until the project reward can be claimed.
At the moment, the reward claim period start corresponds to:
[beginning of an ***Epoch_Block*** + ***BufferPeriod***] (The ***BufferPeriod*** can be configured in the runtime).

### Terminology

- **PotId:** Pot containing the funds used to pay the rewards.
- **BufferPeriod:** minimum required buffer time period between project nomination and reward claim.

## Interface

### Dispatchable Functions

#### Public

These calls can be made from any externally held account capable of creating
a signed extrinsic.

Basic actions:
- `claim_reward_for` - From this extrinsic any user can claim a reward for a nominated/whitelisted project.

License: Apache-2.0
115 changes: 115 additions & 0 deletions substrate/frame/distribution/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// This file is part of Substrate.

// 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.

//! Distribution pallet benchmarking.

#![cfg(feature = "runtime-benchmarks")]

use super::*;

use crate::Pallet as Distribution;
use frame_benchmarking::{
v1::{account, BenchmarkError},
v2::*,
};
use frame_support::ensure;
use frame_system::RawOrigin;
use sp_runtime::traits::One;

const SEED: u32 = 0;

fn run_to_block<T: Config>(n: frame_system::pallet_prelude::BlockNumberFor<T>) {
while T::BlockNumberProvider::current_block_number() < n {
crate::Pallet::<T>::on_finalize(T::BlockNumberProvider::current_block_number());
frame_system::Pallet::<T>::on_finalize(T::BlockNumberProvider::current_block_number());
frame_system::Pallet::<T>::set_block_number(
T::BlockNumberProvider::current_block_number() + One::one(),
);
frame_system::Pallet::<T>::on_initialize(T::BlockNumberProvider::current_block_number());
crate::Pallet::<T>::on_initialize(T::BlockNumberProvider::current_block_number());
}
}

fn create_project<T: Config>(project_id: AccountIdOf<T>, amount: BalanceOf<T>) {
let submission_block = T::BlockNumberProvider::current_block_number();
let project: types::ProjectInfo<T> = ProjectInfo { project_id, submission_block, amount };
Projects::<T>::mutate(|value| {
let mut val = value.clone();
let _ = val.try_push(project);
*value = val;
});
}

/*fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}*/

fn create_parameters<T: Config>(n: u32) -> (AccountIdOf<T>, BalanceOf<T>) {
let project_id = account("project", n, SEED);
let value: BalanceOf<T> = T::NativeBalance::minimum_balance() * 100u32.into() * (n + 1).into();
let _ = T::NativeBalance::set_balance(&project_id, value);
(project_id, value)
}

fn setup_pot_account<T: Config>() -> AccountIdOf<T> {
let pot_account = Distribution::<T>::pot_account();
let value = T::NativeBalance::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = T::NativeBalance::set_balance(&pot_account, value);
pot_account
}

fn add_projects<T: Config>(r: u32) -> Result<(), &'static str> {
for i in 0..r {
let (project_id, amount) = create_parameters::<T>(i);
create_project::<T>(project_id, amount);
}

Ok(())
}

#[benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn claim_reward_for(r: Linear<1, { T::MaxProjects::get() }>) -> Result<(), BenchmarkError> {
/* setup initial state */
add_projects::<T>(r)?;

ensure!(<Projects<T>>::get().len() as u32 == r, "Project list setting failed !!");
let index: usize = (r - 1).try_into().unwrap();
let project = &<Projects<T>>::get()[index];
let _pot = setup_pot_account::<T>();
let caller: T::AccountId = whitelisted_caller();
let epoch = T::EpochDurationBlocks::get();
let mut when = T::BlockNumberProvider::current_block_number().saturating_add(epoch);
run_to_block::<T>(when);
/* execute extrinsic or function */

let project_id = &project.project_id;
let spend = <Spends<T>>::get(&project_id);
when = when.saturating_add(spend.unwrap().valid_from);
run_to_block::<T>(when);

#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), project_id.clone());

Ok(())
}

impl_benchmark_test_suite!(Distribution, crate::mock::new_test_ext(), crate::mock::Test);
}
Loading
Loading