-
Notifications
You must be signed in to change notification settings - Fork 236
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 initializing account contracts
- Loading branch information
Showing
33 changed files
with
834 additions
and
262 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
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
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
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
71 changes: 71 additions & 0 deletions
71
yarn-project/aztec.js/src/account_manager/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,71 @@ | ||
import { type PublicKey } from '@aztec/circuit-types'; | ||
import { FunctionData } from '@aztec/circuits.js'; | ||
import { | ||
type ContractArtifact, | ||
type FunctionArtifact, | ||
encodeArguments, | ||
getFunctionArtifact, | ||
} from '@aztec/foundation/abi'; | ||
|
||
import { type AuthWitnessProvider } from '../account/interface.js'; | ||
import { type Wallet } from '../account/wallet.js'; | ||
import { type ExecutionRequestInit } from '../api/entrypoint.js'; | ||
import { Contract } from '../contract/contract.js'; | ||
import { DeployMethod, type DeployOptions } from '../contract/deploy_method.js'; | ||
import { EntrypointPayload } from '../entrypoint/payload.js'; | ||
|
||
/** | ||
* Contract interaction for deploying an account contract. Handles fee preparation and contract initialization. | ||
*/ | ||
export class DeployAccountMethod extends DeployMethod { | ||
#authWitnessProvider: AuthWitnessProvider; | ||
#feePaymentArtifact: FunctionArtifact | undefined; | ||
|
||
constructor( | ||
authWitnessProvider: AuthWitnessProvider, | ||
publicKey: PublicKey, | ||
wallet: Wallet, | ||
artifact: ContractArtifact, | ||
args: any[] = [], | ||
constructorNameOrArtifact?: string | FunctionArtifact, | ||
feePaymentNameOrArtifact?: string | FunctionArtifact, | ||
) { | ||
super( | ||
publicKey, | ||
wallet, | ||
artifact, | ||
(address, wallet) => Contract.at(address, artifact, wallet), | ||
args, | ||
constructorNameOrArtifact, | ||
); | ||
|
||
this.#authWitnessProvider = authWitnessProvider; | ||
this.#feePaymentArtifact = | ||
typeof feePaymentNameOrArtifact === 'string' | ||
? getFunctionArtifact(artifact, feePaymentNameOrArtifact) | ||
: feePaymentNameOrArtifact; | ||
} | ||
|
||
protected async getInitializeFunctionCalls(options: DeployOptions): Promise<ExecutionRequestInit> { | ||
const exec = await super.getInitializeFunctionCalls(options); | ||
|
||
if (options.fee && this.#feePaymentArtifact) { | ||
const { address } = this.getInstance(); | ||
const feePayload = await EntrypointPayload.fromFeeOptions(options?.fee); | ||
|
||
exec.calls.push({ | ||
to: address, | ||
args: encodeArguments(this.#feePaymentArtifact, [feePayload]), | ||
functionData: FunctionData.fromAbi(this.#feePaymentArtifact), | ||
}); | ||
|
||
exec.authWitnesses ??= []; | ||
exec.packedArguments ??= []; | ||
|
||
exec.authWitnesses.push(await this.#authWitnessProvider.createAuthWit(feePayload.hash())); | ||
exec.packedArguments.push(...feePayload.packedArguments); | ||
} | ||
|
||
return exec; | ||
} | ||
} |
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.