📲STX per stSTX Calculation
How the ratio of STX per stSTX is enforced in Clarity
Each cycle, the amount of STX backing a single stSTX token should go up, unless the amount of withdrawals have been greater than deposits (i.e. a net outflow). Nonetheless, each stacker using the protocol will get their pro-rata share of the yield each stacking cycle.
Let's take a look at the code that calculates the ratio:
(define-public (get-stx-per-ststx (reserve-trait <sticky-reserve-trait>))
(let (
(stx-amount (unwrap-panic (contract-call? reserve-trait get-total-stx)))
)
(try! (contract-call? .sticky-dao check-is-protocol (contract-of reserve-trait)))
(ok (get-stx-per-ststx-helper stx-amount))
)
)
(define-read-only (get-stx-per-ststx-helper (stx-amount uint))
(let (
(ststx-supply (unwrap-panic (contract-call? .ststx-token get-total-supply)))
)
(if (is-eq ststx-supply u0)
u1000000
(/ (* stx-amount u1000000) ststx-supply)
)
)
)
In the above calculation, we simply take the ratio of total deposits against PoX rewards that have been earned in STX.
Last updated