After a cursory glance, is it me or is floating point being used? I thought this was something you wanted to avoid because of precision errors.
ie 0.2 * 0.1
ie 0.2 * 0.1
parseFloat((0.2 * 0.1).toFixed(10))
Shameless plug: use https://www.npmjs.com/package/bigint-money