-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pay fee when deploying schnorr account
- Loading branch information
Showing
16 changed files
with
367 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copied from noir-contracts/contracts/slow_tree_contract/src/capsule.nr | ||
// We should extract this to a shared lib in aztec-nr once we settle on a design for capsules | ||
|
||
#[oracle(popCapsule)] | ||
fn pop_capsule_oracle<N>() -> [Field; N] {} | ||
|
||
// A capsule is a "blob" of data that is passed to the contract through an oracle. | ||
unconstrained pub fn pop_capsule<N>() -> [Field; N] { | ||
pop_capsule_oracle() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ mod account; | |
mod auth_witness; | ||
mod auth; | ||
mod entrypoint; | ||
mod capsule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
yarn-project/aztec.js/src/contract/deploy_account_method.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { PackedArguments, TxExecutionRequest } from '@aztec/circuit-types'; | ||
import { type AztecAddress, type PublicKey, TxContext } from '@aztec/circuits.js'; | ||
|
||
import { type AuthWitnessProvider } from '../account/interface.js'; | ||
import { type Wallet } from '../account/wallet.js'; | ||
import { type ContractArtifact, type FunctionArtifact } from '../api/abi.js'; | ||
import { EntrypointPayload } from '../entrypoint/payload.js'; | ||
import { type Contract } from './contract.js'; | ||
import { type ContractBase } from './contract_base.js'; | ||
import { DeployMethod, type DeployOptions } from './deploy_method.js'; | ||
|
||
/** | ||
* Contract interaction for deployment. Handles class registration, public instance deployment, | ||
* and initialization of the contract. Extends the BaseContractInteraction class. | ||
*/ | ||
export class DeployAccountMethod<TContract extends ContractBase = Contract> extends DeployMethod<TContract> { | ||
constructor( | ||
private authWitnessProvider: AuthWitnessProvider, | ||
publicKey: PublicKey, | ||
wallet: Wallet, | ||
artifact: ContractArtifact, | ||
postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>, | ||
args: any[] = [], | ||
constructorNameOrArtifact?: string | FunctionArtifact, | ||
) { | ||
super(publicKey, wallet, artifact, postDeployCtor, args, constructorNameOrArtifact); | ||
} | ||
|
||
/** | ||
* Creates a TxExecutionRequest for deploying the contract. | ||
* @param options - Prepares the contract for deployment by calling the request method and creating a TxExecutionRequest. | ||
* @returns The TxExecutionRequest for deploying the contract. | ||
*/ | ||
public async create(options: DeployOptions = {}): Promise<TxExecutionRequest> { | ||
if (this.txRequest) { | ||
return this.txRequest; | ||
} | ||
|
||
const calls = await this.request(options); | ||
if (calls.length === 0) { | ||
throw new Error(`No function calls needed to deploy contract`); | ||
} | ||
const feePayload = await EntrypointPayload.fromFeeOptions(options.fee); | ||
const feeAuthWit = await this.authWitnessProvider.createAuthWit(feePayload.hash()); | ||
await this.pxe.addCapsule(feePayload.toFields()); | ||
|
||
const execution = calls[0]; | ||
const packedArguments = PackedArguments.fromArgs(execution.args); | ||
|
||
const { chainId, protocolVersion } = await this.wallet.getNodeInfo(); | ||
const txContext = TxContext.empty(chainId, protocolVersion); | ||
this.txRequest = new TxExecutionRequest( | ||
execution.to, | ||
execution.functionData, | ||
packedArguments.hash, | ||
txContext, | ||
[packedArguments, ...feePayload.packedArguments], | ||
[feeAuthWit], | ||
); | ||
|
||
await this.pxe.registerContract({ artifact: this.artifact, instance: this.getInstance() }); | ||
|
||
return this.txRequest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.