keynesol-shared 1.0.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.
Files changed (154) hide show
  1. package/README.md +118 -0
  2. package/dist/components/Common/ErrorBoundary.d.ts +23 -0
  3. package/dist/components/Common/ErrorBoundary.d.ts.map +1 -0
  4. package/dist/components/Common/ErrorBoundary.js +93 -0
  5. package/dist/components/Common/ErrorBoundary.jsx +103 -0
  6. package/dist/components/Common/ErrorMessage.d.ts +8 -0
  7. package/dist/components/Common/ErrorMessage.d.ts.map +1 -0
  8. package/dist/components/Common/ErrorMessage.js +36 -0
  9. package/dist/components/Common/ErrorMessage.jsx +40 -0
  10. package/dist/components/Common/Loading.d.ts +8 -0
  11. package/dist/components/Common/Loading.d.ts.map +1 -0
  12. package/dist/components/Common/Loading.js +41 -0
  13. package/dist/components/Common/Loading.jsx +44 -0
  14. package/dist/components/Common/LoadingIndicator.d.ts +17 -0
  15. package/dist/components/Common/LoadingIndicator.d.ts.map +1 -0
  16. package/dist/components/Common/LoadingIndicator.js +95 -0
  17. package/dist/components/Common/LoadingIndicator.jsx +108 -0
  18. package/dist/components/Common/ProgramStatus.d.ts +3 -0
  19. package/dist/components/Common/ProgramStatus.d.ts.map +1 -0
  20. package/dist/components/Common/ProgramStatus.js +26 -0
  21. package/dist/components/Common/ProgramStatus.jsx +27 -0
  22. package/dist/components/Common/Skeleton.d.ts +39 -0
  23. package/dist/components/Common/Skeleton.d.ts.map +1 -0
  24. package/dist/components/Common/Skeleton.js +53 -0
  25. package/dist/components/Common/Skeleton.jsx +67 -0
  26. package/dist/components/Common/SkeletonScreen.d.ts +18 -0
  27. package/dist/components/Common/SkeletonScreen.d.ts.map +1 -0
  28. package/dist/components/Common/SkeletonScreen.js +98 -0
  29. package/dist/components/Common/SkeletonScreen.jsx +108 -0
  30. package/dist/components/Common/index.d.ts +11 -0
  31. package/dist/components/Common/index.d.ts.map +1 -0
  32. package/dist/components/Common/index.js +10 -0
  33. package/dist/components/Wallet/TransactionStatus.d.ts +11 -0
  34. package/dist/components/Wallet/TransactionStatus.d.ts.map +1 -0
  35. package/dist/components/Wallet/TransactionStatus.js +97 -0
  36. package/dist/components/Wallet/TransactionStatus.jsx +106 -0
  37. package/dist/components/Wallet/WalletBalance.d.ts +4 -0
  38. package/dist/components/Wallet/WalletBalance.d.ts.map +1 -0
  39. package/dist/components/Wallet/WalletBalance.js +82 -0
  40. package/dist/components/Wallet/WalletBalance.jsx +86 -0
  41. package/dist/components/Wallet/WalletButton.d.ts +3 -0
  42. package/dist/components/Wallet/WalletButton.d.ts.map +1 -0
  43. package/dist/components/Wallet/WalletButton.js +51 -0
  44. package/dist/components/Wallet/WalletButton.jsx +53 -0
  45. package/dist/components/Wallet/WalletConnectionModal.d.ts +8 -0
  46. package/dist/components/Wallet/WalletConnectionModal.d.ts.map +1 -0
  47. package/dist/components/Wallet/WalletConnectionModal.js +150 -0
  48. package/dist/components/Wallet/WalletConnectionModal.jsx +170 -0
  49. package/dist/components/Wallet/WalletProvider.d.ts +9 -0
  50. package/dist/components/Wallet/WalletProvider.d.ts.map +1 -0
  51. package/dist/components/Wallet/WalletProvider.js +70 -0
  52. package/dist/components/Wallet/WalletProvider.jsx +75 -0
  53. package/dist/components/Wallet/index.d.ts +9 -0
  54. package/dist/components/Wallet/index.d.ts.map +1 -0
  55. package/dist/components/Wallet/index.js +8 -0
  56. package/dist/components/index.d.ts +7 -0
  57. package/dist/components/index.d.ts.map +1 -0
  58. package/dist/components/index.js +6 -0
  59. package/dist/hooks/index.d.ts +10 -0
  60. package/dist/hooks/index.d.ts.map +1 -0
  61. package/dist/hooks/index.js +9 -0
  62. package/dist/hooks/useCache.d.ts +16 -0
  63. package/dist/hooks/useCache.d.ts.map +1 -0
  64. package/dist/hooks/useCache.js +67 -0
  65. package/dist/hooks/usePolling.d.ts +16 -0
  66. package/dist/hooks/usePolling.d.ts.map +1 -0
  67. package/dist/hooks/usePolling.js +79 -0
  68. package/dist/hooks/useProgram.d.ts +14 -0
  69. package/dist/hooks/useProgram.d.ts.map +1 -0
  70. package/dist/hooks/useProgram.js +88 -0
  71. package/dist/hooks/useTokenBalance.d.ts +16 -0
  72. package/dist/hooks/useTokenBalance.d.ts.map +1 -0
  73. package/dist/hooks/useTokenBalance.js +100 -0
  74. package/dist/hooks/useVaults.d.ts +23 -0
  75. package/dist/hooks/useVaults.d.ts.map +1 -0
  76. package/dist/hooks/useVaults.js +98 -0
  77. package/dist/index.d.ts +12 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +17 -0
  80. package/dist/services/index.d.ts +7 -0
  81. package/dist/services/index.d.ts.map +1 -0
  82. package/dist/services/index.js +6 -0
  83. package/dist/services/reconciliationService.d.ts +76 -0
  84. package/dist/services/reconciliationService.d.ts.map +1 -0
  85. package/dist/services/reconciliationService.js +216 -0
  86. package/dist/services/syncService.d.ts +51 -0
  87. package/dist/services/syncService.d.ts.map +1 -0
  88. package/dist/services/syncService.js +218 -0
  89. package/dist/types/index.d.ts +201 -0
  90. package/dist/types/index.d.ts.map +1 -0
  91. package/dist/types/index.js +1 -0
  92. package/dist/utils/cacheManager.d.ts +73 -0
  93. package/dist/utils/cacheManager.d.ts.map +1 -0
  94. package/dist/utils/cacheManager.js +232 -0
  95. package/dist/utils/errorHandler.d.ts +76 -0
  96. package/dist/utils/errorHandler.d.ts.map +1 -0
  97. package/dist/utils/errorHandler.js +267 -0
  98. package/dist/utils/index.d.ts +12 -0
  99. package/dist/utils/index.d.ts.map +1 -0
  100. package/dist/utils/index.js +11 -0
  101. package/dist/utils/performanceMonitor.d.ts +75 -0
  102. package/dist/utils/performanceMonitor.d.ts.map +1 -0
  103. package/dist/utils/performanceMonitor.js +197 -0
  104. package/dist/utils/rpcRetry.d.ts +12 -0
  105. package/dist/utils/rpcRetry.d.ts.map +1 -0
  106. package/dist/utils/rpcRetry.js +47 -0
  107. package/dist/utils/supabase.d.ts +198 -0
  108. package/dist/utils/supabase.d.ts.map +1 -0
  109. package/dist/utils/supabase.js +50 -0
  110. package/dist/utils/toastService.d.ts +52 -0
  111. package/dist/utils/toastService.d.ts.map +1 -0
  112. package/dist/utils/toastService.js +139 -0
  113. package/dist/utils/tokenUtils.d.ts +33 -0
  114. package/dist/utils/tokenUtils.d.ts.map +1 -0
  115. package/dist/utils/tokenUtils.js +66 -0
  116. package/dist/utils/validation.d.ts +35 -0
  117. package/dist/utils/validation.d.ts.map +1 -0
  118. package/dist/utils/validation.js +83 -0
  119. package/package.json +45 -0
  120. package/src/components/Common/ErrorBoundary.tsx +135 -0
  121. package/src/components/Common/ErrorMessage.tsx +52 -0
  122. package/src/components/Common/Loading.tsx +56 -0
  123. package/src/components/Common/LoadingIndicator.tsx +143 -0
  124. package/src/components/Common/ProgramStatus.tsx +37 -0
  125. package/src/components/Common/Skeleton.tsx +83 -0
  126. package/src/components/Common/SkeletonScreen.tsx +166 -0
  127. package/src/components/Common/index.ts +10 -0
  128. package/src/components/Wallet/TransactionStatus.tsx +138 -0
  129. package/src/components/Wallet/WalletBalance.tsx +94 -0
  130. package/src/components/Wallet/WalletButton.tsx +65 -0
  131. package/src/components/Wallet/WalletConnectionModal.tsx +193 -0
  132. package/src/components/Wallet/WalletProvider.tsx +104 -0
  133. package/src/components/Wallet/index.ts +8 -0
  134. package/src/components/index.ts +6 -0
  135. package/src/hooks/index.ts +10 -0
  136. package/src/hooks/useCache.ts +87 -0
  137. package/src/hooks/usePolling.ts +98 -0
  138. package/src/hooks/useProgram.ts +93 -0
  139. package/src/hooks/useTokenBalance.ts +113 -0
  140. package/src/hooks/useVaults.ts +122 -0
  141. package/src/index.ts +23 -0
  142. package/src/services/index.ts +6 -0
  143. package/src/services/reconciliationService.ts +246 -0
  144. package/src/services/syncService.ts +238 -0
  145. package/src/types/index.ts +233 -0
  146. package/src/utils/cacheManager.ts +286 -0
  147. package/src/utils/errorHandler.ts +336 -0
  148. package/src/utils/index.ts +12 -0
  149. package/src/utils/performanceMonitor.ts +222 -0
  150. package/src/utils/rpcRetry.ts +55 -0
  151. package/src/utils/supabase.ts +253 -0
  152. package/src/utils/toastService.ts +166 -0
  153. package/src/utils/tokenUtils.ts +75 -0
  154. package/src/utils/validation.ts +107 -0
