@@ -24,8 +24,6 @@ import { ContractArtifact, FunctionAbi, getAllFunctionAbis } from '@aztec/aztec.
2424import { SchnorrAccountContract } from '@aztec/accounts/schnorr' ;
2525import { getAccountContractAddress } from '@aztec/aztec.js/account' ;
2626
27-
28-
2927@Injectable ( )
3028export class AztecTreasuryService extends TreasuryService {
3129
@@ -47,47 +45,45 @@ export class AztecTreasuryService extends TreasuryService {
4745
4846 const fullConfig = { ...getPXEConfig ( ) , l1Contracts, proverEnabled : true } ;
4947
48+ const accountContract = new SchnorrAccountContract ( deriveSigningKey ( Fr . fromString ( privateKey ) ) ) ;
49+ const solverAddress = ( await getAccountContractAddress ( accountContract , Fr . fromString ( privateKey ) , Fr . fromString ( privateSalt ) ) ) . toString ( ) ;
50+
5051 const store = await createStore ( request . address , {
5152 dataDirectory : this . configService . storePath ,
5253 dataStoreMapSizeKb : 1e6 ,
5354 } ) ;
5455
55- const wallet = await TestWallet . create ( provider , fullConfig , { store } ) ;
56-
57- const accountManager = await wallet . createSchnorrAccount (
58- Fr . fromString ( privateKey ) ,
59- Fr . fromString ( privateSalt ) ,
60- deriveSigningKey ( Fr . fromString ( privateKey ) ) ,
61- ) ;
56+ const pxe = await TestWallet . create ( provider , fullConfig , { store } ) ;
6257
6358 const sponsoredFPCInstance = await getContractInstanceFromInstantiationParams (
6459 SponsoredFPCContract . artifact ,
6560 { salt : new Fr ( 0 ) } ,
6661 ) ;
6762
68- await wallet . registerContract (
63+ await pxe . registerContract (
6964 sponsoredFPCInstance ,
7065 SponsoredFPCContract . artifact ,
7166 ) ;
7267
73- const token = await TokenContract . at ( AztecAddress . fromString ( request . tokenContract ) , wallet ) ;
74- const contractInstance = await TrainContract . at ( AztecAddress . fromString ( request . contractAddress ) , wallet ) ;
68+ await pxe . createSchnorrAccount (
69+ Fr . fromString ( privateKey ) ,
70+ Fr . fromString ( privateSalt ) ,
71+ deriveSigningKey ( Fr . fromString ( privateKey ) ) ,
72+ ) ;
7573
7674 const contractInstanceWithAddress = await provider . getContract ( AztecAddress . fromString ( request . contractAddress ) ) ;
77- await wallet . registerContract ( contractInstanceWithAddress , TrainContract . artifact ) ;
75+ await pxe . registerContract ( contractInstanceWithAddress , TrainContract . artifact ) ;
7876
7977 const tokenInstance = await provider . getContract ( AztecAddress . fromString ( request . tokenContract ) ) ;
80- await wallet . registerContract ( tokenInstance , TokenContract . artifact )
78+ await pxe . registerContract ( tokenInstance , TokenContract . artifact )
8179
8280 const contractFunctionInteraction : FunctionInteraction = JSON . parse ( request . unsignedTxn ) ;
8381 let authWitnesses : AuthWitness [ ] = [ ] ;
8482
8583 if ( contractFunctionInteraction . authwiths ) {
86-
87- contractFunctionInteraction . authwiths . forEach ( async ( authWith ) => {
88-
89- const requestContractClass = await provider . getContract ( AztecAddress . fromString ( authWith . interactionAddress ) )
90- const contractClassMetadata = await wallet . getContractClassMetadata ( requestContractClass . currentContractClassId , true )
84+ for ( const authWith of contractFunctionInteraction . authwiths ) {
85+ const requestContractClass = await provider . getContract ( AztecAddress . fromString ( authWith . interactionAddress ) ) ;
86+ const contractClassMetadata = await pxe . getContractClassMetadata ( requestContractClass . currentContractClassId , true ) ;
9187
9288 if ( ! contractClassMetadata . artifact ) {
9389 throw new BadRequestException ( `Artifact not registered` ) ;
@@ -99,33 +95,31 @@ export class AztecTreasuryService extends TreasuryService {
9995 throw new BadRequestException ( "Unable to get function ABI" ) ;
10096 }
10197
102- authWith . args . unshift ( ) ;
98+ authWith . args . unshift ( solverAddress ) ;
10399
104100 const functionInteraction = new ContractFunctionInteraction (
105- wallet ,
101+ pxe ,
106102 AztecAddress . fromString ( authWith . interactionAddress ) ,
107103 functionAbi ,
108- [
109- ...authWith . args
110- ] ,
104+ [ ...authWith . args ] ,
111105 ) ;
112106
113107 const intent : ContractFunctionInteractionCallIntent = {
114108 caller : AztecAddress . fromString ( authWith . callerAddress ) ,
115109 action : functionInteraction ,
116110 } ;
117111
118- const witness = await wallet . createAuthWit (
119- AztecAddress . fromString ( authWith . senderAddress ) ,
112+ const witness = await pxe . createAuthWit (
113+ AztecAddress . fromString ( solverAddress ) ,
120114 intent ,
121115 ) ;
122116
123117 authWitnesses . push ( witness ) ;
124- } ) ;
118+ }
125119 }
126120
127121 const requestcontractClass = await provider . getContract ( AztecAddress . fromString ( contractFunctionInteraction . interactionAddress ) )
128- const contractClassMetadata = await wallet . getContractClassMetadata ( requestcontractClass . currentContractClassId , true )
122+ const contractClassMetadata = await pxe . getContractClassMetadata ( requestcontractClass . currentContractClassId , true )
129123
130124 if ( ! contractClassMetadata . artifact ) {
131125 throw new BadRequestException ( `Artifact not registered` ) ;
@@ -134,7 +128,7 @@ export class AztecTreasuryService extends TreasuryService {
134128 const functionAbi = getFunctionAbi ( contractClassMetadata . artifact , contractFunctionInteraction . functionName ) ;
135129
136130 const functionInteraction = new ContractFunctionInteraction (
137- wallet ,
131+ pxe ,
138132 AztecAddress . fromString ( contractFunctionInteraction . interactionAddress ) ,
139133 functionAbi ,
140134 [
@@ -156,7 +150,7 @@ export class AztecTreasuryService extends TreasuryService {
156150 } ,
157151 ) ;
158152
159- const provenTx = await wallet . proveTx ( executionPayload , sendOptions ) ;
153+ const provenTx = await pxe . proveTx ( executionPayload , sendOptions ) ;
160154
161155 const tx = new Tx (
162156 provenTx . getTxHash ( ) ,
@@ -170,7 +164,6 @@ export class AztecTreasuryService extends TreasuryService {
170164 const signedTxn = JSON . stringify ( { signedTx : signedTxHex } ) ;
171165
172166 return { signedTxn } ;
173-
174167 }
175168 catch ( error ) {
176169 throw new BadRequestException ( `Invalid unsigned transaction: ${ error . message } ` ) ;
@@ -206,14 +199,12 @@ export class AztecTreasuryService extends TreasuryService {
206199
207200 const wallet = await TestWallet . create ( provider , fullConfig , { store } ) ;
208201
209-
210202 const sponsoredFPCInstance = await getContractInstanceFromInstantiationParams (
211203 SponsoredFPCContract . artifact ,
212204 { salt : new Fr ( 0 ) } ,
213205 ) ;
214206
215207 const paymentMethod = new SponsoredFeePaymentMethod ( sponsoredFPCInstance . address ) ;
216-
217208 const schnorrAccount = await wallet . createSchnorrAccount (
218209 pkKey ,
219210 salt ,
@@ -269,7 +260,6 @@ interface FunctionInteraction {
269260 functionName : string ,
270261 args : any [ ] ,
271262 callerAddress ?: string ,
272- senderAddress ?: string ,
273263 authwiths ?: FunctionInteraction [ ] ,
274264}
275265
0 commit comments