Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add deployed contract to PXE from CLI #2850

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 33 additions & 1 deletion yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
AztecAddress,
Contract,
ContractDeployer,
EthAddress,
Fr,
GrumpkinScalar,
NotePreimage,
Expand Down Expand Up @@ -33,6 +35,7 @@ import {
getFunctionArtifact,
getTxSender,
parseAztecAddress,
parseEthereumAddress,
parseField,
parseFields,
parseOptionalAztecAddress,
Expand Down Expand Up @@ -223,9 +226,11 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
debugLogger(`Deploy tx sent with hash ${txHash}`);
if (wait) {
const deployed = await tx.wait();
log(`\nContract deployed at ${deployed.contractAddress!.toString()}\n`);
log(`\nContract deployed at ${deployed.contract.completeAddress.address.toString()}\n`);
log(`\nContract partial address ${deployed.contract.completeAddress.partialAddress.toString()}\n`);
} else {
log(`\nContract Address: ${tx.completeContractAddress?.address.toString() ?? 'N/A'}`);
log(`\nContract Partial Address: ${tx.completeContractAddress?.partialAddress.toString() ?? 'N/A'}`);
log(`Deployment transaction hash: ${txHash}\n`);
}
});
Expand All @@ -247,6 +252,33 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
else log(`\nNo contract found at ${address.toString()}\n`);
});

program
.command('add-contract')
.description(
'Adds an existing contract to the PXE. This is useful if you have deployed a contract outside of the PXE and want to use it with the PXE.',
)
.requiredOption(
'-c, --contract-artifact <fileLocation>',
"A compiled Aztec.nr contract's ABI in JSON format or name of a contract ABI exported by @aztec/noir-contracts",
)
.requiredOption('-ca, --contract-address <address>', 'Aztec address of the contract.', parseAztecAddress)
.requiredOption('--partial-address <address>', 'Partial address of the contract', parsePartialAddress)
.option('--public-key <public key>', 'Optional public key for this contract', parsePublicKey)
.option('-pa, --portal-address <address>', 'Optional address to a portal contract on L1', parseEthereumAddress)
.addOption(pxeOption)
.action(async options => {
const artifact = await getContractArtifact(options.contractArtifact, log);
const contractAddress: AztecAddress = options.contractAddress;
const completeAddress = new CompleteAddress(
contractAddress,
options.publicKey ?? Fr.ZERO,
options.partialAddress,
);
const portalContract: EthAddress = options.portalContract ?? EthAddress.ZERO;
const client = await createCompatibleClient(options.rpcUrl, debugLogger);

await client.addContracts([{ artifact, completeAddress, portalContract }]);
});
program
.command('get-tx-receipt')
.description('Gets the receipt for the specified transaction hash.')
Expand Down
16 changes: 15 additions & 1 deletion yarn-project/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AztecAddress, Fr, FunctionSelector, GrumpkinScalar, PXE, Point, TxHash } from '@aztec/aztec.js';
import { AztecAddress, EthAddress, Fr, FunctionSelector, GrumpkinScalar, PXE, Point, TxHash } from '@aztec/aztec.js';
import { L1ContractArtifactsForDeployment, createEthereumChain, deployL1Contracts } from '@aztec/ethereum';
import { ContractArtifact } from '@aztec/foundation/abi';
import { DebugLogger, LogFn } from '@aztec/foundation/log';
Expand Down Expand Up @@ -211,6 +211,20 @@ export function parseAztecAddress(address: string): AztecAddress {
}
}

/**
* Parses an Ethereum address from a string.
* @param address - A serialized Ethereum address
* @returns An Ethereum address
* @throws InvalidArgumentError if the input string is not valid.
*/
export function parseEthereumAddress(address: string): EthAddress {
try {
return EthAddress.fromString(address);
} catch {
throw new InvalidArgumentError(`Invalid address: ${address}`);
}
}

/**
* Parses an AztecAddress from a string.
* @param address - A serialized Aztec address
Expand Down