From b5d9477f56b0f93aa13383fcb788b5afa3030c35 Mon Sep 17 00:00:00 2001 From: jpbogle Date: Fri, 4 Feb 2022 10:47:39 -0800 Subject: [PATCH] Use freeze feature from mpl_token_metadata --- Cargo.lock | 105 ++++++++++++------ .../cardinal-paid-claim-approver/Cargo.toml | 6 +- programs/cardinal-payment-manager/Cargo.toml | 4 +- programs/cardinal-rent-receipt/Cargo.toml | 4 +- .../src/instructions/claim.rs | 2 +- programs/cardinal-rental-counter/Cargo.toml | 4 +- programs/cardinal-time-invalidator/Cargo.toml | 4 +- programs/cardinal-token-manager/Cargo.toml | 3 +- programs/cardinal-token-manager/src/errors.rs | 4 +- .../src/instructions/claim.rs | 41 ++++++- .../src/instructions/invalidate.rs | 42 ++++++- .../src/instructions/issue.rs | 2 +- programs/cardinal-token-manager/src/lib.rs | 4 +- programs/cardinal-token-manager/src/state.rs | 2 +- programs/cardinal-use-invalidator/Cargo.toml | 4 +- src/{api.ts => rentals.ts} | 0 16 files changed, 172 insertions(+), 59 deletions(-) rename src/{api.ts => rentals.ts} (100%) diff --git a/Cargo.lock b/Cargo.lock index 5a9fc3968..14bb9e241 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,14 @@ version = 3 [[package]] name = "ahash" -version = "0.4.7" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.4", + "once_cell", + "version_check", +] [[package]] name = "aho-corasick" @@ -308,9 +313,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "borsh" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18dda7dc709193c0d86a1a51050a926dc3df1cf262ec46a23a25dba421ea1924" +checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ "borsh-derive", "hashbrown", @@ -318,9 +323,9 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684155372435f578c0fa1acd13ebbb182cc19d6b38b64ae7901da4393217d264" +checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ "borsh-derive-internal", "borsh-schema-derive-internal", @@ -331,9 +336,9 @@ dependencies = [ [[package]] name = "borsh-derive-internal" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2102f62f8b6d3edeab871830782285b64cc1830168094db05c8e458f209bc5c3" +checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" dependencies = [ "proc-macro2", "quote", @@ -342,9 +347,9 @@ dependencies = [ [[package]] name = "borsh-schema-derive-internal" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196c978c4c9b0b142d446ef3240690bf5a8a33497074a113ff9a337ccb750483" +checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" dependencies = [ "proc-macro2", "quote", @@ -407,7 +412,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cardinal-paid-claim-approver" -version = "0.0.3" +version = "0.0.4" dependencies = [ "anchor-lang", "anchor-spl", @@ -421,7 +426,7 @@ dependencies = [ [[package]] name = "cardinal-payment-manager" -version = "0.0.3" +version = "0.0.4" dependencies = [ "anchor-lang", "anchor-spl", @@ -434,7 +439,7 @@ dependencies = [ [[package]] name = "cardinal-rent-receipt" -version = "0.0.3" +version = "0.0.4" dependencies = [ "anchor-lang", "anchor-spl", @@ -447,7 +452,7 @@ dependencies = [ [[package]] name = "cardinal-rental-counter" -version = "0.0.3" +version = "0.0.4" dependencies = [ "anchor-lang", "anchor-spl", @@ -460,7 +465,7 @@ dependencies = [ [[package]] name = "cardinal-time-invalidator" -version = "0.0.3" +version = "0.0.4" dependencies = [ "anchor-lang", "anchor-spl", @@ -473,10 +478,11 @@ dependencies = [ [[package]] name = "cardinal-token-manager" -version = "0.0.3" +version = "0.0.4" dependencies = [ "anchor-lang", "anchor-spl", + "mpl-token-metadata", "proptest", "solana-program", "spl-associated-token-account", @@ -486,7 +492,7 @@ dependencies = [ [[package]] name = "cardinal-use-invalidator" -version = "0.0.3" +version = "0.0.4" dependencies = [ "anchor-lang", "anchor-spl", @@ -680,9 +686,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.9.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ "ahash", ] @@ -864,6 +870,37 @@ dependencies = [ "libc", ] +[[package]] +name = "mpl-token-metadata" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ee274b7bcfd37715e60a3549e36d322f48e4719d50e273b21a43418490c242" +dependencies = [ + "arrayref", + "borsh", + "mpl-token-vault", + "num-derive", + "num-traits", + "solana-program", + "spl-associated-token-account", + "spl-token", + "thiserror", +] + +[[package]] +name = "mpl-token-vault" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ade4ef15bc06a6033076c4ff28cba9b42521df5ec61211d6f419415ace2746a" +dependencies = [ + "borsh", + "num-derive", + "num-traits", + "solana-program", + "spl-token", + "thiserror", +] + [[package]] name = "num-derive" version = "0.3.3" @@ -905,6 +942,12 @@ dependencies = [ "syn", ] +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -1257,9 +1300,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "solana-frozen-abi" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89bcde59ac3e8d4dbf7c4d990b0627b8ca0d25394c4ce17896dde7a1452e40c" +checksum = "fbb58e258da28e714904b62a1e8b7de5b01d349420a88409c84cb57264699021" dependencies = [ "bs58 0.4.0", "bv", @@ -1277,9 +1320,9 @@ dependencies = [ [[package]] name = "solana-frozen-abi-macro" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56a7d630da35993631ecc4dd155f92d0d58000cdde3d5e2764fe9fd49d20a3a8" +checksum = "7f9c141ee23138a001bf94a9850fff3c8804e52fa36c151a8a4699f60bd55f74" dependencies = [ "proc-macro2", "quote", @@ -1289,9 +1332,9 @@ dependencies = [ [[package]] name = "solana-logger" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6eaf925bb665de46f96fcea2c8a900d0d870a96fd1f50cf2bad16e22a1da71c4" +checksum = "72b63b04c1a2077f2eadb3c63988a14bc4fa4419f291fea7112a9c595db1e63b" dependencies = [ "env_logger", "lazy_static", @@ -1300,9 +1343,9 @@ dependencies = [ [[package]] name = "solana-program" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fc4d7a0baa649a3bda06d6a1cc30bd3d8ac692702a75fa8e76369cf7b3f6329" +checksum = "0c41b2af0be4fc039852c74926a8a026e97f9b1d7c02c15610bb6a614268a4ea" dependencies = [ "base64 0.13.0", "bincode", @@ -1343,9 +1386,9 @@ dependencies = [ [[package]] name = "solana-sdk-macro" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec22a924c73abe3376a2046715a2f6a9ae4094095b8ea08e8e56e8de198264ad" +checksum = "238b93350286f73c2bd94c1a307bb0226a2f78070937bcf273bf968859f8cc39" dependencies = [ "bs58 0.4.0", "proc-macro2", @@ -1366,9 +1409,9 @@ dependencies = [ [[package]] name = "spl-token" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93bfdd5bd7c869cb565c7d7635c4fafe189b988a0bdef81063cd9585c6b8dc01" +checksum = "0cc67166ef99d10c18cb5e9c208901e6d8255c6513bb1f877977eba48e6cc4fb" dependencies = [ "arrayref", "num-derive", diff --git a/programs/cardinal-paid-claim-approver/Cargo.toml b/programs/cardinal-paid-claim-approver/Cargo.toml index 2b49a28a2..6d3c925f7 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.3" +version = "0.0.4" 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.3", path = "../cardinal-token-manager", features = ["cpi"] } -cardinal-payment-manager = { version = "^0.0.3", path = "../cardinal-payment-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.4", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-payment-manager = { version = "^0.0.4", 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 c6ee19722..491eade56 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.3" +version = "0.0.4" 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.3", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.4", 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 618b6f1d4..7dce7521e 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.3" +version = "0.0.4" 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.3", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.4", 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 cb9d8b49f..06378ac52 100644 --- a/programs/cardinal-rent-receipt/src/instructions/claim.rs +++ b/programs/cardinal-rent-receipt/src/instructions/claim.rs @@ -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::Authority as u8})?; + cardinal_token_manager::cpi::issue(issue_ctx, IssueIx{amount: 1, kind: TokenManagerKind::Managed 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 332347e9b..abadf5cbf 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.3" +version = "0.0.4" 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.3", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.4", 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 c9c821a2e..0b51dda24 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.3" +version = "0.0.4" 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.3", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.4", 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 58cf1c345..63e4548ea 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.3" +version = "0.0.4" description = "Cardinal token manager" edition = "2021" homepage = "https://cardinal.so" @@ -25,6 +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" +mpl-token-metadata = { version = "1.2.2", features = ["no-entrypoint"] } vipers = "1.5.7" [dev-dependencies] diff --git a/programs/cardinal-token-manager/src/errors.rs b/programs/cardinal-token-manager/src/errors.rs index b67415dbb..e22e6626c 100644 --- a/programs/cardinal-token-manager/src/errors.rs +++ b/programs/cardinal-token-manager/src/errors.rs @@ -2,6 +2,8 @@ use anchor_lang::prelude::*; #[error] pub enum ErrorCode { + #[msg("Account not initialized")] + Uninitialized, #[msg("Too many invalidators have already been added")] TooManyInvalidators, #[msg("Token account not owned by token manager")] @@ -25,5 +27,5 @@ pub enum ErrorCode { #[msg("Invalid mint")] InvalidMint, #[msg("Invalid token manager state")] - InvalidTokenManagerState, + InvalidTokenManagerState } \ No newline at end of file diff --git a/programs/cardinal-token-manager/src/instructions/claim.rs b/programs/cardinal-token-manager/src/instructions/claim.rs index 0db509cb7..0a69719aa 100644 --- a/programs/cardinal-token-manager/src/instructions/claim.rs +++ b/programs/cardinal-token-manager/src/instructions/claim.rs @@ -1,7 +1,8 @@ use { crate::{state::*, errors::*}, - anchor_lang::{prelude::*}, + anchor_lang::{prelude::*, solana_program::program::invoke_signed}, anchor_spl::{token::{self, Token, TokenAccount, Mint, Transfer, FreezeAccount, Approve}}, + mpl_token_metadata::instruction::freeze_delegated_account, vipers::assert_keys_eq }; @@ -30,7 +31,7 @@ pub struct ClaimCtx<'info> { token_program: Program<'info, Token>, } -pub fn handler(ctx: Context) -> ProgramResult { +pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts, 'remaining, 'info, ClaimCtx<'info>>) -> ProgramResult { let token_manager = &mut ctx.accounts.token_manager; token_manager.recipient_token_account = ctx.accounts.recipient_token_account.key(); token_manager.state = TokenManagerState::Claimed as u8; @@ -66,8 +67,8 @@ pub fn handler(ctx: Context) -> ProgramResult { token::transfer(cpi_context, token_manager.amount)?; // if this is a managed token, this means we will revoke it at the end of life, so we need to delegate and freeze - if token_manager.kind == TokenManagerKind::Authority as u8 { - // set account delegate of recipient token account to certificate PDA + if token_manager.kind == TokenManagerKind::Managed as u8 { + // set account delegate of recipient token account to token manager PDA let cpi_accounts = Approve { to: ctx.accounts.recipient_token_account.to_account_info(), delegate: token_manager.to_account_info(), @@ -87,7 +88,39 @@ pub fn handler(ctx: Context) -> ProgramResult { let cpi_context = CpiContext::new(cpi_program, cpi_accounts).with_signer(token_manager_signer); token::freeze_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()); + // set account delegate of recipient token account to token manager PDA + let cpi_accounts = Approve { + to: ctx.accounts.recipient_token_account.to_account_info(), + delegate: token_manager.to_account_info(), + authority: ctx.accounts.recipient.to_account_info(), + }; + let cpi_program = ctx.accounts.token_program.to_account_info(); + let cpi_context = CpiContext::new(cpi_program, cpi_accounts); + token::approve(cpi_context, token_manager.amount)?; + + 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], + )?; } return Ok(()) } diff --git a/programs/cardinal-token-manager/src/instructions/invalidate.rs b/programs/cardinal-token-manager/src/instructions/invalidate.rs index 7c9bb4f9a..89eaa6d06 100644 --- a/programs/cardinal-token-manager/src/instructions/invalidate.rs +++ b/programs/cardinal-token-manager/src/instructions/invalidate.rs @@ -1,7 +1,9 @@ use { crate::{state::*, errors::*}, - anchor_lang::{prelude::*}, - anchor_spl::{token::{self, Token, TokenAccount, Mint, Transfer, ThawAccount, CloseAccount}} + anchor_lang::{prelude::*, solana_program::program::invoke_signed}, + anchor_spl::{token::{self, Token, TokenAccount, Mint, Transfer, ThawAccount, CloseAccount}}, + mpl_token_metadata::instruction::freeze_delegated_account, + vipers::assert_keys_eq }; #[derive(Accounts)] @@ -36,7 +38,7 @@ pub struct InvalidateCtx<'info> { token_program: Program<'info, Token>, } -pub fn handler(ctx: Context) -> ProgramResult { +pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts, 'remaining, 'info, InvalidateCtx<'info>>) -> ProgramResult { let token_manager = &mut ctx.accounts.token_manager; // get PDA seeds to sign with @@ -44,7 +46,7 @@ pub fn handler(ctx: Context) -> ProgramResult { 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::Authority as u8 { + if token_manager.kind == TokenManagerKind::Managed as u8 { // if claimed we need to thaw if token_manager.state == TokenManagerState::Claimed as u8 { // thaw recipient account @@ -68,7 +70,39 @@ pub fn handler(ctx: Context) -> ProgramResult { 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], + )?; + + // 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)?; } token_manager.state = TokenManagerState::Invalidated as u8; diff --git a/programs/cardinal-token-manager/src/instructions/issue.rs b/programs/cardinal-token-manager/src/instructions/issue.rs index fa85b3e5b..a2823c7f8 100644 --- a/programs/cardinal-token-manager/src/instructions/issue.rs +++ b/programs/cardinal-token-manager/src/instructions/issue.rs @@ -35,7 +35,7 @@ pub struct IssueCtx<'info> { } pub fn handler(ctx: Context, ix: IssueIx) -> ProgramResult { - if ix.kind != TokenManagerKind::Authority as u8 + if ix.kind != TokenManagerKind::Managed as u8 && ix.kind != TokenManagerKind::Unmanaged as u8 && ix.kind != TokenManagerKind::Edition as u8 { return Err(ErrorCode::InvalidTokenManagerKind.into()); diff --git a/programs/cardinal-token-manager/src/lib.rs b/programs/cardinal-token-manager/src/lib.rs index 79d71d8c5..b6a642905 100644 --- a/programs/cardinal-token-manager/src/lib.rs +++ b/programs/cardinal-token-manager/src/lib.rs @@ -46,11 +46,11 @@ pub mod cardinal_token_manager { unissue::handler(ctx) } - pub fn claim(ctx: Context) -> ProgramResult { + pub fn claim<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts, 'remaining, 'info, ClaimCtx<'info>>) -> ProgramResult { claim::handler(ctx) } - pub fn invalidate(ctx: Context) -> ProgramResult { + pub fn invalidate<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts, 'remaining, 'info, InvalidateCtx<'info>>) -> ProgramResult { invalidate::handler(ctx) } } \ No newline at end of file diff --git a/programs/cardinal-token-manager/src/state.rs b/programs/cardinal-token-manager/src/state.rs index 7a92e38de..9d9f94315 100644 --- a/programs/cardinal-token-manager/src/state.rs +++ b/programs/cardinal-token-manager/src/state.rs @@ -18,7 +18,7 @@ pub enum TokenManagerState { #[repr(u8)] pub enum TokenManagerKind { /// Token a managed rental and will use freeze authority to manage the token - Authority = 1, + Managed = 1, /// Token is unmanaged and can be traded freely until expiration Unmanaged = 2, /// Token is a metaplex edition and so it uses metaplex program to freeze diff --git a/programs/cardinal-use-invalidator/Cargo.toml b/programs/cardinal-use-invalidator/Cargo.toml index 64c60cb01..87dfeb161 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.3" +version = "0.0.4" 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.3", path = "../cardinal-token-manager", features = ["cpi"] } +cardinal-token-manager = { version = "^0.0.4", path = "../cardinal-token-manager", features = ["cpi"] } [dev-dependencies] proptest = { version = "1.0" } \ No newline at end of file diff --git a/src/api.ts b/src/rentals.ts similarity index 100% rename from src/api.ts rename to src/rentals.ts