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

feat: referrals #708

Merged
merged 95 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
18f52d2
initial referral pallet structure
enthusiastmartin Nov 17, 2023
e32dfb0
initial referral pallet structure
enthusiastmartin Nov 17, 2023
bbcc9a6
add register code with tests
enthusiastmartin Nov 17, 2023
47b6652
add registration fee payment
enthusiastmartin Nov 17, 2023
f6f9350
Add test to check existence if lowercase
enthusiastmartin Nov 17, 2023
26c39a6
add todoreminder
enthusiastmartin Nov 18, 2023
753745b
add link account and testS
enthusiastmartin Nov 20, 2023
55e7b03
Rewards storage
enthusiastmartin Nov 20, 2023
4995689
add convert initial stub and tests
enthusiastmartin Nov 21, 2023
7f1ac11
link same account is not allowed
enthusiastmartin Nov 21, 2023
420fc60
add conversion support
enthusiastmartin Nov 21, 2023
41b63e6
add reward asset config param
enthusiastmartin Nov 21, 2023
1fb2955
implement convert
enthusiastmartin Nov 21, 2023
06cc305
emit converted event
enthusiastmartin Nov 21, 2023
0e3a789
add claim implementation and tests
enthusiastmartin Nov 21, 2023
c2bd576
add referrer level info
enthusiastmartin Nov 22, 2023
5ae5e07
implement level ups
enthusiastmartin Nov 23, 2023
d857a4e
remove unused stuff
enthusiastmartin Nov 23, 2023
f268cb8
clippy
enthusiastmartin Nov 23, 2023
6173fbe
add prcess fee
enthusiastmartin Nov 23, 2023
57b4f1c
Add tests for process fees
enthusiastmartin Nov 24, 2023
6876f51
Merge branch 'master' into feat/referrals
enthusiastmartin Nov 28, 2023
016f2f3
rework rewards accumulation using shares
enthusiastmartin Nov 28, 2023
c4629be
claim tests reworked
enthusiastmartin Nov 28, 2023
e45e9aa
implement claim
enthusiastmartin Nov 28, 2023
63106a7
use safe math
enthusiastmartin Nov 28, 2023
94dd7de
add tiers tests
enthusiastmartin Nov 28, 2023
c63f7cb
benchmarking
enthusiastmartin Nov 28, 2023
23a04e5
add benchamrks for some extrinsics
enthusiastmartin Nov 28, 2023
ada274f
happy clippy happy life
enthusiastmartin Nov 28, 2023
fdcc721
update dependencies
enthusiastmartin Nov 28, 2023
3ff68de
cargo description
enthusiastmartin Nov 28, 2023
b706144
finish benchmarks
enthusiastmartin Nov 29, 2023
ada57a8
use correct claim rewards weight
enthusiastmartin Nov 29, 2023
fcb5628
use correct claim rewards weight
enthusiastmartin Nov 29, 2023
bf427b8
happy clippy happy life
enthusiastmartin Nov 29, 2023
cd9189b
reformat
enthusiastmartin Nov 29, 2023
00ebe5d
docd and readme
enthusiastmartin Nov 30, 2023
25abc70
runtime integration
enthusiastmartin Nov 30, 2023
27adcd0
fix trait change
enthusiastmartin Nov 30, 2023
b6f8b39
reformat
enthusiastmartin Nov 30, 2023
b3ab072
Merge branch 'master' into feat/referrals
enthusiastmartin Dec 8, 2023
fe08035
ressurect readme
enthusiastmartin Dec 8, 2023
a1aa65a
ressurect readme
enthusiastmartin Dec 8, 2023
2bee22a
unneccesary stuff
enthusiastmartin Dec 8, 2023
87ea6ee
keep alive for reward transfer
enthusiastmartin Dec 8, 2023
aff0e73
remove account param from register call
enthusiastmartin Dec 8, 2023
595a4f1
Add reward pot to list of non dust accounts
enthusiastmartin Dec 8, 2023
f31278a
use ratio instead fixed type for price and use oracle provider
enthusiastmartin Dec 11, 2023
20bba19
fix integration tests
enthusiastmartin Dec 11, 2023
78708ce
add seed amount param and exclude it from total rewards
enthusiastmartin Dec 11, 2023
e08027e
tests for seed amount
enthusiastmartin Dec 11, 2023
5ab6809
add pallet to benchmarks
enthusiastmartin Dec 11, 2023
593963f
Merge branch 'master' into feat/referrals
enthusiastmartin Dec 11, 2023
c8468e4
referalls benchmarks adjusted and added weights
enthusiastmartin Dec 12, 2023
c6c5a06
bump versions
enthusiastmartin Dec 12, 2023
d6f1ecc
add aditional test
enthusiastmartin Dec 12, 2023
9754847
Add to try runtime
enthusiastmartin Dec 12, 2023
313d3dc
happy clippy happy life
enthusiastmartin Dec 12, 2023
2e943d2
change reg fee to 222HDX
enthusiastmartin Dec 12, 2023
30aa177
set levels
enthusiastmartin Dec 13, 2023
2d9727d
adjust omnipool benchmark
enthusiastmartin Dec 13, 2023
7cb4424
allow only one code per account
enthusiastmartin Dec 13, 2023
e14b0e4
set min length to 5
enthusiastmartin Dec 13, 2023
c064836
new weights for omnipool and referrals
enthusiastmartin Dec 13, 2023
623693e
happy clippy happy life
enthusiastmartin Dec 13, 2023
3b5d9a8
reformat
enthusiastmartin Dec 13, 2023
2f72623
fix test - make dxa fee check more permissive
dmoka Dec 13, 2023
6d82112
change oracle period to 10mins
enthusiastmartin Dec 13, 2023
c261548
happy clippy happy life
enthusiastmartin Dec 13, 2023
dc5431d
change code param type, add min buy amount
enthusiastmartin Dec 14, 2023
6eee1a9
fix omnipool benchmakrs
enthusiastmartin Dec 14, 2023
09889e3
happy clippy happy life
enthusiastmartin Dec 14, 2023
fee2f33
on_idle convert and permissive conversions in claim
enthusiastmartin Dec 14, 2023
55e0a43
rework levels
enthusiastmartin Dec 15, 2023
cd0362e
rework tier volume in config
enthusiastmartin Dec 15, 2023
0ae4a92
omnipool fee amount check
enthusiastmartin Dec 15, 2023
e1f3b74
happy clippy happy life
enthusiastmartin Dec 15, 2023
39cbdb0
integration tests
enthusiastmartin Dec 18, 2023
76b0dfc
reformat
enthusiastmartin Dec 18, 2023
2fb7ddd
happy clippy happy life
enthusiastmartin Dec 18, 2023
ff09203
happy clippy happy life
enthusiastmartin Dec 18, 2023
f9329c9
on trade fee hook result change
enthusiastmartin Dec 18, 2023
3913f50
version bump
enthusiastmartin Dec 18, 2023
716cce2
set referrals rewards to 0 for some integration tests
enthusiastmartin Dec 18, 2023
5467e5c
update tier threshold
enthusiastmartin Dec 19, 2023
fe144ab
Add tests of on idle
enthusiastmartin Dec 19, 2023
1ef7850
mark function only for runtime-benchmakrs features
enthusiastmartin Dec 19, 2023
e2ff7f7
Merge branch 'master' into feat/referrals
enthusiastmartin Dec 19, 2023
3ee5e27
fix draining assets in claims
enthusiastmartin Dec 20, 2023
0c85184
rename Assets to PendingConversions
enthusiastmartin Dec 20, 2023
206a160
combine volume and rewards in config param
enthusiastmartin Dec 20, 2023
91327a2
renamed Tier
enthusiastmartin Dec 20, 2023
2127894
Merge branch 'master' into feat/referrals
mrq1911 Dec 20, 2023
55ce109
treshold adjustment
enthusiastmartin Dec 21, 2023
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
44 changes: 34 additions & 10 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 @@ -36,6 +36,7 @@ members = [
'pallets/staking',
'pallets/democracy',
'runtime/hydradx/src/evm/evm-utility/macro',
'pallets/referrals',
]

