MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ComputeCDPInterest

Function ComputeCDPInterest

src/tx/cdptx.cpp:124–139  ·  view source on GitHub ↗

* Interest Ratio Formula: ( a / Log10(b + N) ) * * ==> ratio = a / Log10 (b+N) */

Source from the content-addressed store, hash-verified

122 * ==> ratio = a / Log10 (b+N)
123 */
124uint64_t ComputeCDPInterest(const uint64_t total_owed_scoins, const int32_t beginHeight, const uint32_t endHeight,
125 uint64_t A, uint64_t B) {
126
127 int32_t blockInterval = endHeight - beginHeight;
128 int32_t loanedDays = std::max<int32_t>(1, ceil((double)blockInterval / SysCfg().GetOneDayBlocks(endHeight)));
129
130 uint64_t N = total_owed_scoins;
131 double annualInterestRate = 0.1 * A / log10(1.0 + B * N / (double)COIN);
132 uint64_t interest = (uint64_t)(((double)N / 365) * loanedDays * annualInterestRate);
133
134 LogPrint(BCLog::CDP, "beginHeight=%d, endHeight=%d, loanedDays=%d, A=%llu, B=%llu, N="
135 "%llu, annualInterestRate=%f, interest=%llu\n",
136 beginHeight, endHeight, loanedDays, A, B, N, annualInterestRate, interest);
137
138 return interest;
139}
140
141/**
142 * Interest Ratio Formula: ( a / Log10(b + N) )

Callers 1

ExecuteTxMethod · 0.70

Calls 4

GetOneDayBlocksMethod · 0.80
DoSMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected