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 all commits
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
2 changes: 2 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ impl pallet_assets::Config for Runtime {
}

parameter_types! {
pub IgnoredIssuance: Balance = Treasury::pot();
pub const QueueCount: u32 = 300;
pub const MaxQueueLen: u32 = 1000;
pub const FifoQueueLen: u32 = 500;
Expand All @@ -1061,6 +1062,7 @@ impl pallet_gilt::Config for Runtime {
type AdminOrigin = frame_system::EnsureRoot<AccountId>;
type Deficit = ();
type Surplus = ();
type IgnoredIssuance = IgnoredIssuance;
type QueueCount = QueueCount;
type MaxQueueLen = MaxQueueLen;
type FifoQueueLen = FifoQueueLen;
Expand Down
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
5 changes: 4 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, Currency},
};
use sp_core::H256;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
Expand Down Expand Up @@ -86,6 +87,7 @@ impl pallet_balances::Config for Test {
}

parameter_types! {
pub IgnoredIssuance: u64 = Balances::total_balance(&0); // Account zero is ignored.
pub const QueueCount: u32 = 3;
pub const MaxQueueLen: u32 = 3;
pub const FifoQueueLen: u32 = 1;
Expand All @@ -104,6 +106,7 @@ impl pallet_gilt::Config for Test {
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