@aztec/end-to-end 0.0.0-test.0 → 0.0.1-fake-c83136db25
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 +73 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +311 -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 -36
- 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 +20 -12
- 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 +18 -24
- 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 +48 -69
- package/dest/e2e_deploy_contract/deploy_test.d.ts +14 -6
- 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 +58 -17
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +224 -43
- 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 +20 -9
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +98 -107
- 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 +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 +9 -6
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +22 -19
- 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 +135 -0
- package/dest/e2e_p2p/p2p_network.d.ts +69 -22
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +180 -129
- package/dest/e2e_p2p/shared.d.ts +41 -5
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +163 -19
- package/dest/e2e_token_contract/token_contract_test.d.ts +11 -5
- 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/{e2e_prover → fixtures}/e2e_prover_test.d.ts +14 -9
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +95 -100
- 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 +1 -1
- 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 +1 -1
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +10 -17
- 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 +4 -4
- package/dest/fixtures/setup_p2p_test.d.ts +14 -13
- 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 +15 -7
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +147 -121
- package/dest/fixtures/token_utils.d.ts +6 -3
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +23 -10
- package/dest/fixtures/utils.d.ts +76 -37
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +464 -368
- 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/quality_of_service/alert_checker.d.ts +1 -1
- package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts +41 -25
- 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 +32 -24
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +50 -29
- package/dest/shared/jest_setup.js +1 -1
- package/dest/shared/submit-transactions.d.ts +5 -3
- 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 +13 -11
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +138 -108
- package/dest/simulators/lending_simulator.d.ts +6 -6
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +13 -16
- package/dest/simulators/token_simulator.d.ts +5 -2
- 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 +23 -10
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +167 -58
- package/dest/spartan/utils.d.ts +100 -303
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +407 -130
- package/package.json +61 -56
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +402 -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 +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 +63 -105
- package/src/e2e_deploy_contract/deploy_test.ts +23 -38
- package/src/e2e_epochs/epochs_test.ts +274 -54
- package/src/e2e_fees/bridging_race.notest.ts +80 -0
- package/src/e2e_fees/fees_test.ts +137 -136
- package/src/e2e_l1_publisher/write_json.ts +76 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +27 -18
- package/src/e2e_p2p/inactivity_slash_test.ts +178 -0
- package/src/e2e_p2p/p2p_network.ts +272 -166
- package/src/e2e_p2p/shared.ts +244 -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 +101 -145
- package/src/fixtures/fixtures.ts +4 -3
- package/src/fixtures/get_acvm_config.ts +3 -11
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/l1_to_l2_messaging.ts +53 -23
- package/src/fixtures/setup_l1_contracts.ts +6 -7
- package/src/fixtures/setup_p2p_test.ts +112 -38
- package/src/fixtures/snapshot_manager.ts +187 -139
- package/src/fixtures/token_utils.ts +29 -12
- package/src/fixtures/utils.ts +552 -425
- package/src/fixtures/web3signer.ts +63 -0
- package/src/guides/up_quick_start.sh +6 -14
- package/src/quality_of_service/alert_checker.ts +1 -1
- package/src/shared/cross_chain_test_harness.ts +108 -79
- package/src/shared/gas_portal_test_harness.ts +58 -49
- package/src/shared/jest_setup.ts +1 -1
- package/src/shared/submit-transactions.ts +12 -8
- package/src/shared/uniswap_l1_l2.ts +173 -176
- package/src/simulators/lending_simulator.ts +12 -15
- package/src/simulators/token_simulator.ts +21 -13
- package/src/spartan/DEVELOP.md +121 -0
- package/src/spartan/setup_test_wallets.ts +215 -93
- package/src/spartan/utils.ts +458 -130
- 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
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { AztecAddress, EthAddress
|
|
2
|
-
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, deployL1Contract, extractEvent } from '@aztec/ethereum';
|
|
3
6
|
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
4
|
-
import { InboxAbi,
|
|
7
|
+
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
5
8
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
9
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
10
|
+
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
6
11
|
import { jest } from '@jest/globals';
|
|
7
12
|
import { getContract, parseEther, toFunctionSelector } from 'viem';
|
|
8
|
-
import {
|
|
13
|
+
import { ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
9
14
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
10
15
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
11
16
|
// don't need to burn through RPC requests.
|
|
@@ -13,26 +18,20 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
|
13
18
|
// To start an actual fork, use the command:
|
|
14
19
|
// anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
|
|
15
20
|
// For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
|
|
16
|
-
// docs:start:uniswap_l1_l2_test_setup_const
|
|
17
21
|
const TIMEOUT = 360_000;
|
|
18
|
-
// docs:end:uniswap_l1_l2_test_setup_const
|
|
19
22
|
export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 17514288)=>{
|
|
20
|
-
// docs:start:uniswap_l1_l2_test_beforeAll
|
|
21
23
|
describe('uniswap_trade_on_l1_from_l2', ()=>{
|
|
22
24
|
jest.setTimeout(TIMEOUT);
|
|
23
25
|
const WETH9_ADDRESS = EthAddress.fromString('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2');
|
|
24
26
|
const DAI_ADDRESS = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');
|
|
25
27
|
let aztecNode;
|
|
26
|
-
let pxe;
|
|
27
28
|
let logger;
|
|
28
|
-
let
|
|
29
|
-
let
|
|
30
|
-
let ownerWallet;
|
|
29
|
+
let l1Client;
|
|
30
|
+
let wallet;
|
|
31
31
|
let ownerAddress;
|
|
32
32
|
let ownerEthAddress;
|
|
33
33
|
// does transactions on behalf of owner on Aztec:
|
|
34
|
-
let
|
|
35
|
-
// let sponsorAddress: AztecAddress;
|
|
34
|
+
let sponsorAddress;
|
|
36
35
|
let daiCrossChainHarness;
|
|
37
36
|
let wethCrossChainHarness;
|
|
38
37
|
let deployL1ContractsValues;
|
|
@@ -44,54 +43,51 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
44
43
|
const uniswapFeeTier = 3000n;
|
|
45
44
|
const minimumOutputAmount = 0n;
|
|
46
45
|
let cheatCodes;
|
|
46
|
+
let version;
|
|
47
47
|
beforeAll(async ()=>{
|
|
48
|
-
({ aztecNode,
|
|
49
|
-
if (Number(await
|
|
48
|
+
({ aztecNode, logger, l1Client, wallet, ownerAddress, sponsorAddress, deployL1ContractsValues, cheatCodes } = await setup());
|
|
49
|
+
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
50
50
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
51
51
|
}
|
|
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
|
|
52
|
+
rollup = new RollupContract(deployL1ContractsValues.l1Client, deployL1ContractsValues.l1ContractAddresses.rollupAddress);
|
|
53
|
+
version = Number(await rollup.getVersion());
|
|
54
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
55
|
+
await ensureAccountContractsPublished(wallet, [
|
|
56
|
+
ownerAddress,
|
|
57
|
+
sponsorAddress
|
|
63
58
|
]);
|
|
64
59
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
65
|
-
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode,
|
|
60
|
+
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, deployL1ContractsValues.l1Client, wallet, ownerAddress, logger, DAI_ADDRESS);
|
|
66
61
|
logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
|
|
67
|
-
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode,
|
|
62
|
+
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, l1Client, wallet, ownerAddress, logger, WETH9_ADDRESS);
|
|
68
63
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
69
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
64
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
|
|
70
65
|
uniswapPortal = getContract({
|
|
71
66
|
address: uniswapPortalAddress.toString(),
|
|
72
67
|
abi: UniswapPortalAbi,
|
|
73
|
-
client:
|
|
68
|
+
client: l1Client
|
|
74
69
|
});
|
|
75
70
|
// deploy l2 uniswap contract and attach to portal
|
|
76
|
-
uniswapL2Contract = await UniswapContract.deploy(
|
|
77
|
-
|
|
71
|
+
uniswapL2Contract = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
|
|
72
|
+
from: ownerAddress
|
|
73
|
+
}).deployed();
|
|
74
|
+
const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
78
75
|
await uniswapPortal.write.initialize([
|
|
79
76
|
registryAddress.toString(),
|
|
80
77
|
uniswapL2Contract.address.toString()
|
|
81
78
|
], {});
|
|
82
79
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
83
80
|
logger.info('Getting some weth');
|
|
84
|
-
const hash = await
|
|
81
|
+
const hash = await l1Client.sendTransaction({
|
|
85
82
|
to: WETH9_ADDRESS.toString(),
|
|
86
83
|
value: parseEther('1000')
|
|
87
84
|
});
|
|
88
|
-
await
|
|
85
|
+
await l1Client.waitForTransactionReceipt({
|
|
89
86
|
hash
|
|
90
87
|
});
|
|
91
88
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
92
89
|
expect(wethBalance).toBe(parseEther('1000'));
|
|
93
90
|
});
|
|
94
|
-
// docs:end:uniswap_l1_l2_test_beforeAll
|
|
95
91
|
afterAll(async ()=>{
|
|
96
92
|
await cleanup();
|
|
97
93
|
});
|
|
@@ -114,14 +110,19 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
114
110
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
115
111
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
116
112
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
117
|
-
await
|
|
113
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
118
114
|
caller: uniswapL2Contract.address,
|
|
119
115
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
120
116
|
});
|
|
121
117
|
// 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets.
|
|
122
118
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
123
119
|
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(
|
|
120
|
+
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
121
|
+
from: ownerAddress,
|
|
122
|
+
authWitnesses: [
|
|
123
|
+
transferToPublicAuhtwit
|
|
124
|
+
]
|
|
125
|
+
}).wait();
|
|
125
126
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
126
127
|
const swapPrivateContent = sha256ToField([
|
|
127
128
|
Buffer.from(toFunctionSelector(swapPrivateFunction).substring(2), 'hex'),
|
|
@@ -133,37 +134,41 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
133
134
|
secretHashForDepositingSwappedDai,
|
|
134
135
|
ownerEthAddress.toBuffer32()
|
|
135
136
|
]);
|
|
136
|
-
const swapPrivateLeaf =
|
|
137
|
-
uniswapL2Contract.address,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
new Fr(
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
138
|
+
l2Sender: uniswapL2Contract.address,
|
|
139
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
140
|
+
content: swapPrivateContent,
|
|
141
|
+
rollupVersion: new Fr(version),
|
|
142
|
+
chainId: new Fr(l1Client.chain.id)
|
|
143
|
+
});
|
|
143
144
|
const withdrawContent = sha256ToField([
|
|
144
145
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
145
146
|
uniswapPortalAddress.toBuffer32(),
|
|
146
147
|
new Fr(wethAmountToBridge),
|
|
147
148
|
uniswapPortalAddress.toBuffer32()
|
|
148
149
|
]);
|
|
149
|
-
const withdrawLeaf =
|
|
150
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
new Fr(
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
151
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
152
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
153
|
+
content: withdrawContent,
|
|
154
|
+
rollupVersion: new Fr(version),
|
|
155
|
+
chainId: new Fr(l1Client.chain.id)
|
|
156
|
+
});
|
|
156
157
|
// ensure that user's funds were burnt
|
|
157
158
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
158
159
|
// ensure that uniswap contract didn't eat the funds.
|
|
159
160
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
160
161
|
// 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.
|
|
162
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
162
163
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
163
164
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
164
165
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(daiCrossChainHarness.tokenPortalAddress);
|
|
165
|
-
const
|
|
166
|
-
const
|
|
166
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, l2UniswapInteractionReceipt.blockNumber, swapPrivateLeaf);
|
|
167
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, l2UniswapInteractionReceipt.blockNumber, withdrawLeaf);
|
|
168
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
169
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
170
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
171
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
167
172
|
const withdrawMessageMetadata = {
|
|
168
173
|
_l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber),
|
|
169
174
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -188,7 +193,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
188
193
|
]
|
|
189
194
|
];
|
|
190
195
|
// this should also insert a message into the inbox.
|
|
191
|
-
const txReceipt = await daiCrossChainHarness.
|
|
196
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
192
197
|
hash: await uniswapPortal.write.swapPrivate(swapArgs)
|
|
193
198
|
});
|
|
194
199
|
// We get the msg leaf from event so that we can later wait for it to be available for consumption
|
|
@@ -432,12 +437,11 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
432
437
|
const nonceForWETHTransferToPublicApproval = new Fr(2n);
|
|
433
438
|
const expectedMessageHash = await computeAuthWitMessageHash({
|
|
434
439
|
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()}`);
|
|
440
|
+
call: await wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval).getFunctionCall()
|
|
441
|
+
}, await wallet.getChainInfo());
|
|
442
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).simulate({
|
|
443
|
+
from: ownerAddress
|
|
444
|
+
})).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
441
445
|
});
|
|
442
446
|
it("can't swap if user passes a token different to what the bridge tracks", async ()=>{
|
|
443
447
|
// 1. give user private funds on L2:
|
|
@@ -446,13 +450,18 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
446
450
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
447
451
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
448
452
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
449
|
-
await
|
|
453
|
+
const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
|
|
450
454
|
caller: uniswapL2Contract.address,
|
|
451
455
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
452
456
|
});
|
|
453
457
|
// 3. Swap but send the wrong token address
|
|
454
458
|
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).
|
|
459
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).send({
|
|
460
|
+
from: ownerAddress,
|
|
461
|
+
authWitnesses: [
|
|
462
|
+
transferToPublicAuthwith
|
|
463
|
+
]
|
|
464
|
+
}).wait()).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
456
465
|
});
|
|
457
466
|
// edge cases for public flow:
|
|
458
467
|
it("I don't need approval to call swap_public if I'm swapping on my own behalf", async ()=>{
|
|
@@ -460,14 +469,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
460
469
|
await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
|
|
461
470
|
// 2. Give approval to uniswap to transfer funds to itself
|
|
462
471
|
const nonceForWETHTransferApproval = new Fr(2n);
|
|
463
|
-
const validateActionInteraction = await
|
|
472
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
464
473
|
caller: uniswapL2Contract.address,
|
|
465
474
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
466
475
|
}, true);
|
|
467
476
|
await validateActionInteraction.send().wait();
|
|
468
477
|
// No approval to call `swap` but should work even without it:
|
|
469
478
|
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(
|
|
479
|
+
await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
480
|
+
from: ownerAddress
|
|
481
|
+
}).wait();
|
|
471
482
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
472
483
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
473
484
|
});
|
|
@@ -477,23 +488,27 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
477
488
|
const nonceForWETHTransferApproval = new Fr(3n);
|
|
478
489
|
const nonceForSwap = new Fr(3n);
|
|
479
490
|
const secretHashForDepositingSwappedDai = new Fr(4n);
|
|
480
|
-
const action = uniswapL2Contract.
|
|
481
|
-
const validateActionInteraction = await
|
|
491
|
+
const action = uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, nonceForSwap);
|
|
492
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
482
493
|
caller: approvedUser,
|
|
483
494
|
action
|
|
484
495
|
}, true);
|
|
485
496
|
await validateActionInteraction.send().wait();
|
|
486
|
-
await expect(action.simulate(
|
|
497
|
+
await expect(action.simulate({
|
|
498
|
+
from: sponsorAddress
|
|
499
|
+
})).rejects.toThrow(/unauthorized/);
|
|
487
500
|
});
|
|
488
501
|
it("uniswap can't pull funds without transfer approval", async ()=>{
|
|
489
502
|
// swap should fail since no transfer approval to uniswap:
|
|
490
503
|
const nonceForWETHTransferApproval = new Fr(4n);
|
|
491
|
-
const validateActionInteraction = await
|
|
504
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
492
505
|
caller: uniswapL2Contract.address,
|
|
493
506
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
494
507
|
}, true);
|
|
495
508
|
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(
|
|
509
|
+
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({
|
|
510
|
+
from: ownerAddress
|
|
511
|
+
})).rejects.toThrow(/unauthorized/);
|
|
497
512
|
});
|
|
498
513
|
// tests when trying to mix private and public flows:
|
|
499
514
|
it("can't call swap_public on L1 if called swap_private on L2", async ()=>{
|
|
@@ -503,7 +518,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
503
518
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
504
519
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
505
520
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
506
|
-
await
|
|
521
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
507
522
|
caller: uniswapL2Contract.address,
|
|
508
523
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
509
524
|
});
|
|
@@ -511,7 +526,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
511
526
|
// Swap
|
|
512
527
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
513
528
|
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(
|
|
529
|
+
const withdrawReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
530
|
+
from: ownerAddress,
|
|
531
|
+
authWitnesses: [
|
|
532
|
+
transferToPublicAuhtwit
|
|
533
|
+
]
|
|
534
|
+
}).wait();
|
|
515
535
|
const swapPrivateContent = sha256ToField([
|
|
516
536
|
Buffer.from(toFunctionSelector('swap_private(address,uint256,uint24,address,uint256,bytes32,address)').substring(2), 'hex'),
|
|
517
537
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -522,28 +542,32 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
522
542
|
secretHashForDepositingSwappedDai,
|
|
523
543
|
ownerEthAddress.toBuffer32()
|
|
524
544
|
]);
|
|
525
|
-
const swapPrivateLeaf =
|
|
526
|
-
uniswapL2Contract.address,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
new Fr(
|
|
530
|
-
|
|
531
|
-
|
|
545
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
546
|
+
l2Sender: uniswapL2Contract.address,
|
|
547
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
548
|
+
content: swapPrivateContent,
|
|
549
|
+
rollupVersion: new Fr(version),
|
|
550
|
+
chainId: new Fr(l1Client.chain.id)
|
|
551
|
+
});
|
|
532
552
|
const withdrawContent = sha256ToField([
|
|
533
553
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
534
554
|
uniswapPortalAddress.toBuffer32(),
|
|
535
555
|
new Fr(wethAmountToBridge),
|
|
536
556
|
uniswapPortalAddress.toBuffer32()
|
|
537
557
|
]);
|
|
538
|
-
const withdrawLeaf =
|
|
539
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
new Fr(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
const
|
|
558
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
559
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
560
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
561
|
+
content: withdrawContent,
|
|
562
|
+
rollupVersion: new Fr(version),
|
|
563
|
+
chainId: new Fr(l1Client.chain.id)
|
|
564
|
+
});
|
|
565
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, swapPrivateLeaf);
|
|
566
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, withdrawLeaf);
|
|
567
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
568
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
569
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
570
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
547
571
|
const withdrawMessageMetadata = {
|
|
548
572
|
_l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
|
|
549
573
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -557,7 +581,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
557
581
|
// ensure that user's funds were burnt
|
|
558
582
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
559
583
|
// 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.
|
|
584
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
561
585
|
// On L1 call swap_public!
|
|
562
586
|
logger.info('call swap_public on L1');
|
|
563
587
|
const swapArgs = [
|
|
@@ -583,14 +607,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
583
607
|
await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
|
|
584
608
|
// Owner gives uniswap approval to transfer funds on its behalf
|
|
585
609
|
const nonceForWETHTransferApproval = new Fr(5n);
|
|
586
|
-
const validateActionInteraction = await
|
|
610
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
587
611
|
caller: uniswapL2Contract.address,
|
|
588
612
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
589
613
|
}, true);
|
|
590
614
|
await validateActionInteraction.send().wait();
|
|
591
615
|
// Call swap_public on L2
|
|
592
616
|
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(
|
|
617
|
+
const withdrawReceipt = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
618
|
+
from: ownerAddress
|
|
619
|
+
}).wait();
|
|
594
620
|
const swapPublicContent = sha256ToField([
|
|
595
621
|
Buffer.from(toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(2), 'hex'),
|
|
596
622
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -602,28 +628,32 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
602
628
|
secretHashForDepositingSwappedDai,
|
|
603
629
|
ownerEthAddress.toBuffer32()
|
|
604
630
|
]);
|
|
605
|
-
const swapPublicLeaf =
|
|
606
|
-
uniswapL2Contract.address,
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
new Fr(
|
|
610
|
-
|
|
611
|
-
|
|
631
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
632
|
+
l2Sender: uniswapL2Contract.address,
|
|
633
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
634
|
+
content: swapPublicContent,
|
|
635
|
+
rollupVersion: new Fr(version),
|
|
636
|
+
chainId: new Fr(l1Client.chain.id)
|
|
637
|
+
});
|
|
612
638
|
const withdrawContent = sha256ToField([
|
|
613
639
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
614
640
|
uniswapPortalAddress.toBuffer32(),
|
|
615
641
|
new Fr(wethAmountToBridge),
|
|
616
642
|
uniswapPortalAddress.toBuffer32()
|
|
617
643
|
]);
|
|
618
|
-
const withdrawLeaf =
|
|
619
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
new Fr(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
const
|
|
644
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
645
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
646
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
647
|
+
content: withdrawContent,
|
|
648
|
+
rollupVersion: new Fr(version),
|
|
649
|
+
chainId: new Fr(l1Client.chain.id)
|
|
650
|
+
});
|
|
651
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, swapPublicLeaf);
|
|
652
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber, withdrawLeaf);
|
|
653
|
+
const swapPublicL2MessageIndex = swapResult.leafIndex;
|
|
654
|
+
const swapPublicSiblingPath = swapResult.siblingPath;
|
|
655
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
656
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
627
657
|
const withdrawMessageMetadata = {
|
|
628
658
|
_l2BlockNumber: BigInt(withdrawReceipt.blockNumber),
|
|
629
659
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -637,7 +667,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
637
667
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
638
668
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
639
669
|
// 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.
|
|
670
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
641
671
|
// Call swap_private on L1
|
|
642
672
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
643
673
|
const swapArgs = [
|
|
@@ -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';
|
|
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.
|
|
@@ -29,7 +29,7 @@ export declare class LendingSimulator {
|
|
|
29
29
|
private rate;
|
|
30
30
|
private ethereumSlotDuration;
|
|
31
31
|
/** the rollup contract */
|
|
32
|
-
rollup:
|
|
32
|
+
rollup: RollupContract;
|
|
33
33
|
/** the lending contract */
|
|
34
34
|
lendingContract: LendingContract;
|
|
35
35
|
/** the collateral asset used in the lending contract */
|
|
@@ -46,7 +46,7 @@ export declare class LendingSimulator {
|
|
|
46
46
|
private mintedOutside;
|
|
47
47
|
constructor(cc: CheatCodes, account: LendingAccount, rate: bigint, ethereumSlotDuration: number,
|
|
48
48
|
/** the rollup contract */
|
|
49
|
-
rollup:
|
|
49
|
+
rollup: RollupContract,
|
|
50
50
|
/** the lending contract */
|
|
51
51
|
lendingContract: LendingContract,
|
|
52
52
|
/** the collateral asset used in the lending contract */
|
|
@@ -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,iBAAiB,CAAC;AAEtD,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;gBAEf,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE;IAK7C;;;OAGG;IACI,GAAG;CAGX;AAgCD;;GAEG;AACH,qBAAa,gBAAgB;IAYzB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,oBAAoB;IAC5B,0BAA0B;IACnB,MAAM,EAAE,cAAc;IAC7B,2BAA2B;IACpB,eAAe,EAAE,eAAe;IACvC,wDAAwD;IACjD,eAAe,EAAE,cAAc;IACtC,uDAAuD;IAChD,UAAU,EAAE,cAAc;IAtBnC,gCAAgC;IACzB,WAAW,EAAE,MAAM,CAAM;IAChC,oCAAoC;IAC7B,IAAI,EAAE,MAAM,CAAK;IAExB,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,aAAa,CAAc;gBAGzB,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,EACZ,oBAAoB,EAAE,MAAM;IACpC,0BAA0B;IACnB,MAAM,EAAE,cAAc;IAC7B,2BAA2B;IACpB,eAAe,EAAE,eAAe;IACvC,wDAAwD;IACjD,eAAe,EAAE,cAAc;IACtC,uDAAuD;IAChD,UAAU,EAAE,cAAc;IAG7B,OAAO;IAMP,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,gBAAgB;IAmBjE,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM;IAKjE,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM;IAKhE,OAAO,CAAC,OAAO;IAKf,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAM3D,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IASzD,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM;IAK/D,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM;IAK9D,OAAO,CAAC,KAAK;IAQb,yBAAyB,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,UAAQ;IASzE,KAAK;CA0BZ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Convenience struct to hold an account's address and secret that can easily be passed around.
|
|
2
|
-
import { AztecAddress
|
|
2
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
4
|
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
4
5
|
/**
|
|
5
6
|
* Contains utilities to compute the "key" for private holdings in the public state.
|
|
@@ -76,23 +77,15 @@ const computeMultiplier = (rate, dt)=>{
|
|
|
76
77
|
}
|
|
77
78
|
async prepare() {
|
|
78
79
|
this.accumulator = BASE;
|
|
79
|
-
const slot = await this.rollup.
|
|
80
|
-
|
|
81
|
-
]);
|
|
82
|
-
this.time = Number(await this.rollup.read.getTimestampForSlot([
|
|
83
|
-
slot
|
|
84
|
-
]));
|
|
80
|
+
const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()) + BigInt(this.ethereumSlotDuration));
|
|
81
|
+
this.time = Number(await this.rollup.getTimestampForSlot(slot));
|
|
85
82
|
}
|
|
86
83
|
async progressSlots(diff, dateProvider) {
|
|
87
84
|
if (diff <= 1) {
|
|
88
85
|
return;
|
|
89
86
|
}
|
|
90
|
-
const slot = await this.rollup.
|
|
91
|
-
|
|
92
|
-
]);
|
|
93
|
-
const ts = Number(await this.rollup.read.getTimestampForSlot([
|
|
94
|
-
slot + BigInt(diff)
|
|
95
|
-
]));
|
|
87
|
+
const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()));
|
|
88
|
+
const ts = Number(await this.rollup.getTimestampForSlot(slot + BigInt(diff)));
|
|
96
89
|
const timeDiff = ts - this.time;
|
|
97
90
|
this.time = ts;
|
|
98
91
|
// Mine ethereum blocks such that the next block will be in a new slot
|
|
@@ -100,7 +93,7 @@ const computeMultiplier = (rate, dt)=>{
|
|
|
100
93
|
if (dateProvider) {
|
|
101
94
|
dateProvider.setTime(this.time * 1000);
|
|
102
95
|
}
|
|
103
|
-
await this.cc.rollup.markAsProven(await this.rollup.
|
|
96
|
+
await this.cc.rollup.markAsProven(await this.rollup.getBlockNumber());
|
|
104
97
|
this.accumulator = muldivDown(this.accumulator, computeMultiplier(this.rate, BigInt(timeDiff)), BASE);
|
|
105
98
|
}
|
|
106
99
|
depositPrivate(from, onBehalfOf, amount) {
|
|
@@ -157,7 +150,9 @@ const computeMultiplier = (rate, dt)=>{
|
|
|
157
150
|
const totalCollateral = Object.values(this.collateral).reduce((a, b)=>new Fr(a.value + b.value), Fr.ZERO);
|
|
158
151
|
expect(totalCollateral).toEqual(new Fr(this.collateralAsset.balanceOfPublic(this.lendingContract.address)));
|
|
159
152
|
expect(this.borrowed).toEqual(this.stableCoin.totalSupply - this.mintedOutside);
|
|
160
|
-
const asset = await this.lendingContract.methods.get_asset(0).simulate(
|
|
153
|
+
const asset = await this.lendingContract.methods.get_asset(0).simulate({
|
|
154
|
+
from: this.account.address
|
|
155
|
+
});
|
|
161
156
|
const interestAccumulator = asset['interest_accumulator'];
|
|
162
157
|
expect(interestAccumulator).toEqual(this.accumulator);
|
|
163
158
|
expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
|
|
@@ -165,7 +160,9 @@ const computeMultiplier = (rate, dt)=>{
|
|
|
165
160
|
this.account.address,
|
|
166
161
|
AztecAddress.fromField(await this.account.key())
|
|
167
162
|
]){
|
|
168
|
-
const privatePos = await this.lendingContract.methods.get_position(key).simulate(
|
|
163
|
+
const privatePos = await this.lendingContract.methods.get_position(key).simulate({
|
|
164
|
+
from: this.account.address
|
|
165
|
+
});
|
|
169
166
|
expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO);
|
|
170
167
|
expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO);
|
|
171
168
|
expect(privatePos['debt']).toEqual(muldivUp((this.staticDebt[key.toString()] ?? Fr.ZERO).value, this.accumulator, BASE));
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
3
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
2
4
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
3
5
|
export declare class TokenSimulator {
|
|
4
6
|
protected token: TokenContract;
|
|
5
7
|
protected defaultWallet: Wallet;
|
|
8
|
+
protected defaultAddress: AztecAddress;
|
|
6
9
|
protected logger: Logger;
|
|
7
10
|
protected accounts: AztecAddress[];
|
|
8
11
|
private balancesPrivate;
|
|
9
12
|
private balancePublic;
|
|
10
13
|
totalSupply: bigint;
|
|
11
14
|
private lookupProvider;
|
|
12
|
-
constructor(token: TokenContract, defaultWallet: Wallet, logger: Logger, accounts: AztecAddress[]);
|
|
15
|
+
constructor(token: TokenContract, defaultWallet: Wallet, defaultAddress: AztecAddress, logger: Logger, accounts: AztecAddress[]);
|
|
13
16
|
addAccount(account: AztecAddress): void;
|
|
14
17
|
setLookupProvider(account: AztecAddress, wallet: Wallet): void;
|
|
15
18
|
mintPrivate(to: AztecAddress, amount: bigint): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token_simulator.d.ts","sourceRoot":"","sources":["../../src/simulators/token_simulator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token_simulator.d.ts","sourceRoot":"","sources":["../../src/simulators/token_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAIpE,qBAAa,cAAc;IAQvB,SAAS,CAAC,KAAK,EAAE,aAAa;IAC9B,SAAS,CAAC,aAAa,EAAE,MAAM;IAC/B,SAAS,CAAC,cAAc,EAAE,YAAY;IACtC,SAAS,CAAC,MAAM,EAAE,MAAM;IACxB,SAAS,CAAC,QAAQ,EAAE,YAAY,EAAE;IAXpC,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,aAAa,CAAkC;IAChD,WAAW,EAAE,MAAM,CAAM;IAEhC,OAAO,CAAC,cAAc,CAAkC;gBAG5C,KAAK,EAAE,aAAa,EACpB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,YAAY,EAC5B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EAAE;IAG7B,UAAU,CAAC,OAAO,EAAE,YAAY;IAIhC,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAIvD,WAAW,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAK5C,UAAU,CAAC,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAM3C,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IASnE,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IASpE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAQtE,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAQrE,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAQ9C,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;IAQ7C,eAAe,CAAC,OAAO,EAAE,YAAY;IAIrC,gBAAgB,CAAC,OAAO,EAAE,YAAY;IAIvC,WAAW;IAoBX,YAAY;IAsCL,KAAK;CAInB"}
|