Command to verify candymachine price (#397)

This commit is contained in:
grimAgent 2021-09-14 15:54:51 -04:00 committed by GitHub
parent e9841d4bb1
commit 756f58ecd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 6 deletions

View File

@ -144,6 +144,51 @@ programCommand('verify')
saveCache(cacheName, env, cacheContent);
});
programCommand('verify_price')
.option('-p, --price <string>')
.option('--cache-path <string>')
.action(async (directory, cmd) => {
const { keypair, env, price, cacheName, cachePath } = cmd.opts();
const lamports = parsePrice(price);
if (isNaN(lamports)) {
return log.error(`verify_price requires a --price to be set`);
}
log.info(`Expected price is: ${lamports}`);
const cacheContent = loadCache(cacheName, env, cachePath);
if (!cacheContent) {
return log.error(
`No cache found, can't continue. Make sure you are in the correct directory where the assets are located or use the --cache-path option.`,
);
}
const walletKeyPair = loadWalletKey(keypair);
const anchorProgram = await loadAnchorProgram(walletKeyPair, env);
const [candyMachine] = await getCandyMachineAddress(
new PublicKey(cacheContent.program.config),
cacheContent.program.uuid,
);
const machine = await anchorProgram.account.candyMachine.fetch(
candyMachine,
);
//@ts-ignore
const candyMachineLamports = machine.data.price.toNumber();
log.info(`Candymachine price is: ${candyMachineLamports}`);
if (lamports != candyMachineLamports) {
throw new Error(`Expected price and CandyMachine's price do not match!`);
}
log.info(`Good to go!`);
});
programCommand('create_candy_machine')
.option('-p, --price <string>', 'Price denominated in SOL or spl-token override', '1')
.option('-t, --spl-token <string>', 'SPL token used to price NFT mint. To use SOL leave this empty.')

View File

@ -2,17 +2,17 @@ import path from "path";
import { CACHE_PATH } from "./constants";
import fs from "fs";
export function cachePath(env: string, cacheName: string) {
return path.join(CACHE_PATH, `${env}-${cacheName}`);
export function cachePath(env: string, cacheName: string, cPath: string = CACHE_PATH) {
return path.join(cPath, `${env}-${cacheName}`);
}
export function loadCache(cacheName: string, env: string) {
const path = cachePath(env, cacheName);
export function loadCache(cacheName: string, env: string, cPath: string = CACHE_PATH) {
const path = cachePath(env, cacheName, cPath);
return fs.existsSync(path)
? JSON.parse(fs.readFileSync(path).toString())
: undefined;
}
export function saveCache(cacheName: string, env: string, cacheContent) {
fs.writeFileSync(cachePath(env, cacheName), JSON.stringify(cacheContent));
export function saveCache(cacheName: string, env: string, cacheContent, cPath: string = CACHE_PATH) {
fs.writeFileSync(cachePath(env, cacheName, cPath), JSON.stringify(cacheContent));
}