Skip to content

Commit

Permalink
Merge pull request #708 from galacticcouncil/feat/referrals
Browse files Browse the repository at this point in the history
feat: referrals
  • Loading branch information
mrq1911 authored Dec 21, 2023
2 parents 564553c + 55ce109 commit e92d27d
Show file tree
Hide file tree
Showing 46 changed files with 3,906 additions and 159 deletions.
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

0 comments on commit e92d27d

Please sign in to comment.