Skip to content

Commit

Permalink
Revert "fetching accepted asset from FPC"
Browse files Browse the repository at this point in the history
This reverts commit c29b2ca.
  • Loading branch information
benesjan committed Dec 11, 2024
1 parent 86d65c3 commit 0a7985b
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dep::aztec::macros::aztec;
contract FPC {
use crate::config::Config;
use dep::aztec::{
macros::{functions::{initializer, internal, private, public, view}, storage::storage},
macros::{functions::{initializer, internal, private, public}, storage::storage},
protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress},
state_vars::PublicImmutable,
};
Expand Down Expand Up @@ -111,10 +111,4 @@ contract FPC {
.transfer_in_public(context.this_address(), refund_recipient, refund, 0)
.call(&mut context);
}

#[public]
#[view]
fn get_accepted_asset() -> AztecAddress {
storage.config.read().accepted_asset
}
}
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/fee/fee_juice_payment_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class FeeJuicePaymentMethod implements FeePaymentMethod {
constructor(protected sender: AztecAddress) {}

getAsset() {
return Promise.resolve(ProtocolContractAddress.FeeJuice);
return ProtocolContractAddress.FeeJuice;
}

getFunctionCalls(): Promise<FunctionCall[]> {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/fee/fee_payment_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address';
*/
export interface FeePaymentMethod {
/** The asset used to pay the fee. */
getAsset(): Promise<AztecAddress>;
getAsset(): AztecAddress;
/**
* Creates a function call to pay the fee in the given asset.
* @param gasSettings - The gas limits and max fees.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/fee/no_fee_payment_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class NoFeePaymentMethod implements FeePaymentMethod {
constructor() {}

getAsset() {
return Promise.resolve(AztecAddress.ZERO);
return AztecAddress.ZERO;
}

getFunctionCalls(): Promise<FunctionCall[]> {
Expand Down
46 changes: 8 additions & 38 deletions yarn-project/aztec.js/src/fee/private_fee_payment_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';

import { type Wallet } from '../account/wallet.js';
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
import { type FeePaymentMethod } from './fee_payment_method.js';

/**
* Holds information about how the fee for a transaction is to be paid.
*/
export class PrivateFeePaymentMethod implements FeePaymentMethod {
private assetPromise: Promise<AztecAddress> | null = null;

constructor(
/**
* The asset used to pay the fee.
*/
private asset: AztecAddress,
/**
* Address which will hold the fee payment.
*/
Expand All @@ -41,40 +42,9 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
* The asset used to pay the fee.
* @returns The asset used to pay the fee.
*/
getAsset(): Promise<AztecAddress> {
if (!this.assetPromise) {
const interaction = new ContractFunctionInteraction(
this.wallet,
this.paymentContract,
{
name: 'get_accepted_asset',
functionType: FunctionType.PUBLIC,
isInternal: false,
isStatic: true,
parameters: [],
returnTypes: [
{
kind: 'struct',
path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
fields: [
{
name: 'inner',
type: {
kind: 'field',
},
},
],
},
],
errorTypes: {},
isInitializer: false,
},
[],
);

this.assetPromise = interaction.simulate();
}
return this.assetPromise!;
// TODO(benesjan): obtain directly from contract?
getAsset() {
return this.asset;
}

getFeePayer(): Promise<AztecAddress> {
Expand All @@ -100,7 +70,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
selector: FunctionSelector.fromSignature('setup_refund((Field),(Field),Field,Field)'),
type: FunctionType.PRIVATE,
isStatic: false,
to: await this.getAsset(),
to: this.asset,
returnTypes: [],
},
});
Expand Down
47 changes: 8 additions & 39 deletions yarn-project/aztec.js/src/fee/public_fee_payment_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { type AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';

import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
import { type AccountWallet } from '../wallet/account_wallet.js';
import { type FeePaymentMethod } from './fee_payment_method.js';

/**
* Holds information about how the fee for a transaction is to be paid.
*/
export class PublicFeePaymentMethod implements FeePaymentMethod {
private assetPromise: Promise<AztecAddress> | null = null;

constructor(
/**
* The asset used to pay the fee.
*/
protected asset: AztecAddress,
/**
* Address which will hold the fee payment.
*/
Expand All @@ -29,40 +30,8 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
* The asset used to pay the fee.
* @returns The asset used to pay the fee.
*/
getAsset(): Promise<AztecAddress> {
if (!this.assetPromise) {
const interaction = new ContractFunctionInteraction(
this.wallet,
this.paymentContract,
{
name: 'get_accepted_asset',
functionType: FunctionType.PUBLIC,
isInternal: false,
isStatic: true,
parameters: [],
returnTypes: [
{
kind: 'struct',
path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
fields: [
{
name: 'inner',
type: {
kind: 'field',
},
},
],
},
],
errorTypes: {},
isInitializer: false,
},
[],
);

this.assetPromise = interaction.simulate();
}
return this.assetPromise!;
getAsset() {
return this.asset;
}

getFeePayer(): Promise<AztecAddress> {
Expand All @@ -74,7 +43,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
* @param gasSettings - The gas settings.
* @returns The function call to pay the fee.
*/
async getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
const nonce = Fr.random();
const maxFee = gasSettings.getFeeLimit();

Expand All @@ -89,7 +58,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
selector: FunctionSelector.fromSignature('transfer_in_public((Field),(Field),Field,Field)'),
type: FunctionType.PUBLIC,
isStatic: false,
to: await this.getAsset(),
to: this.asset,
returnTypes: [],
},
},
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/cli-wallet/src/utils/options/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ export function parsePaymentMethod(
case 'fpc-public': {
const [asset, fpc] = getFpcOpts(parsed, db);
log(`Using public fee payment with asset ${asset} via paymaster ${fpc}`);
return new PublicFeePaymentMethod(fpc, sender);
return new PublicFeePaymentMethod(asset, fpc, sender);
}
case 'fpc-private': {
const [asset, fpc, feeRecipient] = getFpcOpts(parsed, db);
log(
`Using private fee payment with asset ${asset} via paymaster ${fpc} with rebate secret ${feeRecipient.toString()}`,
);
return new PrivateFeePaymentMethod(fpc, sender, feeRecipient);
return new PrivateFeePaymentMethod(asset, fpc, sender, feeRecipient);
}
case undefined:
throw new Error('Missing "method" in payment option');
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,13 @@ describe('benchmarks/proving', () => {

const feeFnCall0 = {
gasSettings,
paymentMethod: new PublicFeePaymentMethod(initialFpContract.address, wallet),
paymentMethod: new PublicFeePaymentMethod(initialTokenContract.address, initialFpContract.address, wallet),
};

// const feeFnCall1 = {
// gasSettings,
// paymentMethod: new PrivateFeePaymentMethod(
// initialTokenContract.address,
// initialFpContract.address,
// await getWalletOnPxe(1),
// ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('benchmarks/tx_size_fees', () => {
],
[
'public fee',
() => new PublicFeePaymentMethod(fpc.address, aliceWallet),
() => new PublicFeePaymentMethod(token.address, fpc.address, aliceWallet),
// DA:
// non-rev: 1 nullifiers, overhead; rev: 2 note hashes, 1 nullifier, 1168 B enc note logs, 0 B enc logs,0 B unenc logs, teardown
// L2:
Expand All @@ -98,7 +98,7 @@ describe('benchmarks/tx_size_fees', () => {
],
[
'private fee',
() => new PrivateFeePaymentMethod(fpc.address, aliceWallet, sequencerAddress),
() => new PrivateFeePaymentMethod(token.address, fpc.address, aliceWallet, sequencerAddress),
// DA:
// non-rev: 3 nullifiers, overhead; rev: 2 note hashes, 1168 B enc note logs, 0 B enc logs, 0 B unenc logs, teardown
// L2:
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_fees/account_init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('e2e_fees account_init', () => {

// Bob deploys his account through the private FPC
const paymentMethod = new PrivateFeePaymentMethod(
bananaCoin.address,
bananaFPC.address,
await bobsAccountManager.getWallet(),
t.sequencerAddress, // Sequencer is the recipient of the refund fee notes because it's the FPC admin.
Expand All @@ -141,7 +142,7 @@ describe('e2e_fees account_init', () => {
const mintedBananas = FEE_FUNDING_FOR_TESTER_ACCOUNT;
await bananaCoin.methods.mint_to_public(bobsAddress, mintedBananas).send().wait();

const paymentMethod = new PublicFeePaymentMethod(bananaFPC.address, bobsWallet);
const paymentMethod = new PublicFeePaymentMethod(bananaCoin.address, bananaFPC.address, bobsWallet);
const tx = await bobsAccountManager
.deploy({
skipPublicDeployment: false,
Expand Down
16 changes: 11 additions & 5 deletions yarn-project/end-to-end/src/e2e_fees/dapp_subscription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('e2e_fees dapp_subscription', () => {
*/

const { transactionFee } = await subscribe(
new PrivateFeePaymentMethod(bananaFPC.address, aliceWallet, feeRecipient),
new PrivateFeePaymentMethod(bananaCoin.address, bananaFPC.address, aliceWallet, feeRecipient),
);

// We let Alice see Bob's notes because the expect uses Alice's wallet to interact with the contracts to "get" state.
Expand Down Expand Up @@ -146,7 +146,9 @@ describe('e2e_fees dapp_subscription', () => {
PUBLIC TEARDOWN
the FPC finalizes the partial notes for the fee and the refund
*/
const { transactionFee } = await subscribe(new PublicFeePaymentMethod(bananaFPC.address, aliceWallet));
const { transactionFee } = await subscribe(
new PublicFeePaymentMethod(bananaCoin.address, bananaFPC.address, aliceWallet),
);

await expectMapping(
t.getGasBalanceFn,
Expand All @@ -165,7 +167,7 @@ describe('e2e_fees dapp_subscription', () => {
it('should call dapp subscription entrypoint', async () => {
// Subscribe again, so this test does not depend on the previous ones being run.

await subscribe(new PrivateFeePaymentMethod(bananaFPC.address, aliceWallet, feeRecipient));
await subscribe(new PrivateFeePaymentMethod(bananaCoin.address, bananaFPC.address, aliceWallet, feeRecipient));

expect(await subscriptionContract.methods.is_initialized(aliceAddress).simulate()).toBe(true);

Expand All @@ -187,14 +189,18 @@ describe('e2e_fees dapp_subscription', () => {

it('should reject after the sub runs out', async () => {
// Subscribe again. This will overwrite the previous subscription.
await subscribe(new PrivateFeePaymentMethod(bananaFPC.address, aliceWallet, feeRecipient), 0);
await subscribe(new PrivateFeePaymentMethod(bananaCoin.address, bananaFPC.address, aliceWallet, feeRecipient), 0);
// TODO(#6651): Change back to /(context.block_number()) as u64 < expiry_block_number as u64/ when fixed
await expect(dappIncrement()).rejects.toThrow(/Note encrypted logs hash mismatch/);
});

it('should reject after the txs run out', async () => {
// Subscribe again. This will overwrite the previous subscription.
await subscribe(new PrivateFeePaymentMethod(bananaFPC.address, aliceWallet, feeRecipient), 5, 1);
await subscribe(
new PrivateFeePaymentMethod(bananaCoin.address, bananaFPC.address, aliceWallet, feeRecipient),
5,
1,
);
await expect(dappIncrement()).resolves.toBeDefined();
await expect(dappIncrement()).rejects.toThrow(/note.remaining_txs as u64 > 0/);
});
Expand Down
Loading

0 comments on commit 0a7985b

Please sign in to comment.