]> Git Repo - VerusCoin.git/blob - src/komodo_interest.h
test
[VerusCoin.git] / src / komodo_interest.h
1 /******************************************************************************
2  * Copyright © 2014-2017 The SuperNET Developers.                             *
3  *                                                                            *
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.  *
7  *                                                                            *
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 *
11  *                                                                            *
12  * Removal or modification of this copyright notice is prohibited.            *
13  *                                                                            *
14  ******************************************************************************/
15
16 #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN))   // 5%
17 int64_t MAX_MONEY = 200000000 * 100000000LL;
18
19 uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest)
20 {
21     static uint64_t *interests; static int32_t maxheight;
22     uint64_t total; int32_t ind,incr = 100000;
23     if ( height >= maxheight )
24     {
25         if ( interests == 0 )
26         {
27             maxheight = height + incr;
28             interests = (uint64_t *)calloc(maxheight,sizeof(*interests) * 2);
29         }
30         else
31         {
32             interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2);
33             memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2);
34             maxheight += incr;
35         }
36     }
37     ind = (height << 1);
38     if ( paidinterest < 0 ) // request
39         return(interests[ind]);
40     else
41     {
42         if ( interests[ind + 1] != paidinterest )
43         {
44             interests[ind + 1] = paidinterest;
45             if ( height == 0 )
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++)
50             {
51                 ind = (height << 1);
52                 interests[ind] = total;
53                 interests[ind + 1] = 0;
54             }
55         }
56     }
57     return(0);
58 }
59
60 uint64_t komodo_moneysupply(int32_t height)
61 {
62     if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 )
63         return(0);
64     else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1));
65 }
66
67 uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
68 {
69     int32_t minutes,exception; uint64_t numerator,denominator,interest = 0;
70     if ( ASSETCHAINS_SYMBOL[0] != 0 )
71         return(0);
72     if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN )
73     {
74         if ( (minutes= (tiptime - nLockTime) / 60) >= 60 )
75         {
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 )
80             {
81                 exception = 0;
82                 if ( txheight <= 155949 )
83                 {
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) )
96                         exception = 1;
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);
99                 }
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 )
103                 {
104                     numerator = (nValue / 20); // assumes 5%!
105                     interest = (numerator / denominator);
106                 }
107                 else
108                 {
109                     numerator = (nValue * KOMODO_INTEREST);
110                     interest = (numerator / denominator) / COIN;
111                 }
112             }
113             else
114             {
115                 numerator = (nValue * KOMODO_INTEREST);
116                 interest = (numerator / denominator) / COIN;
117             }
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);
119         }
120     }
121     return(interest);
122 }
123
This page took 0.030032 seconds and 4 git commands to generate.