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