Skip to content

Commit 48270d1

Browse files
committed
wip-added examples
1 parent 1b6da69 commit 48270d1

File tree

3 files changed

+145
-74
lines changed

3 files changed

+145
-74
lines changed

components/StakingCapBar.tsx

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,62 @@
1-
import React from "react";
1+
import React from "react"
22

33
interface StakingCapBarProps {
4-
totalLength?: number;
5-
height?: number;
6-
barColor?: string;
7-
secondBarColor?: string;
8-
backgroundColor?: string;
9-
fillPercentage: number;
10-
secondFillPercentage: number;
4+
totalLength?: number
5+
height?: number
6+
fillPercentage: number
7+
secondFillPercentage: number
8+
labelText?: string
119
}
1210

1311
export default function StakingCapBar({
1412
totalLength = 300,
1513
height = 80,
16-
barColor = "bg-blue-500",
17-
secondBarColor = "bg-green-500",
18-
backgroundColor = "bg-gray-200",
1914
fillPercentage,
2015
secondFillPercentage,
16+
labelText
2117
}: StakingCapBarProps) {
2218
// 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-
);
19+
const clampedFillPercentage = Math.min(100, Math.max(0, fillPercentage))
20+
const clampedSecondFillPercentage = Math.min(100 - clampedFillPercentage, Math.max(0, secondFillPercentage))
21+
const totalFillPercentage = clampedFillPercentage + clampedSecondFillPercentage
2822

