Skip to content

Commit

Permalink
Fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbogle committed Apr 10, 2022
1 parent 30f0469 commit c78c10e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/idl/cardinal_generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type CardinalMetadataGenerator = {
export type CardinalGenerator = {
version: "0.1.0";
name: "cardinal_metadata_generator";
name: "cardinal_generator";
instructions: [
{
name: "createMetadataConfig";
Expand Down Expand Up @@ -104,9 +104,9 @@ export type CardinalMetadataGenerator = {
];
};

export const IDL: CardinalMetadataGenerator = {
export const IDL: CardinalGenerator = {
version: "0.1.0",
name: "cardinal_metadata_generator",
name: "cardinal_generator",
instructions: [
{
name: "createMetadataConfig",
Expand Down
18 changes: 6 additions & 12 deletions src/programs/metadataGenerator/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import type { AccountData } from "@cardinal/common";
import { Program, Provider } from "@project-serum/anchor";
import type * as web3 from "@solana/web3.js";

import type {
METADATA_GENERATOR_PROGRAM,
MetadataConfigData,
} from "./constants";
import {
METADATA_GENERATOR_ADDRESS,
METADATA_GENERATOR_IDL,
} from "./constants";
import type { GENERATOR_PROGRAM, MetadataConfigData } from "./constants";
import { GENERATOR_ADDRESS, GENERATOR_IDL } from "./constants";

export const getMetadataConfig = async (
connection: web3.Connection,
Expand All @@ -18,13 +12,13 @@ export const getMetadataConfig = async (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const provider = new Provider(connection, null, {});
const metadataGeneratorProgram = new Program<METADATA_GENERATOR_PROGRAM>(
METADATA_GENERATOR_IDL,
METADATA_GENERATOR_ADDRESS,
const generatorProgram = new Program<GENERATOR_PROGRAM>(
GENERATOR_IDL,
GENERATOR_ADDRESS,
provider
);

const parsed = (await metadataGeneratorProgram.account.metadataConfig.fetch(
const parsed = (await generatorProgram.account.metadataConfig.fetch(
metadataConfigId
)) as MetadataConfigData;
return {
Expand Down
11 changes: 5 additions & 6 deletions src/programs/metadataGenerator/constants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import type { AnchorTypes } from "@saberhq/anchor-contrib";
import { PublicKey } from "@solana/web3.js";

import * as METADATA_GENERATOR_TYPES from "../../idl/cardinal_generator";
import * as GENERATOR_TYPES from "../../idl/cardinal_generator";

export const METADATA_GENERATOR_ADDRESS = new PublicKey(
export const GENERATOR_ADDRESS = new PublicKey(
"genSsTXZaAGH1kRUe74TXzwuernqZhJksHvpXiAxBQT"
);

export const METADATA_CONFIG_SEED = "metadata-config";

export type METADATA_GENERATOR_PROGRAM =
METADATA_GENERATOR_TYPES.CardinalMetadataGenerator;
export type GENERATOR_PROGRAM = GENERATOR_TYPES.CardinalGenerator;

export const METADATA_GENERATOR_IDL = METADATA_GENERATOR_TYPES.IDL;
export const GENERATOR_IDL = GENERATOR_TYPES.IDL;

export type RewardDistributorTypes = AnchorTypes<METADATA_GENERATOR_PROGRAM>;
export type RewardDistributorTypes = AnchorTypes<GENERATOR_PROGRAM>;

type Accounts = RewardDistributorTypes["Accounts"];
export type MetadataConfigData = Accounts["metadataConfig"];
Expand Down
15 changes: 6 additions & 9 deletions src/programs/metadataGenerator/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import type {
} from "@solana/web3.js";
import { SystemProgram } from "@solana/web3.js";

import type { AttributeConfig, METADATA_GENERATOR_PROGRAM } from "./constants";
import {
METADATA_GENERATOR_ADDRESS,
METADATA_GENERATOR_IDL,
} from "./constants";
import type { AttributeConfig, GENERATOR_PROGRAM } from "./constants";
import { GENERATOR_ADDRESS, GENERATOR_IDL } from "./constants";
import { findMetadatConfigId } from "./pda";

export const createMetadataConfig = async (
Expand All @@ -23,16 +20,16 @@ export const createMetadataConfig = async (
attributes: AttributeConfig[]
): Promise<TransactionInstruction> => {
const provider = new Provider(connection, wallet, {});
const metadataGeneratorProgram = new Program<METADATA_GENERATOR_PROGRAM>(
METADATA_GENERATOR_IDL,
METADATA_GENERATOR_ADDRESS,
const generatorProgram = new Program<GENERATOR_PROGRAM>(
GENERATOR_IDL,
GENERATOR_ADDRESS,
provider
);
const [[metadataConfigId], mintMetadataId] = await Promise.all([
findMetadatConfigId(configName),
Metadata.getPDA(mint),
]);
return metadataGeneratorProgram.instruction.createMetadataConfig(
return generatorProgram.instruction.createMetadataConfig(
{ seedString: configName, attributes: attributes },
{
accounts: {
Expand Down
5 changes: 3 additions & 2 deletions src/programs/metadataGenerator/pda.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { utils } from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";

import { METADATA_CONFIG_SEED, METADATA_GENERATOR_ADDRESS } from ".";
import { GENERATOR_ADDRESS, METADATA_CONFIG_SEED } from ".";

/**
* Finds the metadata config id.
Expand All @@ -15,6 +15,7 @@ export const findMetadatConfigId = async (
utils.bytes.utf8.encode(METADATA_CONFIG_SEED),
utils.bytes.utf8.encode(configName),
],
METADATA_GENERATOR_ADDRESS
GENERATOR_ADDRESS
);
};
s;

0 comments on commit c78c10e

Please sign in to comment.