Skip to content

Commit

Permalink
chore: update private token box (#2385)
Browse files Browse the repository at this point in the history
recompiled artifacts with latest toolchain.

note initially this was supposed to change to the new "token" contract,
but there are quite a few changes needed because that contract is quite
different. so pausing on that (maybe separate box), and just doing a
small bump on the private token
# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: Jonathan Bursztyn <jobur93@gmail.com>
  • Loading branch information
dan-aztec and jonybur authored Sep 26, 2023
1 parent 2e43248 commit b730196
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export async function callContractFunction(
// TODO: switch to the generated typescript class?
const contract = await Contract.at(address, abi, selectedWallet);

const returnVal = contract.methods[functionName](...typedArgs)
return contract.methods[functionName](...typedArgs)
.send()
.wait();

return await returnVal;
}
3 changes: 1 addition & 2 deletions yarn-project/boxes/blank-react/src/scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export function convertArgs(functionAbi: FunctionAbi, args: any): Fr[] {
}
});

const typedArgs = encodeArguments(functionAbi, untypedArgs);
return typedArgs;
return encodeArguments(functionAbi, untypedArgs);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getWallet } from './util.js';
import { AztecAddress, AztecRPC, CompleteAddress, Contract } from '@aztec/aztec.js';
import { ContractAbi } from '@aztec/foundation/abi';
import { getWallet } from './util.js';

export async function viewContractFunction(
address: AztecAddress,
Expand All @@ -14,7 +14,5 @@ export async function viewContractFunction(
const selectedWallet = await getWallet(wallet, rpc);
const contract = await Contract.at(address, abi, selectedWallet);

// TODO: see if we can remove the {from: wallet.address}?
const viewResult = await contract.methods[functionName](...typedArgs).view({ from: wallet.address });
return viewResult;
return await contract.methods[functionName](...typedArgs).view({ from: wallet.address });
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const setupSandbox = async () => {
const { SANDBOX_URL = 'http://localhost:8080' } = process.env;
const aztecRpc = createAztecRpcClient(SANDBOX_URL);
await waitForSandbox(aztecRpc);

return aztecRpc;
};

Expand All @@ -30,8 +31,7 @@ async function deployZKContract(owner: CompleteAddress, wallet: Wallet, rpcClien
const contractAddress = await deployContract(owner, BlankContract.abi, [], Fr.random(), rpcClient);

logger(`L2 contract deployed at ${contractAddress}`);
const contract = await BlankContract.at(contractAddress, wallet);
return contract;
return BlankContract.at(contractAddress, wallet);
}

describe('ZK Contract Tests', () => {
Expand Down
9 changes: 4 additions & 5 deletions yarn-project/boxes/blank/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const FILTERED_FUNCTION_NAMES = [];

export const DEFAULT_PUBLIC_ADDRESS: string = '0x25048e8c1b7dea68053d597ac2d920637c99523651edfb123d0632da785970d0';

// interaction with the button

let contractAddress: string = '';

// interaction with the buttons
document.getElementById('deploy')?.addEventListener('click', async () => {
console.log('Deploying Contract');
const [wallet, ..._rest] = await getSandboxAccountsWallets(rpcClient);
Expand Down Expand Up @@ -55,7 +55,7 @@ document.getElementById('interact')?.addEventListener('click', async () => {
wallet.getCompleteAddress(),
);

console.log('Interaction transaction succeeded', call);
console.log('transaction outcome:', call);
});

export const getFunctionAbi = (contractAbi: any, functionName: string) => {
Expand Down Expand Up @@ -132,6 +132,5 @@ export function convertArgs(functionAbi: FunctionAbi, args: any): Fr[] {
}
});

const typedArgs = encodeArguments(functionAbi, untypedArgs);
return typedArgs;
return encodeArguments(functionAbi, untypedArgs);
}
3 changes: 1 addition & 2 deletions yarn-project/boxes/blank/src/tests/blank.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ async function deployZKContract(owner: CompleteAddress, wallet: Wallet, rpcClien
const contractAddress = await deployContract(owner, BlankContract.abi, [], Fr.random(), rpcClient);

logger(`L2 contract deployed at ${contractAddress}`);
const contract = await BlankContract.at(contractAddress, wallet);
return contract;
return BlankContract.at(contractAddress, wallet);
}

describe('ZK Contract Tests', () => {
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/boxes/private-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Dependencies can be installed from the root of the package:
yarn
yarn install:noir
yarn install:sandbox
yarn build
```

In addition to the usual javascript dependencies, this project requires `nargo` (package manager) and `noir` (a Domain Specific Language for SNARK proving systems) in addition to `@aztec/aztec-cli`.
Expand All @@ -33,7 +32,7 @@ docker pull aztecprotocol/aztec-sandbox:latest

## Getting started

After `yarn build` has run,`yarn start:sandbox` in one terminal will launch a local instance of the Aztec sandbox via Docker Compose and `yarn start:dev` will launch a frontend app for deploying and interacting with the PrivateToken contract.
After `yarn` has run,`yarn start:sandbox` in one terminal will launch a local instance of the Aztec sandbox via Docker Compose and `yarn start:dev` will launch a frontend app for deploying and interacting with the PrivateToken contract.

At this point, [http://localhost:5173](http://localhost:5173) should provide a minimal smart contract frontend.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function generateYupSchema(functionAbi: FunctionAbi, defaultAddress: string) {
return value;
});
initialValues[param.name] = Array(arrayLength).fill(
CONTRACT_ADDRESS_PARAM_NAMES.includes(param.name) ? DEFAULT_PUBLIC_ADDRESS : 200,
CONTRACT_ADDRESS_PARAM_NAMES.includes(param.name) ? defaultAddress : 200,
);
break;
case 'boolean':
Expand Down
6 changes: 4 additions & 2 deletions yarn-project/boxes/private-token/src/app/contract.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button, ButtonSize, ButtonTheme, Card, CardTheme, ImageButton, ImageButtonIcon } from '@aztec/aztec-ui';
import { AztecAddress, CompleteAddress } from '@aztec/aztec.js';
import { FunctionAbi } from '@aztec/foundation/abi';
import { ReactNode, useState } from 'react';
import { FILTERED_FUNCTION_NAMES, contractAbi } from '../config.js';
import { Copy } from './components/copy.js';
import { ContractFunctionForm, Popup } from './components/index.js';
import styles from './contract.module.scss';
import { Button, ButtonSize, ButtonTheme, Card, CardTheme, ImageButton, ImageButtonIcon } from '@aztec/aztec-ui';
import { Copy } from './components/copy.js';

const functionTypeSortOrder = {
secret: 0,
Expand Down Expand Up @@ -98,6 +98,7 @@ export function Contract({ wallet }: Props) {
contractAddress={contractAddress}
contractAbi={contractAbi}
functionAbi={selectedFunctionAbi}
defaultAddress={wallet.address.toString()}
isLoading={processingFunction === selectedFunctionAbi.name && !hasResult}
disabled={processingFunction === selectedFunctionAbi.name && hasResult}
onSubmit={() => handleSubmitForm(selectedFunctionAbi.name)}
Expand All @@ -116,6 +117,7 @@ export function Contract({ wallet }: Props) {
wallet={wallet}
contractAbi={contractAbi}
functionAbi={constructorAbi}
defaultAddress={wallet.address.toString()}
buttonText="Deploy"
isLoading={!!processingFunction && !hasResult}
disabled={!!processingFunction && hasResult}
Expand Down
Loading

0 comments on commit b730196

Please sign in to comment.