Skip to content

Commit 1b6da69

Browse files
committed
added math
1 parent 5f069f9 commit 1b6da69

File tree

5 files changed

+181
-51
lines changed

5 files changed

+181
-51
lines changed

components/StakingCapBar.tsx

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,70 @@
1-
import React, { useState } from "react";
1+
import React from "react";
22

3-
const StakingCapBar = () => {
4-
const [maxRewardRate, setMaxRewardRate] = useState(10);
3+
interface StakingCapBarProps {
4+
totalLength?: number;
5+
height?: number;
6+
barColor?: string;
7+
secondBarColor?: string;
8+
backgroundColor?: string;
9+
fillPercentage: number;
10+
secondFillPercentage: number;
11+
}
512

6-
const barWidth = 300;
7-
const barHeight = 30;
13+
export default function StakingCapBar({
14+
totalLength = 300,
15+
height = 80,
16+
barColor = "bg-blue-500",
17+
secondBarColor = "bg-green-500",
18+
backgroundColor = "bg-gray-200",
19+
fillPercentage,
20+
secondFillPercentage,
21+
}: StakingCapBarProps) {
22+
// Ensure fillPercentages are between 0 and 100
23+
const clampedFillPercentage = Math.min(100, Math.max(0, fillPercentage));
24+
const clampedSecondFillPercentage = Math.min(
25+
100 - clampedFillPercentage,
26+
Math.max(0, secondFillPercentage)
27+
);
828

929
return (
10-
<div className="flex flex-col items-start p-4 max-w-md">
11-
<h2 className="text-xl font-bold mb-2">Example:</h2>
12-
<div className="mb-4 w-full">
13-
<label
14-
htmlFor="rewardRateSlider"
15-
className="block text-sm font-medium text-gray-700 mb-1"
16-
>
17-
Max Reward Rate: {maxRewardRate}%
18-
</label>
19-
<input
20-
type="range"
21-
id="rewardRateSlider"
22-
min="0"
23-
max="100"
24-
value={maxRewardRate}
25-
onChange={(e) => setMaxRewardRate(Number(e.target.value))}
26-
className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer"
27-
/>
28-
</div>
29-
<div className="relative w-full h-8 bg-gray-200 rounded">
30+
<div className="flex flex-col items-center space-y-6 p-6 bg-gray-100 rounded-lg">
31+
<h2 className="text-2xl font-bold">Staking Cap Bar</h2>
32+
<div
33+
className="w-full max-w-sm bg-white p-4 rounded-lg shadow-inner"
34+
style={{ width: `${totalLength}px` }}
35+
>
3036
<div
31-
className="absolute top-0 left-0 h-full bg-blue-500 rounded"
32-
style={{ width: `${maxRewardRate}%` }}
33-
></div>
34-
<div className="absolute top-0 left-0 w-full h-full flex items-center justify-between px-2">
35-
<span className="text-sm font-semibold">0%</span>
36-
<span className="text-sm font-semibold">100%</span>
37+
className={`${backgroundColor} rounded overflow-hidden border border-gray-300`}
38+
style={{ height: `${height}px` }}
39+
role="progressbar"
40+
aria-valuenow={clampedFillPercentage + clampedSecondFillPercentage}
41+
aria-valuemin={0}
42+
aria-valuemax={100}
43+
>
44+
<div className="flex h-full">
45+
<div
46+
className={`${barColor} h-full transition-all duration-300 ease-in-out`}
47+
style={{ width: `${clampedFillPercentage}%` }}
48+
></div>
49+
<div
50+
className={`${secondBarColor} h-full transition-all duration-300 ease-in-out`}
51+
style={{ width: `${clampedSecondFillPercentage}%` }}
52+
></div>
53+
</div>
3754
</div>
3855
</div>
39-
<p className="mt-2 text-sm text-gray-600">
40-
Max Reward Rate = {maxRewardRate}%
41-
</p>
56+
<div className="text-center">
57+
<p className="text-lg font-semibold text-gray-700">
58+
First Fill: {clampedFillPercentage}%
59+
</p>
60+
<p className="text-lg font-semibold text-gray-700">
61+
Second Fill: {clampedSecondFillPercentage}%
62+
</p>
63+
<p className="text-lg font-semibold text-gray-700">
64+
Total Fill: {clampedFillPercentage + clampedSecondFillPercentage}%
65+
</p>
66+
<p className="text-sm text-gray-600">Total Length: {totalLength}px</p>
67+
</div>
4268
</div>
4369
);
44-
};
45-
46-
export default StakingCapBar;
70+
}

