@orderly.network/trading-points 1.0.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # Rewards Calculation Module
2
+
3
+ This module provides functionality for calculating estimated rewards and estimated tickets earned.
4
+
5
+ ## Features
6
+
7
+ ### 1. Estimated Rewards
8
+
9
+ - Supports multiple prize pool configurations
10
+ - Supports different metrics based on trading volume and PnL (Profit and Loss)
11
+ - Supports fixed position rewards and position range rewards
12
+ - Automatically estimates user ranking and calculates corresponding rewards
13
+
14
+ ### 2. Estimated Tickets
15
+
16
+ - Supports tiered mode: Awards different ticket amounts based on different trading volume tiers
17
+ - Supports linear mode: Earn Y tickets for every X trading volume
18
+
19
+ ## Type Definitions
20
+
21
+ ### Prize Pool Configuration
22
+
23
+ ```typescript
24
+ interface PrizePool {
25
+ pool_id: string; // Prize pool ID
26
+ label: string; // Prize pool label
27
+ total_prize: number; // Total prize amount
28
+ currency: string; // Reward currency
29
+ metric: "volume" | "pnl"; // Evaluation metric
30
+ tiers: PrizePoolTier[]; // Tier configuration
31
+ }
32
+ ```
33
+
34
+ ### Ticket Rules
35
+
36
+ ```typescript
37
+ interface TicketRules {
38
+ total_prize: number; // Total ticket prize amount
39
+ currency: string; // Currency
40
+ metric: "volume" | "pnl"; // Evaluation metric
41
+ mode: "tiered" | "linear"; // Mode
42
+ tiers?: TicketTierRule[]; // Tiered mode configuration
43
+ linear?: TicketLinearRule; // Linear mode configuration
44
+ }
45
+ ```
46
+
47
+ ## Usage Examples
48
+
49
+ ### Basic Usage
50
+
51
+ ```typescript
52
+ import {
53
+ calculateEstimatedRewards,
54
+ calculateEstimatedTickets,
55
+ CampaignConfig,
56
+ UserData,
57
+ } from "./utils";
58
+
59
+ const userdata: UserData = {
60
+ account_id: "user_001",
61
+ trading_volume: 50000,
62
+ pnl: 1500,
63
+ current_rank: 5,
64
+ total_participants: 1000,
65
+ };
66
+
67
+ const campaign: CampaignConfig = {
68
+ // ... campaign configuration
69
+ };
70
+
71
+ // Calculate estimated rewards
72
+ const rewards = calculateEstimatedRewards(userdata, campaign);
73
+ console.log(`Estimated rewards: ${rewards?.amount} ${rewards?.currency}`);
74
+
75
+ // Calculate estimated tickets
76
+ if (campaign.ticket_rules) {
77
+ const tickets = calculateEstimatedTickets(userdata, campaign.ticket_rules);
78
+ console.log(`Estimated tickets: ${tickets}`);
79
+ }
80
+ ```
81
+
82
+ ### Usage in React Components
83
+
84
+ ```typescript
85
+ import { RewardsDesktopUI } from './rewards.desktop.ui';
86
+
87
+ function MyComponent() {
88
+ return (
89
+ <RewardsDesktopUI
90
+ campaign={campaignConfig}
91
+ userdata={userData}
92
+ />
93
+ );
94
+ }
95
+ ```
96
+
97
+ ## Configuration Examples
98
+
99
+ ### Tiered Mode Ticket Configuration
100
+
101
+ ```typescript
102
+ ticket_rules: {
103
+ total_prize: 2000,
104
+ currency: "WIF",
105
+ metric: "volume",
106
+ mode: "tiered",
107
+ tiers: [
108
+ { value: 25000, tickets: 10 }, // ≥ 25,000 volume → 10 tickets
109
+ { value: 10000, tickets: 5 }, // ≥ 10,000 volume → 5 tickets
110
+ { value: 5000, tickets: 1 } // ≥ 5,000 volume → 1 ticket
111
+ ]
112
+ }
113
+ ```
114
+
115
+ ### Linear Mode Ticket Configuration
116
+
117
+ ```typescript
118
+ ticket_rules: {
119
+ total_prize: 1000,
120
+ currency: "WIF",
121
+ metric: "volume",
122
+ mode: "linear",
123
+ linear: {
124
+ every: 5000, // Every 5000 trading volume
125
+ tickets: 1 // Earn 1 ticket
126
+ }
127
+ }
128
+ ```
129
+
130
+ ### Prize Pool Configuration Example
131
+
132
+ ```typescript
133
+ prize_pools: [
134
+ {
135
+ pool_id: "general",
136
+ label: "General Pool",
137
+ total_prize: 10000,
138
+ currency: "USDC",
139
+ metric: "volume",
140
+ tiers: [
141
+ { position: 1, amount: 3000 }, // 1st place: 3000 USDC
142
+ { position: 2, amount: 2000 }, // 2nd place: 2000 USDC
143
+ { position: 3, amount: 1000 }, // 3rd place: 1000 USDC
144
+ { position_range: [4, 10], amount: 500 }, // 4th-10th place: 500 USDC each
145
+ { position_range: [11, 50], amount: 100 }, // 11th-50th place: 100 USDC each
146
+ ],
147
+ },
148
+ ];
149
+ ```
150
+
151
+ ## Calculation Logic
152
+
153
+ ### Ranking Estimation
154
+
155
+ The system estimates user ranking based on trading performance:
156
+
157
+ - If `current_rank` is provided, it is used directly
158
+ - Otherwise, a simple estimation is made based on trading volume/PnL:
159
+ - ≥ 100,000: Rank 1
160
+ - ≥ 50,000: Top 5%
161
+ - ≥ 10,000: Top 20%
162
+ - ≥ 1,000: Top 50%
163
+ - < 1,000: Bottom 80%
164
+
165
+ ### Reward Calculation
166
+
167
+ 1. Iterate through all prize pools
168
+ 2. Get user data based on the pool's metric (volume/pnl)
169
+ 3. Estimate user ranking for that metric
170
+ 4. Find matching tier and accumulate rewards
171
+
172
+ ### Ticket Calculation
173
+
174
+ - **Tiered Mode**: Find the highest tier that matches the user's trading volume
175
+ - **Linear Mode**: Calculate proportionally using `Math.floor(volume / every) * tickets`
176
+
177
+ ## Important Notes
178
+
179
+ 1. Ranking estimation is based on simplified logic; it's recommended to use real leaderboard data in actual applications
180
+ 2. When user trading volume or PnL is 0 or negative, some calculations may return empty results
181
+ 3. It's recommended to integrate real API data sources in production environments
@@ -0,0 +1,14 @@
1
+ import { FC } from 'react';
2
+
3
+ type RouteOption = {
4
+ href: string;
5
+ name: string;
6
+ scope?: string;
7
+ target?: string;
8
+ };
9
+ type PointSystemPageProps = {
10
+ onRouteChange: (option: RouteOption) => void;
11
+ };
12
+ declare const PointSystemPage: FC<PointSystemPageProps>;
13
+
14
+ export { PointSystemPage, type PointSystemPageProps, type RouteOption };
@@ -0,0 +1,14 @@
1
+ import { FC } from 'react';
2
+
3
+ type RouteOption = {
4
+ href: string;
5
+ name: string;
6
+ scope?: string;
7
+ target?: string;
8
+ };
9
+ type PointSystemPageProps = {
10
+ onRouteChange: (option: RouteOption) => void;
11
+ };
12
+ declare const PointSystemPage: FC<PointSystemPageProps>;
13
+
14
+ export { PointSystemPage, type PointSystemPageProps, type RouteOption };