Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion yarn-project/aztec.js/src/api/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export {
type ContractClassMetadata,
AppCapabilitiesSchema,
WalletCapabilitiesSchema,
FunctionCallSchema,
ExecutionPayloadSchema,
GasSettingsOptionSchema,
WalletSimulationFeeOptionSchema,
Expand Down
25 changes: 11 additions & 14 deletions yarn-project/aztec.js/src/contract/batch_call.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fr } from '@aztec/foundation/curves/bn254';
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { ExecutionPayload, TxSimulationResult, UtilitySimulationResult } from '@aztec/stdlib/tx';

Expand All @@ -8,24 +8,23 @@ import { type MockProxy, mock } from 'jest-mock-extended';
import type { Wallet } from '../wallet/wallet.js';
import { BatchCall } from './batch_call.js';

// eslint-disable-next-line jsdoc/require-jsdoc
function createUtilityExecutionPayload(
functionName: string,
args: Fr[],
contractAddress: AztecAddress,
): ExecutionPayload {
return new ExecutionPayload(
[
{
FunctionCall.from({
name: functionName,
to: contractAddress,
selector: FunctionSelector.random(),
type: FunctionType.UTILITY,
isStatic: true,
hideMsgSender: false,
isStatic: true,
args,
returnTypes: [{ kind: 'field' }],
},
}),
],
[],
[],
Expand All @@ -34,7 +33,6 @@ function createUtilityExecutionPayload(
);
}

// eslint-disable-next-line jsdoc/require-jsdoc
function createPrivateExecutionPayload(
functionName: string,
args: Fr[],
Expand All @@ -43,16 +41,16 @@ function createPrivateExecutionPayload(
): ExecutionPayload {
return new ExecutionPayload(
[
{
FunctionCall.from({
name: functionName,
to: contractAddress,
selector: FunctionSelector.random(),
type: FunctionType.PRIVATE,
isStatic: false,
hideMsgSender: false,
isStatic: false,
args,
returnTypes: Array(numReturnValues).fill({ kind: 'field' }),
},
}),
],
[],
[],
Expand All @@ -61,24 +59,23 @@ function createPrivateExecutionPayload(
);
}

// eslint-disable-next-line jsdoc/require-jsdoc
function createPublicExecutionPayload(
functionName: string,
args: Fr[],
contractAddress: AztecAddress,
): ExecutionPayload {
return new ExecutionPayload(
[
{
FunctionCall.from({
name: functionName,
to: contractAddress,
selector: FunctionSelector.random(),
type: FunctionType.PUBLIC,
isStatic: false,
hideMsgSender: false,
isStatic: false,
args,
returnTypes: [{ kind: 'field' }],
},
}),
],
[],
[],
Expand Down Expand Up @@ -272,7 +269,7 @@ describe('BatchCall', () => {
batchCall = new BatchCall(wallet, [payload]);

const feePayload = createPrivateExecutionPayload('payFee', [Fr.random()], await AztecAddress.random());
// eslint-disable-next-line jsdoc/require-jsdoc

const mockPaymentMethod = mock<{ getExecutionPayload: () => Promise<ExecutionPayload> }>();
mockPaymentMethod.getExecutionPayload.mockResolvedValue(feePayload);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi';
import {
type FunctionAbi,
FunctionCall,
FunctionSelector,
FunctionType,
decodeFromAbi,
encodeArguments,
} from '@aztec/stdlib/abi';
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { type Capsule, type HashedValues, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
Expand Down Expand Up @@ -43,16 +50,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
*/
public async getFunctionCall() {
const args = encodeArguments(this.functionDao, this.args);
return {
return FunctionCall.from({
name: this.functionDao.name,
args,
to: this.contractAddress,
selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
type: this.functionDao.functionType,
to: this.contractAddress,
isStatic: this.functionDao.isStatic,
hideMsgSender: false /** Only set to `true` for enqueued public function calls */,
isStatic: this.functionDao.isStatic,
args,
returnTypes: this.functionDao.returnTypes,
};
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr } from '@aztec/foundation/curves/bn254';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { GasSettings } from '@aztec/stdlib/gas';
import { ExecutionPayload } from '@aztec/stdlib/tx';
Expand All @@ -27,10 +27,11 @@ export class FeeJuicePaymentMethodWithClaim implements FeePaymentMethod {

return new ExecutionPayload(
[
{
to: ProtocolContractAddress.FeeJuice,
FunctionCall.from({
name: 'claim_and_end_setup',
to: ProtocolContractAddress.FeeJuice,
selector,
type: FunctionType.PRIVATE,
hideMsgSender: false,
isStatic: false,
args: [
Expand All @@ -40,8 +41,7 @@ export class FeeJuicePaymentMethodWithClaim implements FeePaymentMethod {
new Fr(this.claim.messageLeafIndex),
],
returnTypes: [],
type: FunctionType.PRIVATE,
},
}),
],
[],
[],
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/aztec.js/src/fee/private_fee_payment_method.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fr } from '@aztec/foundation/curves/bn254';
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
import { type FunctionAbi, FunctionCall, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { GasSettings } from '@aztec/stdlib/gas';
import { ExecutionPayload } from '@aztec/stdlib/tx';
Expand Down Expand Up @@ -102,21 +102,21 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {

const witness = await this.wallet.createAuthWit(this.sender, {
caller: this.paymentContract,
call: {
call: FunctionCall.from({
name: 'transfer_to_public',
args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
to: await this.getAsset(),
selector: await FunctionSelector.fromSignature('transfer_to_public((Field),(Field),u128,Field)'),
type: FunctionType.PRIVATE,
hideMsgSender: false,
isStatic: false,
to: await this.getAsset(),
args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
returnTypes: [],
},
}),
});

return new ExecutionPayload(
[
{
FunctionCall.from({
name: 'fee_entrypoint_private',
to: this.paymentContract,
selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'),
Expand All @@ -125,7 +125,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
isStatic: false,
args: [maxFee, txNonce],
returnTypes: [],
},
}),
],
[witness],
[],
Expand Down
16 changes: 8 additions & 8 deletions yarn-project/aztec.js/src/fee/public_fee_payment_method.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fr } from '@aztec/foundation/curves/bn254';
import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
import { type FunctionAbi, FunctionCall, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { GasSettings } from '@aztec/stdlib/gas';
import { ExecutionPayload } from '@aztec/stdlib/tx';
Expand Down Expand Up @@ -94,16 +94,16 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {

const intent = {
caller: this.paymentContract,
call: {
call: FunctionCall.from({
name: 'transfer_in_public',
args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
to: await this.getAsset(),
selector: await FunctionSelector.fromSignature('transfer_in_public((Field),(Field),u128,Field)'),
type: FunctionType.PUBLIC,
isStatic: false,
hideMsgSender: false /** The target function performs an authwit check, so msg_sender is needed */,
to: await this.getAsset(),
isStatic: false,
args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
returnTypes: [],
},
}),
};

const setPublicAuthWitInteraction = await SetPublicAuthwitContractInteraction.create(
Expand All @@ -116,7 +116,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
return new ExecutionPayload(
[
...(await setPublicAuthWitInteraction.request()).calls,
{
FunctionCall.from({
name: 'fee_entrypoint_public',
to: this.paymentContract,
selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
Expand All @@ -125,7 +125,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
isStatic: false,
args: [maxFee, txNonce],
returnTypes: [],
},
}),
],
[],
[],
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/fee/sponsored_fee_payment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { GasSettings } from '@aztec/stdlib/gas';
import { ExecutionPayload } from '@aztec/stdlib/tx';
Expand All @@ -22,7 +22,7 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
async getExecutionPayload(): Promise<ExecutionPayload> {
return new ExecutionPayload(
[
{
FunctionCall.from({
name: 'sponsor_unconditionally',
to: this.paymentContract,
selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
Expand All @@ -31,7 +31,7 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
isStatic: false,
args: [],
returnTypes: [],
},
}),
],
[],
[],
Expand Down
15 changes: 7 additions & 8 deletions yarn-project/aztec.js/src/wallet/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
import { Fr } from '@aztec/foundation/curves/bn254';
import { type JsonRpcTestContext, createJsonRpcTestSetup } from '@aztec/foundation/json-rpc/test';
import type { ContractArtifact, EventMetadataDefinition } from '@aztec/stdlib/abi';
import { EventSelector, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import { EventSelector, FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
import { AuthWitness } from '@aztec/stdlib/auth-witness';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { BlockHash } from '@aztec/stdlib/block';
Expand Down Expand Up @@ -164,16 +164,16 @@ describe('WalletSchema', () => {
});

it('simulateUtility', async () => {
const call = {
const call = FunctionCall.from({
name: 'testFunction',
to: await AztecAddress.random(),
selector: FunctionSelector.fromField(new Fr(1)),
type: FunctionType.UTILITY,
isStatic: false,
hideMsgSender: false,
isStatic: false,
args: [Fr.random()],
returnTypes: [],
};
});
const result = await context.client.simulateUtility(call, [AuthWitness.random()]);
expect(result).toBeInstanceOf(UtilitySimulationResult);
});
Expand Down Expand Up @@ -272,16 +272,16 @@ describe('WalletSchema', () => {
profileMode: 'gates',
};

const call = {
const call = FunctionCall.from({
name: 'testFunction',
to: address3,
selector: FunctionSelector.fromField(new Fr(1)),
type: FunctionType.UTILITY,
isStatic: false,
hideMsgSender: false,
isStatic: false,
args: [Fr.random()],
returnTypes: [],
};
});

const mockInstance: ContractInstanceWithAddress = {
address: address2,
Expand Down Expand Up @@ -355,7 +355,6 @@ describe('WalletSchema', () => {
});
});

// eslint-disable-next-line jsdoc/require-jsdoc
class MockWallet implements Wallet {
getChainInfo(): Promise<ChainInfo> {
return Promise.resolve({
Expand Down
20 changes: 4 additions & 16 deletions yarn-project/aztec.js/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
type ContractArtifact,
ContractArtifactSchema,
type EventMetadataDefinition,
type FunctionCall,
FunctionType,
FunctionCall,
} from '@aztec/stdlib/abi';
import { AuthWitness } from '@aztec/stdlib/auth-witness';
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
Expand Down Expand Up @@ -257,19 +256,8 @@ export type Wallet = {
batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
};

export const FunctionCallSchema = z.object({
name: z.string(),
to: schemas.AztecAddress,
selector: schemas.FunctionSelector,
type: z.nativeEnum(FunctionType),
isStatic: z.boolean(),
hideMsgSender: z.boolean(),
args: z.array(schemas.Fr),
returnTypes: z.array(AbiTypeSchema),
});

export const ExecutionPayloadSchema = z.object({
calls: z.array(FunctionCallSchema),
calls: z.array(FunctionCall.schema),
authWitnesses: z.array(AuthWitness.schema),
capsules: z.array(Capsule.schema),
extraHashedArgs: z.array(HashedValues.schema),
Expand Down Expand Up @@ -326,7 +314,7 @@ export const MessageHashOrIntentSchema = z.union([
z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
z.object({
caller: schemas.AztecAddress,
call: FunctionCallSchema,
call: FunctionCall.schema,
}),
]);

Expand Down Expand Up @@ -522,7 +510,7 @@ const WalletMethodSchemas = {
simulateTx: z.function().args(ExecutionPayloadSchema, SimulateOptionsSchema).returns(TxSimulationResult.schema),
simulateUtility: z
.function()
.args(FunctionCallSchema, optional(z.array(AuthWitness.schema)))
.args(FunctionCall.schema, optional(z.array(AuthWitness.schema)))
.returns(UtilitySimulationResult.schema),
profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
sendTx: z
Expand Down
Loading
Loading