2923
return (
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` }}
24+
<div className="flex flex-col items-start">
25+
<div
26+
className="rounded overflow-hidden"
27+
style={{
28+
width: `${totalLength}px`,
29+
height: `${height}px`,
30+
border: '2px solid #7142CF',
31+
backgroundColor: '#FFFFFF'
32+
}}
33+
role="progressbar"
34+
aria-valuenow={totalFillPercentage}
35+
aria-valuemin={0}
36+
aria-valuemax={100}
3537
>
36-
<div
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>
38+
<div className="flex h-full">
39+
<div
40+
className="h-full transition-all duration-300 ease-in-out"
41+
style={{
42+
width: `${clampedFillPercentage}%`,
43+
backgroundColor: '#7142CF'
44+
}}
45+
></div>
46+
<div
47+
className="h-full transition-all duration-300 ease-in-out"
48+
style={{
49+
width: `${clampedSecondFillPercentage}%`,
50+
backgroundColor: '#E6DAFE'
51+
}}
52+
></div>
5453
</div>
5554
</div>
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>
55+
{labelText && (
56+
<div className="mt-2 text-sm font-medium text-gray-700">
57+
{labelText}: {totalFillPercentage}%
58+
</div>
59+
)}
6860
</div>
69-
);
70-
}
61+
)
62+
}
Lines changed: 99 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,122 @@
11
import StakingCapBar from "@/components/StakingCapBar";
22

3-
# Examples(WIP)
3+
# Examples
44

5-
<StakingCapBar fillPercentage={50} secondFillPercentage={20} />
5+
This reference page provides examples of various scenarios to illustrate the Mathematical Representations of OIS.
66

7-
### Example 1:Only Publisher State
7+
NOTE: All the symbols used in the examples are explained in the [Mathematical Representation](/home/pyth-token/oracle-integrity-staking/mathematical-representation) section.
88

9-
$$
10-
\text{Publisher's Stake} \quad{S^p_p} = 100
11-
$$
9+
## Example 1: Only Publisher Stake
1210

13-
$$
14-
\text{Delegator Stake} \quad{S^d_p} = 0
15-
$$
11+
This example take the case where only the publisher has staked PYTH tokens.
1612

1713
$$
18-
\text{Total Stake} \quad{S_p} = {S^p_p} + {S^d_p} = 100
19-
$$
14+
\begin{aligned}
15+
{S^p_p} &= 100 \\
16+
{S^d_p} &= 0 \\
17+
{S^p} &= {S^p_p} + {S^d_p} = 100 + 0 = 100 \\
18+
{C}_p &= 500 \\
19+
\text{Total Amount eligible for Reward} \quad{R_p} &= min({S}_p, {C}_p) = min(500, 100) = 100 \\
20+
\text{Reward Rate} \quad{r} &= 10\% \\
2021
21-
$$
22-
\text{Pool Cap} \quad{C}_p = 500
22+
\text{Total Reward} \quad{R_p} &= {r} \times {E_p} = 10\% \times 100 = 10 \\
23+
\text{Publisher Reward} \quad{R^p_p} &= {r} \times min({S^p_p}, {C}_p) = 10\% \times 100 = 10 \\
24+
\text{Delegator Reward} \quad{R^d_p} &= {R_p} - {R^p_p} = 10 - 10 = 0 \\
25+
\end{aligned}
2326
$$
2427

25-
$$
26-
\text{Total Amount eligible for Reward} \quad{R_a} = min({S}_p, {C}_p) = min(500, 100) = 100
27-
$$
28+
29+
# Example 2: Publisher and Delegator Stake
30+
31+
This example take the case where both the publisher and the delegator have staked PYTH tokens.
2832

2933
$$
30-
\text{Reward Rate} \quad{r} = 10\%
34+
\begin{aligned}
35+
{S^p_p} &= 100 \\
36+
{S^d_p} &= 100 \\
37+
{S^p} &= {S^p_p} + {S^d_p} = 100 + 100 = 200 \\
38+
{C}_p &= 500 \\
39+
\text{Total Amount eligible for Reward} \quad{R_p} &= min({S}_p, {C}_p) = min(500, 200) = 200 \\
40+
\text{Reward Rate} \quad{r} &= 10\% \\
41+
\text{Total Reward} \quad{R_p} &= {r} \times {E_p} = 10\% \times 200 = 20 \\
42+
\text{Publisher Reward} \quad{R^p_p} &= {r} \times min({S^p_p}, {C}_p) = 10\% \times 100 = 10 \\
43+
\text{Delegator Reward} \quad{R^d_p} &= {R_p} - {R^p_p} = 20 - 10 = 10 \\
44+
\end{aligned}
3145
$$
3246

47+
# Example 3: Publisher and Delegator Stake more than the Cap
48+
49+
This example take the case where the combined stake of both the publisher and the delegator is more than the cap.
50+
3351
$$
34-
\text{Total Reward} \quad{R_p} = {r} \times {E_p} = 10\% \times 100 = 10
52+
\begin{aligned}
53+
{S^p_p} &= 300 \\
54+
{S^d_p} &= 300 \\
55+
{S^p} &= {S^p_p} + {S^d_p} = 300 + 300 = 600 \\
56+
{C}_p &= 500 \\
57+
\text{Total Amount eligible for Reward} \quad{R_p} &= min({S}_p, {C}_p) = min(500, 600) = 500 \\
58+
\text{Reward Rate} \quad{r} &= 10\% \\
59+
\text{Total Reward} \quad{R_p} &= {r} \times {E_p} = 10\% \times 500 = 50 \\
60+
\text{Publisher Reward} \quad{R^p_p} &= {r} \times min({S^p_p}, {C}_p) = 10\% \times 300 = 30 \\
61+
\text{Delegator Reward} \quad{R^d_p} &= {R_p} - {R^p_p} = 50 - 30 = 20 \\
62+
\end{aligned}
3563
$$
3664

65+
66+
# Example 4: Introducing Delegator Fees
67+
68+
This example demonstrates how delegator fees affect the reward distribution between publishers and delegators.
69+
3770
$$
38-
\text{Publisher Reward} \quad{R^p_p} = {r} \times min({S^p_p}, {C}_p) = 10\% \times 100 = 10
71+
\begin{aligned}
72+
\quad{S^p_p} &= 200 \\
73+
\quad{S^d_p} &= 300 \\
74+
\quad{S^p} &= {S^p_p} + {S^d_p} = 200 + 300 = 500 \\
75+
\quad{C}_p &= 500 \\
76+
\quad{R_p} &= min({S}_p, {C}_p) = min(500, 500) = 500 \\
77+
\quad{r} &= 10\% \\
78+
\quad{f} &= 2\% \\
79+
80+
\quad{R_p} &= {r} \times {R_p} = 10\% \times 500 = 50 \\
81+
\quad{R^p_p} &= {r} \times min({S^p_p}, {C}_p) = 10\% \times 200 = 20 \\
82+
\quad{R^d_p} &= {R_p} - {R^p_p} = 50 - 20 = 30 \\
83+
\text{Fee paid by Delegator} \quad{F^d_p} &= {f} \times {R^d_p} = 2\% \times 30 = 0.6 \\
84+
\text{Final Delegator Reward} \quad{R^d_p} &= {R^d_p} - {F^d_p} = 30 - 0.6 = 29.4 \\
85+
\text{Total Publisher Reward} \quad{R^p_p} &= {R^p_p} + {F^d_p} = 20 + 0.6 = 20.6 \\
86+
\end{aligned}
3987
$$
4088

89+
In this example, the delegator pays a 2% fee on their rewards to the publisher. This fee is deducted from the delegator's reward and added to the publisher's reward.
90+
91+
92+
# Example 5: Slashing event on the pool
93+
94+
This example demonstrates the impact of a slashing event on the staked PYTH tokens.
95+
4196
$$
42-
\text{Delegator Reward} \quad{R^d_p} = {R_p} - {R^p_p} = 10 - 10 = 0
97+
\begin{aligned}
98+
\quad{S^p_p} &= 200 \\
99+
\quad{S^d_p} &= 300 \\
100+
\quad{S^p} &= {S^p_p} + {S^d_p} = 200 + 300 = 500 \\
101+
\quad{C}_p &= 500 \\
102+
\quad{R_p} &= min({S}_p, {C}_p) = min(500, 500) = 500 \\
103+
\quad{r} &= 10\% \\
104+
\quad{f} &= 2\% \\
105+
106+
\quad{R_p} &= {r} \times {R_p} = 10\% \times 500 = 50 \\
107+
\quad{R^p_p} &= {r} \times min({S^p_p}, {C}_p) = 10\% \times 200 = 20 \\
108+
\quad{R^d_p} &= {R_p} - {R^p_p} = 50 - 20 = 30 \\
109+
\text{Fee paid by Delegator} \quad{F^d_p} &= {f} \times {R^d_p} = 2\% \times 30 = 0.6 \\
110+
111+
\text{Slashed percentage}\quad{z} &= 50\% \\
112+
\text{Final Delegator Reward} \quad{\Pi^d_p} &= ( R^p_p + f \cdot R^d_p ) - z \cdot S^p_p = (20 + 0.6) - 0.5 \cdot 200 = 20.6 - 100 = -79.4 \\
113+
\text{Total Publisher Reward} \quad{\Pi^p_p} &= {R^p_p} + {F^d_p} = 20 + 0.6 = 20.6 \\
114+
\end{aligned}
43115
$$
116+
117+
In this example, the publisher's stake is slashed by 50%. This means that the publisher's stake is reduced to 100 and the delegator's stake remains the same.
118+
119+
120+
121+
{/* <StakingCapBar fillPercentage={50} secondFillPercentage={20} labelText="100" /> */}
122+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ $$
9797
Where:
9898

9999
- $\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.
100+
- $\Pi^d_p$ is the net reward received by the delegators after slashing.
101101
- $f$ is the delegation fee charged by the publisher.
102102
- $z$ is the slashing rate.
103103
- $S^p_p$ is the amount self-staked by the publisher $p$.

0 commit comments

Comments
 (0)