Skip to content

Commit

Permalink
Add Edition Drop Redeem implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
RustySol committed Aug 18, 2022
1 parent 2ecdeee commit 822a048
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 75 deletions.
65 changes: 39 additions & 26 deletions core/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ programCommand('sellMany')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.requiredOption('-p, --price <string>', 'price in token decimals')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMintList, treasuryMint, price, shopCreator, rpcUrl, version, isEnterpriseArg } =
cmd.opts();

Expand Down Expand Up @@ -82,8 +80,6 @@ programCommand('cancelMany')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.requiredOption('-p, --price <string>', 'price in token decimals')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMintList, treasuryMint, price, shopCreator, rpcUrl, version, isEnterpriseArg } =
cmd.opts();

Expand Down Expand Up @@ -128,8 +124,6 @@ programCommand('sell')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.requiredOption('-p, --price <string>', 'price in token decimals')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMint, treasuryMint, price, shopCreator, rpcUrl, version, isEnterpriseArg } =
cmd.opts();

Expand Down Expand Up @@ -170,8 +164,6 @@ programCommand('cancel')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.requiredOption('-p, --price <string>', 'price in token decimals')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMint, treasuryMint, price, shopCreator, rpcUrl, version, isEnterpriseArg } =
cmd.opts();

Expand Down Expand Up @@ -214,8 +206,6 @@ programCommand('buy')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.requiredOption('-p, --price <string>', 'price in token decimals')
.action(async (name, cmd) => {
console.log(name);

let {
keypair,
env,
Expand Down Expand Up @@ -268,8 +258,6 @@ programCommand('createAuction')
.requiredOption('-ts, --tick-size <string>', 'tick size')
.option('-bnp, --buy-now-price <string>', 'Buy now price, in the unit of treasury mint, nullable')
.action(async (name, cmd) => {
console.log(name);

let {
keypair,
env,
Expand Down Expand Up @@ -326,8 +314,6 @@ programCommand('cancelAuction')
.requiredOption('-tm, --treasury-mint <string>', 'Candy Shop treasury mint')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMint, treasuryMint, rpcUrl, shopCreator, version, isEnterpriseArg } = cmd.opts();

const wallet = loadKey(keypair);
Expand Down Expand Up @@ -366,8 +352,6 @@ programCommand('makeBid')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.requiredOption('-p, --price <string>', 'price in token decimals')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMint, treasuryMint, rpcUrl, shopCreator, price, version, isEnterpriseArg } =
cmd.opts();

Expand Down Expand Up @@ -407,8 +391,6 @@ programCommand('withdrawBid')
.requiredOption('-tm, --treasury-mint <string>', 'Candy Shop treasury mint')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMint, treasuryMint, rpcUrl, shopCreator, version, isEnterpriseArg } = cmd.opts();

const wallet = loadKey(keypair);
Expand Down Expand Up @@ -445,8 +427,6 @@ programCommand('buyNow')
.requiredOption('-tm, --treasury-mint <string>', 'Candy Shop treasury mint')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMint, treasuryMint, rpcUrl, shopCreator, version, isEnterpriseArg } = cmd.opts();

const wallet = loadKey(keypair);
Expand Down Expand Up @@ -484,8 +464,6 @@ programCommand('settleAndDistribute')
.requiredOption('-tm, --treasury-mint <string>', 'Candy Shop treasury mint')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.action(async (name, cmd) => {
console.log(name);

let { keypair, env, tokenAccountMint, treasuryMint, rpcUrl, shopCreator, version, isEnterpriseArg } = cmd.opts();

const wallet = loadKey(keypair);
Expand Down Expand Up @@ -529,8 +507,6 @@ programCommand('commitEditionDropNft')
.option('-wtt, --whitelist-time <string>', 'whitelist time, unix timestamp')

.action(async (name, cmd) => {
console.log(name);

let {
keypair,
env,
Expand Down Expand Up @@ -591,8 +567,6 @@ programCommand('mintPrint')
.option('-wtm, --whitelist-mint <string>', 'whitelist mint')

.action(async (name, cmd) => {
console.log(name);

let {
keypair,
env,
Expand Down Expand Up @@ -636,4 +610,43 @@ programCommand('mintPrint')
console.log('txHash', txHash);
});

programCommand('redeemDrop')
.description('mint an edition-ed NFT from the master edition')
.requiredOption('-ota, --nft-owner-token-account <string>', 'NFT token account address')
.requiredOption('-tm, --treasury-mint <string>', 'Candy Shop treasury mint')
.requiredOption('-sc, --shop-creator <string>', 'Candy Shop creator address')
.action(async (name, cmd) => {
let { keypair, env, nftOwnerTokenAccount, treasuryMint, rpcUrl, shopCreator, version, isEnterpriseArg } =
cmd.opts();
const wallet = loadKey(keypair);

if (version !== 'v2') {
throw new CandyShopError(CandyShopErrorType.IncorrectProgramId);
}

// default to v2
const candyShopProgramId = CANDY_SHOP_V2_PROGRAM_ID;

const candyShop = new CandyShop({
candyShopCreatorAddress: new anchor.web3.PublicKey(shopCreator),
treasuryMint: new anchor.web3.PublicKey(treasuryMint),
candyShopProgramId,
env,
settings: {
mainnetConnectionUrl: rpcUrl
},
isEnterprise: isEnterprise(isEnterpriseArg)
});

const tokenAccountInfo = await getAccount(candyShop.connection(), new PublicKey(nftOwnerTokenAccount), 'finalized');

const txHash = await candyShop.redeemDrop({
nftOwner: wallet,
nftOwnerTokenAccount: new PublicKey(nftOwnerTokenAccount),
masterMint: tokenAccountInfo.mint
});

console.log('txHash', txHash);
});

CMD.parse(process.argv);
92 changes: 61 additions & 31 deletions core/sdk/src/CandyShop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,10 @@ import {
TradeQuery,
WhitelistNft
} from '@liqnft/candy-shop-types';
import { BN, Idl, Program, Provider, web3 } from '@project-serum/anchor';
import { Idl, Program, Provider, web3 } from '@project-serum/anchor';
import { AnchorWallet } from '@solana/wallet-adapter-react';
import {
getAuction,
getAuctionHouse,
getAuctionHouseAuthority,
getAuctionHouseFeeAcct,
getAuctionHouseTreasuryAcct,
getCandyShopSync,
getMetadataAccount,
getProgram,
CandyShopError,
CandyShopErrorType,
getCandyShopVersion
} from './vendor';
import { supply } from './vendor/shipping';
import { CANDY_SHOP_PROGRAM_ID, CANDY_SHOP_V2_PROGRAM_ID } from './factory/constants';
import { CandyShopCommitNftParams, CandyShopMintPrintParams } from '.';
import { CandyShopDrop } from './CandyShopDrop';
import {
fetchNFTByMintAddress,
fetchOrderByShopAndMintAddress,
Expand All @@ -39,46 +26,60 @@ import {
} from './CandyShopInfoAPI';
import {
CandyShopBidAuctionParams,
CandyShopBuyNowParams,
CandyShopBuyParams,
CandyShopCancelAuctionParams,
CandyShopCancelParams,
CandyShopConstructorParams,
CandyShopCreateAuctionParams,
CandyShopRedeemParams,
CandyShopSellParams,
CandyShopSettings,
CandyShopWithdrawAuctionBidParams,
CandyShopSettleAndDistributeParams,
CandyShopBuyNowParams,
CandyShopUpdateParams,
CandyShopConstructorParams,
CandyShopVersion
CandyShopVersion,
CandyShopWithdrawAuctionBidParams
} from './CandyShopModel';
import { CandyShopTrade } from './CandyShopTrade';
import { configBaseUrl } from './vendor/config';
import { CANDY_SHOP_PROGRAM_ID, CANDY_SHOP_V2_PROGRAM_ID } from './factory/constants';
import {
bidAuction,
BidAuctionParams,
bidAuctionV1,
bidAuction,
buyNowAuction,
BuyNowAuctionParams,
buyNowAuctionV1,
buyNowAuction,
cancelAuction,
CancelAuctionParams,
cancelAuctionV1,
cancelAuction,
createAuction,
CreateAuctionParams,
createAuctionV1,
createAuction,
SettleAndDistributeProceedParams,
settleAndDistributeProceedsV1,
settleAndDistributeProceeds,
settleAndDistributeProceedsV1,
updateCandyShop,
UpdateCandyShopParams,
updateCandyShopV1,
updateCandyShop,
withdrawBid,
WithdrawBidParams,
withdrawBidV1,
withdrawBid
withdrawBidV1
} from './factory/program';
import { CandyShopCommitNftParams, CandyShopMintPrintParams } from '.';
import { CandyShopDrop } from './CandyShopDrop';
import {
CandyShopError,
CandyShopErrorType,
getAuction,
getAuctionHouse,
getAuctionHouseAuthority,
getAuctionHouseFeeAcct,
getAuctionHouseTreasuryAcct,
getCandyShopSync,
getCandyShopVersion,
getMetadataAccount,
getProgram
} from './vendor';
import { configBaseUrl } from './vendor/config';
import { supply } from './vendor/shipping';

const Logger = 'CandyShop';

Expand Down Expand Up @@ -755,6 +756,35 @@ export class CandyShop {
return txHash;
}

/**
* Executes Edition Drop __RedeemNft__ action
*
* @param {CandyShopRedeemParams} params required parameters for mint print action
*/
public async redeemDrop(params: CandyShopRedeemParams) {
const { nftOwnerTokenAccount, masterMint, nftOwner } = params;

if (this._version !== CandyShopVersion.V2) {
throw new CandyShopError(CandyShopErrorType.IncorrectProgramId);
}

console.log(`${Logger}: performing redeem drop `, {
masterNft: masterMint.toString()
});

const txHash = await CandyShopDrop.redeemDrop({
nftOwner,
candyShop: this._candyShopAddress,
nftOwnerTokenAccount,
masterMint,
isEnterprise: this._isEnterprise,
connection: this.connection(),
candyShopProgram: this.getStaticProgram(nftOwner)
});

return txHash;
}

/**
* Fetch stats associated with this Candy Shop
*/
Expand Down
23 changes: 21 additions & 2 deletions core/sdk/src/CandyShopDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import {
} from '@solana/spl-token';
import { AnchorWallet } from '@solana/wallet-adapter-react';
import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
import { EditionDropCommitNftParams, EditionDropMintPrintParams } from '.';
import { EditionDropCommitNftParams, EditionDropMintPrintParams, EditionDropRedeemParams } from '.';
import { EDITION_DROP_PROGRAM_ID } from './factory/constants';
import {
commitNft,
CommitNftParams,
enterpriseCommitNft,
enterpriseMintPrint,
mintPrint,
MintPrintParams
MintPrintParams,
redeemNft,
RedeemNftParams
} from './factory/program';
import editionDropIdl from './idl/edition_drop.json';
import {
Expand Down Expand Up @@ -133,6 +135,23 @@ export abstract class CandyShopDrop {

return mintPrint(instructions, mintPrintParams);
}

static async redeemDrop(params: EditionDropRedeemParams): Promise<string> {
const { nftOwner, candyShop, nftOwnerTokenAccount, masterMint, connection } = params;
const [vaultAccount] = await getEditionVaultAccount(candyShop, nftOwnerTokenAccount);
const program = this.getProgram(connection, nftOwner);

const redeemParams: RedeemNftParams = {
nftOwner,
candyShop,
vaultAccount,
nftOwnerTokenAccount,
masterMint,
program
};

return redeemNft(redeemParams);
}
}

interface NewToken {
Expand Down
6 changes: 6 additions & 0 deletions core/sdk/src/CandyShopModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ export interface CandyShopMintPrintParams extends CandyShopEditionDropParams {
editionBuyer: AnchorWallet | web3.Keypair;
}

export interface CandyShopRedeemParams extends CandyShopEditionDropParams {
nftOwner: AnchorWallet | web3.Keypair;
}

interface EditionDropParams extends CandyShopEditionDropParams {
isEnterprise: boolean;
candyShop: web3.PublicKey;
Expand All @@ -238,3 +242,5 @@ export interface EditionDropCommitNftParams extends EditionDropParams, CandyShop
export interface EditionDropMintPrintParams extends EditionDropParams, CandyShopMintPrintParams {
auctionHouse: web3.PublicKey;
}

export interface EditionDropRedeemParams extends EditionDropParams, CandyShopRedeemParams {}
4 changes: 4 additions & 0 deletions core/sdk/src/factory/program/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ export interface MintPrintParams extends EditionDropParams {
auctionHouse: web3.PublicKey;
editionNumber: BN;
}

export interface RedeemNftParams extends EditionDropParams {
nftOwner: AnchorWallet | web3.Keypair;
}
1 change: 1 addition & 0 deletions core/sdk/src/factory/program/v2/editionDrop/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './commitNft';
export * from './mintPrint';
export * from './redeemNft';
export { commitNft as enterpriseCommitNft } from './enterpriseCommitNft';
export { mintPrint as enterpriseMintPrint } from './enterpriseMintPrint';
Loading

0 comments on commit 822a048

Please sign in to comment.