Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into metaplex-foundation-master
  • Loading branch information
KermitSwap committed Jun 15, 2021
2 parents 5a5fa38 + 377f6cd commit fd29171
Show file tree
Hide file tree
Showing 125 changed files with 27,219 additions and 218 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Metaplex is a protocol built on top of Solana that allows:

Metaplex is comprised of two core components: an on-chain program, and a self-hosted front-end web2 application.

## In Depth Developer's Guide

If you want to deep dive on the Architecture, you can do so here:

https://www.notion.so/Metaplex-Developer-Guide-afefbc19841744c28587ab948a08cfac

## Installing

Clone the repo, and run `deploy-web.sh`.
Expand All @@ -20,6 +26,7 @@ Clone the repo, and run `deploy-web.sh`.
$ git clone https://github.com/metaplex-foundation/metaplex.git
$ cd metaplex
$ cd js
$ yarn install
$ ./deploy-web.sh
```

Expand Down
27 changes: 18 additions & 9 deletions js/packages/common/src/actions/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,24 @@ export enum PriceFloorType {
}
export class PriceFloor {
type: PriceFloorType;
// It's an array of 32 u8s, when minimum, only first 4 are used (a u64), when blinded price, the entire
// It's an array of 32 u8s, when minimum, only first 8 are used (a u64), when blinded price, the entire
// thing is a hash and not actually a public key, and none is all zeroes
hash: PublicKey;
hash: Uint8Array;

constructor(args: { type: PriceFloorType; hash: PublicKey }) {
minPrice?: BN;

constructor(args: {
type: PriceFloorType;
hash?: Uint8Array;
minPrice?: BN;
}) {
this.type = args.type;
this.hash = args.hash;
this.hash = args.hash || new Uint8Array(32);
if (this.type === PriceFloorType.Minimum) {
if (args.minPrice) {
this.hash.set(args.minPrice.toArrayLike(Buffer, 'le', 8), 0);
}
}
}
}

Expand Down Expand Up @@ -463,7 +474,7 @@ export const AUCTION_SCHEMA = new Map<any, any>([
kind: 'struct',
fields: [
['type', 'u8'],
['hash', 'pubkey'],
['hash', [32]],
],
},
],
Expand Down Expand Up @@ -528,6 +539,7 @@ export async function createAuction(
resource: PublicKey,
endAuctionAt: BN | null,
auctionGap: BN | null,
priceFloor: PriceFloor,
tokenMint: PublicKey,
authority: PublicKey,
creator: PublicKey,
Expand All @@ -545,10 +557,7 @@ export async function createAuction(
auctionGap,
tokenMint,
authority,
priceFloor: new PriceFloor({
type: PriceFloorType.None,
hash: SystemProgram.programId,
}),
priceFloor,
}),
),
);
Expand Down
13 changes: 7 additions & 6 deletions js/packages/common/src/contexts/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useLocation } from "react-router";
import { MetaplexModal } from "../components/MetaplexModal";

import './wallet.css'
import { TorusWalletAdapter } from "../wallet-adapters/torus";


const ASSETS_URL = 'https://raw.githubusercontent.com/solana-labs/oyster/main/assets/wallets/';
Expand All @@ -31,12 +32,12 @@ export const WALLET_PROVIDERS = [
url: "https://mathwallet.org",
icon: `${ASSETS_URL}mathwallet.svg`,
},
// {
// name: 'Torus',
// url: 'https://tor.us',
// icon: `${ASSETS_URL}torus.svg`,
// adapter: TorusWalletAdapter,
// }
{
name: 'Torus',
url: 'https://tor.us',
icon: `${ASSETS_URL}torus.svg`,
adapter: TorusWalletAdapter,
}
];

const WalletContext = React.createContext<{
Expand Down
40 changes: 18 additions & 22 deletions js/packages/common/src/utils/ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

return STORE;
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 CUSTOM;
};

export const setProgramIds = async (envName: string) => {
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion js/packages/common/src/wallet-adapters/torus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
}

console.log(this.account?.publicKey.toBase58());

this.name = this._provider?.state.store.get('name');;
this.image = this._provider?.state.store.get('profileImage');;

Expand Down
1 change: 1 addition & 0 deletions js/packages/web/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_STORE_OWNER_ADDRESS_ADDRESS=
2 changes: 1 addition & 1 deletion js/packages/web/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GENERATE_SOURCEMAP = false
GENERATE_SOURCEMAP=false
1 change: 0 additions & 1 deletion js/packages/web/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions js/packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"@oyster/common": "0.0.1",
"@project-serum/serum": "^0.13.34",
"@project-serum/sol-wallet-adapter": "^0.2.0",
"@solana/spl-name-service": "0.1.1",
"@solana/spl-name-service": "0.1.2",
"@solana/spl-token": "0.1.4",
"@solana/spl-token-registry": "^0.2.77",
"@solana/spl-token-registry": "^0.2.131",
"@solana/spl-token-swap": "0.1.0",
"@solana/wallet-base": "0.0.1",
"@solana/wallet-ledger": "0.0.1",
"@solana/web3.js": "^1.10.0",
"@toruslabs/openlogin": "0.8.5",
"@toruslabs/openlogin-ed25519": "0.8.5",
"@toruslabs/openlogin-utils": "0.8.5",
"@toruslabs/openlogin": "0.9.0",
"@toruslabs/openlogin-ed25519": "0.9.0",
"@toruslabs/openlogin-utils": "0.9.0",
"@welldone-software/why-did-you-render": "^6.0.5",
"bn.js": "^5.1.3",
"borsh": "^0.4.0",
Expand All @@ -44,7 +44,7 @@
"test": "craco test",
"eject": "react-scripts eject",
"deploy:ar": "arweave deploy-dir ../../build/web --key-file ",
"deploy": "gh-pages -d ../../build/web --repo https://github.com/solana-labs/oyster-meta",
"deploy": "gh-pages -d ../../build/web --repo https://github.com/metaplex-foundation/metaplex",
"format:fix": "prettier --write \"**/*.+(js|jsx|ts|tsx|json|css|md)\""
},
"eslintConfig": {
Expand All @@ -64,7 +64,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/solana-labs/oyster"
"url": "https://github.com/metaplex-foundation/metaplex"
},
"homepage": ".",
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions js/packages/web/src/App.less
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ code {
}
}

.ant-image-img {
border-radius: 8px;
}

.ant-card-cover {
position: relative;
overflow: hidden;
Expand Down
24 changes: 21 additions & 3 deletions js/packages/web/src/actions/createAuctionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getSafetyDepositBoxAddress,
createAssociatedTokenAccountInstruction,
sendTransactionWithRetry,
PriceFloor,
} from '@oyster/common';

import { AccountLayout, Token } from '@solana/spl-token';
Expand Down Expand Up @@ -104,6 +105,7 @@ export async function createAuctionManager(
safetyDepositDrafts: SafetyDepositDraft[],
participationSafetyDepositDraft: SafetyDepositDraft | undefined,
paymentMint: PublicKey,
priceFloor: PriceFloor,
): Promise<{
vault: PublicKey;
auction: PublicKey;
Expand Down Expand Up @@ -140,6 +142,7 @@ export async function createAuctionManager(
endAuctionAt,
auctionGap,
paymentMint,
priceFloor,
);

let safetyDepositConfigsWithPotentiallyUnsetTokens =
Expand Down Expand Up @@ -438,6 +441,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[] = [];

Expand All @@ -457,7 +465,7 @@ async function setupAuctionManagerInstructions(
wallet.publicKey,
wallet.publicKey,
acceptPayment,
programIds().store,
store,
settings,
instructions,
);
Expand Down Expand Up @@ -492,6 +500,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
Expand Down Expand Up @@ -521,7 +534,7 @@ async function validateParticipationHelper(
printingTokenHoldingAccount,
wallet.publicKey,
whitelistedCreator,
programIds().store,
store,
await getSafetyDepositBoxAddress(
vault,
participationSafetyDepositDraft.masterEdition.info
Expand Down Expand Up @@ -568,6 +581,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[][] = [];

Expand Down Expand Up @@ -628,7 +646,7 @@ async function validateBoxes(
tokenInstructions,
edition,
whitelistedCreator,
programIds().store,
store,
safetyDeposits[i].draft.masterEdition?.info.printingMint,
safetyDeposits[i].draft.masterEdition ? wallet.publicKey : undefined,
);
Expand Down
4 changes: 3 additions & 1 deletion js/packages/web/src/actions/makeAuction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
import { utils, actions, WinnerLimit } from '@oyster/common';
import { utils, actions, WinnerLimit, PriceFloor } from '@oyster/common';

import BN from 'bn.js';
import { METAPLEX_PREFIX } from '../models/metaplex';
Expand All @@ -13,6 +13,7 @@ export async function makeAuction(
endAuctionAt: BN,
auctionGap: BN,
paymentMint: PublicKey,
priceFloor: PriceFloor,
): Promise<{
auction: PublicKey;
instructions: TransactionInstruction[];
Expand Down Expand Up @@ -45,6 +46,7 @@ export async function makeAuction(
vault,
endAuctionAt,
auctionGap,
priceFloor,
paymentMint,
auctionManagerKey,
wallet.publicKey,
Expand Down
2 changes: 1 addition & 1 deletion js/packages/web/src/actions/nft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const mintNFT = async (
const result: IArweaveResult = await (
await fetch(
// TODO: add CNAME
env === 'mainnet-beta'
env.startsWith('mainnet-beta')
? 'https://us-central1-principal-lane-200702.cloudfunctions.net/uploadFileProd-1'
: 'https://us-central1-principal-lane-200702.cloudfunctions.net/uploadFile-1',
{
Expand Down
2 changes: 1 addition & 1 deletion js/packages/web/src/components/AppBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading

0 comments on commit fd29171

Please sign in to comment.