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,88 @@
|
|
|
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 { useMemo, useState, useEffect } from 'react';
|
|
11
|
+
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
|
|
12
|
+
import { Program, AnchorProvider } from '@coral-xyz/anchor';
|
|
13
|
+
import { PublicKey } from '@solana/web3.js';
|
|
14
|
+
// Program ID from environment or default
|
|
15
|
+
const getProgramId = () => {
|
|
16
|
+
var _a;
|
|
17
|
+
const PROGRAM_ID_STRING = typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_PROGRAM_ID)
|
|
18
|
+
? process.env.NEXT_PUBLIC_PROGRAM_ID
|
|
19
|
+
: 'Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS';
|
|
20
|
+
try {
|
|
21
|
+
return new PublicKey(PROGRAM_ID_STRING);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error('Invalid Program ID:', PROGRAM_ID_STRING, error);
|
|
25
|
+
// Fallback to default
|
|
26
|
+
return new PublicKey('Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS');
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const PROGRAM_ID = getProgramId();
|
|
30
|
+
export const useProgram = (options = {}) => {
|
|
31
|
+
const { connection } = useConnection();
|
|
32
|
+
const wallet = useWallet();
|
|
33
|
+
const [idl, setIdl] = useState(null);
|
|
34
|
+
const [idlError, setIdlError] = useState(null);
|
|
35
|
+
const idlPath = options.idlPath || '/web3_prediction_platform.json';
|
|
36
|
+
const programId = options.programId || PROGRAM_ID;
|
|
37
|
+
// Load IDL from public folder (works with static export)
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const loadIdl = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
const response = yield fetch(idlPath);
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Failed to load IDL: ${response.statusText}`);
|
|
44
|
+
}
|
|
45
|
+
const idlData = yield response.json();
|
|
46
|
+
setIdl(idlData);
|
|
47
|
+
setIdlError(null);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('Error loading IDL:', error);
|
|
51
|
+
setIdlError(error.message || 'Failed to load IDL');
|
|
52
|
+
setIdl(null);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
loadIdl();
|
|
56
|
+
}, [idlPath]);
|
|
57
|
+
const provider = useMemo(() => {
|
|
58
|
+
if (!wallet.publicKey || !connection)
|
|
59
|
+
return null;
|
|
60
|
+
try {
|
|
61
|
+
return new AnchorProvider(connection, wallet, { commitment: 'confirmed' });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error('Error creating provider:', error);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}, [connection, wallet]);
|
|
68
|
+
const program = useMemo(() => {
|
|
69
|
+
if (!provider || !idl)
|
|
70
|
+
return null;
|
|
71
|
+
try {
|
|
72
|
+
// Anchor Program constructor: new Program(idl, programId, provider)
|
|
73
|
+
// @ts-ignore - TypeScript inference issue with Program constructor argument types
|
|
74
|
+
return new Program(idl, programId, provider);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('Error creating program:', error);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}, [provider, idl, programId]);
|
|
81
|
+
return {
|
|
82
|
+
program,
|
|
83
|
+
provider,
|
|
84
|
+
idl,
|
|
85
|
+
idlError,
|
|
86
|
+
programId
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
export interface TokenBalance {
|
|
3
|
+
sol: number;
|
|
4
|
+
usdc: number;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
error: string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const useTokenBalance: (tokenMint?: PublicKey | string) => {
|
|
9
|
+
sol: number;
|
|
10
|
+
usdc: number;
|
|
11
|
+
getBalance: (mint?: PublicKey | string) => number;
|
|
12
|
+
loading: boolean;
|
|
13
|
+
error: string;
|
|
14
|
+
refresh: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useTokenBalance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTokenBalance.d.ts","sourceRoot":"","sources":["../../src/hooks/useTokenBalance.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAK9D,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,eAAe,GAAI,YAAY,SAAS,GAAG,MAAM;;;wBA2ErB,SAAS,GAAG,MAAM,KAAG,MAAM;;;;CAmBnE,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Token Balance Hook
|
|
12
|
+
* Fetches balance for both SOL and SPL tokens (USDC)
|
|
13
|
+
*/
|
|
14
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
15
|
+
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
|
|
16
|
+
import { PublicKey, LAMPORTS_PER_SOL } from '@solana/web3.js';
|
|
17
|
+
import { getAccount, getAssociatedTokenAddress, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
18
|
+
import { isNativeSOL, fromLamports } from '../utils/tokenUtils';
|
|
19
|
+
import { retryRpcCall } from '../utils/rpcRetry';
|
|
20
|
+
export const useTokenBalance = (tokenMint) => {
|
|
21
|
+
const { connection } = useConnection();
|
|
22
|
+
const { publicKey } = useWallet();
|
|
23
|
+
const [solBalance, setSolBalance] = useState(0);
|
|
24
|
+
const [usdcBalance, setUsdcBalance] = useState(0);
|
|
25
|
+
const [loading, setLoading] = useState(false);
|
|
26
|
+
const [error, setError] = useState(null);
|
|
27
|
+
const fetchBalances = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
if (!connection || !publicKey) {
|
|
30
|
+
setSolBalance(0);
|
|
31
|
+
setUsdcBalance(0);
|
|
32
|
+
setLoading(false);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
setLoading(true);
|
|
37
|
+
setError(null);
|
|
38
|
+
// Fetch SOL balance
|
|
39
|
+
const solBalanceLamports = yield retryRpcCall(() => connection.getBalance(publicKey));
|
|
40
|
+
setSolBalance(Number(solBalanceLamports) / LAMPORTS_PER_SOL);
|
|
41
|
+
// Fetch USDC balance if needed
|
|
42
|
+
try {
|
|
43
|
+
// USDC devnet mint
|
|
44
|
+
const usdcMint = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
45
|
+
const usdcTokenAccount = yield getAssociatedTokenAddress(usdcMint, publicKey, false, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
46
|
+
try {
|
|
47
|
+
const tokenAccount = yield retryRpcCall(() => getAccount(connection, usdcTokenAccount));
|
|
48
|
+
const amount = typeof tokenAccount.amount === 'bigint'
|
|
49
|
+
? Number(tokenAccount.amount)
|
|
50
|
+
: tokenAccount.amount;
|
|
51
|
+
setUsdcBalance(fromLamports(amount, usdcMint));
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
// Token account doesn't exist, balance is 0
|
|
55
|
+
if (((_a = err.message) === null || _a === void 0 ? void 0 : _a.includes('InvalidAccountData')) || ((_b = err.message) === null || _b === void 0 ? void 0 : _b.includes('could not find account'))) {
|
|
56
|
+
setUsdcBalance(0);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
console.warn('Error fetching USDC balance:', err);
|
|
65
|
+
setUsdcBalance(0);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
console.error('Error fetching balances:', err);
|
|
70
|
+
setError(err.message);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
}
|
|
75
|
+
}), [connection, publicKey]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
fetchBalances();
|
|
78
|
+
// Poll for balance updates every 5 seconds
|
|
79
|
+
const interval = setInterval(fetchBalances, 5000);
|
|
80
|
+
return () => clearInterval(interval);
|
|
81
|
+
}, [fetchBalances]);
|
|
82
|
+
// Get balance for specific token mint
|
|
83
|
+
const getBalance = useCallback((mint) => {
|
|
84
|
+
if (!mint)
|
|
85
|
+
return solBalance; // Default to SOL
|
|
86
|
+
if (isNativeSOL(mint)) {
|
|
87
|
+
return solBalance;
|
|
88
|
+
}
|
|
89
|
+
// Assume USDC for now (can be extended for other tokens)
|
|
90
|
+
return usdcBalance;
|
|
91
|
+
}, [solBalance, usdcBalance]);
|
|
92
|
+
return {
|
|
93
|
+
sol: solBalance,
|
|
94
|
+
usdc: usdcBalance,
|
|
95
|
+
getBalance,
|
|
96
|
+
loading,
|
|
97
|
+
error,
|
|
98
|
+
refresh: fetchBalances,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
export interface Vault {
|
|
3
|
+
id: number;
|
|
4
|
+
aprRate: number;
|
|
5
|
+
totalStaked: number;
|
|
6
|
+
stakerCount: number;
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
tokenMint: PublicKey | string;
|
|
9
|
+
name?: string;
|
|
10
|
+
logo?: string;
|
|
11
|
+
lpOperation?: string;
|
|
12
|
+
lpOperationLogo?: string;
|
|
13
|
+
contentTitle?: string;
|
|
14
|
+
content?: string;
|
|
15
|
+
currentEpoch?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const useVaults: () => {
|
|
18
|
+
vaults: Vault[];
|
|
19
|
+
loading: boolean;
|
|
20
|
+
error: string;
|
|
21
|
+
refreshVaults: () => void;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=useVaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVaults.d.ts","sourceRoot":"","sources":["../../src/hooks/useVaults.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC;IAE9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,SAAS;;;;;CA+FrB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { useState, useEffect, useCallback } from 'react';
|
|
11
|
+
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
|
|
12
|
+
import { useProgram } from './useProgram';
|
|
13
|
+
import { usePolling } from './usePolling';
|
|
14
|
+
import { retryRpcCall } from '../utils/rpcRetry';
|
|
15
|
+
export const useVaults = () => {
|
|
16
|
+
const { connection } = useConnection();
|
|
17
|
+
const { publicKey } = useWallet();
|
|
18
|
+
const { program } = useProgram();
|
|
19
|
+
const [vaults, setVaults] = useState([]);
|
|
20
|
+
const [loading, setLoading] = useState(true);
|
|
21
|
+
const [error, setError] = useState(null);
|
|
22
|
+
const loadVaults = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
if (!program) {
|
|
24
|
+
setLoading(false);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
setLoading(true);
|
|
29
|
+
setError(null);
|
|
30
|
+
// Load all vault accounts with retry
|
|
31
|
+
const vaultAccounts = yield retryRpcCall(() => program.account.vault.all());
|
|
32
|
+
// Load vault metadata from localStorage
|
|
33
|
+
let vaultMetadata = {};
|
|
34
|
+
if (typeof window !== 'undefined') {
|
|
35
|
+
try {
|
|
36
|
+
vaultMetadata = JSON.parse(localStorage.getItem('vaultMetadata') || '{}');
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.warn('Failed to load vault metadata from localStorage:', e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const loadedVaults = vaultAccounts.map((account) => {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
44
|
+
// Handle both camelCase and snake_case field names (depending on IDL generation)
|
|
45
|
+
const vault = account.account;
|
|
46
|
+
const tokenMint = vault.tokenMint || vault.token_mint;
|
|
47
|
+
const vaultId = ((_b = (_a = (vault.id || vault.vaultId)) === null || _a === void 0 ? void 0 : _a.toNumber) === null || _b === void 0 ? void 0 : _b.call(_a)) || 0;
|
|
48
|
+
const metadata = vaultMetadata[vaultId] || {};
|
|
49
|
+
return {
|
|
50
|
+
id: vaultId,
|
|
51
|
+
aprRate: ((_d = (_c = (vault.aprRate || vault.apr_rate)) === null || _c === void 0 ? void 0 : _c.toNumber) === null || _d === void 0 ? void 0 : _d.call(_c)) || 0,
|
|
52
|
+
totalStaked: ((_f = (_e = (vault.totalStaked || vault.total_staked)) === null || _e === void 0 ? void 0 : _e.toNumber) === null || _f === void 0 ? void 0 : _f.call(_e)) || 0,
|
|
53
|
+
stakerCount: ((_h = (_g = (vault.stakerCount || vault.staker_count)) === null || _g === void 0 ? void 0 : _g.toNumber) === null || _h === void 0 ? void 0 : _h.call(_g)) || 0,
|
|
54
|
+
isActive: (_k = (_j = vault.isActive) !== null && _j !== void 0 ? _j : vault.is_active) !== null && _k !== void 0 ? _k : false,
|
|
55
|
+
tokenMint: tokenMint ? (typeof tokenMint === 'string' ? tokenMint : tokenMint.toString()) : '',
|
|
56
|
+
currentEpoch: ((_m = (_l = (vault.currentEpoch || vault.current_epoch)) === null || _l === void 0 ? void 0 : _l.toNumber) === null || _m === void 0 ? void 0 : _m.call(_l)) || 0,
|
|
57
|
+
// Load metadata from localStorage
|
|
58
|
+
name: metadata.name,
|
|
59
|
+
logo: metadata.logo,
|
|
60
|
+
lpOperation: metadata.lpOperation,
|
|
61
|
+
lpOperationLogo: metadata.lpOperationLogo,
|
|
62
|
+
contentTitle: metadata.contentTitle,
|
|
63
|
+
content: metadata.content,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
setVaults(loadedVaults);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
console.error('Error loading vaults:', err);
|
|
70
|
+
setError(err.message);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
setLoading(false);
|
|
74
|
+
}
|
|
75
|
+
}), [program]);
|
|
76
|
+
// Initial load
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
loadVaults();
|
|
79
|
+
}, [loadVaults]);
|
|
80
|
+
// Real-time synchronization: Requirement 10.1 - 5-second blockchain sync
|
|
81
|
+
usePolling(loadVaults, {
|
|
82
|
+
interval: 5000, // 5 seconds as per Requirement 10.1
|
|
83
|
+
enabled: !!program, // Only poll when program is available
|
|
84
|
+
onError: (error) => {
|
|
85
|
+
console.error('Polling error in useVaults:', error);
|
|
86
|
+
setError(error.message);
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const refreshVaults = useCallback(() => {
|
|
90
|
+
loadVaults();
|
|
91
|
+
}, [loadVaults]);
|
|
92
|
+
return {
|
|
93
|
+
vaults,
|
|
94
|
+
loading,
|
|
95
|
+
error,
|
|
96
|
+
refreshVaults,
|
|
97
|
+
};
|
|
98
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @keynesol/shared
|
|
3
|
+
* Shared code package for Keynesol Web3 Prediction Platform
|
|
4
|
+
*/
|
|
5
|
+
export * from './components';
|
|
6
|
+
export * from './hooks';
|
|
7
|
+
export * from './utils';
|
|
8
|
+
export * from './utils/supabase';
|
|
9
|
+
export * from './services';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export declare const IDL_PATH = "/web3_prediction_platform.json";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,cAAc,CAAC;AAG7B,cAAc,SAAS,CAAC;AAGxB,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AAGjC,cAAc,YAAY,CAAC;AAG3B,cAAc,SAAS,CAAC;AAGxB,eAAO,MAAM,QAAQ,mCAAmC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @keynesol/shared
|
|
3
|
+
* Shared code package for Keynesol Web3 Prediction Platform
|
|
4
|
+
*/
|
|
5
|
+
// Export all components
|
|
6
|
+
export * from './components';
|
|
7
|
+
// Export all hooks
|
|
8
|
+
export * from './hooks';
|
|
9
|
+
// Export all utils
|
|
10
|
+
export * from './utils';
|
|
11
|
+
export * from './utils/supabase';
|
|
12
|
+
// Export all services
|
|
13
|
+
export * from './services';
|
|
14
|
+
// Export all types
|
|
15
|
+
export * from './types';
|
|
16
|
+
// Export IDL path (for reference)
|
|
17
|
+
export const IDL_PATH = '/web3_prediction_platform.json';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Reconciliation Service
|
|
3
|
+
* Ensures consistency between Supabase and blockchain
|
|
4
|
+
* Requirements: 10.5
|
|
5
|
+
*/
|
|
6
|
+
import { Connection } from '@solana/web3.js';
|
|
7
|
+
import { SupabaseConfig } from '../utils/supabase';
|
|
8
|
+
interface ReconciliationResult {
|
|
9
|
+
transactions: {
|
|
10
|
+
missing: number;
|
|
11
|
+
inconsistent: number;
|
|
12
|
+
fixed: number;
|
|
13
|
+
};
|
|
14
|
+
rewards: {
|
|
15
|
+
missing: number;
|
|
16
|
+
inconsistent: number;
|
|
17
|
+
fixed: number;
|
|
18
|
+
};
|
|
19
|
+
vaults: {
|
|
20
|
+
missing: number;
|
|
21
|
+
inconsistent: number;
|
|
22
|
+
fixed: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
declare class ReconciliationService {
|
|
26
|
+
private connection;
|
|
27
|
+
private reconciliationInterval;
|
|
28
|
+
private supabaseConfig?;
|
|
29
|
+
/**
|
|
30
|
+
* Initialize reconciliation service
|
|
31
|
+
*/
|
|
32
|
+
initialize(connection: Connection, supabaseConfig?: SupabaseConfig): void;
|
|
33
|
+
/**
|
|
34
|
+
* Start periodic reconciliation
|
|
35
|
+
*/
|
|
36
|
+
startReconciliation(interval?: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Stop reconciliation
|
|
39
|
+
*/
|
|
40
|
+
stopReconciliation(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Reconcile all data types
|
|
43
|
+
*/
|
|
44
|
+
reconcileAll(): Promise<ReconciliationResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Reconcile transactions
|
|
47
|
+
*/
|
|
48
|
+
reconcileTransactions(): Promise<{
|
|
49
|
+
missing: number;
|
|
50
|
+
inconsistent: number;
|
|
51
|
+
fixed: number;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Reconcile rewards
|
|
55
|
+
*/
|
|
56
|
+
reconcileRewards(): Promise<{
|
|
57
|
+
missing: number;
|
|
58
|
+
inconsistent: number;
|
|
59
|
+
fixed: number;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Reconcile vaults
|
|
63
|
+
*/
|
|
64
|
+
reconcileVaults(): Promise<{
|
|
65
|
+
missing: number;
|
|
66
|
+
inconsistent: number;
|
|
67
|
+
fixed: number;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Manual reconciliation trigger
|
|
71
|
+
*/
|
|
72
|
+
manualReconcile(): Promise<ReconciliationResult>;
|
|
73
|
+
}
|
|
74
|
+
export declare const reconciliationService: ReconciliationService;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=reconciliationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconciliationService.d.ts","sourceRoot":"","sources":["../../src/services/reconciliationService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAA2C,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAI5F,UAAU,oBAAoB;IAC5B,YAAY,EAAE;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,cAAM,qBAAqB;IACzB,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,sBAAsB,CAA+B;IAC7D,OAAO,CAAC,cAAc,CAAC,CAAiB;IAExC;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI;IAKzE;;OAEG;IACH,mBAAmB,CAAC,QAAQ,GAAE,MAAgB,GAAG,IAAI;IAcrD;;OAEG;IACH,kBAAkB,IAAI,IAAI;IAO1B;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,oBAAoB,CAAC;IA2BnD;;OAEG;IACG,qBAAqB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAwEhG;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAoC3F;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAqB1F;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,oBAAoB,CAAC;CAGvD;AAGD,eAAO,MAAM,qBAAqB,uBAA8B,CAAC"}
|