pages/home/pyth-token/oracle-integrity-staking.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document outlines the design principles and implementation details of the O
44

55
## Design Principles
66

7-
OIS's economic design focuses on awarding and penalizing Stakers over the primary dimension of data accuracy.
7+
OIS's economic design focuses on awarding and penalizing Stakers over the primary dimension of data accuracy.
88
Stakers receive rewards from an open-ended pool for helping to ensure data quality. They will also have their stake slashed as a penalty for failing to maintain data accuracy.
99

1010
The core design principles behind OIS include the following:
@@ -19,17 +19,17 @@ The core design principles behind OIS include the following:
1919

2020
## Implementation
2121

22-
OIS implements the principle above through the following structure:
22+
OIS implements the principle above through the following structure:
2323

2424
1. OIS is subject to the same 7-day epoch as Governance voting. All parameters used in the OIS protocol are captured at each start of the epoch on Thursdays at 0:00 UTC and remain constant until the end of the epoch. Staking into OIS is also subject to warmup and cooldown period prior and post epoch respectively.
2525

2626
2. Each publisher is programmatically assigned a staking pool where they can self-stake and to which other stakers can delegate
27-
- The staking pool assigned to each publisher covers all price feeds/symbols they publish.
28-
- Each staking pool has a soft cap. This soft cap dynamically expands and shrinks given the number of symbols published by the assigned publisher.
29-
- Price feeds with a low number of publishers contribute less to the cap's expansion.
30-
- Staking into the pool can exceed the soft cap. However no rewards are paid nor penalties are levied on the excess amount.
31-
- The OIS protocol prioritizes self-stake attributed to the **publisher's stake** when distributing rewards to the publisher's pool.
32-
- All staking pools charge the same delegation fee for stakers who are delating stake to one or many pools.
27+
- The staking pool assigned to each publisher covers all price feeds/symbols they publish.
28+
- Each staking pool has a soft cap. This soft cap dynamically expands and shrinks given the number of symbols published by the assigned publisher.
29+
- Price feeds with a low number of publishers contribute less to the cap's expansion.
30+
- Staking into the pool can exceed the soft cap. However no rewards are paid nor penalties are levied on the excess amount.
31+
- The OIS protocol prioritizes self-stake attributed to the **publisher's stake** when distributing rewards to the publisher's pool.
32+
- All staking pools charge the same delegation fee for stakers who are delating stake to one or many pools.
3333
3. Each pool has a maximum reward rate per epoch, which applies only to the staked amount within the soft cap.
3434
4. The total amount of rewards paid to all pools is bound by the same cap relative to the amount of rewards available to the OIS protocol.
35-
5. Slashing of stake has a hard cap and only impacts pools that assigned to publishers responsible for the poor data quality. Both self-stakers and delegators are also slashed proportionally to their staked amount in the impacted pools.
35+
5. Slashing of stake has a hard cap and only impacts pools that assigned to publishers responsible for the poor data quality. Both self-stakers and delegators are also slashed proportionally to their staked amount in the impacted pools.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"mathematical-representation": "Mathematical Representation",
3+
"examples": "Examples"
4+
}

pages/home/pyth-token/oracle-integrity-staking/examples.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import StakingCapBar from '@/components/StakingCapBar'
1+
import StakingCapBar from "@/components/StakingCapBar";
22

33
# Examples(WIP)
44

5+
<StakingCapBar fillPercentage={50} secondFillPercentage={20} />
56

67
### Example 1:Only Publisher State
78

@@ -25,9 +26,6 @@ $$
2526
\text{Total Amount eligible for Reward} \quad{R_a} = min({S}_p, {C}_p) = min(500, 100) = 100
2627
$$
2728

28-
29-
30-
3129
$$
3230
\text{Reward Rate} \quad{r} = 10\%
3331
$$
@@ -42,4 +40,4 @@ $$
4240

