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

updated depenedencies and files/instructions for hydra #1179

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
343 changes: 227 additions & 116 deletions core/rust/utils/Cargo.lock

Large diffs are not rendered by default.

1,266 changes: 891 additions & 375 deletions hydra/program/Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions hydra/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.26.0"
anchor-spl = "0.26.0"
solana-zk-token-sdk = "~1.14.13"
spl-token = {version="3.5.0", features = [ "no-entrypoint" ]}
mpl-token-metadata = {version="1.7.0", features = [ "no-entrypoint" ]}
anchor-lang = "0.30.0"
anchor-spl = "0.30.0"
solana-zk-token-sdk = "1.18.14"
spl-token = {version="4.0.1", features = [ "no-entrypoint" ]}
mpl-token-metadata = {version="4.1.2"}

[profile.release]
overflow-checks = true # Enable integer overflow checks.
5 changes: 3 additions & 2 deletions hydra/program/src/processors/add_member/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
};
use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, Token};
use mpl_token_metadata::programs::MPL_TOKEN_METADATA_ID;

#[derive(Accounts)]
#[instruction(args: AddMemberArgs)]
Expand Down Expand Up @@ -43,13 +44,13 @@ pub fn add_member_nft(ctx: Context<AddMemberWithNFT>, args: AddMemberArgs) -> Re
let membership_account = &mut ctx.accounts.membership_account;
let metadata = &ctx.accounts.metadata;
let mint = &ctx.accounts.mint;
assert_owned_by(metadata, &mpl_token_metadata::id())?;
assert_owned_by(metadata, &MPL_TOKEN_METADATA_ID)?;
assert_membership_model(fanout, MembershipModel::NFT)?;
assert_valid_metadata(metadata, &mint.to_account_info())?;
update_fanout_for_add(fanout, args.shares)?;
membership_account.membership_key = ctx.accounts.mint.to_account_info().key();
membership_account.shares = args.shares;
membership_account.bump_seed = *ctx.bumps.get("membership_account").unwrap();
membership_account.bump_seed = ctx.bumps.membership_account;
membership_account.fanout = fanout.key();
membership_account.stake_time = Clock::get()?.unix_timestamp;

Expand Down
2 changes: 1 addition & 1 deletion hydra/program/src/processors/add_member/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn add_member_wallet(ctx: Context<AddMemberWallet>, args: AddMemberArgs) ->
assert_owned_by_one(&member.to_account_info(), vec![&System::id(), &crate::id()])?;
membership_account.membership_key = member.key();
membership_account.shares = args.shares;
membership_account.bump_seed = *ctx.bumps.get("membership_account").unwrap();
membership_account.bump_seed = ctx.bumps.membership_account;
membership_account.fanout = fanout.key();
membership_account.stake_time = Clock::get()?.unix_timestamp;

Expand Down
38 changes: 19 additions & 19 deletions hydra/program/src/processors/signing/sign_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{error::HydraError, state::Fanout, utils::validation::assert_owned_by};
use anchor_lang::prelude::*;

use spl_token::solana_program::program::invoke_signed;
use mpl_token_metadata::programs::MPL_TOKEN_METADATA_ID;

#[derive(Accounts)]
pub struct SignMetadata<'info> {
Expand All @@ -23,40 +23,40 @@ pub struct SignMetadata<'info> {
#[account(mut)]
/// CHECK: Checked in Program
pub metadata: UncheckedAccount<'info>,
#[account(address=mpl_token_metadata::id())]
#[account(address=MPL_TOKEN_METADATA_ID)]
/// CHECK: Checked in Program
pub token_metadata_program: UncheckedAccount<'info>,
}

pub fn sign_metadata(ctx: Context<SignMetadata>) -> Result<()> {
let metadata = ctx.accounts.metadata.to_account_info();
let holding_account = &ctx.accounts.holding_account;
assert_owned_by(&metadata, &mpl_token_metadata::id())?;
assert_owned_by(&metadata, &MPL_TOKEN_METADATA_ID)?;
let meta_data = metadata.try_borrow_data()?;
if meta_data[0] != mpl_token_metadata::state::Key::MetadataV1 as u8 {

if mpl_token_metadata::accounts::Metadata::from_bytes(&meta_data).is_ok() {
return Err(HydraError::InvalidMetadata.into());
}

drop(meta_data);
let ix = mpl_token_metadata::instruction::sign_metadata(
ctx.accounts.token_metadata_program.key(),
metadata.key(),
holding_account.key(),
);
invoke_signed(
&ix,
&[metadata.to_owned(), holding_account.to_account_info()],
&[&[
"fanout-native-account".as_bytes(),
ctx.accounts.fanout.key().as_ref(),
&[*ctx.bumps.get("holding_account").unwrap()],
]],

mpl_token_metadata::instructions::VerifyCreatorV1CpiBuilder::new(
&ctx.accounts.token_metadata_program,
)
.metadata(&ctx.accounts.metadata)
.authority(&holding_account)
.invoke_signed(&[&[
"fanout-native-account".as_bytes(),
ctx.accounts.fanout.key().as_ref(),
&[ctx.bumps.holding_account],
]])
.map_err(|e| {
error::Error::ProgramError(ProgramErrorWithOrigin {
error::Error::ProgramError(Box::new(ProgramErrorWithOrigin {
program_error: e,
error_origin: None,
compared_values: None,
})
}))
})?;

Ok(())
}
2 changes: 1 addition & 1 deletion hydra/program/src/processors/stake/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn set_token_member_stake(ctx: Context<SetTokenMemberStake>, shares: u64) ->
fanout.total_shares = membership_mint.supply;
fanout.total_members = fanout.total_members.checked_add(1).or_arith_error()?;
membership_voucher.shares = shares;
membership_voucher.bump_seed = *ctx.bumps.get("membership_voucher").unwrap();
membership_voucher.bump_seed = ctx.bumps.membership_voucher;
let cpi_program = ctx.accounts.token_program.to_account_info();
let accounts = anchor_spl::token::Transfer {
from: ctx.accounts.membership_mint_token_account.to_account_info(),
Expand Down
2 changes: 1 addition & 1 deletion hydra/program/src/processors/stake/set_for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn set_for_token_member_stake(ctx: Context<SetForTokenMemberStake>, shares:
fanout.total_shares = membership_mint.supply;
fanout.total_members = fanout.total_members.checked_add(1).or_arith_error()?;
membership_voucher.shares = shares;
membership_voucher.bump_seed = *ctx.bumps.get("membership_voucher").unwrap();
membership_voucher.bump_seed = ctx.bumps.membership_voucher;
let cpi_program = ctx.accounts.token_program.to_account_info();
let accounts = anchor_spl::token::Transfer {
from: ctx.accounts.membership_mint_token_account.to_account_info(),
Expand Down
2 changes: 1 addition & 1 deletion hydra/program/src/processors/stake/unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn unstake(ctx: Context<UnStakeTokenMember>) -> Result<()> {
"fanout-membership".as_bytes(),
fanout.key().as_ref(),
member.key().as_ref(),
&[*ctx.bumps.get("membership_voucher").unwrap()],
&[ctx.bumps.membership_voucher],
]]),
amount,
)?;
Expand Down
5 changes: 3 additions & 2 deletions hydra/program/src/utils/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use anchor_lang::{
solana_program::{instruction::Instruction, program_memory::sol_memcmp, pubkey::PUBKEY_BYTES},
};
use anchor_spl::token::TokenAccount;
use mpl_token_metadata::state::{Metadata, TokenMetadataAccount};
use mpl_token_metadata::accounts::Metadata;


pub fn cmp_pubkeys(a: &Pubkey, b: &Pubkey) -> bool {
sol_memcmp(a.as_ref(), b.as_ref(), PUBKEY_BYTES) == 0
Expand Down Expand Up @@ -117,7 +118,7 @@ pub fn assert_valid_metadata(
metadata_account: &AccountInfo,
mint: &AccountInfo,
) -> Result<Metadata> {
let meta = Metadata::from_account_info(metadata_account)?;
let meta = Metadata::from_bytes(&metadata_account.data.borrow())?;
if !cmp_pubkeys(&meta.mint, mint.key) {
return Err(HydraError::InvalidMetadata.into());
}
Expand Down
Loading