@aztec/aztec.js 0.0.1-commit.d3ec352c → 0.0.1-commit.d431d1c
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/account/account.d.ts +25 -40
- package/dest/account/account.d.ts.map +1 -1
- package/dest/account/account.js +19 -47
- package/dest/account/account_contract.d.ts +9 -10
- package/dest/account/account_contract.d.ts.map +1 -1
- package/dest/account/account_with_secret_key.d.ts +21 -9
- package/dest/account/account_with_secret_key.d.ts.map +1 -1
- package/dest/account/account_with_secret_key.js +21 -4
- package/dest/account/index.d.ts +4 -3
- package/dest/account/index.d.ts.map +1 -1
- package/dest/account/index.js +2 -0
- package/dest/account/signerless_account.d.ts +6 -7
- package/dest/account/signerless_account.d.ts.map +1 -1
- package/dest/account/signerless_account.js +8 -11
- package/dest/api/account.d.ts +2 -4
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +1 -3
- package/dest/api/authorization.d.ts +2 -2
- package/dest/api/authorization.d.ts.map +1 -1
- package/dest/api/authorization.js +1 -1
- package/dest/api/block.d.ts +2 -2
- package/dest/api/block.d.ts.map +1 -1
- package/dest/api/block.js +1 -1
- package/dest/api/fields.d.ts +3 -2
- package/dest/api/fields.d.ts.map +1 -1
- package/dest/api/fields.js +2 -1
- package/dest/api/protocol.d.ts +7 -1
- package/dest/api/protocol.d.ts.map +1 -1
- package/dest/api/protocol.js +6 -0
- package/dest/api/wallet.d.ts +2 -2
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +1 -1
- package/dest/authorization/call_authorization_request.d.ts +23 -2
- package/dest/authorization/call_authorization_request.d.ts.map +1 -1
- package/dest/contract/batch_call.d.ts +1 -1
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +3 -1
- package/dest/contract/contract_base.d.ts +4 -1
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.d.ts +1 -1
- package/dest/contract/deploy_method.d.ts +2 -2
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +6 -5
- package/dest/contract/protocol_contracts/auth-registry.d.ts +36 -0
- package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/auth-registry.js +976 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +35 -0
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-class-registry.js +797 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +31 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/contract-instance-registry.js +871 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts +30 -0
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/fee-juice.js +840 -0
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +34 -0
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/multi-call-entrypoint.js +576 -0
- package/dest/contract/protocol_contracts/public-checks.d.ts +26 -0
- package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -0
- package/dest/contract/protocol_contracts/public-checks.js +592 -0
- package/dest/contract/sent_tx.d.ts +2 -3
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/wait_for_proven.d.ts +2 -2
- package/dest/contract/wait_for_proven.d.ts.map +1 -1
- package/dest/deployment/broadcast_function.js +4 -4
- package/dest/deployment/publish_class.js +3 -3
- package/dest/deployment/publish_instance.d.ts +2 -2
- package/dest/deployment/publish_instance.d.ts.map +1 -1
- package/dest/deployment/publish_instance.js +3 -3
- package/dest/ethereum/portal_manager.d.ts +9 -6
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +17 -18
- package/dest/fee/fee_juice_payment_method_with_claim.js +1 -1
- package/dest/fee/private_fee_payment_method.js +1 -1
- package/dest/fee/public_fee_payment_method.js +1 -1
- package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
- package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
- package/dest/scripts/generate_protocol_contract_types.js +120 -0
- package/dest/utils/abi_types.d.ts +2 -2
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/authwit.d.ts +4 -2
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +4 -4
- package/dest/utils/cross_chain.d.ts +2 -2
- package/dest/utils/cross_chain.d.ts.map +1 -1
- package/dest/utils/fee_juice.js +1 -1
- package/dest/utils/field_compressed_string.js +1 -1
- package/dest/utils/pub_key.d.ts +2 -2
- package/dest/utils/pub_key.d.ts.map +1 -1
- package/dest/utils/pub_key.js +1 -1
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +5 -8
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
- package/dest/wallet/account_entrypoint_meta_payment_method.js +28 -43
- package/dest/wallet/account_manager.d.ts +6 -9
- package/dest/wallet/account_manager.d.ts.map +1 -1
- package/dest/wallet/account_manager.js +6 -12
- package/dest/wallet/deploy_account_method.d.ts +18 -4
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +8 -6
- package/dest/wallet/wallet.d.ts +242 -955
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +61 -88
- package/package.json +14 -12
- package/src/account/account.ts +34 -58
- package/src/account/account_contract.ts +7 -8
- package/src/account/account_with_secret_key.ts +34 -9
- package/src/account/index.ts +3 -2
- package/src/account/signerless_account.ts +14 -13
- package/src/api/account.ts +9 -3
- package/src/api/authorization.ts +1 -0
- package/src/api/block.ts +1 -1
- package/src/api/fields.ts +2 -1
- package/src/api/protocol.ts +7 -0
- package/src/api/wallet.ts +4 -2
- package/src/authorization/call_authorization_request.ts +1 -1
- package/src/contract/batch_call.ts +4 -2
- package/src/contract/deploy_method.ts +8 -7
- package/src/contract/protocol_contracts/auth-registry.ts +554 -0
- package/src/contract/protocol_contracts/contract-class-registry.ts +442 -0
- package/src/contract/protocol_contracts/contract-instance-registry.ts +502 -0
- package/src/contract/protocol_contracts/fee-juice.ts +466 -0
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +338 -0
- package/src/contract/protocol_contracts/public-checks.ts +324 -0
- package/src/contract/sent_tx.ts +1 -2
- package/src/deployment/broadcast_function.ts +4 -4
- package/src/deployment/publish_class.ts +3 -3
- package/src/deployment/publish_instance.ts +3 -6
- package/src/ethereum/portal_manager.ts +20 -24
- package/src/fee/fee_juice_payment_method_with_claim.ts +1 -1
- package/src/fee/private_fee_payment_method.ts +1 -1
- package/src/fee/public_fee_payment_method.ts +1 -1
- package/src/scripts/generate_protocol_contract_types.ts +150 -0
- package/src/utils/abi_types.ts +1 -1
- package/src/utils/authwit.ts +4 -4
- package/src/utils/cross_chain.ts +1 -1
- package/src/utils/fee_juice.ts +1 -1
- package/src/utils/field_compressed_string.ts +1 -1
- package/src/utils/pub_key.ts +2 -2
- package/src/wallet/account_entrypoint_meta_payment_method.ts +28 -60
- package/src/wallet/account_manager.ts +6 -14
- package/src/wallet/deploy_account_method.ts +20 -11
- package/src/wallet/wallet.ts +162 -83
- package/dest/account/interface.d.ts +0 -19
- package/dest/account/interface.d.ts.map +0 -1
- package/dest/account/interface.js +0 -5
- package/dest/contract/protocol_contracts.d.ts +0 -9
- package/dest/contract/protocol_contracts.d.ts.map +0 -1
- package/dest/contract/protocol_contracts.js +0 -26
- package/dest/contract/unsafe_contract.d.ts +0 -15
- package/dest/contract/unsafe_contract.d.ts.map +0 -1
- package/dest/contract/unsafe_contract.js +0 -6
- package/src/account/interface.ts +0 -25
- package/src/contract/protocol_contracts.ts +0 -35
- package/src/contract/unsafe_contract.ts +0 -19
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
5
5
|
} from '@aztec/constants';
|
|
6
6
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
7
|
-
import { Fr } from '@aztec/foundation/
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
8
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
9
9
|
import { type ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi';
|
|
10
10
|
import {
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import { Capsule } from '@aztec/stdlib/tx';
|
|
17
17
|
|
|
18
18
|
import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
19
|
-
import {
|
|
19
|
+
import { ContractClassRegistryContract } from '../contract/protocol_contracts/contract-class-registry.js';
|
|
20
20
|
import type { Wallet } from '../wallet/index.js';
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -58,7 +58,7 @@ export async function broadcastPrivateFunction(
|
|
|
58
58
|
|
|
59
59
|
const vkHash = await computeVerificationKeyHash(privateFunctionArtifact);
|
|
60
60
|
|
|
61
|
-
const classRegistry =
|
|
61
|
+
const classRegistry = ContractClassRegistryContract.at(wallet);
|
|
62
62
|
const bytecode = bufferAsFields(
|
|
63
63
|
privateFunctionArtifact.bytecode,
|
|
64
64
|
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
@@ -121,7 +121,7 @@ export async function broadcastUtilityFunction(
|
|
|
121
121
|
privateFunctionsArtifactTreeRoot,
|
|
122
122
|
} = await createUtilityFunctionMembershipProof(selector, artifact);
|
|
123
123
|
|
|
124
|
-
const classRegistry =
|
|
124
|
+
const classRegistry = ContractClassRegistryContract.at(wallet);
|
|
125
125
|
const bytecode = bufferAsFields(
|
|
126
126
|
utilityFunctionArtifact.bytecode,
|
|
127
127
|
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
CONTRACT_CLASS_REGISTRY_BYTECODE_CAPSULE_SLOT,
|
|
3
3
|
MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS,
|
|
4
4
|
} from '@aztec/constants';
|
|
5
|
-
import { Fr } from '@aztec/foundation/
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
7
7
|
import { type ContractArtifact, bufferAsFields } from '@aztec/stdlib/abi';
|
|
8
8
|
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
9
9
|
import { Capsule } from '@aztec/stdlib/tx';
|
|
10
10
|
|
|
11
11
|
import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
12
|
-
import {
|
|
12
|
+
import { ContractClassRegistryContract } from '../contract/protocol_contracts/contract-class-registry.js';
|
|
13
13
|
import type { Wallet } from '../wallet/index.js';
|
|
14
14
|
|
|
15
15
|
/** Sets up a call to publish a contract class given its artifact. */
|
|
@@ -19,7 +19,7 @@ export async function publishContractClass(
|
|
|
19
19
|
): Promise<ContractFunctionInteraction> {
|
|
20
20
|
const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } =
|
|
21
21
|
await getContractClassFromArtifact(artifact);
|
|
22
|
-
const classRegistry =
|
|
22
|
+
const classRegistry = ContractClassRegistryContract.at(wallet);
|
|
23
23
|
|
|
24
24
|
const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS);
|
|
25
25
|
return classRegistry.methods.publish(artifactHash, privateFunctionsRoot, publicBytecodeCommitment).with({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
2
2
|
|
|
3
3
|
import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ContractInstanceRegistryContract } from '../contract/protocol_contracts/contract-instance-registry.js';
|
|
5
5
|
import type { Wallet } from '../wallet/wallet.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -9,11 +9,8 @@ import type { Wallet } from '../wallet/wallet.js';
|
|
|
9
9
|
* @param wallet - The wallet to use for the publication (setup) tx.
|
|
10
10
|
* @param instance - The instance to publish.
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
13
|
-
wallet
|
|
14
|
-
instance: ContractInstanceWithAddress,
|
|
15
|
-
): Promise<ContractFunctionInteraction> {
|
|
16
|
-
const contractInstanceRegistry = await getInstanceRegistryContract(wallet);
|
|
12
|
+
export function publishInstance(wallet: Wallet, instance: ContractInstanceWithAddress): ContractFunctionInteraction {
|
|
13
|
+
const contractInstanceRegistry = ContractInstanceRegistryContract.at(wallet);
|
|
17
14
|
const { salt, currentContractClassId: contractClassId, publicKeys, deployer: instanceDeployer } = instance;
|
|
18
15
|
const isUniversalDeploy = instanceDeployer.isZero();
|
|
19
16
|
return contractInstanceRegistry.methods.publish_for_public_execution(
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { ExtendedViemWalletClient, ViemContract } from '@aztec/ethereum';
|
|
1
|
+
import type { ExtendedViemWalletClient, ViemContract } from '@aztec/ethereum/types';
|
|
2
2
|
import { extractEvent } from '@aztec/ethereum/utils';
|
|
3
|
-
import {
|
|
3
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
6
7
|
import type { Logger } from '@aztec/foundation/log';
|
|
7
8
|
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
8
9
|
import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
|
|
@@ -132,7 +133,7 @@ export class L1FeeJuicePortalManager {
|
|
|
132
133
|
constructor(
|
|
133
134
|
portalAddress: EthAddress,
|
|
134
135
|
tokenAddress: EthAddress,
|
|
135
|
-
handlerAddress: EthAddress,
|
|
136
|
+
handlerAddress: EthAddress | undefined,
|
|
136
137
|
private readonly extendedClient: ExtendedViemWalletClient,
|
|
137
138
|
private readonly logger: Logger,
|
|
138
139
|
) {
|
|
@@ -157,9 +158,9 @@ export class L1FeeJuicePortalManager {
|
|
|
157
158
|
*/
|
|
158
159
|
public async bridgeTokensPublic(to: AztecAddress, amount: bigint | undefined, mint = false): Promise<L2AmountClaim> {
|
|
159
160
|
const [claimSecret, claimSecretHash] = await generateClaimSecret();
|
|
160
|
-
const
|
|
161
|
-
const amountToBridge = amount ?? mintableAmount;
|
|
161
|
+
const amountToBridge = amount ?? (await this.tokenManager.getMintAmount());
|
|
162
162
|
if (mint) {
|
|
163
|
+
const mintableAmount = await this.tokenManager.getMintAmount();
|
|
163
164
|
if (amountToBridge !== mintableAmount) {
|
|
164
165
|
throw new Error(`Minting amount must be ${mintableAmount}`);
|
|
165
166
|
}
|
|
@@ -233,17 +234,12 @@ export class L1FeeJuicePortalManager {
|
|
|
233
234
|
if (feeJuiceAddress.isZero() || feeJuicePortalAddress.isZero()) {
|
|
234
235
|
throw new Error('Portal or token not deployed on L1');
|
|
235
236
|
}
|
|
236
|
-
if (!feeAssetHandlerAddress || feeAssetHandlerAddress.isZero()) {
|
|
237
|
-
throw new Error('Handler not deployed on L1, or handler address is zero');
|
|
238
|
-
}
|
|
239
237
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
logger,
|
|
246
|
-
);
|
|
238
|
+
// Handler is optional - it's only needed for minting tokens during testing
|
|
239
|
+
const handlerAddress =
|
|
240
|
+
feeAssetHandlerAddress && !feeAssetHandlerAddress.isZero() ? feeAssetHandlerAddress : undefined;
|
|
241
|
+
|
|
242
|
+
return new L1FeeJuicePortalManager(feeJuicePortalAddress, feeJuiceAddress, handlerAddress, extendedClient, logger);
|
|
247
243
|
}
|
|
248
244
|
}
|
|
249
245
|
|
|
@@ -413,26 +409,26 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
|
|
|
413
409
|
* Withdraws funds from the portal by consuming an L2 to L1 message. Returns once the tx is mined on L1.
|
|
414
410
|
* @param amount - Amount to withdraw.
|
|
415
411
|
* @param recipient - Who will receive the funds.
|
|
416
|
-
* @param
|
|
412
|
+
* @param epochNumber - Epoch number of the message.
|
|
417
413
|
* @param messageIndex - Index of the message.
|
|
418
414
|
* @param siblingPath - Sibling path of the message.
|
|
419
415
|
*/
|
|
420
416
|
public async withdrawFunds(
|
|
421
417
|
amount: bigint,
|
|
422
418
|
recipient: EthAddress,
|
|
423
|
-
|
|
419
|
+
epochNumber: EpochNumber,
|
|
424
420
|
messageIndex: bigint,
|
|
425
421
|
siblingPath: SiblingPath<number>,
|
|
426
422
|
) {
|
|
427
423
|
this.logger.info(
|
|
428
|
-
`Sending L1 tx to consume message at
|
|
424
|
+
`Sending L1 tx to consume message at epoch ${epochNumber} index ${messageIndex} to withdraw ${amount}`,
|
|
429
425
|
);
|
|
430
426
|
|
|
431
427
|
const messageLeafId = getL2ToL1MessageLeafId({ leafIndex: messageIndex, siblingPath });
|
|
432
|
-
const isConsumedBefore = await this.outbox.read.
|
|
428
|
+
const isConsumedBefore = await this.outbox.read.hasMessageBeenConsumedAtEpoch([BigInt(epochNumber), messageLeafId]);
|
|
433
429
|
if (isConsumedBefore) {
|
|
434
430
|
throw new Error(
|
|
435
|
-
`
|
|
431
|
+
`L2 to L1 message at epoch ${epochNumber} index ${messageIndex} height ${siblingPath.pathSize} has already been consumed`,
|
|
436
432
|
);
|
|
437
433
|
}
|
|
438
434
|
|
|
@@ -441,7 +437,7 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
|
|
|
441
437
|
recipient.toString(),
|
|
442
438
|
amount,
|
|
443
439
|
false,
|
|
444
|
-
BigInt(
|
|
440
|
+
BigInt(epochNumber),
|
|
445
441
|
messageIndex,
|
|
446
442
|
siblingPath.toBufferArray().map((buf: Buffer): Hex => `0x${buf.toString('hex')}`),
|
|
447
443
|
]);
|
|
@@ -450,10 +446,10 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
|
|
|
450
446
|
hash: await this.extendedClient.writeContract(withdrawRequest),
|
|
451
447
|
});
|
|
452
448
|
|
|
453
|
-
const isConsumedAfter = await this.outbox.read.
|
|
449
|
+
const isConsumedAfter = await this.outbox.read.hasMessageBeenConsumedAtEpoch([BigInt(epochNumber), messageLeafId]);
|
|
454
450
|
if (!isConsumedAfter) {
|
|
455
451
|
throw new Error(
|
|
456
|
-
`
|
|
452
|
+
`L2 to L1 message at epoch ${epochNumber} index ${messageIndex} height ${siblingPath.pathSize} not consumed after withdrawal`,
|
|
457
453
|
);
|
|
458
454
|
}
|
|
459
455
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
3
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates type-safe contract wrappers for protocol contracts.
|
|
3
|
+
* These wrappers use a minimal artifact (without bytecode) since PXE already has the full artifacts registered.
|
|
4
|
+
*/
|
|
5
|
+
import { generateTypescriptContractInterface } from '@aztec/builder/codegen';
|
|
6
|
+
import {
|
|
7
|
+
type ContractArtifact,
|
|
8
|
+
type FunctionAbi,
|
|
9
|
+
FunctionType,
|
|
10
|
+
getAllFunctionAbis,
|
|
11
|
+
loadContractArtifact,
|
|
12
|
+
} from '@aztec/stdlib/abi';
|
|
13
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
14
|
+
|
|
15
|
+
import { promises as fs } from 'fs';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
|
|
18
|
+
const log = console.log;
|
|
19
|
+
|
|
20
|
+
const noirContractsRoot = path.join(import.meta.dirname, '../../../../noir-projects/noir-contracts');
|
|
21
|
+
const srcPath = path.join(noirContractsRoot, 'target');
|
|
22
|
+
const outputDir = path.join(import.meta.dirname, '../contract/protocol_contracts');
|
|
23
|
+
|
|
24
|
+
function toKebabCase(str: string): string {
|
|
25
|
+
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function functionTypeToEnum(type: FunctionType): string {
|
|
29
|
+
switch (type) {
|
|
30
|
+
case FunctionType.PRIVATE:
|
|
31
|
+
return 'FunctionType.PRIVATE';
|
|
32
|
+
case FunctionType.PUBLIC:
|
|
33
|
+
return 'FunctionType.PUBLIC';
|
|
34
|
+
case FunctionType.UTILITY:
|
|
35
|
+
return 'FunctionType.UTILITY';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function generateFunctionAbiJson(abi: FunctionAbi): string {
|
|
40
|
+
const baseObj = {
|
|
41
|
+
name: abi.name,
|
|
42
|
+
isOnlySelf: abi.isOnlySelf,
|
|
43
|
+
isStatic: abi.isStatic,
|
|
44
|
+
isInitializer: abi.isInitializer,
|
|
45
|
+
parameters: abi.parameters,
|
|
46
|
+
returnTypes: abi.returnTypes,
|
|
47
|
+
errorTypes: abi.errorTypes,
|
|
48
|
+
};
|
|
49
|
+
const jsonStr = JSON.stringify(baseObj);
|
|
50
|
+
return jsonStr.replace('{', `{ functionType: ${functionTypeToEnum(abi.functionType)},`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function generateProtocolContractArtifact(input: ContractArtifact): string {
|
|
54
|
+
const allAbis = getAllFunctionAbis(input);
|
|
55
|
+
const functionAbis = input.functions.map(f => allAbis.find(abi => abi.name === f.name)!);
|
|
56
|
+
const nonDispatchAbis = input.nonDispatchPublicFunctions;
|
|
57
|
+
|
|
58
|
+
const functionsArray = functionAbis
|
|
59
|
+
.map(abi => `{ ...${generateFunctionAbiJson(abi)}, bytecode: Buffer.from([]), debugSymbols: '' }`)
|
|
60
|
+
.join(',\n ');
|
|
61
|
+
|
|
62
|
+
const nonDispatchArray = nonDispatchAbis.map(abi => generateFunctionAbiJson(abi)).join(',\n ');
|
|
63
|
+
|
|
64
|
+
return `{
|
|
65
|
+
name: '${input.name}',
|
|
66
|
+
functions: [
|
|
67
|
+
${functionsArray}
|
|
68
|
+
],
|
|
69
|
+
nonDispatchPublicFunctions: [
|
|
70
|
+
${nonDispatchArray}
|
|
71
|
+
],
|
|
72
|
+
outputs: { structs: {}, globals: {} },
|
|
73
|
+
storageLayout: {},
|
|
74
|
+
fileMap: {},
|
|
75
|
+
}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function generateProtocolContractInterface(
|
|
79
|
+
input: ContractArtifact,
|
|
80
|
+
protocolContractName: string,
|
|
81
|
+
): Promise<string> {
|
|
82
|
+
const baseInterface = await generateTypescriptContractInterface(input);
|
|
83
|
+
|
|
84
|
+
// Match everything between "public declare methods: {" and the closing "};"
|
|
85
|
+
const methodsMatch = baseInterface.match(/public declare methods: \{([\s\S]*?)\n \};/);
|
|
86
|
+
if (!methodsMatch) {
|
|
87
|
+
throw new Error('Could not extract methods from generated interface');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const artifactCode = generateProtocolContractArtifact(input);
|
|
91
|
+
const contractName = `${input.name}Contract`;
|
|
92
|
+
|
|
93
|
+
return `
|
|
94
|
+
/* Autogenerated file, do not edit! */
|
|
95
|
+
|
|
96
|
+
/* eslint-disable */
|
|
97
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
98
|
+
import { FunctionType } from '@aztec/stdlib/abi';
|
|
99
|
+
|
|
100
|
+
import type { ContractArtifact } from '../../api/abi.js';
|
|
101
|
+
import { PublicKeys } from '../../api/keys.js';
|
|
102
|
+
import type { AztecAddressLike, EthAddressLike, FieldLike, FunctionSelectorLike, WrappedFieldLike } from '../../utils/abi_types.js';
|
|
103
|
+
import { ContractBase, type ContractMethod } from '../contract_base.js';
|
|
104
|
+
import { ContractFunctionInteraction } from '../contract_function_interaction.js';
|
|
105
|
+
import type { Wallet } from '../../wallet/wallet.js';
|
|
106
|
+
|
|
107
|
+
const ${contractName}Artifact: ContractArtifact = ${artifactCode};
|
|
108
|
+
|
|
109
|
+
export class ${contractName} extends ContractBase {
|
|
110
|
+
private constructor(wallet: Wallet) {
|
|
111
|
+
super(ProtocolContractAddress.${protocolContractName}, ${contractName}Artifact, wallet);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public static at(wallet: Wallet): ${contractName} {
|
|
115
|
+
return new ${contractName}(wallet);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public declare methods: {${methodsMatch[1]}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function main() {
|
|
125
|
+
await fs.rm(outputDir, { recursive: true, force: true });
|
|
126
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
127
|
+
|
|
128
|
+
const srcNames = JSON.parse(
|
|
129
|
+
await fs.readFile(path.join(noirContractsRoot, 'protocol_contracts.json'), 'utf8'),
|
|
130
|
+
) as string[];
|
|
131
|
+
|
|
132
|
+
for (const srcName of srcNames) {
|
|
133
|
+
// srcName is like "auth_registry_contract-AuthRegistry", split to get the contract name
|
|
134
|
+
const name = srcName.split('-')[1];
|
|
135
|
+
const artifactPath = path.join(srcPath, `${srcName}.json`);
|
|
136
|
+
const json = JSON.parse(await fs.readFile(artifactPath, 'utf8')) as NoirCompiledContract;
|
|
137
|
+
const contractArtifact = loadContractArtifact(json);
|
|
138
|
+
|
|
139
|
+
const content = await generateProtocolContractInterface(contractArtifact, name);
|
|
140
|
+
const fileName = `${toKebabCase(name)}.ts`;
|
|
141
|
+
await fs.writeFile(path.join(outputDir, fileName), content);
|
|
142
|
+
|
|
143
|
+
log(`Generated ${fileName}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
main().catch(err => {
|
|
148
|
+
console.error('Error generating protocol contract types:', err);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
});
|
package/src/utils/abi_types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import type { EventSelector, FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
|
package/src/utils/authwit.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
4
|
import { type ABIParameterVisibility, type FunctionAbi, type FunctionCall, FunctionType } from '@aztec/stdlib/abi';
|
|
5
5
|
import { AuthWitness, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
|
|
@@ -42,7 +42,7 @@ export type ContractFunctionInteractionCallIntent = {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/** Identifies ContractFunctionInteractionCallIntents */
|
|
45
|
-
function
|
|
45
|
+
export function isContractFunctionInteractionCallIntent(
|
|
46
46
|
messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
47
47
|
): messageHashOrIntent is ContractFunctionInteractionCallIntent {
|
|
48
48
|
return (
|
|
@@ -81,7 +81,7 @@ export const computeAuthWitMessageHash = async (
|
|
|
81
81
|
const version = metadata.version;
|
|
82
82
|
|
|
83
83
|
if ('caller' in intent) {
|
|
84
|
-
const call =
|
|
84
|
+
const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
|
|
85
85
|
return computeOuterAuthWitHash(
|
|
86
86
|
call.to,
|
|
87
87
|
chainId,
|
|
@@ -154,7 +154,7 @@ export async function lookupValidity(
|
|
|
154
154
|
}> {
|
|
155
155
|
let innerHash, consumer;
|
|
156
156
|
if ('caller' in intent) {
|
|
157
|
-
const call =
|
|
157
|
+
const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
|
|
158
158
|
innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
|
|
159
159
|
consumer = call.to;
|
|
160
160
|
} else {
|
package/src/utils/cross_chain.ts
CHANGED
package/src/utils/fee_juice.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
|
package/src/utils/pub_key.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Grumpkin } from '@aztec/foundation/crypto';
|
|
2
|
-
import type { GrumpkinScalar } from '@aztec/foundation/
|
|
1
|
+
import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
|
|
2
|
+
import type { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
3
3
|
import type { PublicKey } from '@aztec/stdlib/keys';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
2
|
-
import { EncodedAppEntrypointCalls } from '@aztec/entrypoints/encoding';
|
|
3
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
|
-
import {
|
|
5
|
-
type ContractArtifact,
|
|
6
|
-
type FunctionArtifact,
|
|
7
|
-
FunctionCall,
|
|
8
|
-
FunctionSelector,
|
|
9
|
-
encodeArguments,
|
|
10
|
-
getFunctionArtifactByName,
|
|
11
|
-
} from '@aztec/stdlib/abi';
|
|
12
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
4
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
14
5
|
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
15
6
|
|
|
7
|
+
import type { Account } from '../account/account.js';
|
|
16
8
|
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
17
|
-
import type { Wallet } from './index.js';
|
|
18
9
|
|
|
19
10
|
/**
|
|
20
11
|
* Fee payment method that allows an account contract to pay for its own deployment
|
|
@@ -33,11 +24,9 @@ import type { Wallet } from './index.js';
|
|
|
33
24
|
*/
|
|
34
25
|
export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
35
26
|
constructor(
|
|
36
|
-
private
|
|
37
|
-
private artifact: ContractArtifact,
|
|
38
|
-
private feePaymentNameOrArtifact: string | FunctionArtifact,
|
|
39
|
-
private accountAddress: AztecAddress,
|
|
27
|
+
private account: Account,
|
|
40
28
|
private paymentMethod?: FeePaymentMethod,
|
|
29
|
+
private feeEntrypointOptions?: any,
|
|
41
30
|
) {}
|
|
42
31
|
|
|
43
32
|
getAsset(): Promise<AztecAddress> {
|
|
@@ -45,59 +34,38 @@ export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
|
|
|
45
34
|
}
|
|
46
35
|
|
|
47
36
|
async getExecutionPayload(): Promise<ExecutionPayload> {
|
|
48
|
-
// Get the execution payload for the fee
|
|
49
|
-
|
|
50
|
-
// FeeJuice balance
|
|
51
|
-
const { calls: feeCalls, authWitnesses: feeAuthwitnesses } =
|
|
52
|
-
(await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
|
|
53
|
-
// Encode the calls for the fee
|
|
54
|
-
const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.accountAddress;
|
|
55
|
-
const isFeePayer = feePayer.equals(this.accountAddress);
|
|
56
|
-
let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
|
|
57
|
-
if (isFeePayer) {
|
|
58
|
-
// If the account is the fee payer, and the incoming fee payload has calls
|
|
59
|
-
// it can only be FeeJuicePaymentMethodWithClaim
|
|
60
|
-
// If the payload has no calls, it's paying using
|
|
61
|
-
// its own fee juice balance
|
|
62
|
-
accountFeePaymentMethodOptions =
|
|
63
|
-
feeCalls.length === 0
|
|
64
|
-
? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
|
|
65
|
-
: AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
|
|
66
|
-
}
|
|
67
|
-
const feeEncodedCalls = await EncodedAppEntrypointCalls.create(feeCalls);
|
|
37
|
+
// Get the execution payload for the fee
|
|
38
|
+
const innerPayload = (await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
|
|
68
39
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
40
|
+
// If no fee entrypoint options were provided, compute them based on the wrapped payment method
|
|
41
|
+
// This mimics how the actual account contract works when invoked directly:
|
|
42
|
+
// - If we are the fee payer, are there calls in the inner payload? In that case, those calls can
|
|
43
|
+
// only be claiming fee juice, so we use FEE_JUICE_WITH_CLAIM
|
|
44
|
+
// - If we are the fee payer, but there are no calls, then we assume the account already has
|
|
45
|
+
// fee juice and can pay directly with PREEXISTING_FEE_JUICE
|
|
46
|
+
// - If we are not the fee payer, then EXTERNAL is used
|
|
47
|
+
let options = this.feeEntrypointOptions;
|
|
48
|
+
if (!options) {
|
|
49
|
+
const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.account.getAddress();
|
|
50
|
+
const isFeePayer = feePayer.equals(this.account.getAddress());
|
|
75
51
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
encodeArguments(feePaymentArtifact, args),
|
|
84
|
-
feePaymentArtifact.returnTypes,
|
|
85
|
-
);
|
|
52
|
+
let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
|
|
53
|
+
if (isFeePayer) {
|
|
54
|
+
accountFeePaymentMethodOptions =
|
|
55
|
+
innerPayload.calls.length === 0
|
|
56
|
+
? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
|
|
57
|
+
: AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
|
|
58
|
+
}
|
|
86
59
|
|
|
87
|
-
|
|
88
|
-
|
|
60
|
+
options = { feePaymentMethodOptions: accountFeePaymentMethodOptions };
|
|
61
|
+
}
|
|
89
62
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[payloadAuthWitness, ...feeAuthwitnesses],
|
|
93
|
-
[],
|
|
94
|
-
feeEncodedCalls.hashedArguments,
|
|
95
|
-
feePayer,
|
|
96
|
-
);
|
|
63
|
+
// Use the generic wrapping mechanism from the account interface
|
|
64
|
+
return this.account.wrapExecutionPayload(innerPayload, options);
|
|
97
65
|
}
|
|
98
66
|
|
|
99
67
|
getFeePayer(): Promise<AztecAddress> {
|
|
100
|
-
return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.
|
|
68
|
+
return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.account.getAddress());
|
|
101
69
|
}
|
|
102
70
|
|
|
103
71
|
getGasSettings(): GasSettings | undefined {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import {
|
|
3
3
|
CompleteAddress,
|
|
4
4
|
type ContractInstanceWithAddress,
|
|
@@ -9,7 +9,6 @@ import { deriveKeys } from '@aztec/stdlib/keys';
|
|
|
9
9
|
import type { AccountContract } from '../account/account_contract.js';
|
|
10
10
|
import { AccountWithSecretKey } from '../account/account_with_secret_key.js';
|
|
11
11
|
import type { Salt } from '../account/index.js';
|
|
12
|
-
import type { AccountInterface } from '../account/interface.js';
|
|
13
12
|
import { Contract } from '../contract/contract.js';
|
|
14
13
|
import { DeployAccountMethod } from './deploy_account_method.js';
|
|
15
14
|
import type { Wallet } from './wallet.js';
|
|
@@ -58,16 +57,6 @@ export class AccountManager {
|
|
|
58
57
|
return this.getPublicKeys().hash();
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
/**
|
|
62
|
-
* Returns the entrypoint for this account as defined by its account contract.
|
|
63
|
-
* @returns An entrypoint.
|
|
64
|
-
*/
|
|
65
|
-
public async getAccountInterface(): Promise<AccountInterface> {
|
|
66
|
-
const chainInfo = await this.wallet.getChainInfo();
|
|
67
|
-
const completeAddress = await this.getCompleteAddress();
|
|
68
|
-
return this.accountContract.getInterface(completeAddress, chainInfo);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
60
|
/**
|
|
72
61
|
* Gets the calculated complete address associated with this account.
|
|
73
62
|
* Does not require the account to have been published for public execution.
|
|
@@ -103,8 +92,9 @@ export class AccountManager {
|
|
|
103
92
|
* @returns A Wallet instance.
|
|
104
93
|
*/
|
|
105
94
|
public async getAccount(): Promise<AccountWithSecretKey> {
|
|
106
|
-
const
|
|
107
|
-
|
|
95
|
+
const completeAddress = await this.getCompleteAddress();
|
|
96
|
+
const account = this.accountContract.getAccount(completeAddress);
|
|
97
|
+
return new AccountWithSecretKey(account, this.secretKey, this.salt);
|
|
108
98
|
}
|
|
109
99
|
|
|
110
100
|
/**
|
|
@@ -134,12 +124,14 @@ export class AccountManager {
|
|
|
134
124
|
constructorArgs: undefined,
|
|
135
125
|
};
|
|
136
126
|
|
|
127
|
+
const account = await this.getAccount();
|
|
137
128
|
return new DeployAccountMethod(
|
|
138
129
|
this.getPublicKeys(),
|
|
139
130
|
this.wallet,
|
|
140
131
|
artifact,
|
|
141
132
|
instance => Contract.at(instance.address, artifact, this.wallet),
|
|
142
133
|
new Fr(this.salt),
|
|
134
|
+
account,
|
|
143
135
|
constructorArgs,
|
|
144
136
|
constructorName,
|
|
145
137
|
);
|