|
| 1 | +import { PublicKey, TransactionInstruction } from "@solana/web3.js"; |
| 2 | +import { PythCluster } from "@pythnetwork/client"; |
| 3 | + |
| 4 | +/** |
| 5 | + * Program adapter interface that defines the contract for interacting with |
| 6 | + * different Pyth programs (Core, Lazer, etc). |
| 7 | + * |
| 8 | + * This adapter pattern allows the frontend to use a consistent interface |
| 9 | + * while supporting multiple program implementations. |
| 10 | + */ |
| 11 | +export interface ProgramAdapter { |
| 12 | + /** |
| 13 | + * Program address on Solana |
| 14 | + * Each program may have different addresses on different clusters |
| 15 | + */ |
| 16 | + getProgramAddress(cluster: PythCluster): PublicKey; |
| 17 | + |
| 18 | + /** |
| 19 | + * Human-readable name of the program |
| 20 | + */ |
| 21 | + readonly name: string; |
| 22 | + |
| 23 | + /** |
| 24 | + * Brief description of the program |
| 25 | + */ |
| 26 | + readonly description: string; |
| 27 | + |
| 28 | + /** |
| 29 | + * Type identifier for the program |
| 30 | + */ |
| 31 | + readonly type: string; |
| 32 | + |
| 33 | + /** |
| 34 | + * Parse raw on-chain accounts into a standardized configuration object |
| 35 | + * for the specific program. |
| 36 | + * |
| 37 | + * @param accounts Array of account data from the blockchain |
| 38 | + * @param cluster The Pyth cluster where the accounts were fetched from |
| 39 | + * @returns Program-specific configuration object |
| 40 | + */ |
| 41 | + getConfigFromRawAccounts(accounts: any[], cluster: PythCluster): any; |
| 42 | + |
| 43 | + /** |
| 44 | + * Format the configuration for downloading as a JSON file |
| 45 | + * |
| 46 | + * @param config The program's configuration object |
| 47 | + * @returns Configuration formatted for download |
| 48 | + */ |
| 49 | + getDownloadableConfig(config: any): any; |
| 50 | + |
| 51 | + /** |
| 52 | + * Validate an uploaded configuration against the current configuration |
| 53 | + * |
| 54 | + * @param existingConfig Current configuration |
| 55 | + * @param uploadedConfig Configuration from an uploaded file |
| 56 | + * @returns Object with validation result and optional error message |
| 57 | + */ |
| 58 | + validateUploadedConfig( |
| 59 | + existingConfig: any, |
| 60 | + uploadedConfig: any, |
| 61 | + cluster: PythCluster, |
| 62 | + ): { |
| 63 | + isValid: boolean; |
| 64 | + error?: string; |
| 65 | + changes?: any; |
| 66 | + }; |
| 67 | + |
| 68 | + /** |
| 69 | + * Generate the necessary instructions to apply configuration changes |
| 70 | + * |
| 71 | + * @param changes Configuration changes to apply |
| 72 | + * @param cluster The Pyth cluster where the changes will be applied |
| 73 | + * @param accounts Additional context needed for generating instructions |
| 74 | + * @returns Promise resolving to an array of TransactionInstructions |
| 75 | + */ |
| 76 | + generateInstructions( |
| 77 | + changes: any, |
| 78 | + cluster: PythCluster, |
| 79 | + accounts: { |
| 80 | + fundingAccount: PublicKey; |
| 81 | + [key: string]: any; |
| 82 | + }, |
| 83 | + ): Promise<TransactionInstruction[]>; |
| 84 | + |
| 85 | + /** |
| 86 | + * Check if the program is available on the specified cluster |
| 87 | + * |
| 88 | + * @param cluster The Pyth cluster to check |
| 89 | + * @returns True if the program is available on the cluster |
| 90 | + */ |
| 91 | + isAvailableOnCluster(cluster: PythCluster): boolean; |
| 92 | +} |
0 commit comments