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