Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make release init via hub work with versioned tx #1132

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 0 additions & 96 deletions programs/nina/src/instructions/hub_init_with_credit.rs

This file was deleted.

6 changes: 2 additions & 4 deletions programs/nina/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod release_init;
pub mod release_init_with_credit;
pub mod release_init_via_hub;
pub mod release_init_via_hub_v0;
pub mod release_purchase;
pub mod release_purchase_via_hub;
pub mod release_revenue_share_collect;
Expand All @@ -24,7 +24,6 @@ pub mod vault_init;
pub mod vault_withdraw;

pub mod hub_init;
pub mod hub_init_with_credit;
pub mod hub_add_collaborator;
pub mod hub_add_release;
pub mod hub_remove_collaborator;
Expand All @@ -42,8 +41,8 @@ pub mod subscription_subscribe_hub;
pub mod subscription_unsubscribe;

pub use release_init::*;
pub use release_init_with_credit::*;
pub use release_init_via_hub::*;
pub use release_init_via_hub_v0::*;
pub use release_purchase::*;
pub use release_purchase_via_hub::*;
pub use release_revenue_share_collect::*;
Expand All @@ -67,7 +66,6 @@ pub use vault_init::*;
pub use vault_withdraw::*;

pub use hub_init::*;
pub use hub_init_with_credit::*;
pub use hub_add_collaborator::*;
pub use hub_add_release::*;
pub use hub_remove_collaborator::*;
Expand Down
2 changes: 1 addition & 1 deletion programs/nina/src/instructions/release_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn handler(
ctx.accounts.release_signer.to_account_info().clone(),
ctx.accounts.metadata.to_account_info().clone(),
ctx.accounts.release_mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.payer.clone(),
ctx.accounts.metadata_program.to_account_info().clone(),
ctx.accounts.token_program.clone(),
ctx.accounts.system_program.clone(),
Expand Down
4 changes: 2 additions & 2 deletions programs/nina/src/instructions/release_init_via_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn handler(
ctx.accounts.release_signer.to_account_info().clone(),
ctx.accounts.metadata.to_account_info().clone(),
ctx.accounts.release_mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.payer.clone(),
ctx.accounts.metadata_program.to_account_info().clone(),
ctx.accounts.token_program.clone(),
ctx.accounts.system_program.clone(),
Expand All @@ -164,4 +164,4 @@ pub fn handler(
)?;

Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use anchor_lang::prelude::*;
use anchor_spl::token::{self, TokenAccount, Mint, Token, Burn};

use crate::state::*;
use crate::utils::{nina_publishing_credit_mint, file_service_account};
use anchor_spl::token::{self, TokenAccount, Mint, Token};
use crate::utils::{file_service_account};
use crate::errors::ErrorCode;
use crate::state::*;

#[derive(Accounts)]
pub struct ReleaseInitializeWithCredit<'info> {
#[instruction(
_config: ReleaseConfig,
_bumps: ReleaseBumps,
_metadata_data: ReleaseMetadataData,
)]
pub struct ReleaseInitializeViaHubV0<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(
init,
seeds = [b"nina-release".as_ref(), release_mint.key().as_ref()],
Expand All @@ -20,50 +26,72 @@ pub struct ReleaseInitializeWithCredit<'info> {
seeds = [release.key().as_ref()],
bump,
)]
pub release_signer: UncheckedAccount<'info>,
pub release_signer: AccountInfo<'info>,
#[account(
mut,
seeds = [b"nina-hub-collaborator".as_ref(), hub.key().as_ref(), authority.key().as_ref()],
bump,
constraint = hub_collaborator.collaborator == authority.key(),
)]
pub hub_collaborator: Account<'info, HubCollaborator>,
pub hub: AccountLoader<'info, Hub>,
#[account(
init,
seeds = [b"nina-hub-release".as_ref(), hub.key().as_ref(), release.key().as_ref()],
bump,
payer = payer,
space = 120
)]
pub hub_release: Box<Account<'info, HubRelease>>,
#[account(
init,
seeds = [b"nina-hub-content".as_ref(), hub.key().as_ref(), release.key().as_ref()],
bump,
payer = payer,
space = 153
)]
pub hub_content: Box<Account<'info, HubContent>>,
/// CHECK: This is safe because we are deriving the PDA from hub - which is initialized above
#[account(
seeds = [b"nina-hub-signer".as_ref(), hub.key().as_ref()],
bump,
)]
pub hub_signer: UncheckedAccount<'info>,
#[account(
constraint = hub_wallet.owner == hub_signer.key(),
constraint = hub_wallet.mint == payment_mint.key()
)]
pub hub_wallet: Box<Account<'info, TokenAccount>>,
pub release_mint: Box<Account<'info, Mint>>,
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: This is safe because we check in the handler that authority === payer
/// or that payer is nina operated file-service wallet
pub authority: UncheckedAccount<'info>,
#[account(
constraint = authority_token_account.owner == authority.key(),
constraint = authority_token_account.mint == payment_mint.key(),
)]
pub authority_token_account: Box<Account<'info, TokenAccount>>,
pub payment_mint: Box<Account<'info, Mint>>,
#[account(
mut,
constraint = authority_publishing_credit_token_account.owner == authority.key(),
constraint = authority_publishing_credit_token_account.mint == publishing_credit_mint.key(),
)]
pub authority_publishing_credit_token_account: Box<Account<'info, TokenAccount>>,
#[account(mut)]
#[cfg_attr(
not(feature = "test"),
account(address = nina_publishing_credit_mint::ID),
)]
pub publishing_credit_mint: Account<'info, Mint>,
pub payment_mint: Account<'info, Mint>,
#[account(
constraint = royalty_token_account.owner == release_signer.key(),
constraint = royalty_token_account.mint == payment_mint.key(),
constraint = royalty_token_account.owner == *release_signer.key
)]
pub royalty_token_account: Box<Account<'info, TokenAccount>>,
#[account(address = token::ID)]
pub token_program: Program<'info, Token>,
/// CHECK: This is safe because it is initialized here
#[account(mut)]
pub metadata: AccountInfo<'info>,
/// CHECK: This is safe because we check against ID
#[account(address = mpl_token_metadata::ID)]
pub metadata_program: AccountInfo<'info>,
#[account(address = token::ID)]
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
/// CHECK: This is safe because we check in the handler that authority === payer
/// or that payer is nina operated file-service wallet
#[account(mut)]
pub authority: UncheckedAccount<'info>,
}

