@aztec/bot 0.0.1-commit.43c09e3f → 0.0.1-commit.4d3c002
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/amm_bot.d.ts +4 -4
- package/dest/amm_bot.d.ts.map +1 -1
- package/dest/amm_bot.js +24 -17
- package/dest/base_bot.d.ts +6 -6
- package/dest/base_bot.d.ts.map +1 -1
- package/dest/base_bot.js +21 -32
- package/dest/bot.d.ts +4 -4
- package/dest/bot.d.ts.map +1 -1
- package/dest/bot.js +5 -8
- package/dest/config.d.ts +34 -18
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +39 -12
- package/dest/cross_chain_bot.d.ts +54 -0
- package/dest/cross_chain_bot.d.ts.map +1 -0
- package/dest/cross_chain_bot.js +134 -0
- package/dest/factory.d.ts +24 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +282 -72
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1_to_l2_seeding.d.ts +8 -0
- package/dest/l1_to_l2_seeding.d.ts.map +1 -0
- package/dest/l1_to_l2_seeding.js +63 -0
- package/dest/runner.d.ts +3 -3
- package/dest/runner.d.ts.map +1 -1
- package/dest/runner.js +17 -1
- package/dest/store/bot_store.d.ts +30 -5
- package/dest/store/bot_store.d.ts.map +1 -1
- package/dest/store/bot_store.js +37 -6
- package/dest/store/index.d.ts +2 -2
- package/dest/store/index.d.ts.map +1 -1
- package/dest/utils.js +3 -3
- package/package.json +16 -13
- package/src/amm_bot.ts +24 -19
- package/src/base_bot.ts +15 -33
- package/src/bot.ts +8 -10
- package/src/config.ts +44 -16
- package/src/cross_chain_bot.ts +203 -0
- package/src/factory.ts +337 -73
- package/src/index.ts +1 -0
- package/src/l1_to_l2_seeding.ts +79 -0
- package/src/runner.ts +18 -5
- package/src/store/bot_store.ts +60 -5
- package/src/store/index.ts +1 -1
- package/src/utils.ts +3 -3
package/dest/factory.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
2
1
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
3
|
-
import {
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
4
3
|
import { BatchCall, NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
5
4
|
import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
|
|
6
5
|
import { FeeJuicePaymentMethodWithClaim } from '@aztec/aztec.js/fee';
|
|
@@ -8,19 +7,27 @@ import { deriveKeys } from '@aztec/aztec.js/keys';
|
|
|
8
7
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
9
8
|
import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
|
|
10
9
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
10
|
+
import { getFeeJuiceBalance } from '@aztec/aztec.js/utils';
|
|
11
|
+
import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
11
12
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
12
13
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
14
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
13
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
16
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
17
|
import { Timer } from '@aztec/foundation/timer';
|
|
15
18
|
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
16
19
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
17
20
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
18
|
-
import {
|
|
21
|
+
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
22
|
+
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
19
23
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
20
24
|
import { SupportedTokenContracts } from './config.js';
|
|
25
|
+
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
21
26
|
import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
|
|
22
27
|
const MINT_BALANCE = 1e12;
|
|
23
28
|
const MIN_BALANCE = 1e3;
|
|
29
|
+
const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
|
|
30
|
+
const FEE_JUICE_TOP_UP_TARGET = 10_000n * 10n ** 18n;
|
|
24
31
|
export class BotFactory {
|
|
25
32
|
config;
|
|
26
33
|
wallet;
|
|
@@ -35,14 +42,18 @@ export class BotFactory {
|
|
|
35
42
|
this.aztecNode = aztecNode;
|
|
36
43
|
this.aztecNodeAdmin = aztecNodeAdmin;
|
|
37
44
|
this.log = createLogger('bot');
|
|
45
|
+
// Set fee padding on the wallet so that all transactions during setup
|
|
46
|
+
// (token deploy, minting, etc.) use the configured padding, not the default.
|
|
47
|
+
this.wallet.setMinFeePadding(config.minFeePadding);
|
|
38
48
|
}
|
|
39
49
|
/**
|
|
40
50
|
* Initializes a new bot by setting up the sender account, registering the recipient,
|
|
41
51
|
* deploying the token contract, and minting tokens if necessary.
|
|
42
52
|
*/ async setup() {
|
|
43
53
|
const defaultAccountAddress = await this.setupAccount();
|
|
44
|
-
const recipient = (await this.wallet.
|
|
45
|
-
const token = await this.
|
|
54
|
+
const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
|
|
55
|
+
const token = await this.setupTokenWithOptionalEarlyRefuel(defaultAccountAddress);
|
|
56
|
+
await this.ensureFeeJuiceBalance(defaultAccountAddress, token);
|
|
46
57
|
await this.mintTokens(token, defaultAccountAddress);
|
|
47
58
|
return {
|
|
48
59
|
wallet: this.wallet,
|
|
@@ -54,7 +65,8 @@ export class BotFactory {
|
|
|
54
65
|
}
|
|
55
66
|
async setupAmm() {
|
|
56
67
|
const defaultAccountAddress = await this.setupAccount();
|
|
57
|
-
const token0 = await this.
|
|
68
|
+
const token0 = await this.setupTokenContractWithOptionalEarlyRefuel(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
|
|
69
|
+
await this.ensureFeeJuiceBalance(defaultAccountAddress, token0);
|
|
58
70
|
const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
|
|
59
71
|
const liquidityToken = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotLPToken', 'BOTLP');
|
|
60
72
|
const amm = await this.setupAmmContract(defaultAccountAddress, this.config.tokenSalt, token0, token1, liquidityToken);
|
|
@@ -70,6 +82,65 @@ export class BotFactory {
|
|
|
70
82
|
};
|
|
71
83
|
}
|
|
72
84
|
/**
|
|
85
|
+
* Initializes the cross-chain bot by deploying TestContract, creating an L1 client,
|
|
86
|
+
* seeding initial L1→L2 messages, and waiting for the first to be ready.
|
|
87
|
+
*/ async setupCrossChain() {
|
|
88
|
+
const defaultAccountAddress = await this.setupAccount();
|
|
89
|
+
// Create L1 client (same pattern as bridgeL1FeeJuice)
|
|
90
|
+
const l1RpcUrls = this.config.l1RpcUrls;
|
|
91
|
+
if (!l1RpcUrls?.length) {
|
|
92
|
+
throw new Error('L1 RPC URLs required for cross-chain bot');
|
|
93
|
+
}
|
|
94
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
95
|
+
if (!mnemonicOrPrivateKey) {
|
|
96
|
+
throw new Error('L1 mnemonic or private key required for cross-chain bot');
|
|
97
|
+
}
|
|
98
|
+
const { l1ChainId, l1ContractAddresses } = await this.aztecNode.getNodeInfo();
|
|
99
|
+
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
100
|
+
const l1Client = createExtendedL1Client(chain.rpcUrls, mnemonicOrPrivateKey, chain.chainInfo);
|
|
101
|
+
// Fetch Rollup version (needed for Inbox L2Actor struct)
|
|
102
|
+
const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
|
|
103
|
+
const rollupVersion = await rollupContract.getVersion();
|
|
104
|
+
// Deploy TestContract
|
|
105
|
+
const contract = await this.setupTestContract(defaultAccountAddress);
|
|
106
|
+
// Recover any pending messages from store (clean up stale ones first)
|
|
107
|
+
await this.store.cleanupOldPendingMessages();
|
|
108
|
+
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
109
|
+
// Seed initial L1→L2 messages if pipeline is empty
|
|
110
|
+
const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
|
|
111
|
+
for(let i = 0; i < seedCount; i++){
|
|
112
|
+
await seedL1ToL2Message(l1Client, EthAddress.fromString(l1ContractAddresses.inboxAddress.toString()), contract.address, rollupVersion, this.store, this.log);
|
|
113
|
+
}
|
|
114
|
+
// Block until at least one message is ready
|
|
115
|
+
const allMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
116
|
+
if (allMessages.length > 0) {
|
|
117
|
+
this.log.info(`Waiting for first L1→L2 message to be ready...`);
|
|
118
|
+
const firstMsg = allMessages[0];
|
|
119
|
+
await waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(firstMsg.msgHash), {
|
|
120
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
121
|
+
});
|
|
122
|
+
this.log.info(`First L1→L2 message is ready`);
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
wallet: this.wallet,
|
|
126
|
+
defaultAccountAddress,
|
|
127
|
+
contract,
|
|
128
|
+
node: this.aztecNode,
|
|
129
|
+
l1Client,
|
|
130
|
+
rollupVersion
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async setupTestContract(deployer) {
|
|
134
|
+
const deployOpts = {
|
|
135
|
+
from: deployer,
|
|
136
|
+
contractAddressSalt: this.config.tokenSalt,
|
|
137
|
+
universalDeploy: true
|
|
138
|
+
};
|
|
139
|
+
const deploy = TestContract.deploy(this.wallet);
|
|
140
|
+
const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
|
|
141
|
+
return TestContract.at(instance.address, this.wallet);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
73
144
|
* Checks if the sender account contract is initialized, and initializes it if necessary.
|
|
74
145
|
* @returns The sender wallet.
|
|
75
146
|
*/ async setupAccount() {
|
|
@@ -85,14 +156,9 @@ export class BotFactory {
|
|
|
85
156
|
async setupAccountWithPrivateKey(secret) {
|
|
86
157
|
const salt = this.config.senderSalt ?? Fr.ONE;
|
|
87
158
|
const signingKey = deriveSigningKey(secret);
|
|
88
|
-
const
|
|
89
|
-
secret,
|
|
90
|
-
salt,
|
|
91
|
-
contract: new SchnorrAccountContract(signingKey)
|
|
92
|
-
};
|
|
93
|
-
const accountManager = await this.wallet.createAccount(accountData);
|
|
159
|
+
const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
94
160
|
const metadata = await this.wallet.getContractMetadata(accountManager.address);
|
|
95
|
-
if (metadata.
|
|
161
|
+
if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
|
|
96
162
|
this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
|
|
97
163
|
const timer = new Timer();
|
|
98
164
|
const address = accountManager.address;
|
|
@@ -105,15 +171,10 @@ export class BotFactory {
|
|
|
105
171
|
const claim = await this.getOrCreateBridgeClaim(address);
|
|
106
172
|
const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
|
|
107
173
|
const deployMethod = await accountManager.getDeployMethod();
|
|
108
|
-
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
109
|
-
const gasSettings = GasSettings.default({
|
|
110
|
-
maxFeesPerGas
|
|
111
|
-
});
|
|
112
174
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
113
|
-
const txHash = await deployMethod.send({
|
|
114
|
-
from:
|
|
175
|
+
const { txHash } = await deployMethod.send({
|
|
176
|
+
from: NO_FROM,
|
|
115
177
|
fee: {
|
|
116
|
-
gasSettings,
|
|
117
178
|
paymentMethod
|
|
118
179
|
},
|
|
119
180
|
wait: NO_WAIT
|
|
@@ -131,21 +192,74 @@ export class BotFactory {
|
|
|
131
192
|
}
|
|
132
193
|
async setupTestAccount() {
|
|
133
194
|
const [initialAccountData] = await getInitialTestAccountsData();
|
|
134
|
-
const
|
|
135
|
-
secret: initialAccountData.secret,
|
|
136
|
-
salt: initialAccountData.salt,
|
|
137
|
-
contract: new SchnorrAccountContract(initialAccountData.signingKey)
|
|
138
|
-
};
|
|
139
|
-
const accountManager = await this.wallet.createAccount(accountData);
|
|
195
|
+
const accountManager = await this.wallet.createSchnorrAccount(initialAccountData.secret, initialAccountData.salt, initialAccountData.signingKey);
|
|
140
196
|
return accountManager.address;
|
|
141
197
|
}
|
|
142
198
|
/**
|
|
199
|
+
* Setup token and refuel first: if the token already exists (restart scenario),
|
|
200
|
+
* run ensureFeeJuiceBalance before any step that might need fee juice. When deploying,
|
|
201
|
+
* use a bridge claim if balance is below threshold.
|
|
202
|
+
*/ async setupTokenWithOptionalEarlyRefuel(sender) {
|
|
203
|
+
const token = await this.getTokenInstance(sender);
|
|
204
|
+
const address = token.address;
|
|
205
|
+
const metadata = await this.wallet.getContractMetadata(address);
|
|
206
|
+
if (metadata.isContractPublished) {
|
|
207
|
+
this.log.info(`Token at ${address.toString()} already deployed, refueling before setup`);
|
|
208
|
+
await this.ensureFeeJuiceBalance(sender, token);
|
|
209
|
+
}
|
|
210
|
+
return this.setupToken(sender);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Setup token0 for AMM with refuel-first behaviour when token already exists.
|
|
214
|
+
*/ async setupTokenContractWithOptionalEarlyRefuel(deployer, contractAddressSalt, name, ticker, decimals = 18) {
|
|
215
|
+
const deployOpts = {
|
|
216
|
+
from: deployer,
|
|
217
|
+
contractAddressSalt,
|
|
218
|
+
universalDeploy: true
|
|
219
|
+
};
|
|
220
|
+
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals);
|
|
221
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
222
|
+
const metadata = await this.wallet.getContractMetadata(instance.address);
|
|
223
|
+
if (metadata.isContractPublished) {
|
|
224
|
+
this.log.info(`Token ${name} at ${instance.address.toString()} already deployed, refueling before setup`);
|
|
225
|
+
const token = TokenContract.at(instance.address, this.wallet);
|
|
226
|
+
await this.ensureFeeJuiceBalance(deployer, token);
|
|
227
|
+
}
|
|
228
|
+
return this.setupTokenContract(deployer, contractAddressSalt, name, ticker, decimals);
|
|
229
|
+
}
|
|
230
|
+
async getTokenInstance(sender) {
|
|
231
|
+
const deployOpts = {
|
|
232
|
+
from: sender,
|
|
233
|
+
contractAddressSalt: this.config.tokenSalt,
|
|
234
|
+
universalDeploy: true
|
|
235
|
+
};
|
|
236
|
+
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
237
|
+
const deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
|
|
238
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
239
|
+
return TokenContract.at(instance.address, this.wallet);
|
|
240
|
+
}
|
|
241
|
+
if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
242
|
+
const tokenSecretKey = Fr.random();
|
|
243
|
+
const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
|
|
244
|
+
const deploy = PrivateTokenContract.deployWithPublicKeys(tokenPublicKeys, this.wallet, MINT_BALANCE, sender);
|
|
245
|
+
const instance = await deploy.getInstance({
|
|
246
|
+
...deployOpts,
|
|
247
|
+
skipInstancePublication: true,
|
|
248
|
+
skipClassPublication: true,
|
|
249
|
+
skipInitialization: false
|
|
250
|
+
});
|
|
251
|
+
return PrivateTokenContract.at(instance.address, this.wallet);
|
|
252
|
+
}
|
|
253
|
+
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
143
256
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
144
|
-
*
|
|
145
|
-
* @
|
|
257
|
+
* Uses a bridge claim for deploy when balance is below threshold to avoid failing before refuel.
|
|
258
|
+
* @param sender - Aztec address to deploy the token contract from.
|
|
259
|
+
* @param existingToken - Optional token instance when called from setupTokenWithOptionalEarlyRefuel.
|
|
260
|
+
* @returns The TokenContract or PrivateTokenContract instance.
|
|
146
261
|
*/ async setupToken(sender) {
|
|
147
262
|
let deploy;
|
|
148
|
-
let tokenInstance;
|
|
149
263
|
const deployOpts = {
|
|
150
264
|
from: sender,
|
|
151
265
|
contractAddressSalt: this.config.tokenSalt,
|
|
@@ -154,8 +268,8 @@ export class BotFactory {
|
|
|
154
268
|
let token;
|
|
155
269
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
156
270
|
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
|
|
157
|
-
|
|
158
|
-
token = TokenContract.at(
|
|
271
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
272
|
+
token = TokenContract.at(instance.address, this.wallet);
|
|
159
273
|
} else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
160
274
|
// Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
|
|
161
275
|
const tokenSecretKey = Fr.random();
|
|
@@ -165,31 +279,17 @@ export class BotFactory {
|
|
|
165
279
|
deployOpts.skipClassPublication = true;
|
|
166
280
|
deployOpts.skipInitialization = false;
|
|
167
281
|
// Register the contract with the secret key before deployment
|
|
168
|
-
tokenInstance = await deploy.getInstance(deployOpts);
|
|
282
|
+
const tokenInstance = await deploy.getInstance(deployOpts);
|
|
169
283
|
token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
|
|
170
284
|
await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
|
|
285
|
+
// The contract constructor initializes private storage vars that need the contract's own nullifier key.
|
|
286
|
+
deployOpts.additionalScopes = [
|
|
287
|
+
tokenInstance.address
|
|
288
|
+
];
|
|
171
289
|
} else {
|
|
172
290
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
173
291
|
}
|
|
174
|
-
|
|
175
|
-
const metadata = await this.wallet.getContractMetadata(address);
|
|
176
|
-
if (metadata.isContractPublished) {
|
|
177
|
-
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
178
|
-
await deploy.register();
|
|
179
|
-
} else {
|
|
180
|
-
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
181
|
-
const txHash = await deploy.send({
|
|
182
|
-
...deployOpts,
|
|
183
|
-
wait: NO_WAIT
|
|
184
|
-
});
|
|
185
|
-
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
|
|
186
|
-
await this.withNoMinTxsPerBlock(async ()=>{
|
|
187
|
-
await waitForTx(this.aztecNode, txHash, {
|
|
188
|
-
timeout: this.config.txMinedWaitSeconds
|
|
189
|
-
});
|
|
190
|
-
return token;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
292
|
+
await this.registerOrDeployContract('token', deploy, deployOpts);
|
|
193
293
|
return token;
|
|
194
294
|
}
|
|
195
295
|
/**
|
|
@@ -216,7 +316,8 @@ export class BotFactory {
|
|
|
216
316
|
const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
217
317
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
218
318
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
219
|
-
const
|
|
319
|
+
const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
|
|
320
|
+
const { receipt: minterReceipt } = await setMinterInteraction.send({
|
|
220
321
|
from: deployer,
|
|
221
322
|
wait: {
|
|
222
323
|
timeout: this.config.txMinedWaitSeconds
|
|
@@ -230,13 +331,13 @@ export class BotFactory {
|
|
|
230
331
|
const getPrivateBalances = ()=>Promise.all([
|
|
231
332
|
token0.methods.balance_of_private(liquidityProvider).simulate({
|
|
232
333
|
from: liquidityProvider
|
|
233
|
-
}),
|
|
334
|
+
}).then((r)=>r.result),
|
|
234
335
|
token1.methods.balance_of_private(liquidityProvider).simulate({
|
|
235
336
|
from: liquidityProvider
|
|
236
|
-
}),
|
|
337
|
+
}).then((r)=>r.result),
|
|
237
338
|
lpToken.methods.balance_of_private(liquidityProvider).simulate({
|
|
238
339
|
from: liquidityProvider
|
|
239
|
-
})
|
|
340
|
+
}).then((r)=>r.result)
|
|
240
341
|
]);
|
|
241
342
|
const authwitNonce = Fr.random();
|
|
242
343
|
// keep some tokens for swapping
|
|
@@ -255,17 +356,19 @@ export class BotFactory {
|
|
|
255
356
|
caller: amm.address,
|
|
256
357
|
call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
|
|
257
358
|
});
|
|
258
|
-
const
|
|
359
|
+
const mintBatch = new BatchCall(this.wallet, [
|
|
259
360
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
260
361
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
261
|
-
])
|
|
362
|
+
]);
|
|
363
|
+
const { receipt: mintReceipt } = await mintBatch.send({
|
|
262
364
|
from: liquidityProvider,
|
|
263
365
|
wait: {
|
|
264
366
|
timeout: this.config.txMinedWaitSeconds
|
|
265
367
|
}
|
|
266
368
|
});
|
|
267
369
|
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
268
|
-
const
|
|
370
|
+
const addLiquidityInteraction = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce);
|
|
371
|
+
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
269
372
|
from: liquidityProvider,
|
|
270
373
|
authWitnesses: [
|
|
271
374
|
token0Authwit,
|
|
@@ -288,24 +391,127 @@ export class BotFactory {
|
|
|
288
391
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
289
392
|
await deploy.register();
|
|
290
393
|
} else {
|
|
291
|
-
|
|
292
|
-
await this.
|
|
293
|
-
|
|
394
|
+
const sender = deployOpts.from === NO_FROM ? undefined : deployOpts.from;
|
|
395
|
+
const balance = sender ? await getFeeJuiceBalance(sender, this.aztecNode) : 0n;
|
|
396
|
+
const useClaim = sender && balance < FEE_JUICE_TOP_UP_THRESHOLD && this.config.feePaymentMethod === 'fee_juice' && !!this.config.l1RpcUrls?.length;
|
|
397
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
398
|
+
if (useClaim && mnemonicOrPrivateKey) {
|
|
399
|
+
const claim = await this.getOrCreateBridgeClaim(sender);
|
|
400
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(sender, claim);
|
|
401
|
+
const { estimatedGas } = await deploy.simulate({
|
|
294
402
|
...deployOpts,
|
|
295
|
-
|
|
403
|
+
fee: {
|
|
404
|
+
estimateGas: true,
|
|
405
|
+
paymentMethod
|
|
406
|
+
}
|
|
296
407
|
});
|
|
297
|
-
this.
|
|
298
|
-
|
|
299
|
-
|
|
408
|
+
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
409
|
+
const gasSettings = GasSettings.from({
|
|
410
|
+
...estimatedGas,
|
|
411
|
+
maxFeesPerGas,
|
|
412
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
300
413
|
});
|
|
301
|
-
|
|
414
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
415
|
+
const { txHash } = await deploy.send({
|
|
416
|
+
...deployOpts,
|
|
417
|
+
fee: {
|
|
418
|
+
gasSettings,
|
|
419
|
+
paymentMethod
|
|
420
|
+
},
|
|
421
|
+
wait: NO_WAIT
|
|
422
|
+
});
|
|
423
|
+
this.log.info(`Sent contract ${name} deploy tx ${txHash.toString()} (using bridge claim, balance was ${balance})`);
|
|
424
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
425
|
+
timeout: this.config.txMinedWaitSeconds
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
await this.store.deleteBridgeClaim(sender);
|
|
429
|
+
} else {
|
|
430
|
+
const { estimatedGas } = await deploy.simulate({
|
|
431
|
+
...deployOpts,
|
|
432
|
+
fee: {
|
|
433
|
+
estimateGas: true
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
this.log.info(`Deploying contract ${name} at ${address.toString()}`, {
|
|
437
|
+
estimatedGas
|
|
438
|
+
});
|
|
439
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
440
|
+
const { txHash } = await deploy.send({
|
|
441
|
+
...deployOpts,
|
|
442
|
+
fee: {
|
|
443
|
+
gasSettings: estimatedGas
|
|
444
|
+
},
|
|
445
|
+
wait: NO_WAIT
|
|
446
|
+
});
|
|
447
|
+
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
448
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
449
|
+
timeout: this.config.txMinedWaitSeconds
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
}
|
|
302
453
|
}
|
|
303
454
|
return instance;
|
|
304
455
|
}
|
|
305
456
|
/**
|
|
306
457
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
307
458
|
* @param token - Token contract.
|
|
308
|
-
*/
|
|
459
|
+
*/ /**
|
|
460
|
+
* Ensures the account has sufficient fee juice by bridging from L1 if balance is below threshold.
|
|
461
|
+
* Bridges repeatedly until balance reaches the target (10k FJ).
|
|
462
|
+
* Used on startup/restart to top up when the account has run out after previous runs.
|
|
463
|
+
*/ async ensureFeeJuiceBalance(account, token) {
|
|
464
|
+
const { feePaymentMethod, l1RpcUrls } = this.config;
|
|
465
|
+
if (feePaymentMethod !== 'fee_juice' || !l1RpcUrls?.length) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
469
|
+
if (!mnemonicOrPrivateKey) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
let balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
473
|
+
if (balance >= FEE_JUICE_TOP_UP_THRESHOLD) {
|
|
474
|
+
this.log.info(`Fee juice balance ${balance} above threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, skipping top-up`);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
this.log.info(`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1 until ${FEE_JUICE_TOP_UP_TARGET}`);
|
|
478
|
+
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
479
|
+
const minimalInteraction = isStandardTokenContract(token) ? token.methods.transfer_in_public(account, account, 0n, 0) : token.methods.transfer(0n, account, account);
|
|
480
|
+
while(balance < FEE_JUICE_TOP_UP_TARGET){
|
|
481
|
+
const claim = await this.bridgeL1FeeJuice(account);
|
|
482
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(account, claim);
|
|
483
|
+
const { estimatedGas } = await minimalInteraction.simulate({
|
|
484
|
+
from: account,
|
|
485
|
+
fee: {
|
|
486
|
+
estimateGas: true,
|
|
487
|
+
paymentMethod
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
const gasSettings = GasSettings.from({
|
|
491
|
+
...estimatedGas,
|
|
492
|
+
maxFeesPerGas,
|
|
493
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
494
|
+
});
|
|
495
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
496
|
+
const { txHash } = await minimalInteraction.send({
|
|
497
|
+
from: account,
|
|
498
|
+
fee: {
|
|
499
|
+
gasSettings,
|
|
500
|
+
paymentMethod
|
|
501
|
+
},
|
|
502
|
+
wait: NO_WAIT
|
|
503
|
+
});
|
|
504
|
+
this.log.info(`Sent fee juice top-up tx ${txHash.toString()}`);
|
|
505
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
506
|
+
timeout: this.config.txMinedWaitSeconds
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
510
|
+
this.log.info(`Fee juice balance after top-up: ${balance}`);
|
|
511
|
+
}
|
|
512
|
+
this.log.info(`Fee juice top-up complete for ${account.toString()}`);
|
|
513
|
+
}
|
|
514
|
+
async mintTokens(token, minter) {
|
|
309
515
|
const isStandardToken = isStandardTokenContract(token);
|
|
310
516
|
let privateBalance = 0n;
|
|
311
517
|
let publicBalance = 0n;
|
|
@@ -327,9 +533,15 @@ export class BotFactory {
|
|
|
327
533
|
this.log.info(`Skipping minting as ${minter.toString()} has enough tokens`);
|
|
328
534
|
return;
|
|
329
535
|
}
|
|
536
|
+
// PrivateToken's mint accesses contract-level private storage vars (admin, total_supply).
|
|
537
|
+
const additionalScopes = isStandardToken ? undefined : [
|
|
538
|
+
token.address
|
|
539
|
+
];
|
|
540
|
+
const mintBatch = new BatchCall(token.wallet, calls);
|
|
330
541
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
331
|
-
const txHash = await
|
|
542
|
+
const { txHash } = await mintBatch.send({
|
|
332
543
|
from: minter,
|
|
544
|
+
additionalScopes,
|
|
333
545
|
wait: NO_WAIT
|
|
334
546
|
});
|
|
335
547
|
this.log.info(`Sent token mint tx with hash ${txHash.toString()}`);
|
|
@@ -351,8 +563,7 @@ export class BotFactory {
|
|
|
351
563
|
try {
|
|
352
564
|
const messageHash = Fr.fromHexString(existingClaim.claim.messageHash);
|
|
353
565
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, messageHash, {
|
|
354
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
355
|
-
forPublicConsumption: false
|
|
566
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
356
567
|
}));
|
|
357
568
|
return existingClaim.claim;
|
|
358
569
|
} catch (err) {
|
|
@@ -380,8 +591,7 @@ export class BotFactory {
|
|
|
380
591
|
const mintAmount = await portal.getTokenManager().getMintAmount();
|
|
381
592
|
const claim = await portal.bridgeTokensPublic(recipient, mintAmount, true);
|
|
382
593
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
|
|
383
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
384
|
-
forPublicConsumption: false
|
|
594
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
385
595
|
}));
|
|
386
596
|
this.log.info(`Created a claim for ${mintAmount} L1 fee juice to ${recipient}.`, claim);
|
|
387
597
|
return claim;
|
package/dest/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { Bot } from './bot.js';
|
|
2
2
|
export { AmmBot } from './amm_bot.js';
|
|
3
|
+
export { CrossChainBot } from './cross_chain_bot.js';
|
|
3
4
|
export { BotRunner } from './runner.js';
|
|
4
5
|
export { BotStore } from './store/bot_store.js';
|
|
5
6
|
export { type BotConfig, getBotConfigFromEnv, getBotDefaultConfig, botConfigMappings, SupportedTokenContracts, } from './config.js';
|
|
6
7
|
export { getBotRunnerApiHandler } from './rpc.js';
|
|
7
8
|
export * from './interface.js';
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsR0FBRyxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBQy9CLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFDdEMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3JELE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFDeEMsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ2hELE9BQU8sRUFDTCxLQUFLLFNBQVMsRUFDZCxtQkFBbUIsRUFDbkIsbUJBQW1CLEVBQ25CLGlCQUFpQixFQUNqQix1QkFBdUIsR0FDeEIsTUFBTSxhQUFhLENBQUM7QUFDckIsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0sVUFBVSxDQUFDO0FBQ2xELGNBQWMsZ0JBQWdCLENBQUMifQ==
|
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACL,KAAK,SAAS,EACd,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACL,KAAK,SAAS,EACd,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,cAAc,gBAAgB,CAAC"}
|
package/dest/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Bot } from './bot.js';
|
|
2
2
|
export { AmmBot } from './amm_bot.js';
|
|
3
|
+
export { CrossChainBot } from './cross_chain_bot.js';
|
|
3
4
|
export { BotRunner } from './runner.js';
|
|
4
5
|
export { BotStore } from './store/bot_store.js';
|
|
5
6
|
export { getBotConfigFromEnv, getBotDefaultConfig, botConfigMappings, SupportedTokenContracts } from './config.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { BotStore, PendingL1ToL2Message } from './store/index.js';
|
|
6
|
+
/** Sends an L1→L2 message via the Inbox contract and stores it. */
|
|
7
|
+
export declare function seedL1ToL2Message(l1Client: ExtendedViemWalletClient, inboxAddress: EthAddress, l2Recipient: AztecAddress, rollupVersion: bigint, store: BotStore, log: Logger): Promise<PendingL1ToL2Message>;
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfdG9fbDJfc2VlZGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2wxX3RvX2wyX3NlZWRpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUd0RSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFcEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFJaEUsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLG9CQUFvQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFdkUscUVBQW1FO0FBQ25FLHdCQUFzQixpQkFBaUIsQ0FDckMsUUFBUSxFQUFFLHdCQUF3QixFQUNsQyxZQUFZLEVBQUUsVUFBVSxFQUN4QixXQUFXLEVBQUUsWUFBWSxFQUN6QixhQUFhLEVBQUUsTUFBTSxFQUNyQixLQUFLLEVBQUUsUUFBUSxFQUNmLEdBQUcsRUFBRSxNQUFNLEdBQ1YsT0FBTyxDQUFDLG9CQUFvQixDQUFDLENBeUQvQiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l1_to_l2_seeding.d.ts","sourceRoot":"","sources":["../src/l1_to_l2_seeding.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAGtE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,qEAAmE;AACnE,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,wBAAwB,EAClC,YAAY,EAAE,UAAU,EACxB,WAAW,EAAE,YAAY,EACzB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,QAAQ,EACf,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,oBAAoB,CAAC,CAyD/B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
|
|
2
|
+
import { compactArray } from '@aztec/foundation/collection';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { InboxAbi } from '@aztec/l1-artifacts';
|
|
5
|
+
import { decodeEventLog, getContract } from 'viem';
|
|
6
|
+
/** Sends an L1→L2 message via the Inbox contract and stores it. */ export async function seedL1ToL2Message(l1Client, inboxAddress, l2Recipient, rollupVersion, store, log) {
|
|
7
|
+
log.info('Seeding L1→L2 message');
|
|
8
|
+
const [secret, secretHash] = await generateClaimSecret(log);
|
|
9
|
+
const content = Fr.random();
|
|
10
|
+
const inbox = getContract({
|
|
11
|
+
address: inboxAddress.toString(),
|
|
12
|
+
abi: InboxAbi,
|
|
13
|
+
client: l1Client
|
|
14
|
+
});
|
|
15
|
+
const txHash = await inbox.write.sendL2Message([
|
|
16
|
+
{
|
|
17
|
+
actor: l2Recipient.toString(),
|
|
18
|
+
version: rollupVersion
|
|
19
|
+
},
|
|
20
|
+
content.toString(),
|
|
21
|
+
secretHash.toString()
|
|
22
|
+
], {
|
|
23
|
+
gas: 1_000_000n
|
|
24
|
+
});
|
|
25
|
+
log.info(`L1→L2 message sent in tx ${txHash}`);
|
|
26
|
+
const txReceipt = await l1Client.waitForTransactionReceipt({
|
|
27
|
+
hash: txHash
|
|
28
|
+
});
|
|
29
|
+
if (txReceipt.status !== 'success') {
|
|
30
|
+
throw new Error(`L1→L2 message tx failed: ${txHash}`);
|
|
31
|
+
}
|
|
32
|
+
// Extract MessageSent event
|
|
33
|
+
const messageSentLogs = compactArray(txReceipt.logs.filter((l)=>l.address.toLowerCase() === inboxAddress.toString().toLowerCase()).map((l)=>{
|
|
34
|
+
try {
|
|
35
|
+
return decodeEventLog({
|
|
36
|
+
abi: InboxAbi,
|
|
37
|
+
eventName: 'MessageSent',
|
|
38
|
+
data: l.data,
|
|
39
|
+
topics: l.topics
|
|
40
|
+
});
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
if (messageSentLogs.length !== 1) {
|
|
46
|
+
throw new Error(`Expected 1 MessageSent event, got ${messageSentLogs.length}`);
|
|
47
|
+
}
|
|
48
|
+
const event = messageSentLogs[0];
|
|
49
|
+
const msgHash = event.args.hash;
|
|
50
|
+
const globalLeafIndex = event.args.index;
|
|
51
|
+
const msg = {
|
|
52
|
+
content: content.toString(),
|
|
53
|
+
secret: secret.toString(),
|
|
54
|
+
secretHash: secretHash.toString(),
|
|
55
|
+
msgHash,
|
|
56
|
+
sender: l1Client.account.address,
|
|
57
|
+
globalLeafIndex: globalLeafIndex.toString(),
|
|
58
|
+
timestamp: Date.now()
|
|
59
|
+
};
|
|
60
|
+
await store.savePendingL1ToL2Message(msg);
|
|
61
|
+
log.info(`Seeded L1→L2 message msgHash=${msg.msgHash}`);
|
|
62
|
+
return msg;
|
|
63
|
+
}
|
package/dest/runner.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
2
2
|
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
3
3
|
import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
4
|
-
import type {
|
|
4
|
+
import type { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
5
5
|
import type { BotConfig } from './config.js';
|
|
6
6
|
import type { BotInfo, BotRunnerApi } from './interface.js';
|
|
7
7
|
import { BotStore } from './store/index.js';
|
|
@@ -19,7 +19,7 @@ export declare class BotRunner implements BotRunnerApi, Traceable {
|
|
|
19
19
|
private consecutiveErrors;
|
|
20
20
|
private healthy;
|
|
21
21
|
readonly tracer: Tracer;
|
|
22
|
-
constructor(config: BotConfig, wallet:
|
|
22
|
+
constructor(config: BotConfig, wallet: EmbeddedWallet, aztecNode: AztecNode, telemetry: TelemetryClient, aztecNodeAdmin: AztecNodeAdmin | undefined, store: BotStore);
|
|
23
23
|
/** Initializes the bot if needed. Blocks until the bot setup is finished. */
|
|
24
24
|
setup(): Promise<void>;
|
|
25
25
|
private doSetup;
|
|
@@ -50,4 +50,4 @@ export declare class BotRunner implements BotRunnerApi, Traceable {
|
|
|
50
50
|
/** Returns the bot sender address. */
|
|
51
51
|
getInfo(): Promise<BotInfo>;
|
|
52
52
|
}
|
|
53
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
53
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVubmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvcnVubmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBR3RELE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ3RFLE9BQU8sRUFBRSxLQUFLLGVBQWUsRUFBRSxLQUFLLFNBQVMsRUFBRSxLQUFLLE1BQU0sRUFBYSxNQUFNLHlCQUF5QixDQUFDO0FBQ3ZHLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBSzlELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUU3QyxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDNUQsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRTVDLHFCQUFhLFNBQVUsWUFBVyxZQUFZLEVBQUUsU0FBUzs7SUFVckQsT0FBTyxDQUFDLE1BQU07SUFDZCxPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU07SUFDdkIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxTQUFTO0lBQzFCLE9BQU8sQ0FBQyxRQUFRLENBQUMsU0FBUztJQUMxQixPQUFPLENBQUMsUUFBUSxDQUFDLGNBQWM7SUFDL0IsT0FBTyxDQUFDLFFBQVEsQ0FBQyxLQUFLO0lBZHhCLE9BQU8sQ0FBQyxHQUFHLENBQXVCO0lBQ2xDLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBbUI7SUFDL0IsT0FBTyxDQUFDLGNBQWMsQ0FBaUI7SUFDdkMsT0FBTyxDQUFDLGlCQUFpQixDQUFLO0lBQzlCLE9BQU8sQ0FBQyxPQUFPLENBQVE7SUFFdkIsU0FBZ0IsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUUvQixZQUNVLE1BQU0sRUFBRSxTQUFTLEVBQ1IsTUFBTSxFQUFFLGNBQWMsRUFDdEIsU0FBUyxFQUFFLFNBQVMsRUFDcEIsU0FBUyxFQUFFLGVBQWUsRUFDMUIsY0FBYyxFQUFFLGNBQWMsR0FBRyxTQUFTLEVBQzFDLEtBQUssRUFBRSxRQUFRLEVBS2pDO0lBRUQsNkVBQTZFO0lBQ2hFLEtBQUssa0JBSWpCO1lBR2EsT0FBTztJQU1yQjs7O09BR0c7SUFDVSxLQUFLLGtCQU1qQjtJQUVEOztPQUVHO0lBQ1UsSUFBSSxrQkFPaEI7SUFFTSxTQUFTLFlBRWY7SUFFRCwwQ0FBMEM7SUFDbkMsU0FBUyxZQUVmO0lBRUQ7OztPQUdHO0lBQ1UsTUFBTSxDQUFDLE1BQU0sRUFBRSxTQUFTLGlCQWFwQztJQUVEOzs7T0FHRztJQUNVLEdBQUcsa0JBc0JmO0lBRUQscURBQXFEO0lBQzlDLFNBQVMsdUJBR2Y7SUFFRCxzQ0FBc0M7SUFDekIsT0FBTyxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FNdkM7Q0FtREYifQ==
|