@aztec/bot 1.2.0 → 2.0.0-nightly.20250813
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 +2 -2
- package/dest/amm_bot.d.ts.map +1 -1
- package/dest/amm_bot.js +26 -12
- package/dest/base_bot.d.ts +3 -2
- package/dest/base_bot.d.ts.map +1 -1
- package/dest/base_bot.js +7 -5
- package/dest/bot.d.ts +1 -1
- package/dest/bot.d.ts.map +1 -1
- package/dest/bot.js +11 -10
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/factory.d.ts +3 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +96 -79
- package/dest/utils.js +9 -3
- package/package.json +11 -11
- package/src/amm_bot.ts +17 -13
- package/src/base_bot.ts +10 -5
- package/src/bot.ts +13 -9
- package/src/config.ts +2 -2
- package/src/factory.ts +105 -74
- package/src/utils.ts +3 -3
package/dest/amm_bot.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SentTx, TxReceipt, type Wallet } from '@aztec/aztec.js';
|
|
1
|
+
import { AztecAddress, SentTx, TxReceipt, type Wallet } from '@aztec/aztec.js';
|
|
2
2
|
import type { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
3
3
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
4
4
|
import type { AztecNode, AztecNodeAdmin, PXE } from '@aztec/stdlib/interfaces/client';
|
|
@@ -12,7 +12,7 @@ export declare class AmmBot extends BaseBot {
|
|
|
12
12
|
readonly amm: AMMContract;
|
|
13
13
|
readonly token0: TokenContract;
|
|
14
14
|
readonly token1: TokenContract;
|
|
15
|
-
protected constructor(pxe: PXE, wallet: Wallet, amm: AMMContract, token0: TokenContract, token1: TokenContract, config: BotConfig);
|
|
15
|
+
protected constructor(pxe: PXE, wallet: Wallet, defaultAccountAddress: AztecAddress, amm: AMMContract, token0: TokenContract, token1: TokenContract, config: BotConfig);
|
|
16
16
|
static create(config: BotConfig, dependencies: {
|
|
17
17
|
pxe?: PXE;
|
|
18
18
|
node?: AztecNode;
|
package/dest/amm_bot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amm_bot.d.ts","sourceRoot":"","sources":["../src/amm_bot.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"amm_bot.d.ts","sourceRoot":"","sources":["../src/amm_bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAM,MAAM,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAEtF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,KAAK,QAAQ,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,qBAAa,MAAO,SAAQ,OAAO;aAKf,GAAG,EAAE,WAAW;aAChB,MAAM,EAAE,aAAa;aACrB,MAAM,EAAE,aAAa;IANvC,SAAS,aACP,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,qBAAqB,EAAE,YAAY,EACnB,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,EACrC,MAAM,EAAE,SAAS;WAKN,MAAM,CACjB,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE;QAAE,GAAG,CAAC,EAAE,GAAG,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,CAAC;QAAC,SAAS,CAAC,EAAE,cAAc,CAAA;KAAE,GACxE,OAAO,CAAC,MAAM,CAAC;cAQF,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cA+CvC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9E,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC;IAI7B,WAAW,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,QAAQ,CAAC;QAAC,aAAa,EAAE,QAAQ,CAAC;QAAC,GAAG,EAAE,QAAQ,CAAA;KAAE,CAAC;YAQzF,mBAAmB;YAMnB,oBAAoB;CAMnC"}
|
package/dest/amm_bot.js
CHANGED
|
@@ -8,12 +8,12 @@ export class AmmBot extends BaseBot {
|
|
|
8
8
|
amm;
|
|
9
9
|
token0;
|
|
10
10
|
token1;
|
|
11
|
-
constructor(pxe, wallet, amm, token0, token1, config){
|
|
12
|
-
super(pxe, wallet, config), this.amm = amm, this.token0 = token0, this.token1 = token1;
|
|
11
|
+
constructor(pxe, wallet, defaultAccountAddress, amm, token0, token1, config){
|
|
12
|
+
super(pxe, wallet, defaultAccountAddress, config), this.amm = amm, this.token0 = token0, this.token1 = token1;
|
|
13
13
|
}
|
|
14
14
|
static async create(config, dependencies) {
|
|
15
|
-
const { pxe, wallet, token0, token1, amm } = await new BotFactory(config, dependencies).setupAmm();
|
|
16
|
-
return new AmmBot(pxe, wallet, amm, token0, token1, config);
|
|
15
|
+
const { pxe, wallet, defaultAccountAddress, token0, token1, amm } = await new BotFactory(config, dependencies).setupAmm();
|
|
16
|
+
return new AmmBot(pxe, wallet, defaultAccountAddress, amm, token0, token1, config);
|
|
17
17
|
}
|
|
18
18
|
async createAndSendTx(logCtx) {
|
|
19
19
|
const { feePaymentMethod } = this.config;
|
|
@@ -35,9 +35,15 @@ export class AmmBot extends BaseBot {
|
|
|
35
35
|
];
|
|
36
36
|
const swapAuthwit = await wallet.createAuthWit({
|
|
37
37
|
caller: amm.address,
|
|
38
|
-
action: tokenIn.methods.transfer_to_public(
|
|
38
|
+
action: tokenIn.methods.transfer_to_public(this.defaultAccountAddress, amm.address, amountIn, authwitNonce)
|
|
39
|
+
});
|
|
40
|
+
const amountOutMin = await amm.methods.get_amount_out_for_exact_in(await tokenIn.methods.balance_of_public(amm.address).simulate({
|
|
41
|
+
from: this.defaultAccountAddress
|
|
42
|
+
}), await tokenOut.methods.balance_of_public(amm.address).simulate({
|
|
43
|
+
from: this.defaultAccountAddress
|
|
44
|
+
}), amountIn).simulate({
|
|
45
|
+
from: this.defaultAccountAddress
|
|
39
46
|
});
|
|
40
|
-
const amountOutMin = await amm.methods.get_amount_out_for_exact_in(await tokenIn.methods.balance_of_public(amm.address).simulate(), await tokenOut.methods.balance_of_public(amm.address).simulate(), amountIn).simulate();
|
|
41
47
|
const swapExactTokensInteraction = amm.methods.swap_exact_tokens_for_tokens(tokenIn.address, tokenOut.address, amountIn, amountOutMin, authwitNonce);
|
|
42
48
|
const opts = this.getSendMethodOpts(swapAuthwit);
|
|
43
49
|
this.log.verbose(`Proving transaction`, logCtx);
|
|
@@ -60,21 +66,29 @@ export class AmmBot extends BaseBot {
|
|
|
60
66
|
}
|
|
61
67
|
async getBalances() {
|
|
62
68
|
return {
|
|
63
|
-
senderPublic: await this.getPublicBalanceFor(this.
|
|
64
|
-
senderPrivate: await this.getPrivateBalanceFor(this.
|
|
69
|
+
senderPublic: await this.getPublicBalanceFor(this.defaultAccountAddress),
|
|
70
|
+
senderPrivate: await this.getPrivateBalanceFor(this.defaultAccountAddress),
|
|
65
71
|
amm: await this.getPublicBalanceFor(this.amm.address)
|
|
66
72
|
};
|
|
67
73
|
}
|
|
68
74
|
async getPublicBalanceFor(address) {
|
|
69
75
|
return {
|
|
70
|
-
token0: await this.token0.methods.balance_of_public(address).simulate(
|
|
71
|
-
|
|
76
|
+
token0: await this.token0.methods.balance_of_public(address).simulate({
|
|
77
|
+
from: address
|
|
78
|
+
}),
|
|
79
|
+
token1: await this.token1.methods.balance_of_public(address).simulate({
|
|
80
|
+
from: address
|
|
81
|
+
})
|
|
72
82
|
};
|
|
73
83
|
}
|
|
74
84
|
async getPrivateBalanceFor(address) {
|
|
75
85
|
return {
|
|
76
|
-
token0: await this.token0.methods.balance_of_private(address).simulate(
|
|
77
|
-
|
|
86
|
+
token0: await this.token0.methods.balance_of_private(address).simulate({
|
|
87
|
+
from: address
|
|
88
|
+
}),
|
|
89
|
+
token1: await this.token1.methods.balance_of_private(address).simulate({
|
|
90
|
+
from: address
|
|
91
|
+
})
|
|
78
92
|
};
|
|
79
93
|
}
|
|
80
94
|
}
|
package/dest/base_bot.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { AuthWitness, type SendMethodOptions, SentTx, TxHash, TxReceipt, type Wallet } from '@aztec/aztec.js';
|
|
1
|
+
import { AuthWitness, AztecAddress, type SendMethodOptions, SentTx, TxHash, TxReceipt, type Wallet } from '@aztec/aztec.js';
|
|
2
2
|
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
3
3
|
import type { BotConfig } from './config.js';
|
|
4
4
|
export declare abstract class BaseBot {
|
|
5
5
|
readonly pxe: PXE;
|
|
6
6
|
readonly wallet: Wallet;
|
|
7
|
+
readonly defaultAccountAddress: AztecAddress;
|
|
7
8
|
config: BotConfig;
|
|
8
9
|
protected log: import("@aztec/aztec.js").Logger;
|
|
9
10
|
protected attempts: number;
|
|
10
11
|
protected successes: number;
|
|
11
|
-
protected constructor(pxe: PXE, wallet: Wallet, config: BotConfig);
|
|
12
|
+
protected constructor(pxe: PXE, wallet: Wallet, defaultAccountAddress: AztecAddress, config: BotConfig);
|
|
12
13
|
run(): Promise<TxReceipt | TxHash>;
|
|
13
14
|
protected abstract createAndSendTx(logCtx: object): Promise<SentTx>;
|
|
14
15
|
protected onTxMined(_receipt: TxReceipt, _logCtx: object): Promise<void>;
|
package/dest/base_bot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_bot.d.ts","sourceRoot":"","sources":["../src/base_bot.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"base_bot.d.ts","sourceRoot":"","sources":["../src/base_bot.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EAEZ,KAAK,iBAAiB,EACtB,MAAM,EACN,MAAM,EACN,SAAS,EACT,KAAK,MAAM,EAGZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,8BAAsB,OAAO;aAOT,GAAG,EAAE,GAAG;aACR,MAAM,EAAE,MAAM;aACd,qBAAqB,EAAE,YAAY;IAC5C,MAAM,EAAE,SAAS;IAT1B,SAAS,CAAC,GAAG,mCAAuB;IAEpC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAK;IAC/B,SAAS,CAAC,SAAS,EAAE,MAAM,CAAK;IAEhC,SAAS,aACS,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,qBAAqB,EAAE,YAAY,EAC5C,MAAM,EAAE,SAAS;IAGb,GAAG,IAAI,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC;IAoC/C,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAEnE,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxE,SAAS,CAAC,iBAAiB,CAAC,GAAG,aAAa,EAAE,WAAW,EAAE,GAAG,iBAAiB;CAoBhF"}
|
package/dest/base_bot.js
CHANGED
|
@@ -3,13 +3,15 @@ import { Gas } from '@aztec/stdlib/gas';
|
|
|
3
3
|
export class BaseBot {
|
|
4
4
|
pxe;
|
|
5
5
|
wallet;
|
|
6
|
+
defaultAccountAddress;
|
|
6
7
|
config;
|
|
7
8
|
log;
|
|
8
9
|
attempts;
|
|
9
10
|
successes;
|
|
10
|
-
constructor(pxe, wallet, config){
|
|
11
|
+
constructor(pxe, wallet, defaultAccountAddress, config){
|
|
11
12
|
this.pxe = pxe;
|
|
12
13
|
this.wallet = wallet;
|
|
14
|
+
this.defaultAccountAddress = defaultAccountAddress;
|
|
13
15
|
this.config = config;
|
|
14
16
|
this.log = createLogger('bot');
|
|
15
17
|
this.attempts = 0;
|
|
@@ -25,10 +27,10 @@ export class BaseBot {
|
|
|
25
27
|
const tx = await this.createAndSendTx(logCtx);
|
|
26
28
|
const txHash = await tx.getTxHash();
|
|
27
29
|
if (followChain === 'NONE') {
|
|
28
|
-
this.log.info(`Transaction ${txHash} sent, not waiting for it to be mined`);
|
|
30
|
+
this.log.info(`Transaction ${txHash.toString()} sent, not waiting for it to be mined`);
|
|
29
31
|
return txHash;
|
|
30
32
|
}
|
|
31
|
-
this.log.verbose(`Awaiting tx ${txHash} to be on the ${followChain} chain (timeout ${txMinedWaitSeconds}s)`, logCtx);
|
|
33
|
+
this.log.verbose(`Awaiting tx ${txHash.toString()} to be on the ${followChain} chain (timeout ${txMinedWaitSeconds}s)`, logCtx);
|
|
32
34
|
const receipt = await tx.wait({
|
|
33
35
|
timeout: txMinedWaitSeconds
|
|
34
36
|
});
|
|
@@ -47,9 +49,8 @@ export class BaseBot {
|
|
|
47
49
|
return Promise.resolve();
|
|
48
50
|
}
|
|
49
51
|
getSendMethodOpts(...authWitnesses) {
|
|
50
|
-
const sender = this.wallet.getAddress();
|
|
51
52
|
const { l2GasLimit, daGasLimit } = this.config;
|
|
52
|
-
const paymentMethod = new FeeJuicePaymentMethod(
|
|
53
|
+
const paymentMethod = new FeeJuicePaymentMethod(this.defaultAccountAddress);
|
|
53
54
|
let gasSettings, estimateGas;
|
|
54
55
|
if (l2GasLimit !== undefined && l2GasLimit > 0 && daGasLimit !== undefined && daGasLimit > 0) {
|
|
55
56
|
gasSettings = {
|
|
@@ -66,6 +67,7 @@ export class BaseBot {
|
|
|
66
67
|
}
|
|
67
68
|
const baseFeePadding = 2; // Send 3x the current base fee
|
|
68
69
|
return {
|
|
70
|
+
from: this.defaultAccountAddress,
|
|
69
71
|
fee: {
|
|
70
72
|
estimateGas,
|
|
71
73
|
paymentMethod,
|
package/dest/bot.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { BotConfig } from './config.js';
|
|
|
7
7
|
export declare class Bot extends BaseBot {
|
|
8
8
|
readonly token: TokenContract | EasyPrivateTokenContract;
|
|
9
9
|
readonly recipient: AztecAddress;
|
|
10
|
-
protected constructor(pxe: PXE, wallet: Wallet, token: TokenContract | EasyPrivateTokenContract, recipient: AztecAddress, config: BotConfig);
|
|
10
|
+
protected constructor(pxe: PXE, wallet: Wallet, defaultAccountAddress: AztecAddress, token: TokenContract | EasyPrivateTokenContract, recipient: AztecAddress, config: BotConfig);
|
|
11
11
|
static create(config: BotConfig, dependencies: {
|
|
12
12
|
pxe?: PXE;
|
|
13
13
|
node?: AztecNode;
|
package/dest/bot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../src/bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAEtF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,qBAAa,GAAI,SAAQ,OAAO;
|
|
1
|
+
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../src/bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAEtF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,qBAAa,GAAI,SAAQ,OAAO;aAKZ,KAAK,EAAE,aAAa,GAAG,wBAAwB;aAC/C,SAAS,EAAE,YAAY;IALzC,SAAS,aACP,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,qBAAqB,EAAE,YAAY,EACnB,KAAK,EAAE,aAAa,GAAG,wBAAwB,EAC/C,SAAS,EAAE,YAAY,EACvC,MAAM,EAAE,SAAS;WAKN,MAAM,CACjB,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE;QAAE,GAAG,CAAC,EAAE,GAAG,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,CAAC;QAAC,SAAS,CAAC,EAAE,cAAc,CAAA;KAAE,GACxE,OAAO,CAAC,GAAG,CAAC;IAKR,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC;cAK9B,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA+BnD,WAAW;;;;;;;;;;CAmBzB"}
|
package/dest/bot.js
CHANGED
|
@@ -7,12 +7,12 @@ const TRANSFER_AMOUNT = 1;
|
|
|
7
7
|
export class Bot extends BaseBot {
|
|
8
8
|
token;
|
|
9
9
|
recipient;
|
|
10
|
-
constructor(pxe, wallet, token, recipient, config){
|
|
11
|
-
super(pxe, wallet, config), this.token = token, this.recipient = recipient;
|
|
10
|
+
constructor(pxe, wallet, defaultAccountAddress, token, recipient, config){
|
|
11
|
+
super(pxe, wallet, defaultAccountAddress, config), this.token = token, this.recipient = recipient;
|
|
12
12
|
}
|
|
13
13
|
static async create(config, dependencies) {
|
|
14
|
-
const { pxe, wallet, token, recipient } = await new BotFactory(config, dependencies).setup();
|
|
15
|
-
return new Bot(pxe, wallet, token, recipient, config);
|
|
14
|
+
const { pxe, wallet, defaultAccountAddress, token, recipient } = await new BotFactory(config, dependencies).setup();
|
|
15
|
+
return new Bot(pxe, wallet, defaultAccountAddress, token, recipient, config);
|
|
16
16
|
}
|
|
17
17
|
updateConfig(config) {
|
|
18
18
|
this.log.info(`Updating bot config ${Object.keys(config).join(', ')}`);
|
|
@@ -24,16 +24,17 @@ export class Bot extends BaseBot {
|
|
|
24
24
|
async createAndSendTx(logCtx) {
|
|
25
25
|
const { privateTransfersPerTx, publicTransfersPerTx, feePaymentMethod } = this.config;
|
|
26
26
|
const { token, recipient, wallet } = this;
|
|
27
|
-
const sender = wallet.getAddress();
|
|
28
27
|
this.log.verbose(`Preparing tx with ${feePaymentMethod} fee with ${privateTransfersPerTx} private and ${publicTransfersPerTx} public transfers`, logCtx);
|
|
29
28
|
const calls = isStandardTokenContract(token) ? [
|
|
30
29
|
times(privateTransfersPerTx, ()=>token.methods.transfer(recipient, TRANSFER_AMOUNT)),
|
|
31
|
-
times(publicTransfersPerTx, ()=>token.methods.transfer_in_public(
|
|
32
|
-
].flat() : times(privateTransfersPerTx, ()=>token.methods.transfer(TRANSFER_AMOUNT,
|
|
30
|
+
times(publicTransfersPerTx, ()=>token.methods.transfer_in_public(this.defaultAccountAddress, recipient, TRANSFER_AMOUNT, 0))
|
|
31
|
+
].flat() : times(privateTransfersPerTx, ()=>token.methods.transfer(TRANSFER_AMOUNT, this.defaultAccountAddress, recipient));
|
|
33
32
|
const opts = this.getSendMethodOpts();
|
|
34
33
|
const batch = new BatchCall(wallet, calls);
|
|
35
34
|
this.log.verbose(`Simulating transaction with ${calls.length}`, logCtx);
|
|
36
|
-
await batch.simulate(
|
|
35
|
+
await batch.simulate({
|
|
36
|
+
from: this.defaultAccountAddress
|
|
37
|
+
});
|
|
37
38
|
this.log.verbose(`Proving transaction`, logCtx);
|
|
38
39
|
const provenTx = await batch.prove(opts);
|
|
39
40
|
return provenTx.send();
|
|
@@ -41,13 +42,13 @@ export class Bot extends BaseBot {
|
|
|
41
42
|
async getBalances() {
|
|
42
43
|
if (isStandardTokenContract(this.token)) {
|
|
43
44
|
return {
|
|
44
|
-
sender: await getBalances(this.token, this.
|
|
45
|
+
sender: await getBalances(this.token, this.defaultAccountAddress),
|
|
45
46
|
recipient: await getBalances(this.token, this.recipient)
|
|
46
47
|
};
|
|
47
48
|
} else {
|
|
48
49
|
return {
|
|
49
50
|
sender: {
|
|
50
|
-
privateBalance: await getPrivateBalance(this.token, this.
|
|
51
|
+
privateBalance: await getPrivateBalance(this.token, this.defaultAccountAddress),
|
|
51
52
|
publicBalance: 0n
|
|
52
53
|
},
|
|
53
54
|
recipient: {
|
package/dest/config.d.ts
CHANGED
|
@@ -26,11 +26,11 @@ export type BotConfig = {
|
|
|
26
26
|
l1ToL2MessageTimeoutSeconds: number;
|
|
27
27
|
/** Signing private key for the sender account. */
|
|
28
28
|
senderPrivateKey: SecretValue<Fr | undefined>;
|
|
29
|
-
/** Optional salt to use to
|
|
29
|
+
/** Optional salt to use to instantiate the sender account */
|
|
30
30
|
senderSalt: Fr | undefined;
|
|
31
31
|
/** Encryption secret for a recipient account. */
|
|
32
32
|
recipientEncryptionSecret: SecretValue<Fr>;
|
|
33
|
-
/** Salt for the token contract
|
|
33
|
+
/** Salt for the token contract instantiation. */
|
|
34
34
|
tokenSalt: Fr;
|
|
35
35
|
/** Every how many seconds should a new tx be sent. */
|
|
36
36
|
txIntervalSeconds: number;
|
package/dest/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAQjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,cAAc,wCAAyC,CAAC;AAC9D,KAAK,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,oBAAY,uBAAuB;IACjC,aAAa,kBAAkB;IAC/B,wBAAwB,6BAA6B;CACtD;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,4EAA4E;IAC5E,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,8EAA8E;IAC9E,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,gCAAgC;IAChC,SAAS,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,gEAAgE;IAChE,UAAU,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC5C,mEAAmE;IACnE,YAAY,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC9C,uEAAuE;IACvE,2BAA2B,EAAE,MAAM,CAAC;IACpC,kDAAkD;IAClD,gBAAgB,EAAE,WAAW,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;IAC9C,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAQjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,cAAc,wCAAyC,CAAC;AAC9D,KAAK,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,oBAAY,uBAAuB;IACjC,aAAa,kBAAkB;IAC/B,wBAAwB,6BAA6B;CACtD;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,4EAA4E;IAC5E,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,8EAA8E;IAC9E,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,gCAAgC;IAChC,SAAS,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,gEAAgE;IAChE,UAAU,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC5C,mEAAmE;IACnE,YAAY,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC9C,uEAAuE;IACvE,2BAA2B,EAAE,MAAM,CAAC;IACpC,kDAAkD;IAClD,gBAAgB,EAAE,WAAW,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;IAC9C,6DAA6D;IAC7D,UAAU,EAAE,EAAE,GAAG,SAAS,CAAC;IAC3B,iDAAiD;IACjD,yBAAyB,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;IAC3C,iDAAiD;IACjD,SAAS,EAAE,EAAE,CAAC;IACd,sDAAsD;IACtD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,4DAA4D;IAC5D,qBAAqB,EAAE,MAAM,CAAC;IAC9B,2DAA2D;IAC3D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kCAAkC;IAClC,gBAAgB,EAAE,WAAW,CAAC;IAC9B,0EAA0E;IAC1E,OAAO,EAAE,OAAO,CAAC;IACjB,uEAAuE;IACvE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,WAAW,EAAE,cAAc,CAAC;IAC5B,gFAAgF;IAChF,aAAa,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,sBAAsB,EAAE,OAAO,CAAC;IAChC,+EAA+E;IAC/E,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,+EAA+E;IAC/E,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,4BAA4B;IAC5B,QAAQ,EAAE,uBAAuB,CAAC;IAClC,yEAAyE;IACzE,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iDAAiD;IACjD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,+DAA+D;IAC/D,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsCK,CAAC;AAElC,eAAO,MAAM,iBAAiB,EAAE,kBAAkB,CAAC,SAAS,CAkJ3D,CAAC;AAEF,wBAAgB,mBAAmB,IAAI,SAAS,CAE/C;AAED,wBAAgB,mBAAmB,IAAI,SAAS,CAE/C;AAED,wBAAgB,WAAW,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAKzD"}
|
package/dest/factory.d.ts
CHANGED
|
@@ -21,12 +21,14 @@ export declare class BotFactory {
|
|
|
21
21
|
*/
|
|
22
22
|
setup(): Promise<{
|
|
23
23
|
wallet: import("@aztec/aztec.js").AccountWalletWithSecretKey;
|
|
24
|
+
defaultAccountAddress: AztecAddress;
|
|
24
25
|
token: TokenContract | EasyPrivateTokenContract;
|
|
25
26
|
pxe: PXE;
|
|
26
27
|
recipient: AztecAddress;
|
|
27
28
|
}>;
|
|
28
29
|
setupAmm(): Promise<{
|
|
29
30
|
wallet: import("@aztec/aztec.js").AccountWalletWithSecretKey;
|
|
31
|
+
defaultAccountAddress: AztecAddress;
|
|
30
32
|
amm: AMMContract;
|
|
31
33
|
token0: TokenContract;
|
|
32
34
|
token1: TokenContract;
|
|
@@ -64,7 +66,7 @@ export declare class BotFactory {
|
|
|
64
66
|
*/
|
|
65
67
|
private mintTokens;
|
|
66
68
|
private bridgeL1FeeJuice;
|
|
69
|
+
private withNoMinTxsPerBlock;
|
|
67
70
|
private advanceL2Block;
|
|
68
|
-
private tryFlushTxs;
|
|
69
71
|
}
|
|
70
72
|
//# sourceMappingURL=factory.d.ts.map
|
package/dest/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,EAQZ,KAAK,GAAG,EAIT,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAIjF,OAAO,EAAE,KAAK,SAAS,EAAwC,MAAM,aAAa,CAAC;AAMnF,qBAAa,UAAU;IAOnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,IAAI,CAAC,CAAY;IACzB,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,GAAG,CAAuB;gBAGf,MAAM,EAAE,SAAS,EAClC,YAAY,EAAE;QAAE,GAAG,CAAC,EAAE,GAAG,CAAC;QAAC,SAAS,CAAC,EAAE,cAAc,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE;IA4B3E;;;OAGG;IACU,KAAK
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,EAQZ,KAAK,GAAG,EAIT,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAIjF,OAAO,EAAE,KAAK,SAAS,EAAwC,MAAM,aAAa,CAAC;AAMnF,qBAAa,UAAU;IAOnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,IAAI,CAAC,CAAY;IACzB,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,GAAG,CAAuB;gBAGf,MAAM,EAAE,SAAS,EAClC,YAAY,EAAE;QAAE,GAAG,CAAC,EAAE,GAAG,CAAC;QAAC,SAAS,CAAC,EAAE,cAAc,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE;IA4B3E;;;OAGG;IACU,KAAK;;;;;;;IASL,QAAQ;;;;;;;;IAuCrB;;;OAGG;YACW,YAAY;YASZ,0BAA0B;YA8B1B,gBAAgB;IAc9B;;OAEG;YACW,iBAAiB;IAK/B;;;;OAIG;YACW,UAAU;IAkCxB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;YAaZ,gBAAgB;YAqBhB,OAAO;YA0EP,wBAAwB;IAkBtC;;;OAGG;YACW,UAAU;YAmCV,gBAAgB;YAgChB,oBAAoB;YAapB,cAAc;CAM7B"}
|
package/dest/factory.js
CHANGED
|
@@ -51,10 +51,12 @@ export class BotFactory {
|
|
|
51
51
|
*/ async setup() {
|
|
52
52
|
const recipient = await this.registerRecipient();
|
|
53
53
|
const wallet = await this.setupAccount();
|
|
54
|
-
const
|
|
55
|
-
await this.
|
|
54
|
+
const defaultAccountAddress = wallet.getAddress();
|
|
55
|
+
const token = await this.setupToken(wallet, defaultAccountAddress);
|
|
56
|
+
await this.mintTokens(token, defaultAccountAddress);
|
|
56
57
|
return {
|
|
57
58
|
wallet,
|
|
59
|
+
defaultAccountAddress,
|
|
58
60
|
token,
|
|
59
61
|
pxe: this.pxe,
|
|
60
62
|
recipient
|
|
@@ -62,14 +64,16 @@ export class BotFactory {
|
|
|
62
64
|
}
|
|
63
65
|
async setupAmm() {
|
|
64
66
|
const wallet = await this.setupAccount();
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
await this.
|
|
67
|
+
const defaultAccountAddress = wallet.getAddress();
|
|
68
|
+
const token0 = await this.setupTokenContract(wallet, wallet.getAddress(), this.config.tokenSalt, 'BotToken0', 'BOT0');
|
|
69
|
+
const token1 = await this.setupTokenContract(wallet, wallet.getAddress(), this.config.tokenSalt, 'BotToken1', 'BOT1');
|
|
70
|
+
const liquidityToken = await this.setupTokenContract(wallet, wallet.getAddress(), this.config.tokenSalt, 'BotLPToken', 'BOTLP');
|
|
71
|
+
const amm = await this.setupAmmContract(wallet, wallet.getAddress(), this.config.tokenSalt, token0, token1, liquidityToken);
|
|
72
|
+
await this.fundAmm(wallet, wallet.getAddress(), amm, token0, token1, liquidityToken);
|
|
70
73
|
this.log.info(`AMM initialized and funded`);
|
|
71
74
|
return {
|
|
72
75
|
wallet,
|
|
76
|
+
defaultAccountAddress,
|
|
73
77
|
amm,
|
|
74
78
|
token0,
|
|
75
79
|
token1,
|
|
@@ -112,12 +116,10 @@ export class BotFactory {
|
|
|
112
116
|
});
|
|
113
117
|
const txHash = await sentTx.getTxHash();
|
|
114
118
|
// docs:end:claim_and_deploy
|
|
115
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
116
|
-
await this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
timeout: this.config.txMinedWaitSeconds
|
|
120
|
-
});
|
|
119
|
+
this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`);
|
|
120
|
+
await this.withNoMinTxsPerBlock(()=>sentTx.wait({
|
|
121
|
+
timeout: this.config.txMinedWaitSeconds
|
|
122
|
+
}));
|
|
121
123
|
this.log.info(`Account deployed at ${address}`);
|
|
122
124
|
return wallet;
|
|
123
125
|
}
|
|
@@ -145,71 +147,80 @@ export class BotFactory {
|
|
|
145
147
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
146
148
|
* @param wallet - Wallet to deploy the token contract from.
|
|
147
149
|
* @returns The TokenContract instance.
|
|
148
|
-
*/ async setupToken(wallet) {
|
|
150
|
+
*/ async setupToken(wallet, sender) {
|
|
149
151
|
let deploy;
|
|
150
152
|
const deployOpts = {
|
|
153
|
+
from: sender,
|
|
151
154
|
contractAddressSalt: this.config.tokenSalt,
|
|
152
155
|
universalDeploy: true
|
|
153
156
|
};
|
|
154
157
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
155
|
-
deploy = TokenContract.deploy(wallet,
|
|
158
|
+
deploy = TokenContract.deploy(wallet, sender, 'BotToken', 'BOT', 18);
|
|
156
159
|
} else if (this.config.contract === SupportedTokenContracts.EasyPrivateTokenContract) {
|
|
157
|
-
deploy = EasyPrivateTokenContract.deploy(wallet, MINT_BALANCE,
|
|
158
|
-
deployOpts.
|
|
159
|
-
deployOpts.
|
|
160
|
+
deploy = EasyPrivateTokenContract.deploy(wallet, MINT_BALANCE, sender);
|
|
161
|
+
deployOpts.skipInstancePublication = true;
|
|
162
|
+
deployOpts.skipClassPublication = true;
|
|
160
163
|
deployOpts.skipInitialization = false;
|
|
161
164
|
} else {
|
|
162
165
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
163
166
|
}
|
|
164
167
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
165
|
-
if ((await this.pxe.getContractMetadata(address)).
|
|
168
|
+
if ((await this.pxe.getContractMetadata(address)).isContractPublished) {
|
|
166
169
|
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
167
170
|
return deploy.register();
|
|
168
171
|
} else {
|
|
169
172
|
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
170
173
|
const sentTx = deploy.send(deployOpts);
|
|
171
174
|
const txHash = await sentTx.getTxHash();
|
|
172
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
timeout: this.config.txMinedWaitSeconds
|
|
177
|
-
});
|
|
175
|
+
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
|
|
176
|
+
return this.withNoMinTxsPerBlock(()=>sentTx.deployed({
|
|
177
|
+
timeout: this.config.txMinedWaitSeconds
|
|
178
|
+
}));
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
/**
|
|
181
182
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
182
183
|
* @param wallet - Wallet to deploy the token contract from.
|
|
183
184
|
* @returns The TokenContract instance.
|
|
184
|
-
*/ setupTokenContract(wallet, contractAddressSalt, name, ticker, decimals = 18) {
|
|
185
|
+
*/ setupTokenContract(wallet, deployer, contractAddressSalt, name, ticker, decimals = 18) {
|
|
185
186
|
const deployOpts = {
|
|
187
|
+
from: deployer,
|
|
186
188
|
contractAddressSalt,
|
|
187
189
|
universalDeploy: true
|
|
188
190
|
};
|
|
189
|
-
const deploy = TokenContract.deploy(wallet,
|
|
191
|
+
const deploy = TokenContract.deploy(wallet, deployer, name, ticker, decimals);
|
|
190
192
|
return this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
|
|
191
193
|
}
|
|
192
|
-
async setupAmmContract(wallet, contractAddressSalt, token0, token1, lpToken) {
|
|
194
|
+
async setupAmmContract(wallet, deployer, contractAddressSalt, token0, token1, lpToken) {
|
|
193
195
|
const deployOpts = {
|
|
196
|
+
from: deployer,
|
|
194
197
|
contractAddressSalt,
|
|
195
198
|
universalDeploy: true
|
|
196
199
|
};
|
|
197
200
|
const deploy = AMMContract.deploy(wallet, token0.address, token1.address, lpToken.address);
|
|
198
201
|
const amm = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
199
202
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
200
|
-
const minterTx = lpToken.methods.set_minter(amm.address, true).send(
|
|
201
|
-
|
|
203
|
+
const minterTx = lpToken.methods.set_minter(amm.address, true).send({
|
|
204
|
+
from: deployer
|
|
205
|
+
});
|
|
206
|
+
this.log.info(`Set LP token minter to AMM txHash=${(await minterTx.getTxHash()).toString()}`);
|
|
202
207
|
await minterTx.wait({
|
|
203
208
|
timeout: this.config.txMinedWaitSeconds
|
|
204
209
|
});
|
|
205
210
|
this.log.info(`Liquidity token initialized`);
|
|
206
211
|
return amm;
|
|
207
212
|
}
|
|
208
|
-
async fundAmm(wallet, amm, token0, token1, lpToken) {
|
|
213
|
+
async fundAmm(wallet, liquidityProvider, amm, token0, token1, lpToken) {
|
|
209
214
|
const getPrivateBalances = ()=>Promise.all([
|
|
210
|
-
token0.methods.balance_of_private(
|
|
211
|
-
|
|
212
|
-
|
|
215
|
+
token0.methods.balance_of_private(liquidityProvider).simulate({
|
|
216
|
+
from: liquidityProvider
|
|
217
|
+
}),
|
|
218
|
+
token1.methods.balance_of_private(liquidityProvider).simulate({
|
|
219
|
+
from: liquidityProvider
|
|
220
|
+
}),
|
|
221
|
+
lpToken.methods.balance_of_private(liquidityProvider).simulate({
|
|
222
|
+
from: liquidityProvider
|
|
223
|
+
})
|
|
213
224
|
]);
|
|
214
225
|
const authwitNonce = Fr.random();
|
|
215
226
|
// keep some tokens for swapping
|
|
@@ -218,31 +229,34 @@ export class BotFactory {
|
|
|
218
229
|
const amount1Max = MINT_BALANCE / 2;
|
|
219
230
|
const amount1Min = MINT_BALANCE / 4;
|
|
220
231
|
const [t0Bal, t1Bal, lpBal] = await getPrivateBalances();
|
|
221
|
-
this.log.info(`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${
|
|
232
|
+
this.log.info(`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${liquidityProvider}: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`);
|
|
222
233
|
// Add authwitnesses for the transfers in AMM::add_liquidity function
|
|
223
234
|
const token0Authwit = await wallet.createAuthWit({
|
|
224
235
|
caller: amm.address,
|
|
225
|
-
action: token0.methods.transfer_to_public_and_prepare_private_balance_increase(
|
|
236
|
+
action: token0.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount0Max, authwitNonce)
|
|
226
237
|
});
|
|
227
238
|
const token1Authwit = await wallet.createAuthWit({
|
|
228
239
|
caller: amm.address,
|
|
229
|
-
action: token1.methods.transfer_to_public_and_prepare_private_balance_increase(
|
|
240
|
+
action: token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce)
|
|
230
241
|
});
|
|
231
242
|
const mintTx = new BatchCall(wallet, [
|
|
232
|
-
token0.methods.mint_to_private(
|
|
233
|
-
token1.methods.mint_to_private(
|
|
234
|
-
]).send(
|
|
235
|
-
|
|
243
|
+
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
244
|
+
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
245
|
+
]).send({
|
|
246
|
+
from: liquidityProvider
|
|
247
|
+
});
|
|
248
|
+
this.log.info(`Sent mint tx: ${(await mintTx.getTxHash()).toString()}`);
|
|
236
249
|
await mintTx.wait({
|
|
237
250
|
timeout: this.config.txMinedWaitSeconds
|
|
238
251
|
});
|
|
239
252
|
const addLiquidityTx = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce).send({
|
|
253
|
+
from: liquidityProvider,
|
|
240
254
|
authWitnesses: [
|
|
241
255
|
token0Authwit,
|
|
242
256
|
token1Authwit
|
|
243
257
|
]
|
|
244
258
|
});
|
|
245
|
-
this.log.info(`Sent tx to add liquidity to the AMM: ${await addLiquidityTx.getTxHash()}`);
|
|
259
|
+
this.log.info(`Sent tx to add liquidity to the AMM: ${(await addLiquidityTx.getTxHash()).toString()}`);
|
|
246
260
|
await addLiquidityTx.wait({
|
|
247
261
|
timeout: this.config.txMinedWaitSeconds
|
|
248
262
|
});
|
|
@@ -252,56 +266,52 @@ export class BotFactory {
|
|
|
252
266
|
}
|
|
253
267
|
async registerOrDeployContract(name, deploy, deployOpts) {
|
|
254
268
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
255
|
-
if ((await this.pxe.getContractMetadata(address)).
|
|
269
|
+
if ((await this.pxe.getContractMetadata(address)).isContractPublished) {
|
|
256
270
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
257
271
|
return deploy.register();
|
|
258
272
|
} else {
|
|
259
273
|
this.log.info(`Deploying contract ${name} at ${address.toString()}`);
|
|
260
274
|
const sentTx = deploy.send(deployOpts);
|
|
261
275
|
const txHash = await sentTx.getTxHash();
|
|
262
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
timeout: this.config.txMinedWaitSeconds
|
|
267
|
-
});
|
|
276
|
+
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
277
|
+
return this.withNoMinTxsPerBlock(()=>sentTx.deployed({
|
|
278
|
+
timeout: this.config.txMinedWaitSeconds
|
|
279
|
+
}));
|
|
268
280
|
}
|
|
269
281
|
}
|
|
270
282
|
/**
|
|
271
283
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
272
284
|
* @param token - Token contract.
|
|
273
|
-
*/ async mintTokens(token) {
|
|
274
|
-
const sender = token.wallet.getAddress();
|
|
285
|
+
*/ async mintTokens(token, minter) {
|
|
275
286
|
const isStandardToken = isStandardTokenContract(token);
|
|
276
287
|
let privateBalance = 0n;
|
|
277
288
|
let publicBalance = 0n;
|
|
278
289
|
if (isStandardToken) {
|
|
279
|
-
({ privateBalance, publicBalance } = await getBalances(token,
|
|
290
|
+
({ privateBalance, publicBalance } = await getBalances(token, minter));
|
|
280
291
|
} else {
|
|
281
|
-
privateBalance = await getPrivateBalance(token,
|
|
292
|
+
privateBalance = await getPrivateBalance(token, minter);
|
|
282
293
|
}
|
|
283
294
|
const calls = [];
|
|
284
295
|
if (privateBalance < MIN_BALANCE) {
|
|
285
|
-
this.log.info(`Minting private tokens for ${
|
|
286
|
-
|
|
287
|
-
calls.push(isStandardToken ? token.methods.mint_to_private(from, sender, MINT_BALANCE) : token.methods.mint(MINT_BALANCE, sender));
|
|
296
|
+
this.log.info(`Minting private tokens for ${minter.toString()}`);
|
|
297
|
+
calls.push(isStandardToken ? token.methods.mint_to_private(minter, MINT_BALANCE) : token.methods.mint(MINT_BALANCE, minter));
|
|
288
298
|
}
|
|
289
299
|
if (isStandardToken && publicBalance < MIN_BALANCE) {
|
|
290
|
-
this.log.info(`Minting public tokens for ${
|
|
291
|
-
calls.push(token.methods.mint_to_public(
|
|
300
|
+
this.log.info(`Minting public tokens for ${minter.toString()}`);
|
|
301
|
+
calls.push(token.methods.mint_to_public(minter, MINT_BALANCE));
|
|
292
302
|
}
|
|
293
303
|
if (calls.length === 0) {
|
|
294
|
-
this.log.info(`Skipping minting as ${
|
|
304
|
+
this.log.info(`Skipping minting as ${minter.toString()} has enough tokens`);
|
|
295
305
|
return;
|
|
296
306
|
}
|
|
297
|
-
const sentTx = new BatchCall(token.wallet, calls).send(
|
|
298
|
-
|
|
299
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
300
|
-
await this.tryFlushTxs();
|
|
301
|
-
this.log.verbose('Waiting for token mint to settle');
|
|
302
|
-
await sentTx.wait({
|
|
303
|
-
timeout: this.config.txMinedWaitSeconds
|
|
307
|
+
const sentTx = new BatchCall(token.wallet, calls).send({
|
|
308
|
+
from: minter
|
|
304
309
|
});
|
|
310
|
+
const txHash = await sentTx.getTxHash();
|
|
311
|
+
this.log.info(`Sent token mint tx with hash ${txHash.toString()}`);
|
|
312
|
+
await this.withNoMinTxsPerBlock(()=>sentTx.wait({
|
|
313
|
+
timeout: this.config.txMinedWaitSeconds
|
|
314
|
+
}));
|
|
305
315
|
}
|
|
306
316
|
async bridgeL1FeeJuice(recipient) {
|
|
307
317
|
const l1RpcUrls = this.config.l1RpcUrls;
|
|
@@ -326,19 +336,26 @@ export class BotFactory {
|
|
|
326
336
|
await this.advanceL2Block();
|
|
327
337
|
return claim;
|
|
328
338
|
}
|
|
329
|
-
async
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
async withNoMinTxsPerBlock(fn) {
|
|
340
|
+
if (!this.nodeAdmin || !this.config.flushSetupTransactions) {
|
|
341
|
+
return fn();
|
|
342
|
+
}
|
|
343
|
+
const { minTxsPerBlock } = await this.nodeAdmin.getConfig();
|
|
344
|
+
await this.nodeAdmin.setConfig({
|
|
345
|
+
minTxsPerBlock: 0
|
|
346
|
+
});
|
|
347
|
+
try {
|
|
348
|
+
return await fn();
|
|
349
|
+
} finally{
|
|
350
|
+
await this.nodeAdmin.setConfig({
|
|
351
|
+
minTxsPerBlock
|
|
352
|
+
});
|
|
342
353
|
}
|
|
343
354
|
}
|
|
355
|
+
async advanceL2Block() {
|
|
356
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
357
|
+
const initialBlockNumber = await this.node.getBlockNumber();
|
|
358
|
+
await retryUntil(async ()=>await this.node.getBlockNumber() >= initialBlockNumber + 1);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
344
361
|
}
|
package/dest/utils.js
CHANGED
|
@@ -4,15 +4,21 @@
|
|
|
4
4
|
* @param who - Address to get the balance for.
|
|
5
5
|
* @returns - Private and public token balances as bigints.
|
|
6
6
|
*/ export async function getBalances(token, who) {
|
|
7
|
-
const privateBalance = await token.methods.balance_of_private(who).simulate(
|
|
8
|
-
|
|
7
|
+
const privateBalance = await token.methods.balance_of_private(who).simulate({
|
|
8
|
+
from: who
|
|
9
|
+
});
|
|
10
|
+
const publicBalance = await token.methods.balance_of_public(who).simulate({
|
|
11
|
+
from: who
|
|
12
|
+
});
|
|
9
13
|
return {
|
|
10
14
|
privateBalance,
|
|
11
15
|
publicBalance
|
|
12
16
|
};
|
|
13
17
|
}
|
|
14
18
|
export async function getPrivateBalance(token, who) {
|
|
15
|
-
const privateBalance = await token.methods.get_balance(who).simulate(
|
|
19
|
+
const privateBalance = await token.methods.get_balance(who).simulate({
|
|
20
|
+
from: who
|
|
21
|
+
});
|
|
16
22
|
return privateBalance;
|
|
17
23
|
}
|
|
18
24
|
export function isStandardTokenContract(token) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bot",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-nightly.20250813",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -54,16 +54,16 @@
|
|
|
54
54
|
]
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@aztec/accounts": "
|
|
58
|
-
"@aztec/aztec.js": "
|
|
59
|
-
"@aztec/entrypoints": "
|
|
60
|
-
"@aztec/ethereum": "
|
|
61
|
-
"@aztec/foundation": "
|
|
62
|
-
"@aztec/noir-contracts.js": "
|
|
63
|
-
"@aztec/noir-protocol-circuits-types": "
|
|
64
|
-
"@aztec/protocol-contracts": "
|
|
65
|
-
"@aztec/stdlib": "
|
|
66
|
-
"@aztec/telemetry-client": "
|
|
57
|
+
"@aztec/accounts": "2.0.0-nightly.20250813",
|
|
58
|
+
"@aztec/aztec.js": "2.0.0-nightly.20250813",
|
|
59
|
+
"@aztec/entrypoints": "2.0.0-nightly.20250813",
|
|
60
|
+
"@aztec/ethereum": "2.0.0-nightly.20250813",
|
|
61
|
+
"@aztec/foundation": "2.0.0-nightly.20250813",
|
|
62
|
+
"@aztec/noir-contracts.js": "2.0.0-nightly.20250813",
|
|
63
|
+
"@aztec/noir-protocol-circuits-types": "2.0.0-nightly.20250813",
|
|
64
|
+
"@aztec/protocol-contracts": "2.0.0-nightly.20250813",
|
|
65
|
+
"@aztec/stdlib": "2.0.0-nightly.20250813",
|
|
66
|
+
"@aztec/telemetry-client": "2.0.0-nightly.20250813",
|
|
67
67
|
"source-map-support": "^0.5.21",
|
|
68
68
|
"tslib": "^2.4.0",
|
|
69
69
|
"zod": "^3.23.8"
|
package/src/amm_bot.ts
CHANGED
|
@@ -17,20 +17,24 @@ export class AmmBot extends BaseBot {
|
|
|
17
17
|
protected constructor(
|
|
18
18
|
pxe: PXE,
|
|
19
19
|
wallet: Wallet,
|
|
20
|
+
defaultAccountAddress: AztecAddress,
|
|
20
21
|
public readonly amm: AMMContract,
|
|
21
22
|
public readonly token0: TokenContract,
|
|
22
23
|
public readonly token1: TokenContract,
|
|
23
24
|
config: BotConfig,
|
|
24
25
|
) {
|
|
25
|
-
super(pxe, wallet, config);
|
|
26
|
+
super(pxe, wallet, defaultAccountAddress, config);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
static async create(
|
|
29
30
|
config: BotConfig,
|
|
30
31
|
dependencies: { pxe?: PXE; node?: AztecNode; nodeAdmin?: AztecNodeAdmin },
|
|
31
32
|
): Promise<AmmBot> {
|
|
32
|
-
const { pxe, wallet, token0, token1, amm } = await new BotFactory(
|
|
33
|
-
|
|
33
|
+
const { pxe, wallet, defaultAccountAddress, token0, token1, amm } = await new BotFactory(
|
|
34
|
+
config,
|
|
35
|
+
dependencies,
|
|
36
|
+
).setupAmm();
|
|
37
|
+
return new AmmBot(pxe, wallet, defaultAccountAddress, amm, token0, token1, config);
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
protected async createAndSendTx(logCtx: object): Promise<SentTx> {
|
|
@@ -51,16 +55,16 @@ export class AmmBot extends BaseBot {
|
|
|
51
55
|
|
|
52
56
|
const swapAuthwit = await wallet.createAuthWit({
|
|
53
57
|
caller: amm.address,
|
|
54
|
-
action: tokenIn.methods.transfer_to_public(
|
|
58
|
+
action: tokenIn.methods.transfer_to_public(this.defaultAccountAddress, amm.address, amountIn, authwitNonce),
|
|
55
59
|
});
|
|
56
60
|
|
|
57
61
|
const amountOutMin = await amm.methods
|
|
58
62
|
.get_amount_out_for_exact_in(
|
|
59
|
-
await tokenIn.methods.balance_of_public(amm.address).simulate(),
|
|
60
|
-
await tokenOut.methods.balance_of_public(amm.address).simulate(),
|
|
63
|
+
await tokenIn.methods.balance_of_public(amm.address).simulate({ from: this.defaultAccountAddress }),
|
|
64
|
+
await tokenOut.methods.balance_of_public(amm.address).simulate({ from: this.defaultAccountAddress }),
|
|
61
65
|
amountIn,
|
|
62
66
|
)
|
|
63
|
-
.simulate();
|
|
67
|
+
.simulate({ from: this.defaultAccountAddress });
|
|
64
68
|
|
|
65
69
|
const swapExactTokensInteraction = amm.methods.swap_exact_tokens_for_tokens(
|
|
66
70
|
tokenIn.address,
|
|
@@ -91,22 +95,22 @@ export class AmmBot extends BaseBot {
|
|
|
91
95
|
|
|
92
96
|
public async getBalances(): Promise<{ senderPublic: Balances; senderPrivate: Balances; amm: Balances }> {
|
|
93
97
|
return {
|
|
94
|
-
senderPublic: await this.getPublicBalanceFor(this.
|
|
95
|
-
senderPrivate: await this.getPrivateBalanceFor(this.
|
|
98
|
+
senderPublic: await this.getPublicBalanceFor(this.defaultAccountAddress),
|
|
99
|
+
senderPrivate: await this.getPrivateBalanceFor(this.defaultAccountAddress),
|
|
96
100
|
amm: await this.getPublicBalanceFor(this.amm.address),
|
|
97
101
|
};
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
private async getPublicBalanceFor(address: AztecAddress): Promise<Balances> {
|
|
101
105
|
return {
|
|
102
|
-
token0: await this.token0.methods.balance_of_public(address).simulate(),
|
|
103
|
-
token1: await this.token1.methods.balance_of_public(address).simulate(),
|
|
106
|
+
token0: await this.token0.methods.balance_of_public(address).simulate({ from: address }),
|
|
107
|
+
token1: await this.token1.methods.balance_of_public(address).simulate({ from: address }),
|
|
104
108
|
};
|
|
105
109
|
}
|
|
106
110
|
private async getPrivateBalanceFor(address: AztecAddress): Promise<Balances> {
|
|
107
111
|
return {
|
|
108
|
-
token0: await this.token0.methods.balance_of_private(address).simulate(),
|
|
109
|
-
token1: await this.token1.methods.balance_of_private(address).simulate(),
|
|
112
|
+
token0: await this.token0.methods.balance_of_private(address).simulate({ from: address }),
|
|
113
|
+
token1: await this.token1.methods.balance_of_private(address).simulate({ from: address }),
|
|
110
114
|
};
|
|
111
115
|
}
|
|
112
116
|
}
|
package/src/base_bot.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthWitness,
|
|
3
|
+
AztecAddress,
|
|
3
4
|
FeeJuicePaymentMethod,
|
|
4
5
|
type SendMethodOptions,
|
|
5
6
|
SentTx,
|
|
@@ -23,6 +24,7 @@ export abstract class BaseBot {
|
|
|
23
24
|
protected constructor(
|
|
24
25
|
public readonly pxe: PXE,
|
|
25
26
|
public readonly wallet: Wallet,
|
|
27
|
+
public readonly defaultAccountAddress: AztecAddress,
|
|
26
28
|
public config: BotConfig,
|
|
27
29
|
) {}
|
|
28
30
|
|
|
@@ -37,12 +39,12 @@ export abstract class BaseBot {
|
|
|
37
39
|
const txHash = await tx.getTxHash();
|
|
38
40
|
|
|
39
41
|
if (followChain === 'NONE') {
|
|
40
|
-
this.log.info(`Transaction ${txHash} sent, not waiting for it to be mined`);
|
|
42
|
+
this.log.info(`Transaction ${txHash.toString()} sent, not waiting for it to be mined`);
|
|
41
43
|
return txHash;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
this.log.verbose(
|
|
45
|
-
`Awaiting tx ${txHash} to be on the ${followChain} chain (timeout ${txMinedWaitSeconds}s)`,
|
|
47
|
+
`Awaiting tx ${txHash.toString()} to be on the ${followChain} chain (timeout ${txMinedWaitSeconds}s)`,
|
|
46
48
|
logCtx,
|
|
47
49
|
);
|
|
48
50
|
const receipt = await tx.wait({
|
|
@@ -70,9 +72,8 @@ export abstract class BaseBot {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
protected getSendMethodOpts(...authWitnesses: AuthWitness[]): SendMethodOptions {
|
|
73
|
-
const sender = this.wallet.getAddress();
|
|
74
75
|
const { l2GasLimit, daGasLimit } = this.config;
|
|
75
|
-
const paymentMethod = new FeeJuicePaymentMethod(
|
|
76
|
+
const paymentMethod = new FeeJuicePaymentMethod(this.defaultAccountAddress);
|
|
76
77
|
|
|
77
78
|
let gasSettings, estimateGas;
|
|
78
79
|
if (l2GasLimit !== undefined && l2GasLimit > 0 && daGasLimit !== undefined && daGasLimit > 0) {
|
|
@@ -84,6 +85,10 @@ export abstract class BaseBot {
|
|
|
84
85
|
this.log.verbose(`Estimating gas for transaction`);
|
|
85
86
|
}
|
|
86
87
|
const baseFeePadding = 2; // Send 3x the current base fee
|
|
87
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
from: this.defaultAccountAddress,
|
|
90
|
+
fee: { estimateGas, paymentMethod, gasSettings, baseFeePadding },
|
|
91
|
+
authWitnesses,
|
|
92
|
+
};
|
|
88
93
|
}
|
|
89
94
|
}
|
package/src/bot.ts
CHANGED
|
@@ -15,19 +15,20 @@ export class Bot extends BaseBot {
|
|
|
15
15
|
protected constructor(
|
|
16
16
|
pxe: PXE,
|
|
17
17
|
wallet: Wallet,
|
|
18
|
+
defaultAccountAddress: AztecAddress,
|
|
18
19
|
public readonly token: TokenContract | EasyPrivateTokenContract,
|
|
19
20
|
public readonly recipient: AztecAddress,
|
|
20
21
|
config: BotConfig,
|
|
21
22
|
) {
|
|
22
|
-
super(pxe, wallet, config);
|
|
23
|
+
super(pxe, wallet, defaultAccountAddress, config);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
static async create(
|
|
26
27
|
config: BotConfig,
|
|
27
28
|
dependencies: { pxe?: PXE; node?: AztecNode; nodeAdmin?: AztecNodeAdmin },
|
|
28
29
|
): Promise<Bot> {
|
|
29
|
-
const { pxe, wallet, token, recipient } = await new BotFactory(config, dependencies).setup();
|
|
30
|
-
return new Bot(pxe, wallet, token, recipient, config);
|
|
30
|
+
const { pxe, wallet, defaultAccountAddress, token, recipient } = await new BotFactory(config, dependencies).setup();
|
|
31
|
+
return new Bot(pxe, wallet, defaultAccountAddress, token, recipient, config);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
public updateConfig(config: Partial<BotConfig>) {
|
|
@@ -38,7 +39,6 @@ export class Bot extends BaseBot {
|
|
|
38
39
|
protected async createAndSendTx(logCtx: object): Promise<SentTx> {
|
|
39
40
|
const { privateTransfersPerTx, publicTransfersPerTx, feePaymentMethod } = this.config;
|
|
40
41
|
const { token, recipient, wallet } = this;
|
|
41
|
-
const sender = wallet.getAddress();
|
|
42
42
|
|
|
43
43
|
this.log.verbose(
|
|
44
44
|
`Preparing tx with ${feePaymentMethod} fee with ${privateTransfersPerTx} private and ${publicTransfersPerTx} public transfers`,
|
|
@@ -48,15 +48,19 @@ export class Bot extends BaseBot {
|
|
|
48
48
|
const calls = isStandardTokenContract(token)
|
|
49
49
|
? [
|
|
50
50
|
times(privateTransfersPerTx, () => token.methods.transfer(recipient, TRANSFER_AMOUNT)),
|
|
51
|
-
times(publicTransfersPerTx, () =>
|
|
51
|
+
times(publicTransfersPerTx, () =>
|
|
52
|
+
token.methods.transfer_in_public(this.defaultAccountAddress, recipient, TRANSFER_AMOUNT, 0),
|
|
53
|
+
),
|
|
52
54
|
].flat()
|
|
53
|
-
: times(privateTransfersPerTx, () =>
|
|
55
|
+
: times(privateTransfersPerTx, () =>
|
|
56
|
+
token.methods.transfer(TRANSFER_AMOUNT, this.defaultAccountAddress, recipient),
|
|
57
|
+
);
|
|
54
58
|
|
|
55
59
|
const opts = this.getSendMethodOpts();
|
|
56
60
|
const batch = new BatchCall(wallet, calls);
|
|
57
61
|
|
|
58
62
|
this.log.verbose(`Simulating transaction with ${calls.length}`, logCtx);
|
|
59
|
-
await batch.simulate();
|
|
63
|
+
await batch.simulate({ from: this.defaultAccountAddress });
|
|
60
64
|
|
|
61
65
|
this.log.verbose(`Proving transaction`, logCtx);
|
|
62
66
|
const provenTx = await batch.prove(opts);
|
|
@@ -66,13 +70,13 @@ export class Bot extends BaseBot {
|
|
|
66
70
|
public async getBalances() {
|
|
67
71
|
if (isStandardTokenContract(this.token)) {
|
|
68
72
|
return {
|
|
69
|
-
sender: await getBalances(this.token, this.
|
|
73
|
+
sender: await getBalances(this.token, this.defaultAccountAddress),
|
|
70
74
|
recipient: await getBalances(this.token, this.recipient),
|
|
71
75
|
};
|
|
72
76
|
} else {
|
|
73
77
|
return {
|
|
74
78
|
sender: {
|
|
75
|
-
privateBalance: await getPrivateBalance(this.token, this.
|
|
79
|
+
privateBalance: await getPrivateBalance(this.token, this.defaultAccountAddress),
|
|
76
80
|
publicBalance: 0n,
|
|
77
81
|
},
|
|
78
82
|
recipient: {
|
package/src/config.ts
CHANGED
|
@@ -42,11 +42,11 @@ export type BotConfig = {
|
|
|
42
42
|
l1ToL2MessageTimeoutSeconds: number;
|
|
43
43
|
/** Signing private key for the sender account. */
|
|
44
44
|
senderPrivateKey: SecretValue<Fr | undefined>;
|
|
45
|
-
/** Optional salt to use to
|
|
45
|
+
/** Optional salt to use to instantiate the sender account */
|
|
46
46
|
senderSalt: Fr | undefined;
|
|
47
47
|
/** Encryption secret for a recipient account. */
|
|
48
48
|
recipientEncryptionSecret: SecretValue<Fr>;
|
|
49
|
-
/** Salt for the token contract
|
|
49
|
+
/** Salt for the token contract instantiation. */
|
|
50
50
|
tokenSalt: Fr;
|
|
51
51
|
/** Every how many seconds should a new tx be sent. */
|
|
52
52
|
txIntervalSeconds: number;
|
package/src/factory.ts
CHANGED
|
@@ -74,22 +74,49 @@ export class BotFactory {
|
|
|
74
74
|
public async setup() {
|
|
75
75
|
const recipient = await this.registerRecipient();
|
|
76
76
|
const wallet = await this.setupAccount();
|
|
77
|
-
const
|
|
78
|
-
await this.
|
|
79
|
-
|
|
77
|
+
const defaultAccountAddress = wallet.getAddress();
|
|
78
|
+
const token = await this.setupToken(wallet, defaultAccountAddress);
|
|
79
|
+
await this.mintTokens(token, defaultAccountAddress);
|
|
80
|
+
return { wallet, defaultAccountAddress, token, pxe: this.pxe, recipient };
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
public async setupAmm() {
|
|
83
84
|
const wallet = await this.setupAccount();
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const defaultAccountAddress = wallet.getAddress();
|
|
86
|
+
const token0 = await this.setupTokenContract(
|
|
87
|
+
wallet,
|
|
88
|
+
wallet.getAddress(),
|
|
89
|
+
this.config.tokenSalt,
|
|
90
|
+
'BotToken0',
|
|
91
|
+
'BOT0',
|
|
92
|
+
);
|
|
93
|
+
const token1 = await this.setupTokenContract(
|
|
94
|
+
wallet,
|
|
95
|
+
wallet.getAddress(),
|
|
96
|
+
this.config.tokenSalt,
|
|
97
|
+
'BotToken1',
|
|
98
|
+
'BOT1',
|
|
99
|
+
);
|
|
100
|
+
const liquidityToken = await this.setupTokenContract(
|
|
101
|
+
wallet,
|
|
102
|
+
wallet.getAddress(),
|
|
103
|
+
this.config.tokenSalt,
|
|
104
|
+
'BotLPToken',
|
|
105
|
+
'BOTLP',
|
|
106
|
+
);
|
|
107
|
+
const amm = await this.setupAmmContract(
|
|
108
|
+
wallet,
|
|
109
|
+
wallet.getAddress(),
|
|
110
|
+
this.config.tokenSalt,
|
|
111
|
+
token0,
|
|
112
|
+
token1,
|
|
113
|
+
liquidityToken,
|
|
114
|
+
);
|
|
88
115
|
|
|
89
|
-
await this.fundAmm(wallet, amm, token0, token1, liquidityToken);
|
|
116
|
+
await this.fundAmm(wallet, wallet.getAddress(), amm, token0, token1, liquidityToken);
|
|
90
117
|
this.log.info(`AMM initialized and funded`);
|
|
91
118
|
|
|
92
|
-
return { wallet, amm, token0, token1, pxe: this.pxe };
|
|
119
|
+
return { wallet, defaultAccountAddress, amm, token0, token1, pxe: this.pxe };
|
|
93
120
|
}
|
|
94
121
|
|
|
95
122
|
/**
|
|
@@ -128,10 +155,8 @@ export class BotFactory {
|
|
|
128
155
|
const sentTx = account.deploy({ fee: { paymentMethod } });
|
|
129
156
|
const txHash = await sentTx.getTxHash();
|
|
130
157
|
// docs:end:claim_and_deploy
|
|
131
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
132
|
-
await this.
|
|
133
|
-
this.log.verbose('Waiting for account deployment to settle');
|
|
134
|
-
await sentTx.wait({ timeout: this.config.txMinedWaitSeconds });
|
|
158
|
+
this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`);
|
|
159
|
+
await this.withNoMinTxsPerBlock(() => sentTx.wait({ timeout: this.config.txMinedWaitSeconds }));
|
|
135
160
|
this.log.info(`Account deployed at ${address}`);
|
|
136
161
|
return wallet;
|
|
137
162
|
}
|
|
@@ -164,32 +189,37 @@ export class BotFactory {
|
|
|
164
189
|
* @param wallet - Wallet to deploy the token contract from.
|
|
165
190
|
* @returns The TokenContract instance.
|
|
166
191
|
*/
|
|
167
|
-
private async setupToken(
|
|
192
|
+
private async setupToken(
|
|
193
|
+
wallet: AccountWallet,
|
|
194
|
+
sender: AztecAddress,
|
|
195
|
+
): Promise<TokenContract | EasyPrivateTokenContract> {
|
|
168
196
|
let deploy: DeployMethod<TokenContract | EasyPrivateTokenContract>;
|
|
169
|
-
const deployOpts: DeployOptions = {
|
|
197
|
+
const deployOpts: DeployOptions = {
|
|
198
|
+
from: sender,
|
|
199
|
+
contractAddressSalt: this.config.tokenSalt,
|
|
200
|
+
universalDeploy: true,
|
|
201
|
+
};
|
|
170
202
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
171
|
-
deploy = TokenContract.deploy(wallet,
|
|
203
|
+
deploy = TokenContract.deploy(wallet, sender, 'BotToken', 'BOT', 18);
|
|
172
204
|
} else if (this.config.contract === SupportedTokenContracts.EasyPrivateTokenContract) {
|
|
173
|
-
deploy = EasyPrivateTokenContract.deploy(wallet, MINT_BALANCE,
|
|
174
|
-
deployOpts.
|
|
175
|
-
deployOpts.
|
|
205
|
+
deploy = EasyPrivateTokenContract.deploy(wallet, MINT_BALANCE, sender);
|
|
206
|
+
deployOpts.skipInstancePublication = true;
|
|
207
|
+
deployOpts.skipClassPublication = true;
|
|
176
208
|
deployOpts.skipInitialization = false;
|
|
177
209
|
} else {
|
|
178
210
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
179
211
|
}
|
|
180
212
|
|
|
181
213
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
182
|
-
if ((await this.pxe.getContractMetadata(address)).
|
|
214
|
+
if ((await this.pxe.getContractMetadata(address)).isContractPublished) {
|
|
183
215
|
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
184
216
|
return deploy.register();
|
|
185
217
|
} else {
|
|
186
218
|
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
187
219
|
const sentTx = deploy.send(deployOpts);
|
|
188
220
|
const txHash = await sentTx.getTxHash();
|
|
189
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
190
|
-
|
|
191
|
-
this.log.verbose('Waiting for token setup to settle');
|
|
192
|
-
return sentTx.deployed({ timeout: this.config.txMinedWaitSeconds });
|
|
221
|
+
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
|
|
222
|
+
return this.withNoMinTxsPerBlock(() => sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }));
|
|
193
223
|
}
|
|
194
224
|
}
|
|
195
225
|
|
|
@@ -200,30 +230,32 @@ export class BotFactory {
|
|
|
200
230
|
*/
|
|
201
231
|
private setupTokenContract(
|
|
202
232
|
wallet: AccountWallet,
|
|
233
|
+
deployer: AztecAddress,
|
|
203
234
|
contractAddressSalt: Fr,
|
|
204
235
|
name: string,
|
|
205
236
|
ticker: string,
|
|
206
237
|
decimals = 18,
|
|
207
238
|
): Promise<TokenContract> {
|
|
208
|
-
const deployOpts: DeployOptions = { contractAddressSalt, universalDeploy: true };
|
|
209
|
-
const deploy = TokenContract.deploy(wallet,
|
|
239
|
+
const deployOpts: DeployOptions = { from: deployer, contractAddressSalt, universalDeploy: true };
|
|
240
|
+
const deploy = TokenContract.deploy(wallet, deployer, name, ticker, decimals);
|
|
210
241
|
return this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
|
|
211
242
|
}
|
|
212
243
|
|
|
213
244
|
private async setupAmmContract(
|
|
214
245
|
wallet: AccountWallet,
|
|
246
|
+
deployer: AztecAddress,
|
|
215
247
|
contractAddressSalt: Fr,
|
|
216
248
|
token0: TokenContract,
|
|
217
249
|
token1: TokenContract,
|
|
218
250
|
lpToken: TokenContract,
|
|
219
251
|
): Promise<AMMContract> {
|
|
220
|
-
const deployOpts: DeployOptions = { contractAddressSalt, universalDeploy: true };
|
|
252
|
+
const deployOpts: DeployOptions = { from: deployer, contractAddressSalt, universalDeploy: true };
|
|
221
253
|
const deploy = AMMContract.deploy(wallet, token0.address, token1.address, lpToken.address);
|
|
222
254
|
const amm = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
223
255
|
|
|
224
256
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
225
|
-
const minterTx = lpToken.methods.set_minter(amm.address, true).send();
|
|
226
|
-
this.log.info(`Set LP token minter to AMM txHash=${await minterTx.getTxHash()}`);
|
|
257
|
+
const minterTx = lpToken.methods.set_minter(amm.address, true).send({ from: deployer });
|
|
258
|
+
this.log.info(`Set LP token minter to AMM txHash=${(await minterTx.getTxHash()).toString()}`);
|
|
227
259
|
await minterTx.wait({ timeout: this.config.txMinedWaitSeconds });
|
|
228
260
|
this.log.info(`Liquidity token initialized`);
|
|
229
261
|
|
|
@@ -232,6 +264,7 @@ export class BotFactory {
|
|
|
232
264
|
|
|
233
265
|
private async fundAmm(
|
|
234
266
|
wallet: AccountWallet,
|
|
267
|
+
liquidityProvider: AztecAddress,
|
|
235
268
|
amm: AMMContract,
|
|
236
269
|
token0: TokenContract,
|
|
237
270
|
token1: TokenContract,
|
|
@@ -239,9 +272,9 @@ export class BotFactory {
|
|
|
239
272
|
): Promise<void> {
|
|
240
273
|
const getPrivateBalances = () =>
|
|
241
274
|
Promise.all([
|
|
242
|
-
token0.methods.balance_of_private(
|
|
243
|
-
token1.methods.balance_of_private(
|
|
244
|
-
lpToken.methods.balance_of_private(
|
|
275
|
+
token0.methods.balance_of_private(liquidityProvider).simulate({ from: liquidityProvider }),
|
|
276
|
+
token1.methods.balance_of_private(liquidityProvider).simulate({ from: liquidityProvider }),
|
|
277
|
+
lpToken.methods.balance_of_private(liquidityProvider).simulate({ from: liquidityProvider }),
|
|
245
278
|
]);
|
|
246
279
|
|
|
247
280
|
const authwitNonce = Fr.random();
|
|
@@ -255,14 +288,14 @@ export class BotFactory {
|
|
|
255
288
|
const [t0Bal, t1Bal, lpBal] = await getPrivateBalances();
|
|
256
289
|
|
|
257
290
|
this.log.info(
|
|
258
|
-
`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${
|
|
291
|
+
`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${liquidityProvider}: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`,
|
|
259
292
|
);
|
|
260
293
|
|
|
261
294
|
// Add authwitnesses for the transfers in AMM::add_liquidity function
|
|
262
295
|
const token0Authwit = await wallet.createAuthWit({
|
|
263
296
|
caller: amm.address,
|
|
264
297
|
action: token0.methods.transfer_to_public_and_prepare_private_balance_increase(
|
|
265
|
-
|
|
298
|
+
liquidityProvider,
|
|
266
299
|
amm.address,
|
|
267
300
|
amount0Max,
|
|
268
301
|
authwitNonce,
|
|
@@ -271,7 +304,7 @@ export class BotFactory {
|
|
|
271
304
|
const token1Authwit = await wallet.createAuthWit({
|
|
272
305
|
caller: amm.address,
|
|
273
306
|
action: token1.methods.transfer_to_public_and_prepare_private_balance_increase(
|
|
274
|
-
|
|
307
|
+
liquidityProvider,
|
|
275
308
|
amm.address,
|
|
276
309
|
amount1Max,
|
|
277
310
|
authwitNonce,
|
|
@@ -279,20 +312,21 @@ export class BotFactory {
|
|
|
279
312
|
});
|
|
280
313
|
|
|
281
314
|
const mintTx = new BatchCall(wallet, [
|
|
282
|
-
token0.methods.mint_to_private(
|
|
283
|
-
token1.methods.mint_to_private(
|
|
284
|
-
]).send();
|
|
315
|
+
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
316
|
+
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
317
|
+
]).send({ from: liquidityProvider });
|
|
285
318
|
|
|
286
|
-
this.log.info(`Sent mint tx: ${await mintTx.getTxHash()}`);
|
|
319
|
+
this.log.info(`Sent mint tx: ${(await mintTx.getTxHash()).toString()}`);
|
|
287
320
|
await mintTx.wait({ timeout: this.config.txMinedWaitSeconds });
|
|
288
321
|
|
|
289
322
|
const addLiquidityTx = amm.methods
|
|
290
323
|
.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce)
|
|
291
324
|
.send({
|
|
325
|
+
from: liquidityProvider,
|
|
292
326
|
authWitnesses: [token0Authwit, token1Authwit],
|
|
293
327
|
});
|
|
294
328
|
|
|
295
|
-
this.log.info(`Sent tx to add liquidity to the AMM: ${await addLiquidityTx.getTxHash()}`);
|
|
329
|
+
this.log.info(`Sent tx to add liquidity to the AMM: ${(await addLiquidityTx.getTxHash()).toString()}`);
|
|
296
330
|
await addLiquidityTx.wait({ timeout: this.config.txMinedWaitSeconds });
|
|
297
331
|
this.log.info(`Liquidity added`);
|
|
298
332
|
|
|
@@ -308,17 +342,15 @@ export class BotFactory {
|
|
|
308
342
|
deployOpts: DeployOptions,
|
|
309
343
|
): Promise<T> {
|
|
310
344
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
311
|
-
if ((await this.pxe.getContractMetadata(address)).
|
|
345
|
+
if ((await this.pxe.getContractMetadata(address)).isContractPublished) {
|
|
312
346
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
313
347
|
return deploy.register();
|
|
314
348
|
} else {
|
|
315
349
|
this.log.info(`Deploying contract ${name} at ${address.toString()}`);
|
|
316
350
|
const sentTx = deploy.send(deployOpts);
|
|
317
351
|
const txHash = await sentTx.getTxHash();
|
|
318
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
319
|
-
|
|
320
|
-
this.log.verbose(`Waiting for contract ${name} setup to settle`);
|
|
321
|
-
return sentTx.deployed({ timeout: this.config.txMinedWaitSeconds });
|
|
352
|
+
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
353
|
+
return this.withNoMinTxsPerBlock(() => sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }));
|
|
322
354
|
}
|
|
323
355
|
}
|
|
324
356
|
|
|
@@ -326,43 +358,39 @@ export class BotFactory {
|
|
|
326
358
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
327
359
|
* @param token - Token contract.
|
|
328
360
|
*/
|
|
329
|
-
private async mintTokens(token: TokenContract | EasyPrivateTokenContract) {
|
|
330
|
-
const sender = token.wallet.getAddress();
|
|
361
|
+
private async mintTokens(token: TokenContract | EasyPrivateTokenContract, minter: AztecAddress) {
|
|
331
362
|
const isStandardToken = isStandardTokenContract(token);
|
|
332
363
|
let privateBalance = 0n;
|
|
333
364
|
let publicBalance = 0n;
|
|
334
365
|
|
|
335
366
|
if (isStandardToken) {
|
|
336
|
-
({ privateBalance, publicBalance } = await getBalances(token,
|
|
367
|
+
({ privateBalance, publicBalance } = await getBalances(token, minter));
|
|
337
368
|
} else {
|
|
338
|
-
privateBalance = await getPrivateBalance(token,
|
|
369
|
+
privateBalance = await getPrivateBalance(token, minter);
|
|
339
370
|
}
|
|
340
371
|
|
|
341
372
|
const calls: ContractFunctionInteraction[] = [];
|
|
342
373
|
if (privateBalance < MIN_BALANCE) {
|
|
343
|
-
this.log.info(`Minting private tokens for ${
|
|
374
|
+
this.log.info(`Minting private tokens for ${minter.toString()}`);
|
|
344
375
|
|
|
345
|
-
const from = sender; // we are setting from to sender here because we need a sender to calculate the tag
|
|
346
376
|
calls.push(
|
|
347
377
|
isStandardToken
|
|
348
|
-
? token.methods.mint_to_private(
|
|
349
|
-
: token.methods.mint(MINT_BALANCE,
|
|
378
|
+
? token.methods.mint_to_private(minter, MINT_BALANCE)
|
|
379
|
+
: token.methods.mint(MINT_BALANCE, minter),
|
|
350
380
|
);
|
|
351
381
|
}
|
|
352
382
|
if (isStandardToken && publicBalance < MIN_BALANCE) {
|
|
353
|
-
this.log.info(`Minting public tokens for ${
|
|
354
|
-
calls.push(token.methods.mint_to_public(
|
|
383
|
+
this.log.info(`Minting public tokens for ${minter.toString()}`);
|
|
384
|
+
calls.push(token.methods.mint_to_public(minter, MINT_BALANCE));
|
|
355
385
|
}
|
|
356
386
|
if (calls.length === 0) {
|
|
357
|
-
this.log.info(`Skipping minting as ${
|
|
387
|
+
this.log.info(`Skipping minting as ${minter.toString()} has enough tokens`);
|
|
358
388
|
return;
|
|
359
389
|
}
|
|
360
|
-
const sentTx = new BatchCall(token.wallet, calls).send();
|
|
390
|
+
const sentTx = new BatchCall(token.wallet, calls).send({ from: minter });
|
|
361
391
|
const txHash = await sentTx.getTxHash();
|
|
362
|
-
this.log.info(`Sent tx with hash ${txHash.toString()}`);
|
|
363
|
-
await this.
|
|
364
|
-
this.log.verbose('Waiting for token mint to settle');
|
|
365
|
-
await sentTx.wait({ timeout: this.config.txMinedWaitSeconds });
|
|
392
|
+
this.log.info(`Sent token mint tx with hash ${txHash.toString()}`);
|
|
393
|
+
await this.withNoMinTxsPerBlock(() => sentTx.wait({ timeout: this.config.txMinedWaitSeconds }));
|
|
366
394
|
}
|
|
367
395
|
|
|
368
396
|
private async bridgeL1FeeJuice(recipient: AztecAddress) {
|
|
@@ -397,20 +425,23 @@ export class BotFactory {
|
|
|
397
425
|
return claim;
|
|
398
426
|
}
|
|
399
427
|
|
|
400
|
-
private async
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
428
|
+
private async withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T> {
|
|
429
|
+
if (!this.nodeAdmin || !this.config.flushSetupTransactions) {
|
|
430
|
+
return fn();
|
|
431
|
+
}
|
|
432
|
+
const { minTxsPerBlock } = await this.nodeAdmin.getConfig();
|
|
433
|
+
await this.nodeAdmin.setConfig({ minTxsPerBlock: 0 });
|
|
434
|
+
try {
|
|
435
|
+
return await fn();
|
|
436
|
+
} finally {
|
|
437
|
+
await this.nodeAdmin.setConfig({ minTxsPerBlock });
|
|
438
|
+
}
|
|
404
439
|
}
|
|
405
440
|
|
|
406
|
-
private async
|
|
407
|
-
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
} catch (err) {
|
|
412
|
-
this.log.error(`Failed to flush transactions: ${err}`);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
441
|
+
private async advanceL2Block() {
|
|
442
|
+
await this.withNoMinTxsPerBlock(async () => {
|
|
443
|
+
const initialBlockNumber = await this.node!.getBlockNumber();
|
|
444
|
+
await retryUntil(async () => (await this.node!.getBlockNumber()) >= initialBlockNumber + 1);
|
|
445
|
+
});
|
|
415
446
|
}
|
|
416
447
|
}
|
package/src/utils.ts
CHANGED
|
@@ -14,13 +14,13 @@ export async function getBalances(
|
|
|
14
14
|
token: TokenContract,
|
|
15
15
|
who: AztecAddress,
|
|
16
16
|
): Promise<{ privateBalance: bigint; publicBalance: bigint }> {
|
|
17
|
-
const privateBalance = await token.methods.balance_of_private(who).simulate();
|
|
18
|
-
const publicBalance = await token.methods.balance_of_public(who).simulate();
|
|
17
|
+
const privateBalance = await token.methods.balance_of_private(who).simulate({ from: who });
|
|
18
|
+
const publicBalance = await token.methods.balance_of_public(who).simulate({ from: who });
|
|
19
19
|
return { privateBalance, publicBalance };
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export async function getPrivateBalance(token: EasyPrivateTokenContract, who: AztecAddress): Promise<bigint> {
|
|
23
|
-
const privateBalance = await token.methods.get_balance(who).simulate();
|
|
23
|
+
const privateBalance = await token.methods.get_balance(who).simulate({ from: who });
|
|
24
24
|
return privateBalance;
|
|
25
25
|
}
|
|
26
26
|
|