Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix next edition calculation for burned items #1126

Merged
merged 18 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
418 changes: 398 additions & 20 deletions fixed-price-sale/js/idl/fixed_price_sale.json

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions fixed-price-sale/js/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
#
# To run this script, you need:
# - npm install -g esbuild-runner
# - npm install -g tap-spec

# error output colour
RED() { echo $'\e[1;31m'$1$'\e[0m'; }
RUN_ALL=0

# check whether we are running all test files or not

while getopts a-: optchar; do
case "${optchar}" in
a)
RUN_ALL=1 ;;
-)
case "${OPTARG}" in
all) RUN_ALL=1 ;;
*) ;;
esac ;;
*) ;;
esac
done

# runs single or multiple tests

if [ $RUN_ALL -eq 1 ]; then
for file in `ls test/*.test.ts`
do
esr $file | tap-spec
done
else
if [ ! -z "$1" ] && [[ -f "$1" ]]; then
esr $1 | tap-spec
else
echo "$(RED "Error: ")Please specify a test file or [-a | --all] to run all tests"
exit 1
fi
fi
43 changes: 43 additions & 0 deletions fixed-price-sale/js/src/generated/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,49 @@ export class WrongGatingTokenError extends Error {
createErrorFromCodeLookup.set(0x179b, () => new WrongGatingTokenError());
createErrorFromNameLookup.set('WrongGatingToken', () => new WrongGatingTokenError());

/**
* EditionMarkerFull: 'No available editions in edition marker'
*
* @category Errors
* @category generated
*/
export class EditionMarkerFullError extends Error {
readonly code: number = 0x179c;
readonly name: string = 'EditionMarkerFull';
constructor() {
super('No available editions in edition marker');
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, EditionMarkerFullError);
}
}
}

createErrorFromCodeLookup.set(0x179c, () => new EditionMarkerFullError());
createErrorFromNameLookup.set('EditionMarkerFull', () => new EditionMarkerFullError());

/**
* InvalidEditionMarkerAccount: 'Invalid edition marker'
*
* @category Errors
* @category generated
*/
export class InvalidEditionMarkerAccountError extends Error {
readonly code: number = 0x179d;
readonly name: string = 'InvalidEditionMarkerAccount';
constructor() {
super('Invalid edition marker');
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, InvalidEditionMarkerAccountError);
}
}
}

createErrorFromCodeLookup.set(0x179d, () => new InvalidEditionMarkerAccountError());
createErrorFromNameLookup.set(
'InvalidEditionMarkerAccount',
() => new InvalidEditionMarkerAccountError(),
);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
224 changes: 224 additions & 0 deletions fixed-price-sale/js/src/generated/instructions/buyV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/**
* This code was GENERATED using the solita package.
* Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality.
*
* See: https://github.com/metaplex-foundation/solita
*/

import * as splToken from '@solana/spl-token';
import * as beet from '@metaplex-foundation/beet';
import * as web3 from '@solana/web3.js';

