Merge pull request #30 from metaplex-foundation/feature/init-store
Init store
This commit is contained in:
commit
4903342e57
|
@ -64,25 +64,23 @@ export const PROGRAM_IDS = [
|
|||
];
|
||||
|
||||
const getStoreID = async () => {
|
||||
console.log(`STORE_OWNER_ADDRESS: ${STORE_OWNER_ADDRESS}`);
|
||||
console.log(`STORE_OWNER_ADDRESS: ${STORE_OWNER_ADDRESS?.toBase58()}`);
|
||||
if (!STORE_OWNER_ADDRESS) {
|
||||
return DEFAULT_STORE;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!STORE) {
|
||||
STORE = (
|
||||
await PublicKey.findProgramAddress(
|
||||
[
|
||||
Buffer.from('metaplex'),
|
||||
METAPLEX_ID.toBuffer(),
|
||||
STORE_OWNER_ADDRESS.toBuffer(),
|
||||
],
|
||||
METAPLEX_ID,
|
||||
)
|
||||
)[0];
|
||||
}
|
||||
const programs = await PublicKey.findProgramAddress(
|
||||
[
|
||||
Buffer.from('metaplex'),
|
||||
METAPLEX_ID.toBuffer(),
|
||||
STORE_OWNER_ADDRESS.toBuffer(),
|
||||
],
|
||||
METAPLEX_ID,
|
||||
);
|
||||
const CUSTOM = programs[0];
|
||||
console.log(`CUSTOM STORE: ${CUSTOM.toBase58()}`);
|
||||
|
||||
return STORE;
|
||||
return CUSTOM;
|
||||
};
|
||||
|
||||
export const setProgramIds = async (envName: string) => {
|
||||
|
@ -91,14 +89,12 @@ export const setProgramIds = async (envName: string) => {
|
|||
return;
|
||||
}
|
||||
|
||||
STORE = await getStoreID();
|
||||
if (!STORE) {
|
||||
STORE = await getStoreID();
|
||||
}
|
||||
};
|
||||
|
||||
const DEFAULT_STORE = new PublicKey(
|
||||
'7KwpjEy7KBpZTBErE3niBUNxWGAQTPo9kZzkgEoP6dfR',
|
||||
);
|
||||
|
||||
let STORE: PublicKey;
|
||||
let STORE: PublicKey | undefined;
|
||||
|
||||
export const programIds = () => {
|
||||
return {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
REACT_APP_STORE_OWNER_ADDRESS_ADDRESS=
|
|
@ -1 +1 @@
|
|||
GENERATE_SOURCEMAP = false
|
||||
GENERATE_SOURCEMAP=false
|
||||
|
|
|
@ -3,7 +3,6 @@ const CracoAlias = require('craco-alias');
|
|||
const CracoBabelLoader = require('craco-babel-loader');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
//console.log('qualified', pnp.resolveRequest('@babel/preset-typescript'), path.resolve(__dirname, '/') + 'src/');
|
||||
|
||||
// Handle relative paths to sibling packages
|
||||
|
|
|
@ -438,6 +438,11 @@ async function setupAuctionManagerInstructions(
|
|||
signers: Keypair[];
|
||||
auctionManager: PublicKey;
|
||||
}> {
|
||||
let store = programIds().store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
let signers: Keypair[] = [];
|
||||
let instructions: TransactionInstruction[] = [];
|
||||
|
||||
|
@ -457,7 +462,7 @@ async function setupAuctionManagerInstructions(
|
|||
wallet.publicKey,
|
||||
wallet.publicKey,
|
||||
acceptPayment,
|
||||
programIds().store,
|
||||
store,
|
||||
settings,
|
||||
instructions,
|
||||
);
|
||||
|
@ -492,6 +497,11 @@ async function validateParticipationHelper(
|
|||
participationSafetyDepositDraft: SafetyDepositDraft,
|
||||
accountRentExempt: number,
|
||||
): Promise<{ instructions: TransactionInstruction[]; signers: Keypair[] }> {
|
||||
const store = programIds().store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
let instructions: TransactionInstruction[] = [];
|
||||
let signers: Keypair[] = [];
|
||||
const whitelistedCreator = participationSafetyDepositDraft.metadata.info.data
|
||||
|
@ -521,7 +531,7 @@ async function validateParticipationHelper(
|
|||
printingTokenHoldingAccount,
|
||||
wallet.publicKey,
|
||||
whitelistedCreator,
|
||||
programIds().store,
|
||||
store,
|
||||
await getSafetyDepositBoxAddress(
|
||||
vault,
|
||||
participationSafetyDepositDraft.masterEdition.info
|
||||
|
@ -568,6 +578,11 @@ async function validateBoxes(
|
|||
instructions: TransactionInstruction[][];
|
||||
signers: Keypair[][];
|
||||
}> {
|
||||
const store = programIds().store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
let signers: Keypair[][] = [];
|
||||
let instructions: TransactionInstruction[][] = [];
|
||||
|
||||
|
@ -628,7 +643,7 @@ async function validateBoxes(
|
|||
tokenInstructions,
|
||||
edition,
|
||||
whitelistedCreator,
|
||||
programIds().store,
|
||||
store,
|
||||
safetyDeposits[i].draft.masterEdition?.info.printingMint,
|
||||
safetyDeposits[i].draft.masterEdition ? wallet.publicKey : undefined,
|
||||
);
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, { useMemo } from 'react';
|
|||
import './index.less';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Button, Dropdown, Menu } from 'antd';
|
||||
import { ConnectButton, CurrentUserBadge, useWallet } from '@oyster/common';
|
||||
import { ConnectButton, CurrentUserBadge, useConnection, useWallet } from '@oyster/common';
|
||||
import { Notifications } from '../Notifications';
|
||||
import useWindowDimensions from '../../utils/layout';
|
||||
import { MenuOutlined } from '@ant-design/icons';
|
||||
|
|
|
@ -207,7 +207,7 @@ export function MetaProvider({ children = null as any }) {
|
|||
auctions: {},
|
||||
vaults: {},
|
||||
payoutTickets: {},
|
||||
store: {},
|
||||
store: undefined,
|
||||
whitelistedCreatorsByCreator: {},
|
||||
bidderMetadataByAuctionAndBidder: {},
|
||||
bidderPotsByAuctionAndBidder: {},
|
||||
|
@ -295,7 +295,9 @@ export function MetaProvider({ children = null as any }) {
|
|||
setAuctionManagersByAuction(tempCache.auctionManagersByAuction);
|
||||
setBidRedemptions(tempCache.bidRedemptions);
|
||||
setPayoutTickets(tempCache.payoutTickets);
|
||||
setStore(tempCache.store as any);
|
||||
if (tempCache.store) {
|
||||
setStore(tempCache.store as any);
|
||||
}
|
||||
setWhitelistedCreatorsByCreator(tempCache.whitelistedCreatorsByCreator);
|
||||
setIsLoading(false);
|
||||
|
||||
|
@ -645,7 +647,7 @@ const processMetaplexAccounts = async (
|
|||
if (a.account.owner.toBase58() != programIds().metaplex.toBase58()) return;
|
||||
|
||||
try {
|
||||
const STORE_ID = programIds().store.toBase58();
|
||||
const STORE_ID = programIds().store?.toBase58() || '';
|
||||
|
||||
if (
|
||||
a.account.data[0] === MetaplexKey.AuctionManagerV1 ||
|
||||
|
@ -692,7 +694,6 @@ const processMetaplexAccounts = async (
|
|||
}));
|
||||
} else if (a.account.data[0] === MetaplexKey.StoreV1) {
|
||||
const store = decodeStore(a.account.data);
|
||||
console.log('Found store', store);
|
||||
const account: ParsedAccount<Store> = {
|
||||
pubkey: a.pubkey,
|
||||
account: a.account,
|
||||
|
|
|
@ -17,6 +17,10 @@ export async function claimBid(
|
|||
instructions: TransactionInstruction[],
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const { auctionKey, auctionManagerKey } = await getAuctionKeys(vault);
|
||||
|
||||
|
@ -72,7 +76,7 @@ export async function claimBid(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -26,6 +26,10 @@ export async function emptyPaymentAccount(
|
|||
instructions: TransactionInstruction[],
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const value = new EmptyPaymentAccountArgs({
|
||||
winningConfigIndex,
|
||||
|
@ -83,7 +87,7 @@ export async function emptyPaymentAccount(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -690,12 +690,17 @@ export async function getOriginalAuthority(
|
|||
|
||||
export async function getWhitelistedCreator(creator: PublicKey) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
return (
|
||||
await PublicKey.findProgramAddress(
|
||||
[
|
||||
Buffer.from(METAPLEX_PREFIX),
|
||||
PROGRAM_IDS.metaplex.toBuffer(),
|
||||
PROGRAM_IDS.store.toBuffer(),
|
||||
store.toBuffer(),
|
||||
creator.toBuffer(),
|
||||
],
|
||||
PROGRAM_IDS.metaplex,
|
||||
|
|
|
@ -25,6 +25,10 @@ export async function populateParticipationPrintingAccount(
|
|||
instructions: TransactionInstruction[],
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const transferAuthority: PublicKey = (
|
||||
await PublicKey.findProgramAddress(
|
||||
|
@ -115,7 +119,7 @@ export async function populateParticipationPrintingAccount(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -23,6 +23,10 @@ export async function redeemBid(
|
|||
instructions: TransactionInstruction[],
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const { auctionKey, auctionManagerKey } = await getAuctionKeys(vault);
|
||||
|
||||
|
@ -116,7 +120,7 @@ export async function redeemBid(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -27,6 +27,10 @@ export async function redeemFullRightsTransferBid(
|
|||
newAuthority: PublicKey,
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const { auctionKey, auctionManagerKey } = await getAuctionKeys(vault);
|
||||
|
||||
|
@ -120,7 +124,7 @@ export async function redeemFullRightsTransferBid(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -30,6 +30,10 @@ export async function redeemParticipationBid(
|
|||
tokenPaymentAccount: PublicKey,
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const { auctionKey, auctionManagerKey } = await getAuctionKeys(vault);
|
||||
|
||||
|
@ -111,7 +115,7 @@ export async function redeemParticipationBid(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -15,13 +15,17 @@ export async function setStore(
|
|||
instructions: TransactionInstruction[],
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const value = new SetStoreArgs({ public: isPublic });
|
||||
const data = Buffer.from(serialize(SCHEMA, value));
|
||||
|
||||
const keys = [
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: true,
|
||||
},
|
||||
|
|
|
@ -16,6 +16,10 @@ export async function setWhitelistedCreator(
|
|||
instructions: TransactionInstruction[],
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const whitelistedCreatorPDAKey = await getWhitelistedCreator(creator);
|
||||
|
||||
|
@ -44,7 +48,7 @@ export async function setWhitelistedCreator(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,10 @@ export async function startAuction(
|
|||
instructions: TransactionInstruction[],
|
||||
) {
|
||||
const PROGRAM_IDS = programIds();
|
||||
const store = PROGRAM_IDS.store;
|
||||
if (!store) {
|
||||
throw new Error('Store not initialized');
|
||||
}
|
||||
|
||||
const { auctionKey, auctionManagerKey } = await getAuctionKeys(vault);
|
||||
|
||||
|
@ -37,7 +41,7 @@ export async function startAuction(
|
|||
isWritable: false,
|
||||
},
|
||||
{
|
||||
pubkey: PROGRAM_IDS.store,
|
||||
pubkey: store,
|
||||
isSigner: false,
|
||||
isWritable: false,
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from '@solana/web3.js';
|
||||
import { serialize } from 'borsh';
|
||||
|
||||
import { getAuctionKeys, SCHEMA, ValidateParticipationArgs } from '.';
|
||||
import { SCHEMA, ValidateParticipationArgs } from '.';
|
||||
|
||||
export async function validateParticipation(
|
||||
auctionManager: PublicKey,
|
||||
|
|
|
@ -117,11 +117,16 @@ function InnerAdminView({
|
|||
connection: Connection;
|
||||
wallet: WalletAdapter;
|
||||
}) {
|
||||
const [newStore, setNewStore] = useState(new Store(store.info));
|
||||
const [newStore, setNewStore] = useState(store && store.info && new Store(store.info));
|
||||
const [updatedCreators, setUpdatedCreators] = useState<
|
||||
Record<string, WhitelistedCreator>
|
||||
>({});
|
||||
|
||||
|
||||
if (!store || !newStore) {
|
||||
return <p>Store is not defined</p>;
|
||||
}
|
||||
|
||||
const uniqueCreators = Object.values(whitelistedCreatorsByCreator).reduce(
|
||||
(acc: Record<string, WhitelistedCreator>, e) => {
|
||||
acc[e.info.address.toBase58()] = e.info;
|
||||
|
|
|
@ -9,7 +9,6 @@ import {
|
|||
Statistic,
|
||||
Progress,
|
||||
Spin,
|
||||
InputNumber,
|
||||
Radio,
|
||||
Card,
|
||||
Select,
|
||||
|
@ -42,7 +41,6 @@ import {
|
|||
WinningConstraint,
|
||||
ParticipationConfig,
|
||||
WinningConfigItem,
|
||||
WinningConfigState,
|
||||
} from '../../models/metaplex';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
|
@ -59,7 +57,6 @@ import { PlusCircleOutlined } from '@ant-design/icons';
|
|||
|
||||
const { Option } = Select;
|
||||
const { Step } = Steps;
|
||||
const { TextArea } = Input;
|
||||
|
||||
export enum AuctionCategory {
|
||||
Limited,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useState, useMemo } from 'react';
|
||||
import { Layout, Row, Col, Tabs } from 'antd';
|
||||
import { Layout, Row, Col, Tabs, Button } from 'antd';
|
||||
import Masonry from 'react-masonry-css';
|
||||
|
||||
import { PreSaleBanner } from '../../components/PreSaleBanner';
|
||||
|
@ -7,10 +7,13 @@ import { AuctionViewState, useAuctions } from '../../hooks';
|
|||
|
||||
import './index.less';
|
||||
import { AuctionRenderCard } from '../../components/AuctionRenderCard';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Link, useHistory } from 'react-router-dom';
|
||||
import { CardLoader } from '../../components/MyLoader';
|
||||
import { useMeta } from '../../contexts';
|
||||
import BN from 'bn.js';
|
||||
import { programIds, useConnection, useWallet } from '@oyster/common';
|
||||
import { saveAdmin } from '../../actions/saveAdmin';
|
||||
import { WhitelistedCreator } from '../../models/metaplex';
|
||||
|
||||
const { TabPane } = Tabs;
|
||||
|
||||
|
@ -18,7 +21,11 @@ const { Content } = Layout;
|
|||
export const HomeView = () => {
|
||||
const auctions = useAuctions(AuctionViewState.Live);
|
||||
const auctionsEnded = useAuctions(AuctionViewState.Ended);
|
||||
const { isLoading } = useMeta();
|
||||
const { isLoading, store } = useMeta();
|
||||
const [isInitalizingStore, setIsInitalizingStore] = useState(false);
|
||||
const connection = useConnection();
|
||||
const history = useHistory();
|
||||
const { wallet, connect } = useWallet();
|
||||
const breakpointColumnsObj = {
|
||||
default: 4,
|
||||
1100: 3,
|
||||
|
@ -87,8 +94,34 @@ export const HomeView = () => {
|
|||
</Masonry>
|
||||
);
|
||||
|
||||
const CURRENT_STORE = programIds().store;
|
||||
|
||||
return (
|
||||
<Layout style={{ margin: 0, marginTop: 30 }}>
|
||||
<Layout style={{ margin: 0, marginTop: 30, alignItems: 'center' }}>
|
||||
{!store && !isLoading && <>
|
||||
{!CURRENT_STORE && <p>Store has not been configured please set <em>REACT_APP_STORE_OWNER_ADDRESS_ADDRESS</em> to admin wallet inside <em>packages/web/.env</em> and restart yarn</p>}
|
||||
{CURRENT_STORE && !wallet?.publicKey && <p><Button type="primary" className="app-btn" onClick={connect}>Connect</Button> to configure store.</p>}
|
||||
{CURRENT_STORE && wallet?.publicKey && <>
|
||||
<p>Initializing store will allow you to control list of creators.</p>
|
||||
|
||||
<Button className="app-btn" type="primary" loading={isInitalizingStore} disabled={!CURRENT_STORE} onClick={async () => {
|
||||
if(!wallet?.publicKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsInitalizingStore(true);
|
||||
|
||||
await saveAdmin(connection, wallet, false, [new WhitelistedCreator({
|
||||
address: wallet?.publicKey,
|
||||
activated: true,
|
||||
})]);
|
||||
|
||||
history.push('/admin');
|
||||
|
||||
window.location.reload();
|
||||
}}>Init Store</Button>
|
||||
</>}
|
||||
</>}
|
||||
<PreSaleBanner auction={heroAuction} />
|
||||
<Layout>
|
||||
<Content style={{ display: 'flex', flexWrap: 'wrap' }}>
|
||||
|
|
Loading…
Reference in New Issue