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