sdk.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use steel::*;
  2. use crate::prelude::*;
  3. pub fn create(
  4. payer: Pubkey,
  5. mint: Pubkey,
  6. token_name: [u8; 32],
  7. token_symbol: [u8; 8],
  8. token_uri: [u8; 64],
  9. ) -> Instruction {
  10. let metadata_pda = Pubkey::find_program_address(
  11. &[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref()],
  12. &mpl_token_metadata::ID,
  13. );
  14. Instruction {
  15. program_id: crate::ID,
  16. accounts: vec![
  17. AccountMeta::new(payer, true),
  18. AccountMeta::new(mint, true),
  19. AccountMeta::new(metadata_pda.0, false),
  20. AccountMeta::new_readonly(system_program::ID, false),
  21. AccountMeta::new_readonly(spl_token::ID, false),
  22. AccountMeta::new_readonly(mpl_token_metadata::ID, false),
  23. AccountMeta::new_readonly(sysvar::rent::ID, false),
  24. ],
  25. data: Create {
  26. token_name,
  27. token_symbol,
  28. token_uri,
  29. }
  30. .to_bytes(),
  31. }
  32. }
  33. pub fn mint(
  34. mint_authority: Pubkey,
  35. recipient: Pubkey,
  36. mint: Pubkey,
  37. associated_token_account: Pubkey,
  38. quantity: u64,
  39. ) -> Instruction {
  40. Instruction {
  41. program_id: crate::ID,
  42. accounts: vec![
  43. AccountMeta::new(mint_authority, true),
  44. AccountMeta::new(recipient, false),
  45. AccountMeta::new(mint, false),
  46. AccountMeta::new(associated_token_account, false),
  47. AccountMeta::new_readonly(spl_token::ID, false),
  48. AccountMeta::new_readonly(spl_associated_token_account::ID, false),
  49. AccountMeta::new_readonly(system_program::ID, false),
  50. ],
  51. data: Mint {
  52. quantity: quantity.to_le_bytes(),
  53. }
  54. .to_bytes(),
  55. }
  56. }