@@ -54,12 +54,21 @@ export async function registerSwapContracts(
5454 const { TokenContract, TokenContractArtifact } = await import ( '@aztec/noir-contracts.js/Token' ) ;
5555 const { AMMContract, AMMContractArtifact } = await import ( '../../contracts/target/AMM' ) ;
5656
57+ // Determine subscription FPC for sponsored swaps
58+ const subFPC = network . subscriptionFPC ;
59+ const fpcAddress = subFPC ? AztecAddressClass . fromString ( subFPC . address ) : undefined ;
60+
5761 // Check which contracts are already registered
58- const [ ammMetadata , gregoCoinMetadata , gregoCoinPremiumMetadata ] = await wallet . batch ( [
62+ const metadataChecks : { name : 'getContractMetadata' ; args : [ AztecAddress ] } [ ] = [
5963 { name : 'getContractMetadata' , args : [ ammAddress ] } ,
6064 { name : 'getContractMetadata' , args : [ gregoCoinAddress ] } ,
6165 { name : 'getContractMetadata' , args : [ gregoCoinPremiumAddress ] } ,
62- ] ) ;
66+ ] ;
67+ if ( fpcAddress ) {
68+ metadataChecks . push ( { name : 'getContractMetadata' , args : [ fpcAddress ] } ) ;
69+ }
70+ const metadataResults = await wallet . batch ( metadataChecks ) ;
71+ const [ ammMetadata , gregoCoinMetadata , gregoCoinPremiumMetadata ] = metadataResults ;
6372
6473 // Reconstruct contract instances for unregistered contracts
6574 const [ ammInstance , gregoCoinInstance , gregoCoinPremiumInstance ] = await Promise . all ( [
@@ -100,6 +109,23 @@ export async function registerSwapContracts(
100109 registrationBatch . push ( { name : 'registerContract' , args : [ gregoCoinPremiumInstance , undefined , undefined ] } ) ;
101110 }
102111
112+ // Register subscription FPC for sponsored swaps (if configured and not yet registered)
113+ if ( subFPC && fpcAddress ) {
114+ const fpcMetadata = metadataResults [ 3 ] ;
115+ if ( ! fpcMetadata ?. result ?. instance ) {
116+ const instance = await node . getContract ( fpcAddress ) ;
117+ if ( ! instance ) {
118+ throw new Error ( `Subscription FPC at ${ subFPC . address } not found on-chain` ) ;
119+ }
120+ const secretKey = Fr . fromString ( subFPC . secretKey ) ;
121+ const { SubscriptionFPCContractArtifact } = await import ( '@gregojuice/contracts/artifacts/SubscriptionFPC' ) ;
122+ registrationBatch . push ( {
123+ name : 'registerContract' ,
124+ args : [ instance , SubscriptionFPCContractArtifact , secretKey ] ,
125+ } ) ;
126+ }
127+ }
128+
103129 // Only call batch if there are contracts to register
104130 if ( registrationBatch . length > 0 ) {
105131 await wallet . batch ( registrationBatch ) ;
0 commit comments