bancorprotocol / carbon-contracts

Carbon is a fully decentralized protocol for automating on-chain trading strategies.
https://carbondefi.xyz
Other
111 stars 40 forks source link

Increase the maximum permitted value of `timeElapsed / halfLife` from ~23 to 128 #139

Closed barakman closed 7 months ago

barakman commented 8 months ago

The calculation of 2 ^ x for a non-integer value of x is limited by x < 16 * ln(2), which is approximately 23.08.

The solution to this problem relies on the identity:

A ^ B.C = A ^ (B + 0.C) = A ^ B * A ^ 0.C

For example:

2 ^ 3.4 = 2 ^ (3 + 0.4) = 2 ^ 3 * 2 ^ 0.4

Calculating 2 ^ 3 is easy, and calculating 2 ^ 0.4 is also easy, because 0.4 is way below the limit (23.08).