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

Function calc_apy

plugins/bkpr/channelsapy.c:238–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238WARN_UNUSED_RESULT static bool calc_apy(struct amount_msat earned,
239 struct amount_msat capital,
240 u32 blocks_elapsed,
241 double *result)
242{
243 double apy;
244
245 assert(!amount_msat_is_zero(capital));
246 assert(blocks_elapsed > 0);
247
248 apy = amount_msat_ratio(earned, capital) * BLOCK_YEAR / blocks_elapsed;
249
250 /* convert to percent */
251 apy *= 100;
252
253 /* If mantissa is < 64 bits, a naive "if (scaled >
254 * UINT64_MAX)" doesn't work. Stick to powers of 2. */
255 if (apy >= (double)((u64)1 << 63) * 2)
256 return false;
257
258 *result = apy;
259 return true;
260}
261
262void json_add_channel_apy(struct json_stream *res,
263 const struct channel_apy *apy)

Callers 1

json_add_channel_apyFunction · 0.85

Calls 2

amount_msat_is_zeroFunction · 0.85
amount_msat_ratioFunction · 0.85

Tested by

no test coverage detected