Skip to content

Commit

Permalink
treshold adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
enthusiastmartin committed Dec 21, 2023
1 parent 2127894 commit 55ce109
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 90 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions integration-tests/src/referrals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn trading_in_omnipool_should_transfer_portion_of_fee_to_reward_pot() {
0
));
let pot_balance = Currencies::free_balance(DAI, &Referrals::pot_account_id());
assert_eq!(pot_balance, 28_540_796_091_592_978);
assert_eq!(pot_balance, 28_540_796_051_302_768);
});
}

Expand All @@ -66,7 +66,7 @@ fn trading_in_omnipool_should_increase_referrer_shares() {
0
));
let referrer_shares = Referrals::account_shares::<AccountId>(ALICE.into());
assert_eq!(referrer_shares, 128_499_434);
assert_eq!(referrer_shares, 128_499_283);
});
}
#[test]
Expand All @@ -88,7 +88,7 @@ fn trading_in_omnipool_should_increase_trader_shares() {
0
));
let trader_shares = Referrals::account_shares::<AccountId>(BOB.into());
assert_eq!(trader_shares, 256_998_869);
assert_eq!(trader_shares, 256_998_567);
});
}
#[test]
Expand All @@ -110,7 +110,7 @@ fn trading_in_omnipool_should_increase_external_shares() {
0
));
let external_shares = Referrals::account_shares::<AccountId>(Staking::pot_account_id().into());
assert_eq!(external_shares, 2_164_560_909_660);
assert_eq!(external_shares, 1_067_610_243_609);
});
}

Expand All @@ -133,7 +133,7 @@ fn trading_in_omnipool_should_increase_total_shares_correctly() {
0
));
let total_shares = Referrals::total_shares();
assert_eq!(total_shares, 256_998_869 + 128_499_434 + 2_164_560_909_660);
assert_eq!(total_shares, 1_067_995_741_459);
});
}

Expand Down Expand Up @@ -165,7 +165,7 @@ fn claiming_rewards_should_convert_all_assets_to_reward_asset() {
}

#[test]
fn trading_hdx_in_omnipool_should_work_when_fee_is_below_existential_deposit() {
fn trading_hdx_in_omnipool_should_skip_referrals_program() {
Hydra::execute_with(|| {
init_omnipool_with_oracle_for_block_10();
let code =
Expand All @@ -183,7 +183,7 @@ fn trading_hdx_in_omnipool_should_work_when_fee_is_below_existential_deposit() {
0
));
let referrer_shares = Referrals::account_shares::<AccountId>(BOB.into());
assert_eq!(referrer_shares, 98_704_716_390);
assert_eq!(referrer_shares, 0);
});
}

