Skip to content

Commit 82f7113

Browse files
authored
feat: lower discount level thresholds (#638)
1 parent c5ddc2a commit 82f7113

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 8. Lower discount level threshold
2+
3+
Date: 2023-03-10
4+
5+
## Status
6+
7+
Accepted
8+
9+
## Context
10+
11+
See [here](https://github.com/threefoldtech/tfchain/issues/637) for more details.
12+
13+
## Decision
14+
15+
We decided to lower the discount level thresholds by reduzing them by half.
16+
In consequence, a grid user get faster access to a better discount level
17+
18+
Before:
19+
20+
| discount level | pricing discount | nr months staking |
21+
| -------------- | -----------------| ----------------- |
22+
| none | - 0% | 0 month |
23+
| default | - 20% | 3 months |
24+
| bronze | - 30% | 6 months |
25+
| silver | - 40% | 12 months |
26+
| gold | - 60% | 36 months |
27+
28+
Now:
29+
30+
| discount level | pricing discount | nr months staking |
31+
| -------------- | -----------------| ----------------- |
32+
| none | - 0% | 0 month |
33+
| default | - 20% | 1.5 months |
34+
| bronze | - 30% | 3 months |
35+
| silver | - 40% | 6 months |
36+
| gold | - 60% | 18 months |

substrate-node/pallets/pallet-smart-contract/src/cost.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ pub fn calculate_discount<T: Config>(
258258
let discount_level = U64F64::from_num(balance_as_u128) / U64F64::from_num(amount_due_monthly);
259259

260260
// predefined discount levels
261-
// https://wiki.threefold.io/#/threefold__grid_pricing
262-
let discount_received = match discount_level.floor().to_num::<u64>() {
263-
d if d >= 3 && d < 6 => types::DiscountLevel::Default,
264-
d if d >= 6 && d < 12 => types::DiscountLevel::Bronze,
265-
d if d >= 12 && d < 36 => types::DiscountLevel::Silver,
266-
d if d >= 36 => types::DiscountLevel::Gold,
261+
// https://library.threefold.me/info/manual/#/threefold__pricing?id=discount-levels
262+
let discount_received = match discount_level {
263+
d if d >= 1.5 && d < 3 => types::DiscountLevel::Default,
264+
d if d >= 3 && d < 6 => types::DiscountLevel::Bronze,
265+
d if d >= 6 && d < 18 => types::DiscountLevel::Silver,
266+
d if d >= 18 => types::DiscountLevel::Gold,
267267
_ => types::DiscountLevel::None,
268268
};
269269

substrate-node/pallets/pallet-smart-contract/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,12 +3233,12 @@ macro_rules! test_calculate_discount {
32333233
let amount_due = 1000;
32343234
let seconds_elapsed = SECS_PER_HOUR; // amount due is relative to 1h
32353235
// Give just enough balance for targeted number of months at the rate of 1000 per hour
3236-
let balance = (amount_due * 24 * 30) * number_of_months;
3236+
let balance = U64F64::from_num(amount_due * 24 * 30) * U64F64::from_num(number_of_months);
32373237

32383238
let result = cost::calculate_discount::<TestRuntime>(
32393239
amount_due,
32403240
seconds_elapsed,
3241-
balance,
3241+
balance.to_num::<u64>(),
32423242
NodeCertification::Diy,
32433243
);
32443244

@@ -3259,10 +3259,10 @@ macro_rules! test_calculate_discount {
32593259
// Confirm expected discount level given a number of month of balance autonomy
32603260
test_calculate_discount! {
32613261
test_calculate_discount_none_works: (1, types::DiscountLevel::None),
3262-
test_calculate_discount_default_works: (3, types::DiscountLevel::Default),
3263-
test_calculate_discount_bronze_works: (6, types::DiscountLevel::Bronze),
3264-
test_calculate_discount_silver_works: (12, types::DiscountLevel::Silver),
3265-
test_calculate_gold_discount_gold_works: (36, types::DiscountLevel::Gold),
3262+
test_calculate_discount_default_works: (1.5, types::DiscountLevel::Default),
3263+
test_calculate_discount_bronze_works: (3, types::DiscountLevel::Bronze),
3264+
test_calculate_discount_silver_works: (6, types::DiscountLevel::Silver),
3265+
test_calculate_gold_discount_gold_works: (18, types::DiscountLevel::Gold),
32663266
}
32673267

32683268
// ***** HELPER FUNCTIONS ***** //

0 commit comments

Comments
 (0)