Skip to content

Commit

Permalink
Merge pull request #584 from DeckerSU/patch-kip-0001
Browse files Browse the repository at this point in the history
reduce AUR 5% -> 0.01% after nS7HardforkHeight
  • Loading branch information
ca333 authored May 30, 2023
2 parents e94c666 + 64efc07 commit ac466df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/deprecation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height.
// * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down.
static const int WEEKS_UNTIL_DEPRECATION = 52;
static const int DEPRECATION_HEIGHT = 3600000; //TODO: use [last_season_array_item - 1] + 650.000 for automagic update
static const int DEPRECATION_HEIGHT = 4320000; //TODO: use [last_season_array_item - 1] + 650.000 for automagic update
static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60);

// Number of blocks before deprecation to warn users
Expand Down
6 changes: 5 additions & 1 deletion src/komodo_interest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "komodo_interest.h"
#include "komodo_bitcoind.h"
#include "komodo_utils.h" // dstr()
#include "komodo_hardfork.h"

#define KOMODO_INTEREST ((uint64_t)5000000) //((uint64_t)(0.05 * COIN)) // 5%

Expand All @@ -30,7 +31,10 @@ uint64_t _komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime
if ( txheight >= 1000000 && minutes > 31 * 24 * 60 )
minutes = 31 * 24 * 60;
minutes -= ((KOMODO_MAXMEMPOOLTIME/60) - 1);
return (nValue / 10512000) * minutes;
uint64_t res = (nValue / 10512000) * minutes;
if (txheight >= nS7HardforkHeight)
res /= 500; // KIP-0001 implementation, reduce AUR from 5% to 0.01%
return res;
}
return 0;
}
Expand Down
16 changes: 12 additions & 4 deletions src/test-komodo/test_kmd_feat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "komodo_globals.h"
#include "komodo_interest.h"
#include "cc/CCinclude.h"
#include "komodo_hardfork.h"


CCriticalSection& get_cs_main(); // in main.cpp
Expand Down Expand Up @@ -252,6 +253,8 @@ TEST_F(KomodoFeatures, komodo_interest_validate) {
const CAmount interestCollectedBefore1M[] = {0, 5802, 4252378, 24663337, 49320871, 49994387};
/* komodo_interest_height = 3000000 */
const CAmount interestCollected[] = {0, 5795, 4235195, 4235195, 4235195, 4235195};
/* komodo_interest_height = 7113400 */
const CAmount interestCollectedAfterS7[] = {0, 5795 / 500, 4235195 / 500, 4235195 / 500, 4235195 / 500, 4235195 / 500};

/* check collected interest */

Expand All @@ -260,7 +263,7 @@ TEST_F(KomodoFeatures, komodo_interest_validate) {
assert(nMaxTipTimes == nMaxInterestCollected);

const int testHeights[] = {
247205 + 1, 333332, 3000000};
247205 + 1, 333332, 3000000, nS7HardforkHeight + 1};

CValidationState state;

Expand Down Expand Up @@ -320,9 +323,12 @@ TEST_F(KomodoFeatures, komodo_interest_validate) {
case 333332:
ASSERT_EQ(interest, interestCollectedBefore1M[idx]);
break;
default:
case 3000000:
ASSERT_EQ(interest, interestCollected[idx]);
break;
default:
ASSERT_EQ(interest, interestCollectedAfterS7[idx]);
break;
}

delete pLastBlockIndex;
Expand All @@ -339,8 +345,9 @@ TEST_F(KomodoFeatures, komodo_interestnew) {
// time lower than cut off month time limit
EXPECT_EQ(komodo_interestnew(1000000, 10LL*COIN, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600 /*KOMODO_MAXMEMPOOLTIME*/), 10LL*COIN/10512000 * (31*24*60 - 59));

// since 7th season, according to KIP0001 AUR should be reduced from 5% to 0.01%, i.e. div by 500
EXPECT_EQ(komodo_interestnew(7777777-1, 10LL*COIN, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600), 10LL*COIN/10512000 * (31*24*60 - 59) / 500);
// end of interest era
EXPECT_EQ(komodo_interestnew(7777777-1, 10LL*COIN, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600), 10LL*COIN/10512000 * (31*24*60 - 59));
EXPECT_EQ(komodo_interestnew(7777777, 10LL*COIN, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600), 0LL);

// value less than limit
Expand Down Expand Up @@ -382,8 +389,9 @@ TEST_F(KomodoFeatures, komodo_interest) {
// time lower than cut off month time limit
EXPECT_EQ(komodo_interest(1000000, nValue, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600), nValue/10512000 * (31*24*60 - 59));

// since 7th season, according to KIP0001 AUR should be reduced from 5% to 0.01%, i.e. div by 500
EXPECT_EQ(komodo_interest(7777777-1, nValue, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600), nValue/10512000 * (31*24*60 - 59) / 500);
// end of interest era
EXPECT_EQ(komodo_interest(7777777-1, nValue, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600), nValue/10512000 * (31*24*60 - 59));
EXPECT_EQ(komodo_interest(7777777 /*KOMODO_ENDOFERA*/, nValue, 1663839248, 1663839248 + (31 * 24 * 60 - 1) * 60 + 3600), 0LL);

// tip less than nLockTime
Expand Down

0 comments on commit ac466df

Please sign in to comment.