1 /******************************************************************************
2 * Copyright © 2014-2017 The SuperNET Developers. *
4 * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
5 * the top-level directory of this distribution for the individual copyright *
6 * holder information and the developer policies on copyright and licensing. *
8 * Unless otherwise agreed in a custom licensing agreement, no part of the *
9 * SuperNET software, including this file may be copied, modified, propagated *
10 * or distributed except according to the terms contained in the LICENSE file *
12 * Removal or modification of this copyright notice is prohibited. *
14 ******************************************************************************/
16 #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5%
17 int64_t MAX_MONEY = 200000000 * 100000000LL;
19 uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest)
21 static uint64_t *interests; static int32_t maxheight;
22 uint64_t total; int32_t ind,incr = 100000;
23 if ( height >= maxheight )
27 maxheight = height + incr;
28 interests = (uint64_t *)calloc(maxheight,sizeof(*interests) * 2);
32 interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2);
33 memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2);
38 if ( paidinterest < 0 ) // request
39 return(interests[ind]);
42 if ( interests[ind + 1] != paidinterest )
44 interests[ind + 1] = paidinterest;
46 interests[ind] = interests[ind + 1];
47 else interests[ind] = interests[ind - 2] + interests[ind + 1];
48 total = interests[ind];
49 for (++height; height<maxheight; height++)
52 interests[ind] = total;
53 interests[ind + 1] = 0;
60 uint64_t komodo_moneysupply(int32_t height)
62 if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 )
64 else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1));
67 uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
69 int32_t minutes,exception; uint64_t numerator,denominator,interest = 0;
70 if ( ASSETCHAINS_SYMBOL[0] != 0 )
72 if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN )
74 if ( (minutes= (tiptime - nLockTime) / 60) >= 60 )
76 denominator = (((uint64_t)365 * 24 * 60) / minutes);
77 if ( denominator == 0 )
78 denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually!
79 if ( nValue > 25000LL*COIN )
82 if ( txheight <= 155949 )
84 if ( (txheight == 116607 && nValue == 2502721100000LL) ||
85 (txheight == 126891 && nValue == 2879650000000LL) ||
86 (txheight == 129510 && nValue == 3000000000000LL) ||
87 (txheight == 141549 && nValue == 3500000000000LL) ||
88 (txheight == 154473 && nValue == 3983399350000LL) ||
89 (txheight == 154736 && nValue == 3983406748175LL) ||
90 (txheight == 155013 && nValue == 3983414006565LL) ||
91 (txheight == 155492 && nValue == 3983427592291LL) ||
92 (txheight == 155613 && nValue == 9997409999999797LL) ||
93 (txheight == 157927 && nValue == 9997410667451072LL) ||
94 (txheight == 155613 && nValue == 2590000000000LL) ||
95 (txheight == 155949 && nValue == 4000000000000LL) )
97 if ( exception == 0 || nValue == 4000000000000LL )
98 printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime);
100 //if ( nValue == 4000000000000LL )
101 // printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime);
102 if ( exception == 0 )
104 numerator = (nValue / 20); // assumes 5%!
105 interest = (numerator / denominator);
109 numerator = (nValue * KOMODO_INTEREST);
110 interest = (numerator / denominator) / COIN;
115 numerator = (nValue * KOMODO_INTEREST);
116 interest = (numerator / denominator) / COIN;
118 //fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator);