Skip to content

Commit

Permalink
rename pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
Giannis Chatziveroglou committed Sep 14, 2023
1 parent a9a7f68 commit 970c2e6
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 194 deletions.
2 changes: 1 addition & 1 deletion programs/solana-nft-programs-payment-manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "solana-nft-programs-payment-manager"
version = "4.0.0"
version = "1.0.0"
description = "Payment manager"
edition = "2021"
repository = "https://github.com/solana-nft-programs/payment-manager/"
Expand Down
4 changes: 2 additions & 2 deletions sdk/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { PAYMENT_MANAGER_IDL } from ".";

export const getPaymentManager = async (
connection: Connection,
paymentManagerId: PublicKey
paymentManagerId: PublicKey,
): Promise<AccountData<PaymentManagerData>> => {
return fetchIdlAccount<"paymentManager", PAYMENT_MANAGER_PROGRAM>(
connection,
paymentManagerId,
"paymentManager",
PAYMENT_MANAGER_IDL
PAYMENT_MANAGER_IDL,
);
};
10 changes: 5 additions & 5 deletions sdk/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export const BASIS_POINTS_DIVISOR = 10000;
export const DEFAULT_BUY_SIDE_FEE_SHARE = 50;

export const PAYMENT_MANAGER_ADDRESS = new PublicKey(
"pmvYY6Wgvpe3DEj3UX1FcRpMx43sMLYLJrFTVGcqpdn"
"pmvYY6Wgvpe3DEj3UX1FcRpMx43sMLYLJrFTVGcqpdn",
);

export const CRANK_KEY = new PublicKey(
"crkdpVWjHWdggGgBuSyAqSmZUmAjYLzD435tcLDRLXr"
"crkdpVWjHWdggGgBuSyAqSmZUmAjYLzD435tcLDRLXr",
);

export const PAYMENT_MANAGER_SEED = "payment-manager";
Expand All @@ -34,15 +34,15 @@ export type PaymentManagerData = ParsedIdlAccountData<
export const paymentManagerProgram = (
connection: Connection,
wallet?: Wallet,
confirmOptions?: ConfirmOptions
confirmOptions?: ConfirmOptions,
) => {
return new Program<PAYMENT_MANAGER_PROGRAM>(
PAYMENT_MANAGER_IDL,
PAYMENT_MANAGER_ADDRESS,
new AnchorProvider(
connection,
wallet ?? emptyWallet(PublicKey.default),
confirmOptions ?? {}
)
confirmOptions ?? {},
),
);
};
2 changes: 1 addition & 1 deletion sdk/pda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export const findPaymentManagerAddress = (name: string): PublicKey => {
utils.bytes.utf8.encode(PAYMENT_MANAGER_SEED),
utils.bytes.utf8.encode(name),
],
PAYMENT_MANAGER_ADDRESS
PAYMENT_MANAGER_ADDRESS,
)[0];
};
30 changes: 15 additions & 15 deletions sdk/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const withInit = async (
royaltyFeeShare?: BN;
payer?: PublicKey;
authority?: PublicKey;
}
},
): Promise<[Transaction, PublicKey]> => {
const paymentManagerId = findPaymentManagerAddress(params.paymentManagerName);
transaction.add(
Expand All @@ -42,7 +42,7 @@ export const withInit = async (
payer: params.payer ?? wallet.publicKey,
systemProgram: SystemProgram.programId,
})
.instruction()
.instruction(),
);
return [transaction, paymentManagerId];
};
Expand All @@ -57,7 +57,7 @@ export const withManagePayment = async (
payerTokenAccountId: PublicKey;
feeCollectorTokenAccountId: PublicKey;
paymentTokenAccountId: PublicKey;
}
},
): Promise<Transaction> => {
return transaction.add(
await paymentManagerProgram(connection, wallet)
Expand All @@ -70,7 +70,7 @@ export const withManagePayment = async (
payer: wallet.publicKey,
tokenProgram: TOKEN_PROGRAM_ID,
})
.instruction()
.instruction(),
);
};

