@aztec/bot 0.0.1-commit.fffb133c → 0.0.1-dev
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 +32 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +38 -10
- 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 +20 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +126 -60
- 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 +43 -14
- package/src/cross_chain_bot.ts +203 -0
- package/src/factory.ts +158 -59
- 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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CrossChainBot exercises L2->L1 and L1->L2 messaging.
|
|
3
|
+
*
|
|
4
|
+
* createAndSendTx onTxMined
|
|
5
|
+
* ────────────────────────────────────── ──────────────────────────────
|
|
6
|
+
*
|
|
7
|
+
* 1. SEED (fire-and-forget) 3. VERIFY L2->L1
|
|
8
|
+
* if store has fewer pending messages Query getTxEffect, confirm
|
|
9
|
+
* than seedCount and no seed is the expected L2->L1 messages
|
|
10
|
+
* in-flight: appeared in tx effects.
|
|
11
|
+
* * kick off L1 inbox tx
|
|
12
|
+
* * store msg on completion
|
|
13
|
+
*
|
|
14
|
+
* 2. BUILD & SEND BATCH
|
|
15
|
+
* Always:
|
|
16
|
+
* N x create_l2_to_l1_message
|
|
17
|
+
* (random content, fixed
|
|
18
|
+
* L1 recipient)
|
|
19
|
+
* If a ready L1->L2 msg exists:
|
|
20
|
+
* 1 x consume_message_from_
|
|
21
|
+
* arbitrary_sender_public
|
|
22
|
+
* delete consumed msg from store
|
|
23
|
+
* Send batch tx (no wait)
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
27
|
+
import { TxHash, TxReceipt } from '@aztec/aztec.js/tx';
|
|
28
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
29
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
30
|
+
import type { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
31
|
+
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
32
|
+
import type { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
33
|
+
import { BaseBot } from './base_bot.js';
|
|
34
|
+
import type { BotConfig } from './config.js';
|
|
35
|
+
import type { BotStore } from './store/index.js';
|
|
36
|
+
/** Bot that exercises both L2→L1 and L1→L2 cross-chain messaging. */
|
|
37
|
+
export declare class CrossChainBot extends BaseBot {
|
|
38
|
+
private readonly contract;
|
|
39
|
+
private readonly l1Client;
|
|
40
|
+
private readonly l1Recipient;
|
|
41
|
+
private readonly inboxAddress;
|
|
42
|
+
private readonly rollupVersion;
|
|
43
|
+
private readonly store;
|
|
44
|
+
private l2ToL1Sent;
|
|
45
|
+
private l1ToL2Consumed;
|
|
46
|
+
private pendingSeedPromise;
|
|
47
|
+
protected constructor(node: AztecNode, wallet: EmbeddedWallet, defaultAccountAddress: AztecAddress, contract: TestContract, l1Client: ExtendedViemWalletClient, l1Recipient: EthAddress, inboxAddress: EthAddress, rollupVersion: bigint, store: BotStore, config: BotConfig);
|
|
48
|
+
static create(config: BotConfig, wallet: EmbeddedWallet, aztecNode: AztecNode, aztecNodeAdmin: AztecNodeAdmin | undefined, store: BotStore): Promise<CrossChainBot>;
|
|
49
|
+
protected createAndSendTx(logCtx: object): Promise<TxHash>;
|
|
50
|
+
protected onTxMined(receipt: TxReceipt, logCtx: object): Promise<void>;
|
|
51
|
+
private getReadyL1ToL2Message;
|
|
52
|
+
private seedNewL1ToL2Message;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3Jvc3NfY2hhaW5fYm90LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY3Jvc3NfY2hhaW5fYm90LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0F3Qkc7QUFDSCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFHekQsT0FBTyxFQUFFLE1BQU0sRUFBRSxTQUFTLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXRFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkF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
|
+
/**
|
|
2
|
+
* CrossChainBot exercises L2->L1 and L1->L2 messaging.
|
|
3
|
+
*
|
|
4
|
+
* createAndSendTx onTxMined
|
|
5
|
+
* ────────────────────────────────────── ──────────────────────────────
|
|
6
|
+
*
|
|
7
|
+
* 1. SEED (fire-and-forget) 3. VERIFY L2->L1
|
|
8
|
+
* if store has fewer pending messages Query getTxEffect, confirm
|
|
9
|
+
* than seedCount and no seed is the expected L2->L1 messages
|
|
10
|
+
* in-flight: appeared in tx effects.
|
|
11
|
+
* * kick off L1 inbox tx
|
|
12
|
+
* * store msg on completion
|
|
13
|
+
*
|
|
14
|
+
* 2. BUILD & SEND BATCH
|
|
15
|
+
* Always:
|
|
16
|
+
* N x create_l2_to_l1_message
|
|
17
|
+
* (random content, fixed
|
|
18
|
+
* L1 recipient)
|
|
19
|
+
* If a ready L1->L2 msg exists:
|
|
20
|
+
* 1 x consume_message_from_
|
|
21
|
+
* arbitrary_sender_public
|
|
22
|
+
* delete consumed msg from store
|
|
23
|
+
* Send batch tx (no wait)
|
|
24
|
+
*
|
|
25
|
+
*/ import { BatchCall, NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
26
|
+
import { isL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
|
|
27
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
28
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
29
|
+
import { BaseBot } from './base_bot.js';
|
|
30
|
+
import { BotFactory } from './factory.js';
|
|
31
|
+
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
32
|
+
/** Stale message threshold: messages older than this are removed. */ const STALE_MESSAGE_THRESHOLD_MS = 2 * 60 * 60 * 1000; // 2 hours
|
|
33
|
+
/** Bot that exercises both L2→L1 and L1→L2 cross-chain messaging. */ export class CrossChainBot extends BaseBot {
|
|
34
|
+
contract;
|
|
35
|
+
l1Client;
|
|
36
|
+
l1Recipient;
|
|
37
|
+
inboxAddress;
|
|
38
|
+
rollupVersion;
|
|
39
|
+
store;
|
|
40
|
+
l2ToL1Sent;
|
|
41
|
+
l1ToL2Consumed;
|
|
42
|
+
pendingSeedPromise;
|
|
43
|
+
constructor(node, wallet, defaultAccountAddress, contract, l1Client, l1Recipient, inboxAddress, rollupVersion, store, config){
|
|
44
|
+
super(node, wallet, defaultAccountAddress, config), this.contract = contract, this.l1Client = l1Client, this.l1Recipient = l1Recipient, this.inboxAddress = inboxAddress, this.rollupVersion = rollupVersion, this.store = store, this.l2ToL1Sent = 0, this.l1ToL2Consumed = 0;
|
|
45
|
+
}
|
|
46
|
+
static async create(config, wallet, aztecNode, aztecNodeAdmin, store) {
|
|
47
|
+
if (config.followChain === 'NONE') {
|
|
48
|
+
throw new Error(`CrossChainBot requires followChain to be set (got NONE)`);
|
|
49
|
+
}
|
|
50
|
+
const factory = new BotFactory(config, wallet, store, aztecNode, aztecNodeAdmin);
|
|
51
|
+
const { defaultAccountAddress, contract, l1Client, rollupVersion } = await factory.setupCrossChain();
|
|
52
|
+
const l1Recipient = EthAddress.fromString(l1Client.account.address);
|
|
53
|
+
const { l1ContractAddresses } = await aztecNode.getNodeInfo();
|
|
54
|
+
const inboxAddress = EthAddress.fromString(l1ContractAddresses.inboxAddress.toString());
|
|
55
|
+
return new CrossChainBot(aztecNode, wallet, defaultAccountAddress, contract, l1Client, l1Recipient, inboxAddress, rollupVersion, store, config);
|
|
56
|
+
}
|
|
57
|
+
async createAndSendTx(logCtx) {
|
|
58
|
+
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
59
|
+
// Send an L1→L2 message if we're below the threshold and not already seeding one
|
|
60
|
+
if (pendingMessages.length < this.config.l1ToL2SeedCount && !this.pendingSeedPromise) {
|
|
61
|
+
this.pendingSeedPromise = this.seedNewL1ToL2Message().catch((err)=>this.log.warn(`Failed to seed L1→L2 message: ${err}`, logCtx)).finally(()=>{
|
|
62
|
+
this.pendingSeedPromise = undefined;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Build batch: always L2→L1, optionally consume L1→L2
|
|
66
|
+
const calls = [];
|
|
67
|
+
// L2→L1: create messages with random content
|
|
68
|
+
for(let i = 0; i < this.config.l2ToL1MessagesPerTx; i++){
|
|
69
|
+
calls.push(this.contract.methods.create_l2_to_l1_message_arbitrary_recipient_public(Fr.random(), this.l1Recipient));
|
|
70
|
+
}
|
|
71
|
+
// L1→L2: consume oldest ready message if available
|
|
72
|
+
const readyMsg = await this.getReadyL1ToL2Message(pendingMessages);
|
|
73
|
+
if (readyMsg) {
|
|
74
|
+
calls.push(this.contract.methods.consume_message_from_arbitrary_sender_public(Fr.fromHexString(readyMsg.content), Fr.fromHexString(readyMsg.secret), EthAddress.fromString(readyMsg.sender), new Fr(BigInt(readyMsg.globalLeafIndex))));
|
|
75
|
+
// Delete consumed message immediately so it works with FOLLOW_CHAIN=NONE
|
|
76
|
+
await this.store.deleteL1ToL2Message(readyMsg.msgHash);
|
|
77
|
+
this.l1ToL2Consumed++;
|
|
78
|
+
} else {
|
|
79
|
+
this.log.warn(`No ready L1→L2 message to consume`, {
|
|
80
|
+
...logCtx,
|
|
81
|
+
pendingCount: pendingMessages.length
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const batch = new BatchCall(this.wallet, calls);
|
|
85
|
+
const opts = this.getSendMethodOpts();
|
|
86
|
+
this.log.verbose(`Sending cross-chain batch with ${calls.length} calls`, logCtx);
|
|
87
|
+
const { txHash } = await batch.send({
|
|
88
|
+
...opts,
|
|
89
|
+
wait: NO_WAIT
|
|
90
|
+
});
|
|
91
|
+
return txHash;
|
|
92
|
+
}
|
|
93
|
+
async onTxMined(receipt, logCtx) {
|
|
94
|
+
// Verify L2→L1 messages appeared in this tx's effects
|
|
95
|
+
const indexed = await this.node.getTxEffect(receipt.txHash);
|
|
96
|
+
if (indexed) {
|
|
97
|
+
const l2ToL1Msgs = indexed.data.l2ToL1Msgs.filter((m)=>!m.isZero());
|
|
98
|
+
if (l2ToL1Msgs.length >= this.config.l2ToL1MessagesPerTx) {
|
|
99
|
+
this.l2ToL1Sent += l2ToL1Msgs.length;
|
|
100
|
+
} else {
|
|
101
|
+
this.log.error(`Expected ${this.config.l2ToL1MessagesPerTx} L2→L1 messages but found ${l2ToL1Msgs.length}`, {
|
|
102
|
+
...logCtx,
|
|
103
|
+
blockNumber: receipt.blockNumber,
|
|
104
|
+
txHash: receipt.txHash.toString()
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const pendingCount = (await this.store.getUnconsumedL1ToL2Messages()).length;
|
|
109
|
+
this.log.info(`CrossChainBot txs mined`, {
|
|
110
|
+
...logCtx,
|
|
111
|
+
l2ToL1Sent: this.l2ToL1Sent,
|
|
112
|
+
l1ToL2Consumed: this.l1ToL2Consumed,
|
|
113
|
+
l1ToL2Pending: pendingCount
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** Finds the oldest pending message that is ready for consumption. */ async getReadyL1ToL2Message(pendingMessages) {
|
|
117
|
+
const now = Date.now();
|
|
118
|
+
for (const msg of pendingMessages){
|
|
119
|
+
const ready = await isL1ToL2MessageReady(this.node, Fr.fromHexString(msg.msgHash));
|
|
120
|
+
if (ready) {
|
|
121
|
+
return msg;
|
|
122
|
+
}
|
|
123
|
+
// Time-based stale detection: if the message is old and still not ready, remove it
|
|
124
|
+
if (now - msg.timestamp > STALE_MESSAGE_THRESHOLD_MS) {
|
|
125
|
+
await this.store.deleteL1ToL2Message(msg.msgHash);
|
|
126
|
+
this.log.warn(`Removed stale L1→L2 message ${msg.msgHash}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
/** Seeds a new L1→L2 message on L1 and stores it. */ async seedNewL1ToL2Message() {
|
|
132
|
+
await seedL1ToL2Message(this.l1Client, this.inboxAddress, this.contract.address, this.rollupVersion, this.store, this.log);
|
|
133
|
+
}
|
|
134
|
+
}
|
package/dest/factory.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
2
3
|
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
3
4
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
4
5
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
6
|
+
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
5
7
|
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
6
|
-
import {
|
|
8
|
+
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
7
9
|
import { type BotConfig } from './config.js';
|
|
8
10
|
import type { BotStore } from './store/index.js';
|
|
9
11
|
export declare class BotFactory {
|
|
@@ -13,26 +15,39 @@ export declare class BotFactory {
|
|
|
13
15
|
private readonly aztecNode;
|
|
14
16
|
private readonly aztecNodeAdmin?;
|
|
15
17
|
private log;
|
|
16
|
-
constructor(config: BotConfig, wallet:
|
|
18
|
+
constructor(config: BotConfig, wallet: EmbeddedWallet, store: BotStore, aztecNode: AztecNode, aztecNodeAdmin?: AztecNodeAdmin | undefined);
|
|
17
19
|
/**
|
|
18
20
|
* Initializes a new bot by setting up the sender account, registering the recipient,
|
|
19
21
|
* deploying the token contract, and minting tokens if necessary.
|
|
20
22
|
*/
|
|
21
23
|
setup(): Promise<{
|
|
22
|
-
wallet:
|
|
24
|
+
wallet: EmbeddedWallet;
|
|
23
25
|
defaultAccountAddress: AztecAddress;
|
|
24
26
|
token: TokenContract | PrivateTokenContract;
|
|
25
27
|
node: AztecNode;
|
|
26
28
|
recipient: AztecAddress;
|
|
27
29
|
}>;
|
|
28
30
|
setupAmm(): Promise<{
|
|
29
|
-
wallet:
|
|
31
|
+
wallet: EmbeddedWallet;
|
|
30
32
|
defaultAccountAddress: AztecAddress;
|
|
31
33
|
amm: AMMContract;
|
|
32
34
|
token0: TokenContract;
|
|
33
35
|
token1: TokenContract;
|
|
34
36
|
node: AztecNode;
|
|
35
37
|
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Initializes the cross-chain bot by deploying TestContract, creating an L1 client,
|
|
40
|
+
* seeding initial L1→L2 messages, and waiting for the first to be ready.
|
|
41
|
+
*/
|
|
42
|
+
setupCrossChain(): Promise<{
|
|
43
|
+
wallet: EmbeddedWallet;
|
|
44
|
+
defaultAccountAddress: AztecAddress;
|
|
45
|
+
contract: TestContract;
|
|
46
|
+
node: AztecNode;
|
|
47
|
+
l1Client: ExtendedViemWalletClient;
|
|
48
|
+
rollupVersion: bigint;
|
|
49
|
+
}>;
|
|
50
|
+
private setupTestContract;
|
|
36
51
|
private setupAccount;
|
|
37
52
|
private setupAccountWithPrivateKey;
|
|
38
53
|
private setupTestAccount;
|
|
@@ -46,4 +61,4 @@ export declare class BotFactory {
|
|
|
46
61
|
private bridgeL1FeeJuice;
|
|
47
62
|
private withNoMinTxsPerBlock;
|
|
48
63
|
}
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBb0J6RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBSXRFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSx1Q0FBdUMsQ0FBQztBQUM3RSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDL0Qs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Q,IAAI,OAAO,CAAC;QAC/B,MAAM,EAAE,cAAc,CAAC;QACvB,qBAAqB,EAAE,YAAY,CAAC;QACpC,GAAG,EAAE,WAAW,CAAC;QACjB,MAAM,EAAE,aAAa,CAAC;QACtB,MAAM,EAAE,aAAa,CAAC;QACtB,IAAI,EAAE,SAAS,CAAC;KACjB,CAAC,CAsBD;IAED;;;OAGG;IACU,eAAe,IAAI,OAAO,CAAC;QACtC,MAAM,EAAE,cAAc,CAAC;QACvB,qBAAqB,EAAE,YAAY,CAAC;QACpC,QAAQ,EAAE,YAAY,CAAC;QACvB,IAAI,EAAE,SAAS,CAAC;QAChB,QAAQ,EAAE,wBAAwB,CAAC;QACnC,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CA2DD;YAEa,iBAAiB;YAWjB,YAAY;YAWZ,0BAA0B;YAuC1B,gBAAgB;YAehB,UAAU;YAuDV,kBAAkB;YAalB,gBAAgB;YAyBhB,OAAO;YAsFP,wBAAwB;YA0BxB,UAAU;YAgDV,sBAAsB;YA2BtB,gBAAgB;YA+BhB,oBAAoB;CAenC"}
|
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,16 +7,20 @@ 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 { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
11
11
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
12
12
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
13
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
13
14
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
16
|
import { Timer } from '@aztec/foundation/timer';
|
|
15
17
|
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
16
18
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
17
19
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
18
|
-
import {
|
|
20
|
+
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
19
21
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
20
22
|
import { SupportedTokenContracts } from './config.js';
|
|
23
|
+
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
21
24
|
import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
|
|
22
25
|
const MINT_BALANCE = 1e12;
|
|
23
26
|
const MIN_BALANCE = 1e3;
|
|
@@ -35,13 +38,16 @@ export class BotFactory {
|
|
|
35
38
|
this.aztecNode = aztecNode;
|
|
36
39
|
this.aztecNodeAdmin = aztecNodeAdmin;
|
|
37
40
|
this.log = createLogger('bot');
|
|
41
|
+
// Set fee padding on the wallet so that all transactions during setup
|
|
42
|
+
// (token deploy, minting, etc.) use the configured padding, not the default.
|
|
43
|
+
this.wallet.setMinFeePadding(config.minFeePadding);
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Initializes a new bot by setting up the sender account, registering the recipient,
|
|
41
47
|
* deploying the token contract, and minting tokens if necessary.
|
|
42
48
|
*/ async setup() {
|
|
43
49
|
const defaultAccountAddress = await this.setupAccount();
|
|
44
|
-
const recipient = (await this.wallet.
|
|
50
|
+
const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
|
|
45
51
|
const token = await this.setupToken(defaultAccountAddress);
|
|
46
52
|
await this.mintTokens(token, defaultAccountAddress);
|
|
47
53
|
return {
|
|
@@ -70,6 +76,66 @@ export class BotFactory {
|
|
|
70
76
|
};
|
|
71
77
|
}
|
|
72
78
|
/**
|
|
79
|
+
* Initializes the cross-chain bot by deploying TestContract, creating an L1 client,
|
|
80
|
+
* seeding initial L1→L2 messages, and waiting for the first to be ready.
|
|
81
|
+
*/ async setupCrossChain() {
|
|
82
|
+
const defaultAccountAddress = await this.setupAccount();
|
|
83
|
+
// Create L1 client (same pattern as bridgeL1FeeJuice)
|
|
84
|
+
const l1RpcUrls = this.config.l1RpcUrls;
|
|
85
|
+
if (!l1RpcUrls?.length) {
|
|
86
|
+
throw new Error('L1 RPC URLs required for cross-chain bot');
|
|
87
|
+
}
|
|
88
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
89
|
+
if (!mnemonicOrPrivateKey) {
|
|
90
|
+
throw new Error('L1 mnemonic or private key required for cross-chain bot');
|
|
91
|
+
}
|
|
92
|
+
const { l1ChainId, l1ContractAddresses } = await this.aztecNode.getNodeInfo();
|
|
93
|
+
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
94
|
+
const l1Client = createExtendedL1Client(chain.rpcUrls, mnemonicOrPrivateKey, chain.chainInfo);
|
|
95
|
+
// Fetch Rollup version (needed for Inbox L2Actor struct)
|
|
96
|
+
const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
|
|
97
|
+
const rollupVersion = await rollupContract.getVersion();
|
|
98
|
+
// Deploy TestContract
|
|
99
|
+
const contract = await this.setupTestContract(defaultAccountAddress);
|
|
100
|
+
// Recover any pending messages from store (clean up stale ones first)
|
|
101
|
+
await this.store.cleanupOldPendingMessages();
|
|
102
|
+
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
103
|
+
// Seed initial L1→L2 messages if pipeline is empty
|
|
104
|
+
const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
|
|
105
|
+
for(let i = 0; i < seedCount; i++){
|
|
106
|
+
await seedL1ToL2Message(l1Client, EthAddress.fromString(l1ContractAddresses.inboxAddress.toString()), contract.address, rollupVersion, this.store, this.log);
|
|
107
|
+
}
|
|
108
|
+
// Block until at least one message is ready
|
|
109
|
+
const allMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
110
|
+
if (allMessages.length > 0) {
|
|
111
|
+
this.log.info(`Waiting for first L1→L2 message to be ready...`);
|
|
112
|
+
const firstMsg = allMessages[0];
|
|
113
|
+
await waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(firstMsg.msgHash), {
|
|
114
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
115
|
+
});
|
|
116
|
+
this.log.info(`First L1→L2 message is ready`);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
wallet: this.wallet,
|
|
120
|
+
defaultAccountAddress,
|
|
121
|
+
contract,
|
|
122
|
+
node: this.aztecNode,
|
|
123
|
+
l1Client,
|
|
124
|
+
rollupVersion
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async setupTestContract(deployer) {
|
|
128
|
+
const deployOpts = {
|
|
129
|
+
from: deployer
|
|
130
|
+
};
|
|
131
|
+
const deploy = TestContract.deploy(this.wallet, {
|
|
132
|
+
salt: this.config.tokenSalt,
|
|
133
|
+
universalDeploy: true
|
|
134
|
+
});
|
|
135
|
+
const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
|
|
136
|
+
return TestContract.at(instance.address, this.wallet);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
73
139
|
* Checks if the sender account contract is initialized, and initializes it if necessary.
|
|
74
140
|
* @returns The sender wallet.
|
|
75
141
|
*/ async setupAccount() {
|
|
@@ -85,14 +151,9 @@ export class BotFactory {
|
|
|
85
151
|
async setupAccountWithPrivateKey(secret) {
|
|
86
152
|
const salt = this.config.senderSalt ?? Fr.ONE;
|
|
87
153
|
const signingKey = deriveSigningKey(secret);
|
|
88
|
-
const
|
|
89
|
-
secret,
|
|
90
|
-
salt,
|
|
91
|
-
contract: new SchnorrAccountContract(signingKey)
|
|
92
|
-
};
|
|
93
|
-
const accountManager = await this.wallet.createAccount(accountData);
|
|
154
|
+
const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
94
155
|
const metadata = await this.wallet.getContractMetadata(accountManager.address);
|
|
95
|
-
if (metadata.
|
|
156
|
+
if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
|
|
96
157
|
this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
|
|
97
158
|
const timer = new Timer();
|
|
98
159
|
const address = accountManager.address;
|
|
@@ -105,15 +166,10 @@ export class BotFactory {
|
|
|
105
166
|
const claim = await this.getOrCreateBridgeClaim(address);
|
|
106
167
|
const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
|
|
107
168
|
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
169
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
113
|
-
const txHash = await deployMethod.send({
|
|
114
|
-
from:
|
|
170
|
+
const { txHash } = await deployMethod.send({
|
|
171
|
+
from: NO_FROM,
|
|
115
172
|
fee: {
|
|
116
|
-
gasSettings,
|
|
117
173
|
paymentMethod
|
|
118
174
|
},
|
|
119
175
|
wait: NO_WAIT
|
|
@@ -131,12 +187,7 @@ export class BotFactory {
|
|
|
131
187
|
}
|
|
132
188
|
async setupTestAccount() {
|
|
133
189
|
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);
|
|
190
|
+
const accountManager = await this.wallet.createSchnorrAccount(initialAccountData.secret, initialAccountData.salt, initialAccountData.signingKey);
|
|
140
191
|
return accountManager.address;
|
|
141
192
|
}
|
|
142
193
|
/**
|
|
@@ -145,40 +196,50 @@ export class BotFactory {
|
|
|
145
196
|
* @returns The TokenContract instance.
|
|
146
197
|
*/ async setupToken(sender) {
|
|
147
198
|
let deploy;
|
|
148
|
-
|
|
199
|
+
const salt = this.config.tokenSalt;
|
|
149
200
|
const deployOpts = {
|
|
150
|
-
from: sender
|
|
151
|
-
contractAddressSalt: this.config.tokenSalt,
|
|
152
|
-
universalDeploy: true
|
|
201
|
+
from: sender
|
|
153
202
|
};
|
|
154
203
|
let token;
|
|
204
|
+
let instance;
|
|
155
205
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
156
|
-
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18
|
|
157
|
-
|
|
158
|
-
|
|
206
|
+
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18, {
|
|
207
|
+
salt,
|
|
208
|
+
universalDeploy: true
|
|
209
|
+
});
|
|
210
|
+
instance = await deploy.getInstance();
|
|
211
|
+
token = TokenContract.at(instance.address, this.wallet);
|
|
159
212
|
} else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
160
213
|
// Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
|
|
161
214
|
const tokenSecretKey = Fr.random();
|
|
162
215
|
const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
|
|
163
|
-
deploy = PrivateTokenContract.
|
|
216
|
+
deploy = PrivateTokenContract.deploy(this.wallet, MINT_BALANCE, sender, {
|
|
217
|
+
salt,
|
|
218
|
+
universalDeploy: true,
|
|
219
|
+
publicKeys: tokenPublicKeys
|
|
220
|
+
});
|
|
164
221
|
deployOpts.skipInstancePublication = true;
|
|
165
222
|
deployOpts.skipClassPublication = true;
|
|
166
223
|
deployOpts.skipInitialization = false;
|
|
167
224
|
// Register the contract with the secret key before deployment
|
|
168
|
-
|
|
169
|
-
token = PrivateTokenContract.at(
|
|
170
|
-
await this.wallet.registerContract(
|
|
225
|
+
instance = await deploy.getInstance();
|
|
226
|
+
token = PrivateTokenContract.at(instance.address, this.wallet);
|
|
227
|
+
await this.wallet.registerContract(instance, PrivateTokenContract.artifact, tokenSecretKey);
|
|
228
|
+
// The contract constructor initializes private storage vars that need the contract's own nullifier key.
|
|
229
|
+
deployOpts.additionalScopes = [
|
|
230
|
+
instance.address
|
|
231
|
+
];
|
|
171
232
|
} else {
|
|
172
233
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
173
234
|
}
|
|
174
|
-
const address =
|
|
235
|
+
const address = instance.address;
|
|
175
236
|
const metadata = await this.wallet.getContractMetadata(address);
|
|
176
237
|
if (metadata.isContractPublished) {
|
|
177
238
|
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
178
239
|
await deploy.register();
|
|
179
240
|
} else {
|
|
180
241
|
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
181
|
-
const txHash = await deploy.send({
|
|
242
|
+
const { txHash } = await deploy.send({
|
|
182
243
|
...deployOpts,
|
|
183
244
|
wait: NO_WAIT
|
|
184
245
|
});
|
|
@@ -196,27 +257,29 @@ export class BotFactory {
|
|
|
196
257
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
197
258
|
* @param wallet - Wallet to deploy the token contract from.
|
|
198
259
|
* @returns The TokenContract instance.
|
|
199
|
-
*/ async setupTokenContract(deployer,
|
|
260
|
+
*/ async setupTokenContract(deployer, salt, name, ticker, decimals = 18) {
|
|
200
261
|
const deployOpts = {
|
|
201
|
-
from: deployer
|
|
202
|
-
contractAddressSalt,
|
|
203
|
-
universalDeploy: true
|
|
262
|
+
from: deployer
|
|
204
263
|
};
|
|
205
|
-
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals
|
|
264
|
+
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals, {
|
|
265
|
+
salt,
|
|
266
|
+
universalDeploy: true
|
|
267
|
+
});
|
|
206
268
|
const instance = await this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
|
|
207
269
|
return TokenContract.at(instance.address, this.wallet);
|
|
208
270
|
}
|
|
209
|
-
async setupAmmContract(deployer,
|
|
271
|
+
async setupAmmContract(deployer, salt, token0, token1, lpToken) {
|
|
210
272
|
const deployOpts = {
|
|
211
|
-
from: deployer
|
|
212
|
-
contractAddressSalt,
|
|
213
|
-
universalDeploy: true
|
|
273
|
+
from: deployer
|
|
214
274
|
};
|
|
215
|
-
const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address
|
|
275
|
+
const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address, {
|
|
276
|
+
salt,
|
|
277
|
+
universalDeploy: true
|
|
278
|
+
});
|
|
216
279
|
const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
217
280
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
218
281
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
219
|
-
const minterReceipt = await lpToken.methods.set_minter(amm.address, true).send({
|
|
282
|
+
const { receipt: minterReceipt } = await lpToken.methods.set_minter(amm.address, true).send({
|
|
220
283
|
from: deployer,
|
|
221
284
|
wait: {
|
|
222
285
|
timeout: this.config.txMinedWaitSeconds
|
|
@@ -230,13 +293,13 @@ export class BotFactory {
|
|
|
230
293
|
const getPrivateBalances = ()=>Promise.all([
|
|
231
294
|
token0.methods.balance_of_private(liquidityProvider).simulate({
|
|
232
295
|
from: liquidityProvider
|
|
233
|
-
}),
|
|
296
|
+
}).then((r)=>r.result),
|
|
234
297
|
token1.methods.balance_of_private(liquidityProvider).simulate({
|
|
235
298
|
from: liquidityProvider
|
|
236
|
-
}),
|
|
299
|
+
}).then((r)=>r.result),
|
|
237
300
|
lpToken.methods.balance_of_private(liquidityProvider).simulate({
|
|
238
301
|
from: liquidityProvider
|
|
239
|
-
})
|
|
302
|
+
}).then((r)=>r.result)
|
|
240
303
|
]);
|
|
241
304
|
const authwitNonce = Fr.random();
|
|
242
305
|
// keep some tokens for swapping
|
|
@@ -255,7 +318,7 @@ export class BotFactory {
|
|
|
255
318
|
caller: amm.address,
|
|
256
319
|
call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
|
|
257
320
|
});
|
|
258
|
-
const mintReceipt = await new BatchCall(this.wallet, [
|
|
321
|
+
const { receipt: mintReceipt } = await new BatchCall(this.wallet, [
|
|
259
322
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
260
323
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
261
324
|
]).send({
|
|
@@ -265,7 +328,7 @@ export class BotFactory {
|
|
|
265
328
|
}
|
|
266
329
|
});
|
|
267
330
|
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
268
|
-
const addLiquidityReceipt = await amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce).send({
|
|
331
|
+
const { receipt: addLiquidityReceipt } = await amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce).send({
|
|
269
332
|
from: liquidityProvider,
|
|
270
333
|
authWitnesses: [
|
|
271
334
|
token0Authwit,
|
|
@@ -281,7 +344,7 @@ export class BotFactory {
|
|
|
281
344
|
this.log.info(`Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${newT0Bal}, token1=${newT1Bal}, lp=${newLPBal}`);
|
|
282
345
|
}
|
|
283
346
|
async registerOrDeployContract(name, deploy, deployOpts) {
|
|
284
|
-
const instance = await deploy.getInstance(
|
|
347
|
+
const instance = await deploy.getInstance();
|
|
285
348
|
const address = instance.address;
|
|
286
349
|
const metadata = await this.wallet.getContractMetadata(address);
|
|
287
350
|
if (metadata.isContractPublished) {
|
|
@@ -290,7 +353,7 @@ export class BotFactory {
|
|
|
290
353
|
} else {
|
|
291
354
|
this.log.info(`Deploying contract ${name} at ${address.toString()}`);
|
|
292
355
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
293
|
-
const txHash = await deploy.send({
|
|
356
|
+
const { txHash } = await deploy.send({
|
|
294
357
|
...deployOpts,
|
|
295
358
|
wait: NO_WAIT
|
|
296
359
|
});
|
|
@@ -327,9 +390,14 @@ export class BotFactory {
|
|
|
327
390
|
this.log.info(`Skipping minting as ${minter.toString()} has enough tokens`);
|
|
328
391
|
return;
|
|
329
392
|
}
|
|
393
|
+
// PrivateToken's mint accesses contract-level private storage vars (admin, total_supply).
|
|
394
|
+
const additionalScopes = isStandardToken ? undefined : [
|
|
395
|
+
token.address
|
|
396
|
+
];
|
|
330
397
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
331
|
-
const txHash = await new BatchCall(token.wallet, calls).send({
|
|
398
|
+
const { txHash } = await new BatchCall(token.wallet, calls).send({
|
|
332
399
|
from: minter,
|
|
400
|
+
additionalScopes,
|
|
333
401
|
wait: NO_WAIT
|
|
334
402
|
});
|
|
335
403
|
this.log.info(`Sent token mint tx with hash ${txHash.toString()}`);
|
|
@@ -351,8 +419,7 @@ export class BotFactory {
|
|
|
351
419
|
try {
|
|
352
420
|
const messageHash = Fr.fromHexString(existingClaim.claim.messageHash);
|
|
353
421
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, messageHash, {
|
|
354
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
355
|
-
forPublicConsumption: false
|
|
422
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
356
423
|
}));
|
|
357
424
|
return existingClaim.claim;
|
|
358
425
|
} catch (err) {
|
|
@@ -380,8 +447,7 @@ export class BotFactory {
|
|
|
380
447
|
const mintAmount = await portal.getTokenManager().getMintAmount();
|
|
381
448
|
const claim = await portal.bridgeTokensPublic(recipient, mintAmount, true);
|
|
382
449
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
|
|
383
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
384
|
-
forPublicConsumption: false
|
|
450
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
385
451
|
}));
|
|
386
452
|
this.log.info(`Created a claim for ${mintAmount} L1 fee juice to ${recipient}.`, claim);
|
|
387
453
|
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"}
|