@sentio/sdk 1.37.0-rc.2 → 1.37.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/lib/builtin/index.d.ts +0 -2
  2. package/lib/builtin/index.js +1 -3
  3. package/lib/builtin/index.js.map +1 -1
  4. package/lib/core/eth-plugin.js +12 -15
  5. package/lib/core/eth-plugin.js.map +1 -1
  6. package/lib/core/index.d.ts +0 -4
  7. package/lib/core/index.js +1 -9
  8. package/lib/core/index.js.map +1 -1
  9. package/lib/core/sui-plugin.js +1 -1
  10. package/lib/core/sui-plugin.js.map +1 -1
  11. package/lib/index.d.ts +1 -1
  12. package/lib/index.js +3 -14
  13. package/lib/index.js.map +1 -1
  14. package/lib/service.d.ts +0 -4
  15. package/lib/service.js +40 -71
  16. package/lib/service.js.map +1 -1
  17. package/package.json +5 -16
  18. package/src/builtin/index.ts +1 -4
  19. package/src/core/eth-plugin.ts +5 -8
  20. package/src/core/index.ts +0 -5
  21. package/src/core/sui-plugin.ts +2 -2
  22. package/src/index.ts +3 -1
  23. package/src/service.ts +13 -71
  24. package/lib/aptos/api.d.ts +0 -2
  25. package/lib/aptos/api.js +0 -14
  26. package/lib/aptos/api.js.map +0 -1
  27. package/lib/aptos/aptos-plugin.d.ts +0 -14
  28. package/lib/aptos/aptos-plugin.js +0 -185
  29. package/lib/aptos/aptos-plugin.js.map +0 -1
  30. package/lib/aptos/aptos-processor.d.ts +0 -75
  31. package/lib/aptos/aptos-processor.js +0 -193
  32. package/lib/aptos/aptos-processor.js.map +0 -1
  33. package/lib/aptos/context.d.ts +0 -22
  34. package/lib/aptos/context.js +0 -65
  35. package/lib/aptos/context.js.map +0 -1
  36. package/lib/aptos/index.d.ts +0 -9
  37. package/lib/aptos/index.js +0 -34
  38. package/lib/aptos/index.js.map +0 -1
  39. package/lib/aptos/models.d.ts +0 -23
  40. package/lib/aptos/models.js +0 -3
  41. package/lib/aptos/models.js.map +0 -1
  42. package/lib/aptos/network.d.ts +0 -14
  43. package/lib/aptos/network.js +0 -46
  44. package/lib/aptos/network.js.map +0 -1
  45. package/lib/aptos/runtime.d.ts +0 -2
  46. package/lib/aptos/runtime.js +0 -16
  47. package/lib/aptos/runtime.js.map +0 -1
  48. package/lib/aptos/type-registry.d.ts +0 -21
  49. package/lib/aptos/type-registry.js +0 -156
  50. package/lib/aptos/type-registry.js.map +0 -1
  51. package/lib/aptos/types.d.ts +0 -9
  52. package/lib/aptos/types.js +0 -135
  53. package/lib/aptos/types.js.map +0 -1
  54. package/lib/aptos/types.test.d.ts +0 -1
  55. package/lib/aptos/types.test.js.map +0 -1
  56. package/lib/aptos/utils.d.ts +0 -7
  57. package/lib/aptos/utils.js +0 -27
  58. package/lib/aptos/utils.js.map +0 -1
  59. package/lib/aptos-codegen/codegen.d.ts +0 -23
  60. package/lib/aptos-codegen/codegen.js +0 -364
  61. package/lib/aptos-codegen/codegen.js.map +0 -1
  62. package/lib/aptos-codegen/typegen.d.ts +0 -17
  63. package/lib/aptos-codegen/typegen.js +0 -142
  64. package/lib/aptos-codegen/typegen.js.map +0 -1
  65. package/lib/builtin/aptos/0x1.d.ts +0 -1913
  66. package/lib/builtin/aptos/0x1.js +0 -2748
  67. package/lib/builtin/aptos/0x1.js.map +0 -1
  68. package/lib/builtin/aptos/0x3.d.ts +0 -482
  69. package/lib/builtin/aptos/0x3.js +0 -526
  70. package/lib/builtin/aptos/0x3.js.map +0 -1
  71. package/lib/builtin/aptos/index.d.ts +0 -2
  72. package/lib/builtin/aptos/index.js +0 -29
  73. package/lib/builtin/aptos/index.js.map +0 -1
  74. package/lib/builtin/solana/index.d.ts +0 -2
  75. package/lib/builtin/solana/index.js +0 -19
  76. package/lib/builtin/solana/index.js.map +0 -1
  77. package/lib/builtin/solana/spl-token-processor.d.ts +0 -39
  78. package/lib/builtin/solana/spl-token-processor.js +0 -258
  79. package/lib/builtin/solana/spl-token-processor.js.map +0 -1
  80. package/lib/builtin/solana/types.d.ts +0 -427
  81. package/lib/builtin/solana/types.js +0 -203
  82. package/lib/builtin/solana/types.js.map +0 -1
  83. package/lib/builtin/solana/wormhole-processor.d.ts +0 -12
  84. package/lib/builtin/solana/wormhole-processor.js +0 -268
  85. package/lib/builtin/solana/wormhole-processor.js.map +0 -1
  86. package/lib/core/solana-context.d.ts +0 -11
  87. package/lib/core/solana-context.js +0 -34
  88. package/lib/core/solana-context.js.map +0 -1
  89. package/lib/core/solana-options.d.ts +0 -8
  90. package/lib/core/solana-options.js +0 -13
  91. package/lib/core/solana-options.js.map +0 -1
  92. package/lib/core/solana-plugin.d.ts +0 -9
  93. package/lib/core/solana-plugin.js +0 -79
  94. package/lib/core/solana-plugin.js.map +0 -1
  95. package/lib/core/solana-processor.d.ts +0 -40
  96. package/lib/core/solana-processor.js +0 -80
  97. package/lib/core/solana-processor.js.map +0 -1
  98. package/lib/solana-codegen/codegen.d.ts +0 -1
  99. package/lib/solana-codegen/codegen.js +0 -124
  100. package/lib/solana-codegen/codegen.js.map +0 -1
  101. package/lib/test-abi-code-gen.d.ts +0 -2
  102. package/lib/test-abi-code-gen.js +0 -20
  103. package/lib/test-abi-code-gen.js.map +0 -1
  104. package/src/abis/aptos/0x1.json +0 -9205
  105. package/src/abis/aptos/0x3.json +0 -1515
  106. package/src/aptos/api.ts +0 -11
  107. package/src/aptos/aptos-plugin.ts +0 -216
  108. package/src/aptos/aptos-processor.ts +0 -305
  109. package/src/aptos/context.ts +0 -74
  110. package/src/aptos/index.ts +0 -10
  111. package/src/aptos/models.ts +0 -34
  112. package/src/aptos/network.ts +0 -42
  113. package/src/aptos/runtime.ts +0 -13
  114. package/src/aptos/type-registry.ts +0 -187
  115. package/src/aptos/types.ts +0 -149
  116. package/src/aptos/utils.ts +0 -26
  117. package/src/aptos-codegen/codegen.ts +0 -428
  118. package/src/aptos-codegen/tsconfig.json +0 -9
  119. package/src/aptos-codegen/typegen.ts +0 -153
  120. package/src/builtin/aptos/0x1.ts +0 -4210
  121. package/src/builtin/aptos/0x3.ts +0 -888
  122. package/src/builtin/aptos/index.ts +0 -2
  123. package/src/builtin/solana/index.ts +0 -2
  124. package/src/builtin/solana/spl-token-processor.ts +0 -298
  125. package/src/builtin/solana/types.ts +0 -279
  126. package/src/builtin/solana/wormhole-processor.ts +0 -269
  127. package/src/core/solana-context.ts +0 -34
  128. package/src/core/solana-options.ts +0 -8
  129. package/src/core/solana-plugin.ts +0 -97
  130. package/src/core/solana-processor.ts +0 -102
  131. package/src/solana-codegen/codegen.ts +0 -129
  132. package/src/test-abi-code-gen.ts +0 -16
