| 286 | } |
| 287 | |
| 288 | void json_add_channel_apy(struct json_stream *res, |
| 289 | const struct channel_apy *apy) |
| 290 | { |
| 291 | bool ok; |
| 292 | u32 blocks_elapsed; |
| 293 | double apy_result, utilization; |
| 294 | struct amount_msat total_fees, their_start_bal; |
| 295 | |
| 296 | ok = amount_msat_sub(&their_start_bal, apy->total_start_bal, |
| 297 | apy->our_start_bal); |
| 298 | assert(ok); |
| 299 | |
| 300 | json_object_start(res, NULL); |
| 301 | |
| 302 | json_add_string(res, "account", apy->acct_name); |
| 303 | |
| 304 | json_add_amount_msat_only(res, "routed_out_msat", apy->routed_out); |
| 305 | json_add_amount_msat_only(res, "routed_in_msat", apy->routed_in); |
| 306 | json_add_amount_msat_only(res, "lease_fee_paid_msat", apy->lease_out); |
| 307 | json_add_amount_msat_only(res, "lease_fee_earned_msat", apy->lease_in); |
| 308 | json_add_amount_msat_only(res, "pushed_out_msat", apy->push_out); |
| 309 | json_add_amount_msat_only(res, "pushed_in_msat", apy->push_in); |
| 310 | |
| 311 | json_add_amount_msat_only(res, "our_start_balance_msat", apy->our_start_bal); |
| 312 | json_add_amount_msat_only(res, "channel_start_balance_msat", |
| 313 | apy->total_start_bal); |
| 314 | |
| 315 | ok = amount_msat_add(&total_fees, apy->fees_in, apy->fees_out); |
| 316 | assert(ok); |
| 317 | json_add_amount_msat_only(res, "fees_out_msat", apy->fees_out); |
| 318 | json_add_amount_msat_only(res, "fees_in_msat", apy->fees_in); |
| 319 | |
| 320 | /* utilization (out): routed_out/total_balance */ |
| 321 | assert(!amount_msat_zero(apy->total_start_bal)); |
| 322 | utilization = amount_msat_ratio(apy->routed_out, apy->total_start_bal); |
| 323 | json_add_string(res, "utilization_out", |
| 324 | tal_fmt(apy, "%.4f%%", utilization * 100)); |
| 325 | |
| 326 | if (!amount_msat_zero(apy->our_start_bal)) { |
| 327 | utilization = amount_msat_ratio(apy->routed_out, |
| 328 | apy->our_start_bal); |
| 329 | json_add_string(res, "utilization_out_initial", |
| 330 | tal_fmt(apy, "%.4f%%", utilization * 100)); |
| 331 | } |
| 332 | |
| 333 | /* utilization (in): routed_in/total_balance */ |
| 334 | utilization = amount_msat_ratio(apy->routed_in, apy->total_start_bal); |
| 335 | json_add_string(res, "utilization_in", |
| 336 | tal_fmt(apy, "%.4f%%", utilization * 100)); |
| 337 | |
| 338 | if (!amount_msat_zero(their_start_bal)) { |
| 339 | utilization = amount_msat_ratio(apy->routed_in, |
| 340 | their_start_bal); |
| 341 | json_add_string(res, "utilization_in_initial", |
| 342 | tal_fmt(apy, "%.4f%%", utilization * 100)); |
| 343 | } |
| 344 | |
| 345 | /* Can't divide by zero */ |
no test coverage detected