@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.03f7ef2
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 +61 -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 +80 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +336 -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 +77 -0
- package/dest/bench/utils.d.ts +12 -38
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +26 -66
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +21 -13
- 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 +85 -57
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +20 -25
- 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 +51 -70
- package/dest/e2e_deploy_contract/deploy_test.d.ts +16 -8
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +13 -19
- package/dest/e2e_epochs/epochs_test.d.ts +65 -22
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +233 -49
- 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 +63 -0
- package/dest/e2e_fees/fees_test.d.ts +27 -12
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +106 -109
- package/dest/e2e_l1_publisher/write_json.d.ts +10 -0
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
- package/dest/e2e_l1_publisher/write_json.js +58 -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 +10 -7
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +24 -20
- 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 +136 -0
- package/dest/e2e_p2p/p2p_network.d.ts +276 -23
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +188 -133
- package/dest/e2e_p2p/shared.d.ts +43 -7
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +164 -19
- package/dest/e2e_token_contract/token_contract_test.d.ts +12 -6
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +50 -26
- package/dest/fixtures/e2e_prover_test.d.ts +61 -0
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +108 -112
- package/dest/fixtures/fixtures.d.ts +6 -8
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +5 -5
- package/dest/fixtures/get_acvm_config.d.ts +2 -2
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
- package/dest/fixtures/get_acvm_config.js +3 -15
- package/dest/fixtures/get_bb_config.d.ts +2 -2
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +10 -17
- package/dest/fixtures/index.d.ts +1 -1
- package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +45 -19
- package/dest/fixtures/logging.d.ts +1 -1
- package/dest/fixtures/setup_p2p_test.d.ts +15 -14
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +82 -22
- package/dest/fixtures/snapshot_manager.d.ts +20 -14
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +154 -140
- package/dest/fixtures/token_utils.d.ts +10 -4
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +28 -12
- package/dest/fixtures/utils.d.ts +95 -54
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +456 -389
- package/dest/fixtures/web3signer.d.ts +5 -0
- package/dest/fixtures/web3signer.d.ts.map +1 -0
- package/dest/fixtures/web3signer.js +53 -0
- package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
- package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
- package/dest/fixtures/with_telemetry_utils.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/quality_of_service/alert_checker.d.ts +2 -2
- package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts +42 -35
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +104 -50
- package/dest/shared/gas_portal_test_harness.d.ts +29 -31
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +51 -30
- package/dest/shared/index.d.ts +1 -1
- package/dest/shared/jest_setup.d.ts +1 -1
- package/dest/shared/jest_setup.js +1 -1
- package/dest/shared/submit-transactions.d.ts +6 -4
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +8 -7
- package/dest/shared/uniswap_l1_l2.d.ts +16 -13
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +149 -117
- package/dest/simulators/index.d.ts +1 -1
- package/dest/simulators/lending_simulator.d.ts +7 -11
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +16 -17
- package/dest/simulators/token_simulator.d.ts +6 -3
- 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 +26 -11
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +202 -58
- package/dest/spartan/tx_metrics.d.ts +39 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +95 -0
- package/dest/spartan/utils.d.ts +129 -313
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +559 -151
- package/package.json +65 -58
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +450 -0
- package/src/bench/client_flows/config.ts +61 -0
- package/src/bench/client_flows/data_extractor.ts +89 -0
- package/src/bench/utils.ts +22 -76
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +70 -107
- package/src/e2e_deploy_contract/deploy_test.ts +24 -39
- package/src/e2e_epochs/epochs_test.ts +299 -65
- package/src/e2e_fees/bridging_race.notest.ts +80 -0
- package/src/e2e_fees/fees_test.ts +151 -141
- package/src/e2e_l1_publisher/write_json.ts +77 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +29 -19
- package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
- package/src/e2e_p2p/p2p_network.ts +274 -171
- package/src/e2e_p2p/shared.ts +251 -29
- package/src/e2e_token_contract/token_contract_test.ts +43 -39
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +113 -160
- package/src/fixtures/fixtures.ts +5 -7
- package/src/fixtures/get_acvm_config.ts +4 -12
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/l1_to_l2_messaging.ts +56 -24
- package/src/fixtures/setup_p2p_test.ts +127 -39
- package/src/fixtures/snapshot_manager.ts +196 -162
- package/src/fixtures/token_utils.ts +32 -15
- package/src/fixtures/utils.ts +562 -475
- package/src/fixtures/web3signer.ts +63 -0
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/guides/up_quick_start.sh +7 -15
- package/src/quality_of_service/alert_checker.ts +1 -1
- package/src/shared/cross_chain_test_harness.ts +112 -80
- package/src/shared/gas_portal_test_harness.ts +59 -50
- package/src/shared/jest_setup.ts +1 -1
- package/src/shared/submit-transactions.ts +12 -8
- package/src/shared/uniswap_l1_l2.ts +187 -192
- package/src/simulators/lending_simulator.ts +15 -16
- package/src/simulators/token_simulator.ts +21 -13
- package/src/spartan/DEVELOP.md +128 -0
- package/src/spartan/setup_test_wallets.ts +252 -93
- package/src/spartan/tx_metrics.ts +130 -0
- package/src/spartan/utils.ts +641 -146
- package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
- package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
- package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.js +0 -17
- 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/fixtures/setup_l1_contracts.ts +0 -27
- 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
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { AztecAddress, EthAddress
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { computeAuthWitMessageHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
|
|
4
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
5
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
6
|
+
import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
|
|
7
|
+
import { extractEvent } from '@aztec/ethereum/utils';
|
|
8
|
+
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
9
|
+
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
5
10
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
11
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
12
|
+
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
6
13
|
import { jest } from '@jest/globals';
|
|
7
14
|
import { getContract, parseEther, toFunctionSelector } from 'viem';
|
|
8
|
-
import {
|
|
15
|
+
import { ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
9
16
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
10
17
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
11
18
|
// don't need to burn through RPC requests.
|
|
@@ -13,26 +20,20 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
|
13
20
|
// To start an actual fork, use the command:
|
|
14
21
|
// anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
|
|
15
22
|
// For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
|
|
16
|
-
// docs:start:uniswap_l1_l2_test_setup_const
|
|
17
23
|
const TIMEOUT = 360_000;
|
|
18
|
-
// docs:end:uniswap_l1_l2_test_setup_const
|
|
19
24
|
export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 17514288)=>{
|
|
20
|
-
// docs:start:uniswap_l1_l2_test_beforeAll
|
|
21
25
|
describe('uniswap_trade_on_l1_from_l2', ()=>{
|
|
22
26
|
jest.setTimeout(TIMEOUT);
|
|
23
27
|
const WETH9_ADDRESS = EthAddress.fromString('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2');
|
|
24
28
|
const DAI_ADDRESS = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');
|
|
25
29
|
let aztecNode;
|
|
26
|
-
let pxe;
|
|
27
30
|
let logger;
|
|
28
|
-
let
|
|
29
|
-
let
|
|
30
|
-
let ownerWallet;
|
|
31
|
+
let l1Client;
|
|
32
|
+
let wallet;
|
|
31
33
|
let ownerAddress;
|
|
32
34
|
let ownerEthAddress;
|
|
33
35
|
// does transactions on behalf of owner on Aztec:
|
|
34
|
-
let
|
|
35
|
-
// let sponsorAddress: AztecAddress;
|
|
36
|
+
let sponsorAddress;
|
|
36
37
|
let daiCrossChainHarness;
|
|
37
38
|
let wethCrossChainHarness;
|
|
38
39
|
let deployL1ContractsValues;
|
|
@@ -44,54 +45,51 @@ 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,
|
|
49
|
-
if (Number(await
|
|
50
|
+
({ aztecNode, logger, l1Client, wallet, ownerAddress, sponsorAddress, 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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// sponsorAddress = sponsorWallet.getAddress();
|
|
59
|
-
ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
|
|
60
|
-
await ensureAccountsPubliclyDeployed(ownerWallet, [
|
|
61
|
-
ownerWallet,
|
|
62
|
-
sponsorWallet
|
|
54
|
+
rollup = new RollupContract(deployL1ContractsValues.l1Client, deployL1ContractsValues.l1ContractAddresses.rollupAddress);
|
|
55
|
+
version = Number(await rollup.getVersion());
|
|
56
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
57
|
+
await ensureAccountContractsPublished(wallet, [
|
|
58
|
+
ownerAddress,
|
|
59
|
+
sponsorAddress
|
|
63
60
|
]);
|
|
64
61
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
65
|
-
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode,
|
|
62
|
+
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, deployL1ContractsValues.l1Client, wallet, ownerAddress, logger, DAI_ADDRESS);
|
|
66
63
|
logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
|
|
67
|
-
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode,
|
|
64
|
+
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, l1Client, wallet, ownerAddress, logger, WETH9_ADDRESS);
|
|
68
65
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
69
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
66
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
|
|
70
67
|
uniswapPortal = getContract({
|
|
71
68
|
address: uniswapPortalAddress.toString(),
|
|
72
69
|
abi: UniswapPortalAbi,
|
|
73
|
-
client:
|
|
70
|
+
client: l1Client
|
|
74
71
|
});
|
|
75
72
|
// deploy l2 uniswap contract and attach to portal
|
|
76
|
-
uniswapL2Contract = await UniswapContract.deploy(
|
|
77
|
-
|
|
73
|
+
uniswapL2Contract = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
|
|
74
|
+
from: ownerAddress
|
|
75
|
+
}).deployed();
|
|
76
|
+
const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
78
77
|
await uniswapPortal.write.initialize([
|
|
79
78
|
registryAddress.toString(),
|
|
80
79
|
uniswapL2Contract.address.toString()
|
|
81
80
|
], {});
|
|
82
81
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
83
82
|
logger.info('Getting some weth');
|
|
84
|
-
const hash = await
|
|
83
|
+
const hash = await l1Client.sendTransaction({
|
|
85
84
|
to: WETH9_ADDRESS.toString(),
|
|
86
85
|
value: parseEther('1000')
|
|
87
86
|
});
|
|
88
|
-
await
|
|
87
|
+
await l1Client.waitForTransactionReceipt({
|
|
89
88
|
hash
|
|
90
89
|
});
|
|
91
90
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
92
91
|
expect(wethBalance).toBe(parseEther('1000'));
|
|
93
92
|
});
|
|
94
|
-
// docs:end:uniswap_l1_l2_test_beforeAll
|
|
95
93
|
afterAll(async ()=>{
|
|
96
94
|
await cleanup();
|
|
97
95
|
});
|
|
@@ -114,14 +112,19 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
114
112
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
115
113
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
116
114
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
117
|
-
await
|
|
115
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
118
116
|
caller: uniswapL2Contract.address,
|
|
119
117
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
120
118
|
});
|
|
121
119
|
// 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets.
|
|
122
120
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
123
121
|
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(
|
|
122
|
+
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
123
|
+
from: ownerAddress,
|
|
124
|
+
authWitnesses: [
|
|
125
|
+
transferToPublicAuhtwit
|
|
126
|
+
]
|
|
127
|
+
}).wait();
|
|
125
128
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
126
129
|
const swapPrivateContent = sha256ToField([
|
|
127
130
|
Buffer.from(toFunctionSelector(swapPrivateFunction).substring(2), 'hex'),
|
|
@@ -133,44 +136,48 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
133
136
|
secretHashForDepositingSwappedDai,
|
|
134
137
|
ownerEthAddress.toBuffer32()
|
|
135
138
|
]);
|
|
136
|
-
const swapPrivateLeaf =
|
|
137
|
-
uniswapL2Contract.address,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
new Fr(
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
140
|
+
l2Sender: uniswapL2Contract.address,
|
|
141
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
142
|
+
content: swapPrivateContent,
|
|
143
|
+
rollupVersion: new Fr(version),
|
|
144
|
+
chainId: new Fr(l1Client.chain.id)
|
|
145
|
+
});
|
|
143
146
|
const withdrawContent = sha256ToField([
|
|
144
147
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
145
148
|
uniswapPortalAddress.toBuffer32(),
|
|
146
149
|
new Fr(wethAmountToBridge),
|
|
147
150
|
uniswapPortalAddress.toBuffer32()
|
|
148
151
|
]);
|
|
149
|
-
const withdrawLeaf =
|
|
150
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
new Fr(
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
153
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
154
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
155
|
+
content: withdrawContent,
|
|
156
|
+
rollupVersion: new Fr(version),
|
|
157
|
+
chainId: new Fr(l1Client.chain.id)
|
|
158
|
+
});
|
|
156
159
|
// ensure that user's funds were burnt
|
|
157
160
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
158
161
|
// ensure that uniswap contract didn't eat the funds.
|
|
159
162
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
160
163
|
// 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.
|
|
164
|
+
await cheatCodes.rollup.markAsProven(await rollup.getCheckpointNumber());
|
|
162
165
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
163
166
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
164
167
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(daiCrossChainHarness.tokenPortalAddress);
|
|
165
|
-
const
|
|
166
|
-
const
|
|
168
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, l2UniswapInteractionReceipt.blockNumber, swapPrivateLeaf);
|
|
169
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, l2UniswapInteractionReceipt.blockNumber, withdrawLeaf);
|
|
170
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
171
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
172
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
173
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
167
174
|
const withdrawMessageMetadata = {
|
|
168
|
-
|
|
175
|
+
_checkpointNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
|
|
169
176
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
170
177
|
_path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
171
178
|
};
|
|
172
179
|
const swapPrivateMessageMetadata = {
|
|
173
|
-
|
|
180
|
+
_checkpointNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
|
|
174
181
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
175
182
|
_path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
176
183
|
};
|
|
@@ -188,7 +195,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
188
195
|
]
|
|
189
196
|
];
|
|
190
197
|
// this should also insert a message into the inbox.
|
|
191
|
-
const txReceipt = await daiCrossChainHarness.
|
|
198
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
192
199
|
hash: await uniswapPortal.write.swapPrivate(swapArgs)
|
|
193
200
|
});
|
|
194
201
|
// We get the msg leaf from event so that we can later wait for it to be available for consumption
|
|
@@ -352,14 +359,14 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
352
359
|
// withdrawLeaf,
|
|
353
360
|
// );
|
|
354
361
|
// const withdrawMessageMetadata = {
|
|
355
|
-
//
|
|
362
|
+
// _checkpointNumber: BigInt(uniswapL2Interaction.blockNumber!),
|
|
356
363
|
// _leafIndex: BigInt(withdrawL2MessageIndex),
|
|
357
364
|
// _path: withdrawSiblingPath
|
|
358
365
|
// .toBufferArray()
|
|
359
366
|
// .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
|
|
360
367
|
// };
|
|
361
368
|
// const swapPrivateMessageMetadata = {
|
|
362
|
-
//
|
|
369
|
+
// _checkpointNumber: BigInt(uniswapL2Interaction.blockNumber!),
|
|
363
370
|
// _leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
364
371
|
// _path: swapPrivateSiblingPath
|
|
365
372
|
// .toBufferArray()
|
|
@@ -432,12 +439,11 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
432
439
|
const nonceForWETHTransferToPublicApproval = new Fr(2n);
|
|
433
440
|
const expectedMessageHash = await computeAuthWitMessageHash({
|
|
434
441
|
caller: uniswapL2Contract.address,
|
|
435
|
-
|
|
436
|
-
},
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
});
|
|
440
|
-
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).prove()).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
442
|
+
call: await wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval).getFunctionCall()
|
|
443
|
+
}, await wallet.getChainInfo());
|
|
444
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).simulate({
|
|
445
|
+
from: ownerAddress
|
|
446
|
+
})).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
441
447
|
});
|
|
442
448
|
it("can't swap if user passes a token different to what the bridge tracks", async ()=>{
|
|
443
449
|
// 1. give user private funds on L2:
|
|
@@ -446,13 +452,18 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
446
452
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
447
453
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
448
454
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
449
|
-
await
|
|
455
|
+
const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
|
|
450
456
|
caller: uniswapL2Contract.address,
|
|
451
457
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
452
458
|
});
|
|
453
459
|
// 3. Swap but send the wrong token address
|
|
454
460
|
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).
|
|
461
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).send({
|
|
462
|
+
from: ownerAddress,
|
|
463
|
+
authWitnesses: [
|
|
464
|
+
transferToPublicAuthwith
|
|
465
|
+
]
|
|
466
|
+
}).wait()).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
456
467
|
});
|
|
457
468
|
// edge cases for public flow:
|
|
458
469
|
it("I don't need approval to call swap_public if I'm swapping on my own behalf", async ()=>{
|
|
@@ -460,14 +471,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
460
471
|
await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
|
|
461
472
|
// 2. Give approval to uniswap to transfer funds to itself
|
|
462
473
|
const nonceForWETHTransferApproval = new Fr(2n);
|
|
463
|
-
const validateActionInteraction = await
|
|
474
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
464
475
|
caller: uniswapL2Contract.address,
|
|
465
476
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
466
477
|
}, true);
|
|
467
478
|
await validateActionInteraction.send().wait();
|
|
468
479
|
// No approval to call `swap` but should work even without it:
|
|
469
480
|
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(
|
|
481
|
+
await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
482
|
+
from: ownerAddress
|
|
483
|
+
}).wait();
|
|
471
484
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
472
485
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
473
486
|
});
|
|
@@ -477,23 +490,27 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
477
490
|
const nonceForWETHTransferApproval = new Fr(3n);
|
|
478
491
|
const nonceForSwap = new Fr(3n);
|
|
479
492
|
const secretHashForDepositingSwappedDai = new Fr(4n);
|
|
480
|
-
const action = uniswapL2Contract.
|
|
481
|
-
const validateActionInteraction = await
|
|
493
|
+
const action = uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, nonceForSwap);
|
|
494
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
482
495
|
caller: approvedUser,
|
|
483
496
|
action
|
|
484
497
|
}, true);
|
|
485
498
|
await validateActionInteraction.send().wait();
|
|
486
|
-
await expect(action.simulate(
|
|
499
|
+
await expect(action.simulate({
|
|
500
|
+
from: sponsorAddress
|
|
501
|
+
})).rejects.toThrow(/unauthorized/);
|
|
487
502
|
});
|
|
488
503
|
it("uniswap can't pull funds without transfer approval", async ()=>{
|
|
489
504
|
// swap should fail since no transfer approval to uniswap:
|
|
490
505
|
const nonceForWETHTransferApproval = new Fr(4n);
|
|
491
|
-
const validateActionInteraction = await
|
|
506
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
492
507
|
caller: uniswapL2Contract.address,
|
|
493
508
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
494
509
|
}, true);
|
|
495
510
|
await validateActionInteraction.send().wait();
|
|
496
|
-
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(
|
|
511
|
+
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({
|
|
512
|
+
from: ownerAddress
|
|
513
|
+
})).rejects.toThrow(/unauthorized/);
|
|
497
514
|
});
|
|
498
515
|
// tests when trying to mix private and public flows:
|
|
499
516
|
it("can't call swap_public on L1 if called swap_private on L2", async ()=>{
|
|
@@ -503,7 +520,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
503
520
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
504
521
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
505
522
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
506
|
-
await
|
|
523
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
507
524
|
caller: uniswapL2Contract.address,
|
|
508
525
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
509
526
|
});
|
|
@@ -511,7 +528,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
511
528
|
// Swap
|
|
512
529
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
513
530
|
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(
|
|
531
|
+
const withdrawReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
532
|
+
from: ownerAddress,
|
|
533
|
+
authWitnesses: [
|
|
534
|
+
transferToPublicAuhtwit
|
|
535
|
+
]
|
|
536
|
+
}).wait();
|
|
515
537
|
const swapPrivateContent = sha256ToField([
|
|
516
538
|
Buffer.from(toFunctionSelector('swap_private(address,uint256,uint24,address,uint256,bytes32,address)').substring(2), 'hex'),
|
|
517
539
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -522,42 +544,46 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
522
544
|
secretHashForDepositingSwappedDai,
|
|
523
545
|
ownerEthAddress.toBuffer32()
|
|
524
546
|
]);
|
|
525
|
-
const swapPrivateLeaf =
|
|
526
|
-
uniswapL2Contract.address,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
new Fr(
|
|
530
|
-
|
|
531
|
-
|
|
547
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
548
|
+
l2Sender: uniswapL2Contract.address,
|
|
549
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
550
|
+
content: swapPrivateContent,
|
|
551
|
+
rollupVersion: new Fr(version),
|
|
552
|
+
chainId: new Fr(l1Client.chain.id)
|
|
553
|
+
});
|
|
532
554
|
const withdrawContent = sha256ToField([
|
|
533
555
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
534
556
|
uniswapPortalAddress.toBuffer32(),
|
|
535
557
|
new Fr(wethAmountToBridge),
|
|
536
558
|
uniswapPortalAddress.toBuffer32()
|
|
537
559
|
]);
|
|
538
|
-
const withdrawLeaf =
|
|
539
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
new Fr(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
const
|
|
560
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
561
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
562
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
563
|
+
content: withdrawContent,
|
|
564
|
+
rollupVersion: new Fr(version),
|
|
565
|
+
chainId: new Fr(l1Client.chain.id)
|
|
566
|
+
});
|
|
567
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, swapPrivateLeaf);
|
|
568
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, withdrawLeaf);
|
|
569
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
570
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
571
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
572
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
547
573
|
const withdrawMessageMetadata = {
|
|
548
|
-
|
|
574
|
+
_checkpointNumber: BigInt(withdrawReceipt.blockNumber),
|
|
549
575
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
550
576
|
_path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
551
577
|
};
|
|
552
578
|
const swapPrivateMessageMetadata = {
|
|
553
|
-
|
|
579
|
+
_checkpointNumber: BigInt(withdrawReceipt.blockNumber),
|
|
554
580
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
555
581
|
_path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
556
582
|
};
|
|
557
583
|
// ensure that user's funds were burnt
|
|
558
584
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
559
585
|
// 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.
|
|
586
|
+
await cheatCodes.rollup.markAsProven(await rollup.getCheckpointNumber());
|
|
561
587
|
// On L1 call swap_public!
|
|
562
588
|
logger.info('call swap_public on L1');
|
|
563
589
|
const swapArgs = [
|
|
@@ -583,14 +609,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
583
609
|
await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
|
|
584
610
|
// Owner gives uniswap approval to transfer funds on its behalf
|
|
585
611
|
const nonceForWETHTransferApproval = new Fr(5n);
|
|
586
|
-
const validateActionInteraction = await
|
|
612
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
587
613
|
caller: uniswapL2Contract.address,
|
|
588
614
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
589
615
|
}, true);
|
|
590
616
|
await validateActionInteraction.send().wait();
|
|
591
617
|
// Call swap_public on L2
|
|
592
618
|
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(
|
|
619
|
+
const withdrawReceipt = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
620
|
+
from: ownerAddress
|
|
621
|
+
}).wait();
|
|
594
622
|
const swapPublicContent = sha256ToField([
|
|
595
623
|
Buffer.from(toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(2), 'hex'),
|
|
596
624
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -602,42 +630,46 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
602
630
|
secretHashForDepositingSwappedDai,
|
|
603
631
|
ownerEthAddress.toBuffer32()
|
|
604
632
|
]);
|
|
605
|
-
const swapPublicLeaf =
|
|
606
|
-
uniswapL2Contract.address,
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
new Fr(
|
|
610
|
-
|
|
611
|
-
|
|
633
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
634
|
+
l2Sender: uniswapL2Contract.address,
|
|
635
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
636
|
+
content: swapPublicContent,
|
|
637
|
+
rollupVersion: new Fr(version),
|
|
638
|
+
chainId: new Fr(l1Client.chain.id)
|
|
639
|
+
});
|
|
612
640
|
const withdrawContent = sha256ToField([
|
|
613
641
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
614
642
|
uniswapPortalAddress.toBuffer32(),
|
|
615
643
|
new Fr(wethAmountToBridge),
|
|
616
644
|
uniswapPortalAddress.toBuffer32()
|
|
617
645
|
]);
|
|
618
|
-
const withdrawLeaf =
|
|
619
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
new Fr(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
const
|
|
646
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
647
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
648
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
649
|
+
content: withdrawContent,
|
|
650
|
+
rollupVersion: new Fr(version),
|
|
651
|
+
chainId: new Fr(l1Client.chain.id)
|
|
652
|
+
});
|
|
653
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, swapPublicLeaf);
|
|
654
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, withdrawLeaf);
|
|
655
|
+
const swapPublicL2MessageIndex = swapResult.leafIndex;
|
|
656
|
+
const swapPublicSiblingPath = swapResult.siblingPath;
|
|
657
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
658
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
627
659
|
const withdrawMessageMetadata = {
|
|
628
|
-
|
|
660
|
+
_checkpointNumber: BigInt(withdrawReceipt.blockNumber),
|
|
629
661
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
630
662
|
_path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
631
663
|
};
|
|
632
664
|
const swapPublicMessageMetadata = {
|
|
633
|
-
|
|
665
|
+
_checkpointNumber: BigInt(withdrawReceipt.blockNumber),
|
|
634
666
|
_leafIndex: BigInt(swapPublicL2MessageIndex),
|
|
635
667
|
_path: swapPublicSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
636
668
|
};
|
|
637
669
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
638
670
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
639
671
|
// 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.
|
|
672
|
+
await cheatCodes.rollup.markAsProven(await rollup.getCheckpointNumber());
|
|
641
673
|
// Call swap_private on L1
|
|
642
674
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
643
675
|
const swapArgs = [
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './lending_simulator.js';
|
|
2
2
|
export * from './token_simulator.js';
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zaW11bGF0b3JzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsd0JBQXdCLENBQUM7QUFDdkMsY0FBYyxzQkFBc0IsQ0FBQyJ9
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AztecAddress
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
+
import { CheatCodes } from '@aztec/aztec/testing';
|
|
4
|
+
import type { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
5
|
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
3
|
-
import type { RollupAbi } from '@aztec/l1-artifacts';
|
|
4
6
|
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
7
|
import type { TokenSimulator } from './token_simulator.js';
|
|
8
8
|
/**
|
|
9
9
|
* Contains utilities to compute the "key" for private holdings in the public state.
|
|
@@ -28,13 +28,9 @@ export declare class LendingSimulator {
|
|
|
28
28
|
private account;
|
|
29
29
|
private rate;
|
|
30
30
|
private ethereumSlotDuration;
|
|
31
|
-
|
|
32
|
-
rollup: GetContractReturnType<typeof RollupAbi, WalletClient<HttpTransport, chains.Chain, Account>>;
|
|
33
|
-
/** the lending contract */
|
|
31
|
+
rollup: RollupContract;
|
|
34
32
|
lendingContract: LendingContract;
|
|
35
|
-
/** the collateral asset used in the lending contract */
|
|
36
33
|
collateralAsset: TokenSimulator;
|
|
37
|
-
/** the stable-coin borrowed in the lending contract */
|
|
38
34
|
stableCoin: TokenSimulator;
|
|
39
35
|
/** interest rate accumulator */
|
|
40
36
|
accumulator: bigint;
|
|
@@ -46,7 +42,7 @@ export declare class LendingSimulator {
|
|
|
46
42
|
private mintedOutside;
|
|
47
43
|
constructor(cc: CheatCodes, account: LendingAccount, rate: bigint, ethereumSlotDuration: number,
|
|
48
44
|
/** the rollup contract */
|
|
49
|
-
rollup:
|
|
45
|
+
rollup: RollupContract,
|
|
50
46
|
/** the lending contract */
|
|
51
47
|
lendingContract: LendingContract,
|
|
52
48
|
/** the collateral asset used in the lending contract */
|
|
@@ -66,4 +62,4 @@ export declare class LendingSimulator {
|
|
|
66
62
|
mintStableCoinOutsideLoan(recipient: AztecAddress, amount: bigint, priv?: boolean): void;
|
|
67
63
|
check(): Promise<void>;
|
|
68
64
|
}
|
|
69
|
-
//# sourceMappingURL=
|
|
65
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGVuZGluZ19zaW11bGF0b3IuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zaW11bGF0b3JzL2xlbmRpbmdfc2ltdWxhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUN6RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDNUMsT0FBTyxFQUFFLFV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BVSxFQUFFLEVBQUUsRUFBRSxNQUFNLEVBQUUsTUFBTSxRQUc3RDtJQUVELE9BQU8sQ0FBQyxLQUFLO0lBUWIseUJBQXlCLENBQUMsU0FBUyxFQUFFLFlBQVksRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLElBQUksVUFBUSxRQU85RTtJQUVLLEtBQUssa0JBeUJWO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lending_simulator.d.ts","sourceRoot":"","sources":["../../src/simulators/lending_simulator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"lending_simulator.d.ts","sourceRoot":"","sources":["../../src/simulators/lending_simulator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;GAEG;AACH,qBAAa,cAAc;IACzB,yCAAyC;IACzC,SAAgB,OAAO,EAAE,YAAY,CAAC;IACtC,2CAA2C;IAC3C,SAAgB,MAAM,EAAE,EAAE,CAAC;IAE3B,YAAY,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAG5C;IAED;;;OAGG;IACI,GAAG,gBAET;CACF;AAgCD;;GAEG;AACH,qBAAa,gBAAgB;IAYzB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,oBAAoB;IAErB,M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