diff --git a/programs/cardinal-paid-claim-approver/src/instructions/init.rs b/programs/cardinal-paid-claim-approver/src/instructions/init.rs index 07211b1d0..843afe7b0 100644 --- a/programs/cardinal-paid-claim-approver/src/instructions/init.rs +++ b/programs/cardinal-paid-claim-approver/src/instructions/init.rs @@ -26,9 +26,11 @@ pub struct InitCtx<'info> { system_program: Program<'info, System>, } -pub fn handler(ctx: Context, payment_amount: u64) -> ProgramResult { +pub fn handler(ctx: Context, 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(()) } \ No newline at end of file diff --git a/programs/cardinal-paid-claim-approver/src/lib.rs b/programs/cardinal-paid-claim-approver/src/lib.rs index e871ce698..48546b391 100644 --- a/programs/cardinal-paid-claim-approver/src/lib.rs +++ b/programs/cardinal-paid-claim-approver/src/lib.rs @@ -10,8 +10,8 @@ declare_id!("pcaBwhJ1YHp7UDA7HASpQsRUmUNwzgYaLQto2kSj1fR"); pub mod cardinal_paid_claim_approver { use super::*; - pub fn init(ctx: Context, payment_amount: u64) -> ProgramResult { - init::handler(ctx, payment_amount) + pub fn init(ctx: Context, payment_mint: Pubkey, payment_amount: u64) -> ProgramResult { + init::handler(ctx, payment_mint, payment_amount) } pub fn pay(ctx: Context) -> ProgramResult { diff --git a/programs/cardinal-paid-claim-approver/src/state.rs b/programs/cardinal-paid-claim-approver/src/state.rs index 56ea96881..9cb768a02 100644 --- a/programs/cardinal-paid-claim-approver/src/state.rs +++ b/programs/cardinal-paid-claim-approver/src/state.rs @@ -6,4 +6,6 @@ pub const PAID_CLAIM_APPROVER_SIZE: usize = 8 + std::mem::size_of:: => { + const { paymentMint, paymentAmount } = claimApproverParams; const provider = new Provider(connection, wallet, {}); const claimApproverProgram = new Program( @@ -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, diff --git a/src/transaction.ts b/src/transaction.ts index 35e37ddad..d48765d00 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -15,6 +15,7 @@ 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"; @@ -22,8 +23,7 @@ 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; @@ -50,8 +50,7 @@ export const withIssueToken = async ( connection: Connection, wallet: Wallet, { - paymentAmount, - paymentMint, + claimPayment, timeInvalidation, usages, mint, @@ -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"); } @@ -88,7 +87,7 @@ export const withIssueToken = async ( connection, wallet, tokenManagerId, - paymentMint + claimPayment.paymentMint ) ); @@ -98,7 +97,7 @@ export const withIssueToken = async ( connection, wallet, tokenManagerId, - paymentAmount + claimPayment ); transaction.add(paidClaimApproverIx); transaction.add( diff --git a/tests/createAndExtendRental.spec.ts b/tests/createAndExtendRental.spec.ts index 2c84fae88..e0ec0b495 100644 --- a/tests/createAndExtendRental.spec.ts +++ b/tests/createAndExtendRental.spec.ts @@ -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: { diff --git a/tests/createInvalidateCreate.spec.ts b/tests/createInvalidateCreate.spec.ts index 4b6c4f7d5..5deaf63c3 100644 --- a/tests/createInvalidateCreate.spec.ts +++ b/tests/createInvalidateCreate.spec.ts @@ -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, @@ -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, diff --git a/tests/createMultipleRentals.spec.ts b/tests/createMultipleRentals.spec.ts index 8e33969ad..903e538ad 100644 --- a/tests/createMultipleRentals.spec.ts +++ b/tests/createMultipleRentals.spec.ts @@ -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, @@ -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, diff --git a/tests/createRentalMasterEdition.spec.ts b/tests/createRentalMasterEdition.spec.ts index b9697edc4..2a9bc5697 100644 --- a/tests/createRentalMasterEdition.spec.ts +++ b/tests/createRentalMasterEdition.spec.ts @@ -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, diff --git a/tests/createRentalMasterEditionInvalidate.spec.ts b/tests/createRentalMasterEditionInvalidate.spec.ts index 2d5b0a0b6..627c849f0 100644 --- a/tests/createRentalMasterEditionInvalidate.spec.ts +++ b/tests/createRentalMasterEditionInvalidate.spec.ts @@ -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, diff --git a/tests/issueInvalidatePaidToken.spec.ts b/tests/issueInvalidatePaidToken.spec.ts index a031e40e3..511a53a8b 100644 --- a/tests/issueInvalidatePaidToken.spec.ts +++ b/tests/issueInvalidatePaidToken.spec.ts @@ -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, diff --git a/tests/issueUnissue.spec.ts b/tests/issueUnissue.spec.ts index 2ec466e14..6303acb1a 100644 --- a/tests/issueUnissue.spec.ts +++ b/tests/issueUnissue.spec.ts @@ -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, diff --git a/tests/receipts.spec.ts b/tests/receipts.spec.ts index eadb28241..62df41f25 100644 --- a/tests/receipts.spec.ts +++ b/tests/receipts.spec.ts @@ -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, diff --git a/tests/useUnlimited.spec.ts b/tests/useUnlimited.spec.ts index 75cb55de4..fce76b93b 100644 --- a/tests/useUnlimited.spec.ts +++ b/tests/useUnlimited.spec.ts @@ -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,