@@ -17,6 +17,7 @@ import {
17
17
} from '@aztec/aztec.js' ;
18
18
import { createEthereumChain , createL1Clients } from '@aztec/ethereum' ;
19
19
import { Fr } from '@aztec/foundation/fields' ;
20
+ import { Timer } from '@aztec/foundation/timer' ;
20
21
import { AMMContract } from '@aztec/noir-contracts.js/AMM' ;
21
22
import { EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken' ;
22
23
import { TokenContract } from '@aztec/noir-contracts.js/Token' ;
@@ -85,7 +86,7 @@ export class BotFactory {
85
86
const liquidityToken = await this . setupTokenContract ( wallet , this . config . tokenSalt , 'BotLPToken' , 'BOTLP' ) ;
86
87
const amm = await this . setupAmmContract ( wallet , this . config . tokenSalt , token0 , token1 , liquidityToken ) ;
87
88
88
- await this . fundAmm ( wallet , amm , token0 , token1 ) ;
89
+ await this . fundAmm ( wallet , amm , token0 , token1 , liquidityToken ) ;
89
90
this . log . info ( `AMM initialized and funded` ) ;
90
91
91
92
return { wallet, amm, token0, token1, pxe : this . pxe } ;
@@ -110,7 +111,9 @@ export class BotFactory {
110
111
const isInit = ( await this . pxe . getContractMetadata ( account . getAddress ( ) ) ) . isContractInitialized ;
111
112
if ( isInit ) {
112
113
this . log . info ( `Account at ${ account . getAddress ( ) . toString ( ) } already initialized` ) ;
114
+ const timer = new Timer ( ) ;
113
115
const wallet = await account . register ( ) ;
116
+ this . log . info ( `Account at ${ account . getAddress ( ) } registered. duration=${ timer . ms ( ) } ` ) ;
114
117
return wallet ;
115
118
} else {
116
119
const address = account . getAddress ( ) ;
@@ -232,7 +235,15 @@ export class BotFactory {
232
235
amm : AMMContract ,
233
236
token0 : TokenContract ,
234
237
token1 : TokenContract ,
238
+ lpToken : TokenContract ,
235
239
) : Promise < void > {
240
+ const getPrivateBalances = ( ) =>
241
+ Promise . all ( [
242
+ token0 . methods . balance_of_private ( wallet . getAddress ( ) ) ,
243
+ token1 . methods . balance_of_private ( wallet . getAddress ( ) ) ,
244
+ lpToken . methods . balance_of_private ( wallet . getAddress ( ) ) ,
245
+ ] ) ;
246
+
236
247
const nonce = Fr . random ( ) ;
237
248
238
249
// keep some tokens for swapping
@@ -241,6 +252,12 @@ export class BotFactory {
241
252
const amount1Max = MINT_BALANCE / 2 ;
242
253
const amount1Min = MINT_BALANCE / 4 ;
243
254
255
+ const [ t0Bal , t1Bal , lpBal ] = await getPrivateBalances ( ) ;
256
+
257
+ this . log . info (
258
+ `Minting ${ MINT_BALANCE } tokens of each BotToken0 and BotToken1. Current private balances of ${ wallet . getAddress ( ) } : token0=${ t0Bal } , token1=${ t1Bal } , lp=${ lpBal } ` ,
259
+ ) ;
260
+
244
261
const token0Authwit = await wallet . createAuthWit ( {
245
262
caller : amm . address ,
246
263
action : token0 . methods . transfer_to_public ( wallet . getAddress ( ) , amm . address , amount0Max , nonce ) ,
@@ -250,7 +267,6 @@ export class BotFactory {
250
267
action : token1 . methods . transfer_to_public ( wallet . getAddress ( ) , amm . address , amount1Max , nonce ) ,
251
268
} ) ;
252
269
253
- this . log . info ( `Minting tokens` ) ;
254
270
const mintTx = new BatchCall ( wallet , [
255
271
token0 . methods . mint_to_private ( wallet . getAddress ( ) , wallet . getAddress ( ) , MINT_BALANCE ) ,
256
272
token1 . methods . mint_to_private ( wallet . getAddress ( ) , wallet . getAddress ( ) , MINT_BALANCE ) ,
@@ -259,13 +275,18 @@ export class BotFactory {
259
275
this . log . info ( `Sent mint tx: ${ await mintTx . getTxHash ( ) } ` ) ;
260
276
await mintTx . wait ( { timeout : this . config . txMinedWaitSeconds } ) ;
261
277
262
- this . log . info ( `Funding AMM` ) ;
263
278
const addLiquidityTx = amm . methods . add_liquidity ( amount0Max , amount1Max , amount0Min , amount1Min , nonce ) . send ( {
264
279
authWitnesses : [ token0Authwit , token1Authwit ] ,
265
280
} ) ;
266
281
267
282
this . log . info ( `Sent tx to add liquidity to the AMM: ${ await addLiquidityTx . getTxHash ( ) } ` ) ;
268
283
await addLiquidityTx . wait ( { timeout : this . config . txMinedWaitSeconds } ) ;
284
+ this . log . info ( `Liquidity added` ) ;
285
+
286
+ const [ newT0Bal , newT1Bal , newLPBal ] = await getPrivateBalances ( ) ;
287
+ this . log . info (
288
+ `Updated private balances of ${ wallet . getAddress ( ) } after minting and funding AMM: token0=${ newT0Bal } , token1=${ newT1Bal } , lp=${ newLPBal } ` ,
289
+ ) ;
269
290
}
270
291
271
292
private async registerOrDeployContract < T extends ContractBase > (
0 commit comments