instructions.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import * as borsh from "borsh";
  2. class Assignable {
  3. constructor(properties) {
  4. Object.keys(properties).map((key) => {
  5. return (this[key] = properties[key]);
  6. });
  7. };
  8. };
  9. export enum MyInstruction {
  10. Create,
  11. MintNft,
  12. MintSpl,
  13. TransferTokens,
  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. kind: 'struct',
  24. fields: [
  25. ['instruction', 'u8'],
  26. ['token_title', 'string'],
  27. ['token_symbol', 'string'],
  28. ['token_uri', 'string'],
  29. ['decimals', 'u8'],
  30. ]
  31. }
  32. ]
  33. ]);
  34. export class MintNftArgs extends Assignable {
  35. toBuffer() {
  36. return Buffer.from(borsh.serialize(MintNftArgsSchema, this));
  37. }
  38. };
  39. const MintNftArgsSchema = new Map([
  40. [
  41. MintNftArgs, {
  42. kind: 'struct',
  43. fields: [
  44. ['instruction', 'u8'],
  45. ]
  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. kind: 'struct',
  58. fields: [
  59. ['instruction', 'u8'],
  60. ['quantity', 'u64'],
  61. ]
  62. }
  63. ]
  64. ]);
  65. export class TransferTokensArgs extends Assignable {
  66. toBuffer() {
  67. return Buffer.from(borsh.serialize(TransferTokensArgsSchema, this));
  68. }
  69. };
  70. const TransferTokensArgsSchema = new Map([
  71. [
  72. TransferTokensArgs, {
  73. kind: 'struct',
  74. fields: [
  75. ['instruction', 'u8'],
  76. ['quantity', 'u64'],
  77. ]
  78. }
  79. ]
  80. ]);