4341
$$
4442
\text{Delegator Reward} \quad{R^d_p} = {R_p} - {R^p_p} = 10 - 10 = 0
45-
$$
43+
$$
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Mathematical Representation
2+
3+
This section outlines the mathematical representation of the Oracle Integrity Staking (OIS) protocol.
4+
5+
As explained in the [implementation](./implementation.mdx) section, every publisher is assigned a staking pool where they can self-stake and to which other stakers can delegate.
6+
7+
## Pool Cap
8+
9+
The **pool cap** is calculated as follows:
10+
11+
12+
$$
13+
\large{\text{Pool Cap}: {\bold{C_p}} = M \cdot \sum_{s \in \text{Symbols\_p}} \frac{1}{\max(n_s, Z)}}
14+
$$
15+
16+
Where:
17+
18+
- $M$ is a constant parameter representing the target stake per symbol.
19+
- $\text{Symbols\_p}$ is the number of symbols published by the publisher $p$.
20+
- $n_s$ is the number of elements in Symbols_p , or $n_s$ = $|\text{Symbols\_p}|$
21+
- $Z$ is a constant parameter to control cap contribution from symbols with a low number of publishers.
22+
23+
This formula actually ensures that symbols with a lower number of publishers contribute more to the overall cap, while symbols with a higher number of publishers contribute less. This is because the contribution of each symbol is inversely proportional to the number of publishers (or Z, whichever is larger).
24+
25+
26+
## Reward
27+
28+
The reward $R_p$ paid to each pool is calculated as follows:
29+
30+
$$
31+
\large{R_p = y \cdot \min(S_p, C_p)}
32+
$$
33+
34+
Where:
35+
36+
- $y$ is the cap to the rate of rewards for any pool.
37+
- $S_p$ be the stake assigned to the publisher p pool , made of self-staked amount $S^{p}_{p}$ and delegated stake $S^{d}_{p}$ , or $S_{p} = S^{p}_{p} + S^{d}_{p}$.
38+
- $C_p$ be the stake cap for the pool assigned to publisher p.
39+
40+
The reward is capped at the pool cap, $C_p$, to ensure that publishers and delegators are not over-rewarded. (I don't this this is necessary to mention, but it is a good sanity check)
41+
42+
43+
The total amount of rewards paid to all pools is bound the the same cap relative to the amount of rewards available to the OIS protocol.
44+
45+
$$
46+
\large{\sum_{p \in \text{Publishers}} R_p \leq y \cdot \min(NumSymbols \cdot M, \sum_{p=1}^{P} S_p)}
47+
$$
48+
49+
Where:
50+
51+
- $NumSymbols$ is the total number of symbols in the system.
52+
- $P$ is the total number of publishers in the system.
53+
54+
55+
Whereas the reward component relative to the amount self-staked by the publisher $p$ is defined as:
56+
57+
$$
58+
\large{R^{p}_{p} = y \cdot \min(S^p_p, C_p) = R_p - R^d_p}
59+
$$
60+
61+
Where:
62+
63+
- $R^d_p$ is the reward component relative to the amount delegated to the publisher $p$.
64+
65+
66+
## Slashing
67+
68+
Slashing is an important aspect of the OIS protocol to ensure the integrity of the system.
69+
70+
The slashed amount for each pool is calculated as follows:
71+
72+
$$
73+
\large{SL_p = z \cdot S_p = z \cdot (S^{p}_{p} + S^{d}_{p})}
74+
$$
75+
76+
Where:
77+
78+
- $SL_p$ is the slashed amount for the publisher $p$ pool.
79+
- $z$ is the slashing rate.
80+
- $S_p$ is the stake assigned to the publisher $p$ pool , made of self-staked amount $S^{p}_{p}$ and delegated stake $S^{d}_{p}$ , or $S_{p} = S^{p}_{p} + S^{d}_{p}$.
81+
82+
Here $SL_p$ is uniformly allocated to both the self-staking publisher and delegators in the pool, pro-rata to their respective stake.
83+
84+
85+
86+
87+
Subsequently, the rewards received by a publisher and delegators into a pool, net of any slashed amounts can be expressed as below:
88+
89+
$$
90+
\large{\Pi^p_p = ( R^p_p + f \cdot R^d_p ) - z \cdot S^p_p}
91+
$$
92+
93+
$$
94+
\large{\Pi^d_p = R^d_p - ( f \cdot R^d_p + z \cdot S^d_p )}
95+
$$
96+
97+
Where:
98+
99+
- $\Pi^p_p$ is the net reward received by the publisher $p$ after slashing.
100+
- $\Pi^d_p$ is the net reward received by the delegator $p$ after slashing.
101+
- $f$ is the delegation fee charged by the publisher.
102+
- $z$ is the slashing rate.
103+
- $S^p_p$ is the amount self-staked by the publisher $p$.
104+
- $S^d_p$ is the amount delegated to the publisher $p$.

0 commit comments

Comments
 (0)