@aztec/aztec.js 0.16.3 → 0.16.5
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/artifacts/ecdsa_account_contract.json +2 -2
- package/dest/artifacts/schnorr_account_contract.json +2 -2
- package/dest/artifacts/schnorr_single_key_account_contract.json +2 -2
- package/dest/index.d.ts +8 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +7 -6
- package/package.json +5 -5
- package/src/account/contract/base_account_contract.ts +0 -25
- package/src/account/contract/ecdsa_account_contract.ts +0 -38
- package/src/account/contract/index.ts +0 -37
- package/src/account/contract/schnorr_account_contract.ts +0 -38
- package/src/account/contract/single_key_account_contract.ts +0 -45
- package/src/account/defaults/default_entrypoint.ts +0 -102
- package/src/account/defaults/default_interface.ts +0 -38
- package/src/account/defaults/entrypoint_payload.ts +0 -89
- package/src/account/defaults/index.ts +0 -3
- package/src/account/index.ts +0 -124
- package/src/account/interface.ts +0 -35
- package/src/account/manager/deploy_account_sent_tx.ts +0 -42
- package/src/account/manager/index.ts +0 -156
- package/src/account/manager/util.ts +0 -29
- package/src/account/utils.ts +0 -47
- package/src/api/README.md +0 -7
- package/src/api/abi.ts +0 -1
- package/src/api/aztec_address.ts +0 -1
- package/src/api/eth_address.ts +0 -1
- package/src/api/ethereum.ts +0 -6
- package/src/api/fields.ts +0 -1
- package/src/api/init.ts +0 -1
- package/src/api/interfaces/pxe.ts +0 -1
- package/src/api/log_id.ts +0 -1
- package/src/api/tx_hash.ts +0 -1
- package/src/artifacts/ecdsa_account_contract.json +0 -699
- package/src/artifacts/schnorr_account_contract.json +0 -687
- package/src/artifacts/schnorr_single_key_account_contract.json +0 -622
- package/src/contract/base_contract_interaction.ts +0 -61
- package/src/contract/batch_call.ts +0 -23
- package/src/contract/checker.ts +0 -117
- package/src/contract/contract.ts +0 -59
- package/src/contract/contract_base.ts +0 -70
- package/src/contract/contract_function_interaction.ts +0 -80
- package/src/contract/index.ts +0 -42
- package/src/contract/sent_tx.ts +0 -137
- package/src/contract_deployer/contract_deployer.ts +0 -26
- package/src/contract_deployer/deploy_method.ts +0 -139
- package/src/contract_deployer/deploy_sent_tx.ts +0 -71
- package/src/contract_deployer/index.ts +0 -3
- package/src/index.ts +0 -137
- package/src/pxe_client.ts +0 -63
- package/src/sandbox/index.ts +0 -85
- package/src/utils/abi_types.ts +0 -10
- package/src/utils/authwit.ts +0 -24
- package/src/utils/cheat_codes.ts +0 -300
- package/src/utils/defaults.ts +0 -4
- package/src/utils/index.ts +0 -7
- package/src/utils/l1_contracts.ts +0 -21
- package/src/utils/l2_contracts.ts +0 -12
- package/src/utils/pub_key.ts +0 -12
- package/src/utils/secrets.ts +0 -11
- package/src/wallet/account_wallet.ts +0 -86
- package/src/wallet/base_wallet.ts +0 -120
- package/src/wallet/index.ts +0 -12
- package/src/wallet/signerless_wallet.ts +0 -38
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { PXE, Tx, TxExecutionRequest } from '@aztec/types';
|
|
2
|
-
|
|
3
|
-
import { SentTx } from './sent_tx.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents options for calling a (constrained) function in a contract.
|
|
7
|
-
* Allows the user to specify the sender address and nonce for a transaction.
|
|
8
|
-
*/
|
|
9
|
-
export type SendMethodOptions = {
|
|
10
|
-
/**
|
|
11
|
-
* Wether to skip the simulation of the public part of the transaction.
|
|
12
|
-
*/
|
|
13
|
-
skipPublicSimulation?: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Base class for an interaction with a contract, be it a deployment, a function call, or a batch.
|
|
18
|
-
* Implements the sequence create/simulate/send.
|
|
19
|
-
*/
|
|
20
|
-
export abstract class BaseContractInteraction {
|
|
21
|
-
protected tx?: Tx;
|
|
22
|
-
protected txRequest?: TxExecutionRequest;
|
|
23
|
-
|
|
24
|
-
constructor(protected pxe: PXE) {}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Create a transaction execution request ready to be simulated.
|
|
28
|
-
* @param options - An optional object containing additional configuration for the transaction.
|
|
29
|
-
* @returns A transaction execution request.
|
|
30
|
-
*/
|
|
31
|
-
public abstract create(options?: SendMethodOptions): Promise<TxExecutionRequest>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Simulates a transaction execution request and returns a tx object ready to be sent.
|
|
35
|
-
* @param options - optional arguments to be used in the creation of the transaction
|
|
36
|
-
* @returns The resulting transaction
|
|
37
|
-
*/
|
|
38
|
-
public async simulate(options: SendMethodOptions = {}): Promise<Tx> {
|
|
39
|
-
const txRequest = this.txRequest ?? (await this.create(options));
|
|
40
|
-
this.tx = await this.pxe.simulateTx(txRequest, !options.skipPublicSimulation);
|
|
41
|
-
return this.tx;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Sends a transaction to the contract function with the specified options.
|
|
46
|
-
* This function throws an error if called on an unconstrained function.
|
|
47
|
-
* It creates and signs the transaction if necessary, and returns a SentTx instance,
|
|
48
|
-
* which can be used to track the transaction status, receipt, and events.
|
|
49
|
-
* @param options - An optional object containing 'from' property representing
|
|
50
|
-
* the AztecAddress of the sender. If not provided, the default address is used.
|
|
51
|
-
* @returns A SentTx instance for tracking the transaction status and information.
|
|
52
|
-
*/
|
|
53
|
-
public send(options: SendMethodOptions = {}) {
|
|
54
|
-
const promise = (async () => {
|
|
55
|
-
const tx = this.tx ?? (await this.simulate(options));
|
|
56
|
-
return this.pxe.sendTx(tx);
|
|
57
|
-
})();
|
|
58
|
-
|
|
59
|
-
return new SentTx(this.pxe, promise);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
2
|
-
|
|
3
|
-
import { Wallet } from '../wallet/index.js';
|
|
4
|
-
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
5
|
-
|
|
6
|
-
/** A batch of function calls to be sent as a single transaction through a wallet. */
|
|
7
|
-
export class BatchCall extends BaseContractInteraction {
|
|
8
|
-
constructor(protected wallet: Wallet, protected calls: FunctionCall[]) {
|
|
9
|
-
super(wallet);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create a transaction execution request that represents this batch, encoded and authenticated by the
|
|
14
|
-
* user's wallet, ready to be simulated.
|
|
15
|
-
* @returns A Promise that resolves to a transaction instance.
|
|
16
|
-
*/
|
|
17
|
-
public async create(): Promise<TxExecutionRequest> {
|
|
18
|
-
if (!this.txRequest) {
|
|
19
|
-
this.txRequest = await this.wallet.createTxExecutionRequest(this.calls);
|
|
20
|
-
}
|
|
21
|
-
return this.txRequest;
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/contract/checker.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { ABIType, BasicType, ContractArtifact, StructType } from '@aztec/foundation/abi';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a type derived from input type T with the 'kind' property removed.
|
|
5
|
-
* Useful when checking attributes of a specific kind and validating their types.
|
|
6
|
-
*/
|
|
7
|
-
type TypeWithoutKind<T> = Omit<{ [key in keyof T]: any }, 'kind'>;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Validates the given ContractArtifact object by checking its functions and their parameters.
|
|
11
|
-
* Ensures that the ABI has at least one function, a constructor, valid bytecode, and correct parameter types.
|
|
12
|
-
* Throws an error if any inconsistency is detected during the validation process.
|
|
13
|
-
*
|
|
14
|
-
* @param artifact - The ContractArtifact object to be validated.
|
|
15
|
-
* @returns A boolean value indicating whether the artifact is valid or not.
|
|
16
|
-
*/
|
|
17
|
-
export function abiChecker(artifact: ContractArtifact) {
|
|
18
|
-
if (!artifact.functions || artifact.functions.length === 0) {
|
|
19
|
-
throw new Error('artifact has no functions');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
artifact.functions.forEach(func => {
|
|
23
|
-
if (!('name' in func && typeof func.name === 'string' && func.name.length > 0)) {
|
|
24
|
-
throw new Error('ABI function has no name');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// TODO: implement a better check for bytecode (right now only checks if it's > 0)
|
|
28
|
-
if (!('bytecode' in func && typeof func.bytecode === 'string' && func.bytecode.length > 0)) {
|
|
29
|
-
throw new Error('ABI function parameter has incorrect bytecode');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
func.parameters.forEach(param => {
|
|
33
|
-
if (!param.type) {
|
|
34
|
-
throw new Error('ABI function parameter has no type');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
abiParameterTypeChecker(param.type);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// TODO: implement a better check for constructor (right now only checks if it has it or not)
|
|
42
|
-
if (!artifact.functions.find(func => func.name === 'constructor')) {
|
|
43
|
-
throw new Error('ABI has no constructor');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Validates the ABI function parameter's type by checking its kind and attributes.
|
|
51
|
-
* Throws an error if the type has an unrecognized kind or incorrectly formed attributes.
|
|
52
|
-
* Additionally, checks nested types for array and struct kinds.
|
|
53
|
-
*
|
|
54
|
-
* @param type - The ABIType object representing the type of the ABI function parameter.
|
|
55
|
-
* @returns A boolean value indicating whether the type is valid or not.
|
|
56
|
-
*/
|
|
57
|
-
function abiParameterTypeChecker(type: ABIType): boolean {
|
|
58
|
-
switch (type.kind) {
|
|
59
|
-
case 'field':
|
|
60
|
-
case 'boolean':
|
|
61
|
-
return checkAttributes(type, {});
|
|
62
|
-
case 'integer':
|
|
63
|
-
return checkAttributes(type, { sign: 'string', width: 'number' });
|
|
64
|
-
case 'string':
|
|
65
|
-
return checkAttributes(type, { length: 'number' });
|
|
66
|
-
case 'array':
|
|
67
|
-
return checkAttributes(type, { length: 'number', type: 'object' }) && abiParameterTypeChecker(type.type);
|
|
68
|
-
case 'struct':
|
|
69
|
-
return checkAttributes(type, { fields: 'object', path: 'string' }) && checkStruct(type);
|
|
70
|
-
default:
|
|
71
|
-
throw new Error('ABI function parameter has an unrecognized type');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Check if the structure of the ABIType 'struct' is valid by ensuring field names are strings
|
|
77
|
-
* and their type attribute passes the abiParameterTypeChecker. Returns true on successful validation,
|
|
78
|
-
* otherwise throws an error providing insight into the incorrect formation in the struct.
|
|
79
|
-
*
|
|
80
|
-
* @param type - The StructType object containing an array of fields to validate.
|
|
81
|
-
* @returns A boolean value indicating successful validation of the struct's fields.
|
|
82
|
-
*/
|
|
83
|
-
function checkStruct(type: StructType) {
|
|
84
|
-
return type.fields.reduce((acc, field) => {
|
|
85
|
-
if (!('name' in field && typeof field.name === 'string')) {
|
|
86
|
-
throw new Error('ABI function parameter has an incorrectly formed struct');
|
|
87
|
-
}
|
|
88
|
-
return acc && abiParameterTypeChecker(field.type);
|
|
89
|
-
}, true);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Check if a provided ABI type has the correct attributes and their associated types.
|
|
94
|
-
* This function compares the given 'type' object's keys with the expected attribute types
|
|
95
|
-
* specified in 'incompleteAttributes', as well as the required 'kind' property.
|
|
96
|
-
* Throws an error if there are any unrecognized attributes or incorrect attribute types.
|
|
97
|
-
*
|
|
98
|
-
* @param type - The ABI type object to be checked for correct attributes.
|
|
99
|
-
* @param incompleteAttributes - An object representing the expected attribute types without the 'kind' property.
|
|
100
|
-
* @returns Returns true if the provided ABI type has the correct attributes and their associated types, otherwise throws an error.
|
|
101
|
-
*/
|
|
102
|
-
function checkAttributes<T extends BasicType<string>>(type: T, incompleteAttributes: TypeWithoutKind<T>) {
|
|
103
|
-
const typeKeys = Object.keys(type);
|
|
104
|
-
const attributes = { ...incompleteAttributes, kind: 'string' };
|
|
105
|
-
|
|
106
|
-
if (typeKeys.length !== Object.keys(attributes).length) {
|
|
107
|
-
throw new Error(`Unrecognized attribute on type ${type.kind}`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
typeKeys.forEach(element => {
|
|
111
|
-
if (!(element in type && typeof (type as any)[element] === (attributes as any)[element])) {
|
|
112
|
-
throw new Error(`ABI function parameter has an incorrectly formed ${type.kind}`);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return true;
|
|
117
|
-
}
|
package/src/contract/contract.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ContractArtifact } from '@aztec/foundation/abi';
|
|
2
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
-
import { Point } from '@aztec/foundation/fields';
|
|
4
|
-
import { PublicKey } from '@aztec/types';
|
|
5
|
-
|
|
6
|
-
import { DeployMethod } from '../contract_deployer/deploy_method.js';
|
|
7
|
-
import { Wallet } from '../wallet/index.js';
|
|
8
|
-
import { ContractBase } from './contract_base.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The Contract class represents a contract and provides utility methods for interacting with it.
|
|
12
|
-
* It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI,
|
|
13
|
-
* allowing users to call or send transactions to these functions. Additionally, the Contract class can be used
|
|
14
|
-
* to attach the contract instance to a deployed contract on-chain through the PXE, which facilitates
|
|
15
|
-
* interaction with Aztec's privacy protocol.
|
|
16
|
-
*/
|
|
17
|
-
export class Contract extends ContractBase {
|
|
18
|
-
/**
|
|
19
|
-
* Creates a contract instance.
|
|
20
|
-
* @param address - The deployed contract's address.
|
|
21
|
-
* @param artifact - Build artifact of the contract.
|
|
22
|
-
* @param wallet - The wallet to use when interacting with the contract.
|
|
23
|
-
* @param portalContract - The portal contract address on L1, if any.
|
|
24
|
-
* @returns A promise that resolves to a new Contract instance.
|
|
25
|
-
*/
|
|
26
|
-
public static async at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Promise<Contract> {
|
|
27
|
-
const extendedContractData = await wallet.getExtendedContractData(address);
|
|
28
|
-
if (extendedContractData === undefined) {
|
|
29
|
-
throw new Error('Contract ' + address.toString() + ' is not deployed');
|
|
30
|
-
}
|
|
31
|
-
return new Contract(
|
|
32
|
-
extendedContractData.getCompleteAddress(),
|
|
33
|
-
artifact,
|
|
34
|
-
wallet,
|
|
35
|
-
extendedContractData.contractData.portalContractAddress,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates a tx to deploy a new instance of a contract.
|
|
41
|
-
* @param wallet - The wallet for executing the deployment.
|
|
42
|
-
* @param artifact - Build artifact of the contract to deploy
|
|
43
|
-
* @param args - Arguments for the constructor.
|
|
44
|
-
*/
|
|
45
|
-
public static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[]) {
|
|
46
|
-
return new DeployMethod(Point.ZERO, wallet, artifact, args);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Creates a tx to deploy a new instance of a contract using the specified public key to derive the address.
|
|
51
|
-
* @param publicKey - Public key for deriving the address.
|
|
52
|
-
* @param wallet - The wallet for executing the deployment.
|
|
53
|
-
* @param artifact - Build artifact of the contract.
|
|
54
|
-
* @param args - Arguments for the constructor.
|
|
55
|
-
*/
|
|
56
|
-
public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, artifact: ContractArtifact, args: any[]) {
|
|
57
|
-
return new DeployMethod(publicKey, wallet, artifact, args);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { ContractArtifact, FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { CompleteAddress, DeployedContract } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import { Wallet } from '../wallet/index.js';
|
|
6
|
-
import { ContractFunctionInteraction } from './contract_function_interaction.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Type representing a contract method that returns a ContractFunctionInteraction instance
|
|
10
|
-
* and has a readonly 'selector' property of type Buffer. Takes any number of arguments.
|
|
11
|
-
*/
|
|
12
|
-
export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) & {
|
|
13
|
-
/**
|
|
14
|
-
* The unique identifier for a contract function in bytecode.
|
|
15
|
-
*/
|
|
16
|
-
readonly selector: FunctionSelector;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Abstract implementation of a contract extended by the Contract class and generated contract types.
|
|
21
|
-
*/
|
|
22
|
-
export class ContractBase implements DeployedContract {
|
|
23
|
-
/**
|
|
24
|
-
* An object containing contract methods mapped to their respective names.
|
|
25
|
-
*/
|
|
26
|
-
public methods: { [name: string]: ContractMethod } = {};
|
|
27
|
-
|
|
28
|
-
protected constructor(
|
|
29
|
-
/** The deployed contract's complete address. */
|
|
30
|
-
public readonly completeAddress: CompleteAddress,
|
|
31
|
-
/** The Application Binary Interface for the contract. */
|
|
32
|
-
public readonly artifact: ContractArtifact,
|
|
33
|
-
/** The wallet used for interacting with this contract. */
|
|
34
|
-
protected wallet: Wallet,
|
|
35
|
-
/** The portal contract address on L1, if any. */
|
|
36
|
-
public readonly portalContract: EthAddress,
|
|
37
|
-
) {
|
|
38
|
-
artifact.functions.forEach((f: FunctionArtifact) => {
|
|
39
|
-
const interactionFunction = (...args: any[]) => {
|
|
40
|
-
return new ContractFunctionInteraction(this.wallet, this.completeAddress.address!, f, args);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
this.methods[f.name] = Object.assign(interactionFunction, {
|
|
44
|
-
/**
|
|
45
|
-
* A getter for users to fetch the function selector.
|
|
46
|
-
* @returns Selector of the function.
|
|
47
|
-
*/
|
|
48
|
-
get selector() {
|
|
49
|
-
return FunctionSelector.fromNameAndParameters(f.name, f.parameters);
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Address of the contract.
|
|
57
|
-
*/
|
|
58
|
-
public get address() {
|
|
59
|
-
return this.completeAddress.address;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Creates a new instance of the contract wrapper attached to a different wallet.
|
|
64
|
-
* @param wallet - Wallet to use for sending txs.
|
|
65
|
-
* @returns A new contract instance.
|
|
66
|
-
*/
|
|
67
|
-
public withWallet(wallet: Wallet): this {
|
|
68
|
-
return new ContractBase(this.completeAddress, this.artifact, wallet, this.portalContract) as this;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, FunctionData } from '@aztec/circuits.js';
|
|
2
|
-
import { FunctionAbi, FunctionType, encodeArguments } from '@aztec/foundation/abi';
|
|
3
|
-
import { FunctionCall, TxExecutionRequest } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import { Wallet } from '../wallet/index.js';
|
|
6
|
-
import { BaseContractInteraction, SendMethodOptions } from './base_contract_interaction.js';
|
|
7
|
-
|
|
8
|
-
export { SendMethodOptions };
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents the options for a view method in a contract function interaction.
|
|
12
|
-
* Allows specifying the address from which the view method should be called.
|
|
13
|
-
*/
|
|
14
|
-
export type ViewMethodOptions = {
|
|
15
|
-
/**
|
|
16
|
-
* The sender's Aztec address.
|
|
17
|
-
*/
|
|
18
|
-
from?: AztecAddress;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* This is the class that is returned when calling e.g. `contract.methods.myMethod(arg0, arg1)`.
|
|
23
|
-
* It contains available interactions one can call on a method, including view.
|
|
24
|
-
*/
|
|
25
|
-
export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
26
|
-
constructor(
|
|
27
|
-
protected wallet: Wallet,
|
|
28
|
-
protected contractAddress: AztecAddress,
|
|
29
|
-
protected functionDao: FunctionAbi,
|
|
30
|
-
protected args: any[],
|
|
31
|
-
) {
|
|
32
|
-
super(wallet);
|
|
33
|
-
if (args.some(arg => arg === undefined || arg === null)) {
|
|
34
|
-
throw new Error('All function interaction arguments must be defined and not null. Received: ' + args);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Create a transaction execution request that represents this call, encoded and authenticated by the
|
|
40
|
-
* user's wallet, ready to be simulated.
|
|
41
|
-
* @returns A Promise that resolves to a transaction instance.
|
|
42
|
-
*/
|
|
43
|
-
public async create(): Promise<TxExecutionRequest> {
|
|
44
|
-
if (this.functionDao.functionType === FunctionType.UNCONSTRAINED) {
|
|
45
|
-
throw new Error("Can't call `create` on an unconstrained function.");
|
|
46
|
-
}
|
|
47
|
-
if (!this.txRequest) {
|
|
48
|
-
this.txRequest = await this.wallet.createTxExecutionRequest([this.request()]);
|
|
49
|
-
}
|
|
50
|
-
return this.txRequest;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Returns an execution request that represents this operation. Useful as a building
|
|
55
|
-
* block for constructing batch requests.
|
|
56
|
-
* @param options - An optional object containing additional configuration for the transaction.
|
|
57
|
-
* @returns An execution request wrapped in promise.
|
|
58
|
-
*/
|
|
59
|
-
public request(): FunctionCall {
|
|
60
|
-
const args = encodeArguments(this.functionDao, this.args);
|
|
61
|
-
const functionData = FunctionData.fromAbi(this.functionDao);
|
|
62
|
-
return { args, functionData, to: this.contractAddress };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Execute a view (read-only) transaction on an unconstrained function.
|
|
67
|
-
* This method is used to call functions that do not modify the contract state and only return data.
|
|
68
|
-
* Throws an error if called on a non-unconstrained function.
|
|
69
|
-
* @param options - An optional object containing additional configuration for the transaction.
|
|
70
|
-
* @returns The result of the view transaction as returned by the contract function.
|
|
71
|
-
*/
|
|
72
|
-
public view(options: ViewMethodOptions = {}) {
|
|
73
|
-
if (this.functionDao.functionType !== FunctionType.UNCONSTRAINED) {
|
|
74
|
-
throw new Error('Can only call `view` on an unconstrained function.');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const { from } = options;
|
|
78
|
-
return this.wallet.viewTx(this.functionDao.name, this.args, this.contractAddress, from);
|
|
79
|
-
}
|
|
80
|
-
}
|
package/src/contract/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `contract` module provides utilities for deploying and interacting with contracts, based on a
|
|
3
|
-
* `Wallet` instance and a compiled artifact. Refer to the {@link account} module for how to obtain a valid
|
|
4
|
-
* `Wallet` instance, and to the {@link https://docs.aztec.network/dev_docs/contracts/compiling | Compiling contracts}
|
|
5
|
-
* section of the documentation for how to generate an artifact out of your Noir source code.
|
|
6
|
-
*
|
|
7
|
-
* The {@link Contract} class is the main class in this module, and provides static methods for deploying
|
|
8
|
-
* a contract or interacting with an already deployed one. The `methods` property of the contract instance
|
|
9
|
-
* provides access to private, public, and view methods, that can be invoked in a transaction via `send()`,
|
|
10
|
-
* or can be queried via `view()`.
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const contract = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send().deployed();
|
|
14
|
-
* console.log(`Contract deployed at ${contract.address}`);
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* const contract = await Contract.at(address, MyContractArtifact, wallet);
|
|
19
|
-
* await contract.methods.mint(1000, owner).send().wait();
|
|
20
|
-
* console.log(`Total supply is now ${await contract.methods.totalSupply().view()}`);
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* The result of calling a method in a contract instance, such as `contract.methods.mint(1000, owner)`
|
|
24
|
-
* in the example, is a {@link ContractFunctionInteraction} instance. Usually this will be just sent as
|
|
25
|
-
* a transaction to the network via the `send` method, but you can also `simulate` it without sending,
|
|
26
|
-
* or obtaining the `request` for aggregating into a {@link BatchCall}.
|
|
27
|
-
*
|
|
28
|
-
* The result of `send`ing a transaction is a {@link SentTx} object, from which you can get the
|
|
29
|
-
* transaction hash, or simply `wait` until the transaction is mined and the local PXE Service
|
|
30
|
-
* has synchronized its changes.
|
|
31
|
-
*
|
|
32
|
-
* @remarks If you are using typescript, consider using the
|
|
33
|
-
* {@link https://docs.aztec.network/dev_docs/contracts/compiling#typescript-interfaces | autogenerated type-safe interfaces}
|
|
34
|
-
* for interacting with your contracts.
|
|
35
|
-
*
|
|
36
|
-
* @packageDocumentation
|
|
37
|
-
*/
|
|
38
|
-
export * from './contract.js';
|
|
39
|
-
export * from './contract_function_interaction.js';
|
|
40
|
-
export { SentTx, WaitOpts } from './sent_tx.js';
|
|
41
|
-
export * from './contract_base.js';
|
|
42
|
-
export * from './batch_call.js';
|
package/src/contract/sent_tx.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { FieldsOf } from '@aztec/circuits.js';
|
|
2
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
-
import { ExtendedNote, GetUnencryptedLogsResponse, PXE, TxHash, TxReceipt, TxStatus } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import every from 'lodash.every';
|
|
6
|
-
|
|
7
|
-
/** Options related to waiting for a tx. */
|
|
8
|
-
export type WaitOpts = {
|
|
9
|
-
/** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
|
|
10
|
-
timeout?: number;
|
|
11
|
-
/** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
|
|
12
|
-
interval?: number;
|
|
13
|
-
/**
|
|
14
|
-
* Whether to wait for the PXE Service to sync all notes up to the block in which this tx was mined.
|
|
15
|
-
* If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true.
|
|
16
|
-
**/
|
|
17
|
-
waitForNotesSync?: boolean;
|
|
18
|
-
/** Whether to include information useful for debugging/testing in the receipt. */
|
|
19
|
-
debug?: boolean;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const DefaultWaitOpts: WaitOpts = {
|
|
23
|
-
timeout: 60,
|
|
24
|
-
interval: 1,
|
|
25
|
-
waitForNotesSync: true,
|
|
26
|
-
debug: false,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The SentTx class represents a sent transaction through the PXE, providing methods to fetch
|
|
31
|
-
* its hash, receipt, and mining status.
|
|
32
|
-
*/
|
|
33
|
-
export class SentTx {
|
|
34
|
-
constructor(protected pxe: PXE, protected txHashPromise: Promise<TxHash>) {}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Retrieves the transaction hash of the SentTx instance.
|
|
38
|
-
* The function internally awaits for the 'txHashPromise' to resolve, and then returns the resolved transaction hash.
|
|
39
|
-
*
|
|
40
|
-
* @returns A promise that resolves to the transaction hash of the SentTx instance.
|
|
41
|
-
*/
|
|
42
|
-
public async getTxHash() {
|
|
43
|
-
return await this.txHashPromise;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Retrieve the transaction receipt associated with the current SentTx instance.
|
|
48
|
-
* The function fetches the transaction hash using 'getTxHash' and then queries
|
|
49
|
-
* the PXE to get the corresponding transaction receipt.
|
|
50
|
-
*
|
|
51
|
-
* @returns A promise that resolves to a TxReceipt object representing the fetched transaction receipt.
|
|
52
|
-
*/
|
|
53
|
-
public async getReceipt(): Promise<TxReceipt> {
|
|
54
|
-
const txHash = await this.getTxHash();
|
|
55
|
-
return await this.pxe.getTxReceipt(txHash);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Awaits for a tx to be mined and returns the receipt. Throws if tx is not mined.
|
|
60
|
-
* @param opts - Options for configuring the waiting for the tx to be mined.
|
|
61
|
-
* @returns The transaction receipt.
|
|
62
|
-
*/
|
|
63
|
-
public async wait(opts?: WaitOpts): Promise<FieldsOf<TxReceipt>> {
|
|
64
|
-
if (opts?.debug && opts.waitForNotesSync === false) {
|
|
65
|
-
throw new Error('Cannot set getNotes to true if waitForNotesSync is false');
|
|
66
|
-
}
|
|
67
|
-
const receipt = await this.waitForReceipt(opts);
|
|
68
|
-
if (receipt.status !== TxStatus.MINED) {
|
|
69
|
-
throw new Error(`Transaction ${await this.getTxHash()} was ${receipt.status}`);
|
|
70
|
-
}
|
|
71
|
-
if (opts?.debug) {
|
|
72
|
-
const txHash = await this.getTxHash();
|
|
73
|
-
const tx = (await this.pxe.getTx(txHash))!;
|
|
74
|
-
const visibleNotes = await this.pxe.getNotes({ txHash });
|
|
75
|
-
receipt.debugInfo = {
|
|
76
|
-
newCommitments: tx.newCommitments,
|
|
77
|
-
newNullifiers: tx.newNullifiers,
|
|
78
|
-
newPublicDataWrites: tx.newPublicDataWrites,
|
|
79
|
-
newL2ToL1Msgs: tx.newL2ToL1Msgs,
|
|
80
|
-
newContracts: tx.newContracts,
|
|
81
|
-
newContractData: tx.newContractData,
|
|
82
|
-
visibleNotes,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return receipt;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Gets unencrypted logs emitted by this tx.
|
|
90
|
-
* @remarks This function will wait for the tx to be mined if it hasn't been already.
|
|
91
|
-
* @returns The requested logs.
|
|
92
|
-
*/
|
|
93
|
-
public async getUnencryptedLogs(): Promise<GetUnencryptedLogsResponse> {
|
|
94
|
-
await this.wait();
|
|
95
|
-
return this.pxe.getUnencryptedLogs({ txHash: await this.getTxHash() });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Get notes of accounts registered in the provided PXE/Wallet created in this tx.
|
|
100
|
-
* @remarks This function will wait for the tx to be mined if it hasn't been already.
|
|
101
|
-
* @returns The requested notes.
|
|
102
|
-
*/
|
|
103
|
-
public async getVisibleNotes(): Promise<ExtendedNote[]> {
|
|
104
|
-
await this.wait();
|
|
105
|
-
return this.pxe.getNotes({ txHash: await this.getTxHash() });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
|
|
109
|
-
const txHash = await this.getTxHash();
|
|
110
|
-
return await retryUntil(
|
|
111
|
-
async () => {
|
|
112
|
-
const txReceipt = await this.pxe.getTxReceipt(txHash);
|
|
113
|
-
// If receipt is not yet available, try again
|
|
114
|
-
if (txReceipt.status === TxStatus.PENDING) {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
// If the tx was dropped, return it
|
|
118
|
-
if (txReceipt.status === TxStatus.DROPPED) {
|
|
119
|
-
return txReceipt;
|
|
120
|
-
}
|
|
121
|
-
// If we don't care about waiting for notes to be synced, return the receipt
|
|
122
|
-
const waitForNotesSync = opts?.waitForNotesSync ?? DefaultWaitOpts.waitForNotesSync;
|
|
123
|
-
if (!waitForNotesSync) {
|
|
124
|
-
return txReceipt;
|
|
125
|
-
}
|
|
126
|
-
// Check if all sync blocks on the PXE Service are greater or equal than the block in which the tx was mined
|
|
127
|
-
const { blocks, notes } = await this.pxe.getSyncStatus();
|
|
128
|
-
const targetBlock = txReceipt.blockNumber!;
|
|
129
|
-
const areNotesSynced = blocks >= targetBlock && every(notes, block => block >= targetBlock);
|
|
130
|
-
return areNotesSynced ? txReceipt : undefined;
|
|
131
|
-
},
|
|
132
|
-
'isMined',
|
|
133
|
-
opts?.timeout ?? DefaultWaitOpts.timeout,
|
|
134
|
-
opts?.interval ?? DefaultWaitOpts.interval,
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ContractArtifact } from '@aztec/foundation/abi';
|
|
2
|
-
import { Point } from '@aztec/foundation/fields';
|
|
3
|
-
import { PXE, PublicKey } from '@aztec/types';
|
|
4
|
-
|
|
5
|
-
import { DeployMethod } from './deploy_method.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A class for deploying contract.
|
|
9
|
-
* @remarks Keeping this around even though we have Aztec.nr contract types because it can be useful for non-TS users.
|
|
10
|
-
*/
|
|
11
|
-
export class ContractDeployer {
|
|
12
|
-
constructor(private artifact: ContractArtifact, private pxe: PXE, private publicKey?: PublicKey) {}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Deploy a contract using the provided ABI and constructor arguments.
|
|
16
|
-
* This function creates a new DeployMethod instance that can be used to send deployment transactions
|
|
17
|
-
* and query deployment status. The method accepts any number of constructor arguments, which will
|
|
18
|
-
* be passed to the contract's constructor during deployment.
|
|
19
|
-
*
|
|
20
|
-
* @param args - The constructor arguments for the contract being deployed.
|
|
21
|
-
* @returns A DeployMethod instance configured with the ABI, PXE, and constructor arguments.
|
|
22
|
-
*/
|
|
23
|
-
public deploy(...args: any[]) {
|
|
24
|
-
return new DeployMethod(this.publicKey ?? Point.ZERO, this.pxe, this.artifact, args);
|
|
25
|
-
}
|
|
26
|
-
}
|