]>
Commit | Line | Data |
---|---|---|
d019c447 | 1 | /****************************************************************************** |
37fed603 | 2 | * Copyright © 2014-2017 The SuperNET Developers. * |
d019c447 | 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 | ******************************************************************************/ | |
b927fb35 | 15 | |
d019c447 | 16 | #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% |
6ef202b2 | 17 | |
0fec0cc4 | 18 | uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) |
17878015 | 19 | { |
20 | static uint64_t *interests; static int32_t maxheight; | |
fa0d10cc | 21 | uint64_t total; int32_t ind,incr = 100000; |
17878015 | 22 | if ( height >= maxheight ) |
23 | { | |
9b570fb1 | 24 | if ( interests == 0 ) |
25 | { | |
fa0d10cc | 26 | maxheight = height + incr; |
27 | interests = (uint64_t *)calloc(maxheight,sizeof(*interests) * 2); | |
9b570fb1 | 28 | } |
29 | else | |
30 | { | |
31 | interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2); | |
32 | memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2); | |
33 | maxheight += incr; | |
34 | } | |
17878015 | 35 | } |
36 | ind = (height << 1); | |
37 | if ( paidinterest < 0 ) // request | |
38 | return(interests[ind]); | |
39 | else | |
40 | { | |
41 | if ( interests[ind + 1] != paidinterest ) | |
42 | { | |
43 | interests[ind + 1] = paidinterest; | |
44 | if ( height == 0 ) | |
45 | interests[ind] = interests[ind + 1]; | |
46 | else interests[ind] = interests[ind - 2] + interests[ind + 1]; | |
47 | total = interests[ind]; | |
48 | for (++height; height<maxheight; height++) | |
49 | { | |
50 | ind = (height << 1); | |
51 | interests[ind] = total; | |
52 | interests[ind + 1] = 0; | |
53 | } | |
54 | } | |
55 | } | |
88593976 | 56 | return(0); |
17878015 | 57 | } |
58 | ||
59 | uint64_t komodo_moneysupply(int32_t height) | |
60 | { | |
0fec0cc4 | 61 | if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 ) |
17878015 | 62 | return(0); |
0fec0cc4 | 63 | else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1)); |
17878015 | 64 | } |
65 | ||
66 | uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) | |
6ef202b2 | 67 | { |
59d42bc8 | 68 | int32_t minutes,exception; uint64_t numerator,denominator,interest = 0; |
c75c18fc | 69 | if ( ASSETCHAINS_SYMBOL[0] != 0 ) |
70 | return(0); | |
98f68225 | 71 | if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) |
6ef202b2 | 72 | { |
075d0c06 | 73 | if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) |
586e33b1 | 74 | { |
586e33b1 | 75 | denominator = (((uint64_t)365 * 24 * 60) / minutes); |
76 | if ( denominator == 0 ) | |
77 | denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually! | |
d4a420a3 | 78 | if ( nValue > 25000LL*COIN ) |
4fbe3249 | 79 | { |
59d42bc8 | 80 | exception = 0; |
cd586654 | 81 | if ( txheight <= 155949 ) |
d4a420a3 | 82 | { |
cd586654 | 83 | if ( (txheight == 116607 && nValue == 2502721100000LL) || |
ef0d9630 | 84 | (txheight == 126891 && nValue == 2879650000000LL) || |
85 | (txheight == 129510 && nValue == 3000000000000LL) || | |
86 | (txheight == 141549 && nValue == 3500000000000LL) || | |
87 | (txheight == 154473 && nValue == 3983399350000LL) || | |
88 | (txheight == 154736 && nValue == 3983406748175LL) || | |
89 | (txheight == 155013 && nValue == 3983414006565LL) || | |
90 | (txheight == 155492 && nValue == 3983427592291LL) || | |
91 | (txheight == 155613 && nValue == 9997409999999797LL) || | |
92 | (txheight == 157927 && nValue == 9997410667451072LL) || | |
c8c894b6 | 93 | (txheight == 155613 && nValue == 2590000000000LL) || |
ef0d9630 | 94 | (txheight == 155949 && nValue == 4000000000000LL) ) |
cd586654 | 95 | exception = 1; |
fec202b5 | 96 | if ( exception == 0 || nValue == 4000000000000LL ) |
c8c894b6 | 97 | printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime); |
d4a420a3 | 98 | } |
c4df506a | 99 | if ( nValue == 4000000000000LL ) |
100 | printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime); | |
d4a420a3 | 101 | if ( exception == 0 ) |
102 | { | |
103 | numerator = (nValue / 20); // assumes 5%! | |
104 | interest = (numerator / denominator); | |
105 | } | |
106 | else | |
107 | { | |
108 | numerator = (nValue * KOMODO_INTEREST); | |
109 | interest = (numerator / denominator) / COIN; | |
110 | } | |
4fbe3249 | 111 | } |
112 | else | |
113 | { | |
114 | numerator = (nValue * KOMODO_INTEREST); | |
115 | interest = (numerator / denominator) / COIN; | |
116 | } | |
f7c9df28 | 117 | //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); |
8fa5e1ff | 118 | } |
6ef202b2 | 119 | } |
fdbf481f | 120 | return(interest); |
6ef202b2 | 121 | } |
50760585 | 122 |