Skip to content

Commit 9944278

Browse files
authored
feat!: The Great Wallet Refactor (#16865)
Second part of the `Wallet` refactor that moves us closer to a fully fledged `Wallet SDK` and PXEless apps. Focuses on completely unbinding the `Wallet` interface from a particular `AztecAddress`. The former now refers to the wallet *software*, which exposes a clear API to apps. This API is not yet finalized! `ContractFunctionInteraction` and friends have been put on a diet, and most of their responsibilities are now the Wallet's As a consequence of this PR, every single e2e test, the playground, the cli-wallet and boxes have been altered. It's not pretty (yet), but it will be, I promise.
2 parents 2ec7c7c + 72c2195 commit 9944278

File tree

248 files changed

+4311
-4771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+4311
-4771
lines changed

aztec-up/test/amm_flow.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ aztec-wallet \
5252

5353
aztec-wallet \
5454
register-contract $canonical_sponsored_fpc_address SponsoredFPC \
55-
-f accounts:main \
5655
--salt 0
5756

5857
aztec-wallet \

boxes/boxes/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"dependencies": {
3939
"@aztec/accounts": "latest",
4040
"@aztec/aztec.js": "latest",
41+
"@aztec/test-wallet": "latest",
4142
"classnames": "^2.3.2",
4243
"formik": "^2.4.3",
4344
"react": "^18.2.0",

boxes/boxes/react/src/config.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
1-
import { createPXEClient, PXE } from '@aztec/aztec.js';
2-
import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing/lazy';
1+
import { AztecAddress, createPXEClient, PXE, Wallet } from '@aztec/aztec.js';
2+
import { getDeployedTestAccounts } from '@aztec/accounts/testing/lazy';
3+
import { TestWallet } from '@aztec/test-wallet';
34

45
export class PrivateEnv {
6+
private wallet!: Wallet;
7+
private defaultAccountAddress!: AztecAddress;
8+
59
private constructor(private pxe: PXE) {}
610

7-
static async create(pxeURL: string) {
11+
static create(pxeURL: string) {
812
const pxe = createPXEClient(pxeURL);
913
return new PrivateEnv(pxe);
1014
}
1115

12-
async getWallet() {
13-
const wallet = (await getDeployedTestAccountsWallets(this.pxe))[0];
14-
if (!wallet) {
16+
async init() {
17+
const wallet = new TestWallet(this.pxe);
18+
19+
const accountData = (await getDeployedTestAccounts(this.pxe))[0];
20+
if (!accountData) {
1521
console.error(
16-
'Wallet not found. Please connect the app to a testing environment with deployed and funded test accounts.',
22+
'Account not found. Please connect the app to a testing environment with deployed and funded test accounts.',
1723
);
1824
}
19-
return wallet;
25+
26+
await wallet.createSchnorrAccount(accountData.secret, accountData.salt, accountData.signingKey);
27+
this.wallet = wallet;
28+
this.defaultAccountAddress = accountData.address;
29+
}
30+
31+
async getWallet() {
32+
if (!this.wallet) {
33+
await this.init();
34+
}
35+
return this.wallet;
36+
}
37+
38+
getDefaultAccountAddress() {
39+
return this.defaultAccountAddress;
2040
}
2141
}
2242

23-
export const deployerEnv = await PrivateEnv.create(process.env.PXE_URL || 'http://localhost:8080');
43+
export const deployerEnv = PrivateEnv.create(process.env.PXE_URL || 'http://localhost:8080');

boxes/boxes/react/src/hooks/useContract.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export function useContract() {
1313

1414
setWait(true);
1515
const wallet = await deployerEnv.getWallet();
16+
const defaultAccountAddress = deployerEnv.getDefaultAccountAddress();
1617
const salt = Fr.random();
1718

1819
const { BoxReactContract } = await import('../../artifacts/BoxReact');
1920

20-
const tx = await BoxReactContract.deploy(wallet, Fr.random(), wallet.getCompleteAddress().address).send({
21-
from: wallet.getAddress(),
21+
const tx = await BoxReactContract.deploy(wallet, Fr.random(), defaultAccountAddress).send({
22+
from: defaultAccountAddress,
2223
contractAddressSalt: salt,
2324
});
2425
const contract = await toast.promise(tx.deployed(), {

boxes/boxes/react/src/hooks/useNumber.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export function useNumber({ contract }: { contract: Contract }) {
1010
e.preventDefault();
1111

1212
setWait(true);
13-
const deployerWallet = await deployerEnv.getWallet();
13+
const defaultAccountAddress = deployerEnv.getDefaultAccountAddress();
1414
const viewTxReceipt = await contract!.methods
15-
.getNumber(deployerWallet.getCompleteAddress().address)
16-
.simulate({ from: deployerWallet.getAddress() });
15+
.getNumber(defaultAccountAddress)
16+
.simulate({ from: defaultAccountAddress });
1717
toast(`Number is: ${viewTxReceipt.value}`);
1818
setWait(false);
1919
};
@@ -26,13 +26,9 @@ export function useNumber({ contract }: { contract: Contract }) {
2626
setWait(true);
2727

2828
const value = BigInt(el.value);
29-
const deployerWallet = await deployerEnv.getWallet();
30-
29+
const defaultAccountAddress = deployerEnv.getDefaultAccountAddress();
3130
await toast.promise(
32-
contract!.methods
33-
.setNumber(value, deployerWallet.getCompleteAddress().address)
34-
.send({ from: deployerWallet.getAddress() })
35-
.wait(),
31+
contract!.methods.setNumber(value, defaultAccountAddress).send({ from: defaultAccountAddress }).wait(),
3632
{
3733
pending: 'Setting number...',
3834
success: `Number set to: ${value}`,
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
import { AccountWallet, CompleteAddress, Contract, Fr, createLogger } from '@aztec/aztec.js';
1+
import { AztecAddress, Contract, Fr, Wallet, createLogger } from '@aztec/aztec.js';
22
import { BoxReactContract } from '../artifacts/BoxReact.js';
33
import { deployerEnv } from '../src/config.js';
44

55
const logger = createLogger('aztec:http-pxe-client');
66

77
describe('BoxReact Contract Tests', () => {
8-
let wallet: AccountWallet;
8+
let wallet: Wallet;
9+
let defaultAccountAddress: AztecAddress;
910
let contract: Contract;
1011
const numberToSet = Fr.random();
11-
let accountCompleteAddress: CompleteAddress;
1212

1313
beforeAll(async () => {
1414
wallet = await deployerEnv.getWallet();
15-
accountCompleteAddress = wallet.getCompleteAddress();
15+
defaultAccountAddress = deployerEnv.getDefaultAccountAddress();
1616
const salt = Fr.random();
1717

18-
contract = await BoxReactContract.deploy(wallet, Fr.random(), accountCompleteAddress.address)
19-
.send({ from: wallet.getAddress(), contractAddressSalt: salt })
18+
contract = await BoxReactContract.deploy(wallet, Fr.random(), defaultAccountAddress)
19+
.send({ from: defaultAccountAddress, contractAddressSalt: salt })
2020
.deployed();
2121

2222
logger.info(`L2 contract deployed at ${contract.address}`);
2323
}, 60000);
2424

2525
test('Can set a number', async () => {
26-
await contract.methods
27-
.setNumber(numberToSet, accountCompleteAddress.address)
28-
.send({ from: wallet.getAddress() })
29-
.wait();
26+
await contract.methods.setNumber(numberToSet, defaultAccountAddress).send({ from: defaultAccountAddress }).wait();
3027
}, 40000);
3128

3229
test('Can read a number', async () => {
3330
const viewTxReceipt = await contract.methods
34-
.getNumber(accountCompleteAddress.address)
35-
.simulate({ from: wallet.getAddress() });
31+
.getNumber(defaultAccountAddress)
32+
.simulate({ from: defaultAccountAddress });
3633
expect(numberToSet.toBigInt()).toEqual(viewTxReceipt.value);
3734
}, 40000);
3835
});

boxes/boxes/react/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default (_, argv) => ({
4949
path: false,
5050
tty: false,
5151
url: false,
52+
net: false,
5253
worker_threads: false,
5354
events: require.resolve('events/'),
5455
buffer: require.resolve('buffer/'),

0 commit comments

Comments
 (0)