/**
* @category Instructions
* @category BuyV2
* @category generated
*/
export type BuyV2InstructionArgs = {
tradeHistoryBump: number;
vaultOwnerBump: number;
editionMarkerNumber: beet.bignum;
};
/**
* @category Instructions
* @category BuyV2
* @category generated
*/
export const buyV2Struct = new beet.BeetArgsStruct<
BuyV2InstructionArgs & {
instructionDiscriminator: number[] /* size: 8 */;
}
>(
[
['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
['tradeHistoryBump', beet.u8],
['vaultOwnerBump', beet.u8],
['editionMarkerNumber', beet.u64],
],
'BuyV2InstructionArgs',
);
/**
* Accounts required by the _buyV2_ instruction
*
* @property [_writable_] market
* @property [_writable_] sellingResource
* @property [_writable_] userTokenAccount
* @property [_writable_, **signer**] userWallet
* @property [_writable_] tradeHistory
* @property [_writable_] treasuryHolder
* @property [_writable_] newMetadata
* @property [_writable_] newEdition
* @property [_writable_] masterEdition
* @property [_writable_] newMint
* @property [_writable_] editionMarker
* @property [_writable_] vault
* @property [] owner
* @property [_writable_] newTokenAccount
* @property [_writable_] masterEditionMetadata
* @property [] clock
* @property [] tokenMetadataProgram
* @category Instructions
* @category BuyV2
* @category generated
*/
export type BuyV2InstructionAccounts = {
market: web3.PublicKey;
sellingResource: web3.PublicKey;
userTokenAccount: web3.PublicKey;
userWallet: web3.PublicKey;
tradeHistory: web3.PublicKey;
treasuryHolder: web3.PublicKey;
newMetadata: web3.PublicKey;
newEdition: web3.PublicKey;
masterEdition: web3.PublicKey;
newMint: web3.PublicKey;
editionMarker: web3.PublicKey;
vault: web3.PublicKey;
owner: web3.PublicKey;
newTokenAccount: web3.PublicKey;
masterEditionMetadata: web3.PublicKey;
clock: web3.PublicKey;
rent?: web3.PublicKey;
tokenMetadataProgram: web3.PublicKey;
tokenProgram?: web3.PublicKey;
systemProgram?: web3.PublicKey;
anchorRemainingAccounts?: web3.AccountMeta[];
};

export const buyV2InstructionDiscriminator = [184, 23, 238, 97, 103, 197, 211, 61];

/**
* Creates a _BuyV2_ instruction.
*
* @param accounts that will be accessed while the instruction is processed
* @param args to provide as instruction data to the program
*
* @category Instructions
* @category BuyV2
* @category generated
*/
export function createBuyV2Instruction(
accounts: BuyV2InstructionAccounts,
args: BuyV2InstructionArgs,
programId = new web3.PublicKey('SaLeTjyUa5wXHnGuewUSyJ5JWZaHwz3TxqUntCE9czo'),
) {
const [data] = buyV2Struct.serialize({
instructionDiscriminator: buyV2InstructionDiscriminator,
...args,
});
const keys: web3.AccountMeta[] = [
{
pubkey: accounts.market,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.sellingResource,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.userTokenAccount,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.userWallet,
isWritable: true,
isSigner: true,
},
{
pubkey: accounts.tradeHistory,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.treasuryHolder,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.newMetadata,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.newEdition,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.masterEdition,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.newMint,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.editionMarker,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.vault,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.owner,
isWritable: false,
isSigner: false,
},
{
pubkey: accounts.newTokenAccount,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.masterEditionMetadata,
isWritable: true,
isSigner: false,
},
{
pubkey: accounts.clock,
isWritable: false,
isSigner: false,
},
{
pubkey: accounts.rent ?? web3.SYSVAR_RENT_PUBKEY,
isWritable: false,
isSigner: false,
},
{
pubkey: accounts.tokenMetadataProgram,
isWritable: false,
isSigner: false,
},
{
pubkey: accounts.tokenProgram ?? splToken.TOKEN_PROGRAM_ID,
isWritable: false,
isSigner: false,
},
{
pubkey: accounts.systemProgram ?? web3.SystemProgram.programId,
isWritable: false,
isSigner: false,
},
];

if (accounts.anchorRemainingAccounts != null) {
for (const acc of accounts.anchorRemainingAccounts) {
keys.push(acc);
}
}

const ix = new web3.TransactionInstruction({
programId,
keys,
data,
});
return ix;
}
1 change: 1 addition & 0 deletions fixed-price-sale/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './buy';
export * from './buyV2';
export * from './changeMarket';
export * from './claimResource';
export * from './closeMarket';
Expand Down
6 changes: 3 additions & 3 deletions fixed-price-sale/js/test/actions/mintNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
createCreateMasterEditionV3Instruction,
Creator,
DataV2,
createCreateMetadataAccountV2Instruction,
createCreateMetadataAccountV3Instruction,
} from '@metaplex-foundation/mpl-token-metadata';
import { createMintToInstruction } from '@solana/spl-token';
import { strict as assert } from 'assert';
Expand Down Expand Up @@ -66,15 +66,15 @@ export async function mintNFT({
const pdas = metaplex.nfts().pdas();
const metadata = pdas.metadata({ mint: mint.publicKey });

const createMetadataInstruction = createCreateMetadataAccountV2Instruction(
const createMetadataInstruction = createCreateMetadataAccountV3Instruction(
{
metadata,
mint: mint.publicKey,
updateAuthority: payer.publicKey,
mintAuthority: payer.publicKey,
payer: payer.publicKey,
},
{ createMetadataAccountArgsV2: { isMutable: true, data } },
{ createMetadataAccountArgsV3: { isMutable: true, data, collectionDetails: null } },
);

createTokenTx.add(createMetadataInstruction);
Expand Down
6 changes: 6 additions & 0 deletions fixed-price-sale/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,10 @@ pub enum ErrorCode {
// 6043
#[msg("Wrong gating token")]
WrongGatingToken,
// 6044
#[msg("No available editions in edition marker")]
EditionMarkerFull,
// 6045
#[msg("Invalid edition marker")]
InvalidEditionMarkerAccount,
}
Loading
Loading