@aztec/bot 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +6 -7
- package/dest/amm_bot.d.ts.map +1 -1
- package/dest/amm_bot.js +5 -1
- package/dest/base_bot.d.ts +6 -6
- package/dest/base_bot.d.ts.map +1 -1
- package/dest/base_bot.js +14 -15
- package/dest/bot.d.ts +6 -6
- package/dest/bot.d.ts.map +1 -1
- package/dest/bot.js +7 -4
- package/dest/config.d.ts +40 -25
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +43 -15
- 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 +140 -0
- package/dest/factory.d.ts +20 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +175 -75
- 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 +429 -31
- package/dest/store/bot_store.d.ts +31 -6
- package/dest/store/bot_store.d.ts.map +1 -1
- package/dest/store/bot_store.js +38 -7
- package/dest/store/index.d.ts +2 -2
- package/dest/store/index.d.ts.map +1 -1
- package/package.json +19 -16
- package/src/amm_bot.ts +7 -7
- package/src/base_bot.ts +13 -27
- package/src/bot.ts +9 -8
- package/src/config.ts +90 -59
- package/src/cross_chain_bot.ts +209 -0
- package/src/factory.ts +185 -60
- 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 +61 -6
- package/src/store/index.ts +1 -1
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVubmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvcnVubmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU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1IsTUFBTSxFQUFFLGNBQWMsRUFDdEIsU0FBUyxFQUFFLFNBQVMsRUFDcEIsU0FBUyxFQUFFLGVBQWUsRUFDMUIsY0FBYyxFQUFFLGNBQWMsR0FBRyxTQUFTLEVBQzFDLEtBQUssRUFBRSxRQUFRLEVBS2pDO0lBRUQsNkVBQTZFO0lBQ2hFLEtBQUssa0JBSWpCO1lBR2EsT0FBTztJQU1yQjs7O09BR0c7SUFDVSxLQUFLLGtCQU1qQjtJQUVEOztPQUVHO0lBQ1UsSUFBSSxrQkFPaEI7SUFFTSxTQUFTLFlBRWY7SUFFRCwwQ0FBMEM7SUFDbkMsU0FBUyxZQUVmO0lBRUQ7OztPQUdHO0lBQ1UsTUFBTSxDQUFDLE1BQU0sRUFBRSxTQUFTLGlCQWFwQztJQUVEOzs7T0FHRztJQUNVLEdBQUcsa0JBc0JmO0lBRUQscURBQXFEO0lBQzlDLFNBQVMsdUJBR2Y7SUFFRCxzQ0FBc0M7SUFDekIsT0FBTyxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FNdkM7Q0FtREYifQ==
|
package/dest/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAa,MAAM,yBAAyB,CAAC;AACvG,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,O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,uBAGf;IAED,sCAAsC;IACzB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAMvC;CAmDF"}
|
package/dest/runner.js
CHANGED
|
@@ -1,15 +1,384 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function applyDecs2203RFactory() {
|
|
2
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
3
|
+
return function addInitializer(initializer) {
|
|
4
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
5
|
+
assertCallable(initializer, "An initializer");
|
|
6
|
+
initializers.push(initializer);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
10
|
+
var kindStr;
|
|
11
|
+
switch(kind){
|
|
12
|
+
case 1:
|
|
13
|
+
kindStr = "accessor";
|
|
14
|
+
break;
|
|
15
|
+
case 2:
|
|
16
|
+
kindStr = "method";
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
kindStr = "getter";
|
|
20
|
+
break;
|
|
21
|
+
case 4:
|
|
22
|
+
kindStr = "setter";
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
kindStr = "field";
|
|
26
|
+
}
|
|
27
|
+
var ctx = {
|
|
28
|
+
kind: kindStr,
|
|
29
|
+
name: isPrivate ? "#" + name : name,
|
|
30
|
+
static: isStatic,
|
|
31
|
+
private: isPrivate,
|
|
32
|
+
metadata: metadata
|
|
33
|
+
};
|
|
34
|
+
var decoratorFinishedRef = {
|
|
35
|
+
v: false
|
|
36
|
+
};
|
|
37
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
38
|
+
var get, set;
|
|
39
|
+
if (kind === 0) {
|
|
40
|
+
if (isPrivate) {
|
|
41
|
+
get = desc.get;
|
|
42
|
+
set = desc.set;
|
|
43
|
+
} else {
|
|
44
|
+
get = function() {
|
|
45
|
+
return this[name];
|
|
46
|
+
};
|
|
47
|
+
set = function(v) {
|
|
48
|
+
this[name] = v;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
} else if (kind === 2) {
|
|
52
|
+
get = function() {
|
|
53
|
+
return desc.value;
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
if (kind === 1 || kind === 3) {
|
|
57
|
+
get = function() {
|
|
58
|
+
return desc.get.call(this);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (kind === 1 || kind === 4) {
|
|
62
|
+
set = function(v) {
|
|
63
|
+
desc.set.call(this, v);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
ctx.access = get && set ? {
|
|
68
|
+
get: get,
|
|
69
|
+
set: set
|
|
70
|
+
} : get ? {
|
|
71
|
+
get: get
|
|
72
|
+
} : {
|
|
73
|
+
set: set
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
return dec(value, ctx);
|
|
77
|
+
} finally{
|
|
78
|
+
decoratorFinishedRef.v = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
82
|
+
if (decoratorFinishedRef.v) {
|
|
83
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function assertCallable(fn, hint) {
|
|
87
|
+
if (typeof fn !== "function") {
|
|
88
|
+
throw new TypeError(hint + " must be a function");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assertValidReturnValue(kind, value) {
|
|
92
|
+
var type = typeof value;
|
|
93
|
+
if (kind === 1) {
|
|
94
|
+
if (type !== "object" || value === null) {
|
|
95
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
96
|
+
}
|
|
97
|
+
if (value.get !== undefined) {
|
|
98
|
+
assertCallable(value.get, "accessor.get");
|
|
99
|
+
}
|
|
100
|
+
if (value.set !== undefined) {
|
|
101
|
+
assertCallable(value.set, "accessor.set");
|
|
102
|
+
}
|
|
103
|
+
if (value.init !== undefined) {
|
|
104
|
+
assertCallable(value.init, "accessor.init");
|
|
105
|
+
}
|
|
106
|
+
} else if (type !== "function") {
|
|
107
|
+
var hint;
|
|
108
|
+
if (kind === 0) {
|
|
109
|
+
hint = "field";
|
|
110
|
+
} else if (kind === 10) {
|
|
111
|
+
hint = "class";
|
|
112
|
+
} else {
|
|
113
|
+
hint = "method";
|
|
114
|
+
}
|
|
115
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
119
|
+
var decs = decInfo[0];
|
|
120
|
+
var desc, init, value;
|
|
121
|
+
if (isPrivate) {
|
|
122
|
+
if (kind === 0 || kind === 1) {
|
|
123
|
+
desc = {
|
|
124
|
+
get: decInfo[3],
|
|
125
|
+
set: decInfo[4]
|
|
126
|
+
};
|
|
127
|
+
} else if (kind === 3) {
|
|
128
|
+
desc = {
|
|
129
|
+
get: decInfo[3]
|
|
130
|
+
};
|
|
131
|
+
} else if (kind === 4) {
|
|
132
|
+
desc = {
|
|
133
|
+
set: decInfo[3]
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
desc = {
|
|
137
|
+
value: decInfo[3]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
} else if (kind !== 0) {
|
|
141
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
142
|
+
}
|
|
143
|
+
if (kind === 1) {
|
|
144
|
+
value = {
|
|
145
|
+
get: desc.get,
|
|
146
|
+
set: desc.set
|
|
147
|
+
};
|
|
148
|
+
} else if (kind === 2) {
|
|
149
|
+
value = desc.value;
|
|
150
|
+
} else if (kind === 3) {
|
|
151
|
+
value = desc.get;
|
|
152
|
+
} else if (kind === 4) {
|
|
153
|
+
value = desc.set;
|
|
154
|
+
}
|
|
155
|
+
var newValue, get, set;
|
|
156
|
+
if (typeof decs === "function") {
|
|
157
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
158
|
+
if (newValue !== void 0) {
|
|
159
|
+
assertValidReturnValue(kind, newValue);
|
|
160
|
+
if (kind === 0) {
|
|
161
|
+
init = newValue;
|
|
162
|
+
} else if (kind === 1) {
|
|
163
|
+
init = newValue.init;
|
|
164
|
+
get = newValue.get || value.get;
|
|
165
|
+
set = newValue.set || value.set;
|
|
166
|
+
value = {
|
|
167
|
+
get: get,
|
|
168
|
+
set: set
|
|
169
|
+
};
|
|
170
|
+
} else {
|
|
171
|
+
value = newValue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
176
|
+
var dec = decs[i];
|
|
177
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
178
|
+
if (newValue !== void 0) {
|
|
179
|
+
assertValidReturnValue(kind, newValue);
|
|
180
|
+
var newInit;
|
|
181
|
+
if (kind === 0) {
|
|
182
|
+
newInit = newValue;
|
|
183
|
+
} else if (kind === 1) {
|
|
184
|
+
newInit = newValue.init;
|
|
185
|
+
get = newValue.get || value.get;
|
|
186
|
+
set = newValue.set || value.set;
|
|
187
|
+
value = {
|
|
188
|
+
get: get,
|
|
189
|
+
set: set
|
|
190
|
+
};
|
|
191
|
+
} else {
|
|
192
|
+
value = newValue;
|
|
193
|
+
}
|
|
194
|
+
if (newInit !== void 0) {
|
|
195
|
+
if (init === void 0) {
|
|
196
|
+
init = newInit;
|
|
197
|
+
} else if (typeof init === "function") {
|
|
198
|
+
init = [
|
|
199
|
+
init,
|
|
200
|
+
newInit
|
|
201
|
+
];
|
|
202
|
+
} else {
|
|
203
|
+
init.push(newInit);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (kind === 0 || kind === 1) {
|
|
210
|
+
if (init === void 0) {
|
|
211
|
+
init = function(instance, init) {
|
|
212
|
+
return init;
|
|
213
|
+
};
|
|
214
|
+
} else if (typeof init !== "function") {
|
|
215
|
+
var ownInitializers = init;
|
|
216
|
+
init = function(instance, init) {
|
|
217
|
+
var value = init;
|
|
218
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
219
|
+
value = ownInitializers[i].call(instance, value);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
var originalInitializer = init;
|
|
225
|
+
init = function(instance, init) {
|
|
226
|
+
return originalInitializer.call(instance, init);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
ret.push(init);
|
|
230
|
+
}
|
|
231
|
+
if (kind !== 0) {
|
|
232
|
+
if (kind === 1) {
|
|
233
|
+
desc.get = value.get;
|
|
234
|
+
desc.set = value.set;
|
|
235
|
+
} else if (kind === 2) {
|
|
236
|
+
desc.value = value;
|
|
237
|
+
} else if (kind === 3) {
|
|
238
|
+
desc.get = value;
|
|
239
|
+
} else if (kind === 4) {
|
|
240
|
+
desc.set = value;
|
|
241
|
+
}
|
|
242
|
+
if (isPrivate) {
|
|
243
|
+
if (kind === 1) {
|
|
244
|
+
ret.push(function(instance, args) {
|
|
245
|
+
return value.get.call(instance, args);
|
|
246
|
+
});
|
|
247
|
+
ret.push(function(instance, args) {
|
|
248
|
+
return value.set.call(instance, args);
|
|
249
|
+
});
|
|
250
|
+
} else if (kind === 2) {
|
|
251
|
+
ret.push(value);
|
|
252
|
+
} else {
|
|
253
|
+
ret.push(function(instance, args) {
|
|
254
|
+
return value.call(instance, args);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
Object.defineProperty(base, name, desc);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
263
|
+
var ret = [];
|
|
264
|
+
var protoInitializers;
|
|
265
|
+
var staticInitializers;
|
|
266
|
+
var existingProtoNonFields = new Map();
|
|
267
|
+
var existingStaticNonFields = new Map();
|
|
268
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
269
|
+
var decInfo = decInfos[i];
|
|
270
|
+
if (!Array.isArray(decInfo)) continue;
|
|
271
|
+
var kind = decInfo[1];
|
|
272
|
+
var name = decInfo[2];
|
|
273
|
+
var isPrivate = decInfo.length > 3;
|
|
274
|
+
var isStatic = kind >= 5;
|
|
275
|
+
var base;
|
|
276
|
+
var initializers;
|
|
277
|
+
if (isStatic) {
|
|
278
|
+
base = Class;
|
|
279
|
+
kind = kind - 5;
|
|
280
|
+
staticInitializers = staticInitializers || [];
|
|
281
|
+
initializers = staticInitializers;
|
|
282
|
+
} else {
|
|
283
|
+
base = Class.prototype;
|
|
284
|
+
protoInitializers = protoInitializers || [];
|
|
285
|
+
initializers = protoInitializers;
|
|
286
|
+
}
|
|
287
|
+
if (kind !== 0 && !isPrivate) {
|
|
288
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
289
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
290
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
291
|
+
throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
292
|
+
} else if (!existingKind && kind > 2) {
|
|
293
|
+
existingNonFields.set(name, kind);
|
|
294
|
+
} else {
|
|
295
|
+
existingNonFields.set(name, true);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
299
|
+
}
|
|
300
|
+
pushInitializers(ret, protoInitializers);
|
|
301
|
+
pushInitializers(ret, staticInitializers);
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
304
|
+
function pushInitializers(ret, initializers) {
|
|
305
|
+
if (initializers) {
|
|
306
|
+
ret.push(function(instance) {
|
|
307
|
+
for(var i = 0; i < initializers.length; i++){
|
|
308
|
+
initializers[i].call(instance);
|
|
309
|
+
}
|
|
310
|
+
return instance;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
315
|
+
if (classDecs.length > 0) {
|
|
316
|
+
var initializers = [];
|
|
317
|
+
var newClass = targetClass;
|
|
318
|
+
var name = targetClass.name;
|
|
319
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
320
|
+
var decoratorFinishedRef = {
|
|
321
|
+
v: false
|
|
322
|
+
};
|
|
323
|
+
try {
|
|
324
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
325
|
+
kind: "class",
|
|
326
|
+
name: name,
|
|
327
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
328
|
+
metadata
|
|
329
|
+
});
|
|
330
|
+
} finally{
|
|
331
|
+
decoratorFinishedRef.v = true;
|
|
332
|
+
}
|
|
333
|
+
if (nextNewClass !== undefined) {
|
|
334
|
+
assertValidReturnValue(10, nextNewClass);
|
|
335
|
+
newClass = nextNewClass;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return [
|
|
339
|
+
defineMetadata(newClass, metadata),
|
|
340
|
+
function() {
|
|
341
|
+
for(var i = 0; i < initializers.length; i++){
|
|
342
|
+
initializers[i].call(newClass);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function defineMetadata(Class, metadata) {
|
|
349
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
350
|
+
configurable: true,
|
|
351
|
+
enumerable: true,
|
|
352
|
+
value: metadata
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
356
|
+
if (parentClass !== void 0) {
|
|
357
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
358
|
+
}
|
|
359
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
360
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
361
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
362
|
+
return {
|
|
363
|
+
e: e,
|
|
364
|
+
get c () {
|
|
365
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
6
372
|
}
|
|
373
|
+
var _dec, _dec1, _call_work, _initProto;
|
|
7
374
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
8
375
|
import { omit } from '@aztec/foundation/collection';
|
|
9
376
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
10
377
|
import { trackSpan } from '@aztec/telemetry-client';
|
|
11
378
|
import { AmmBot } from './amm_bot.js';
|
|
12
379
|
import { Bot } from './bot.js';
|
|
380
|
+
import { CrossChainBot } from './cross_chain_bot.js';
|
|
381
|
+
_dec = trackSpan('Bot.setup'), _dec1 = trackSpan('Bot.work');
|
|
13
382
|
export class BotRunner {
|
|
14
383
|
config;
|
|
15
384
|
wallet;
|
|
@@ -17,6 +386,42 @@ export class BotRunner {
|
|
|
17
386
|
telemetry;
|
|
18
387
|
aztecNodeAdmin;
|
|
19
388
|
store;
|
|
389
|
+
static{
|
|
390
|
+
({ e: [_call_work, _initProto] } = _apply_decs_2203_r(this, [
|
|
391
|
+
[
|
|
392
|
+
_dec,
|
|
393
|
+
2,
|
|
394
|
+
"doSetup"
|
|
395
|
+
],
|
|
396
|
+
[
|
|
397
|
+
_dec1,
|
|
398
|
+
2,
|
|
399
|
+
"work",
|
|
400
|
+
async function() {
|
|
401
|
+
if (this.config.maxPendingTxs > 0) {
|
|
402
|
+
const pendingTxCount = await this.aztecNode.getPendingTxCount();
|
|
403
|
+
if (pendingTxCount >= this.config.maxPendingTxs) {
|
|
404
|
+
this.log.verbose(`Not sending bot tx since node has ${pendingTxCount} pending txs`);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
await this.run();
|
|
410
|
+
} catch {
|
|
411
|
+
// Already logged in run()
|
|
412
|
+
if (this.config.maxConsecutiveErrors > 0 && this.consecutiveErrors >= this.config.maxConsecutiveErrors) {
|
|
413
|
+
this.log.error(`Too many errors bot is unhealthy`);
|
|
414
|
+
this.healthy = false;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (!this.healthy && this.config.stopWhenUnhealthy) {
|
|
418
|
+
this.log.fatal(`Stopping bot due to errors`);
|
|
419
|
+
process.exit(1); // workaround docker not restarting the container if its unhealthy. We have to exit instead
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
], []));
|
|
424
|
+
}
|
|
20
425
|
log;
|
|
21
426
|
bot;
|
|
22
427
|
runningPromise;
|
|
@@ -30,7 +435,7 @@ export class BotRunner {
|
|
|
30
435
|
this.telemetry = telemetry;
|
|
31
436
|
this.aztecNodeAdmin = aztecNodeAdmin;
|
|
32
437
|
this.store = store;
|
|
33
|
-
this.log = createLogger('bot');
|
|
438
|
+
this.log = (_initProto(this), createLogger('bot'));
|
|
34
439
|
this.consecutiveErrors = 0;
|
|
35
440
|
this.healthy = true;
|
|
36
441
|
this.tracer = telemetry.getTracer('Bot');
|
|
@@ -131,36 +536,29 @@ export class BotRunner {
|
|
|
131
536
|
}
|
|
132
537
|
async #createBot() {
|
|
133
538
|
try {
|
|
134
|
-
|
|
539
|
+
switch(this.config.botMode){
|
|
540
|
+
case 'crosschain':
|
|
541
|
+
this.bot = CrossChainBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
|
|
542
|
+
break;
|
|
543
|
+
case 'amm':
|
|
544
|
+
this.bot = AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
|
|
545
|
+
break;
|
|
546
|
+
case 'transfer':
|
|
547
|
+
this.bot = Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
{
|
|
551
|
+
const _exhaustive = this.config.botMode;
|
|
552
|
+
throw new Error(`Unsupported bot mode: [${_exhaustive}]`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
135
555
|
await this.bot;
|
|
136
556
|
} catch (err) {
|
|
137
557
|
this.log.error(`Error setting up bot: ${err}`);
|
|
138
558
|
throw err;
|
|
139
559
|
}
|
|
140
560
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const pendingTxCount = await this.aztecNode.getPendingTxCount();
|
|
144
|
-
if (pendingTxCount >= this.config.maxPendingTxs) {
|
|
145
|
-
this.log.verbose(`Not sending bot tx since node has ${pendingTxCount} pending txs`);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
await this.run();
|
|
151
|
-
} catch {
|
|
152
|
-
// Already logged in run()
|
|
153
|
-
if (this.config.maxConsecutiveErrors > 0 && this.consecutiveErrors >= this.config.maxConsecutiveErrors) {
|
|
154
|
-
this.log.error(`Too many errors bot is unhealthy`);
|
|
155
|
-
this.healthy = false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (!this.healthy && this.config.stopWhenUnhealthy) {
|
|
159
|
-
this.log.fatal(`Stopping bot due to errors`);
|
|
160
|
-
process.exit(1); // workaround docker not restarting the container if its unhealthy. We have to exit instead
|
|
161
|
-
}
|
|
561
|
+
get #work() {
|
|
562
|
+
return _call_work;
|
|
162
563
|
}
|
|
163
564
|
}
|
|
164
|
-
_ts_decorate([
|
|
165
|
-
trackSpan('Bot.setup')
|
|
166
|
-
], BotRunner.prototype, "doSetup", null);
|