Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbogle committed Mar 2, 2022
2 parents 19fc841 + 282df57 commit 671ceff
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ pub struct InitCtx<'info> {
system_program: Program<'info, System>,
}

pub fn handler(ctx: Context<InitCtx>, payment_amount: u64) -> ProgramResult {
pub fn handler(ctx: Context<InitCtx>, payment_mint: Pubkey, payment_amount: u64) -> ProgramResult {
let claim_approver = &mut ctx.accounts.claim_approver;
claim_approver.bump = *ctx.bumps.get("claim_approver").unwrap();
claim_approver.payment_amount = payment_amount;
claim_approver.payment_mint = payment_mint;
claim_approver.token_manager = ctx.accounts.token_manager.key();
return Ok(())
}
4 changes: 2 additions & 2 deletions programs/cardinal-paid-claim-approver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ declare_id!("pcaBwhJ1YHp7UDA7HASpQsRUmUNwzgYaLQto2kSj1fR");
pub mod cardinal_paid_claim_approver {
use super::*;

pub fn init(ctx: Context<InitCtx>, payment_amount: u64) -> ProgramResult {
init::handler(ctx, payment_amount)
pub fn init(ctx: Context<InitCtx>, payment_mint: Pubkey, payment_amount: u64) -> ProgramResult {
init::handler(ctx, payment_mint, payment_amount)
}

pub fn pay(ctx: Context<PayCtx>) -> ProgramResult {
Expand Down
2 changes: 2 additions & 0 deletions programs/cardinal-paid-claim-approver/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pub const PAID_CLAIM_APPROVER_SIZE: usize = 8 + std::mem::size_of::<PaidClaimApp
pub struct PaidClaimApprover {
pub bump: u8,
pub payment_amount: u64,
pub payment_mint: Pubkey,
pub token_manager: Pubkey,
}
24 changes: 24 additions & 0 deletions src/idl/cardinal_paid_claim_approver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export type CardinalPaidClaimApprover = {
}
];
args: [
{
name: "paymentMint";
type: "publicKey";
},
{
name: "paymentAmount";
type: "u64";
Expand Down Expand Up @@ -98,6 +102,14 @@ export type CardinalPaidClaimApprover = {
{
name: "paymentAmount";
type: "u64";
},
{
name: "paymentMint";
type: "publicKey";
},
{
name: "tokenManager";
type: "publicKey";
}
];
};
Expand Down Expand Up @@ -151,6 +163,10 @@ export const IDL: CardinalPaidClaimApprover = {
},
],
args: [
{
name: "paymentMint",
type: "publicKey",
},
{
name: "paymentAmount",
type: "u64",
Expand Down Expand Up @@ -223,6 +239,14 @@ export const IDL: CardinalPaidClaimApprover = {
name: "paymentAmount",
type: "u64",
},
{
name: "paymentMint",
type: "publicKey",
},
{
name: "tokenManager",
type: "publicKey",
},
],
},
},
Expand Down
10 changes: 8 additions & 2 deletions src/programs/claimApprover/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ import type { CLAIM_APPROVER_PROGRAM } from "./constants";
import { CLAIM_APPROVER_ADDRESS, CLAIM_APPROVER_IDL } from "./constants";
import { findClaimApproverAddress } from "./pda";

export type ClaimApproverParams = {
paymentMint: PublicKey;
paymentAmount: number;
};

export const init = async (
connection: Connection,
wallet: Wallet,
tokenManagerId: PublicKey,
paymentAmount: number
claimApproverParams: ClaimApproverParams
): Promise<[TransactionInstruction, PublicKey]> => {
const { paymentMint, paymentAmount } = claimApproverParams;
const provider = new Provider(connection, wallet, {});

const claimApproverProgram = new Program<CLAIM_APPROVER_PROGRAM>(
Expand All @@ -33,7 +39,7 @@ export const init = async (
);

return [
claimApproverProgram.instruction.init(new BN(paymentAmount), {
claimApproverProgram.instruction.init(paymentMint, new BN(paymentAmount), {
accounts: {
tokenManager: tokenManagerId,
claimApprover: claimApproverId,
Expand Down
13 changes: 6 additions & 7 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import {
tokenManager,
useInvalidator,
} from "./programs";
import type { ClaimApproverParams } from "./programs/claimApprover/instruction";
import type { TimeInvalidationParams } from "./programs/timeInvalidator/instruction";
import { InvalidationType, TokenManagerKind } from "./programs/tokenManager";
import { tokenManagerAddressFromMint } from "./programs/tokenManager/pda";
import { withRemainingAccountsForReturn } from "./programs/tokenManager/utils";
import { tryGetAccount, withFindOrInitAssociatedTokenAccount } from "./utils";

export type IssueParameters = {
paymentAmount?: number;
paymentMint?: PublicKey;
claimPayment?: ClaimApproverParams;
timeInvalidation?: TimeInvalidationParams;
usages?: number;
mint: PublicKey;
Expand All @@ -50,8 +50,7 @@ export const withIssueToken = async (
connection: Connection,
wallet: Wallet,
{
paymentAmount,
paymentMint,
claimPayment,
timeInvalidation,
usages,
mint,
Expand All @@ -77,7 +76,7 @@ export const withIssueToken = async (
/////// claim approver ///////
//////////////////////////////
let otp;
if (paymentAmount && paymentMint) {
if (claimPayment) {
if (visibility === "private") {
throw new Error("Private links do not currently support payment");
}
Expand All @@ -88,7 +87,7 @@ export const withIssueToken = async (
connection,
wallet,
tokenManagerId,
paymentMint
claimPayment.paymentMint
)
);

Expand All @@ -98,7 +97,7 @@ export const withIssueToken = async (
connection,
wallet,
tokenManagerId,
paymentAmount
claimPayment
);
transaction.add(paidClaimApproverIx);
transaction.add(
Expand Down
6 changes: 4 additions & 2 deletions tests/createAndExtendRental.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ describe("Create and Extend Rental", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
timeInvalidation: {
durationSeconds: 1000,
extension: {
Expand Down
12 changes: 8 additions & 4 deletions tests/createInvalidateCreate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ describe("Invalidate rentals", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
usages: 1,
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down Expand Up @@ -206,8 +208,10 @@ describe("Invalidate rentals", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
usages: 1,
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down
12 changes: 8 additions & 4 deletions tests/createMultipleRentals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ describe("Multiple rentals", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
timeInvalidation: { expiration: Date.now() / 1000 + 1 },
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down Expand Up @@ -127,8 +129,10 @@ describe("Multiple rentals", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
timeInvalidation: { expiration: Date.now() / 1000 + 1 },
mint: rentalMint2.publicKey,
issuerTokenAccountId: issuerTokenAccountId2,
Expand Down
6 changes: 4 additions & 2 deletions tests/createRentalMasterEdition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ describe("Master editions", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
timeInvalidation: { expiration: Date.now() / 1000 + 1 },
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down
6 changes: 4 additions & 2 deletions tests/createRentalMasterEditionInvalidate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ describe("Master editions", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
usages: 1,
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down
6 changes: 4 additions & 2 deletions tests/issueInvalidatePaidToken.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ describe("Issue Invalidate", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
timeInvalidation: { expiration: Date.now() / 1000 + 1 },
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down
6 changes: 4 additions & 2 deletions tests/issueUnissue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ describe("Issue Unissue", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
timeInvalidation: { expiration: Date.now() / 1000 + 1 },
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down
6 changes: 4 additions & 2 deletions tests/receipts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ describe("Issue claim receipt invalidate", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
usages: 1,
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down
6 changes: 4 additions & 2 deletions tests/useUnlimited.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ describe("Use without use invalidator", () => {
provider.connection,
provider.wallet,
{
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
claimPayment: {
paymentAmount: RENTAL_PAYMENT_AMONT,
paymentMint: paymentMint.publicKey,
},
timeInvalidation: { expiration: Date.now() / 1000 + 1 },
mint: rentalMint.publicKey,
issuerTokenAccountId: issuerTokenAccountId,
Expand Down

0 comments on commit 671ceff

Please sign in to comment.