@@ -0,0 +1,216 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getSupabaseClient, isSupabaseConfigured } from '../utils/supabase';
11
+ import { errorHandler } from '../utils/errorHandler';
12
+ import { cacheManager } from '../utils/cacheManager';
13
+ class ReconciliationService {
14
+ constructor() {
15
+ this.connection = null;
16
+ this.reconciliationInterval = null;
17
+ }
18
+ /**
19
+ * Initialize reconciliation service
20
+ */
21
+ initialize(connection, supabaseConfig) {
22
+ this.connection = connection;
23
+ this.supabaseConfig = supabaseConfig;
24
+ }
25
+ /**
26
+ * Start periodic reconciliation
27
+ */
28
+ startReconciliation(interval = 3600000) {
29
+ if (this.reconciliationInterval) {
30
+ return; // Already running
31
+ }
32
+ // Initial reconciliation
33
+ this.reconcileAll();
34
+ // Periodic reconciliation (default: 1 hour)
35
+ this.reconciliationInterval = setInterval(() => {
36
+ this.reconcileAll();
37
+ }, interval);
38
+ }
39
+ /**
40
+ * Stop reconciliation
41
+ */
42
+ stopReconciliation() {
43
+ if (this.reconciliationInterval) {
44
+ clearInterval(this.reconciliationInterval);
45
+ this.reconciliationInterval = null;
46
+ }
47
+ }
48
+ /**
49
+ * Reconcile all data types
50
+ */
51
+ reconcileAll() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ if (!isSupabaseConfigured(this.supabaseConfig) || !this.connection) {
54
+ return {
55
+ transactions: { missing: 0, inconsistent: 0, fixed: 0 },
56
+ rewards: { missing: 0, inconsistent: 0, fixed: 0 },
57
+ vaults: { missing: 0, inconsistent: 0, fixed: 0 },
58
+ };
59
+ }
60
+ try {
61
+ const [transactions, rewards, vaults] = yield Promise.all([
62
+ this.reconcileTransactions(),
63
+ this.reconcileRewards(),
64
+ this.reconcileVaults(),
65
+ ]);
66
+ return {
67
+ transactions,
68
+ rewards,
69
+ vaults,
70
+ };
71
+ }
72
+ catch (error) {
73
+ errorHandler.handleError(error, 'ReconciliationService');
74
+ throw error;
75
+ }
76
+ });
77
+ }
78
+ /**
79
+ * Reconcile transactions
80
+ */
81
+ reconcileTransactions() {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ var _a;
84
+ if (!isSupabaseConfigured(this.supabaseConfig) || !this.connection) {
85
+ return { missing: 0, inconsistent: 0, fixed: 0 };
86
+ }
87
+ try {
88
+ const supabase = getSupabaseClient(this.supabaseConfig);
89
+ // Get recent transactions from Supabase
90
+ const { data: supabaseTxs } = yield supabase
91
+ .from('transactions')
92
+ .select('signature, status, amount, vault_id')
93
+ .order('timestamp', { ascending: false })
94
+ .limit(100);
95
+ if (!supabaseTxs) {
96
+ return { missing: 0, inconsistent: 0, fixed: 0 };
97
+ }
98
+ let missing = 0;
99
+ let inconsistent = 0;
100
+ let fixed = 0;
101
+ // Verify each transaction on blockchain
102
+ const transactions = supabaseTxs;
103
+ for (const tx of transactions) {
104
+ try {
105
+ const blockchainTx = yield this.connection.getTransaction(tx.signature, {
106
+ maxSupportedTransactionVersion: 0,
107
+ });
108
+ if (!blockchainTx) {
109
+ // Transaction not found on blockchain - mark as failed
110
+ if (tx.status !== 'failed') {
111
+ const updateData = { status: 'failed' };
112
+ yield supabase
113
+ .from('transactions')
114
+ .update(updateData)
115
+ .eq('signature', tx.signature);
116
+ fixed++;
117
+ }
118
+ missing++;
119
+ }
120
+ else {
121
+ // Transaction found - verify status
122
+ const isConfirmed = ((_a = blockchainTx.meta) === null || _a === void 0 ? void 0 : _a.err) === null;
123
+ const expectedStatus = isConfirmed ? 'confirmed' : 'failed';
124
+ if (tx.status !== expectedStatus) {
125
+ const updateData = { status: expectedStatus };
126
+ yield supabase
127
+ .from('transactions')
128
+ .update(updateData)
129
+ .eq('signature', tx.signature);
130
+ fixed++;
131
+ inconsistent++;
132
+ }
133
+ }
134
+ }
135
+ catch (error) {
136
+ console.error(`Error reconciling transaction ${tx.signature}:`, error);
137
+ }
138
+ }
139
+ // Invalidate cache
140
+ cacheManager.invalidate('transactions');
141
+ return { missing, inconsistent, fixed };
142
+ }
143
+ catch (error) {
144
+ errorHandler.handleError(error, 'ReconciliationService.reconcileTransactions');
145
+ return { missing: 0, inconsistent: 0, fixed: 0 };
146
+ }
147
+ });
148
+ }
149
+ /**
150
+ * Reconcile rewards
151
+ */
152
+ reconcileRewards() {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ if (!isSupabaseConfigured(this.supabaseConfig) || !this.connection) {
155
+ return { missing: 0, inconsistent: 0, fixed: 0 };
156
+ }
157
+ try {
158
+ const supabase = getSupabaseClient(this.supabaseConfig);
159
+ // Get unclaimed rewards from Supabase
160
+ const { data: unclaimedRewards } = yield supabase
161
+ .from('rewards')
162
+ .select('*')
163
+ .eq('claimed', false)
164
+ .limit(100);
165
+ if (!unclaimedRewards) {
166
+ return { missing: 0, inconsistent: 0, fixed: 0 };
167
+ }
168
+ let missing = 0;
169
+ let inconsistent = 0;
170
+ let fixed = 0;
171
+ // Verify rewards on blockchain
172
+ // This would require checking reward distribution transactions
173
+ // For now, this is a placeholder
174
+ cacheManager.invalidate('rewards');
175
+ return { missing, inconsistent, fixed };
176
+ }
177
+ catch (error) {
178
+ errorHandler.handleError(error, 'ReconciliationService.reconcileRewards');
179
+ return { missing: 0, inconsistent: 0, fixed: 0 };
180
+ }
181
+ });
182
+ }
183
+ /**
184
+ * Reconcile vaults
185
+ */
186
+ reconcileVaults() {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ if (!isSupabaseConfigured(this.supabaseConfig) || !this.connection) {
189
+ return { missing: 0, inconsistent: 0, fixed: 0 };
190
+ }
191
+ try {
192
+ // Reconcile vault history with current vault state
193
+ // This would involve:
194
+ // 1. Fetching current vault state from blockchain
195
+ // 2. Comparing with latest vault_history entry
196
+ // 3. Creating new history entry if state changed
197
+ cacheManager.invalidate('vaultHistory');
198
+ return { missing: 0, inconsistent: 0, fixed: 0 };
199
+ }
200
+ catch (error) {
201
+ errorHandler.handleError(error, 'ReconciliationService.reconcileVaults');
202
+ return { missing: 0, inconsistent: 0, fixed: 0 };
203
+ }
204
+ });
205
+ }
206
+ /**
207
+ * Manual reconciliation trigger
208
+ */
209
+ manualReconcile() {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ return this.reconcileAll();
212
+ });
213
+ }
214
+ }
215
+ // Export singleton instance
216
+ export const reconciliationService = new ReconciliationService();
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Data Synchronization Service
3
+ * Synchronizes blockchain events to Supabase
4
+ * Requirements: 10.1, 10.2, 10.3, 10.4, 10.5
5
+ */
6
+ import { Connection } from '@solana/web3.js';
7
+ import { SupabaseConfig } from '../utils/supabase';
8
+ declare class SyncService {
9
+ private connection;
10
+ private syncInterval;
11
+ private config;
12
+ /**
13
+ * Initialize sync service
14
+ */
15
+ initialize(connection: Connection, supabaseConfig?: SupabaseConfig): void;
16
+ /**
17
+ * Start periodic synchronization
18
+ */
19
+ startSync(): void;
20
+ /**
21
+ * Stop synchronization
22
+ */
23
+ stopSync(): void;
24
+ /**
25
+ * Sync all data types
26
+ */
27
+ syncAll(): Promise<void>;
28
+ /**
29
+ * Sync transactions from blockchain to Supabase
30
+ */
31
+ syncTransactions(): Promise<void>;
32
+ /**
33
+ * Sync rewards from blockchain to Supabase
34
+ */
35
+ syncRewards(): Promise<void>;
36
+ /**
37
+ * Sync platform metrics
38
+ */
39
+ syncPlatformMetrics(): Promise<void>;
40
+ /**
41
+ * Sync vault history
42
+ */
43
+ syncVaultHistory(): Promise<void>;
44
+ /**
45
+ * Manually trigger sync for a specific transaction
46
+ */
47
+ syncTransaction(signature: string): Promise<void>;
48
+ }
49
+ export declare const syncService: SyncService;
50
+ export {};
51
+ //# sourceMappingURL=syncService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syncService.d.ts","sourceRoot":"","sources":["../../src/services/syncService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAA2C,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAW5F,cAAM,WAAW;IACf,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,MAAM,CAIZ;IAEF;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI;IAUzE;;OAEG;IACH,SAAS,IAAI,IAAI;IAcjB;;OAEG;IACH,QAAQ,IAAI,IAAI;IAOhB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB9B;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BvC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA2BlC;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmC1C;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBvC;;OAEG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAwBxD;AAGD,eAAO,MAAM,WAAW,aAAoB,CAAC"}
@@ -0,0 +1,218 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getSupabaseClient, isSupabaseConfigured } from '../utils/supabase';
11
+ import { errorHandler } from '../utils/errorHandler';
12
+ import { cacheManager } from '../utils/cacheManager';
13
+ class SyncService {
14
+ constructor() {
15
+ this.connection = null;
16
+ this.syncInterval = null;
17
+ this.config = {
18
+ enabled: false,
19
+ interval: 60000, // 1 minute
20
+ batchSize: 100,
21
+ };
22
+ }
23
+ /**
24
+ * Initialize sync service
25
+ */
26
+ initialize(connection, supabaseConfig) {
27
+ this.connection = connection;
28
+ this.config.supabaseConfig = supabaseConfig;
29
+ this.config.enabled = isSupabaseConfigured(supabaseConfig);
30
+ if (this.config.enabled) {
31
+ this.startSync();
32
+ }
33
+ }
34
+ /**
35
+ * Start periodic synchronization
36
+ */
37
+ startSync() {
38
+ if (this.syncInterval) {
39
+ return; // Already running
40
+ }
41
+ // Initial sync
42
+ this.syncAll();
43
+ // Periodic sync
44
+ this.syncInterval = setInterval(() => {
45
+ this.syncAll();
46
+ }, this.config.interval);
47
+ }
48
+ /**
49
+ * Stop synchronization
50
+ */
51
+ stopSync() {
52
+ if (this.syncInterval) {
53
+ clearInterval(this.syncInterval);
54
+ this.syncInterval = null;
55
+ }
56
+ }
57
+ /**
58
+ * Sync all data types
59
+ */
60
+ syncAll() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ if (!this.config.enabled || !isSupabaseConfigured(this.config.supabaseConfig)) {
63
+ return;
64
+ }
65
+ try {
66
+ yield Promise.all([
67
+ this.syncTransactions(),
68
+ this.syncRewards(),
69
+ this.syncPlatformMetrics(),
70
+ this.syncVaultHistory(),
71
+ ]);
72
+ }
73
+ catch (error) {
74
+ errorHandler.handleError(error, 'SyncService');
75
+ }
76
+ });
77
+ }
78
+ /**
79
+ * Sync transactions from blockchain to Supabase
80
+ */
81
+ syncTransactions() {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ if (!this.connection || !isSupabaseConfigured(this.config.supabaseConfig)) {
84
+ return;
85
+ }
86
+ try {
87
+ const supabase = getSupabaseClient(this.config.supabaseConfig);
88
+ // Get latest transaction signature from Supabase
89
+ const { data: latestTx } = yield supabase
90
+ .from('transactions')
91
+ .select('signature, timestamp')
92
+ .order('timestamp', { ascending: false })
93
+ .limit(1)
94
+ .single();
95
+ // In a real implementation, you would:
96
+ // 1. Query blockchain for new transactions since latestTx.timestamp
97
+ // 2. Parse transaction data
98
+ // 3. Insert into Supabase
99
+ // For now, this is a placeholder
100
+ console.log('Syncing transactions...');
101
+ }
102
+ catch (error) {
103
+ errorHandler.handleError(error, 'SyncService.syncTransactions');
104
+ }
105
+ });
106
+ }
107
+ /**
108
+ * Sync rewards from blockchain to Supabase
109
+ */
110
+ syncRewards() {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ if (!this.connection || !isSupabaseConfigured(this.config.supabaseConfig)) {
113
+ return;
114
+ }
115
+ try {
116
+ const supabase = getSupabaseClient(this.config.supabaseConfig);
117
+ // Get latest reward timestamp from Supabase
118
+ const { data: latestReward } = yield supabase
119
+ .from('rewards')
120
+ .select('timestamp')
121
+ .order('timestamp', { ascending: false })
122
+ .limit(1)
123
+ .single();
124
+ // In a real implementation, you would:
125
+ // 1. Query blockchain for new rewards since latestReward.timestamp
126
+ // 2. Parse reward data
127
+ // 3. Insert into Supabase
128
+ console.log('Syncing rewards...');
129
+ }
130
+ catch (error) {
131
+ errorHandler.handleError(error, 'SyncService.syncRewards');
132
+ }
133
+ });
134
+ }
135
+ /**
136
+ * Sync platform metrics
137
+ */
138
+ syncPlatformMetrics() {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ if (!this.connection || !isSupabaseConfigured(this.config.supabaseConfig)) {
141
+ return;
142
+ }
143
+ try {
144
+ const supabase = getSupabaseClient(this.config.supabaseConfig);
145
+ // Calculate current platform metrics
146
+ // This would typically involve:
147
+ // 1. Fetching all vaults
148
+ // 2. Calculating TVL, user count, etc.
149
+ // 3. Inserting into platform_metrics table
150
+ const metrics = {
151
+ timestamp: new Date().toISOString(),
152
+ total_value_locked: 0,
153
+ total_users: 0,
154
+ active_vaults: 0,
155
+ average_apr: 0,
156
+ current_epoch: 0,
157
+ volume_24h: 0,
158
+ };
159
+ yield supabase.from('platform_metrics').insert(metrics);
160
+ // Invalidate cache
161
+ cacheManager.invalidate('platformMetrics');
162
+ console.log('Syncing platform metrics...');
163
+ }
164
+ catch (error) {
165
+ errorHandler.handleError(error, 'SyncService.syncPlatformMetrics');
166
+ }
167
+ });
168
+ }
169
+ /**
170
+ * Sync vault history
171
+ */
172
+ syncVaultHistory() {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ if (!this.connection || !isSupabaseConfigured(this.config.supabaseConfig)) {
175
+ return;
176
+ }
177
+ try {
178
+ const supabase = getSupabaseClient(this.config.supabaseConfig);
179
+ // In a real implementation, you would:
180
+ // 1. Fetch all vaults from blockchain
181
+ // 2. For each vault, create history entry
182
+ // 3. Insert into vault_history table
183
+ console.log('Syncing vault history...');
184
+ }
185
+ catch (error) {
186
+ errorHandler.handleError(error, 'SyncService.syncVaultHistory');
187
+ }
188
+ });
189
+ }
190
+ /**
191
+ * Manually trigger sync for a specific transaction
192
+ */
193
+ syncTransaction(signature) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ if (!this.connection || !isSupabaseConfigured(this.config.supabaseConfig)) {
196
+ return;
197
+ }
198
+ try {
199
+ // Fetch transaction from blockchain
200
+ const tx = yield this.connection.getTransaction(signature, {
201
+ maxSupportedTransactionVersion: 0,
202
+ });
203
+ if (!tx) {
204
+ throw new Error('Transaction not found');
205
+ }
206
+ // Parse and insert into Supabase
207
+ // This would require parsing the transaction logs
208
+ // to extract stake/unstake/reward information
209
+ console.log('Syncing transaction:', signature);
210
+ }
211
+ catch (error) {
212
+ errorHandler.handleError(error, 'SyncService.syncTransaction');
213
+ }
214
+ });
215
+ }
216
+ }
217
+ // Export singleton instance
218
+ export const syncService = new SyncService();
@@ -0,0 +1,201 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import { BN } from '@coral-xyz/anchor';
3
+ export interface PredictionPlatform {
4
+ admin: PublicKey;
5
+ totalVaults: BN;
6
+ currentEpoch: BN;
7
+ platformFee: number;
8
+ earlyUnstakeFee: number;
9
+ isPaused: boolean;
10
+ }
11
+ export interface BlockchainVault {
12
+ id: BN;
13
+ aprRate: BN;
14
+ totalStaked: BN;
15
+ stakerCount: BN;
16
+ currentEpoch: BN;
17
+ isActive: boolean;
18
+ tokenMint: PublicKey;
19
+ currentRewardPool: BN;
20
+ totalRewardsDistributed: BN;
21
+ createdAt: BN;
22
+ lastUpdated: BN;
23
+ }
24
+ export interface UserStake {
25
+ user: PublicKey;
26
+ vaultId: BN;
27
+ amount: BN;
28
+ epochJoined: BN;
29
+ lastRewardEpoch: BN;
30
+ pendingRewards: BN;
31
+ stakedAt: BN;
32
+ cooldownEnd?: BN;
33
+ }
34
+ export interface Epoch {
35
+ id: BN;
36
+ vaultId: BN;
37
+ startTime: BN;
38
+ endTime?: BN;
39
+ totalRewards: BN;
40
+ participants: BN;
41
+ isActive: boolean;
42
+ rewardRate: BN;
43
+ }
44
+ export interface WalletState {
45
+ connected: boolean;
46
+ publicKey: PublicKey | null;
47
+ balance: number;
48
+ connecting: boolean;
49
+ disconnecting: boolean;
50
+ }
51
+ export interface VaultDisplayData {
52
+ id: number;
53
+ aprRate: number;
54
+ totalStaked: number;
55
+ stakerCount: number;
56
+ userStake: number;
57
+ currentRewardPool: number;
58
+ isActive: boolean;
59
+ loading: boolean;
60
+ historicalAPR: APRHistoryPoint[];
61
+ }
62
+ export interface APRHistoryPoint {
63
+ date: string;
64
+ apr: number;
65
+ totalStaked: number;
66
+ participants: number;
67
+ }
68
+ export interface UserPortfolio {
69
+ totalStaked: number;
70
+ totalRewards: number;
71
+ activeVaults: number;
72
+ portfolioValue: number;
73
+ performanceMetrics: PerformanceData;
74
+ }
75
+ export interface PerformanceData {
76
+ totalReturn: number;
77
+ annualizedReturn: number;
78
+ sharpeRatio: number;
79
+ maxDrawdown: number;
80
+ winRate: number;
81
+ }
82
+ export interface TransactionHistory {
83
+ id: string;
84
+ type: 'stake' | 'unstake' | 'claim' | 'reward';
85
+ amount: number;
86
+ vaultId: number;
87
+ timestamp: Date;
88
+ signature: string;
89
+ status: 'pending' | 'confirmed' | 'failed';
90
+ }
91
+ export interface PlatformStats {
92
+ totalValueLocked: number;
93
+ totalUsers: number;
94
+ totalVaults: number;
95
+ averageAPR: number;
96
+ currentEpoch: number;
97
+ totalRewardsDistributed: number;
98
+ }
99
+ export interface StakeModalProps {
100
+ isOpen: boolean;
101
+ onClose: () => void;
102
+ vault: VaultDisplayData;
103
+ onStake: (amount: number) => Promise<void>;
104
+ }
105
+ export interface UnstakeModalProps {
106
+ isOpen: boolean;
107
+ onClose: () => void;
108
+ vault: VaultDisplayData;
109
+ userStake: number;
110
+ onUnstake: (amount: number, immediate: boolean) => Promise<void>;
111
+ }
112
+ export interface VaultCardProps {
113
+ vault: VaultDisplayData;
114
+ onStake: () => void;
115
+ onUnstake: () => void;
116
+ onViewDetails: () => void;
117
+ }
118
+ export interface PlatformError {
119
+ code: string;
120
+ message: string;
121
+ details?: any;
122
+ }
123
+ export interface Theme {
124
+ colors: {
125
+ primary: string;
126
+ secondary: string;
127
+ background: string;
128
+ surface: string;
129
+ border: string;
130
+ text: string;
131
+ textSecondary: string;
132
+ success: string;
133
+ warning: string;
134
+ error: string;
135
+ accent: string;
136
+ };
137
+ spacing: {
138
+ xs: string;
139
+ sm: string;
140
+ md: string;
141
+ lg: string;
142
+ xl: string;
143
+ xxl: string;
144
+ };
145
+ borderRadius: {
146
+ sm: string;
147
+ md: string;
148
+ lg: string;
149
+ xl: string;
150
+ };
151
+ shadows: {
152
+ sm: string;
153
+ md: string;
154
+ lg: string;
155
+ xl: string;
156
+ };
157
+ breakpoints?: {
158
+ mobile: string;
159
+ tablet: string;
160
+ desktop: string;
161
+ wide: string;
162
+ ultrawide: string;
163
+ };
164
+ }
165
+ export interface ApiResponse<T> {
166
+ success: boolean;
167
+ data?: T;
168
+ error?: PlatformError;
169
+ timestamp: string;
170
+ }
171
+ export interface SustainabilityMetrics {
172
+ energyConsumption: number;
173
+ carbonFootprint: number;
174
+ resourceEfficiency: number;
175
+ renewablePercentage: number;
176
+ sustainabilityScore: number;
177
+ }
178
+ export interface PropertyTestConfig {
179
+ iterations: number;
180
+ seed?: number;
181
+ timeout?: number;
182
+ verbose?: boolean;
183
+ }
184
+ export interface PropertyTestResult {
185
+ property: string;
186
+ passed: boolean;
187
+ iterations: number;
188
+ counterexample?: any;
189
+ error?: string;
190
+ }
191
+ export interface SyncState {
192
+ lastSync: Date;
193
+ syncing: boolean;
194
+ syncError?: string;
195
+ pendingUpdates: number;
196
+ }
197
+ export type VaultId = number;
198
+ export type EpochId = number;
199
+ export type UserId = string;
200
+ export type TransactionSignature = string;
201
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAGvC,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,SAAS,CAAC;IACjB,WAAW,EAAE,EAAE,CAAC;IAChB,YAAY,EAAE,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAGD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAA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