0.3.2 • Published 2 years ago

@rarible/lib-broken-line v0.3.2

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

BrokenLine

This library is inspired by curve.fi staking contract. It's a bit more generalized, added some new features and can be used independently of any staking logic.

It can be used to model linearly declining values.

Library solves this problem: we have some linear functions, which are specified using these params:

  • start - x coordinate where line starts
  • bias - y coordinate where line starts
  • slope - angle of slope of the line (multiplied by -1)
  • cliff - interval when y is constant

These lines end when y falls to zero. Here you can see example line:

Staking 2

Library allows to sum any amount of such lines and calculate value y without iterating over these lines. Only small amount of state changes are required to update broken line.

Functions implemented:

  • add - adds one more line to the broken line, lines should have unique ids
  • remove - removes line from the broken line
  • update - refreshes broken line up to current time - this operation can make many state changes but it can be done in some transactions

NOTE: update can only be done for future. It's impossible to get previous value of the broken line.

0.3.2

2 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago