mirror of https://github.com/certusone/oyster.git
feat: metaplex
This commit is contained in:
parent
ccea274bfd
commit
113d17ca04
|
@ -27,7 +27,6 @@ function deserializeField(
|
||||||
fieldName: string,
|
fieldName: string,
|
||||||
fieldType: any,
|
fieldType: any,
|
||||||
reader: BinaryReader,
|
reader: BinaryReader,
|
||||||
optional: boolean,
|
|
||||||
): any {
|
): any {
|
||||||
try {
|
try {
|
||||||
if (typeof fieldType === 'string') {
|
if (typeof fieldType === 'string') {
|
||||||
|
@ -40,20 +39,14 @@ function deserializeField(
|
||||||
}
|
}
|
||||||
|
|
||||||
return reader.readArray(() =>
|
return reader.readArray(() =>
|
||||||
deserializeField(schema, fieldName, fieldType[0], reader, false),
|
deserializeField(schema, fieldName, fieldType[0], reader),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldType.kind === 'option') {
|
if (fieldType.kind === 'option') {
|
||||||
const option = reader.readU8();
|
const option = reader.readU8();
|
||||||
if (option) {
|
if (option) {
|
||||||
return deserializeField(
|
return deserializeField(schema, fieldName, fieldType.type, reader);
|
||||||
schema,
|
|
||||||
fieldName,
|
|
||||||
fieldType.type,
|
|
||||||
reader,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -86,7 +79,6 @@ function deserializeStruct(
|
||||||
fieldName,
|
fieldName,
|
||||||
fieldType,
|
fieldType,
|
||||||
reader,
|
reader,
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return new classType(result);
|
return new classType(result);
|
||||||
|
@ -98,13 +90,7 @@ function deserializeStruct(
|
||||||
throw new BorshError(`Enum index: ${idx} is out of range`);
|
throw new BorshError(`Enum index: ${idx} is out of range`);
|
||||||
}
|
}
|
||||||
const [fieldName, fieldType] = structSchema.values[idx];
|
const [fieldName, fieldType] = structSchema.values[idx];
|
||||||
const fieldValue = deserializeField(
|
const fieldValue = deserializeField(schema, fieldName, fieldType, reader);
|
||||||
schema,
|
|
||||||
fieldName,
|
|
||||||
fieldType,
|
|
||||||
reader,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
return new classType({ [fieldName]: fieldValue });
|
return new classType({ [fieldName]: fieldValue });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ export * from './redeemOpenEditionBid';
|
||||||
export * from './startAuction';
|
export * from './startAuction';
|
||||||
export * from './validateSafetyDepositBox';
|
export * from './validateSafetyDepositBox';
|
||||||
export class AuctionManager {
|
export class AuctionManager {
|
||||||
key?: number;
|
key: number = 0;
|
||||||
authority?: PublicKey;
|
authority?: PublicKey;
|
||||||
auction?: PublicKey;
|
auction?: PublicKey;
|
||||||
vault?: PublicKey;
|
vault?: PublicKey;
|
||||||
|
@ -20,6 +20,10 @@ export class AuctionManager {
|
||||||
tokenProgram?: PublicKey;
|
tokenProgram?: PublicKey;
|
||||||
state?: AuctionManagerState;
|
state?: AuctionManagerState;
|
||||||
settings?: AuctionManagerSettings;
|
settings?: AuctionManagerSettings;
|
||||||
|
|
||||||
|
constructor(args?: AuctionManager) {
|
||||||
|
Object.assign(this, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InitAuctionManagerArgs {
|
export class InitAuctionManagerArgs {
|
||||||
|
@ -55,9 +59,13 @@ export class AuctionManagerSettings {
|
||||||
WinningConstraint.NoOpenEdition;
|
WinningConstraint.NoOpenEdition;
|
||||||
openEditionNonWinningConstraint: NonWinningConstraint =
|
openEditionNonWinningConstraint: NonWinningConstraint =
|
||||||
NonWinningConstraint.GivenForFixedPrice;
|
NonWinningConstraint.GivenForFixedPrice;
|
||||||
winningConfigs?: WinningConfig[];
|
winningConfigs: WinningConfig[] = [];
|
||||||
openEditionConfig?: number;
|
openEditionConfig: number = 0;
|
||||||
openEditionFixedPrice: number = 0;
|
openEditionFixedPrice: number = 0;
|
||||||
|
|
||||||
|
constructor(args?: AuctionManagerSettings) {
|
||||||
|
Object.assign(this, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum WinningConstraint {
|
export enum WinningConstraint {
|
||||||
|
@ -81,33 +89,36 @@ export enum EditionType {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WinningConfig {
|
export class WinningConfig {
|
||||||
safetyDepositBoxIndex?: number;
|
safetyDepositBoxIndex: number = 0;
|
||||||
amount?: number;
|
amount: number = 0;
|
||||||
hasAuthority?: boolean;
|
hasAuthority: boolean = false;
|
||||||
editionType?: EditionType;
|
editionType: EditionType = EditionType.NA;
|
||||||
|
|
||||||
|
constructor(args?: WinningConfig) {
|
||||||
|
Object.assign(this, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WinningConfigState {
|
export class WinningConfigState {
|
||||||
/// Used for cases of minting Limited Editions and keeping track of how many have been made so far.
|
amountMinted: number = 0;
|
||||||
amountMinted?: number;
|
validated: boolean = false;
|
||||||
/// Each safety deposit box needs to be validated via endpoint before auction manager will agree to let auction begin.
|
claimed: boolean = false;
|
||||||
validated?: boolean;
|
|
||||||
/// Ticked to true when a prize is claimed
|
constructor(args?: WinningConfigState) {
|
||||||
claimed?: boolean;
|
Object.assign(this, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AuctionManagerState {
|
export class AuctionManagerState {
|
||||||
status: AuctionManagerStatus = AuctionManagerStatus.Initialized;
|
status: AuctionManagerStatus = AuctionManagerStatus.Initialized;
|
||||||
/// When all configs are validated the auction is started and auction manager moves to Running
|
winningConfigsValidated: number = 0;
|
||||||
winningConfigsValidated?: number;
|
masterEditionsWithAuthoritiesRemainingToReturn: number = 0;
|
||||||
|
|
||||||
/// Each master edition used as a template has to grant it's authority to the auction manager.
|
winningConfigStates: WinningConfigState[] = [];
|
||||||
/// This counter is incremented by one each time this is done. At the end of the auction; this is decremented
|
|
||||||
/// each time authority is delegated back to the owner or the new owner and when it hits 0 another condition
|
|
||||||
/// is met for going to Finished state.
|
|
||||||
masterEditionsWithAuthoritiesRemainingToReturn?: number;
|
|
||||||
|
|
||||||
winningConfigStates?: WinningConfigState[];
|
constructor(args?: AuctionManagerState) {
|
||||||
|
Object.assign(this, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AuctionManagerStatus {
|
export enum AuctionManagerStatus {
|
||||||
|
@ -119,8 +130,12 @@ export enum AuctionManagerStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BidRedemptionTicket {
|
export class BidRedemptionTicket {
|
||||||
openEditionRedeemed?: boolean;
|
openEditionRedeemed: boolean = false;
|
||||||
bidRedeemed?: boolean;
|
bidRedeemed: boolean = false;
|
||||||
|
|
||||||
|
constructor(args?: BidRedemptionTicket) {
|
||||||
|
Object.assign(this, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SCHEMA = new Map<any, any>([
|
export const SCHEMA = new Map<any, any>([
|
||||||
|
@ -147,11 +162,8 @@ export const SCHEMA = new Map<any, any>([
|
||||||
{
|
{
|
||||||
kind: 'struct',
|
kind: 'struct',
|
||||||
fields: [
|
fields: [
|
||||||
['openEditionWinnerConstraint', { kind: 'enum', values: [0, 1] }], // TODO:
|
['openEditionWinnerConstraint', 'u8'], // enum
|
||||||
[
|
['openEditionNonWinningConstraint', 'u8'], // TODO:
|
||||||
'openEditionNonWinningConstraint',
|
|
||||||
{ kind: 'enum', values: [0, 1, 2] },
|
|
||||||
], // TODO:
|
|
||||||
['winningConfigs', [WinningConfig]], // TODO: check
|
['winningConfigs', [WinningConfig]], // TODO: check
|
||||||
['openEditionConfig', { kind: 'option', type: 'u8' }],
|
['openEditionConfig', { kind: 'option', type: 'u8' }],
|
||||||
['openEditionFixedPrice', { kind: 'option', type: 'u8' }],
|
['openEditionFixedPrice', { kind: 'option', type: 'u8' }],
|
||||||
|
@ -166,7 +178,7 @@ export const SCHEMA = new Map<any, any>([
|
||||||
['safetyDepositBoxIndex', 'u8'],
|
['safetyDepositBoxIndex', 'u8'],
|
||||||
['amount', 'u8'],
|
['amount', 'u8'],
|
||||||
['hasAuthority', 'u8'], // bool
|
['hasAuthority', 'u8'], // bool
|
||||||
['editionType', { kind: 'enum', values: [0, 1, 2] }], // TODO:
|
['editionType', 'u8'], // TODO:
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -187,7 +199,7 @@ export const SCHEMA = new Map<any, any>([
|
||||||
kind: 'struct',
|
kind: 'struct',
|
||||||
fields: [
|
fields: [
|
||||||
// TODO: fix enum
|
// TODO: fix enum
|
||||||
['status', { kind: 'enum', values: [0, 1, 2, 3, 4] }],
|
['status', 'u8'],
|
||||||
['winningConfigsValidated', 'u8'],
|
['winningConfigsValidated', 'u8'],
|
||||||
['masterEditionsWithAuthoritiesRemainingToReturn', 'u8'],
|
['masterEditionsWithAuthoritiesRemainingToReturn', 'u8'],
|
||||||
['winningConfigStates', [WinningConfigState]],
|
['winningConfigStates', [WinningConfigState]],
|
||||||
|
|
|
@ -31,7 +31,7 @@ import {
|
||||||
useConnectionConfig,
|
useConnectionConfig,
|
||||||
Metadata,
|
Metadata,
|
||||||
ParsedAccount,
|
ParsedAccount,
|
||||||
deserializeBorsh,
|
deserializeBorsh
|
||||||
} from '@oyster/common';
|
} from '@oyster/common';
|
||||||
import { getAssetCostToStore, LAMPORT_MULTIPLIER } from '../../utils/assets';
|
import { getAssetCostToStore, LAMPORT_MULTIPLIER } from '../../utils/assets';
|
||||||
import { Connection, ParsedAccountData, PublicKey } from '@solana/web3.js';
|
import { Connection, ParsedAccountData, PublicKey } from '@solana/web3.js';
|
||||||
|
@ -41,7 +41,7 @@ import { useUserArts } from '../../hooks';
|
||||||
import Masonry from 'react-masonry-css';
|
import Masonry from 'react-masonry-css';
|
||||||
import { capitalize } from 'lodash';
|
import { capitalize } from 'lodash';
|
||||||
import { AuctionManager, AuctionManagerSettings, AuctionManagerState, AuctionManagerStatus, NonWinningConstraint, SCHEMA } from '../../models/metaplex';
|
import { AuctionManager, AuctionManagerSettings, AuctionManagerState, AuctionManagerStatus, NonWinningConstraint, SCHEMA } from '../../models/metaplex';
|
||||||
import { serialize } from 'borsh';
|
import { BinaryReader, BorshError, Schema, serialize } from 'borsh';
|
||||||
|
|
||||||
const { Step } = Steps;
|
const { Step } = Steps;
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
@ -122,30 +122,32 @@ export const AuctionCreateView = () => {
|
||||||
}, [step_param])
|
}, [step_param])
|
||||||
|
|
||||||
const gotoNextStep = (_step?: number) => {
|
const gotoNextStep = (_step?: number) => {
|
||||||
// TODO: enums dont work with borsh yet
|
|
||||||
|
|
||||||
// debugger;
|
|
||||||
|
|
||||||
// const test = new AuctionManager();
|
const test = new AuctionManager();
|
||||||
// test.key = 0;
|
test.key = 0;
|
||||||
// test.authority = TOKEN_PROGRAM_ID;
|
test.authority = TOKEN_PROGRAM_ID;
|
||||||
// test.auction = TOKEN_PROGRAM_ID;
|
test.auction = TOKEN_PROGRAM_ID;
|
||||||
// test.vault = TOKEN_PROGRAM_ID;
|
test.vault = TOKEN_PROGRAM_ID;
|
||||||
// test.auctionProgram = TOKEN_PROGRAM_ID;
|
test.auctionProgram = TOKEN_PROGRAM_ID;
|
||||||
// test.tokenVaultProgram = TOKEN_PROGRAM_ID;
|
test.tokenVaultProgram = TOKEN_PROGRAM_ID;
|
||||||
// test.tokenMetadataProgram = TOKEN_PROGRAM_ID;
|
test.tokenMetadataProgram = TOKEN_PROGRAM_ID;
|
||||||
// test.tokenProgram = TOKEN_PROGRAM_ID;
|
test.tokenProgram = TOKEN_PROGRAM_ID;
|
||||||
// test.state = new AuctionManagerState();
|
test.state = new AuctionManagerState();
|
||||||
// test.state.status = AuctionManagerStatus.Finished;
|
test.state.status = AuctionManagerStatus.Finished;
|
||||||
// test.settings = new AuctionManagerSettings();
|
test.settings = new AuctionManagerSettings();
|
||||||
// test.settings.openEditionConfig = 0;
|
test.settings.openEditionConfig = 0;
|
||||||
// test.settings.openEditionFixedPrice = 0;
|
test.settings.openEditionFixedPrice = 0;
|
||||||
// test.settings.openEditionNonWinningConstraint = NonWinningConstraint.GivenForFixedPrice;
|
test.settings.openEditionNonWinningConstraint = NonWinningConstraint.GivenForFixedPrice;
|
||||||
// const buffer = serialize(SCHEMA, test);
|
const buffer = serialize(SCHEMA, test);
|
||||||
|
|
||||||
|
debugger;
|
||||||
|
|
||||||
|
const test2 = deserializeBorsh(SCHEMA, AuctionManager, Buffer.from(buffer));
|
||||||
|
|
||||||
|
console.log(test2);
|
||||||
|
|
||||||
// const test2 = deserializeBorsh(SCHEMA, AuctionManager, Buffer.from(buffer));
|
|
||||||
|
|
||||||
// debugger;
|
|
||||||
|
|
||||||
const nextStep = _step === undefined ? (step + 1) : _step;
|
const nextStep = _step === undefined ? (step + 1) : _step;
|
||||||
history.push(`/auction/create/${nextStep.toString()}`)
|
history.push(`/auction/create/${nextStep.toString()}`)
|
||||||
|
|
Loading…
Reference in New Issue