diff --git a/Cargo.lock b/Cargo.lock index c9d7da338..46eca12b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,7 +412,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cardinal-paid-claim-approver" -version = "0.0.6" +version = "0.0.10" dependencies = [ "anchor-lang", "anchor-spl", @@ -426,7 +426,7 @@ dependencies = [ [[package]] name = "cardinal-payment-manager" -version = "0.0.6" +version = "0.0.10" dependencies = [ "anchor-lang", "anchor-spl", @@ -439,7 +439,7 @@ dependencies = [ [[package]] name = "cardinal-rent-receipt" -version = "0.0.6" +version = "0.0.10" dependencies = [ "anchor-lang", "anchor-spl", @@ -452,7 +452,7 @@ dependencies = [ [[package]] name = "cardinal-rental-counter" -version = "0.0.6" +version = "0.0.10" dependencies = [ "anchor-lang", "anchor-spl", @@ -465,7 +465,7 @@ dependencies = [ [[package]] name = "cardinal-time-invalidator" -version = "0.0.6" +version = "0.0.10" dependencies = [ "anchor-lang", "anchor-spl", @@ -478,7 +478,7 @@ dependencies = [ [[package]] name = "cardinal-token-manager" -version = "0.0.6" +version = "0.0.10" dependencies = [ "anchor-lang", "anchor-spl", @@ -492,7 +492,7 @@ dependencies = [ [[package]] name = "cardinal-use-invalidator" -version = "0.0.6" +version = "0.0.10" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/package.json b/package.json index 0525a5b25..424842005 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cardinal/token-manager", - "version": "0.0.9", + "version": "0.0.10", "description": "Cardinal token manager SDK", "keywords": [ "solana", diff --git a/programs/cardinal-paid-claim-approver/Cargo.toml b/programs/cardinal-paid-claim-approver/Cargo.toml index 689979c5d..a9a691337 100644 --- a/programs/cardinal-paid-claim-approver/Cargo.toml +++ b/programs/cardinal-paid-claim-approver/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardinal-paid-claim-approver" -version = "0.0.6" +version = "0.0.10" description = "Cardinal paid claim approver" edition = "2021" homepage = "https://cardinal.so" @@ -25,8 +25,8 @@ anchor-spl = "0.20.1" spl-associated-token-account = "1.0.2" spl-token = { version = "3.1.1", features = ["no-entrypoint"] } solana-program = "1.8.1" -cardinal-token-manager = { version = "^0.0.6", path = "../cardinal-token-manager", features = ["cpi"] } -cardinal-payment-manager = { version = "^0.0.6", path = "../cardinal-payment-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.10", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-payment-manager = { version = "^0.0.10", path = "../cardinal-payment-manager", features = ["cpi"] } [dev-dependencies] proptest = { version = "1.0" } \ No newline at end of file diff --git a/programs/cardinal-payment-manager/Cargo.toml b/programs/cardinal-payment-manager/Cargo.toml index 95054b45a..461bdf8f0 100644 --- a/programs/cardinal-payment-manager/Cargo.toml +++ b/programs/cardinal-payment-manager/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardinal-payment-manager" -version = "0.0.6" +version = "0.0.10" description = "Cardinal paid claim approver" edition = "2021" homepage = "https://cardinal.so" @@ -25,7 +25,7 @@ anchor-spl = "0.20.1" spl-associated-token-account = "1.0.2" spl-token = { version = "3.1.1", features = ["no-entrypoint"] } solana-program = "1.8.1" -cardinal-token-manager = { version = "^0.0.6", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.10", path = "../cardinal-token-manager", features = ["cpi"] } [dev-dependencies] proptest = { version = "1.0" } \ No newline at end of file diff --git a/programs/cardinal-rent-receipt/Cargo.toml b/programs/cardinal-rent-receipt/Cargo.toml index 16618b341..fc92e1e84 100644 --- a/programs/cardinal-rent-receipt/Cargo.toml +++ b/programs/cardinal-rent-receipt/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardinal-rent-receipt" -version = "0.0.6" +version = "0.0.10" description = "Cardinal paid claim approver" edition = "2021" homepage = "https://cardinal.so" @@ -25,7 +25,7 @@ anchor-spl = "0.20.1" spl-associated-token-account = "1.0.2" spl-token = { version = "3.1.1", features = ["no-entrypoint"] } solana-program = "1.8.1" -cardinal-token-manager = { version = "^0.0.6", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.10", path = "../cardinal-token-manager", features = ["cpi"] } [dev-dependencies] proptest = { version = "1.0" } \ No newline at end of file diff --git a/programs/cardinal-rent-receipt/src/instructions/claim.rs b/programs/cardinal-rent-receipt/src/instructions/claim.rs index 06378ac52..72eb491bf 100644 --- a/programs/cardinal-rent-receipt/src/instructions/claim.rs +++ b/programs/cardinal-rent-receipt/src/instructions/claim.rs @@ -1,7 +1,7 @@ use { crate::{state::*}, anchor_lang::{prelude::*}, - cardinal_token_manager::{program::CardinalTokenManager, state::{TokenManagerKind, TokenManager}, instructions::IssueIx}, + cardinal_token_manager::{program::CardinalTokenManager, state::{TokenManagerKind, TokenManager, InvalidationType}, instructions::IssueIx}, anchor_spl::{token::{Token}} }; @@ -67,7 +67,7 @@ pub fn handler(ctx: Context, bump: u8, receipt_token_manager_bump: u8) system_program: ctx.accounts.system_program.to_account_info(), }; let issue_ctx = CpiContext::new(ctx.accounts.cardinal_token_manager.to_account_info(), cpi_accounts).with_signer(rent_receipt_signer); - cardinal_token_manager::cpi::issue(issue_ctx, IssueIx{amount: 1, kind: TokenManagerKind::Managed as u8})?; + cardinal_token_manager::cpi::issue(issue_ctx, IssueIx{amount: 1, kind: TokenManagerKind::Managed as u8, invalidation_type: InvalidationType::Return as u8 })?; let cpi_accounts = cardinal_token_manager::cpi::accounts::ClaimCtx { token_manager: ctx.accounts.receipt_token_manager.to_account_info(), diff --git a/programs/cardinal-rental-counter/Cargo.toml b/programs/cardinal-rental-counter/Cargo.toml index 23d65330b..94ed2c389 100644 --- a/programs/cardinal-rental-counter/Cargo.toml +++ b/programs/cardinal-rental-counter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardinal-rental-counter" -version = "0.0.6" +version = "0.0.10" description = "Cardinal paid claim approver" edition = "2021" homepage = "https://cardinal.so" @@ -25,7 +25,7 @@ anchor-spl = "0.20.1" spl-associated-token-account = "1.0.2" spl-token = { version = "3.1.1", features = ["no-entrypoint"] } solana-program = "1.8.1" -cardinal-token-manager = { version = "^0.0.6", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.10", path = "../cardinal-token-manager", features = ["cpi"] } [dev-dependencies] proptest = { version = "1.0" } \ No newline at end of file diff --git a/programs/cardinal-time-invalidator/Cargo.toml b/programs/cardinal-time-invalidator/Cargo.toml index de2d0ae45..4ffdf025d 100644 --- a/programs/cardinal-time-invalidator/Cargo.toml +++ b/programs/cardinal-time-invalidator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardinal-time-invalidator" -version = "0.0.6" +version = "0.0.10" description = "Program for a invalidating token managers based on time" edition = "2021" homepage = "https://cardinal.so" @@ -25,7 +25,7 @@ anchor-spl = "0.20.1" spl-associated-token-account = "1.0.2" spl-token = { version = "3.1.1", features = ["no-entrypoint"] } solana-program = "1.8.1" -cardinal-token-manager = { version = "^0.0.6", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.10", path = "../cardinal-token-manager", features = ["cpi"] } [dev-dependencies] proptest = { version = "1.0" } \ No newline at end of file diff --git a/programs/cardinal-token-manager/Cargo.toml b/programs/cardinal-token-manager/Cargo.toml index 84bfa1003..a300ca10a 100644 --- a/programs/cardinal-token-manager/Cargo.toml +++ b/programs/cardinal-token-manager/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardinal-token-manager" -version = "0.0.6" +version = "0.0.10" description = "Cardinal token manager" edition = "2021" homepage = "https://cardinal.so" diff --git a/programs/cardinal-token-manager/src/errors.rs b/programs/cardinal-token-manager/src/errors.rs index e22e6626c..b1409fd3c 100644 --- a/programs/cardinal-token-manager/src/errors.rs +++ b/programs/cardinal-token-manager/src/errors.rs @@ -16,6 +16,8 @@ pub enum ErrorCode { InvalidInvalidatorTokenAccount, #[msg("Token manager kind is not valid")] InvalidTokenManagerKind, + #[msg("Invalid invalidation type")] + InvalidInvalidationType, #[msg("Invalid claim authority")] InvalidClaimAuthority, #[msg("Invalid transfer authority")] diff --git a/programs/cardinal-token-manager/src/instructions/invalidate.rs b/programs/cardinal-token-manager/src/instructions/invalidate.rs index 89eaa6d06..54d72bfe6 100644 --- a/programs/cardinal-token-manager/src/instructions/invalidate.rs +++ b/programs/cardinal-token-manager/src/instructions/invalidate.rs @@ -46,9 +46,8 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts, let token_manager_seeds = &[TOKEN_MANAGER_SEED.as_bytes(), mint.as_ref(), &[token_manager.bump]]; let token_manager_signer = &[&token_manager_seeds[..]]; - if token_manager.kind == TokenManagerKind::Managed as u8 { - // if claimed we need to thaw - if token_manager.state == TokenManagerState::Claimed as u8 { + if token_manager.state == TokenManagerState::Claimed as u8 { + if token_manager.kind == TokenManagerKind::Managed as u8 { // thaw recipient account let cpi_accounts = ThawAccount { account: ctx.accounts.recipient_token_account.to_account_info(), @@ -58,42 +57,35 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts, let cpi_program = ctx.accounts.token_program.to_account_info(); let cpi_context = CpiContext::new(cpi_program, cpi_accounts).with_signer(token_manager_signer); token::thaw_account(cpi_context)?; + + } else if token_manager.kind == TokenManagerKind::Edition as u8 { + let remaining_accs = &mut ctx.remaining_accounts.iter(); + let edition_info = next_account_info(remaining_accs)?; + let metadata_program = next_account_info(remaining_accs)?; + // edition will be validated by metadata_program + assert_keys_eq!(metadata_program.key, mpl_token_metadata::id()); + + invoke_signed( + &freeze_delegated_account( + *metadata_program.key, + token_manager.key(), + ctx.accounts.recipient_token_account.key(), + *edition_info.key, + ctx.accounts.mint.key(), + ), + &vec![ + token_manager.to_account_info(), + ctx.accounts.recipient_token_account.to_account_info(), + edition_info.to_account_info(), + ctx.accounts.mint.to_account_info(), + ], + &[token_manager_seeds], + )?; } - // transfer back to issuer - let cpi_accounts = Transfer { - from: ctx.accounts.recipient_token_account.to_account_info(), - to: ctx.accounts.issuer_token_account.to_account_info(), - authority: token_manager.to_account_info(), - }; - let cpi_program = ctx.accounts.token_program.to_account_info(); - let cpi_context = CpiContext::new(cpi_program, cpi_accounts).with_signer(token_manager_signer); - token::transfer(cpi_context, token_manager.amount)?; - } else if token_manager.kind == TokenManagerKind::Edition as u8 { - let remaining_accs = &mut ctx.remaining_accounts.iter(); - let edition_info = next_account_info(remaining_accs)?; - let metadata_program = next_account_info(remaining_accs)?; - - // edition will be validated by metadata_program - assert_keys_eq!(metadata_program.key, mpl_token_metadata::id()); - - invoke_signed( - &freeze_delegated_account( - *metadata_program.key, - token_manager.key(), - ctx.accounts.recipient_token_account.key(), - *edition_info.key, - ctx.accounts.mint.key(), - ), - &vec![ - token_manager.to_account_info(), - ctx.accounts.recipient_token_account.to_account_info(), - edition_info.to_account_info(), - ctx.accounts.mint.to_account_info(), - ], - &[token_manager_seeds], - )?; + } + if token_manager.invalidation_type == InvalidationType::Return as u8 { // transfer back to issuer let cpi_accounts = Transfer { from: ctx.accounts.recipient_token_account.to_account_info(), @@ -104,7 +96,7 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts, let cpi_context = CpiContext::new(cpi_program, cpi_accounts).with_signer(token_manager_signer); token::transfer(cpi_context, token_manager.amount)?; } - + token_manager.state = TokenManagerState::Invalidated as u8; // close token_manager_token_account diff --git a/programs/cardinal-token-manager/src/instructions/issue.rs b/programs/cardinal-token-manager/src/instructions/issue.rs index a2823c7f8..6240c45f8 100644 --- a/programs/cardinal-token-manager/src/instructions/issue.rs +++ b/programs/cardinal-token-manager/src/instructions/issue.rs @@ -8,6 +8,7 @@ use { pub struct IssueIx { pub amount: u64, pub kind: u8, + pub invalidation_type: u8, } #[derive(Accounts)] @@ -40,11 +41,17 @@ pub fn handler(ctx: Context, ix: IssueIx) -> ProgramResult { && ix.kind != TokenManagerKind::Edition as u8 { return Err(ErrorCode::InvalidTokenManagerKind.into()); } + if ix.invalidation_type != InvalidationType::Return as u8 + && ix.invalidation_type != InvalidationType::Invalidate as u8 { + return Err(ErrorCode::InvalidInvalidationType.into()); + } + // set token manager data let token_manager = &mut ctx.accounts.token_manager; token_manager.mint = ctx.accounts.mint.key(); token_manager.amount = ix.amount; token_manager.kind = ix.kind; + token_manager.invalidation_type = ix.invalidation_type; token_manager.state = TokenManagerState::Issued as u8; // transfer token to token manager token account diff --git a/programs/cardinal-token-manager/src/state.rs b/programs/cardinal-token-manager/src/state.rs index 9d9f94315..0744ab471 100644 --- a/programs/cardinal-token-manager/src/state.rs +++ b/programs/cardinal-token-manager/src/state.rs @@ -25,8 +25,17 @@ pub enum TokenManagerKind { Edition = 3, } +#[derive(Clone, Debug, PartialEq, AnchorSerialize, AnchorDeserialize)] +#[repr(u8)] +pub enum InvalidationType { + /// Upon invalidation it will be returned to the issuer + Return = 1, + /// Upon invalidation it will remain marked as invalid + Invalidate = 2, +} + pub fn token_manager_size(num_invalidators: usize) -> usize { - return (8 + 32 + 1 + 1 + 32 + 32 + 8 + 1 + 1 + 32 + 32 + 32 + 32 + num_invalidators * 32) + 8 as usize + return (8 + 32 + 1 + 1 + 32 + 32 + 8 + 1 + 1 + 1 + 32 + 32 + 32 + 32 + num_invalidators * 32) + 8 as usize } pub const MAX_INVALIDATORS: u8 = 5; @@ -40,6 +49,7 @@ pub struct TokenManager { pub amount: u64, pub kind: u8, pub state: u8, + pub invalidation_type: u8, pub recipient_token_account: Pubkey, pub payment_manager: Option, pub claim_approver: Option, diff --git a/programs/cardinal-use-invalidator/Cargo.toml b/programs/cardinal-use-invalidator/Cargo.toml index 50aa62292..44af34c09 100644 --- a/programs/cardinal-use-invalidator/Cargo.toml +++ b/programs/cardinal-use-invalidator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardinal-use-invalidator" -version = "0.0.6" +version = "0.0.10" description = "Cardinal usage invalidator and counter" edition = "2021" homepage = "https://cardinal.so" @@ -25,7 +25,7 @@ anchor-spl = "0.20.1" spl-associated-token-account = "1.0.2" spl-token = { version = "3.1.1", features = ["no-entrypoint"] } solana-program = "1.8.1" -cardinal-token-manager = { version = "^0.0.6", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.10", path = "../cardinal-token-manager", features = ["cpi"] } [dev-dependencies] proptest = { version = "1.0" } \ No newline at end of file diff --git a/src/claimLinks.ts b/src/claimLinks.ts index 2c720fb3c..7a56d969b 100644 --- a/src/claimLinks.ts +++ b/src/claimLinks.ts @@ -8,9 +8,10 @@ import { } from "@solana/spl-token"; import type { Connection, PublicKey } from "@solana/web3.js"; import { Keypair, Transaction } from "@solana/web3.js"; +import { tryGetAccount } from "."; import { tokenManager, useInvalidator } from "./programs"; -import { TokenManagerKind } from "./programs/tokenManager"; +import { InvalidationType, TokenManagerKind } from "./programs/tokenManager"; import { findTokenManagerAddress } from "./programs/tokenManager/pda"; import { withFindOrInitAssociatedTokenAccount } from "./utils"; @@ -54,12 +55,14 @@ export const issueToken = async ( usages = 1, amount = new BN(1), kind = TokenManagerKind.Managed, + invalidationType = InvalidationType.Return, }: { rentalMint: PublicKey; issuerTokenAccountId: PublicKey; usages?: number; amount?: BN; kind?: TokenManagerKind; + invalidationType?: InvalidationType; } ): Promise<[Transaction, PublicKey, Keypair]> => { const otp = Keypair.generate(); @@ -122,7 +125,8 @@ export const issueToken = async ( rentalMint, tokenManagerTokenAccountId, issuerTokenAccountId, - kind + kind, + invalidationType ) ); @@ -196,6 +200,25 @@ export const useTransaction = async ( const transaction = new Transaction(); const [tokenManagerId] = await findTokenManagerAddress(mintId); + const [useInvalidatorId] = await useInvalidator.pda.findUseInvalidatorAddress( + tokenManagerId + ); + + const useInvalidatorData = await tryGetAccount(() => + useInvalidator.accounts.getUseInvalidator(connection, useInvalidatorId) + ); + + if (!useInvalidatorData) { + // init + const [InitTx] = await useInvalidator.instruction.init( + connection, + wallet, + tokenManagerId, + null + ); + transaction.add(InitTx); + } + // use transaction.add( await useInvalidator.instruction.incrementUsages( diff --git a/src/idl/cardinal_paid_claim_approver.ts b/src/idl/cardinal_paid_claim_approver.ts index 919ce8bef..7ad3c650b 100644 --- a/src/idl/cardinal_paid_claim_approver.ts +++ b/src/idl/cardinal_paid_claim_approver.ts @@ -1,295 +1,295 @@ export type CardinalPaidClaimApprover = { - "version": "0.0.0", - "name": "cardinal_paid_claim_approver", - "instructions": [ + version: "0.0.0"; + name: "cardinal_paid_claim_approver"; + instructions: [ { - "name": "init", - "accounts": [ + name: "init"; + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager"; + isMut: false; + isSigner: false; }, { - "name": "paymentManager", - "isMut": false, - "isSigner": false + name: "paymentManager"; + isMut: false; + isSigner: false; }, { - "name": "claimApprover", - "isMut": true, - "isSigner": false + name: "claimApprover"; + isMut: true; + isSigner: false; }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer"; + isMut: true; + isSigner: true; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "paymentAmount", - "type": "u64" + name: "paymentAmount"; + type: "u64"; } - ] + ]; }, { - "name": "pay", - "accounts": [ + name: "pay"; + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager"; + isMut: false; + isSigner: false; }, { - "name": "paymentManager", - "isMut": false, - "isSigner": false + name: "paymentManager"; + isMut: false; + isSigner: false; }, { - "name": "paymentManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "paymentManagerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "claimApprover", - "isMut": true, - "isSigner": false + name: "claimApprover"; + isMut: true; + isSigner: false; }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer"; + isMut: true; + isSigner: true; }, { - "name": "payerTokenAccount", - "isMut": true, - "isSigner": false + name: "payerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "claimReceipt", - "isMut": true, - "isSigner": false + name: "claimReceipt"; + isMut: true; + isSigner: false; }, { - "name": "cardinalTokenManager", - "isMut": false, - "isSigner": false + name: "cardinalTokenManager"; + isMut: false; + isSigner: false; }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram"; + isMut: false; + isSigner: false; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "claimReceiptBump", - "type": "u8" + name: "claimReceiptBump"; + type: "u8"; } - ] + ]; } - ], - "accounts": [ + ]; + accounts: [ { - "name": "paidClaimApprover", - "type": { - "kind": "struct", - "fields": [ + name: "paidClaimApprover"; + type: { + kind: "struct"; + fields: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "paymentAmount", - "type": "u64" + name: "paymentAmount"; + type: "u64"; } - ] - } + ]; + }; } - ], - "errors": [ + ]; + errors: [ { - "code": 300, - "name": "InvalidPaymentTokenAccount", - "msg": "Token account not owned by the claim approver" + code: 300; + name: "InvalidPaymentTokenAccount"; + msg: "Token account not owned by the claim approver"; }, { - "code": 301, - "name": "InvalidPayerTokenAccount", - "msg": "Token account not owned by the payer" + code: 301; + name: "InvalidPayerTokenAccount"; + msg: "Token account not owned by the payer"; }, { - "code": 302, - "name": "InvalidTokenManager", - "msg": "Invalid token manager for this claim approver" + code: 302; + name: "InvalidTokenManager"; + msg: "Invalid token manager for this claim approver"; }, { - "code": 303, - "name": "InvalidPaymentManager", - "msg": "Payment manager is invalid" + code: 303; + name: "InvalidPaymentManager"; + msg: "Payment manager is invalid"; } - ] + ]; }; export const IDL: CardinalPaidClaimApprover = { - "version": "0.0.0", - "name": "cardinal_paid_claim_approver", - "instructions": [ + version: "0.0.0", + name: "cardinal_paid_claim_approver", + instructions: [ { - "name": "init", - "accounts": [ + name: "init", + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager", + isMut: false, + isSigner: false, }, { - "name": "paymentManager", - "isMut": false, - "isSigner": false + name: "paymentManager", + isMut: false, + isSigner: false, }, { - "name": "claimApprover", - "isMut": true, - "isSigner": false + name: "claimApprover", + isMut: true, + isSigner: false, }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer", + isMut: true, + isSigner: true, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "paymentAmount", - "type": "u64" - } - ] + name: "paymentAmount", + type: "u64", + }, + ], }, { - "name": "pay", - "accounts": [ + name: "pay", + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager", + isMut: false, + isSigner: false, }, { - "name": "paymentManager", - "isMut": false, - "isSigner": false + name: "paymentManager", + isMut: false, + isSigner: false, }, { - "name": "paymentManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "paymentManagerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "claimApprover", - "isMut": true, - "isSigner": false + name: "claimApprover", + isMut: true, + isSigner: false, }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer", + isMut: true, + isSigner: true, }, { - "name": "payerTokenAccount", - "isMut": true, - "isSigner": false + name: "payerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "claimReceipt", - "isMut": true, - "isSigner": false + name: "claimReceipt", + isMut: true, + isSigner: false, }, { - "name": "cardinalTokenManager", - "isMut": false, - "isSigner": false + name: "cardinalTokenManager", + isMut: false, + isSigner: false, }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram", + isMut: false, + isSigner: false, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "claimReceiptBump", - "type": "u8" - } - ] - } + name: "claimReceiptBump", + type: "u8", + }, + ], + }, ], - "accounts": [ + accounts: [ { - "name": "paidClaimApprover", - "type": { - "kind": "struct", - "fields": [ + name: "paidClaimApprover", + type: { + kind: "struct", + fields: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "paymentAmount", - "type": "u64" - } - ] - } - } + name: "paymentAmount", + type: "u64", + }, + ], + }, + }, ], - "errors": [ + errors: [ { - "code": 300, - "name": "InvalidPaymentTokenAccount", - "msg": "Token account not owned by the claim approver" + code: 300, + name: "InvalidPaymentTokenAccount", + msg: "Token account not owned by the claim approver", }, { - "code": 301, - "name": "InvalidPayerTokenAccount", - "msg": "Token account not owned by the payer" + code: 301, + name: "InvalidPayerTokenAccount", + msg: "Token account not owned by the payer", }, { - "code": 302, - "name": "InvalidTokenManager", - "msg": "Invalid token manager for this claim approver" + code: 302, + name: "InvalidTokenManager", + msg: "Invalid token manager for this claim approver", }, { - "code": 303, - "name": "InvalidPaymentManager", - "msg": "Payment manager is invalid" - } - ] + code: 303, + name: "InvalidPaymentManager", + msg: "Payment manager is invalid", + }, + ], }; diff --git a/src/idl/cardinal_payment_manager.ts b/src/idl/cardinal_payment_manager.ts index c18341a48..7a44985fa 100644 --- a/src/idl/cardinal_payment_manager.ts +++ b/src/idl/cardinal_payment_manager.ts @@ -1,227 +1,227 @@ export type CardinalPaymentManager = { - "version": "0.0.0", - "name": "cardinal_payment_manager", - "instructions": [ + version: "0.0.0"; + name: "cardinal_payment_manager"; + instructions: [ { - "name": "init", - "accounts": [ + name: "init"; + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager"; + isMut: false; + isSigner: false; }, { - "name": "paymentManager", - "isMut": true, - "isSigner": false + name: "paymentManager"; + isMut: true; + isSigner: false; }, { - "name": "paymentMint", - "isMut": false, - "isSigner": false + name: "paymentMint"; + isMut: false; + isSigner: false; }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer"; + isMut: true; + isSigner: true; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; } - ] + ]; }, { - "name": "settle", - "accounts": [ + name: "settle"; + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager"; + isMut: false; + isSigner: false; }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "paymentManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "paymentManagerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "paymentManager", - "isMut": true, - "isSigner": false + name: "paymentManager"; + isMut: true; + isSigner: false; }, { - "name": "invalidator", - "isMut": true, - "isSigner": true + name: "invalidator"; + isMut: true; + isSigner: true; }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram"; + isMut: false; + isSigner: false; } - ], - "args": [] + ]; + args: []; } - ], - "accounts": [ + ]; + accounts: [ { - "name": "paymentManager", - "type": { - "kind": "struct", - "fields": [ + name: "paymentManager"; + type: { + kind: "struct"; + fields: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "paymentMint", - "type": "publicKey" + name: "paymentMint"; + type: "publicKey"; } - ] - } + ]; + }; } - ], - "errors": [ + ]; + errors: [ { - "code": 300, - "name": "InvalidPaymentTokenAccount", - "msg": "Token account not owned by the claim approver" + code: 300; + name: "InvalidPaymentTokenAccount"; + msg: "Token account not owned by the claim approver"; }, { - "code": 301, - "name": "InvalidIssuerTokenAccount", - "msg": "Token account not owned by the issuer" + code: 301; + name: "InvalidIssuerTokenAccount"; + msg: "Token account not owned by the issuer"; }, { - "code": 302, - "name": "InvalidTokenManager", - "msg": "Invalid token manager for this claim approver" + code: 302; + name: "InvalidTokenManager"; + msg: "Invalid token manager for this claim approver"; } - ] + ]; }; export const IDL: CardinalPaymentManager = { - "version": "0.0.0", - "name": "cardinal_payment_manager", - "instructions": [ + version: "0.0.0", + name: "cardinal_payment_manager", + instructions: [ { - "name": "init", - "accounts": [ + name: "init", + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager", + isMut: false, + isSigner: false, }, { - "name": "paymentManager", - "isMut": true, - "isSigner": false + name: "paymentManager", + isMut: true, + isSigner: false, }, { - "name": "paymentMint", - "isMut": false, - "isSigner": false + name: "paymentMint", + isMut: false, + isSigner: false, }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer", + isMut: true, + isSigner: true, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "bump", - "type": "u8" - } - ] + name: "bump", + type: "u8", + }, + ], }, { - "name": "settle", - "accounts": [ + name: "settle", + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager", + isMut: false, + isSigner: false, }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "paymentManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "paymentManagerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "paymentManager", - "isMut": true, - "isSigner": false + name: "paymentManager", + isMut: true, + isSigner: false, }, { - "name": "invalidator", - "isMut": true, - "isSigner": true + name: "invalidator", + isMut: true, + isSigner: true, }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false - } + name: "tokenProgram", + isMut: false, + isSigner: false, + }, ], - "args": [] - } + args: [], + }, ], - "accounts": [ + accounts: [ { - "name": "paymentManager", - "type": { - "kind": "struct", - "fields": [ + name: "paymentManager", + type: { + kind: "struct", + fields: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "paymentMint", - "type": "publicKey" - } - ] - } - } + name: "paymentMint", + type: "publicKey", + }, + ], + }, + }, ], - "errors": [ + errors: [ { - "code": 300, - "name": "InvalidPaymentTokenAccount", - "msg": "Token account not owned by the claim approver" + code: 300, + name: "InvalidPaymentTokenAccount", + msg: "Token account not owned by the claim approver", }, { - "code": 301, - "name": "InvalidIssuerTokenAccount", - "msg": "Token account not owned by the issuer" + code: 301, + name: "InvalidIssuerTokenAccount", + msg: "Token account not owned by the issuer", }, { - "code": 302, - "name": "InvalidTokenManager", - "msg": "Invalid token manager for this claim approver" - } - ] + code: 302, + name: "InvalidTokenManager", + msg: "Invalid token manager for this claim approver", + }, + ], }; diff --git a/src/idl/cardinal_token_manager.ts b/src/idl/cardinal_token_manager.ts index 08cd0fc45..97ea71540 100644 --- a/src/idl/cardinal_token_manager.ts +++ b/src/idl/cardinal_token_manager.ts @@ -1,1125 +1,1179 @@ export type CardinalTokenManager = { - "version": "0.0.0", - "name": "cardinal_token_manager", - "instructions": [ + version: "0.0.0"; + name: "cardinal_token_manager"; + instructions: [ { - "name": "init", - "accounts": [ + name: "init"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer"; + isMut: true; + isSigner: true; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "mint", - "type": "publicKey" + name: "mint"; + type: "publicKey"; }, { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "numInvalidators", - "type": "u8" + name: "numInvalidators"; + type: "u8"; } - ] + ]; }, { - "name": "setPaymentManager", - "accounts": [ + name: "setPaymentManager"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer"; + isMut: true; + isSigner: true; } - ], - "args": [ + ]; + args: [ { - "name": "paymentManager", - "type": "publicKey" + name: "paymentManager"; + type: "publicKey"; } - ] + ]; }, { - "name": "setClaimApprover", - "accounts": [ + name: "setClaimApprover"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer"; + isMut: true; + isSigner: true; } - ], - "args": [ + ]; + args: [ { - "name": "claimApprover", - "type": "publicKey" + name: "claimApprover"; + type: "publicKey"; } - ] + ]; }, { - "name": "setTransferAuthority", - "accounts": [ + name: "setTransferAuthority"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer"; + isMut: true; + isSigner: true; } - ], - "args": [ + ]; + args: [ { - "name": "transferAuthority", - "type": "publicKey" + name: "transferAuthority"; + type: "publicKey"; } - ] + ]; }, { - "name": "addInvalidator", - "accounts": [ + name: "addInvalidator"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer"; + isMut: true; + isSigner: true; } - ], - "args": [ + ]; + args: [ { - "name": "invalidator", - "type": "publicKey" + name: "invalidator"; + type: "publicKey"; } - ] + ]; }, { - "name": "createClaimReceipt", - "accounts": [ + name: "createClaimReceipt"; + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager"; + isMut: false; + isSigner: false; }, { - "name": "claimApprover", - "isMut": false, - "isSigner": true + name: "claimApprover"; + isMut: false; + isSigner: true; }, { - "name": "claimReceipt", - "isMut": true, - "isSigner": false + name: "claimReceipt"; + isMut: true; + isSigner: false; }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer"; + isMut: true; + isSigner: true; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "target", - "type": "publicKey" + name: "target"; + type: "publicKey"; } - ] + ]; }, { - "name": "createTransferReceipt", - "accounts": [ + name: "createTransferReceipt"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "transferAuthority", - "isMut": true, - "isSigner": true + name: "transferAuthority"; + isMut: true; + isSigner: true; }, { - "name": "transferReceipt", - "isMut": true, - "isSigner": false + name: "transferReceipt"; + isMut: true; + isSigner: false; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "target", - "type": "publicKey" + name: "target"; + type: "publicKey"; } - ] + ]; }, { - "name": "issue", - "accounts": [ + name: "issue"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer"; + isMut: true; + isSigner: true; }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "mint", - "isMut": false, - "isSigner": false + name: "mint"; + isMut: false; + isSigner: false; }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer"; + isMut: true; + isSigner: true; }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram"; + isMut: false; + isSigner: false; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "ix", - "type": { - "defined": "IssueIx" - } + name: "ix"; + type: { + defined: "IssueIx"; + }; } - ] + ]; }, { - "name": "unissue", - "accounts": [ + name: "unissue"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer"; + isMut: true; + isSigner: true; }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram"; + isMut: false; + isSigner: false; } - ], - "args": [] + ]; + args: []; }, { - "name": "claim", - "accounts": [ + name: "claim"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "mint", - "isMut": false, - "isSigner": false + name: "mint"; + isMut: false; + isSigner: false; }, { - "name": "recipient", - "isMut": true, - "isSigner": true + name: "recipient"; + isMut: true; + isSigner: true; }, { - "name": "recipientTokenAccount", - "isMut": true, - "isSigner": false + name: "recipientTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram"; + isMut: false; + isSigner: false; } - ], - "args": [] + ]; + args: []; }, { - "name": "invalidate", - "accounts": [ + name: "invalidate"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "mint", - "isMut": true, - "isSigner": false + name: "mint"; + isMut: true; + isSigner: false; }, { - "name": "recipientTokenAccount", - "isMut": true, - "isSigner": false + name: "recipientTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount"; + isMut: true; + isSigner: false; }, { - "name": "invalidator", - "isMut": true, - "isSigner": true + name: "invalidator"; + isMut: true; + isSigner: true; }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram"; + isMut: false; + isSigner: false; } - ], - "args": [] + ]; + args: []; } - ], - "accounts": [ + ]; + accounts: [ { - "name": "tokenManager", - "type": { - "kind": "struct", - "fields": [ + name: "tokenManager"; + type: { + kind: "struct"; + fields: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "numInvalidators", - "type": "u8" + name: "numInvalidators"; + type: "u8"; }, { - "name": "issuer", - "type": "publicKey" + name: "issuer"; + type: "publicKey"; }, { - "name": "mint", - "type": "publicKey" + name: "mint"; + type: "publicKey"; }, { - "name": "amount", - "type": "u64" + name: "amount"; + type: "u64"; }, { - "name": "kind", - "type": "u8" + name: "kind"; + type: "u8"; }, { - "name": "state", - "type": "u8" + name: "state"; + type: "u8"; }, { - "name": "recipientTokenAccount", - "type": "publicKey" + name: "invalidationType"; + type: "u8"; }, { - "name": "paymentManager", - "type": { - "option": "publicKey" - } + name: "recipientTokenAccount"; + type: "publicKey"; }, { - "name": "claimApprover", - "type": { - "option": "publicKey" - } + name: "paymentManager"; + type: { + option: "publicKey"; + }; }, { - "name": "transferAuthority", - "type": { - "option": "publicKey" - } + name: "claimApprover"; + type: { + option: "publicKey"; + }; }, { - "name": "invalidators", - "type": { - "vec": "publicKey" - } + name: "transferAuthority"; + type: { + option: "publicKey"; + }; + }, + { + name: "invalidators"; + type: { + vec: "publicKey"; + }; } - ] - } + ]; + }; }, { - "name": "claimReceipt", - "type": { - "kind": "struct", - "fields": [] - } + name: "claimReceipt"; + type: { + kind: "struct"; + fields: []; + }; }, { - "name": "tranferReceipt", - "type": { - "kind": "struct", - "fields": [] - } + name: "tranferReceipt"; + type: { + kind: "struct"; + fields: []; + }; } - ], - "types": [ + ]; + types: [ { - "name": "IssueIx", - "type": { - "kind": "struct", - "fields": [ + name: "IssueIx"; + type: { + kind: "struct"; + fields: [ { - "name": "amount", - "type": "u64" + name: "amount"; + type: "u64"; }, { - "name": "kind", - "type": "u8" + name: "kind"; + type: "u8"; + }, + { + name: "invalidationType"; + type: "u8"; } - ] - } + ]; + }; }, { - "name": "TokenManagerState", - "type": { - "kind": "enum", - "variants": [ + name: "TokenManagerState"; + type: { + kind: "enum"; + variants: [ { - "name": "Initialized" + name: "Initialized"; }, { - "name": "Issued" + name: "Issued"; }, { - "name": "Claimed" + name: "Claimed"; }, { - "name": "Invalidated" + name: "Invalidated"; } - ] - } + ]; + }; }, { - "name": "TokenManagerKind", - "type": { - "kind": "enum", - "variants": [ + name: "TokenManagerKind"; + type: { + kind: "enum"; + variants: [ { - "name": "Managed" + name: "Managed"; }, { - "name": "Unmanaged" + name: "Unmanaged"; }, { - "name": "Edition" + name: "Edition"; } - ] - } + ]; + }; + }, + { + name: "InvalidationType"; + type: { + kind: "enum"; + variants: [ + { + name: "Return"; + }, + { + name: "Invalidate"; + } + ]; + }; } - ], - "errors": [ + ]; + errors: [ + { + code: 300; + name: "Uninitialized"; + msg: "Account not initialized"; + }, { - "code": 300, - "name": "Uninitialized", - "msg": "Account not initialized" + code: 301; + name: "TooManyInvalidators"; + msg: "Too many invalidators have already been added"; }, { - "code": 301, - "name": "TooManyInvalidators", - "msg": "Too many invalidators have already been added" + code: 302; + name: "InvalidTokenManagerTokenAccount"; + msg: "Token account not owned by token manager"; }, { - "code": 302, - "name": "InvalidTokenManagerTokenAccount", - "msg": "Token account not owned by token manager" + code: 303; + name: "InvalidIssuerTokenAccount"; + msg: "Token account not owned by issuer"; }, { - "code": 303, - "name": "InvalidIssuerTokenAccount", - "msg": "Token account not owned by issuer" + code: 304; + name: "InvalidRecipientTokenAccount"; + msg: "Token account not owned by recipient"; }, { - "code": 304, - "name": "InvalidRecipientTokenAccount", - "msg": "Token account not owned by recipient" + code: 305; + name: "InvalidInvalidatorTokenAccount"; + msg: "Token account not owned by invalidator"; }, { - "code": 305, - "name": "InvalidInvalidatorTokenAccount", - "msg": "Token account not owned by invalidator" + code: 306; + name: "InvalidTokenManagerKind"; + msg: "Token manager kind is not valid"; }, { - "code": 306, - "name": "InvalidTokenManagerKind", - "msg": "Token manager kind is not valid" + code: 307; + name: "InvalidInvalidationType"; + msg: "Invalid invalidation type"; }, { - "code": 307, - "name": "InvalidClaimAuthority", - "msg": "Invalid claim authority" + code: 308; + name: "InvalidClaimAuthority"; + msg: "Invalid claim authority"; }, { - "code": 308, - "name": "InvalidTransferAuthority", - "msg": "Invalid transfer authority" + code: 309; + name: "InvalidTransferAuthority"; + msg: "Invalid transfer authority"; }, { - "code": 309, - "name": "InvalidIssuer", - "msg": "Invalid issuer" + code: 310; + name: "InvalidIssuer"; + msg: "Invalid issuer"; }, { - "code": 310, - "name": "InvalidInvalidator", - "msg": "Invalid invalidator" + code: 311; + name: "InvalidInvalidator"; + msg: "Invalid invalidator"; }, { - "code": 311, - "name": "InvalidMint", - "msg": "Invalid mint" + code: 312; + name: "InvalidMint"; + msg: "Invalid mint"; }, { - "code": 312, - "name": "InvalidTokenManagerState", - "msg": "Invalid token manager state" + code: 313; + name: "InvalidTokenManagerState"; + msg: "Invalid token manager state"; } - ] + ]; }; export const IDL: CardinalTokenManager = { - "version": "0.0.0", - "name": "cardinal_token_manager", - "instructions": [ + version: "0.0.0", + name: "cardinal_token_manager", + instructions: [ { - "name": "init", - "accounts": [ + name: "init", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer", + isMut: true, + isSigner: true, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "mint", - "type": "publicKey" + name: "mint", + type: "publicKey", }, { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "numInvalidators", - "type": "u8" - } - ] + name: "numInvalidators", + type: "u8", + }, + ], }, { - "name": "setPaymentManager", - "accounts": [ + name: "setPaymentManager", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "issuer", - "isMut": true, - "isSigner": true - } + name: "issuer", + isMut: true, + isSigner: true, + }, ], - "args": [ + args: [ { - "name": "paymentManager", - "type": "publicKey" - } - ] + name: "paymentManager", + type: "publicKey", + }, + ], }, { - "name": "setClaimApprover", - "accounts": [ + name: "setClaimApprover", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "issuer", - "isMut": true, - "isSigner": true - } + name: "issuer", + isMut: true, + isSigner: true, + }, ], - "args": [ + args: [ { - "name": "claimApprover", - "type": "publicKey" - } - ] + name: "claimApprover", + type: "publicKey", + }, + ], }, { - "name": "setTransferAuthority", - "accounts": [ + name: "setTransferAuthority", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "issuer", - "isMut": true, - "isSigner": true - } + name: "issuer", + isMut: true, + isSigner: true, + }, ], - "args": [ + args: [ { - "name": "transferAuthority", - "type": "publicKey" - } - ] + name: "transferAuthority", + type: "publicKey", + }, + ], }, { - "name": "addInvalidator", - "accounts": [ + name: "addInvalidator", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "issuer", - "isMut": true, - "isSigner": true - } + name: "issuer", + isMut: true, + isSigner: true, + }, ], - "args": [ + args: [ { - "name": "invalidator", - "type": "publicKey" - } - ] + name: "invalidator", + type: "publicKey", + }, + ], }, { - "name": "createClaimReceipt", - "accounts": [ + name: "createClaimReceipt", + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager", + isMut: false, + isSigner: false, }, { - "name": "claimApprover", - "isMut": false, - "isSigner": true + name: "claimApprover", + isMut: false, + isSigner: true, }, { - "name": "claimReceipt", - "isMut": true, - "isSigner": false + name: "claimReceipt", + isMut: true, + isSigner: false, }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer", + isMut: true, + isSigner: true, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "target", - "type": "publicKey" - } - ] + name: "target", + type: "publicKey", + }, + ], }, { - "name": "createTransferReceipt", - "accounts": [ + name: "createTransferReceipt", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "transferAuthority", - "isMut": true, - "isSigner": true + name: "transferAuthority", + isMut: true, + isSigner: true, }, { - "name": "transferReceipt", - "isMut": true, - "isSigner": false + name: "transferReceipt", + isMut: true, + isSigner: false, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "target", - "type": "publicKey" - } - ] + name: "target", + type: "publicKey", + }, + ], }, { - "name": "issue", - "accounts": [ + name: "issue", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer", + isMut: true, + isSigner: true, }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "mint", - "isMut": false, - "isSigner": false + name: "mint", + isMut: false, + isSigner: false, }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer", + isMut: true, + isSigner: true, }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram", + isMut: false, + isSigner: false, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "ix", - "type": { - "defined": "IssueIx" - } - } - ] + name: "ix", + type: { + defined: "IssueIx", + }, + }, + ], }, { - "name": "unissue", - "accounts": [ + name: "unissue", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "issuer", - "isMut": true, - "isSigner": true + name: "issuer", + isMut: true, + isSigner: true, }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false - } + name: "tokenProgram", + isMut: false, + isSigner: false, + }, ], - "args": [] + args: [], }, { - "name": "claim", - "accounts": [ + name: "claim", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "mint", - "isMut": false, - "isSigner": false + name: "mint", + isMut: false, + isSigner: false, }, { - "name": "recipient", - "isMut": true, - "isSigner": true + name: "recipient", + isMut: true, + isSigner: true, }, { - "name": "recipientTokenAccount", - "isMut": true, - "isSigner": false + name: "recipientTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false - } + name: "tokenProgram", + isMut: false, + isSigner: false, + }, ], - "args": [] + args: [], }, { - "name": "invalidate", - "accounts": [ + name: "invalidate", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "tokenManagerTokenAccount", - "isMut": true, - "isSigner": false + name: "tokenManagerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "mint", - "isMut": true, - "isSigner": false + name: "mint", + isMut: true, + isSigner: false, }, { - "name": "recipientTokenAccount", - "isMut": true, - "isSigner": false + name: "recipientTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "issuerTokenAccount", - "isMut": true, - "isSigner": false + name: "issuerTokenAccount", + isMut: true, + isSigner: false, }, { - "name": "invalidator", - "isMut": true, - "isSigner": true + name: "invalidator", + isMut: true, + isSigner: true, }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false - } + name: "tokenProgram", + isMut: false, + isSigner: false, + }, ], - "args": [] - } + args: [], + }, ], - "accounts": [ + accounts: [ { - "name": "tokenManager", - "type": { - "kind": "struct", - "fields": [ + name: "tokenManager", + type: { + kind: "struct", + fields: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "numInvalidators", - "type": "u8" + name: "numInvalidators", + type: "u8", }, { - "name": "issuer", - "type": "publicKey" + name: "issuer", + type: "publicKey", }, { - "name": "mint", - "type": "publicKey" + name: "mint", + type: "publicKey", }, { - "name": "amount", - "type": "u64" + name: "amount", + type: "u64", }, { - "name": "kind", - "type": "u8" + name: "kind", + type: "u8", }, { - "name": "state", - "type": "u8" + name: "state", + type: "u8", }, { - "name": "recipientTokenAccount", - "type": "publicKey" + name: "invalidationType", + type: "u8", }, { - "name": "paymentManager", - "type": { - "option": "publicKey" - } + name: "recipientTokenAccount", + type: "publicKey", }, { - "name": "claimApprover", - "type": { - "option": "publicKey" - } + name: "paymentManager", + type: { + option: "publicKey", + }, }, { - "name": "transferAuthority", - "type": { - "option": "publicKey" - } + name: "claimApprover", + type: { + option: "publicKey", + }, }, { - "name": "invalidators", - "type": { - "vec": "publicKey" - } - } - ] - } + name: "transferAuthority", + type: { + option: "publicKey", + }, + }, + { + name: "invalidators", + type: { + vec: "publicKey", + }, + }, + ], + }, }, { - "name": "claimReceipt", - "type": { - "kind": "struct", - "fields": [] - } + name: "claimReceipt", + type: { + kind: "struct", + fields: [], + }, }, { - "name": "tranferReceipt", - "type": { - "kind": "struct", - "fields": [] - } - } + name: "tranferReceipt", + type: { + kind: "struct", + fields: [], + }, + }, ], - "types": [ + types: [ { - "name": "IssueIx", - "type": { - "kind": "struct", - "fields": [ + name: "IssueIx", + type: { + kind: "struct", + fields: [ { - "name": "amount", - "type": "u64" + name: "amount", + type: "u64", }, { - "name": "kind", - "type": "u8" - } - ] - } + name: "kind", + type: "u8", + }, + { + name: "invalidationType", + type: "u8", + }, + ], + }, }, { - "name": "TokenManagerState", - "type": { - "kind": "enum", - "variants": [ + name: "TokenManagerState", + type: { + kind: "enum", + variants: [ { - "name": "Initialized" + name: "Initialized", }, { - "name": "Issued" + name: "Issued", }, { - "name": "Claimed" + name: "Claimed", }, { - "name": "Invalidated" - } - ] - } + name: "Invalidated", + }, + ], + }, }, { - "name": "TokenManagerKind", - "type": { - "kind": "enum", - "variants": [ + name: "TokenManagerKind", + type: { + kind: "enum", + variants: [ { - "name": "Managed" + name: "Managed", }, { - "name": "Unmanaged" + name: "Unmanaged", }, { - "name": "Edition" - } - ] - } - } + name: "Edition", + }, + ], + }, + }, + { + name: "InvalidationType", + type: { + kind: "enum", + variants: [ + { + name: "Return", + }, + { + name: "Invalidate", + }, + ], + }, + }, ], - "errors": [ + errors: [ { - "code": 300, - "name": "Uninitialized", - "msg": "Account not initialized" + code: 300, + name: "Uninitialized", + msg: "Account not initialized", }, { - "code": 301, - "name": "TooManyInvalidators", - "msg": "Too many invalidators have already been added" + code: 301, + name: "TooManyInvalidators", + msg: "Too many invalidators have already been added", }, { - "code": 302, - "name": "InvalidTokenManagerTokenAccount", - "msg": "Token account not owned by token manager" + code: 302, + name: "InvalidTokenManagerTokenAccount", + msg: "Token account not owned by token manager", }, { - "code": 303, - "name": "InvalidIssuerTokenAccount", - "msg": "Token account not owned by issuer" + code: 303, + name: "InvalidIssuerTokenAccount", + msg: "Token account not owned by issuer", }, { - "code": 304, - "name": "InvalidRecipientTokenAccount", - "msg": "Token account not owned by recipient" + code: 304, + name: "InvalidRecipientTokenAccount", + msg: "Token account not owned by recipient", }, { - "code": 305, - "name": "InvalidInvalidatorTokenAccount", - "msg": "Token account not owned by invalidator" + code: 305, + name: "InvalidInvalidatorTokenAccount", + msg: "Token account not owned by invalidator", }, { - "code": 306, - "name": "InvalidTokenManagerKind", - "msg": "Token manager kind is not valid" + code: 306, + name: "InvalidTokenManagerKind", + msg: "Token manager kind is not valid", }, { - "code": 307, - "name": "InvalidClaimAuthority", - "msg": "Invalid claim authority" + code: 307, + name: "InvalidInvalidationType", + msg: "Invalid invalidation type", }, { - "code": 308, - "name": "InvalidTransferAuthority", - "msg": "Invalid transfer authority" + code: 308, + name: "InvalidClaimAuthority", + msg: "Invalid claim authority", }, { - "code": 309, - "name": "InvalidIssuer", - "msg": "Invalid issuer" + code: 309, + name: "InvalidTransferAuthority", + msg: "Invalid transfer authority", }, { - "code": 310, - "name": "InvalidInvalidator", - "msg": "Invalid invalidator" + code: 310, + name: "InvalidIssuer", + msg: "Invalid issuer", }, { - "code": 311, - "name": "InvalidMint", - "msg": "Invalid mint" + code: 311, + name: "InvalidInvalidator", + msg: "Invalid invalidator", }, { - "code": 312, - "name": "InvalidTokenManagerState", - "msg": "Invalid token manager state" - } - ] + code: 312, + name: "InvalidMint", + msg: "Invalid mint", + }, + { + code: 313, + name: "InvalidTokenManagerState", + msg: "Invalid token manager state", + }, + ], }; diff --git a/src/idl/cardinal_use_invalidator.ts b/src/idl/cardinal_use_invalidator.ts index 12534bde4..e60c56933 100644 --- a/src/idl/cardinal_use_invalidator.ts +++ b/src/idl/cardinal_use_invalidator.ts @@ -1,341 +1,341 @@ export type CardinalUseInvalidator = { - "version": "0.0.0", - "name": "cardinal_use_invalidator", - "instructions": [ + version: "0.0.0"; + name: "cardinal_use_invalidator"; + instructions: [ { - "name": "init", - "accounts": [ + name: "init"; + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager"; + isMut: false; + isSigner: false; }, { - "name": "useInvalidator", - "isMut": true, - "isSigner": false + name: "useInvalidator"; + isMut: true; + isSigner: false; }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer"; + isMut: true; + isSigner: true; }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + name: "systemProgram"; + isMut: false; + isSigner: false; } - ], - "args": [ + ]; + args: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "maxUsages", - "type": { - "option": "u64" - } + name: "maxUsages"; + type: { + option: "u64"; + }; } - ] + ]; }, { - "name": "incrementUsages", - "accounts": [ + name: "incrementUsages"; + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager"; + isMut: false; + isSigner: false; }, { - "name": "useInvalidator", - "isMut": true, - "isSigner": false + name: "useInvalidator"; + isMut: true; + isSigner: false; }, { - "name": "user", - "isMut": false, - "isSigner": true + name: "user"; + isMut: false; + isSigner: true; } - ], - "args": [ + ]; + args: [ { - "name": "numUsages", - "type": "u64" + name: "numUsages"; + type: "u64"; } - ] + ]; }, { - "name": "invalidate", - "accounts": [ + name: "invalidate"; + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager"; + isMut: true; + isSigner: false; }, { - "name": "useInvalidator", - "isMut": true, - "isSigner": false + name: "useInvalidator"; + isMut: true; + isSigner: false; }, { - "name": "invalidator", - "isMut": true, - "isSigner": true + name: "invalidator"; + isMut: true; + isSigner: true; }, { - "name": "cardinalTokenManager", - "isMut": false, - "isSigner": false + name: "cardinalTokenManager"; + isMut: false; + isSigner: false; }, { - "name": "tokenManagerTokenAccount", - "isMut": false, - "isSigner": false + name: "tokenManagerTokenAccount"; + isMut: false; + isSigner: false; }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram"; + isMut: false; + isSigner: false; }, { - "name": "mint", - "isMut": false, - "isSigner": false + name: "mint"; + isMut: false; + isSigner: false; }, { - "name": "recipientTokenAccount", - "isMut": false, - "isSigner": false + name: "recipientTokenAccount"; + isMut: false; + isSigner: false; }, { - "name": "issuerTokenAccount", - "isMut": false, - "isSigner": false + name: "issuerTokenAccount"; + isMut: false; + isSigner: false; } - ], - "args": [] + ]; + args: []; } - ], - "accounts": [ + ]; + accounts: [ { - "name": "useInvalidator", - "type": { - "kind": "struct", - "fields": [ + name: "useInvalidator"; + type: { + kind: "struct"; + fields: [ { - "name": "bump", - "type": "u8" + name: "bump"; + type: "u8"; }, { - "name": "usages", - "type": "u64" + name: "usages"; + type: "u64"; }, { - "name": "maxUsages", - "type": { - "option": "u64" - } + name: "maxUsages"; + type: { + option: "u64"; + }; }, { - "name": "useAuthority", - "type": "publicKey" + name: "useAuthority"; + type: "publicKey"; } - ] - } + ]; + }; } - ], - "errors": [ + ]; + errors: [ { - "code": 300, - "name": "InvalidPaymentTokenAccount", - "msg": "Token account not owned by the claim approver" + code: 300; + name: "InvalidPaymentTokenAccount"; + msg: "Token account not owned by the claim approver"; }, { - "code": 301, - "name": "InvalidIssuerTokenAccount", - "msg": "Token account not owned by the issuer" + code: 301; + name: "InvalidIssuerTokenAccount"; + msg: "Token account not owned by the issuer"; }, { - "code": 302, - "name": "InvalidTokenManager", - "msg": "Invalid token manager for this claim approver" + code: 302; + name: "InvalidTokenManager"; + msg: "Invalid token manager for this claim approver"; }, { - "code": 303, - "name": "InvalidUsages", - "msg": "Usages not at the maximum" + code: 303; + name: "InsufficientUsages"; + msg: "Usages at the maximum"; } - ] + ]; }; export const IDL: CardinalUseInvalidator = { - "version": "0.0.0", - "name": "cardinal_use_invalidator", - "instructions": [ + version: "0.0.0", + name: "cardinal_use_invalidator", + instructions: [ { - "name": "init", - "accounts": [ + name: "init", + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager", + isMut: false, + isSigner: false, }, { - "name": "useInvalidator", - "isMut": true, - "isSigner": false + name: "useInvalidator", + isMut: true, + isSigner: false, }, { - "name": "payer", - "isMut": true, - "isSigner": true + name: "payer", + isMut: true, + isSigner: true, }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } + name: "systemProgram", + isMut: false, + isSigner: false, + }, ], - "args": [ + args: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "maxUsages", - "type": { - "option": "u64" - } - } - ] + name: "maxUsages", + type: { + option: "u64", + }, + }, + ], }, { - "name": "incrementUsages", - "accounts": [ + name: "incrementUsages", + accounts: [ { - "name": "tokenManager", - "isMut": false, - "isSigner": false + name: "tokenManager", + isMut: false, + isSigner: false, }, { - "name": "useInvalidator", - "isMut": true, - "isSigner": false + name: "useInvalidator", + isMut: true, + isSigner: false, }, { - "name": "user", - "isMut": false, - "isSigner": true - } + name: "user", + isMut: false, + isSigner: true, + }, ], - "args": [ + args: [ { - "name": "numUsages", - "type": "u64" - } - ] + name: "numUsages", + type: "u64", + }, + ], }, { - "name": "invalidate", - "accounts": [ + name: "invalidate", + accounts: [ { - "name": "tokenManager", - "isMut": true, - "isSigner": false + name: "tokenManager", + isMut: true, + isSigner: false, }, { - "name": "useInvalidator", - "isMut": true, - "isSigner": false + name: "useInvalidator", + isMut: true, + isSigner: false, }, { - "name": "invalidator", - "isMut": true, - "isSigner": true + name: "invalidator", + isMut: true, + isSigner: true, }, { - "name": "cardinalTokenManager", - "isMut": false, - "isSigner": false + name: "cardinalTokenManager", + isMut: false, + isSigner: false, }, { - "name": "tokenManagerTokenAccount", - "isMut": false, - "isSigner": false + name: "tokenManagerTokenAccount", + isMut: false, + isSigner: false, }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + name: "tokenProgram", + isMut: false, + isSigner: false, }, { - "name": "mint", - "isMut": false, - "isSigner": false + name: "mint", + isMut: false, + isSigner: false, }, { - "name": "recipientTokenAccount", - "isMut": false, - "isSigner": false + name: "recipientTokenAccount", + isMut: false, + isSigner: false, }, { - "name": "issuerTokenAccount", - "isMut": false, - "isSigner": false - } + name: "issuerTokenAccount", + isMut: false, + isSigner: false, + }, ], - "args": [] - } + args: [], + }, ], - "accounts": [ + accounts: [ { - "name": "useInvalidator", - "type": { - "kind": "struct", - "fields": [ + name: "useInvalidator", + type: { + kind: "struct", + fields: [ { - "name": "bump", - "type": "u8" + name: "bump", + type: "u8", }, { - "name": "usages", - "type": "u64" + name: "usages", + type: "u64", }, { - "name": "maxUsages", - "type": { - "option": "u64" - } + name: "maxUsages", + type: { + option: "u64", + }, }, { - "name": "useAuthority", - "type": "publicKey" - } - ] - } - } + name: "useAuthority", + type: "publicKey", + }, + ], + }, + }, ], - "errors": [ + errors: [ { - "code": 300, - "name": "InvalidPaymentTokenAccount", - "msg": "Token account not owned by the claim approver" + code: 300, + name: "InvalidPaymentTokenAccount", + msg: "Token account not owned by the claim approver", }, { - "code": 301, - "name": "InvalidIssuerTokenAccount", - "msg": "Token account not owned by the issuer" + code: 301, + name: "InvalidIssuerTokenAccount", + msg: "Token account not owned by the issuer", }, { - "code": 302, - "name": "InvalidTokenManager", - "msg": "Invalid token manager for this claim approver" + code: 302, + name: "InvalidTokenManager", + msg: "Invalid token manager for this claim approver", }, { - "code": 303, - "name": "InvalidUsages", - "msg": "Usages not at the maximum" - } - ] + code: 303, + name: "InsufficientUsages", + msg: "Usages at the maximum", + }, + ], }; diff --git a/src/programs/tokenManager/constants.ts b/src/programs/tokenManager/constants.ts index b7f37f69e..606f91c18 100644 --- a/src/programs/tokenManager/constants.ts +++ b/src/programs/tokenManager/constants.ts @@ -33,6 +33,11 @@ export enum TokenManagerKind { Edition = 3, } +export enum InvalidationType { + Return = 1, + Invalidate = 2, +} + export enum TokenManagerState { Initialized = 0, Issued = 1, diff --git a/src/programs/tokenManager/instruction.ts b/src/programs/tokenManager/instruction.ts index 7c81b209d..7ef6e57d3 100644 --- a/src/programs/tokenManager/instruction.ts +++ b/src/programs/tokenManager/instruction.ts @@ -9,7 +9,11 @@ import type { } from "@solana/web3.js"; import { SystemProgram } from "@solana/web3.js"; -import type { TOKEN_MANAGER_PROGRAM, TokenManagerKind } from "./constants"; +import type { + InvalidationType, + TOKEN_MANAGER_PROGRAM, + TokenManagerKind, +} from "./constants"; import { TOKEN_MANAGER_ADDRESS, TOKEN_MANAGER_IDL } from "./constants"; import { findClaimReceiptId, findTokenManagerAddress } from "./pda"; @@ -142,7 +146,8 @@ export const issue = ( mintId: PublicKey, tokenManagerTokenAccountId: PublicKey, issuerTokenAccountId: PublicKey, - kind: TokenManagerKind + kind: TokenManagerKind, + invalidationType: InvalidationType ): TransactionInstruction => { const provider = new Provider(connection, wallet, {}); const tokenManagerProgram = new Program( @@ -155,6 +160,7 @@ export const issue = ( { amount, kind: kind, + invalidationType: invalidationType, }, { accounts: { diff --git a/src/rentals.ts b/src/rentals.ts index 86632d4a0..38412af07 100644 --- a/src/rentals.ts +++ b/src/rentals.ts @@ -15,7 +15,7 @@ import { timeInvalidator, tokenManager, } from "./programs"; -import { TokenManagerKind } from "./programs/tokenManager"; +import { InvalidationType, TokenManagerKind } from "./programs/tokenManager"; import { withFindOrInitAssociatedTokenAccount } from "./utils"; export const createRental = async ( @@ -138,7 +138,8 @@ export const createRental = async ( rentalMint, tokenManagerTokenAccountId, issuerTokenAccountId, - kind + kind, + InvalidationType.Return ) ); diff --git a/src/utils.ts b/src/utils.ts index 8e4e70e13..daf12c29b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -10,6 +10,15 @@ export type AccountData = { parsed: T; }; +type AccountFn = () => Promise>; +export async function tryGetAccount(fn: AccountFn) { + try { + return await fn(); + } catch { + return null; + } +} + export async function findAta( mint: PublicKey, owner: PublicKey, diff --git a/tests/createRental.spec.ts b/tests/createRental.spec.ts index bcf42d8ee..ce60c4c77 100644 --- a/tests/createRental.spec.ts +++ b/tests/createRental.spec.ts @@ -58,7 +58,7 @@ describe("Rentals", () => { ); }); - it("Create rent", async () => { + it("Create rental", async () => { const provider = getProvider(); const [transaction, tokenManagerId] = await rentals.createRental( provider.connection, diff --git a/tests/usages.spec.ts b/tests/usages.spec.ts new file mode 100644 index 000000000..8ba678590 --- /dev/null +++ b/tests/usages.spec.ts @@ -0,0 +1,192 @@ +import { BN } from "@project-serum/anchor"; +import { expectTXTable } from "@saberhq/chai-solana"; +import { + SignerWallet, + SolanaProvider, + TransactionEnvelope, +} from "@saberhq/solana-contrib"; +import type { Token } from "@solana/spl-token"; +import type { PublicKey } from "@solana/web3.js"; +import { Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js"; +import { expect } from "chai"; + +import { claimLinks, findAta, rentals } from "../src"; +import { tokenManager, useInvalidator } from "../src/programs"; +import { TokenManagerState } from "../src/programs/tokenManager"; +import { createMint } from "./utils"; +import { getProvider } from "./workspace"; + +describe("Use without use invalidator", () => { + const RECIPIENT_START_PAYMENT_AMOUNT = 1000; + const RENTAL_PAYMENT_AMONT = 10; + const recipient = Keypair.generate(); + const tokenCreator = Keypair.generate(); + let recipientPaymentTokenAccountId: PublicKey; + let issuerTokenAccountId: PublicKey; + let paymentMint: Token; + let rentalMint: Token; + + before(async () => { + const provider = getProvider(); + const airdropCreator = await provider.connection.requestAirdrop( + tokenCreator.publicKey, + LAMPORTS_PER_SOL + ); + await provider.connection.confirmTransaction(airdropCreator); + + const airdropRecipient = await provider.connection.requestAirdrop( + recipient.publicKey, + LAMPORTS_PER_SOL + ); + await provider.connection.confirmTransaction(airdropRecipient); + + // create payment mint + [recipientPaymentTokenAccountId, paymentMint] = await createMint( + provider.connection, + tokenCreator, + recipient.publicKey, + RECIPIENT_START_PAYMENT_AMOUNT + ); + + // create rental mint + [issuerTokenAccountId, rentalMint] = await createMint( + provider.connection, + tokenCreator, + provider.wallet.publicKey, + 1, + provider.wallet.publicKey + ); + }); + + it("Create rental", async () => { + const provider = getProvider(); + const [transaction, tokenManagerId] = await rentals.createRental( + provider.connection, + provider.wallet, + { + paymentAmount: RENTAL_PAYMENT_AMONT, + paymentMint: paymentMint.publicKey, + expiration: Date.now() / 1000 + 1, + rentalMint: rentalMint.publicKey, + issuerTokenAccountId: issuerTokenAccountId, + amount: new BN(1), + } + ); + const txEnvelope = new TransactionEnvelope( + SolanaProvider.init({ + connection: provider.connection, + wallet: provider.wallet, + opts: provider.opts, + }), + [...transaction.instructions] + ); + await expectTXTable(txEnvelope, "test", { + verbosity: "always", + formatLogs: true, + }).to.be.fulfilled; + + const tokenManagerData = await tokenManager.accounts.getTokenManager( + provider.connection, + tokenManagerId + ); + expect(tokenManagerData.parsed.state).to.eq(TokenManagerState.Issued); + expect(tokenManagerData.parsed.amount.toNumber()).to.eq(1); + expect(tokenManagerData.parsed.mint).to.eqAddress(rentalMint.publicKey); + expect(tokenManagerData.parsed.invalidators).length.greaterThanOrEqual(1); + expect(tokenManagerData.parsed.issuer).to.eqAddress( + provider.wallet.publicKey + ); + + const checkIssuerTokenAccount = await rentalMint.getAccountInfo( + issuerTokenAccountId + ); + expect(checkIssuerTokenAccount.amount.toNumber()).to.eq(0); + }); + + it("Claim rental", async () => { + const provider = getProvider(); + + const [tokenManagerId] = await tokenManager.pda.findTokenManagerAddress( + rentalMint.publicKey + ); + + const transaction = await rentals.claimRental( + provider.connection, + new SignerWallet(recipient), + tokenManagerId + ); + + const txEnvelope = new TransactionEnvelope( + SolanaProvider.init({ + connection: provider.connection, + wallet: new SignerWallet(recipient), + opts: provider.opts, + }), + [...transaction.instructions] + ); + + await expectTXTable(txEnvelope, "test", { + verbosity: "always", + formatLogs: true, + }).to.be.fulfilled; + + const tokenManagerData = await tokenManager.accounts.getTokenManager( + provider.connection, + tokenManagerId + ); + expect(tokenManagerData.parsed.state).to.eq(TokenManagerState.Claimed); + expect(tokenManagerData.parsed.amount.toNumber()).to.eq(1); + + const checkIssuerTokenAccount = await rentalMint.getAccountInfo( + issuerTokenAccountId + ); + expect(checkIssuerTokenAccount.amount.toNumber()).to.eq(0); + + const checkRecipientTokenAccount = await rentalMint.getAccountInfo( + await findAta(rentalMint.publicKey, recipient.publicKey) + ); + expect(checkRecipientTokenAccount.amount.toNumber()).to.eq(1); + + const checkRecipientPaymentTokenAccount = await paymentMint.getAccountInfo( + recipientPaymentTokenAccountId + ); + expect(checkRecipientPaymentTokenAccount.amount.toNumber()).to.eq( + RECIPIENT_START_PAYMENT_AMOUNT - RENTAL_PAYMENT_AMONT + ); + }); + + it("Use", async () => { + const provider = getProvider(); + const transaction = await claimLinks.useTransaction( + provider.connection, + new SignerWallet(recipient), + rentalMint.publicKey, + 1 + ); + + const txEnvelope = new TransactionEnvelope( + SolanaProvider.init({ + connection: provider.connection, + wallet: new SignerWallet(recipient), + opts: provider.opts, + }), + [...transaction.instructions] + ); + + await expectTXTable(txEnvelope, "test", { + verbosity: "always", + formatLogs: true, + }).to.be.fulfilled; + + const [tokenManagerId] = await tokenManager.pda.findTokenManagerAddress( + rentalMint.publicKey + ); + const [useInvalidatorId] = + await useInvalidator.pda.findUseInvalidatorAddress(tokenManagerId); + const useInvalidatorData = await useInvalidator.accounts.getUseInvalidator( + provider.connection, + useInvalidatorId + ); + expect(useInvalidatorData.parsed.usages.toNumber()).to.eq(1); + }); +});