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

Refactor farming gauge #1509

Merged
merged 24 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
df1af36
Bifrost v0.15.0
SunTiebing Oct 29, 2024
70ea90a
Migrated benchmarking of asset-registry from v1 to v2. (#1486)
MJLNSN Oct 31, 2024
90774f7
Feat/ban vbnc transfer (#1487)
SunTiebing Oct 31, 2024
b0a58c0
Feat/flexible fee ban vbnc (#1488)
SunTiebing Oct 31, 2024
b60ba06
Add XcmWeightTrader, XcmPaymentApi and DryRunApi #1484 (#1490)
hqwangningbo Nov 5, 2024
f251aac
feat: change benefit receiving account (#1493)
Wsteth Nov 9, 2024
18328f8
Preparing for async backing support (#1491)
hqwangningbo Nov 9, 2024
393ddc9
Add parachain staking (#1494)
SunTiebing Nov 11, 2024
2a23f03
Migrated benchmarking from v1 to v2 for bb-bnc. (#1495)
MJLNSN Nov 12, 2024
49f79c2
fix: 🐛 notify_rewards (#1496)
yooml Nov 12, 2024
1cdde78
Feat/flexible fee ban vbnc (#1497)
SunTiebing Nov 12, 2024
ea82ddd
Optimize the CallFilter logic. (#1498)
SunTiebing Nov 14, 2024
781a329
Fix vtoken minting (#1500)
hqwangningbo Nov 14, 2024
9dd688f
[skip ci] fix: bifrost-polkadot chain-spec (#1499)
TomatoAres Nov 15, 2024
1d3e12c
Vtoken-voting support vbnc. (#1501)
SunTiebing Nov 17, 2024
36ef1e9
refactor: 💡 gauge
yooml Nov 20, 2024
0c551bd
refactor: 💡 remove old gauge logic
yooml Nov 20, 2024
55836ab
fix: 🐛 rm max_block
yooml Nov 21, 2024
fc5fd76
fix: 🐛 fmt
yooml Nov 21, 2024
9c1cc62
fix: 🐛 fmt
yooml Nov 21, 2024
049d67b
fix: 🐛 fmt
yooml Nov 21, 2024
1842262
fix: 🐛 clippy
yooml Nov 21, 2024
46745a8
fix: 🐛 conflict
yooml Nov 22, 2024
0c6f499
Merge branch 'v0.16.0' into refactor-farming-gauge
ark930 Nov 29, 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
50 changes: 13 additions & 37 deletions pallets/farming/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ benchmarks! {
}: _(RawOrigin::Root,
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -56,7 +56,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -78,7 +78,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -101,7 +101,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -115,30 +115,6 @@ benchmarks! {
Farming::<T>::on_initialize(BlockNumberFor::<T>::from(0u32));
}: _(RawOrigin::Signed(caller.clone()), 0)

gauge_withdraw {
let caller: T::AccountId = whitelisted_caller();
let token_amount = BalanceOf::<T>::unique_saturated_from(1000u128);
let default_currency_id = CurrencyIdOf::<T>::default();
let tokens_proportion = vec![(default_currency_id, Perbill::from_percent(100))];
let basic_rewards = vec![(default_currency_id, token_amount)];
let gauge_basic_rewards = vec![(default_currency_id, token_amount)];
assert_ok!(Farming::<T>::create_farming_pool(
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
BlockNumberFor::<T>::from(6u32),
5,
));
let charge_rewards = vec![(default_currency_id,BalanceOf::<T>::unique_saturated_from(300000u128))];
assert_ok!(Farming::<T>::charge(RawOrigin::Signed(caller.clone()).into(), 0, charge_rewards, false));
assert_ok!(Farming::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, token_amount));
// System::<T>::set_block_number(System::<T>::block_number() + BlockNumberFor::<T>::from(10u32));
}: _(RawOrigin::Signed(caller.clone()), 0)

withdraw_claim {
let caller: T::AccountId = whitelisted_caller();
let token_amount = BalanceOf::<T>::unique_saturated_from(1000u128);
Expand All @@ -150,7 +126,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -175,7 +151,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards.clone())),
Some(gauge_basic_rewards.clone()),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -196,7 +172,7 @@ benchmarks! {
Some(BlockNumberFor::<T>::from(7u32)),
Some(BlockNumberFor::<T>::from(6u32)),
Some(5),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards))
Some(gauge_basic_rewards)
)

force_retire_pool {
Expand All @@ -212,7 +188,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards.clone())),
Some(gauge_basic_rewards.clone()),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -239,7 +215,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards.clone())),
Some(gauge_basic_rewards.clone()),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -258,7 +234,7 @@ benchmarks! {
assert_ok!(Farming::<T>::create_farming_pool(RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards.clone())),
Some(gauge_basic_rewards.clone()),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -283,7 +259,7 @@ benchmarks! {
assert_ok!(Farming::<T>::create_farming_pool(RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -305,7 +281,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand All @@ -326,7 +302,7 @@ benchmarks! {
RawOrigin::Root.into(),
tokens_proportion.clone(),
basic_rewards.clone(),
Some((BlockNumberFor::<T>::from(1000u32), gauge_basic_rewards)),
Some(gauge_basic_rewards),
BalanceOf::<T>::unique_saturated_from(0u128),
BlockNumberFor::<T>::from(0u32),
BlockNumberFor::<T>::from(7u32),
Expand Down
43 changes: 15 additions & 28 deletions pallets/farming/src/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,25 @@ where
pid: PoolId,
pool_info: &mut PoolInfo<BalanceOf<T>, CurrencyIdOf<T>, AccountIdOf<T>, BlockNumberFor<T>>,
gauge_basic_rewards: BTreeMap<CurrencyIdOf<T>, BalanceOf<T>>,
max_block: BlockNumberFor<T>,
) -> DispatchResult {
pool_info.gauge = Some(pid);
let current_block_number = frame_system::Pallet::<T>::block_number();
let gauge_pool_info = GaugePoolInfo::new(
pid,
let gid: u32 = pid + GAUGE_BASE_ID;
pool_info.gauge = Some(gid);
let gauge_reward_issuer: AccountIdOf<T> =
T::RewardIssuer::get().into_sub_account_truncating(gid);
let gauge_pool_info = PoolInfo::new_gauge(
pool_info.keeper.clone(),
pool_info.reward_issuer.clone(),
gauge_reward_issuer,
pool_info.tokens_proportion.clone(),
pool_info.basic_token,
gauge_basic_rewards,
max_block,
current_block_number,
None,
Zero::zero(), // min_deposit_to_start,
Default::default(),
Default::default(),
Default::default(),
Default::default(),
);

GaugePoolInfos::<T>::insert(pid, &gauge_pool_info);
GaugePoolNextId::<T>::mutate(|id| -> DispatchResult {
*id = id.checked_add(1).ok_or(ArithmeticError::Overflow)?;
Ok(())
})?;

let controller = T::GaugeRewardIssuer::get().into_sub_account_truncating(pid);
T::BbBNC::set_incentive(pid, Some(max_block), Some(controller));
PoolInfos::<T>::insert(gid, &gauge_pool_info);
Ok(())
}

Expand Down Expand Up @@ -252,15 +250,4 @@ where
};
Ok(result_vec)
}

pub fn update_reward(who: &AccountIdOf<T>, pid: PoolId) -> Result<(), DispatchError> {
let pool_info = PoolInfos::<T>::get(pid).ok_or(Error::<T>::PoolDoesNotExist)?;
let share_info =
SharesAndWithdrawnRewards::<T>::get(pid, who).ok_or(Error::<T>::ShareInfoNotExists)?;
if T::BbBNC::balance_of(who, None)? == BalanceOf::<T>::zero() {
return Ok(());
}
T::BbBNC::update_reward(pid, Some(who), Some((share_info.share, pool_info.total_shares)))?;
Ok(())
}
}
Loading