@@ -305,17 +305,84 @@ class SolanaChainStrategy extends BaseChainStrategy {
305305 }
306306}
307307
308- // Strategy Factory
308+ class AptosChainStrategy extends BaseChainStrategy {
309+ private static readonly REQUIRED_FIELDS = {
310+ tokenAdminRegistry : ( config : ChainsConfig [ string ] ) => ! config . tokenAdminRegistry ?. address ,
311+ mcms : ( config : ChainsConfig [ string ] ) => ! config . mcms ?. address ,
312+ } as const
313+
314+ validateChainData (
315+ chainId : number | string | undefined ,
316+ networkId : string ,
317+ chainConfig : ChainsConfig [ string ] ,
318+ selectorEntry ?: { selector : string ; name : string } ,
319+ supportedChain ?: SupportedChain
320+ ) : {
321+ isValid : boolean
322+ missingFields : string [ ]
323+ validatedData ?: ChainDetails
324+ } {
325+ const baseValidation = this . validateBaseFields ( chainId , networkId , chainConfig , selectorEntry , supportedChain )
326+
327+ if ( ! baseValidation . isValid || ! baseValidation . baseData ) {
328+ return {
329+ isValid : false ,
330+ missingFields : baseValidation . missingFields ,
331+ }
332+ }
333+
334+ const missingFields = this . validateAptosRequirements ( chainConfig )
335+
336+ if ( missingFields . length > 0 ) {
337+ logger . warn ( {
338+ message : "Aptos chain configuration incomplete" ,
339+ requestId : this . requestId ,
340+ networkId,
341+ missingFields,
342+ } )
343+
344+ return {
345+ isValid : false ,
346+ missingFields,
347+ }
348+ }
349+
350+ const validatedData : ChainDetails = {
351+ ...( baseValidation . baseData as ChainDetails ) ,
352+ tokenAdminRegistry : chainConfig . tokenAdminRegistry ?. address ?? "" ,
353+ mcms : chainConfig . mcms ?. address ?? "" ,
354+ }
355+
356+ return {
357+ isValid : true ,
358+ missingFields : [ ] ,
359+ validatedData,
360+ }
361+ }
362+
363+ private validateAptosRequirements ( chainConfig : ChainsConfig [ string ] ) : string [ ] {
364+ return Object . entries ( AptosChainStrategy . REQUIRED_FIELDS )
365+ . filter ( ( [ _ , validator ] ) => validator ( chainConfig ) )
366+ . map ( ( [ field ] ) => field )
367+ }
368+ }
369+
309370class ChainStrategyFactory {
371+ private static readonly strategies = new Map < ChainType , new ( requestId : string ) => IChainProcessingStrategy > ( [
372+ [ "evm" , EvmChainStrategy ] ,
373+ [ "solana" , SolanaChainStrategy ] ,
374+ [ "aptos" , AptosChainStrategy ] ,
375+ ] )
376+
310377 static getStrategy ( chainType : ChainType , requestId : string ) : IChainProcessingStrategy {
311- switch ( chainType ) {
312- case "evm" :
313- return new EvmChainStrategy ( requestId )
314- case "solana" :
315- return new SolanaChainStrategy ( requestId )
316- default :
317- throw new Error ( `Unsupported chain type: ${ chainType } ` )
378+ const StrategyClass = this . strategies . get ( chainType )
379+
380+ if ( ! StrategyClass ) {
381+ const supportedTypes = Array . from ( this . strategies . keys ( ) ) . join ( ", " )
382+ throw new Error ( `Chain type "${ chainType } " not supported. Available strategies: ${ supportedTypes } ` )
318383 }
384+
385+ return new StrategyClass ( requestId )
319386 }
320387}
321388
0 commit comments