Skip to content

Commit

Permalink
Add exclude array for withRemainingAccountsForHanldePaymentWithRoyalties
Browse files Browse the repository at this point in the history
  • Loading branch information
Giannis Chatziveroglou committed Aug 2, 2022
1 parent aa43993 commit 910a0a9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cardinal/token-manager",
"version": "1.5.0",
"version": "1.5.5",
"description": "Cardinal token manager SDK",
"keywords": [
"solana",
Expand Down
84 changes: 45 additions & 39 deletions src/programs/tokenManager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,20 @@ export const withRemainingAccountsForPayment = async (
issuerId: PublicKey,
paymentManagerId: PublicKey,
receiptMint?: PublicKey | null,
payer = wallet.publicKey
payer = wallet.publicKey,
excludeCreators?: string[],
skipRoyaltiesAccounts?: boolean
): Promise<[PublicKey, PublicKey, AccountMeta[]]> => {
const royaltiesRemainingAccounts =
await withRemainingAccountsForHanldePaymentWithRoyalties(
transaction,
connection,
wallet,
mint,
paymentMint
);
const mintMetadataId = await Metadata.getPDA(mint);
const paymentRemainingAccounts = [
{
pubkey: paymentMint,
isSigner: false,
isWritable: true,
},
{
pubkey: mint,
isSigner: false,
isWritable: true,
},
{
pubkey: mintMetadataId,
isSigner: false,
isWritable: true,
},
];
const royaltiesRemainingAccounts = !skipRoyaltiesAccounts
? await withRemainingAccountsForHanldePaymentWithRoyalties(
transaction,
connection,
wallet,
mint,
paymentMint,
excludeCreators
)
: [];

if (receiptMint) {
const receiptMintLargestAccount = await connection.getTokenLargestAccounts(
Expand Down Expand Up @@ -139,7 +125,6 @@ export const withRemainingAccountsForPayment = async (
isSigner: false,
isWritable: true,
},
...paymentRemainingAccounts,
...royaltiesRemainingAccounts,
],
];
Expand Down Expand Up @@ -169,7 +154,7 @@ export const withRemainingAccountsForPayment = async (
return [
issuerTokenAccountId,
feeCollectorTokenAccountId,
[...paymentRemainingAccounts, ...royaltiesRemainingAccounts],
royaltiesRemainingAccounts,
];
}
};
Expand Down Expand Up @@ -252,7 +237,8 @@ export const withRemainingAccountsForHanldePaymentWithRoyalties = async (
connection: Connection,
wallet: Wallet,
mint: PublicKey,
paymentMint: PublicKey
paymentMint: PublicKey,
excludeCreators?: string[]
): Promise<AccountMeta[]> => {
const creatorsRemainingAccounts: AccountMeta[] = [];
const mintMetadataId = await Metadata.getPDA(mint);
Expand All @@ -270,14 +256,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,
Expand All @@ -287,5 +276,22 @@ export const withRemainingAccountsForHanldePaymentWithRoyalties = async (
}
}

return creatorsRemainingAccounts;
return [
{
pubkey: paymentMint,
isSigner: false,
isWritable: true,
},
{
pubkey: mint,
isSigner: false,
isWritable: true,
},
{
pubkey: mintMetadataId,
isSigner: false,
isWritable: true,
},
...creatorsRemainingAccounts,
];
};

0 comments on commit 910a0a9

Please sign in to comment.