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,75 @@
1
+ /**
2
+ * Token Utilities
3
+ * Helper functions for handling SOL and SPL tokens
4
+ */
5
+ import { PublicKey, SystemProgram, LAMPORTS_PER_SOL } from '@solana/web3.js';
6
+ import { TOKEN_PROGRAM_ID, NATIVE_MINT } from '@solana/spl-token';
7
+
8
+ // SOL native mint (System Program)
9
+ export const SOL_MINT = SystemProgram.programId;
10
+
11
+ // USDC devnet mint
12
+ export const USDC_DEVNET_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
13
+
14
+ // USDC mainnet mint
15
+ export const USDC_MAINNET_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
16
+
17
+ /**
18
+ * Check if a token mint is native SOL
19
+ */
20
+ export function isNativeSOL(tokenMint: PublicKey | string): boolean {
21
+ const mint = typeof tokenMint === 'string' ? new PublicKey(tokenMint) : tokenMint;
22
+ // Native SOL uses SystemProgram
23
+ // We can also check against NATIVE_MINT (wrapped SOL)
24
+ return mint.equals(SOL_MINT) || mint.equals(NATIVE_MINT);
25
+ }
26
+
27
+ /**
28
+ * Check if a token mint is USDC
29
+ */
30
+ export function isUSDC(tokenMint: PublicKey | string): boolean {
31
+ const mint = typeof tokenMint === 'string' ? new PublicKey(tokenMint) : tokenMint;
32
+ return mint.equals(USDC_DEVNET_MINT) || mint.equals(USDC_MAINNET_MINT);
33
+ }
34
+
35
+ /**
36
+ * Get token name from mint
37
+ */
38
+ export function getTokenName(tokenMint: PublicKey | string): string {
39
+ if (isNativeSOL(tokenMint)) {
40
+ return 'SOL';
41
+ }
42
+ if (isUSDC(tokenMint)) {
43
+ return 'USDC';
44
+ }
45
+ return 'Token';
46
+ }
47
+
48
+ /**
49
+ * Get token decimals
50
+ */
51
+ export function getTokenDecimals(tokenMint: PublicKey | string): number {
52
+ if (isNativeSOL(tokenMint)) {
53
+ return 9; // SOL has 9 decimals
54
+ }
55
+ if (isUSDC(tokenMint)) {
56
+ return 6; // USDC has 6 decimals
57
+ }
58
+ return 9; // Default to 9
59
+ }
60
+
61
+ /**
62
+ * Convert amount to lamports based on token type
63
+ */
64
+ export function toLamports(amount: number, tokenMint: PublicKey | string): number {
65
+ const decimals = getTokenDecimals(tokenMint);
66
+ return Math.floor(amount * Math.pow(10, decimals));
67
+ }
68
+
69
+ /**
70
+ * Convert lamports to amount based on token type
71
+ */
72
+ export function fromLamports(lamports: number, tokenMint: PublicKey | string): number {
73
+ const decimals = getTokenDecimals(tokenMint);
74
+ return lamports / Math.pow(10, decimals);
75
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Validation Utilities
3
+ * Centralized validation functions for user inputs
4
+ */
5
+
6
+ import { PublicKey } from '@solana/web3.js';
7
+
8
+ export interface ValidationResult {
9
+ valid: boolean;
10
+ error?: string;
11
+ number?: number;
12
+ }
13
+
14
+ /**
15
+ * Validate and parse numeric input
16
+ */
17
+ export function validateNumericInput(input: string): ValidationResult {
18
+ if (!input || input.trim() === '') {
19
+ return { valid: false, error: 'Please enter an amount' };
20
+ }
21
+
22
+ const trimmed = input.trim();
23
+ const number = parseFloat(trimmed);
24
+
25
+ if (isNaN(number)) {
26
+ return { valid: false, error: 'Please enter a valid number' };
27
+ }
28
+
29
+ if (number <= 0) {
30
+ return { valid: false, error: 'Amount must be greater than 0' };
31
+ }
32
+
33
+ if (!isFinite(number)) {
34
+ return { valid: false, error: 'Amount must be a finite number' };
35
+ }
36
+
37
+ return { valid: true, number };
38
+ }
39
+
40
+ /**
41
+ * Validate stake amount
42
+ */
43
+ export function validateStakeAmount(amount: number, balance: number, minStake: number = 0): ValidationResult {
44
+ if (isNaN(amount) || amount <= 0) {
45
+ return { valid: false, error: 'Amount must be greater than 0' };
46
+ }
47
+
48
+ if (amount < minStake) {
49
+ return { valid: false, error: `Minimum stake amount is ${minStake}` };
50
+ }
51
+
52
+ if (amount > balance) {
53
+ return { valid: false, error: 'Insufficient balance' };
54
+ }
55
+
56
+ return { valid: true };
57
+ }
58
+
59
+ /**
60
+ * Validate unstake amount
61
+ */
62
+ export function validateUnstakeAmount(amount: number, stakedAmount: number): ValidationResult {
63
+ if (isNaN(amount) || amount <= 0) {
64
+ return { valid: false, error: 'Amount must be greater than 0' };
65
+ }
66
+
67
+ if (amount > stakedAmount) {
68
+ return { valid: false, error: 'Insufficient staked balance' };
69
+ }
70
+
71
+ return { valid: true };
72
+ }
73
+
74
+ /**
75
+ * Validate PublicKey
76
+ */
77
+ export function validatePublicKey(address: string | PublicKey): ValidationResult {
78
+ try {
79
+ const pubkey = typeof address === 'string' ? new PublicKey(address) : address;
80
+ // PublicKey constructor will throw if invalid
81
+ return { valid: true };
82
+ } catch (error) {
83
+ return { valid: false, error: 'Invalid public key address' };
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Validate vault ID
89
+ */
90
+ export function validateVaultId(vaultId: number): ValidationResult {
91
+ if (!Number.isInteger(vaultId) || vaultId <= 0) {
92
+ return { valid: false, error: 'Invalid vault ID' };
93
+ }
94
+
95
+ return { valid: true };
96
+ }
97
+
98
+ /**
99
+ * Validate percentage (0-100)
100
+ */
101
+ export function validatePercentage(value: number): ValidationResult {
102
+ if (isNaN(value) || value < 0 || value > 100) {
103
+ return { valid: false, error: 'Percentage must be between 0 and 100' };
104
+ }
105
+
106
+ return { valid: true };
107
+ }