Expand All @@ -199,7 +199,7 @@ fn trading_in_omnipool_should_transfer_some_portion_of_fee_when_no_code_linked()
0
));
let pot_balance = Currencies::free_balance(DAI, &Referrals::pot_account_id());
assert_eq!(pot_balance, 28_540_796_091_592_980);
assert_eq!(pot_balance, 28_540_796_051_302_770);
let external_shares = Referrals::account_shares::<AccountId>(Staking::pot_account_id());
let total_shares = Referrals::total_shares();
assert_eq!(total_shares, external_shares);
Expand All @@ -225,11 +225,11 @@ fn trading_in_omnipool_should_use_global_rewards_when_not_set() {
0
));
let referrer_shares = Referrals::account_shares::<AccountId>(ALICE.into());
assert_eq!(referrer_shares, 128_499_434);
assert_eq!(referrer_shares, 128_499_283);
let trader_shares = Referrals::account_shares::<AccountId>(BOB.into());
assert_eq!(trader_shares, 256_998_869);
assert_eq!(trader_shares, 256_998_567);
let external_shares = Referrals::account_shares::<AccountId>(Staking::pot_account_id());
assert_eq!(external_shares, 2_164_560_909_660);
assert_eq!(external_shares, 1_067_610_243_609);
let total_shares = Referrals::total_shares();
assert_eq!(total_shares, referrer_shares + trader_shares + external_shares);
});
Expand Down Expand Up @@ -264,11 +264,11 @@ fn trading_in_omnipool_should_use_asset_rewards_when_set() {
0
));
let referrer_shares = Referrals::account_shares::<AccountId>(ALICE.into());
assert_eq!(referrer_shares, 51_399_773);
assert_eq!(referrer_shares, 51_399_713);
let trader_shares = Referrals::account_shares::<AccountId>(BOB.into());
assert_eq!(trader_shares, 25_699_886);
assert_eq!(trader_shares, 25_699_856);
let external_shares = Referrals::account_shares::<AccountId>(Staking::pot_account_id());
assert_eq!(external_shares, 2_163_918_412_488);
assert_eq!(external_shares, 1_066_967_747_190);
let total_shares = Referrals::total_shares();
assert_eq!(total_shares, referrer_shares + trader_shares + external_shares);
});
Expand All @@ -287,7 +287,7 @@ fn trading_in_omnipool_should_increase_staking_shares_when_no_code_linked() {
));
let staking_acc = Staking::pot_account_id();
let staking_shares = Referrals::account_shares::<AccountId>(staking_acc.into());
assert_eq!(staking_shares, 2_164_946_407_964);
assert_eq!(staking_shares, 1_067_995_741_461);
let total_shares = Referrals::total_shares();
assert_eq!(total_shares, staking_shares);
});
Expand Down
60 changes: 28 additions & 32 deletions integration-tests/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,23 +625,21 @@ mod router_different_pools_tests {
assert_eq!(
RouterWeightInfo::sell_weight(trades.as_slice()),
hydradx_runtime::weights::omnipool::HydraWeight::<Runtime>::router_execution_sell(1, 1)
.checked_add(
&<OmnipoolHookAdapter<RuntimeOrigin, ConstU32<LRNA>, Runtime> as OmnipoolHooks::<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_trade_weight()
)
.checked_add(&<OmnipoolHookAdapter<
RuntimeOrigin,
ConstU32<HDX>,
ConstU32<LRNA>,
Runtime,
> as OmnipoolHooks::<RuntimeOrigin, AccountId, AssetId, Balance>>::on_trade_weight(
))
.unwrap()
.checked_add(
&<OmnipoolHookAdapter<RuntimeOrigin, ConstU32<LRNA>, Runtime> as OmnipoolHooks::<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_liquidity_changed_weight()
)
.checked_add(&<OmnipoolHookAdapter<
RuntimeOrigin,
ConstU32<HDX>,
ConstU32<LRNA>,
Runtime,
> as OmnipoolHooks::<RuntimeOrigin, AccountId, AssetId, Balance>>::on_liquidity_changed_weight(
))
.unwrap()
.checked_add(&hydradx_runtime::weights::lbp::HydraWeight::<Runtime>::router_execution_sell(1, 1))
.unwrap()
Expand All @@ -655,23 +653,21 @@ mod router_different_pools_tests {
assert_eq!(
RouterWeightInfo::buy_weight(trades.as_slice()),
hydradx_runtime::weights::omnipool::HydraWeight::<Runtime>::router_execution_buy(1, 1)
.checked_add(
&<OmnipoolHookAdapter<RuntimeOrigin, ConstU32<LRNA>, Runtime> as OmnipoolHooks::<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_trade_weight()
)
.checked_add(&<OmnipoolHookAdapter<
RuntimeOrigin,
ConstU32<HDX>,
ConstU32<LRNA>,
Runtime,
> as OmnipoolHooks::<RuntimeOrigin, AccountId, AssetId, Balance>>::on_trade_weight(
))
.unwrap()
.checked_add(
&<OmnipoolHookAdapter<RuntimeOrigin, ConstU32<LRNA>, Runtime> as OmnipoolHooks::<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_liquidity_changed_weight()
)
.checked_add(&<OmnipoolHookAdapter<
RuntimeOrigin,
ConstU32<HDX>,
ConstU32<LRNA>,
Runtime,
> as OmnipoolHooks::<RuntimeOrigin, AccountId, AssetId, Balance>>::on_liquidity_changed_weight(
))
.unwrap()
.checked_add(&hydradx_runtime::weights::lbp::HydraWeight::<Runtime>::router_execution_buy(1, 1))
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion runtime/adapters/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-adapters"
version = "0.6.8"
version = "0.6.9"
description = "Structs and other generic types for building runtimes."
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
24 changes: 15 additions & 9 deletions runtime/adapters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,13 @@ where
}

/// Passes on trade and liquidity data from the omnipool to the oracle.
pub struct OmnipoolHookAdapter<Origin, Lrna, Runtime>(PhantomData<(Origin, Lrna, Runtime)>);
pub struct OmnipoolHookAdapter<Origin, NativeAsset, Lrna, Runtime>(PhantomData<(Origin, NativeAsset, Lrna, Runtime)>);

impl<Origin, Lrna, Runtime> OmnipoolHooks<Origin, AccountId, AssetId, Balance>
for OmnipoolHookAdapter<Origin, Lrna, Runtime>
impl<Origin, NativeAsset, Lrna, Runtime> OmnipoolHooks<Origin, AccountId, AssetId, Balance>
for OmnipoolHookAdapter<Origin, NativeAsset, Lrna, Runtime>
where
Lrna: Get<AssetId>,
NativeAsset: Get<AssetId>,
Runtime: pallet_ema_oracle::Config
+ pallet_circuit_breaker::Config
+ frame_system::Config<RuntimeOrigin = Origin>
Expand Down Expand Up @@ -470,12 +471,17 @@ where
asset: AssetId,
amount: Balance,
) -> Result<Balance, Self::Error> {
let referrals_used = pallet_referrals::Pallet::<Runtime>::process_trade_fee(
fee_account.clone().into(),
trader.into(),
asset.into(),
amount,
)?;
let referrals_used = if asset == NativeAsset::get() {
Balance::zero()
} else {
pallet_referrals::Pallet::<Runtime>::process_trade_fee(
fee_account.clone().into(),
trader.into(),
asset.into(),
amount,
)?
};

let staking_used = pallet_staking::Pallet::<Runtime>::process_trade_fee(
fee_account.into(),
asset.into(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-runtime"
version = "195.0.0"
version = "196.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down
66 changes: 37 additions & 29 deletions runtime/hydradx/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl pallet_omnipool::Config for Runtime {
type NFTCollectionId = OmnipoolCollectionId;
type NFTHandler = Uniques;
type WeightInfo = weights::omnipool::HydraWeight<Runtime>;
type OmnipoolHooks = OmnipoolHookAdapter<Self::RuntimeOrigin, LRNA, Runtime>;
type OmnipoolHooks = OmnipoolHookAdapter<Self::RuntimeOrigin, NativeAssetId, LRNA, Runtime>;
type PriceBarrier = (
EnsurePriceWithin<
AccountId,
Expand Down Expand Up @@ -573,18 +573,22 @@ impl AmmTradeWeights<Trade<AssetId>> for RouterWeightInfo {

let amm_weight = match trade.pool {
PoolType::Omnipool => weights::omnipool::HydraWeight::<Runtime>::router_execution_sell(c, e)
.saturating_add(<OmnipoolHookAdapter<RuntimeOrigin, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_trade_weight())
.saturating_add(<OmnipoolHookAdapter<RuntimeOrigin, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_liquidity_changed_weight()),
.saturating_add(
<OmnipoolHookAdapter<RuntimeOrigin, NativeAssetId, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_trade_weight(),
)
.saturating_add(
<OmnipoolHookAdapter<RuntimeOrigin, NativeAssetId, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_liquidity_changed_weight(),
),
PoolType::LBP => weights::lbp::HydraWeight::<Runtime>::router_execution_sell(c, e),
PoolType::Stableswap(_) => weights::stableswap::HydraWeight::<Runtime>::router_execution_sell(c, e),
PoolType::XYK => weights::xyk::HydraWeight::<Runtime>::router_execution_sell(c, e)
Expand All @@ -607,18 +611,22 @@ impl AmmTradeWeights<Trade<AssetId>> for RouterWeightInfo {

let amm_weight = match trade.pool {
PoolType::Omnipool => weights::omnipool::HydraWeight::<Runtime>::router_execution_buy(c, e)
.saturating_add(<OmnipoolHookAdapter<RuntimeOrigin, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_trade_weight())
.saturating_add(<OmnipoolHookAdapter<RuntimeOrigin, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_liquidity_changed_weight()),
.saturating_add(
<OmnipoolHookAdapter<RuntimeOrigin, NativeAssetId, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_trade_weight(),
)
.saturating_add(
<OmnipoolHookAdapter<RuntimeOrigin, NativeAssetId, LRNA, Runtime> as OmnipoolHooks<
RuntimeOrigin,
AccountId,
AssetId,
Balance,
>>::on_liquidity_changed_weight(),
),
PoolType::LBP => weights::lbp::HydraWeight::<Runtime>::router_execution_buy(c, e),
PoolType::Stableswap(_) => weights::stableswap::HydraWeight::<Runtime>::router_execution_buy(c, e),
PoolType::XYK => weights::xyk::HydraWeight::<Runtime>::router_execution_buy(c, e)
Expand Down Expand Up @@ -1093,10 +1101,10 @@ impl GetByKey<Level, (Balance, FeeDistribution)> for ReferralsLevelVolumeAndRewa
fn get(k: &Level) -> (Balance, FeeDistribution) {
let volume = match k {
Level::Tier0 | Level::None => 0,
Level::Tier1 => 1_222_222_000_000_000_000,
Level::Tier2 => 12_222_220_000_000_000_000,
Level::Tier3 => 122_222_200_000_000_000_000,
Level::Tier4 => 1_222_222_000_000_000_000_000,
Level::Tier1 => 305 * UNITS,
Level::Tier2 => 4_583 * UNITS,
Level::Tier3 => 61_111 * UNITS,
Level::Tier4 => 763_888 * UNITS,
};
let rewards = match k {
Level::None => FeeDistribution {
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("hydradx"),
impl_name: create_runtime_str!("hydradx"),
authoring_version: 1,
spec_version: 195,
spec_version: 196,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 55ce109

Please sign in to comment.