]> Git Repo - VerusCoin.git/blame - src/komodo_interest.h
test
[VerusCoin.git] / src / komodo_interest.h
CommitLineData
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%
be7695c2 17int64_t MAX_MONEY = 200000000 * SATOSHIDEN;
6ef202b2 18
0fec0cc4 19uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest)
17878015 20{
21 static uint64_t *interests; static int32_t maxheight;
fa0d10cc 22 uint64_t total; int32_t ind,incr = 100000;
17878015 23 if ( height >= maxheight )
24 {
9b570fb1 25 if ( interests == 0 )
26 {
fa0d10cc 27 maxheight = height + incr;
28 interests = (uint64_t *)calloc(maxheight,sizeof(*interests) * 2);
9b570fb1 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 }
17878015 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 }
88593976 57 return(0);
17878015 58}
59
60uint64_t komodo_moneysupply(int32_t height)
61{
0fec0cc4 62 if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 )
17878015 63 return(0);
0fec0cc4 64 else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1));
17878015 65}
66
67uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
6ef202b2 68{
59d42bc8 69 int32_t minutes,exception; uint64_t numerator,denominator,interest = 0;
c75c18fc 70 if ( ASSETCHAINS_SYMBOL[0] != 0 )
71 return(0);
98f68225 72 if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN )
6ef202b2 73 {
075d0c06 74 if ( (minutes= (tiptime - nLockTime) / 60) >= 60 )
586e33b1 75 {
586e33b1 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!
d4a420a3 79 if ( nValue > 25000LL*COIN )
4fbe3249 80 {
59d42bc8 81 exception = 0;
cd586654 82 if ( txheight <= 155949 )
d4a420a3 83 {
cd586654 84 if ( (txheight == 116607 && nValue == 2502721100000LL) ||
ef0d9630 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) ||
c8c894b6 94 (txheight == 155613 && nValue == 2590000000000LL) ||
ef0d9630 95 (txheight == 155949 && nValue == 4000000000000LL) )
cd586654 96 exception = 1;
fec202b5 97 if ( exception == 0 || nValue == 4000000000000LL )
c8c894b6 98 printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime);
d4a420a3 99 }
68c266b2 100 //if ( nValue == 4000000000000LL )
101 // printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime);
d4a420a3 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 }
4fbe3249 112 }
113 else
114 {
115 numerator = (nValue * KOMODO_INTEREST);
116 interest = (numerator / denominator) / COIN;
117 }
f7c9df28 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);
8fa5e1ff 119 }
6ef202b2 120 }
fdbf481f 121 return(interest);
6ef202b2 122}
50760585 123
This page took 0.128551 seconds and 4 git commands to generate.