Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playground/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
LOG_LEVEL=verbose
# Uncomment to provide a custom barretenberg.wasm file
#BB_WASM_PATH='/assets/barretenberg.wasm.gz'
# BB_WASM_PATH='/assets/barretenberg-debug.wasm'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { type NoirCompiledContract } from '@aztec/stdlib/noir';
const circuit: NoirCompiledContract;
export = circuit;

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions playground/src/components/common/FeePaymentSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AztecContext } from '../../aztecEnv';
import { progressIndicator, select } from '../../styles/common';
import { INFO_TEXT } from '../../constants';
import { InfoText } from './InfoText';
import { prepareForFeePayment } from '../../utils/sponsoredFPC';

const FeePaymentMethods = ['sponsored_fpc', 'private_fpc', 'public_fpc', 'fee_juice', 'bridged_fee_juice'] as const;
type FeePaymentMethodType = (typeof FeePaymentMethods)[number];
Expand All @@ -34,8 +35,11 @@ export function FeePaymentSelector({ setFeePaymentMethod }: FeePaymentSelectorPr
setSelectedMethod(method);
switch (method) {
case 'sponsored_fpc': {
const { prepareForFeePayment } = await import('../../utils/sponsoredFPC');
const feePaymentMethod = await prepareForFeePayment(pxe);
const feePaymentMethod = await prepareForFeePayment(
pxe,
network.sponsoredFPC?.address,
network.sponsoredFPC?.version,
);
setFeePaymentMethod(feePaymentMethod);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function NetworkSelector({}: NetworkSelectorProps) {
if (isNetworkStoreInitialized && !network) {
handleNetworkChange(NETWORKS[0].nodeURL);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isNetworkStoreInitialized]);

useEffect(() => {
Expand Down Expand Up @@ -212,7 +212,7 @@ export function NetworkSelector({}: NetworkSelectorProps) {
return 'Select Network';
}}
disabled={connecting}
onChange={(e) => handleNetworkChange(e.target.value)}
onChange={e => handleNetworkChange(e.target.value)}
>
{networks.map(network => (
<MenuItem
Expand Down
9 changes: 9 additions & 0 deletions playground/src/utils/networks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AztecAddress } from '@aztec/aztec.js';
import { VERSION } from './constants';

export type Network = {
Expand All @@ -6,6 +7,10 @@ export type Network = {
description: string;
hasTestAccounts: boolean;
hasSponsoredFPC: boolean;
sponsoredFPC?: {
version: string;
address: AztecAddress;
};
};

export const NETWORKS: Network[] = [
Expand All @@ -15,6 +20,10 @@ export const NETWORKS: Network[] = [
description: 'Public testnet',
hasTestAccounts: false,
hasSponsoredFPC: true,
sponsoredFPC: {
version: '0.85.0-alpha-testnet.2',
address: AztecAddress.fromString('0x0b27e30667202907fc700d50e9bc816be42f8141fae8b9f2281873dbdb9fc2e5'),
},
},
{
nodeURL: 'http://34.169.170.55:8080',
Expand Down
44 changes: 30 additions & 14 deletions playground/src/utils/sponsoredFPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,44 @@ import {
SponsoredFeePaymentMethod,
AztecAddress,
Fr,
loadContractArtifact,
type ContractArtifact,
} from '@aztec/aztec.js';
import { SPONSORED_FPC_SALT } from '@aztec/constants';
import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';

export async function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
return await getContractInstanceFromDeployParams(SponsoredFPCContract.artifact, {
salt: new Fr(SPONSORED_FPC_SALT),
});
}

export async function getSponsoredFPCAddress(): Promise<AztecAddress> {
return (await getSponsoredFPCInstance()).address;
export async function getSponsoredFPCArtifact(version?: string): Promise<ContractArtifact> {
if (version) {
const artifact = (await import(`../assets/artifacts/${version}/sponsored_fpc_contract-SponsoredFPC.json`)).default;
return loadContractArtifact(artifact);
} else {
const contract = (await import('@aztec/noir-contracts.js/SponsoredFPC')).SponsoredFPCContract;
return contract.artifact;
}
}

export async function prepareForFeePayment(pxe: PXE): Promise<SponsoredFeePaymentMethod> {
export async function prepareForFeePayment(
pxe: PXE,
sponsoredFPCAddress?: AztecAddress,
sponsoredFPCVersion?: string,
): Promise<SponsoredFeePaymentMethod> {
try {
const sponsoredFPC = await getSponsoredFPCInstance();
const contractArtifact = await getSponsoredFPCArtifact(sponsoredFPCVersion);

const instance = await getContractInstanceFromDeployParams(contractArtifact, {
salt: new Fr(SPONSORED_FPC_SALT),
});

if (sponsoredFPCAddress && !sponsoredFPCAddress.equals(instance.address)) {
throw new Error(
`SponsoredFPC at version ${sponsoredFPCVersion} does not match the expected address. Computed ${instance.address} but received ${sponsoredFPCAddress}`,
);
}

await pxe.registerContract({
instance: sponsoredFPC,
artifact: SponsoredFPCContract.artifact,
instance: instance,
artifact: contractArtifact,
});
return new SponsoredFeePaymentMethod(sponsoredFPC.address);
return new SponsoredFeePaymentMethod(instance.address);
} catch (error) {
console.error('Error preparing SponsoredFeePaymentMethod:', error);
throw error;
Expand Down
7 changes: 3 additions & 4 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { defineConfig, loadEnv, searchForWorkspaceRoot } from 'vite';
import react from '@vitejs/plugin-react-swc';
import { PolyfillOptions, nodePolyfills } from 'vite-plugin-node-polyfills';
import bundlesize from 'vite-plugin-bundlesize';
import path from 'path';

// Only required for alternative bb wasm file, left as reference
// import { viteStaticCopy } from "vite-plugin-static-copy";
//import { viteStaticCopy } from 'vite-plugin-static-copy';

// Unfortunate, but needed due to https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues/81
// Suspected to be because of the yarn workspace setup, but not sure
Expand Down Expand Up @@ -54,8 +53,8 @@ export default defineConfig(({ mode }) => {
// viteStaticCopy({
// targets: [
// {
// src: "../barretenberg/ts/dest/node/barretenberg_wasm/*.gz",
// dest: "assets/",
// src: '../barretenberg/cpp/build-wasm-threads/bin/*.wasm',
// dest: 'assets/',
// },
// ],
// }),
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/cli-wallet/src/cmds/deploy_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function deployAccount(
account: AccountManager,
wait: boolean,
registerClass: boolean,
publicDeploy: boolean,
feeOpts: IFeeOpts,
json: boolean,
debugLogger: Logger,
Expand Down Expand Up @@ -43,7 +44,7 @@ export async function deployAccount(

const deployOpts: DeployAccountOptions = {
skipInitialization: false,
skipPublicDeployment: false,
skipPublicDeployment: !publicDeploy,
skipClassRegistration: !registerClass,
...(await feeOpts.toDeployAccountOpts(wallet)),
};
Expand Down
6 changes: 4 additions & 2 deletions yarn-project/cli-wallet/src/cmds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ export function injectCommands(
.option(
'--register-class',
'Register the contract class (useful for when the contract class has not been deployed yet).',
);
)
.option('--public-deploy', 'Publicly deploy this account contract (only useful if it contains public functions');

addOptions(deployAccountCommand, FeeOptsWithFeePayer.getOptions()).action(async (_options, command) => {
const { deployAccount } = await import('./deploy_account.js');
const options = command.optsWithGlobals();
const { rpcUrl, wait, from: parsedFromAddress, json, registerClass } = options;
const { rpcUrl, wait, from: parsedFromAddress, json, registerClass, publicDeploy } = options;

const client = pxeWrapper?.getPXE() ?? (await createCompatibleClient(rpcUrl, debugLogger));
const account = await createOrRetrieveAccount(client, parsedFromAddress, db);
Expand All @@ -167,6 +168,7 @@ export function injectCommands(
account,
wait,
registerClass,
publicDeploy,
await FeeOptsWithFeePayer.fromCli(options, client, log, db),
json,
debugLogger,
Expand Down