pub fn handler(
ctx: Context<ReleaseInitializeWithCredit>,
ctx: Context<ReleaseInitializeViaHubV0>,
config: ReleaseConfig,
bumps: ReleaseBumps,
metadata_data: ReleaseMetadataData,
Expand All @@ -74,17 +102,10 @@ pub fn handler(
}
}


// Redeemer burn redeemable token
let cpi_program = ctx.accounts.token_program.to_account_info().clone();
let cpi_accounts = Burn {
mint: ctx.accounts.publishing_credit_mint.to_account_info(),
from: ctx.accounts.authority_publishing_credit_token_account.to_account_info(),
authority: ctx.accounts.authority.to_account_info().clone(),
};

let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
token::burn(cpi_ctx, 1)?;
Hub::hub_collaborator_can_add_or_publish_content(
&mut ctx.accounts.hub_collaborator,
true
)?;

Release::release_init_handler(
&ctx.accounts.release,
Expand All @@ -100,11 +121,24 @@ pub fn handler(
bumps,
)?;

let hub = ctx.accounts.hub.load()?;
Release::release_revenue_share_transfer_handler (
&ctx.accounts.release,
ctx.accounts.release_signer.to_account_info().clone(),
ctx.accounts.royalty_token_account.to_account_info(),
*ctx.accounts.authority.to_account_info().key,
*ctx.accounts.hub_signer.to_account_info().key,
ctx.accounts.hub_wallet.to_account_info().clone(),
ctx.accounts.token_program.to_account_info().clone(),
hub.publish_fee,
true,
)?;

Release::create_metadata_handler(
ctx.accounts.release_signer.to_account_info().clone(),
ctx.accounts.metadata.to_account_info().clone(),
ctx.accounts.release_mint.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.payer.clone(),
ctx.accounts.metadata_program.to_account_info().clone(),
ctx.accounts.token_program.clone(),
ctx.accounts.system_program.clone(),
Expand All @@ -114,5 +148,15 @@ pub fn handler(
bumps,
)?;

Hub::hub_release_create_handler(
ctx.accounts.hub.clone(),
&mut ctx.accounts.hub_content,
&mut ctx.accounts.hub_release,
ctx.accounts.release.clone(),
ctx.accounts.authority.key(),
true,
None,
)?;

Ok(())
}
}
25 changes: 8 additions & 17 deletions programs/nina/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ pub mod nina {
instructions::release_init::handler(ctx, config, bumps, metadata_data)
}

#[deprecated(since="0.2.14", note="please use `release_init` instead")]
pub fn release_init_with_credit(
ctx: Context<ReleaseInitializeWithCredit>,
pub fn release_init_via_hub(
ctx: Context<ReleaseInitializeViaHub>,
config: ReleaseConfig,
bumps: ReleaseBumps,
metadata_data: ReleaseMetadataData
metadata_data: ReleaseMetadataData,
hub_handle: String,
) -> Result<()> {
instructions::release_init_with_credit::handler(ctx, config, bumps, metadata_data)
instructions::release_init_via_hub::handler(ctx, config, bumps, metadata_data, hub_handle)
}

pub fn release_init_via_hub(
ctx: Context<ReleaseInitializeViaHub>,
pub fn release_init_via_hub_v0(
ctx: Context<ReleaseInitializeViaHubV0>,
config: ReleaseConfig,
bumps: ReleaseBumps,
metadata_data: ReleaseMetadataData,
hub_handle: String,
) -> Result<()> {
instructions::release_init_via_hub::handler(ctx, config, bumps, metadata_data, hub_handle)
instructions::release_init_via_hub_v0::handler(ctx, config, bumps, metadata_data)
}

pub fn release_purchase(
Expand Down Expand Up @@ -180,14 +179,6 @@ pub mod nina {
instructions::hub_init::handler(ctx, params)
}

#[deprecated(since="0.2.14", note="please use `hub_init` instead")]
pub fn hub_init_with_credit(
ctx: Context<HubInitWithCredit>,
params: HubInitParams,
) -> Result<()> {
instructions::hub_init_with_credit::handler(ctx, params)
}

pub fn hub_add_collaborator(
ctx: Context<HubAddCollaborator>,
can_add_content: bool,
Expand Down
Loading