@@ -27,6 +27,7 @@ import pReduce from 'p-reduce'
2727import { SubgraphClient , QueryResult } from '../subgraph-client'
2828import gql from 'graphql-tag'
2929import { getEscrowAccounts } from './escrow-accounts'
30+ import { HDNodeWallet , Wallet } from 'ethers'
3031
3132// every 15 minutes
3233const RAV_CHECK_INTERVAL_MS = 900_000
@@ -52,6 +53,7 @@ interface TapCollectorOptions {
5253 networkSpecification : spec . NetworkSpecification
5354 tapSubgraph : SubgraphClient
5455 networkSubgraph : SubgraphClient
56+ legacyMnemonics : string [ ]
5557}
5658
5759interface ValidRavs {
@@ -109,6 +111,7 @@ export class TapCollector {
109111 declare networkSubgraph : SubgraphClient
110112 declare finalityTime : number
111113 declare indexerAddress : Address
114+ declare legacyMnemonics : string [ ]
112115
113116 // eslint-disable-next-line @typescript-eslint/no-empty-function -- Private constructor to prevent direct instantiation
114117 private constructor ( ) { }
@@ -123,6 +126,7 @@ export class TapCollector {
123126 networkSpecification,
124127 tapSubgraph,
125128 networkSubgraph,
129+ legacyMnemonics,
126130 } : TapCollectorOptions ) : TapCollector {
127131 const collector = new TapCollector ( )
128132 collector . logger = logger . child ( { component : 'TapCollector' } )
@@ -137,14 +141,21 @@ export class TapCollector {
137141 collector . protocolNetwork = networkSpecification . networkIdentifier
138142 collector . tapSubgraph = tapSubgraph
139143 collector . networkSubgraph = networkSubgraph
144+ collector . legacyMnemonics = legacyMnemonics
140145
141146 const { voucherRedemptionThreshold, finalityTime, address } =
142147 networkSpecification . indexerOptions
143148 collector . ravRedemptionThreshold = voucherRedemptionThreshold
144149 collector . finalityTime = finalityTime
145150 collector . indexerAddress = address
146151
147- collector . logger . info ( `[TAPv1] RAV processing is initiated` )
152+ if ( legacyMnemonics . length > 0 ) {
153+ collector . logger . info (
154+ `[TAPv1] RAV processing is initiated with ${ legacyMnemonics . length } legacy mnemonic(s) for old allocation support` ,
155+ )
156+ } else {
157+ collector . logger . info ( `[TAPv1] RAV processing is initiated` )
158+ }
148159 collector . startRAVProcessing ( )
149160 return collector
150161 }
@@ -712,6 +723,37 @@ export class TapCollector {
712723 )
713724 }
714725
726+ private getAllocationSigner ( allocation : Allocation ) : {
727+ signer : ReturnType < typeof allocationSigner >
728+ isLegacy : boolean
729+ } {
730+ // Try current wallet first
731+ try {
732+ return {
733+ signer : allocationSigner ( this . transactionManager . wallet , allocation ) ,
734+ isLegacy : false ,
735+ }
736+ } catch {
737+ // Current wallet doesn't match, try legacy mnemonics
738+ }
739+
740+ // Try legacy mnemonics
741+ for ( const mnemonic of this . legacyMnemonics ) {
742+ try {
743+ const legacyWallet = Wallet . fromPhrase ( mnemonic ) as HDNodeWallet
744+ return { signer : allocationSigner ( legacyWallet , allocation ) , isLegacy : true }
745+ } catch {
746+ // This mnemonic doesn't match either, try next
747+ continue
748+ }
749+ }
750+
751+ throw new Error (
752+ `[TAPv1] No mnemonic found that can sign for allocation ${ allocation . id } . ` +
753+ `Tried current operator wallet and ${ this . legacyMnemonics . length } legacy mnemonic(s).` ,
754+ )
755+ }
756+
715757 public async redeemRav (
716758 logger : Logger ,
717759 allocation : Allocation ,
@@ -722,8 +764,13 @@ export class TapCollector {
722764
723765 const escrow = this . tapContracts
724766
767+ const { signer, isLegacy } = this . getAllocationSigner ( allocation )
768+ if ( isLegacy ) {
769+ logger . info ( `[TAPv1] Using legacy mnemonic to sign for allocation ${ allocation . id } ` )
770+ }
771+
725772 const proof = await tapAllocationIdProof (
726- allocationSigner ( this . transactionManager . wallet , allocation ) ,
773+ signer ,
727774 parseInt ( this . protocolNetwork . split ( ':' ) [ 1 ] ) ,
728775 sender ,
729776 toAddress ( rav . allocationId . toString ( ) ) ,
@@ -732,6 +779,7 @@ export class TapCollector {
732779 this . logger . debug ( `[TAPv1] Computed allocationIdProof` , {
733780 allocationId : rav . allocationId ,
734781 proof,
782+ isLegacySigner : isLegacy ,
735783 } )
736784 // Submit the signed RAV on chain
737785 const txReceipt = await this . transactionManager . executeTransaction (
0 commit comments