SACRED Technical Private Doc
  • What is Sacred?
    • Introduction to Sacred
    • Repos and Video Walkthrough
    • How to Use Sacred
    • Sacred Pools (Boxes)
    • Anonymity Set
    • User journey - from Deposit to Withdrawal
      • 1. Receive Note
      • 2. Deposit Tokens
      • 3. Earn While Waiting
        • Shares-of-Staked Seconds
        • Interest earning interest
        • Share Tracking Quirks
      • 4. Withdraw
      • 5. Redeem Claim - Receive Principal
        • Sacred Automated Market Maker
      • 6. Redeem Yield
      • 7. Redeem Incognito Credits
      • Using a Relayer to withdraw the principal, IC and yield
    • Sacred Rules to keep your deposit private
    • Circuits Summary
    • Links to individual Contracts
Powered by GitBook
On this page
  1. What is Sacred?
  2. User journey - from Deposit to Withdrawal
  3. 3. Earn While Waiting

Interest earning interest

PreviousShares-of-Staked SecondsNextShare Tracking Quirks

Last updated 2 years ago

When a user withdraws their deposit, there is a time delay until they can claim the interest earned on their deposit. During that time delay the portion of their interest is earning interest. However the system does not track this time. We also don’t know how much interest that user has accumulated at the time of withdrawal. Unlike the deposit amounts which are of a fixed denomination, the interest amounts vary by user. Leaking the time delay between the withdrawal and interest claim has privacy consequences.

Conclusion: The amount of interest earned on users’ unclaimed interest will be added to the total amount of interest and distributed to all users according to their share of the interest. The process is summarized below.

Note: interest from all Sacred Pools are managed as one, as this simplifies the tracking logic.

Code Summary - Share tracking mechanism

The share tracker is a structure containing the following (public) information:

  • Total shares currently

  • Number of active deposits

  • Last updated

Every time a deposit, withdrawal or interest claim happens, the Share Tracker’s values are updated. When a User claims their share of Interest, we calculate the ratio of their deposit’s Share in the Sacred Pool to the Total Shares which the Tracker holds.

Each time a deposit happens:

  • calculate # of blocks since last

  • update and multiply by # of current depositors

  • update Total Share value update the # of current depositors by 1.

Each time a withdraw happens:

  • Calculate # of blocks since last update and multiply by # of current depositors

  • Update Total Share value

  • Update the # of current depositors by -1.

Each time a claim happens:

  • Calculate # of blocks since last update and multiply by # of current depositors

  • Update Total Share value

  • Withdraw # of blocks that the claim spent in the protocol from tracker value

When a claim happens and the # of blocks that the claim spent in the protocol information is known, but it is not linked to the withdrawal or deposit of that claim. This is the same information that is known during IC claim.