sora-xor / sora2-network

SORA is a new economic system aimed at creating a supranational, world economic system with built-in tools for decentralized finance (DeFi). The SORA network implements a new way of parachain architecture on Polkadot and Kusama network, with the capability to bridge external blockchains (like Ethereum) to the Polkadot ecosystem.
Other
51 stars 23 forks source link

[Tech]: Change the format of stabilityFeeRate to simple percent #1077

Open ra9mls opened 3 months ago

ra9mls commented 3 months ago

Problem statement

We need to operate with numbers in ms per year, APR 1% in milliseconds is 0.000000000000315303 APR 2% in milliseconds is 0.000000000000627498 APR 5% in milliseconds is 0.000000000001546096 APR 10% in milliseconds is 0.000000000003020250 APR 15% in milliseconds is 0.000000000004428901 APR 20% in milliseconds is 0.000000000005777600

It's hard to manage in future

Description

No response

Definition of Done

stabilityFeeRate sets like simple numbers in percents

Requirements

No response

Alexey-N-Chernyshov commented 3 months ago
  1. Improve accuracy for internal usage by changing from milliseconds to seconds.
  2. Extrinsic should have human-readable format in per-year. This format should be stored on-chain for front-end
  3. Test it.
  4. Migration.

Note: additional configuration via extrinsic updateCollateralInfo required since current format may be not so "human-readable".

Alexey-N-Chernyshov commented 3 months ago

Rate per second can be calculated by rate_seconds = (1 + rate_annual)^(1/seconds_per_year) - 1. The problem with this formula in computation of n-th root, where n is a number of seconds in year, it is a large number. Substrate pallets are built without rust std which doesn't allow usage of std math functions. Thus, there is no tool to provide desired functionality in substrate. Implementing such a tool requires additional types that support needed precision, because u128 is not enough. Overall, implementation of the feature requires inadequately large effort and gives very little benefits. What we can do is to improve precision by changing milliseconds to seconds in computations, it is implemented in PR #1088

ra9mls commented 3 months ago

"We should have discussed this point deeper during the analysis phase of the MVP" - @Tieumsan cc @Alexey-N-Chernyshov

ra9mls commented 3 months ago

Not needed to implement it now.