-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathdeploy_contract.ts
More file actions
146 lines (125 loc) Β· 6.67 KB
/
deploy_contract.ts
File metadata and controls
146 lines (125 loc) Β· 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import { PodRacingContract } from "../src/artifacts/PodRacing.js"
import { type Logger, createLogger } from "@aztec/foundation/log";
import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee";
import { setupWallet } from "../src/utils/setup_wallet.js";
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
import { SponsoredFPCContractArtifact } from "@aztec/noir-contracts.js/SponsoredFPC";
import { deploySchnorrAccount } from "../src/utils/deploy_account.js";
import { getTimeouts, getAztecScanConfig } from "../config/config.js";
import { verifyArtifactOnAztecScan, verifyInstanceOnAztecScan } from "../src/utils/verify_on_aztecscan.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
async function main() {
let logger: Logger;
logger = createLogger('aztec:aztec-starter');
logger.info(`π Starting contract deployment process...`);
const timeouts = getTimeouts();
// Setup wallet
logger.info('π‘ Setting up wallet...');
const wallet = await setupWallet();
logger.info(`π Wallet set up successfully`);
// Setup sponsored FPC
logger.info('π° Setting up sponsored fee payment contract...');
const sponsoredFPC = await getSponsoredFPCInstance();
logger.info(`π° Sponsored FPC instance obtained at: ${sponsoredFPC.address}`);
logger.info('π Registering sponsored FPC contract with wallet...');
await wallet.registerContract(sponsoredFPC, SponsoredFPCContractArtifact);
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address);
logger.info('β
Sponsored fee payment method configured');
// Deploy account
logger.info('π€ Deploying Schnorr account...');
let accountManager = await deploySchnorrAccount(wallet);
const address = accountManager.address;
logger.info(`β
Account deployed successfully at: ${address}`);
// Deploy pod racing contract
logger.info('ποΈ Starting pod racing contract deployment...');
logger.info(`π Admin address for pod racing contract: ${address}`);
logger.info('β³ Waiting for deployment transaction to be mined...');
const { contract: podRacingContract, instance } = await PodRacingContract.deploy(wallet, address).send({
from: address,
fee: { paymentMethod: sponsoredPaymentMethod },
wait: { timeout: timeouts.deployTimeout, returnReceipt: true }
});
logger.info(`π Pod Racing Contract deployed successfully!`);
logger.info(`π Contract address: ${podRacingContract.address}`);
logger.info(`π€ Admin address: ${address}`);
// Log contract instantiation data
if (instance) {
logger.info('π¦ Contract instantiation data:');
logger.info(`Salt: ${instance.salt}`);
logger.info(`Deployer: ${instance.deployer}`);
if (instance.publicKeys) {
logger.info(`Public Keys - Master Nullifier: ${instance.publicKeys.masterNullifierPublicKey}`);
logger.info(`Public Keys - Master Incoming Viewing: ${instance.publicKeys.masterIncomingViewingPublicKey}`);
logger.info(`Public Keys - Master Outgoing Viewing: ${instance.publicKeys.masterOutgoingViewingPublicKey}`);
logger.info(`Public Keys - Master Tagging: ${instance.publicKeys.masterTaggingPublicKey}`);
}
logger.info(`Constructor args: ${JSON.stringify([address.toString()])}`);
}
// Verify on AztecScan (best-effort β deploy succeeds regardless)
const aztecscanConfig = getAztecScanConfig();
if (aztecscanConfig && instance) {
logger.info('π Verifying contract on AztecScan...');
const contractClassId = instance.currentContractClassId.toString();
const publicKeysString = instance.publicKeys
? instance.publicKeys.toString()
: "0x" + "0".repeat(512);
const constructorArgs = [address.toString()];
// Load the raw JSON artifact (Noir compiler output) β NOT the codegen'd
// ContractArtifact. The server expects the original JSON with base64 bytecode
// strings, snake_case keys, etc. The codegen'd artifact has Buffer objects,
// camelCase keys, and transformed function structure that the server can't parse.
const rawArtifactPath = join(__dirname, "../target/pod_racing_contract-PodRacing.json");
const rawArtifact = JSON.parse(readFileSync(rawArtifactPath, "utf8"));
try {
// Wait for the AztecScan indexer to pick up the on-chain data
logger.info('β³ Waiting 15s for AztecScan indexer...');
await new Promise(resolve => setTimeout(resolve, 15_000));
// 1. Verify artifact (contract class)
const artifactResult = await verifyArtifactOnAztecScan(
aztecscanConfig,
contractClassId,
1,
rawArtifact,
);
logger.info(`π Artifact verification: ${artifactResult.status} ${artifactResult.statusText}`);
// 2. Verify instance (deployment)
const instanceResult = await verifyInstanceOnAztecScan(
aztecscanConfig,
podRacingContract.address.toString(),
{
publicKeysString,
deployer: instance.deployer.toString(),
salt: instance.salt.toString(),
constructorArgs,
},
rawArtifact,
);
logger.info(`π Instance verification: ${instanceResult.status} ${instanceResult.statusText}`);
if (artifactResult.ok && instanceResult.ok) {
logger.info('β
Contract verified on AztecScan');
} else {
logger.warn('β οΈ AztecScan verification returned non-OK status (contract still deployed successfully)');
}
} catch (err) {
logger.warn(`β οΈ AztecScan verification failed (contract still deployed successfully): ${err}`);
}
} else if (!aztecscanConfig) {
logger.info('βΉοΈ AztecScan not configured for this environment, skipping verification');
}
logger.info('π Deployment process completed successfully!');
logger.info(`π Summary:`);
logger.info(` - Contract Address: ${podRacingContract.address}`);
logger.info(` - Admin Address: ${address}`);
logger.info(` - Sponsored FPC: ${sponsoredFPC.address}`);
}
main()
.then(() => process.exit(0))
.catch((error) => {
const logger = createLogger('aztec:aztec-starter');
logger.error(`β Deployment failed: ${error.message}`);
logger.error(`π Error details: ${error.stack}`);
process.exit(1);
});