@@ -1,124 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.codeGenSolanaProcessor = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const chalk_1 = __importDefault(require("chalk"));
10
- function codeGenSolanaProcessor(abisDir, targetPath = path_1.default.join('src', 'types', 'solana')) {
11
- if (!fs_1.default.existsSync(abisDir)) {
12
- return;
13
- }
14
- const abisFiles = fs_1.default.readdirSync(abisDir);
15
- if (abisFiles.length > 0) {
16
- console.log(chalk_1.default.green('Generated Types for Solana'));
17
- }
18
- for (const file of abisFiles) {
19
- if (path_1.default.extname(file) === '.json') {
20
- if (!fs_1.default.existsSync(targetPath)) {
21
- fs_1.default.mkdirSync(targetPath, { recursive: true });
22
- }
23
- const idlContent = fs_1.default.readFileSync(path_1.default.join(abisDir, file), 'utf-8');
24
- const idlObj = JSON.parse(idlContent);
25
- const idlName = idlObj.name;
26
- const idlFile = path_1.default.join(targetPath, idlName + '.ts');
27
- fs_1.default.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`);
28
- fs_1.default.writeFileSync(path_1.default.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj));
29
- }
30
- }
31
- }
32
- exports.codeGenSolanaProcessor = codeGenSolanaProcessor;
33
- function codeGenSolanaIdlProcessor(idlObj) {
34
- const idlName = idlObj.name;
35
- const idlNamePascalCase = toPascalCase(idlName);
36
- const instructions = idlObj.instructions;
37
- return `import { BorshInstructionCoder, Instruction, Idl } from '@project-serum/anchor'
38
- import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from "@sentio/sdk"
39
- import { ${idlName}_idl } from "./${idlName}"
40
- import bs58 from 'bs58'
41
- import { PublicKey } from '@solana/web3.js'
42
-
43
- export class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {
44
- static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {
45
- if (options && !options.name) {
46
- options.name = '${idlNamePascalCase}'
47
- }
48
- return new ${idlNamePascalCase}Processor(options)
49
- }
50
-
51
- decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {
52
- const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)
53
- const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))
54
- return decodedIns
55
- }
56
-
57
- ${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}
58
- }
59
- `;
60
- }
61
- function codeGenSolanaInstruction(idlName, ins) {
62
- const instructionName = ins.name;
63
- return `
64
- on${instructionName.charAt(0).toUpperCase() + instructionName.slice(1)}(handler: (args: ${codeGenInstructionArgsType(ins.args)}, accounts: string[], ctx: SolanaContext) => void): ${idlName}Processor {
65
- this.onInstruction('${instructionName}', (ins: Instruction, ctx, accounts: string[]) => {
66
- const origin = ins.data as any
67
- const data = ${codeGenInstructionArgs(ins.args)}
68
- if (ins) {
69
- handler(data, accounts, ctx)
70
- }
71
- })
72
- return this
73
- }
74
- `;
75
- }
76
- function codeGenInstructionArgs(args) {
77
- return `{ ${args.map((arg) => codeGenInstructionArg(arg.name, arg.type)).join(', ')} }`;
78
- }
79
- function codeGenInstructionArg(name, type) {
80
- const mType = mapType(type);
81
- if (mType === 'bigint') {
82
- return `${name}: BigInt(origin.${name}.toString())`;
83
- }
84
- return `${name}: origin.${name} as ${mType}`;
85
- }
86
- function codeGenInstructionArgsType(args) {
87
- return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`;
88
- }
89
- // Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104
90
- function mapType(tpe) {
91
- switch (tpe) {
92
- case 'publicKey':
93
- return 'PublicKey';
94
- case 'bool':
95
- return 'boolean';
96
- case 'string':
97
- return 'string';
98
- case 'u8':
99
- case 'i8':
100
- case 'u16':
101
- case 'i16':
102
- case 'u32':
103
- case 'i32':
104
- case 'f32':
105
- case 'f64':
106
- return 'number';
107
- case 'u64':
108
- case 'i64':
109
- case 'u128':
110
- case 'i128':
111
- return 'bigint';
112
- default:
113
- return 'any';
114
- }
115
- }
116
- function toPascalCase(str) {
117
- return `${str}`
118
- .toLowerCase()
119
- .replace(new RegExp(/[-_]+/, 'g'), ' ')
120
- .replace(new RegExp(/[^\w\s]/, 'g'), '')
121
- .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)
122
- .replace(new RegExp(/\w/), (s) => s.toUpperCase());
123
- }
124
- //# sourceMappingURL=codegen.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/solana-codegen/codegen.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,4CAAmB;AACnB,kDAAyB;AAEzB,SAAgB,sBAAsB,CAAC,OAAe,EAAE,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC;IACtG,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAM;KACP;IAED,MAAM,SAAS,GAAG,YAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAEzC,IAAI,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anaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n const abisFiles = fs.readdirSync(abisDir)\n\n if (abisFiles.length > 0) {\n console.log(chalk.green('Generated Types for Solana'))\n }\n\n for (const file of abisFiles) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(targetPath)) {\n fs.mkdirSync(targetPath, { recursive: true })\n }\n const idlContent = fs.readFileSync(path.join(abisDir, file), 'utf-8')\n const idlObj = JSON.parse(idlContent)\n const idlName = idlObj.name\n const idlFile = path.join(targetPath, idlName + '.ts')\n fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)\n fs.writeFileSync(path.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))\n }\n }\n}\n\nfunction codeGenSolanaIdlProcessor(idlObj: any): string {\n const idlName = idlObj.name\n const idlNamePascalCase = toPascalCase(idlName)\n const instructions: any[] = idlObj.instructions\n return `import { BorshInstructionCoder, Instruction, Idl } from '@project-serum/anchor'\nimport { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from \"@sentio/sdk\"\nimport { ${idlName}_idl } from \"./${idlName}\"\nimport bs58 from 'bs58'\nimport { PublicKey } from '@solana/web3.js'\n\nexport class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {\n static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {\n if (options && !options.name) {\n options.name = '${idlNamePascalCase}'\n }\n return new ${idlNamePascalCase}Processor(options)\n }\n\n decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {\n const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)\n const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))\n return decodedIns\n }\n\n ${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}\n}\n `\n}\n\nfunction codeGenSolanaInstruction(idlName: string, ins: any): string {\n const instructionName = ins.name\n return `\n on${instructionName.charAt(0).toUpperCase() + instructionName.slice(1)}(handler: (args: ${codeGenInstructionArgsType(\n ins.args\n )}, accounts: string[], ctx: SolanaContext) => void): ${idlName}Processor {\n this.onInstruction('${instructionName}', (ins: Instruction, ctx, accounts: string[]) => {\n const origin = ins.data as any\n const data = ${codeGenInstructionArgs(ins.args)}\n if (ins) {\n handler(data, accounts, ctx)\n }\n })\n return this\n }\n `\n}\n\nfunction codeGenInstructionArgs(args: { name: string; type: string }[]): string {\n return `{ ${args.map((arg) => codeGenInstructionArg(arg.name, arg.type)).join(', ')} }`\n}\n\nfunction codeGenInstructionArg(name: string, type: string): string {\n const mType = mapType(type)\n if (mType === 'bigint') {\n return `${name}: BigInt(origin.${name}.toString())`\n }\n return `${name}: origin.${name} as ${mType}`\n}\n\nfunction codeGenInstructionArgsType(args: { name: string; type: string }[]): string {\n return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`\n}\n\n// Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104\nfunction mapType(tpe: string): string {\n switch (tpe) {\n case 'publicKey':\n return 'PublicKey'\n case 'bool':\n return 'boolean'\n case 'string':\n return 'string'\n case 'u8':\n case 'i8':\n case 'u16':\n case 'i16':\n case 'u32':\n case 'i32':\n case 'f32':\n case 'f64':\n return 'number'\n case 'u64':\n case 'i64':\n case 'u128':\n case 'i128':\n return 'bigint'\n default:\n return 'any'\n }\n}\n\nfunction toPascalCase(str: string) {\n return `${str}`\n .toLowerCase()\n .replace(new RegExp(/[-_]+/, 'g'), ' ')\n .replace(new RegExp(/[^\\w\\s]/, 'g'), '')\n .replace(new RegExp(/\\s+(.)(\\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)\n .replace(new RegExp(/\\w/), (s) => s.toUpperCase())\n}\n"]}
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const path_1 = __importDefault(require("path"));
8
- const codegen_1 = require("./solana-codegen/codegen");
9
- const codegen_2 = require("./aptos-codegen/codegen");
10
- if (process.argv.length > 3) {
11
- const abisDir = process.argv[2];
12
- const targetDir = process.argv[3];
13
- (0, codegen_2.codeGenAptosProcessor)(path_1.default.join(abisDir, 'aptos'), path_1.default.join(targetDir, 'aptos'));
14
- (0, codegen_1.codeGenSolanaProcessor)(path_1.default.join(abisDir, 'solana'), path_1.default.join(targetDir, 'solana'));
15
- }
16
- else {
17
- console.error('Not enough argument');
18
- process.exit(1);
19
- }
20
- //# sourceMappingURL=test-abi-code-gen.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-abi-code-gen.js","sourceRoot":"","sources":["../src/test-abi-code-gen.ts"],"names":[],"mappings":";;;;;;AAEA,gDAAuB;AACvB,sDAAiE;AACjE,qDAA+D;AAE/D,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;IAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAEjC,IAAA,+BAAqB,EAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAA;IACjF,IAAA,gCAAsB,EAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA;CACrF;KAAM;IACL,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;CAChB","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport { codeGenSolanaProcessor } from './solana-codegen/codegen'\nimport { codeGenAptosProcessor } from './aptos-codegen/codegen'\n\nif (process.argv.length > 3) {\n const abisDir = process.argv[2]\n const targetDir = process.argv[3]\n\n codeGenAptosProcessor(path.join(abisDir, 'aptos'), path.join(targetDir, 'aptos'))\n codeGenSolanaProcessor(path.join(abisDir, 'solana'), path.join(targetDir, 'solana'))\n} else {\n console.error('Not enough argument')\n process.exit(1)\n}\n"]}