Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
14 changes: 10 additions & 4 deletions frame/gilt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ pub mod pallet {
/// over freezing period).
type Surplus: OnUnbalanced<NegativeImbalanceOf<Self>>;

/// The issuance to ignore. This is subtracted from the `Currency`'s `total_issuance` to get
/// the issuance by which we inflate or deflate the gilt.
type IgnoredIssuance: Get<BalanceOf<Self>>;

/// Number of duration queues in total. This sets the maximum duration supported, which is
/// this value multiplied by `Period`.
#[pallet::constant]
Expand Down Expand Up @@ -191,7 +195,9 @@ pub mod pallet {
/// The way of determining the net issuance (i.e. after factoring in all maturing frozen funds)
/// is:
///
/// `total_issuance - frozen + proportion * total_issuance`
/// `issuance - frozen + proportion * issuance`
///
/// where `issuance = total_issuance - IgnoredIssuance`
#[derive(Clone, Eq, PartialEq, Default, Encode, Decode, RuntimeDebug)]
pub struct ActiveGiltsTotal<Balance> {
/// The total amount of funds held in reserve for all active gilts.
Expand Down Expand Up @@ -440,7 +446,7 @@ pub mod pallet {
Active::<T>::remove(index);

// Multiply the proportion it is by the total issued.
let total_issuance = T::Currency::total_issuance();
let total_issuance = T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
ActiveTotal::<T>::mutate(|totals| {
let nongilt_issuance: u128 = total_issuance.saturating_sub(totals.frozen)
.saturated_into();
Expand Down Expand Up @@ -490,7 +496,7 @@ pub mod pallet {
if totals.proportion < totals.target {
let missing = totals.target.saturating_sub(totals.proportion);

let total_issuance = T::Currency::total_issuance();
let total_issuance = T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
let nongilt_issuance: u128 = total_issuance.saturating_sub(totals.frozen)
.saturated_into();
let effective_issuance = totals.proportion.left_from_one()
Expand All @@ -515,7 +521,7 @@ pub mod pallet {
amount: BalanceOf<T>,
max_bids: u32,
) -> (u32, u32) {
let total_issuance = T::Currency::total_issuance();
let total_issuance = T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
let mut remaining = amount;
let mut bids_taken = 0;
let mut queues_hit = 0;
Expand Down
12 changes: 11 additions & 1 deletion frame/gilt/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
use crate as pallet_gilt;

use frame_support::{
parameter_types, ord_parameter_types, traits::{OnInitialize, OnFinalize, GenesisBuild},
parameter_types, ord_parameter_types,
traits::{OnInitialize, OnFinalize, GenesisBuild, Get, Currency},
};
use sp_core::H256;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
Expand Down Expand Up @@ -98,12 +99,21 @@ ord_parameter_types! {
pub const One: u64 = 1;
}

pub struct IgnoredIssuance;
impl Get<u64> for IgnoredIssuance {
fn get() -> u64 {
// Account zero is ignored.
Balances::total_balance(&0)
}
}

impl pallet_gilt::Config for Test {
type Event = Event;
type Currency = Balances;
type AdminOrigin = frame_system::EnsureSignedBy<One, Self::AccountId>;
type Deficit = ();
type Surplus = ();
type IgnoredIssuance = IgnoredIssuance;
type QueueCount = QueueCount;
type MaxQueueLen = MaxQueueLen;
type FifoQueueLen = FifoQueueLen;
Expand Down
24 changes: 24 additions & 0 deletions frame/gilt/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,30 @@ fn thaw_when_issuance_higher_works() {
});
}

#[test]
fn thaw_with_ignored_issuance_works() {
new_test_ext().execute_with(|| {
run_to_block(1);
// Give account zero some balance.
Balances::make_free_balance_be(&0, 200);

assert_ok!(Gilt::place_bid(Origin::signed(1), 100, 1));
Gilt::enlarge(100, 1);

// Account zero transfers 50 into everyone else's accounts.
assert_ok!(Balances::transfer(Origin::signed(0), 2, 50));
assert_ok!(Balances::transfer(Origin::signed(0), 3, 50));
assert_ok!(Balances::transfer(Origin::signed(0), 4, 50));

run_to_block(4);
assert_ok!(Gilt::thaw(Origin::signed(1), 0));

// Account zero changes have been ignored.
assert_eq!(Balances::free_balance(1), 150);
assert_eq!(Balances::reserved_balance(1), 0);
});
}

#[test]
fn thaw_when_issuance_lower_works() {
new_test_ext().execute_with(|| {
Expand Down