@aztec/aztec.js 0.1.0-alpha30 → 0.1.0-alpha31
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/.tsbuildinfo +1 -1
- package/dest/account_impl/account_collection.d.ts +4 -4
- package/dest/account_impl/account_collection.d.ts.map +1 -1
- package/dest/account_impl/account_collection.js +4 -5
- package/dest/account_impl/entrypoint_payload.d.ts +2 -2
- package/dest/account_impl/entrypoint_payload.d.ts.map +1 -1
- package/dest/account_impl/entrypoint_payload.js +4 -4
- package/dest/account_impl/index.d.ts +11 -6
- package/dest/account_impl/index.d.ts.map +1 -1
- package/dest/account_impl/index.js +2 -2
- package/dest/account_impl/single_key_account_contract.d.ts +7 -7
- package/dest/account_impl/single_key_account_contract.d.ts.map +1 -1
- package/dest/account_impl/single_key_account_contract.js +11 -18
- package/dest/account_impl/stored_key_account_contract.d.ts +7 -7
- package/dest/account_impl/stored_key_account_contract.d.ts.map +1 -1
- package/dest/account_impl/stored_key_account_contract.js +11 -18
- package/dest/aztec_rpc_client/wallet.d.ts +5 -5
- package/dest/aztec_rpc_client/wallet.d.ts.map +1 -1
- package/dest/aztec_rpc_client/wallet.js +3 -3
- package/dest/contract/base_contract_interaction.d.ts +46 -0
- package/dest/contract/base_contract_interaction.d.ts.map +1 -0
- package/dest/contract/base_contract_interaction.js +37 -0
- package/dest/contract/batch_call.d.ts +16 -0
- package/dest/contract/batch_call.d.ts.map +1 -0
- package/dest/contract/batch_call.js +22 -0
- package/dest/contract/contract.test.js +6 -7
- package/dest/contract/contract_function_interaction.d.ts +10 -47
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +14 -59
- package/dest/contract/index.d.ts +1 -0
- package/dest/contract/index.d.ts.map +1 -1
- package/dest/contract/index.js +2 -1
- package/dest/contract_deployer/deploy_method.d.ts +8 -15
- package/dest/contract_deployer/deploy_method.d.ts.map +1 -1
- package/dest/contract_deployer/deploy_method.js +28 -53
- package/dest/contract_deployer/deploy_sent_tx.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -2
- package/dest/main.js +1 -1
- package/dest/utils/defaults.d.ts +5 -0
- package/dest/utils/defaults.d.ts.map +1 -0
- package/dest/utils/defaults.js +5 -0
- package/package.json +4 -4
- package/src/account_impl/account_collection.ts +8 -9
- package/src/account_impl/entrypoint_payload.ts +5 -5
- package/src/account_impl/index.ts +12 -6
- package/src/account_impl/single_key_account_contract.ts +12 -23
- package/src/account_impl/stored_key_account_contract.ts +17 -24
- package/src/aztec_rpc_client/wallet.ts +8 -9
- package/src/contract/base_contract_interaction.ts +62 -0
- package/src/contract/batch_call.ts +22 -0
- package/src/contract/contract.test.ts +5 -8
- package/src/contract/contract_function_interaction.ts +15 -82
- package/src/contract/index.ts +1 -0
- package/src/contract_deployer/deploy_method.ts +31 -62
- package/src/contract_deployer/deploy_sent_tx.ts +1 -1
- package/src/index.ts +2 -2
- package/src/utils/defaults.ts +4 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CircuitsWasm,
|
|
3
2
|
ContractDeploymentData,
|
|
3
|
+
FunctionData,
|
|
4
4
|
PartialContractAddress,
|
|
5
5
|
TxContext,
|
|
6
6
|
getContractDeploymentInfo,
|
|
7
7
|
} from '@aztec/circuits.js';
|
|
8
|
-
import { ContractAbi } from '@aztec/foundation/abi';
|
|
8
|
+
import { ContractAbi, FunctionAbi, encodeArguments } from '@aztec/foundation/abi';
|
|
9
9
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
10
10
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
11
|
import { Fr } from '@aztec/foundation/fields';
|
|
12
|
-
import { AztecRPC,
|
|
12
|
+
import { AztecRPC, PackedArguments, PublicKey, Tx, TxExecutionRequest } from '@aztec/types';
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
import { Contract, ContractBase,
|
|
14
|
+
import { BaseContractInteraction } from '../contract/base_contract_interaction.js';
|
|
15
|
+
import { Contract, ContractBase, SendMethodOptions } from '../contract/index.js';
|
|
16
16
|
import { DeploySentTx } from './deploy_sent_tx.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -30,51 +30,25 @@ export interface DeployOptions extends SendMethodOptions {
|
|
|
30
30
|
contractAddressSalt?: Fr;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* Simple wallet implementation for use when deploying contracts only.
|
|
35
|
-
*/
|
|
36
|
-
class DeployerWallet extends BaseWallet {
|
|
37
|
-
getAddress(): AztecAddress {
|
|
38
|
-
return AztecAddress.ZERO;
|
|
39
|
-
}
|
|
40
|
-
async createAuthenticatedTxRequest(
|
|
41
|
-
executions: ExecutionRequest[],
|
|
42
|
-
txContext: TxContext,
|
|
43
|
-
): Promise<TxExecutionRequest> {
|
|
44
|
-
if (executions.length !== 1) {
|
|
45
|
-
throw new Error(`Deployer wallet can only run one execution at a time (requested ${executions.length})`);
|
|
46
|
-
}
|
|
47
|
-
const [execution] = executions;
|
|
48
|
-
const wasm = await CircuitsWasm.get();
|
|
49
|
-
const packedArguments = await PackedArguments.fromArgs(execution.args, wasm);
|
|
50
|
-
return Promise.resolve(
|
|
51
|
-
new TxExecutionRequest(execution.to, execution.functionData, packedArguments.hash, txContext, [packedArguments]),
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
33
|
/**
|
|
57
34
|
* Creates a TxRequest from a contract ABI, for contract deployment.
|
|
58
35
|
* Extends the ContractFunctionInteraction class.
|
|
59
36
|
*/
|
|
60
|
-
export class DeployMethod<TContract extends ContractBase = Contract> extends
|
|
61
|
-
/**
|
|
62
|
-
* The partially computed contract address. Known after creation of the deployment transaction.
|
|
63
|
-
*/
|
|
37
|
+
export class DeployMethod<TContract extends ContractBase = Contract> extends BaseContractInteraction {
|
|
38
|
+
/** The partially computed contract address. Known after creation of the deployment transaction. */
|
|
64
39
|
public partialContractAddress?: PartialContractAddress = undefined;
|
|
65
40
|
|
|
66
|
-
/**
|
|
67
|
-
* The complete contract address.
|
|
68
|
-
*/
|
|
41
|
+
/** The complete contract address. */
|
|
69
42
|
public completeContractAddress?: AztecAddress = undefined;
|
|
70
43
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!constructorAbi) {
|
|
74
|
-
throw new Error('Cannot find constructor in the ABI.');
|
|
75
|
-
}
|
|
44
|
+
/** Constructor function to call. */
|
|
45
|
+
private constructorAbi: FunctionAbi;
|
|
76
46
|
|
|
77
|
-
|
|
47
|
+
constructor(private publicKey: PublicKey, private arc: AztecRPC, private abi: ContractAbi, private args: any[] = []) {
|
|
48
|
+
super(arc);
|
|
49
|
+
const constructorAbi = abi.functions.find(f => f.name === 'constructor');
|
|
50
|
+
if (!constructorAbi) throw new Error('Cannot find constructor in the ABI.');
|
|
51
|
+
this.constructorAbi = constructorAbi;
|
|
78
52
|
}
|
|
79
53
|
|
|
80
54
|
/**
|
|
@@ -90,7 +64,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Con
|
|
|
90
64
|
const portalContract = options.portalContract ?? EthAddress.ZERO;
|
|
91
65
|
const contractAddressSalt = options.contractAddressSalt ?? Fr.random();
|
|
92
66
|
|
|
93
|
-
const { chainId, version } = await this.
|
|
67
|
+
const { chainId, version } = await this.rpc.getNodeInfo();
|
|
94
68
|
|
|
95
69
|
const { address, constructorHash, functionTreeRoot, partialAddress } = await getContractDeploymentInfo(
|
|
96
70
|
this.abi,
|
|
@@ -108,15 +82,25 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Con
|
|
|
108
82
|
);
|
|
109
83
|
|
|
110
84
|
const txContext = new TxContext(false, false, true, contractDeploymentData, new Fr(chainId), new Fr(version));
|
|
111
|
-
const
|
|
112
|
-
const
|
|
85
|
+
const args = encodeArguments(this.constructorAbi, this.args);
|
|
86
|
+
const functionData = FunctionData.fromAbi(this.constructorAbi);
|
|
87
|
+
const execution = { args, functionData, to: address };
|
|
88
|
+
const packedArguments = await PackedArguments.fromArgs(execution.args);
|
|
89
|
+
|
|
90
|
+
const txRequest = TxExecutionRequest.from({
|
|
91
|
+
origin: execution.to,
|
|
92
|
+
functionData: execution.functionData,
|
|
93
|
+
argsHash: packedArguments.hash,
|
|
94
|
+
txContext,
|
|
95
|
+
packedArguments: [packedArguments],
|
|
96
|
+
});
|
|
113
97
|
|
|
114
98
|
this.txRequest = txRequest;
|
|
115
99
|
this.partialContractAddress = partialAddress;
|
|
116
100
|
this.completeContractAddress = address;
|
|
117
101
|
|
|
118
102
|
// TODO: Should we add the contracts to the DB here, or once the tx has been sent or mined?
|
|
119
|
-
await this.
|
|
103
|
+
await this.rpc.addContracts([{ abi: this.abi, address, portalContract }]);
|
|
120
104
|
|
|
121
105
|
return this.txRequest;
|
|
122
106
|
}
|
|
@@ -139,22 +123,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Con
|
|
|
139
123
|
* @param options - Deployment options.
|
|
140
124
|
* @returns The simulated tx.
|
|
141
125
|
*/
|
|
142
|
-
public
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.tx = await this.wallet.simulateTx(txRequest);
|
|
146
|
-
return this.tx;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Creates a contract abstraction given a wallet.
|
|
151
|
-
* @param withWallet - The wallet to provide to the contract abstraction
|
|
152
|
-
* @returns - The generated contract abstraction.
|
|
153
|
-
*/
|
|
154
|
-
public async getContract(withWallet: Wallet) {
|
|
155
|
-
if (!this.completeContractAddress) {
|
|
156
|
-
throw new Error(`Cannot get a contract instance for a contract not yet deployed`);
|
|
157
|
-
}
|
|
158
|
-
return await Contract.create(this.completeContractAddress, this.abi, withWallet);
|
|
126
|
+
public simulate(options: DeployOptions): Promise<Tx> {
|
|
127
|
+
return super.simulate(options);
|
|
159
128
|
}
|
|
160
129
|
}
|
|
@@ -46,7 +46,7 @@ export class DeploySentTx<TContract extends ContractBase = Contract> extends Sen
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
protected getContractInstance(wallet?: Wallet, address?: AztecAddress): Promise<TContract> {
|
|
49
|
-
const isWallet = (rpc: AztecRPC | Wallet): rpc is Wallet => !!(rpc as Wallet).
|
|
49
|
+
const isWallet = (rpc: AztecRPC | Wallet): rpc is Wallet => !!(rpc as Wallet).createTxExecutionRequest;
|
|
50
50
|
const contractWallet = wallet ?? (isWallet(this.arc) && this.arc);
|
|
51
51
|
if (!contractWallet) throw new Error(`A wallet is required for creating a contract instance`);
|
|
52
52
|
if (!address) throw new Error(`Contract address is missing from transaction receipt`);
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export {
|
|
|
15
15
|
ContractDeploymentTx,
|
|
16
16
|
ContractPublicData,
|
|
17
17
|
DeployedContract,
|
|
18
|
-
|
|
18
|
+
FunctionCall,
|
|
19
19
|
L2BlockL2Logs,
|
|
20
20
|
NodeInfo,
|
|
21
21
|
PackedArguments,
|
|
@@ -26,7 +26,7 @@ export {
|
|
|
26
26
|
TxHash,
|
|
27
27
|
TxReceipt,
|
|
28
28
|
TxStatus,
|
|
29
|
-
|
|
29
|
+
emptyFunctionCall,
|
|
30
30
|
} from '@aztec/types';
|
|
31
31
|
|
|
32
32
|
export { createDebugLogger } from '@aztec/foundation/log';
|