|
| 1 | +use steel::*; |
| 2 | + |
| 3 | +use crate::prelude::*; |
| 4 | + |
| 5 | +pub fn create( |
| 6 | + payer: Pubkey, |
| 7 | + mint_authority: Pubkey, |
| 8 | + token_name: String, |
| 9 | + token_symbol: String, |
| 10 | + token_uri: String, |
| 11 | +) -> Instruction { |
| 12 | + let token_name_bytes: [u8; 32] = token_name |
| 13 | + .as_bytes() |
| 14 | + .try_into() |
| 15 | + .expect("String wrong length, expected 32 bytes"); |
| 16 | + let token_symbol_bytes: [u8; 8] = token_symbol |
| 17 | + .as_bytes() |
| 18 | + .try_into() |
| 19 | + .expect("String wrong length, expected 32 bytes"); |
| 20 | + let token_uri_bytes: [u8; 64] = token_uri |
| 21 | + .as_bytes() |
| 22 | + .try_into() |
| 23 | + .expect("String wrong length, expected 32 bytes"); |
| 24 | + |
| 25 | + let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::ID); |
| 26 | + let metadata_pda = Pubkey::find_program_address( |
| 27 | + &[ |
| 28 | + METADATA, |
| 29 | + mpl_token_metadata::ID.as_ref(), |
| 30 | + mint_pda.0.as_ref(), |
| 31 | + ], |
| 32 | + &mpl_token_metadata::ID, |
| 33 | + ); |
| 34 | + |
| 35 | + Instruction { |
| 36 | + program_id: crate::ID, |
| 37 | + accounts: vec![ |
| 38 | + AccountMeta::new(payer, true), |
| 39 | + AccountMeta::new(mint_pda.0, false), |
| 40 | + AccountMeta::new(mint_authority, false), |
| 41 | + AccountMeta::new(metadata_pda.0, false), |
| 42 | + AccountMeta::new_readonly(system_program::ID, false), |
| 43 | + AccountMeta::new_readonly(spl_token::ID, false), |
| 44 | + AccountMeta::new_readonly(mpl_token_metadata::ID, false), |
| 45 | + AccountMeta::new_readonly(sysvar::rent::ID, false), |
| 46 | + ], |
| 47 | + data: Create { |
| 48 | + token_name: token_name_bytes, |
| 49 | + token_symbol: token_symbol_bytes, |
| 50 | + token_uri: token_uri_bytes, |
| 51 | + } |
| 52 | + .to_bytes(), |
| 53 | + } |
| 54 | +} |
| 55 | +pub fn mint( |
| 56 | + signer: Pubkey, |
| 57 | + mint: Pubkey, |
| 58 | + to: Pubkey, |
| 59 | + authority: Pubkey, |
| 60 | + amount: u64, |
| 61 | +) -> Instruction { |
| 62 | + Instruction { |
| 63 | + program_id: crate::ID, |
| 64 | + accounts: vec![ |
| 65 | + AccountMeta::new(signer, true), |
| 66 | + AccountMeta::new(mint, false), |
| 67 | + AccountMeta::new(to, false), |
| 68 | + AccountMeta::new(authority, false), |
| 69 | + AccountMeta::new_readonly(spl_token::ID, false), |
| 70 | + ], |
| 71 | + data: Mint { |
| 72 | + amount: amount.to_le_bytes(), |
| 73 | + } |
| 74 | + .to_bytes(), |
| 75 | + } |
| 76 | +} |
0 commit comments