instructions.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import * as borsh from 'borsh';
  2. class Assignable {
  3. constructor(properties) {
  4. for (const [key, value] of Object.entries(properties)) {
  5. this[key] = value;
  6. }
  7. }
  8. }
  9. export enum MyInstruction {
  10. Create = 0,
  11. MintNft = 1,
  12. MintSpl = 2,
  13. TransferTokens = 3,
  14. }
  15. export class CreateTokenArgs extends Assignable {
  16. toBuffer() {
  17. return Buffer.from(borsh.serialize(CreateTokenArgsSchema, this));
  18. }
  19. }
  20. const CreateTokenArgsSchema = new Map([
  21. [
  22. CreateTokenArgs,
  23. {
  24. kind: 'struct',
  25. fields: [
  26. ['instruction', 'u8'],
  27. ['token_title', 'string'],
  28. ['token_symbol', 'string'],
  29. ['token_uri', 'string'],
  30. ['decimals', 'u8'],
  31. ],
  32. },
  33. ],
  34. ]);
  35. export class MintNftArgs extends Assignable {
  36. toBuffer() {
  37. return Buffer.from(borsh.serialize(MintNftArgsSchema, this));
  38. }
  39. }
  40. const MintNftArgsSchema = new Map([
  41. [
  42. MintNftArgs,
  43. {
  44. kind: 'struct',
  45. fields: [['instruction', 'u8']],
  46. },
  47. ],
  48. ]);
  49. export class MintSplArgs extends Assignable {
  50. toBuffer() {
  51. return Buffer.from(borsh.serialize(MintSplArgsSchema, this));
  52. }
  53. }
  54. const MintSplArgsSchema = new Map([
  55. [
  56. MintSplArgs,
  57. {
  58. kind: 'struct',
  59. fields: [
  60. ['instruction', 'u8'],
  61. ['quantity', 'u64'],
  62. ],
  63. },
  64. ],
  65. ]);
  66. export class TransferTokensArgs extends Assignable {
  67. toBuffer() {
  68. return Buffer.from(borsh.serialize(TransferTokensArgsSchema, this));
  69. }
  70. }
  71. const TransferTokensArgsSchema = new Map([
  72. [
  73. TransferTokensArgs,
  74. {
  75. kind: 'struct',
  76. fields: [
  77. ['instruction', 'u8'],
  78. ['quantity', 'u64'],
  79. ],
  80. },
  81. ],
  82. ]);