Expand All @@ -88,7 +88,7 @@ export const withHandlePaymentWithRoyalties = async (
paymentTokenAccountId: PublicKey;
buySideTokenAccountId?: PublicKey;
excludeCretors?: string[];
}
},
): Promise<Transaction> => {
const paymentManagerId = findPaymentManagerAddress(params.paymentManagerName);

Expand All @@ -100,7 +100,7 @@ export const withHandlePaymentWithRoyalties = async (
params.mintId,
params.paymentMintId,
params.buySideTokenAccountId,
params.excludeCretors ?? []
params.excludeCretors ?? [],
);
transaction.add(
await paymentManagerProgram(connection, wallet)
Expand All @@ -117,7 +117,7 @@ export const withHandlePaymentWithRoyalties = async (
tokenProgram: TOKEN_PROGRAM_ID,
})
.remainingAccounts(remainingAccounts)
.instruction()
.instruction(),
);
return transaction;
};
Expand All @@ -134,7 +134,7 @@ export const withHandleNativePaymentWithRoyalties = async (
paymentTargetId: PublicKey;
buySideTokenAccountId?: PublicKey;
excludeCretors?: string[];
}
},
): Promise<Transaction> => {
const paymentManagerId = findPaymentManagerAddress(params.paymentManagerName);

Expand All @@ -146,7 +146,7 @@ export const withHandleNativePaymentWithRoyalties = async (
params.mintId,
PublicKey.default,
params.buySideTokenAccountId,
params.excludeCretors ?? []
params.excludeCretors ?? [],
);

transaction.add(
Expand All @@ -162,7 +162,7 @@ export const withHandleNativePaymentWithRoyalties = async (
systemProgram: SystemProgram.programId,
})
.remainingAccounts(remainingAccounts)
.instruction()
.instruction(),
);
return transaction;
};
Expand All @@ -174,7 +174,7 @@ export const withClose = async (
params: {
paymentManagerName: string;
collectorId?: PublicKey;
}
},
): Promise<Transaction> => {
transaction.add(
await paymentManagerProgram(connection, wallet)
Expand All @@ -184,7 +184,7 @@ export const withClose = async (
collector: params.collectorId ?? wallet.publicKey,
closer: wallet.publicKey,
})
.instruction()
.instruction(),
);
return transaction;
};
Expand All @@ -200,11 +200,11 @@ export const withUpdate = async (
makerFeeBasisPoints?: number;
takerFeeBasisPoints?: number;
royaltyFeeShare?: BN;
}
},
): Promise<Transaction> => {
const paymentManagerId = findPaymentManagerAddress(params.paymentManagerName);
const checkPaymentManager = await tryGetAccount(() =>
getPaymentManager(connection, paymentManagerId)
getPaymentManager(connection, paymentManagerId),
);
if (!checkPaymentManager) {
throw `No payment manager found with name ${params.paymentManagerName}`;
Expand Down Expand Up @@ -232,7 +232,7 @@ export const withUpdate = async (
payer: wallet.publicKey,
systemProgram: SystemProgram.programId,
})
.instruction()
.instruction(),
);
return transaction;
};
30 changes: 15 additions & 15 deletions sdk/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const withRemainingAccountsForPayment = async (
options?: {
payer?: PublicKey;
receiptMint?: PublicKey | null;
}
},
): Promise<[PublicKey, PublicKey, AccountMeta[]]> => {
const payer = options?.payer ?? wallet.publicKey;
const royaltiesRemainingAccounts =
Expand All @@ -35,7 +35,7 @@ export const withRemainingAccountsForPayment = async (
mint,
paymentMint,
buySideTokenAccountId,
[issuerId.toString()]
[issuerId.toString()],
);
const mintMetadataId = findMintMetadataId(mint);
const paymentRemainingAccounts = [
Expand All @@ -58,19 +58,19 @@ export const withRemainingAccountsForPayment = async (

if (options?.receiptMint) {
const receiptMintLargestAccount = await connection.getTokenLargestAccounts(
options.receiptMint
options.receiptMint,
);
// get holder of receipt mint
const receiptTokenAccountId = receiptMintLargestAccount.value[0]?.address;
if (!receiptTokenAccountId) throw new Error("No token accounts found");
const receiptTokenAccount = await getAccount(
connection,
receiptTokenAccountId
receiptTokenAccountId,
);

// get ATA for this mint of receipt mint holder
const returnTokenAccountId = receiptTokenAccount.owner.equals(
wallet.publicKey
wallet.publicKey,
)
? await findAta(paymentMint, receiptTokenAccount.owner, true)
: await withFindOrInitAssociatedTokenAccount(
Expand All @@ -79,11 +79,11 @@ export const withRemainingAccountsForPayment = async (
paymentMint,
receiptTokenAccount.owner,
payer,
true
true,
);

const paymentManager = await tryNull(
getPaymentManager(connection, paymentManagerId)
getPaymentManager(connection, paymentManagerId),
);
const feeCollectorTokenAccountId =
await withFindOrInitAssociatedTokenAccount(
Expand All @@ -92,7 +92,7 @@ export const withRemainingAccountsForPayment = async (
paymentMint,
paymentManager ? paymentManager.parsed.feeCollector : paymentManagerId,
payer,
true
true,
);
return [
returnTokenAccountId,
Expand All @@ -116,10 +116,10 @@ export const withRemainingAccountsForPayment = async (
paymentMint,
issuerId,
payer,
true
true,
);
const paymentManager = await tryNull(
getPaymentManager(connection, paymentManagerId)
getPaymentManager(connection, paymentManagerId),
);
const feeCollectorTokenAccountId =
await withFindOrInitAssociatedTokenAccount(
Expand All @@ -128,7 +128,7 @@ export const withRemainingAccountsForPayment = async (
paymentMint,
paymentManager ? paymentManager.parsed.feeCollector : paymentManagerId,
payer,
true
true,
);
return [
issuerTokenAccountId,
Expand All @@ -145,15 +145,15 @@ export const withRemainingAccountsForHandlePaymentWithRoyalties = async (
mint: PublicKey,
paymentMint: PublicKey,
buySideTokenAccountId?: PublicKey,
excludeCreators?: string[]
excludeCreators?: string[],
): Promise<AccountMeta[]> => {
const remainingAccounts: AccountMeta[] = [];
let metaplexMintData: Metadata | undefined;
try {
const mintMetadataId = findMintMetadataId(mint);
metaplexMintData = await Metadata.fromAccountAddress(
connection,
mintMetadataId
mintMetadataId,
);
} catch (e) {
// pass
Expand All @@ -170,7 +170,7 @@ export const withRemainingAccountsForHandlePaymentWithRoyalties = async (
});
} else {
const creatorMintTokenAccount = excludeCreators?.includes(
creator.address.toString()
creator.address.toString(),
)
? await findAta(paymentMint, creatorAddress, true)
: await withFindOrInitAssociatedTokenAccount(
Expand All @@ -179,7 +179,7 @@ export const withRemainingAccountsForHandlePaymentWithRoyalties = async (
paymentMint,
creatorAddress,
wallet.publicKey,
true
true,
);
remainingAccounts.push({
pubkey: creatorMintTokenAccount,
Expand Down
Loading

0 comments on commit 970c2e6

Please sign in to comment.