From bbf77704a8f337933a02a8c4bfbc9f23ca964005 Mon Sep 17 00:00:00 2001 From: Giannis Chatziveroglou Date: Mon, 1 Aug 2022 21:12:55 -0400 Subject: [PATCH] Add exclude array for withRemainingAccountsForHanldePaymentWithRoyalties --- package.json | 2 +- src/programs/tokenManager/utils.ts | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 445e7a3fd..abdd08140 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cardinal/token-manager", - "version": "1.5.0", + "version": "1.5.3", "description": "Cardinal token manager SDK", "keywords": [ "solana", diff --git a/src/programs/tokenManager/utils.ts b/src/programs/tokenManager/utils.ts index 9c952612c..19b115df5 100644 --- a/src/programs/tokenManager/utils.ts +++ b/src/programs/tokenManager/utils.ts @@ -58,7 +58,8 @@ export const withRemainingAccountsForPayment = async ( issuerId: PublicKey, paymentManagerId: PublicKey, receiptMint?: PublicKey | null, - payer = wallet.publicKey + payer = wallet.publicKey, + excludeCreators?: string[] ): Promise<[PublicKey, PublicKey, AccountMeta[]]> => { const royaltiesRemainingAccounts = await withRemainingAccountsForHanldePaymentWithRoyalties( @@ -66,7 +67,8 @@ export const withRemainingAccountsForPayment = async ( connection, wallet, mint, - paymentMint + paymentMint, + excludeCreators ); const mintMetadataId = await Metadata.getPDA(mint); const paymentRemainingAccounts = [ @@ -252,7 +254,8 @@ export const withRemainingAccountsForHanldePaymentWithRoyalties = async ( connection: Connection, wallet: Wallet, mint: PublicKey, - paymentMint: PublicKey + paymentMint: PublicKey, + excludeCreators?: string[] ): Promise => { const creatorsRemainingAccounts: AccountMeta[] = []; const mintMetadataId = await Metadata.getPDA(mint); @@ -270,14 +273,17 @@ export const withRemainingAccountsForHanldePaymentWithRoyalties = async ( if (creator.share !== 0) { const creatorAddress = new PublicKey(creator.address); const creatorMintTokenAccount = - await withFindOrInitAssociatedTokenAccount( - transaction, - connection, - paymentMint, - creatorAddress, - wallet.publicKey, - true - ); + !excludeCreators || + !excludeCreators.includes(creator.address.toString()) + ? await withFindOrInitAssociatedTokenAccount( + transaction, + connection, + paymentMint, + creatorAddress, + wallet.publicKey, + true + ) + : await findAta(mint, wallet.publicKey, true); creatorsRemainingAccounts.push({ pubkey: creatorMintTokenAccount, isSigner: false,