MCPcopy Create free account
hub / github.com/ElementsProject/lightning / calc_apy

Function calc_apy

plugins/bkpr/channelsapy.c:264–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264WARN_UNUSED_RESULT static bool calc_apy(struct amount_msat earned,
265 struct amount_msat capital,
266 u32 blocks_elapsed,
267 double *result)
268{
269 double apy;
270
271 assert(!amount_msat_zero(capital));
272 assert(blocks_elapsed > 0);
273
274 apy = amount_msat_ratio(earned, capital) * BLOCK_YEAR / blocks_elapsed;
275
276 /* convert to percent */
277 apy *= 100;
278
279 /* If mantissa is < 64 bits, a naive "if (scaled >
280 * UINT64_MAX)" doesn't work. Stick to powers of 2. */
281 if (apy >= (double)((u64)1 << 63) * 2)
282 return false;
283
284 *result = apy;
285 return true;
286}
287
288void json_add_channel_apy(struct json_stream *res,
289 const struct channel_apy *apy)

Callers 1

json_add_channel_apyFunction · 0.85

Calls 2

amount_msat_zeroFunction · 0.85
amount_msat_ratioFunction · 0.85

Tested by

no test coverage detected