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.
- package/README.md +118 -0
- package/dist/components/Common/ErrorBoundary.d.ts +23 -0
- package/dist/components/Common/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/Common/ErrorBoundary.js +93 -0
- package/dist/components/Common/ErrorBoundary.jsx +103 -0
- package/dist/components/Common/ErrorMessage.d.ts +8 -0
- package/dist/components/Common/ErrorMessage.d.ts.map +1 -0
- package/dist/components/Common/ErrorMessage.js +36 -0
- package/dist/components/Common/ErrorMessage.jsx +40 -0
- package/dist/components/Common/Loading.d.ts +8 -0
- package/dist/components/Common/Loading.d.ts.map +1 -0
- package/dist/components/Common/Loading.js +41 -0
- package/dist/components/Common/Loading.jsx +44 -0
- package/dist/components/Common/LoadingIndicator.d.ts +17 -0
- package/dist/components/Common/LoadingIndicator.d.ts.map +1 -0
- package/dist/components/Common/LoadingIndicator.js +95 -0
- package/dist/components/Common/LoadingIndicator.jsx +108 -0
- package/dist/components/Common/ProgramStatus.d.ts +3 -0
- package/dist/components/Common/ProgramStatus.d.ts.map +1 -0
- package/dist/components/Common/ProgramStatus.js +26 -0
- package/dist/components/Common/ProgramStatus.jsx +27 -0
- package/dist/components/Common/Skeleton.d.ts +39 -0
- package/dist/components/Common/Skeleton.d.ts.map +1 -0
- package/dist/components/Common/Skeleton.js +53 -0
- package/dist/components/Common/Skeleton.jsx +67 -0
- package/dist/components/Common/SkeletonScreen.d.ts +18 -0
- package/dist/components/Common/SkeletonScreen.d.ts.map +1 -0
- package/dist/components/Common/SkeletonScreen.js +98 -0
- package/dist/components/Common/SkeletonScreen.jsx +108 -0
- package/dist/components/Common/index.d.ts +11 -0
- package/dist/components/Common/index.d.ts.map +1 -0
- package/dist/components/Common/index.js +10 -0
- package/dist/components/Wallet/TransactionStatus.d.ts +11 -0
- package/dist/components/Wallet/TransactionStatus.d.ts.map +1 -0
- package/dist/components/Wallet/TransactionStatus.js +97 -0
- package/dist/components/Wallet/TransactionStatus.jsx +106 -0
- package/dist/components/Wallet/WalletBalance.d.ts +4 -0
- package/dist/components/Wallet/WalletBalance.d.ts.map +1 -0
- package/dist/components/Wallet/WalletBalance.js +82 -0
- package/dist/components/Wallet/WalletBalance.jsx +86 -0
- package/dist/components/Wallet/WalletButton.d.ts +3 -0
- package/dist/components/Wallet/WalletButton.d.ts.map +1 -0
- package/dist/components/Wallet/WalletButton.js +51 -0
- package/dist/components/Wallet/WalletButton.jsx +53 -0
- package/dist/components/Wallet/WalletConnectionModal.d.ts +8 -0
- package/dist/components/Wallet/WalletConnectionModal.d.ts.map +1 -0
- package/dist/components/Wallet/WalletConnectionModal.js +150 -0
- package/dist/components/Wallet/WalletConnectionModal.jsx +170 -0
- package/dist/components/Wallet/WalletProvider.d.ts +9 -0
- package/dist/components/Wallet/WalletProvider.d.ts.map +1 -0
- package/dist/components/Wallet/WalletProvider.js +70 -0
- package/dist/components/Wallet/WalletProvider.jsx +75 -0
- package/dist/components/Wallet/index.d.ts +9 -0
- package/dist/components/Wallet/index.d.ts.map +1 -0
- package/dist/components/Wallet/index.js +8 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/useCache.d.ts +16 -0
- package/dist/hooks/useCache.d.ts.map +1 -0
- package/dist/hooks/useCache.js +67 -0
- package/dist/hooks/usePolling.d.ts +16 -0
- package/dist/hooks/usePolling.d.ts.map +1 -0
- package/dist/hooks/usePolling.js +79 -0
- package/dist/hooks/useProgram.d.ts +14 -0
- package/dist/hooks/useProgram.d.ts.map +1 -0
- package/dist/hooks/useProgram.js +88 -0
- package/dist/hooks/useTokenBalance.d.ts +16 -0
- package/dist/hooks/useTokenBalance.d.ts.map +1 -0
- package/dist/hooks/useTokenBalance.js +100 -0
- package/dist/hooks/useVaults.d.ts +23 -0
- package/dist/hooks/useVaults.d.ts.map +1 -0
- package/dist/hooks/useVaults.js +98 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +6 -0
- package/dist/services/reconciliationService.d.ts +76 -0
- package/dist/services/reconciliationService.d.ts.map +1 -0
- package/dist/services/reconciliationService.js +216 -0
- package/dist/services/syncService.d.ts +51 -0
- package/dist/services/syncService.d.ts.map +1 -0
- package/dist/services/syncService.js +218 -0
- package/dist/types/index.d.ts +201 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/cacheManager.d.ts +73 -0
- package/dist/utils/cacheManager.d.ts.map +1 -0
- package/dist/utils/cacheManager.js +232 -0
- package/dist/utils/errorHandler.d.ts +76 -0
- package/dist/utils/errorHandler.d.ts.map +1 -0
- package/dist/utils/errorHandler.js +267 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/performanceMonitor.d.ts +75 -0
- package/dist/utils/performanceMonitor.d.ts.map +1 -0
- package/dist/utils/performanceMonitor.js +197 -0
- package/dist/utils/rpcRetry.d.ts +12 -0
- package/dist/utils/rpcRetry.d.ts.map +1 -0
- package/dist/utils/rpcRetry.js +47 -0
- package/dist/utils/supabase.d.ts +198 -0
- package/dist/utils/supabase.d.ts.map +1 -0
- package/dist/utils/supabase.js +50 -0
- package/dist/utils/toastService.d.ts +52 -0
- package/dist/utils/toastService.d.ts.map +1 -0
- package/dist/utils/toastService.js +139 -0
- package/dist/utils/tokenUtils.d.ts +33 -0
- package/dist/utils/tokenUtils.d.ts.map +1 -0
- package/dist/utils/tokenUtils.js +66 -0
- package/dist/utils/validation.d.ts +35 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +83 -0
- package/package.json +45 -0
- package/src/components/Common/ErrorBoundary.tsx +135 -0
- package/src/components/Common/ErrorMessage.tsx +52 -0
- package/src/components/Common/Loading.tsx +56 -0
- package/src/components/Common/LoadingIndicator.tsx +143 -0
- package/src/components/Common/ProgramStatus.tsx +37 -0
- package/src/components/Common/Skeleton.tsx +83 -0
- package/src/components/Common/SkeletonScreen.tsx +166 -0
- package/src/components/Common/index.ts +10 -0
- package/src/components/Wallet/TransactionStatus.tsx +138 -0
- package/src/components/Wallet/WalletBalance.tsx +94 -0
- package/src/components/Wallet/WalletButton.tsx +65 -0
- package/src/components/Wallet/WalletConnectionModal.tsx +193 -0
- package/src/components/Wallet/WalletProvider.tsx +104 -0
- package/src/components/Wallet/index.ts +8 -0
- package/src/components/index.ts +6 -0
- package/src/hooks/index.ts +10 -0
- package/src/hooks/useCache.ts +87 -0
- package/src/hooks/usePolling.ts +98 -0
- package/src/hooks/useProgram.ts +93 -0
- package/src/hooks/useTokenBalance.ts +113 -0
- package/src/hooks/useVaults.ts +122 -0
- package/src/index.ts +23 -0
- package/src/services/index.ts +6 -0
- package/src/services/reconciliationService.ts +246 -0
- package/src/services/syncService.ts +238 -0
- package/src/types/index.ts +233 -0
- package/src/utils/cacheManager.ts +286 -0
- package/src/utils/errorHandler.ts +336 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/performanceMonitor.ts +222 -0
- package/src/utils/rpcRetry.ts +55 -0
- package/src/utils/supabase.ts +253 -0
- package/src/utils/toastService.ts +166 -0
- package/src/utils/tokenUtils.ts +75 -0
- 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
|
+
}
|