Skip to content

Commit

Permalink
sanity check for royalty basis points (#73)
Browse files Browse the repository at this point in the history
* sanity check for royalty basis points

* fix comments

---------

Co-authored-by: fubin.jiang <[email protected]>
  • Loading branch information
calldata and fubin.jiang authored May 15, 2024
1 parent 3d6f146 commit cf3d6ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions programs/asset/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub enum Error {
#[error("Total creators share is invalid (expected {0}, got {1})")]
InvalidCreatorsTotalShare(u8, u8),

#[error("Royalty basis points exceed 10000")]
InvalidRoyaltyBasisPoints,

/// 1 - Cannot unverify creator
#[error("Cannot unverify creator")]
CannotUnverifyCreator,
Expand Down
26 changes: 25 additions & 1 deletion programs/asset/types/src/extensions/royalties.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::Deref;

use crate::constraints::{Constraint, ConstraintBuilder, FromBytes};
use crate::error::Error;

use super::{ExtensionBuilder, ExtensionData, ExtensionDataMut, ExtensionType, Lifecycle};

Expand Down Expand Up @@ -50,7 +51,30 @@ impl<'a> ExtensionDataMut<'a> for RoyaltiesMut<'a> {
}
}

impl Lifecycle for RoyaltiesMut<'_> {}
impl Lifecycle for RoyaltiesMut<'_> {
fn on_create(
&mut self,
_authority: Option<&solana_program::pubkey::Pubkey>,
) -> Result<(), Error> {
if *self.basis_points > 10000 {
return Err(Error::InvalidRoyaltyBasisPoints);
}

Ok(())
}

fn on_update(
&mut self,
other: &mut Self,
_authority: Option<&solana_program::pubkey::Pubkey>,
) -> Result<(), Error> {
if *other.basis_points > 10000 {
return Err(Error::InvalidRoyaltyBasisPoints);
}

Ok(())
}
}

#[derive(Default)]
pub struct RoyaltiesBuilder(Vec<u8>);
Expand Down

0 comments on commit cf3d6ec

Please sign in to comment.