[workspace.dependencies]
Expand Down Expand Up @@ -76,6 +77,7 @@ warehouse-liquidity-mining = { package = "pallet-liquidity-mining", path = "pall
pallet-bonds = { path = "pallets/bonds", default-features = false}
pallet-lbp = { path = "pallets/lbp", default-features = false}
pallet-xyk = { path = "pallets/xyk", default-features = false}
pallet-referrals = { path = "pallets/referrals", default-features = false}

hydra-dx-build-script-utils = { path = "utils/build-script-utils", default-features = false }
scraper = { path = "scraper", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.16.4"
version = "1.16.5"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand All @@ -20,6 +20,7 @@ pallet-circuit-breaker = { workspace = true }
pallet-omnipool-liquidity-mining = { workspace = true }
pallet-bonds = { workspace = true }
pallet-stableswap = { workspace = true }
pallet-referrals = { workspace = true }

# Warehouse dependencies
pallet-asset-registry = { workspace = true }
Expand Down
23 changes: 18 additions & 5 deletions integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,7 @@ mod stableswap {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(DAI, HDX, UNITS);

set_relaychain_block_number(10);
Expand Down Expand Up @@ -1426,7 +1427,7 @@ mod stableswap {
Permill::from_percent(100),
AccountId::from(BOB),
));

set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(DAI, HDX, UNITS);

set_relaychain_block_number(10);
Expand Down Expand Up @@ -1490,6 +1491,7 @@ mod stableswap {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(DAI, HDX, UNITS);

set_relaychain_block_number(10);
Expand Down Expand Up @@ -1578,7 +1580,7 @@ mod stableswap {
Permill::from_percent(100),
AccountId::from(BOB),
));

set_zero_reward_for_referrals(pool_id);
//Populate oracle with omnipool source
assert_ok!(Tokens::set_balance(
RawOrigin::Root.into(),
Expand Down Expand Up @@ -1693,6 +1695,7 @@ mod stableswap {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);

//Populate oracle with omnipool source
assert_ok!(Tokens::set_balance(
Expand Down Expand Up @@ -1788,6 +1791,7 @@ mod stableswap {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);

//Populate oracle with omnipool source
assert_ok!(Tokens::set_balance(
Expand Down Expand Up @@ -1890,6 +1894,7 @@ mod stableswap {
AccountId::from(BOB),
));
do_trade_to_populate_oracle(DAI, HDX, UNITS);
set_zero_reward_for_referrals(pool_id);

set_relaychain_block_number(10);

Expand Down Expand Up @@ -2061,7 +2066,7 @@ mod stableswap {
Permill::from_percent(100),
AccountId::from(BOB),
));

set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(pool_id, HDX, 100 * UNITS);

set_relaychain_block_number(10);
Expand Down Expand Up @@ -2293,6 +2298,7 @@ mod all_pools {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(DAI, HDX, UNITS);

//Create xyk and populate oracle
Expand Down Expand Up @@ -2445,6 +2451,7 @@ mod with_onchain_route {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(DAI, HDX, UNITS);

set_relaychain_block_number(10);
Expand Down Expand Up @@ -2555,6 +2562,7 @@ mod with_onchain_route {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(DAI, HDX, UNITS);

set_relaychain_block_number(10);
Expand Down Expand Up @@ -2656,6 +2664,7 @@ mod with_onchain_route {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(DOT);
do_trade_to_populate_oracle(DAI, HDX, UNITS);

assert_ok!(Currencies::update_balance(
Expand Down Expand Up @@ -2775,6 +2784,7 @@ mod with_onchain_route {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(pool_id);
do_trade_to_populate_oracle(pool_id, HDX, 10000000 * UNITS);

set_relaychain_block_number(10);
Expand Down Expand Up @@ -2987,8 +2997,8 @@ mod with_onchain_route {
assert!(fee > 0, "The treasury did not receive the fee");

//The fee would be 5310255478763 in HDX, so it is less in DOT, which checks out
assert!(fee < 38 * UNITS / 10);
assert!(fee > 37 * UNITS / 10);
assert!(fee < 40 * UNITS / 10);
assert!(fee > 36 * UNITS / 10);

assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance + 278060378846663);
assert_reserved_balance!(&ALICE.into(), DOT, dca_budget - amount_to_sell - fee);
Expand Down Expand Up @@ -3172,6 +3182,9 @@ pub fn init_omnipol() {
TREASURY_ACCOUNT_INIT_BALANCE,
0,
));

set_zero_reward_for_referrals(HDX);
set_zero_reward_for_referrals(DAI);
}

fn init_omnipool_with_oracle_for_block_10() {
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/src/dynamic_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ fn init_omnipool() {
Permill::from_percent(100),
AccountId::from(BOB),
));
set_zero_reward_for_referrals(HDX);
set_zero_reward_for_referrals(DAI);
set_zero_reward_for_referrals(DOT);
set_zero_reward_for_referrals(ETH);
}

/// This function executes one sell and buy with HDX for all assets in the omnipool. This is necessary to
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod omnipool_liquidity_mining;
mod oracle;
mod otc;
mod polkadot_test_net;
mod referrals;
mod router;
mod staking;
mod transact_call_filter;
Expand Down
15 changes: 15 additions & 0 deletions integration-tests/src/polkadot_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ pub use primitives::{constants::chain::CORE_ASSET_ID, AssetId, Balance, Moment};

use cumulus_primitives_core::ParaId;
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use frame_system::RawOrigin;
use hex_literal::hex;
use hydradx_runtime::evm::WETH_ASSET_LOCATION;
use hydradx_runtime::Referrals;
use hydradx_runtime::RuntimeOrigin;
use pallet_evm::AddressMapping;
use pallet_referrals::{FeeDistribution, Level};
use polkadot_primitives::v2::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_runtime_parachains::configuration::HostConfiguration;
use sp_core::H160;
Expand Down Expand Up @@ -525,6 +528,9 @@ pub fn init_omnipool() {
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
stable_position_id,
));

set_zero_reward_for_referrals(DAI);
set_zero_reward_for_referrals(HDX);
}

#[macro_export]
Expand All @@ -540,3 +546,12 @@ macro_rules! assert_reserved_balance {
assert_eq!(Currencies::reserved_balance($asset, &$who), $amount);
}};
}

pub fn set_zero_reward_for_referrals(asset_id: AssetId) {
assert_ok!(Referrals::set_reward_percentage(
RawOrigin::Root.into(),
asset_id,
Level::None,
FeeDistribution::default(),
));
}
Loading
Loading