seahorse.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # seahorse
  2. # Built with Seahorse v0.2.7
  3. from seahorse.prelude import *
  4. declare_id('5KCV219sxBAZMfXWP5EZ57D6K9568krgPKGe1Lq2nkxH')
  5. @instruction
  6. def create_token(
  7. mint: Empty[TokenMint],
  8. signer: Signer
  9. ):
  10. mint.init(
  11. payer = signer,
  12. decimals = 6,
  13. authority = signer
  14. )
  15. @instruction
  16. def mint_token(
  17. mint: TokenMint,
  18. recipient: TokenAccount,
  19. signer: Signer,
  20. amount: u64
  21. ):
  22. mint.mint(
  23. authority = signer,
  24. to = recipient,
  25. amount = amount * u64(10) ** u32(mint.decimals)
  26. )
  27. @instruction
  28. def create_associated_token_account(
  29. token_account: Empty[TokenAccount],
  30. mint: TokenMint,
  31. signer: Signer
  32. ):
  33. token_account.init(
  34. associated = True,
  35. payer = signer,
  36. mint = mint,
  37. authority = signer
  38. )
  39. @instruction
  40. def transfer(
  41. signer_token_account: TokenAccount,
  42. recipient: TokenAccount,
  43. signer: Signer,
  44. amount: u64,
  45. mint: TokenMint
  46. ):
  47. assert signer_token_account.mint() == mint.key(), 'Mint is not the token account mint'
  48. signer_token_account.transfer(
  49. authority = signer,
  50. to = recipient,
  51. amount = amount * u64(10) ** u32(mint.decimals)
  52. )