Skip to content

Instantly share code, notes, and snippets.

View 2075's full-sized avatar

2075

View GitHub Profile
@2075
2075 / 1.43.0
Created January 15, 2022 08:17
{
"Address": "MultiAddress",
"LookupSource": "MultiAddress",
"AccountInfo": "AccountInfoWithDualRefCount",
"AccountInfoWithDualRefCount": {
"nonce": "Index",
"consumers": "RefCount",
"providers": "RefCount",
"data": "AccountData"
},
@2075
2075 / substrate-fixed-arithmetic.md
Last active March 2, 2022 14:15
Substrate and Fixed Point Arithmetic

Collection of reference material to do fixed point arithmetic on substrate based chains.

overview

How can I do math on floating point values in substrate runtime. As a simple example imagine I want to keep track of an interest rate in a decentralized finance application. I can prototype by using the percentage as an integer:

  let rate = 2;
  let dividend = capital * rate / 100;

But what if my interest rate is 2.5% or 2.4554%?