@aztec/end-to-end 0.0.0-test.1 → 0.0.1-fake-ceab37513c
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/bench/client_flows/benchmark.d.ts +60 -0
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/benchmark.js +261 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +69 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +315 -0
- package/dest/bench/client_flows/config.d.ts +14 -0
- package/dest/bench/client_flows/config.d.ts.map +1 -0
- package/dest/bench/client_flows/config.js +106 -0
- package/dest/bench/client_flows/data_extractor.d.ts +2 -0
- package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
- package/dest/bench/client_flows/data_extractor.js +99 -0
- package/dest/bench/utils.d.ts +10 -27
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +27 -43
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +15 -7
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +66 -38
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +10 -18
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +34 -53
- package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -2
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +9 -6
- package/dest/e2e_epochs/epochs_test.d.ts +56 -17
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +222 -42
- package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
- package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
- package/dest/e2e_fees/bridging_race.notest.js +60 -0
- package/dest/e2e_fees/fees_test.d.ts +16 -5
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +87 -88
- package/dest/e2e_l1_publisher/write_json.d.ts +8 -0
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
- package/dest/e2e_l1_publisher/write_json.js +57 -0
- package/dest/e2e_multi_validator/utils.d.ts +12 -0
- package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
- package/dest/e2e_multi_validator/utils.js +214 -0
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +5 -5
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +19 -14
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
- package/dest/e2e_p2p/inactivity_slash_test.js +132 -0
- package/dest/e2e_p2p/p2p_network.d.ts +56 -21
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +154 -125
- package/dest/e2e_p2p/shared.d.ts +41 -3
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +146 -6
- package/dest/e2e_token_contract/token_contract_test.d.ts +10 -5
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +51 -24
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +7 -4
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +67 -62
- package/dest/fixtures/fixtures.d.ts +5 -6
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +4 -3
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
- package/dest/fixtures/get_acvm_config.js +2 -14
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +8 -15
- package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +44 -18
- package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
- package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
- package/dest/fixtures/setup_l1_contracts.js +3 -3
- package/dest/fixtures/setup_p2p_test.d.ts +14 -6
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +73 -21
- package/dest/fixtures/snapshot_manager.d.ts +8 -3
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +120 -104
- package/dest/fixtures/token_utils.d.ts +4 -3
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +24 -7
- package/dest/fixtures/utils.d.ts +65 -22
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +439 -318
- package/dest/fixtures/web3signer.d.ts +5 -0
- package/dest/fixtures/web3signer.d.ts.map +1 -0
- package/dest/fixtures/web3signer.js +42 -0
- package/dest/shared/cross_chain_test_harness.d.ts +28 -18
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +97 -41
- package/dest/shared/gas_portal_test_harness.d.ts +23 -18
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +43 -25
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.d.ts +5 -6
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +136 -90
- package/dest/simulators/lending_simulator.d.ts +5 -6
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +11 -15
- package/dest/simulators/token_simulator.d.ts +2 -1
- package/dest/simulators/token_simulator.d.ts.map +1 -1
- package/dest/simulators/token_simulator.js +16 -13
- package/dest/spartan/setup_test_wallets.d.ts +8 -1
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +108 -22
- package/dest/spartan/utils.d.ts +60 -307
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +200 -115
- package/package.json +60 -56
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +422 -0
- package/src/bench/client_flows/config.ts +61 -0
- package/src/bench/client_flows/data_extractor.ts +111 -0
- package/src/bench/utils.ts +26 -52
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +60 -40
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +47 -75
- package/src/e2e_deploy_contract/deploy_test.ts +11 -8
- package/src/e2e_epochs/epochs_test.ts +276 -54
- package/src/e2e_fees/bridging_race.notest.ts +75 -0
- package/src/e2e_fees/fees_test.ts +121 -108
- package/src/e2e_l1_publisher/write_json.ts +74 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +22 -14
- package/src/e2e_p2p/inactivity_slash_test.ts +174 -0
- package/src/e2e_p2p/p2p_network.ts +212 -144
- package/src/e2e_p2p/shared.ts +234 -14
- package/src/e2e_token_contract/token_contract_test.ts +42 -38
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +62 -69
- package/src/fixtures/fixtures.ts +4 -3
- package/src/fixtures/get_acvm_config.ts +2 -10
- package/src/fixtures/get_bb_config.ts +15 -11
- package/src/fixtures/l1_to_l2_messaging.ts +53 -23
- package/src/fixtures/setup_l1_contracts.ts +5 -6
- package/src/fixtures/setup_p2p_test.ts +112 -30
- package/src/fixtures/snapshot_manager.ts +150 -102
- package/src/fixtures/token_utils.ts +33 -8
- package/src/fixtures/utils.ts +530 -352
- package/src/fixtures/web3signer.ts +46 -0
- package/src/guides/up_quick_start.sh +4 -4
- package/src/shared/cross_chain_test_harness.ts +92 -52
- package/src/shared/gas_portal_test_harness.ts +47 -31
- package/src/shared/uniswap_l1_l2.ts +127 -124
- package/src/simulators/lending_simulator.ts +11 -15
- package/src/simulators/token_simulator.ts +17 -12
- package/src/spartan/DEVELOP.md +116 -0
- package/src/spartan/setup_test_wallets.ts +144 -29
- package/src/spartan/utils.ts +194 -116
- package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
- package/dest/sample-dapp/connect.js +0 -12
- package/dest/sample-dapp/contracts.js +0 -10
- package/dest/sample-dapp/deploy.js +0 -35
- package/dest/sample-dapp/index.js +0 -98
- package/src/sample-dapp/connect.mjs +0 -16
- package/src/sample-dapp/contracts.mjs +0 -14
- package/src/sample-dapp/deploy.mjs +0 -40
- package/src/sample-dapp/index.mjs +0 -128
|
@@ -7,8 +7,8 @@ export class FeeJuicePortalTestingHarnessFactory {
|
|
|
7
7
|
this.config = config;
|
|
8
8
|
}
|
|
9
9
|
async createReal() {
|
|
10
|
-
const { aztecNode,
|
|
11
|
-
const ethAccount = EthAddress.fromString((await
|
|
10
|
+
const { aztecNode, aztecNodeAdmin, pxeService, l1Client, wallet, logger } = this.config;
|
|
11
|
+
const ethAccount = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
12
12
|
const l1ContractAddresses = (await pxeService.getNodeInfo()).l1ContractAddresses;
|
|
13
13
|
const feeJuiceAddress = l1ContractAddresses.feeJuiceAddress;
|
|
14
14
|
const feeJuicePortalAddress = l1ContractAddresses.feeJuicePortalAddress;
|
|
@@ -16,7 +16,7 @@ export class FeeJuicePortalTestingHarnessFactory {
|
|
|
16
16
|
throw new Error('Fee Juice portal not deployed on L1');
|
|
17
17
|
}
|
|
18
18
|
const gasL2 = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, wallet);
|
|
19
|
-
return new GasBridgingTestHarness(aztecNode, pxeService, logger, gasL2, ethAccount, feeJuicePortalAddress, feeJuiceAddress,
|
|
19
|
+
return new GasBridgingTestHarness(aztecNode, aztecNodeAdmin, pxeService, logger, gasL2, ethAccount, feeJuicePortalAddress, feeJuiceAddress, l1ContractAddresses.feeAssetHandlerAddress, l1Client);
|
|
20
20
|
}
|
|
21
21
|
static create(config) {
|
|
22
22
|
const factory = new FeeJuicePortalTestingHarnessFactory(config);
|
|
@@ -28,54 +28,62 @@ export class FeeJuicePortalTestingHarnessFactory {
|
|
|
28
28
|
* shared between cross chain tests.
|
|
29
29
|
*/ export class GasBridgingTestHarness {
|
|
30
30
|
aztecNode;
|
|
31
|
+
aztecNodeAdmin;
|
|
31
32
|
pxeService;
|
|
32
33
|
logger;
|
|
33
34
|
feeJuice;
|
|
34
35
|
ethAccount;
|
|
35
36
|
feeJuicePortalAddress;
|
|
36
37
|
l1FeeJuiceAddress;
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
feeAssetHandlerAddress;
|
|
39
|
+
l1Client;
|
|
39
40
|
l1TokenManager;
|
|
40
41
|
feeJuicePortalManager;
|
|
41
|
-
constructor(/** Aztec node */ aztecNode, /** Private eXecution Environment (PXE). */ pxeService, /** Logger. */ logger, /** L2 Token/Bridge contract. */ feeJuice, /** Eth account to interact with. */ ethAccount, /** Portal address. */ feeJuicePortalAddress, /** Underlying token for portal tests. */ l1FeeJuiceAddress, /**
|
|
42
|
+
constructor(/** Aztec node */ aztecNode, /** Aztec node admin interface */ aztecNodeAdmin, /** Private eXecution Environment (PXE). */ pxeService, /** Logger. */ logger, /** L2 Token/Bridge contract. */ feeJuice, /** Eth account to interact with. */ ethAccount, /** Portal address. */ feeJuicePortalAddress, /** Underlying token for portal tests. */ l1FeeJuiceAddress, /** Fee asset handler address. */ feeAssetHandlerAddress, /** Viem Extended client instance. */ l1Client){
|
|
42
43
|
this.aztecNode = aztecNode;
|
|
44
|
+
this.aztecNodeAdmin = aztecNodeAdmin;
|
|
43
45
|
this.pxeService = pxeService;
|
|
44
46
|
this.logger = logger;
|
|
45
47
|
this.feeJuice = feeJuice;
|
|
46
48
|
this.ethAccount = ethAccount;
|
|
47
49
|
this.feeJuicePortalAddress = feeJuicePortalAddress;
|
|
48
50
|
this.l1FeeJuiceAddress = l1FeeJuiceAddress;
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.feeJuicePortalManager = new L1FeeJuicePortalManager(this.feeJuicePortalAddress, this.l1FeeJuiceAddress, this.
|
|
51
|
+
this.feeAssetHandlerAddress = feeAssetHandlerAddress;
|
|
52
|
+
this.l1Client = l1Client;
|
|
53
|
+
this.feeJuicePortalManager = new L1FeeJuicePortalManager(this.feeJuicePortalAddress, this.l1FeeJuiceAddress, this.feeAssetHandlerAddress, this.l1Client, this.logger);
|
|
52
54
|
this.l1TokenManager = this.feeJuicePortalManager.getTokenManager();
|
|
53
55
|
}
|
|
54
|
-
async mintTokensOnL1(
|
|
55
|
-
const balanceBefore = await this.l1TokenManager.getL1TokenBalance(to.toString());
|
|
56
|
-
await this.l1TokenManager.mint(
|
|
57
|
-
|
|
56
|
+
async mintTokensOnL1(to = this.ethAccount) {
|
|
57
|
+
// const balanceBefore = await this.l1TokenManager.getL1TokenBalance(to.toString());
|
|
58
|
+
await this.l1TokenManager.mint(to.toString());
|
|
59
|
+
// expect(await this.l1TokenManager.getL1TokenBalance(to.toString())).toEqual(balanceBefore + amount);
|
|
58
60
|
}
|
|
59
61
|
async getL1FeeJuiceBalance(address) {
|
|
60
62
|
return await this.l1TokenManager.getL1TokenBalance(address.toString());
|
|
61
63
|
}
|
|
62
|
-
sendTokensToPortalPublic(bridgeAmount, l2Address
|
|
63
|
-
return this.feeJuicePortalManager.bridgeTokensPublic(l2Address, bridgeAmount,
|
|
64
|
+
sendTokensToPortalPublic(bridgeAmount, l2Address) {
|
|
65
|
+
return this.feeJuicePortalManager.bridgeTokensPublic(l2Address, bridgeAmount, false);
|
|
64
66
|
}
|
|
65
|
-
async consumeMessageOnAztecAndClaimPrivately(owner, claim) {
|
|
67
|
+
async consumeMessageOnAztecAndClaimPrivately(owner, claimer, claim) {
|
|
66
68
|
this.logger.info('Consuming messages on L2 Privately');
|
|
67
69
|
const { claimAmount, claimSecret, messageLeafIndex } = claim;
|
|
68
|
-
await this.feeJuice.methods.claim(owner, claimAmount, claimSecret, messageLeafIndex).send(
|
|
70
|
+
await this.feeJuice.methods.claim(owner, claimAmount, claimSecret, messageLeafIndex).send({
|
|
71
|
+
from: claimer
|
|
72
|
+
}).wait();
|
|
69
73
|
}
|
|
70
74
|
async getL2PublicBalanceOf(owner) {
|
|
71
|
-
return await this.feeJuice.methods.balance_of_public(owner).simulate(
|
|
75
|
+
return await this.feeJuice.methods.balance_of_public(owner).simulate({
|
|
76
|
+
from: owner
|
|
77
|
+
});
|
|
72
78
|
}
|
|
73
79
|
async expectPublicBalanceOnL2(owner, expectedBalance) {
|
|
74
80
|
const balance = await this.getL2PublicBalanceOf(owner);
|
|
75
81
|
expect(balance).toBe(expectedBalance);
|
|
76
82
|
}
|
|
77
|
-
async prepareTokensOnL1(
|
|
78
|
-
const
|
|
83
|
+
async prepareTokensOnL1(owner) {
|
|
84
|
+
const bridgeAmount = await this.l1TokenManager.getMintAmount();
|
|
85
|
+
await this.mintTokensOnL1();
|
|
86
|
+
const claim = await this.sendTokensToPortalPublic(bridgeAmount, owner);
|
|
79
87
|
const isSynced = async ()=>await this.aztecNode.isL1ToL2MessageSynced(Fr.fromHexString(claim.messageHash));
|
|
80
88
|
await retryUntil(isSynced, `message ${claim.messageHash} sync`, 24, 1);
|
|
81
89
|
// Progress by 2 L2 blocks so that the l1ToL2Message added above will be available to use on L2.
|
|
@@ -83,16 +91,26 @@ export class FeeJuicePortalTestingHarnessFactory {
|
|
|
83
91
|
await this.advanceL2Block();
|
|
84
92
|
return claim;
|
|
85
93
|
}
|
|
86
|
-
async bridgeFromL1ToL2(
|
|
94
|
+
async bridgeFromL1ToL2(owner, claimer) {
|
|
87
95
|
// Prepare the tokens on the L1 side
|
|
88
|
-
const claim = await this.prepareTokensOnL1(
|
|
96
|
+
const claim = await this.prepareTokensOnL1(owner);
|
|
89
97
|
// Consume L1 -> L2 message and claim tokens privately on L2
|
|
90
|
-
await this.consumeMessageOnAztecAndClaimPrivately(owner, claim);
|
|
91
|
-
await this.expectPublicBalanceOnL2(owner, bridgeAmount);
|
|
98
|
+
await this.consumeMessageOnAztecAndClaimPrivately(owner, claimer, claim);
|
|
92
99
|
}
|
|
93
100
|
async advanceL2Block() {
|
|
94
101
|
const initialBlockNumber = await this.aztecNode.getBlockNumber();
|
|
95
|
-
|
|
102
|
+
let minTxsPerBlock = undefined;
|
|
103
|
+
if (this.aztecNodeAdmin) {
|
|
104
|
+
({ minTxsPerBlock } = await this.aztecNodeAdmin.getConfig());
|
|
105
|
+
await this.aztecNodeAdmin.setConfig({
|
|
106
|
+
minTxsPerBlock: 0
|
|
107
|
+
}); // Set to 0 to ensure we can advance the block
|
|
108
|
+
}
|
|
96
109
|
await retryUntil(async ()=>await this.aztecNode.getBlockNumber() >= initialBlockNumber + 1);
|
|
110
|
+
if (this.aztecNodeAdmin && minTxsPerBlock !== undefined) {
|
|
111
|
+
await this.aztecNodeAdmin.setConfig({
|
|
112
|
+
minTxsPerBlock
|
|
113
|
+
});
|
|
114
|
+
}
|
|
97
115
|
}
|
|
98
116
|
} // docs:end:cross_chain_test_harness
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submit-transactions.d.ts","sourceRoot":"","sources":["../../src/shared/submit-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,MAAM,EAAE,KAAK,MAAM,EAAY,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEtG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"submit-transactions.d.ts","sourceRoot":"","sources":["../../src/shared/submit-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,MAAM,EAAE,KAAK,MAAM,EAAY,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEtG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,eAAO,MAAM,WAAW,GACtB,KAAK,UAAU,EACf,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,QAAQ,MAAM,KACb,OAAO,CAAC,MAAM,EAAE,CAqBlB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type AccountWallet, type AztecNode, type
|
|
2
|
-
import {
|
|
1
|
+
import { type AccountWallet, type AztecNode, type Logger, type PXE } from '@aztec/aztec.js';
|
|
2
|
+
import { CheatCodes } from '@aztec/aztec/testing';
|
|
3
|
+
import { type DeployL1ContractsReturnType, type ExtendedViemWalletClient } from '@aztec/ethereum';
|
|
3
4
|
/** Objects to be returned by the uniswap setup function */
|
|
4
5
|
export type UniswapSetupContext = {
|
|
5
6
|
/** Aztec Node instance */
|
|
@@ -8,10 +9,8 @@ export type UniswapSetupContext = {
|
|
|
8
9
|
pxe: PXE;
|
|
9
10
|
/** Logger instance named as the current test. */
|
|
10
11
|
logger: Logger;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/** Viem Wallet Client instance. */
|
|
14
|
-
walletClient: ViemWalletClient;
|
|
12
|
+
/** The L1 wallet client, extended with public actions. */
|
|
13
|
+
l1Client: ExtendedViemWalletClient;
|
|
15
14
|
/** The owner wallet. */
|
|
16
15
|
ownerWallet: AccountWallet;
|
|
17
16
|
/** The sponsor wallet. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniswap_l1_l2.d.ts","sourceRoot":"","sources":["../../src/shared/uniswap_l1_l2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"uniswap_l1_l2.d.ts","sourceRoot":"","sources":["../../src/shared/uniswap_l1_l2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,SAAS,EAGd,KAAK,MAAM,EACX,KAAK,GAAG,EAGT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAI9B,MAAM,iBAAiB,CAAC;AAuBzB,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,0BAA0B;IAC1B,SAAS,EAAE,SAAS,CAAC;IACrB,+CAA+C;IAC/C,GAAG,EAAE,GAAG,CAAC;IACT,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,QAAQ,EAAE,wBAAwB,CAAC;IACnC,wBAAwB;IACxB,WAAW,EAAE,aAAa,CAAC;IAC3B,0BAA0B;IAC1B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO;IACP,uBAAuB,EAAE,2BAA2B,CAAC;IACrD,4BAA4B;IAC5B,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAGF,eAAO,MAAM,oBAAoB,GAC/B,OAAO,MAAM,OAAO,CAAC,mBAAmB,CAAC,EACzC,SAAS,MAAM,OAAO,CAAC,IAAI,CAAC,EAC5B,gCAAkC,SAg+BnC,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { AztecAddress, EthAddress, Fr, computeAuthWitMessageHash, generateClaimSecret } from '@aztec/aztec.js';
|
|
2
|
-
import { deployL1Contract, extractEvent } from '@aztec/ethereum';
|
|
2
|
+
import { RollupContract, deployL1Contract, extractEvent } from '@aztec/ethereum';
|
|
3
3
|
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
4
|
-
import { InboxAbi,
|
|
4
|
+
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
5
5
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
6
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
7
|
+
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
6
8
|
import { jest } from '@jest/globals';
|
|
7
9
|
import { getContract, parseEther, toFunctionSelector } from 'viem';
|
|
8
|
-
import {
|
|
10
|
+
import { ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
9
11
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
10
12
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
11
13
|
// don't need to burn through RPC requests.
|
|
@@ -25,14 +27,13 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
25
27
|
let aztecNode;
|
|
26
28
|
let pxe;
|
|
27
29
|
let logger;
|
|
28
|
-
let
|
|
29
|
-
let publicClient;
|
|
30
|
+
let l1Client;
|
|
30
31
|
let ownerWallet;
|
|
31
32
|
let ownerAddress;
|
|
32
33
|
let ownerEthAddress;
|
|
33
34
|
// does transactions on behalf of owner on Aztec:
|
|
34
35
|
let sponsorWallet;
|
|
35
|
-
|
|
36
|
+
let sponsorAddress;
|
|
36
37
|
let daiCrossChainHarness;
|
|
37
38
|
let wethCrossChainHarness;
|
|
38
39
|
let deployL1ContractsValues;
|
|
@@ -44,36 +45,36 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
44
45
|
const uniswapFeeTier = 3000n;
|
|
45
46
|
const minimumOutputAmount = 0n;
|
|
46
47
|
let cheatCodes;
|
|
48
|
+
let version;
|
|
47
49
|
beforeAll(async ()=>{
|
|
48
|
-
({ aztecNode, pxe, logger,
|
|
49
|
-
if (Number(await
|
|
50
|
+
({ aztecNode, pxe, logger, l1Client, ownerWallet, sponsorWallet, deployL1ContractsValues, cheatCodes } = await setup());
|
|
51
|
+
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
50
52
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
51
53
|
}
|
|
52
|
-
rollup =
|
|
53
|
-
|
|
54
|
-
abi: RollupAbi,
|
|
55
|
-
client: deployL1ContractsValues.walletClient
|
|
56
|
-
});
|
|
54
|
+
rollup = new RollupContract(deployL1ContractsValues.l1Client, deployL1ContractsValues.l1ContractAddresses.rollupAddress);
|
|
55
|
+
version = Number(await rollup.getVersion());
|
|
57
56
|
ownerAddress = ownerWallet.getAddress();
|
|
58
|
-
|
|
59
|
-
ownerEthAddress = EthAddress.fromString((await
|
|
60
|
-
await
|
|
57
|
+
sponsorAddress = sponsorWallet.getAddress();
|
|
58
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
59
|
+
await ensureAccountContractsPublished(ownerWallet, [
|
|
61
60
|
ownerWallet,
|
|
62
61
|
sponsorWallet
|
|
63
62
|
]);
|
|
64
63
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
65
|
-
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe,
|
|
64
|
+
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe, deployL1ContractsValues.l1Client, ownerWallet, ownerAddress, logger, DAI_ADDRESS);
|
|
66
65
|
logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
|
|
67
|
-
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe,
|
|
66
|
+
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, pxe, l1Client, ownerWallet, ownerAddress, logger, WETH9_ADDRESS);
|
|
68
67
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
69
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
68
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
|
|
70
69
|
uniswapPortal = getContract({
|
|
71
70
|
address: uniswapPortalAddress.toString(),
|
|
72
71
|
abi: UniswapPortalAbi,
|
|
73
|
-
client:
|
|
72
|
+
client: l1Client
|
|
74
73
|
});
|
|
75
74
|
// deploy l2 uniswap contract and attach to portal
|
|
76
|
-
uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress).send(
|
|
75
|
+
uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress).send({
|
|
76
|
+
from: ownerAddress
|
|
77
|
+
}).deployed();
|
|
77
78
|
const registryAddress = (await pxe.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
78
79
|
await uniswapPortal.write.initialize([
|
|
79
80
|
registryAddress.toString(),
|
|
@@ -81,11 +82,11 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
81
82
|
], {});
|
|
82
83
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
83
84
|
logger.info('Getting some weth');
|
|
84
|
-
const hash = await
|
|
85
|
+
const hash = await l1Client.sendTransaction({
|
|
85
86
|
to: WETH9_ADDRESS.toString(),
|
|
86
87
|
value: parseEther('1000')
|
|
87
88
|
});
|
|
88
|
-
await
|
|
89
|
+
await l1Client.waitForTransactionReceipt({
|
|
89
90
|
hash
|
|
90
91
|
});
|
|
91
92
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
@@ -114,14 +115,19 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
114
115
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
115
116
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
116
117
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
117
|
-
await ownerWallet.createAuthWit({
|
|
118
|
+
const transferToPublicAuhtwit = await ownerWallet.createAuthWit({
|
|
118
119
|
caller: uniswapL2Contract.address,
|
|
119
120
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
120
121
|
});
|
|
121
122
|
// 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets.
|
|
122
123
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
123
124
|
const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
124
|
-
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send(
|
|
125
|
+
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
126
|
+
from: ownerAddress,
|
|
127
|
+
authWitnesses: [
|
|
128
|
+
transferToPublicAuhtwit
|
|
129
|
+
]
|
|
130
|
+
}).wait();
|
|
125
131
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
126
132
|
const swapPrivateContent = sha256ToField([
|
|
127
133
|
Buffer.from(toFunctionSelector(swapPrivateFunction).substring(2), 'hex'),
|
|
@@ -133,37 +139,41 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
133
139
|
secretHashForDepositingSwappedDai,
|
|
134
140
|
ownerEthAddress.toBuffer32()
|
|
135
141
|
]);
|
|
136
|
-
const swapPrivateLeaf =
|
|
137
|
-
uniswapL2Contract.address,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
new Fr(
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
143
|
+
l2Sender: uniswapL2Contract.address,
|
|
144
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
145
|
+
content: swapPrivateContent,
|
|
146
|
+
rollupVersion: new Fr(version),
|
|
147
|
+
chainId: new Fr(l1Client.chain.id)
|
|
148
|
+
});
|
|
143
149
|
const withdrawContent = sha256ToField([
|
|
144
150
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
145
151
|
uniswapPortalAddress.toBuffer32(),
|
|
146
152
|
new Fr(wethAmountToBridge),
|
|
147
153
|
uniswapPortalAddress.toBuffer32()
|
|
148
154
|
]);
|
|
149
|
-
const withdrawLeaf =
|
|
150
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
new Fr(
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
156
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
157
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
158
|
+
content: withdrawContent,
|
|
159
|
+
rollupVersion: new Fr(version),
|
|
160
|
+
chainId: new Fr(l1Client.chain.id)
|
|
161
|
+
});
|
|
156
162
|
// ensure that user's funds were burnt
|
|
157
163
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
158
164
|
// ensure that uniswap contract didn't eat the funds.
|
|
159
165
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
160
166
|
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
161
|
-
await cheatCodes.rollup.markAsProven(await rollup.
|
|
167
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
162
168
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
163
169
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
164
170
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(daiCrossChainHarness.tokenPortalAddress);
|
|
165
|
-
const
|
|
166
|
-
const
|
|
171
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, l2UniswapInteractionReceipt.blockNumber, swapPrivateLeaf);
|
|
172
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, l2UniswapInteractionReceipt.blockNumber, withdrawLeaf);
|
|
173
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
174
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
175
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
176
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
167
177
|
const withdrawMessageMetadata = {
|
|
168
178
|
_l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
|
|
169
179
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -188,7 +198,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
188
198
|
]
|
|
189
199
|
];
|
|
190
200
|
// this should also insert a message into the inbox.
|
|
191
|
-
const txReceipt = await daiCrossChainHarness.
|
|
201
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
192
202
|
hash: await uniswapPortal.write.swapPrivate(swapArgs)
|
|
193
203
|
});
|
|
194
204
|
// We get the msg leaf from event so that we can later wait for it to be available for consumption
|
|
@@ -437,7 +447,9 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
437
447
|
chainId: ownerWallet.getChainId(),
|
|
438
448
|
version: ownerWallet.getVersion()
|
|
439
449
|
});
|
|
440
|
-
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).
|
|
450
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).simulate({
|
|
451
|
+
from: ownerAddress
|
|
452
|
+
})).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
441
453
|
});
|
|
442
454
|
it("can't swap if user passes a token different to what the bridge tracks", async ()=>{
|
|
443
455
|
// 1. give user private funds on L2:
|
|
@@ -446,13 +458,18 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
446
458
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
447
459
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
448
460
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
449
|
-
await ownerWallet.createAuthWit({
|
|
461
|
+
const transferToPublicAuthwith = await ownerWallet.createAuthWit({
|
|
450
462
|
caller: uniswapL2Contract.address,
|
|
451
463
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
452
464
|
});
|
|
453
465
|
// 3. Swap but send the wrong token address
|
|
454
466
|
logger.info('Swap but send the wrong token address');
|
|
455
|
-
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).prove(
|
|
467
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).prove({
|
|
468
|
+
from: ownerAddress,
|
|
469
|
+
authWitnesses: [
|
|
470
|
+
transferToPublicAuthwith
|
|
471
|
+
]
|
|
472
|
+
})).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
456
473
|
});
|
|
457
474
|
// edge cases for public flow:
|
|
458
475
|
it("I don't need approval to call swap_public if I'm swapping on my own behalf", async ()=>{
|
|
@@ -464,10 +481,14 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
464
481
|
caller: uniswapL2Contract.address,
|
|
465
482
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
466
483
|
}, true);
|
|
467
|
-
await validateActionInteraction.send(
|
|
484
|
+
await validateActionInteraction.send({
|
|
485
|
+
from: ownerAddress
|
|
486
|
+
}).wait();
|
|
468
487
|
// No approval to call `swap` but should work even without it:
|
|
469
488
|
const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
470
|
-
await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send(
|
|
489
|
+
await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
490
|
+
from: ownerAddress
|
|
491
|
+
}).wait();
|
|
471
492
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
472
493
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
473
494
|
});
|
|
@@ -482,8 +503,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
482
503
|
caller: approvedUser,
|
|
483
504
|
action
|
|
484
505
|
}, true);
|
|
485
|
-
await validateActionInteraction.send(
|
|
486
|
-
|
|
506
|
+
await validateActionInteraction.send({
|
|
507
|
+
from: ownerAddress
|
|
508
|
+
}).wait();
|
|
509
|
+
await expect(action.simulate({
|
|
510
|
+
from: sponsorAddress
|
|
511
|
+
})).rejects.toThrow(/unauthorized/);
|
|
487
512
|
});
|
|
488
513
|
it("uniswap can't pull funds without transfer approval", async ()=>{
|
|
489
514
|
// swap should fail since no transfer approval to uniswap:
|
|
@@ -492,8 +517,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
492
517
|
caller: uniswapL2Contract.address,
|
|
493
518
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
494
519
|
}, true);
|
|
495
|
-
await validateActionInteraction.send(
|
|
496
|
-
|
|
520
|
+
await validateActionInteraction.send({
|
|
521
|
+
from: ownerAddress
|
|
522
|
+
}).wait();
|
|
523
|
+
await expect(uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, new Fr(420), uniswapFeeTier, minimumOutputAmount, ownerAddress, Fr.random(), ownerEthAddress, Fr.ZERO).simulate({
|
|
524
|
+
from: ownerAddress
|
|
525
|
+
})).rejects.toThrow(/unauthorized/);
|
|
497
526
|
});
|
|
498
527
|
// tests when trying to mix private and public flows:
|
|
499
528
|
it("can't call swap_public on L1 if called swap_private on L2", async ()=>{
|
|
@@ -503,7 +532,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
503
532
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
504
533
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
505
534
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
506
|
-
await ownerWallet.createAuthWit({
|
|
535
|
+
const transferToPublicAuhtwit = await ownerWallet.createAuthWit({
|
|
507
536
|
caller: uniswapL2Contract.address,
|
|
508
537
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
509
538
|
});
|
|
@@ -511,7 +540,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
511
540
|
// Swap
|
|
512
541
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
513
542
|
const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
514
|
-
const withdrawReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send(
|
|
543
|
+
const withdrawReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
544
|
+
from: ownerAddress,
|
|
545
|
+
authWitnesses: [
|
|
546
|
+
transferToPublicAuhtwit
|
|
547
|
+
]
|
|
548
|
+
}).wait();
|
|
515
549
|
const swapPrivateContent = sha256ToField([
|
|
516
550
|
Buffer.from(toFunctionSelector('swap_private(address,uint256,uint24,address,uint256,bytes32,address)').substring(2), 'hex'),
|
|
517
551
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -522,28 +556,32 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
522
556
|
secretHashForDepositingSwappedDai,
|
|
523
557
|
ownerEthAddress.toBuffer32()
|
|
524
558
|
]);
|
|
525
|
-
const swapPrivateLeaf =
|
|
526
|
-
uniswapL2Contract.address,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
new Fr(
|
|
530
|
-
|
|
531
|
-
|
|
559
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
560
|
+
l2Sender: uniswapL2Contract.address,
|
|
561
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
562
|
+
content: swapPrivateContent,
|
|
563
|
+
rollupVersion: new Fr(version),
|
|
564
|
+
chainId: new Fr(l1Client.chain.id)
|
|
565
|
+
});
|
|
532
566
|
const withdrawContent = sha256ToField([
|
|
533
567
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
534
568
|
uniswapPortalAddress.toBuffer32(),
|
|
535
569
|
new Fr(wethAmountToBridge),
|
|
536
570
|
uniswapPortalAddress.toBuffer32()
|
|
537
571
|
]);
|
|
538
|
-
const withdrawLeaf =
|
|
539
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
new Fr(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
const
|
|
572
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
573
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
574
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
575
|
+
content: withdrawContent,
|
|
576
|
+
rollupVersion: new Fr(version),
|
|
577
|
+
chainId: new Fr(l1Client.chain.id)
|
|
578
|
+
});
|
|
579
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, swapPrivateLeaf);
|
|
580
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, withdrawLeaf);
|
|
581
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
582
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
583
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
584
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
547
585
|
const withdrawMessageMetadata = {
|
|
548
586
|
_l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
|
|
549
587
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -557,7 +595,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
557
595
|
// ensure that user's funds were burnt
|
|
558
596
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
559
597
|
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
560
|
-
await cheatCodes.rollup.markAsProven(await rollup.
|
|
598
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
561
599
|
// On L1 call swap_public!
|
|
562
600
|
logger.info('call swap_public on L1');
|
|
563
601
|
const swapArgs = [
|
|
@@ -587,10 +625,14 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
587
625
|
caller: uniswapL2Contract.address,
|
|
588
626
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
589
627
|
}, true);
|
|
590
|
-
await validateActionInteraction.send(
|
|
628
|
+
await validateActionInteraction.send({
|
|
629
|
+
from: ownerAddress
|
|
630
|
+
}).wait();
|
|
591
631
|
// Call swap_public on L2
|
|
592
632
|
const secretHashForDepositingSwappedDai = Fr.random();
|
|
593
|
-
const withdrawReceipt = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send(
|
|
633
|
+
const withdrawReceipt = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
634
|
+
from: ownerAddress
|
|
635
|
+
}).wait();
|
|
594
636
|
const swapPublicContent = sha256ToField([
|
|
595
637
|
Buffer.from(toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(2), 'hex'),
|
|
596
638
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -602,28 +644,32 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
602
644
|
secretHashForDepositingSwappedDai,
|
|
603
645
|
ownerEthAddress.toBuffer32()
|
|
604
646
|
]);
|
|
605
|
-
const swapPublicLeaf =
|
|
606
|
-
uniswapL2Contract.address,
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
new Fr(
|
|
610
|
-
|
|
611
|
-
|
|
647
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
648
|
+
l2Sender: uniswapL2Contract.address,
|
|
649
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
650
|
+
content: swapPublicContent,
|
|
651
|
+
rollupVersion: new Fr(version),
|
|
652
|
+
chainId: new Fr(l1Client.chain.id)
|
|
653
|
+
});
|
|
612
654
|
const withdrawContent = sha256ToField([
|
|
613
655
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
614
656
|
uniswapPortalAddress.toBuffer32(),
|
|
615
657
|
new Fr(wethAmountToBridge),
|
|
616
658
|
uniswapPortalAddress.toBuffer32()
|
|
617
659
|
]);
|
|
618
|
-
const withdrawLeaf =
|
|
619
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
new Fr(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
const
|
|
660
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
661
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
662
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
663
|
+
content: withdrawContent,
|
|
664
|
+
rollupVersion: new Fr(version),
|
|
665
|
+
chainId: new Fr(l1Client.chain.id)
|
|
666
|
+
});
|
|
667
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, swapPublicLeaf);
|
|
668
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, withdrawLeaf);
|
|
669
|
+
const swapPublicL2MessageIndex = swapResult.leafIndex;
|
|
670
|
+
const swapPublicSiblingPath = swapResult.siblingPath;
|
|
671
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
672
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
627
673
|
const withdrawMessageMetadata = {
|
|
628
674
|
_l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
|
|
629
675
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -637,7 +683,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
637
683
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
638
684
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
639
685
|
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
640
|
-
await cheatCodes.rollup.markAsProven(await rollup.
|
|
686
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
641
687
|
// Call swap_private on L1
|
|
642
688
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
643
689
|
const swapArgs = [
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AztecAddress,
|
|
1
|
+
import { AztecAddress, Fr } from '@aztec/aztec.js';
|
|
2
|
+
import { CheatCodes } from '@aztec/aztec/testing';
|
|
3
|
+
import type { RollupContract } from '@aztec/ethereum';
|
|
2
4
|
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
3
|
-
import type { RollupAbi } from '@aztec/l1-artifacts';
|
|
4
5
|
import type { LendingContract } from '@aztec/noir-contracts.js/Lending';
|
|
5
|
-
import type { Account, GetContractReturnType, HttpTransport, WalletClient } from 'viem';
|
|
6
|
-
import type * as chains from 'viem/chains';
|
|
7
6
|
import type { TokenSimulator } from './token_simulator.js';
|
|
8
7
|
/**
|
|
9
8
|
* Contains utilities to compute the "key" for private holdings in the public state.
|
|
@@ -29,7 +28,7 @@ export declare class LendingSimulator {
|
|
|
29
28
|
private rate;
|
|
30
29
|
private ethereumSlotDuration;
|
|
31
30
|
/** the rollup contract */
|
|
32
|
-
rollup:
|
|
31
|
+
rollup: RollupContract;
|
|
33
32
|
/** the lending contract */
|
|
34
33
|
lendingContract: LendingContract;
|
|
35
34
|
/** the collateral asset used in the lending contract */
|
|
@@ -46,7 +45,7 @@ export declare class LendingSimulator {
|
|
|
46
45
|
private mintedOutside;
|
|
47
46
|
constructor(cc: CheatCodes, account: LendingAccount, rate: bigint, ethereumSlotDuration: number,
|
|
48
47
|
/** the rollup contract */
|
|
49
|
-
rollup:
|
|
48
|
+
rollup: RollupContract,
|
|
50
49
|
/** the lending contract */
|
|
51
50
|
lendingContract: LendingContract,
|
|
52
51
|
/** the collateral asset used in the lending contract */
|