@sentio/sdk 1.7.13 → 1.7.16

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 (299) hide show
  1. package/{base-processor-template.d.ts → lib/base-processor-template.d.ts} +0 -0
  2. package/{base-processor-template.js → lib/base-processor-template.js} +0 -0
  3. package/lib/base-processor-template.js.map +1 -0
  4. package/{base-processor.d.ts → lib/base-processor.d.ts} +0 -0
  5. package/{base-processor.js → lib/base-processor.js} +0 -0
  6. package/lib/base-processor.js.map +1 -0
  7. package/{bind-options.d.ts → lib/bind-options.d.ts} +0 -0
  8. package/{bind-options.js → lib/bind-options.js} +0 -0
  9. package/lib/bind-options.js.map +1 -0
  10. package/{binds.d.ts → lib/binds.d.ts} +0 -0
  11. package/{binds.js → lib/binds.js} +0 -0
  12. package/lib/binds.js.map +1 -0
  13. package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
  14. package/{builtin → lib/builtin}/erc20/index.js +0 -0
  15. package/lib/builtin/erc20/index.js.map +1 -0
  16. package/{builtin → lib/builtin}/erc20/test-utils.d.ts +0 -0
  17. package/{builtin → lib/builtin}/erc20/test-utils.js +0 -0
  18. package/lib/builtin/erc20/test-utils.js.map +1 -0
  19. package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
  20. package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
  21. package/lib/builtin/internal/Erc20.js.map +1 -0
  22. package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
  23. package/{builtin → lib/builtin}/internal/common.js +0 -0
  24. package/lib/builtin/internal/common.js.map +1 -0
  25. package/{builtin → lib/builtin}/internal/erc20_processor.d.ts +0 -0
  26. package/{builtin → lib/builtin}/internal/erc20_processor.js +0 -0
  27. package/lib/builtin/internal/erc20_processor.js.map +1 -0
  28. package/{builtin → lib/builtin}/internal/factories/Erc20__factory.d.ts +0 -0
  29. package/{builtin → lib/builtin}/internal/factories/Erc20__factory.js +0 -0
  30. package/lib/builtin/internal/factories/Erc20__factory.js.map +1 -0
  31. package/{builtin → lib/builtin}/internal/factories/index.d.ts +0 -0
  32. package/{builtin → lib/builtin}/internal/factories/index.js +0 -0
  33. package/{builtin → lib/builtin}/internal/factories/index.js.map +1 -1
  34. package/{builtin → lib/builtin}/internal/index.d.ts +0 -0
  35. package/{builtin → lib/builtin}/internal/index.js +0 -0
  36. package/lib/builtin/internal/index.js.map +1 -0
  37. package/{chain-config.d.ts → lib/chain-config.d.ts} +0 -0
  38. package/{chain-config.js → lib/chain-config.js} +0 -0
  39. package/lib/chain-config.js.map +1 -0
  40. package/{cli → lib/cli}/build.d.ts +0 -0
  41. package/{cli → lib/cli}/build.js +0 -0
  42. package/lib/cli/build.js.map +1 -0
  43. package/{cli → lib/cli}/cli.d.ts +0 -0
  44. package/{cli → lib/cli}/cli.js +0 -0
  45. package/lib/cli/cli.js.map +1 -0
  46. package/{cli → lib/cli}/config.d.ts +0 -0
  47. package/{cli → lib/cli}/config.js +0 -0
  48. package/lib/cli/config.js.map +1 -0
  49. package/{cli → lib/cli}/key.d.ts +0 -0
  50. package/{cli → lib/cli}/key.js +0 -0
  51. package/{cli → lib/cli}/key.js.map +1 -1
  52. package/{cli → lib/cli}/solana-code-gen.d.ts +0 -0
  53. package/{cli → lib/cli}/solana-code-gen.js +0 -0
  54. package/{cli → lib/cli}/solana-code-gen.js.map +1 -1
  55. package/{cli → lib/cli}/upload.d.ts +0 -0
  56. package/{cli → lib/cli}/upload.js +0 -0
  57. package/{cli → lib/cli}/upload.js.map +1 -1
  58. package/{cli → lib/cli}/webpack.config.js +0 -0
  59. package/{context.d.ts → lib/context.d.ts} +0 -0
  60. package/{context.js → lib/context.js} +0 -0
  61. package/lib/context.js.map +1 -0
  62. package/{contract-namer.d.ts → lib/contract-namer.d.ts} +0 -0
  63. package/{contract-namer.js → lib/contract-namer.js} +0 -0
  64. package/{contract-namer.js.map → lib/contract-namer.js.map} +1 -1
  65. package/{error.d.ts → lib/error.d.ts} +0 -0
  66. package/{error.js → lib/error.js} +0 -0
  67. package/lib/error.js.map +1 -0
  68. package/{gen → lib/gen}/builtin.d.ts +0 -0
  69. package/{gen → lib/gen}/builtin.js +0 -0
  70. package/lib/gen/builtin.js.map +1 -0
  71. package/{gen → lib/gen}/google/protobuf/empty.d.ts +0 -0
  72. package/{gen → lib/gen}/google/protobuf/empty.js +0 -0
  73. package/lib/gen/google/protobuf/empty.js.map +1 -0
  74. package/{gen → lib/gen}/processor/protos/processor.d.ts +0 -0
  75. package/{gen → lib/gen}/processor/protos/processor.js +0 -0
  76. package/lib/gen/processor/protos/processor.js.map +1 -0
  77. package/{generic-processor.d.ts → lib/generic-processor.d.ts} +0 -0
  78. package/{generic-processor.js → lib/generic-processor.js} +0 -0
  79. package/lib/generic-processor.js.map +1 -0
  80. package/{index.d.ts → lib/index.d.ts} +0 -0
  81. package/{index.js → lib/index.js} +0 -0
  82. package/lib/index.js.map +1 -0
  83. package/lib/loader.d.ts +5 -0
  84. package/lib/loader.js +30 -0
  85. package/lib/loader.js.map +1 -0
  86. package/{meter.d.ts → lib/meter.d.ts} +0 -0
  87. package/{meter.js → lib/meter.js} +0 -0
  88. package/lib/meter.js.map +1 -0
  89. package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
  90. package/{numberish.js → lib/numberish.js} +0 -0
  91. package/lib/numberish.js.map +1 -0
  92. package/{numberish.test.d.ts → lib/numberish.test.d.ts} +0 -0
  93. package/{numberish.test.js → lib/numberish.test.js} +0 -0
  94. package/{numberish.test.js.map → lib/numberish.test.js.map} +1 -1
  95. package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
  96. package/{processor-runner.js → lib/processor-runner.js} +2 -27
  97. package/lib/processor-runner.js.map +1 -0
  98. package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
  99. package/{processor-state.js → lib/processor-state.js} +0 -0
  100. package/lib/processor-state.js.map +1 -0
  101. package/{promise-or-void.d.ts → lib/promise-or-void.d.ts} +0 -0
  102. package/{promise-or-void.js → lib/promise-or-void.js} +0 -0
  103. package/lib/promise-or-void.js.map +1 -0
  104. package/{provider.d.ts → lib/provider.d.ts} +0 -0
  105. package/{provider.js → lib/provider.js} +0 -0
  106. package/lib/provider.js.map +1 -0
  107. package/{release.config.js → lib/release.config.js} +0 -0
  108. package/{service.d.ts → lib/service.d.ts} +2 -1
  109. package/{service.js → lib/service.js} +6 -3
  110. package/lib/service.js.map +1 -0
  111. package/{solana → lib/solana}/builtin/index.d.ts +0 -0
  112. package/{solana → lib/solana}/builtin/index.js +0 -0
  113. package/lib/solana/builtin/index.js.map +1 -0
  114. package/{solana → lib/solana}/builtin/spl-token-processor.d.ts +0 -0
  115. package/{solana → lib/solana}/builtin/spl-token-processor.js +0 -0
  116. package/lib/solana/builtin/spl-token-processor.js.map +1 -0
  117. package/{solana → lib/solana}/builtin/types.d.ts +0 -0
  118. package/{solana → lib/solana}/builtin/types.js +0 -0
  119. package/lib/solana/builtin/types.js.map +1 -0
  120. package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
  121. package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
  122. package/lib/solana/builtin/wormhole-processor.js.map +1 -0
  123. package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
  124. package/{solana-processor.js → lib/solana-processor.js} +0 -0
  125. package/lib/solana-processor.js.map +1 -0
  126. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.d.ts +0 -0
  127. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js +0 -0
  128. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js.map +0 -0
  129. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.d.ts +0 -0
  130. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js +0 -0
  131. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js.map +0 -0
  132. package/{test → lib/test}/codegen.test.d.ts +0 -0
  133. package/{test → lib/test}/codegen.test.js +1 -1
  134. package/lib/test/codegen.test.js.map +1 -0
  135. package/{test → lib/test}/erc20-template.d.ts +0 -0
  136. package/{test → lib/test}/erc20-template.js +0 -0
  137. package/lib/test/erc20-template.js.map +1 -0
  138. package/{test → lib/test}/erc20-template.test.d.ts +0 -0
  139. package/{test → lib/test}/erc20-template.test.js +1 -3
  140. package/lib/test/erc20-template.test.js.map +1 -0
  141. package/{test → lib/test}/erc20.d.ts +0 -0
  142. package/{test → lib/test}/erc20.js +0 -0
  143. package/lib/test/erc20.js.map +1 -0
  144. package/{test → lib/test}/erc20.test.d.ts +0 -0
  145. package/{test → lib/test}/erc20.test.js +1 -3
  146. package/lib/test/erc20.test.js.map +1 -0
  147. package/{test → lib/test}/generic-processor.test.d.ts +0 -0
  148. package/{test → lib/test}/generic-processor.test.js +14 -4
  149. package/lib/test/generic-processor.test.js.map +1 -0
  150. package/{test → lib/test}/index.d.ts +0 -0
  151. package/{test → lib/test}/index.js +0 -0
  152. package/{test → lib/test}/index.js.map +1 -1
  153. package/{test → lib/test}/metric-utils.d.ts +0 -0
  154. package/{test → lib/test}/metric-utils.js +0 -0
  155. package/lib/test/metric-utils.js.map +1 -0
  156. package/{test → lib/test}/mirrorworld.d.ts +0 -0
  157. package/{test → lib/test}/mirrorworld.js +0 -0
  158. package/{test → lib/test}/mirrorworld.js.map +1 -1
  159. package/{test → lib/test}/solana.test.d.ts +0 -0
  160. package/{test → lib/test}/solana.test.js +3 -3
  161. package/lib/test/solana.test.js.map +1 -0
  162. package/{test → lib/test}/test-processor-server.d.ts +1 -1
  163. package/{test → lib/test}/test-processor-server.js +3 -8
  164. package/lib/test/test-processor-server.js.map +1 -0
  165. package/{test → lib/test}/types/game_wallet.d.ts +0 -0
  166. package/{test → lib/test}/types/game_wallet.js +0 -0
  167. package/lib/test/types/game_wallet.js.map +1 -0
  168. package/{test → lib/test}/types/game_wallet_processor.d.ts +0 -0
  169. package/{test → lib/test}/types/game_wallet_processor.js +0 -0
  170. package/lib/test/types/game_wallet_processor.js.map +1 -0
  171. package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
  172. package/{test → lib/test}/wormhole-token-bridge.js +0 -0
  173. package/lib/test/wormhole-token-bridge.js.map +1 -0
  174. package/{utils → lib/utils}/chainmap.d.ts +0 -0
  175. package/{utils → lib/utils}/chainmap.js +0 -0
  176. package/lib/utils/chainmap.js.map +1 -0
  177. package/{utils → lib/utils}/convert.d.ts +0 -0
  178. package/{utils → lib/utils}/convert.js +0 -0
  179. package/lib/utils/convert.js.map +1 -0
  180. package/{utils → lib/utils}/index.d.ts +0 -0
  181. package/{utils → lib/utils}/index.js +0 -0
  182. package/lib/utils/index.js.map +1 -0
  183. package/package.json +47 -6
  184. package/src/abis/erc20.json +198 -0
  185. package/src/base-processor-template.ts +92 -0
  186. package/src/base-processor.ts +128 -0
  187. package/src/bind-options.ts +41 -0
  188. package/src/binds.ts +73 -0
  189. package/src/builtin/erc20/index.ts +6 -0
  190. package/src/builtin/erc20/test-utils.ts +49 -0
  191. package/src/builtin/internal/Erc20.ts +356 -0
  192. package/src/builtin/internal/common.ts +46 -0
  193. package/src/builtin/internal/erc20_processor.ts +295 -0
  194. package/src/builtin/internal/factories/Erc20__factory.ts +216 -0
  195. package/src/builtin/internal/factories/index.ts +4 -0
  196. package/src/builtin/internal/index.ts +6 -0
  197. package/src/chain-config.ts +6 -0
  198. package/src/cli/build.ts +180 -0
  199. package/src/cli/cli.ts +217 -0
  200. package/src/cli/config.ts +43 -0
  201. package/src/cli/key.ts +43 -0
  202. package/src/cli/solana-code-gen.ts +16 -0
  203. package/src/cli/upload.ts +86 -0
  204. package/src/cli/webpack.config.js +42 -0
  205. package/src/context.ts +93 -0
  206. package/src/contract-namer.ts +17 -0
  207. package/src/error.ts +43 -0
  208. package/src/gen/builtin.ts +22 -0
  209. package/src/gen/google/protobuf/empty.ts +70 -0
  210. package/src/gen/processor/protos/processor.ts +3071 -0
  211. package/src/generic-processor.ts +38 -0
  212. package/src/index.ts +19 -0
  213. package/src/loader.ts +24 -0
  214. package/src/meter.ts +122 -0
  215. package/src/numberish.test.ts +82 -0
  216. package/src/numberish.ts +99 -0
  217. package/src/processor-runner.ts +49 -0
  218. package/src/processor-state.ts +24 -0
  219. package/src/promise-or-void.ts +1 -0
  220. package/src/provider.ts +74 -0
  221. package/src/service.ts +439 -0
  222. package/src/solana/builtin/index.ts +2 -0
  223. package/src/solana/builtin/spl-token-processor.ts +164 -0
  224. package/src/solana/builtin/types.ts +268 -0
  225. package/src/solana/builtin/wormhole-processor.ts +178 -0
  226. package/src/solana-processor.ts +105 -0
  227. package/src/target-ethers-sentio/codegen.ts +289 -0
  228. package/src/target-ethers-sentio/index.ts +50 -0
  229. package/src/target-ethers-sentio/tsconfig.json +9 -0
  230. package/src/test/abis/evm/anyswapRouter.json +490 -0
  231. package/src/test/abis/solana/mirrorworld.json +1392 -0
  232. package/src/test/codegen.test.ts +26 -0
  233. package/src/test/erc20-template.test.ts +37 -0
  234. package/src/test/erc20-template.ts +25 -0
  235. package/src/test/erc20.test.ts +90 -0
  236. package/src/test/erc20.ts +48 -0
  237. package/src/test/generic-processor.test.ts +70 -0
  238. package/src/test/index.ts +1 -0
  239. package/src/test/metric-utils.ts +49 -0
  240. package/src/test/mirrorworld.ts +40 -0
  241. package/src/test/sentio.yaml +4 -0
  242. package/src/test/solana.test.ts +93 -0
  243. package/src/test/test-processor-server.ts +205 -0
  244. package/src/test/types/game_wallet.ts +1392 -0
  245. package/src/test/types/game_wallet_processor.ts +113 -0
  246. package/src/test/wormhole-token-bridge.ts +21 -0
  247. package/src/types/global.d.ts +17 -0
  248. package/src/utils/chainmap.ts +95 -0
  249. package/src/utils/convert.ts +6 -0
  250. package/src/utils/index.ts +2 -0
  251. package/base-processor-template.js.map +0 -1
  252. package/base-processor.js.map +0 -1
  253. package/bind-options.js.map +0 -1
  254. package/binds.js.map +0 -1
  255. package/builtin/erc20/index.js.map +0 -1
  256. package/builtin/erc20/test-utils.js.map +0 -1
  257. package/builtin/internal/Erc20.js.map +0 -1
  258. package/builtin/internal/common.js.map +0 -1
  259. package/builtin/internal/erc20_processor.js.map +0 -1
  260. package/builtin/internal/factories/Erc20__factory.js.map +0 -1
  261. package/builtin/internal/index.js.map +0 -1
  262. package/chain-config.js.map +0 -1
  263. package/cli/build.js.map +0 -1
  264. package/cli/cli.js.map +0 -1
  265. package/cli/config.js.map +0 -1
  266. package/context.js.map +0 -1
  267. package/error.js.map +0 -1
  268. package/gen/builtin.js.map +0 -1
  269. package/gen/google/protobuf/empty.js.map +0 -1
  270. package/gen/processor/protos/processor.js.map +0 -1
  271. package/generic-processor.js.map +0 -1
  272. package/index.js.map +0 -1
  273. package/meter.js.map +0 -1
  274. package/numberish.js.map +0 -1
  275. package/processor-runner.js.map +0 -1
  276. package/processor-state.js.map +0 -1
  277. package/promise-or-void.js.map +0 -1
  278. package/provider.js.map +0 -1
  279. package/service.js.map +0 -1
  280. package/solana/builtin/index.js.map +0 -1
  281. package/solana/builtin/spl-token-processor.js.map +0 -1
  282. package/solana/builtin/types.js.map +0 -1
  283. package/solana/builtin/wormhole-processor.js.map +0 -1
  284. package/solana-processor.js.map +0 -1
  285. package/test/codegen.test.js.map +0 -1
  286. package/test/erc20-template.js.map +0 -1
  287. package/test/erc20-template.test.js.map +0 -1
  288. package/test/erc20.js.map +0 -1
  289. package/test/erc20.test.js.map +0 -1
  290. package/test/generic-processor.test.js.map +0 -1
  291. package/test/metric-utils.js.map +0 -1
  292. package/test/solana.test.js.map +0 -1
  293. package/test/test-processor-server.js.map +0 -1
  294. package/test/types/game_wallet.js.map +0 -1
  295. package/test/types/game_wallet_processor.js.map +0 -1
  296. package/test/wormhole-token-bridge.js.map +0 -1
  297. package/utils/chainmap.js.map +0 -1
  298. package/utils/convert.js.map +0 -1
  299. package/utils/index.js.map +0 -1
@@ -0,0 +1,268 @@
1
+ /* eslint-disable @typescript-eslint/no-redeclare */
2
+ // copy from https://github.com/solana-labs/solana/blob/master/explorer/src/components/instruction/token/types.ts
3
+
4
+ import {
5
+ enums,
6
+ type,
7
+ Infer,
8
+ number,
9
+ string,
10
+ optional,
11
+ array,
12
+ nullable,
13
+ union,
14
+ coerce,
15
+ instance,
16
+ } from "superstruct";
17
+
18
+ // Replace with string
19
+ export const PublicKeyFromString = coerce(
20
+ instance(String),
21
+ string(),
22
+ (value) => (value)
23
+ );
24
+
25
+ export type TokenAmountUi = Infer<typeof TokenAmountUi>;
26
+ export type MintTo = Infer<typeof MintTo>;
27
+ export type Burn = Infer<typeof Burn>;
28
+ export type InitializeMint = Infer<typeof InitializeMint>;
29
+ export type InitializeAccount = Infer<typeof InitializeAccount>;
30
+ export type InitializeAccount2 = Infer<typeof InitializeAccount2>;
31
+ export type InitializeAccount3 = Infer<typeof InitializeAccount3>;
32
+ export type InitializeMultisig = Infer<typeof InitializeMultisig>;
33
+
34
+ export const TokenAmountUi = type({
35
+ amount: string(),
36
+ decimals: number(),
37
+ uiAmountString: string(),
38
+ });
39
+
40
+ const InitializeMint = type({
41
+ mint: PublicKeyFromString,
42
+ decimals: number(),
43
+ mintAuthority: PublicKeyFromString,
44
+ rentSysvar: PublicKeyFromString,
45
+ freezeAuthority: optional(PublicKeyFromString),
46
+ });
47
+
48
+ const InitializeAccount = type({
49
+ account: PublicKeyFromString,
50
+ mint: PublicKeyFromString,
51
+ owner: PublicKeyFromString,
52
+ rentSysvar: PublicKeyFromString,
53
+ });
54
+
55
+ const InitializeAccount2 = type({
56
+ account: PublicKeyFromString,
57
+ mint: PublicKeyFromString,
58
+ rentSysvar: PublicKeyFromString,
59
+ owner: PublicKeyFromString,
60
+ });
61
+
62
+ const InitializeAccount3 = type({
63
+ account: PublicKeyFromString,
64
+ mint: PublicKeyFromString,
65
+ owner: PublicKeyFromString,
66
+ });
67
+
68
+ const InitializeMultisig = type({
69
+ multisig: PublicKeyFromString,
70
+ rentSysvar: PublicKeyFromString,
71
+ signers: array(PublicKeyFromString),
72
+ m: number(),
73
+ });
74
+
75
+ export type Transfer = Infer<typeof Transfer>;
76
+ export const Transfer = type({
77
+ source: PublicKeyFromString,
78
+ destination: PublicKeyFromString,
79
+ amount: union([string(), number()]),
80
+ authority: optional(PublicKeyFromString),
81
+ multisigAuthority: optional(PublicKeyFromString),
82
+ signers: optional(array(PublicKeyFromString)),
83
+ });
84
+
85
+ export type Approve = Infer<typeof Approve>;
86
+ const Approve = type({
87
+ source: PublicKeyFromString,
88
+ delegate: PublicKeyFromString,
89
+ amount: union([string(), number()]),
90
+ owner: optional(PublicKeyFromString),
91
+ multisigOwner: optional(PublicKeyFromString),
92
+ signers: optional(array(PublicKeyFromString)),
93
+ });
94
+
95
+ export type Revoke = Infer<typeof Revoke>;
96
+ const Revoke = type({
97
+ source: PublicKeyFromString,
98
+ owner: optional(PublicKeyFromString),
99
+ multisigOwner: optional(PublicKeyFromString),
100
+ signers: optional(array(PublicKeyFromString)),
101
+ });
102
+
103
+ const AuthorityType = enums([
104
+ "mintTokens",
105
+ "freezeAccount",
106
+ "accountOwner",
107
+ "closeAccount",
108
+ ]);
109
+
110
+ export type SetAuthority = Infer<typeof SetAuthority>;
111
+ const SetAuthority = type({
112
+ mint: optional(PublicKeyFromString),
113
+ account: optional(PublicKeyFromString),
114
+ authorityType: AuthorityType,
115
+ newAuthority: nullable(PublicKeyFromString),
116
+ authority: optional(PublicKeyFromString),
117
+ multisigAuthority: optional(PublicKeyFromString),
118
+ signers: optional(array(PublicKeyFromString)),
119
+ });
120
+
121
+ const MintTo = type({
122
+ mint: PublicKeyFromString,
123
+ account: PublicKeyFromString,
124
+ amount: union([string(), number()]),
125
+ mintAuthority: optional(PublicKeyFromString),
126
+ multisigMintAuthority: optional(PublicKeyFromString),
127
+ signers: optional(array(PublicKeyFromString)),
128
+ });
129
+
130
+ const Burn = type({
131
+ account: PublicKeyFromString,
132
+ mint: PublicKeyFromString,
133
+ amount: union([string(), number()]),
134
+ authority: optional(PublicKeyFromString),
135
+ multisigAuthority: optional(PublicKeyFromString),
136
+ signers: optional(array(PublicKeyFromString)),
137
+ });
138
+
139
+ const CloseAccount = type({
140
+ account: PublicKeyFromString,
141
+ destination: PublicKeyFromString,
142
+ owner: optional(PublicKeyFromString),
143
+ multisigOwner: optional(PublicKeyFromString),
144
+ signers: optional(array(PublicKeyFromString)),
145
+ });
146
+ export type CloseAccount = Infer<typeof CloseAccount>;
147
+
148
+ export type FreezeAccount = Infer<typeof FreezeAccount>;
149
+ const FreezeAccount = type({
150
+ account: PublicKeyFromString,
151
+ mint: PublicKeyFromString,
152
+ freezeAuthority: optional(PublicKeyFromString),
153
+ multisigFreezeAuthority: optional(PublicKeyFromString),
154
+ signers: optional(array(PublicKeyFromString)),
155
+ });
156
+
157
+ export type ThawAccount = Infer<typeof ThawAccount>;
158
+ const ThawAccount = type({
159
+ account: PublicKeyFromString,
160
+ mint: PublicKeyFromString,
161
+ freezeAuthority: optional(PublicKeyFromString),
162
+ multisigFreezeAuthority: optional(PublicKeyFromString),
163
+ signers: optional(array(PublicKeyFromString)),
164
+ });
165
+
166
+ export type TransferChecked = Infer<typeof TransferChecked>;
167
+ export const TransferChecked = type({
168
+ source: PublicKeyFromString,
169
+ mint: PublicKeyFromString,
170
+ destination: PublicKeyFromString,
171
+ authority: optional(PublicKeyFromString),
172
+ multisigAuthority: optional(PublicKeyFromString),
173
+ signers: optional(array(PublicKeyFromString)),
174
+ tokenAmount: TokenAmountUi,
175
+ });
176
+
177
+ export type ApproveChecked = Infer<typeof ApproveChecked>;
178
+ const ApproveChecked = type({
179
+ source: PublicKeyFromString,
180
+ mint: PublicKeyFromString,
181
+ delegate: PublicKeyFromString,
182
+ owner: optional(PublicKeyFromString),
183
+ multisigOwner: optional(PublicKeyFromString),
184
+ signers: optional(array(PublicKeyFromString)),
185
+ tokenAmount: TokenAmountUi,
186
+ });
187
+
188
+ export type MintToChecked = Infer<typeof MintToChecked>;
189
+ const MintToChecked = type({
190
+ account: PublicKeyFromString,
191
+ mint: PublicKeyFromString,
192
+ mintAuthority: optional(PublicKeyFromString),
193
+ multisigMintAuthority: optional(PublicKeyFromString),
194
+ signers: optional(array(PublicKeyFromString)),
195
+ tokenAmount: TokenAmountUi,
196
+ });
197
+
198
+ export type BurnChecked = Infer<typeof BurnChecked>;
199
+ const BurnChecked = type({
200
+ account: PublicKeyFromString,
201
+ mint: PublicKeyFromString,
202
+ authority: optional(PublicKeyFromString),
203
+ multisigAuthority: optional(PublicKeyFromString),
204
+ signers: optional(array(PublicKeyFromString)),
205
+ tokenAmount: TokenAmountUi,
206
+ });
207
+
208
+ const SyncNative = type({
209
+ account: PublicKeyFromString,
210
+ });
211
+
212
+ const GetAccountDataSize = type({
213
+ mint: PublicKeyFromString,
214
+ extensionTypes: optional(array(string())),
215
+ });
216
+
217
+ const InitializeImmutableOwner = type({
218
+ account: PublicKeyFromString,
219
+ });
220
+
221
+ const AmountToUiAmount = type({
222
+ mint: PublicKeyFromString,
223
+ amount: union([string(), number()]),
224
+ });
225
+
226
+ const UiAmountToAmount = type({
227
+ mint: PublicKeyFromString,
228
+ uiAmount: string(),
229
+ });
230
+
231
+ const InitializeMintCloseAuthority = type({
232
+ mint: PublicKeyFromString,
233
+ newAuthority: PublicKeyFromString,
234
+ });
235
+
236
+ const TransferFeeExtension = type({
237
+ mint: PublicKeyFromString,
238
+ transferFeeConfigAuthority: PublicKeyFromString,
239
+ withdrawWitheldAuthority: PublicKeyFromString,
240
+ transferFeeBasisPoints: number(),
241
+ maximumFee: number(),
242
+ });
243
+
244
+ const DefaultAccountStateExtension = type({
245
+ mint: PublicKeyFromString,
246
+ accountState: string(),
247
+ freezeAuthority: optional(PublicKeyFromString),
248
+ });
249
+
250
+ const Reallocate = type({
251
+ account: PublicKeyFromString,
252
+ payer: PublicKeyFromString,
253
+ systemProgram: PublicKeyFromString,
254
+ extensionTypes: array(string()),
255
+ });
256
+
257
+ const MemoTransferExtension = type({
258
+ account: PublicKeyFromString,
259
+ owner: optional(PublicKeyFromString),
260
+ multisigOwner: optional(PublicKeyFromString),
261
+ signers: optional(array(PublicKeyFromString)),
262
+ });
263
+
264
+ const CreateNativeMint = type({
265
+ payer: PublicKeyFromString,
266
+ nativeMint: PublicKeyFromString,
267
+ systemProgram: PublicKeyFromString,
268
+ });
@@ -0,0 +1,178 @@
1
+ import { SolanaBaseProcessor } from '../../solana-processor'
2
+ import { SolanaContext } from '../../context'
3
+ import { SolanaBindOptions } from '../../bind-options'
4
+ import { Instruction } from '@project-serum/anchor'
5
+ import * as borsh from '@project-serum/borsh'
6
+ import bs58 from 'bs58'
7
+
8
+ // https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100
9
+ enum TokenBrigeInstruction {
10
+ Initialize = 0,
11
+ AttestToken,
12
+ CompleteNative, // no args
13
+ CompleteWrapped, // no args
14
+ TransferWrapped,
15
+ TransferNative,
16
+ RegisterChain, // no args
17
+ CreateWrapped, // no args
18
+ UpgradeContract, // no args
19
+ CompleteNativeWithPayload, // no args
20
+ CompleteWrappedWithPayload, // no args
21
+ TransferWrappedWithPayload,
22
+ TransferNativeWithPayload,
23
+ }
24
+
25
+ export class TokenBridgeProcessor extends SolanaBaseProcessor {
26
+
27
+ private readonly transferDataValues = [
28
+ borsh.u32('nonce'),
29
+ borsh.u64('amount'),
30
+ borsh.u64('fee'),
31
+ borsh.array(borsh.u8(undefined), 32, 'target_address'),
32
+ borsh.u16('target_chain')
33
+ ]
34
+ // https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer_payload.rs#L170
35
+ private readonly transferDataWithPayloadValues = [
36
+ borsh.u32('nonce'),
37
+ borsh.u64('amount'),
38
+ borsh.array(borsh.u8(undefined), 32, 'target_address'),
39
+ borsh.u16('target_chain'),
40
+ borsh.vecU8('payload'),
41
+ borsh.option(borsh.publicKey(undefined), 'cpi_program_id')
42
+ ]
43
+ private readonly attestTokenValues = [
44
+ borsh.u32('nonce')
45
+ ]
46
+ private readonly initializeDataValues = [
47
+ borsh.publicKey('bridge')
48
+ ]
49
+
50
+ static bind(options: SolanaBindOptions): TokenBridgeProcessor {
51
+ return new TokenBridgeProcessor(options)
52
+ }
53
+
54
+ decodeInstruction: (rawInstruction: string) => Instruction | null = (ins) => {
55
+ const u8Arr = bs58.decode(ins)
56
+ if (u8Arr.length === 0) {
57
+ return null
58
+ }
59
+
60
+ let data: any
61
+ // wormhole pass intruction's enum value as its first instrcution data
62
+ switch (u8Arr[0]) {
63
+ case TokenBrigeInstruction.Initialize:
64
+ return {
65
+ data: '',
66
+ name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]
67
+ }
68
+ case TokenBrigeInstruction.TransferNative:
69
+ // struct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
70
+ data = borsh.struct(this.transferDataValues, 'TransferNativeData').decode(Buffer.from(u8Arr.slice(1)))
71
+ return {
72
+ data,
73
+ name: TokenBrigeInstruction[TokenBrigeInstruction.TransferNative]
74
+ }
75
+ case TokenBrigeInstruction.TransferWrapped:
76
+ // stuct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
77
+ data = borsh.struct(this.transferDataValues, 'TransferWrappedData').decode(Buffer.from(u8Arr.slice(1)))
78
+ return {
79
+ data,
80
+ name: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrapped]
81
+ }
82
+ case TokenBrigeInstruction.TransferNativeWithPayload:
83
+ data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
84
+ return {
85
+ data,
86
+ name: TokenBrigeInstruction[TokenBrigeInstruction.TransferNativeWithPayload]
87
+ }
88
+ case TokenBrigeInstruction.TransferWrappedWithPayload:
89
+ data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
90
+ return {
91
+ data,
92
+ name: TokenBrigeInstruction[TokenBrigeInstruction.TransferWrappedWithPayload]
93
+ }
94
+ case TokenBrigeInstruction.Initialize:
95
+ data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))
96
+ return {
97
+ data,
98
+ name: TokenBrigeInstruction[TokenBrigeInstruction.Initialize]
99
+ }
100
+ case TokenBrigeInstruction.AttestToken:
101
+ data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))
102
+ return {
103
+ data,
104
+ name: TokenBrigeInstruction[TokenBrigeInstruction.AttestToken]
105
+ }
106
+ case TokenBrigeInstruction.CompleteNative:
107
+ case TokenBrigeInstruction.CompleteNativeWithPayload:
108
+ case TokenBrigeInstruction.CompleteWrapped:
109
+ case TokenBrigeInstruction.CompleteWrappedWithPayload:
110
+ case TokenBrigeInstruction.CreateWrapped:
111
+ case TokenBrigeInstruction.UpgradeContract:
112
+ case TokenBrigeInstruction.RegisterChain:
113
+ return {
114
+ data: '',
115
+ name: TokenBrigeInstruction[u8Arr[0]]
116
+ }
117
+
118
+ default:
119
+ return null
120
+ }
121
+ }
122
+
123
+ onInitialize(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
124
+ this.onInstruction('Initialize', (ins: Instruction, ctx) => {
125
+ if (ins) {
126
+ handler(ins.data, ctx)
127
+ }
128
+ })
129
+ return this
130
+ }
131
+
132
+ onAttestToken(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
133
+ this.onInstruction('AttestToken', (ins: Instruction, ctx) => {
134
+ if (ins) {
135
+ handler(ins.data, ctx)
136
+ }
137
+ })
138
+ return this
139
+ }
140
+
141
+
142
+ onTransferWrapped(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
143
+ this.onInstruction('TransferWrapped', (ins: Instruction, ctx) => {
144
+ if (ins) {
145
+ handler(ins.data, ctx)
146
+ }
147
+ })
148
+ return this
149
+ }
150
+
151
+ onTransferNativeWithPayload(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
152
+ this.onInstruction('TransferNativeWithPayload', (ins: Instruction, ctx) => {
153
+ if (ins) {
154
+ handler(ins.data, ctx)
155
+ }
156
+ })
157
+ return this
158
+ }
159
+
160
+ onTransferWrappedWithPaylod(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
161
+ this.onInstruction('TransferWrappedWithPaylod', (ins: Instruction, ctx) => {
162
+ if (ins) {
163
+ handler(ins.data, ctx)
164
+ }
165
+ })
166
+ return this
167
+ }
168
+
169
+ onTransferNative(handler: (args: any, ctx: SolanaContext) => void): TokenBridgeProcessor {
170
+ this.onInstruction('TransferNative', (ins: Instruction, ctx) => {
171
+ if (ins) {
172
+ handler(ins.data, ctx)
173
+ }
174
+ })
175
+ return this
176
+ }
177
+ }
178
+
@@ -0,0 +1,105 @@
1
+ import { O11yResult } from './gen/processor/protos/processor'
2
+ import { SolanaContext } from './context'
3
+ import Long from 'long'
4
+ import { Instruction } from '@project-serum/anchor'
5
+ import { SolanaBindOptions } from './bind-options'
6
+
7
+ type IndexConfigure = {
8
+ startSlot: Long
9
+ endSlot?: Long
10
+ }
11
+
12
+ export class SolanaBaseProcessor {
13
+ public instructionHanlderMap: Map<string, (instruction: Instruction, ctx: SolanaContext) => void> = new Map()
14
+ address: string
15
+ endpoint: string
16
+ contractName: string
17
+ processInnerInstruction: boolean
18
+ config: IndexConfigure = { startSlot: new Long(0) }
19
+ decodeInstruction: (rawInstruction: string) => Instruction | null
20
+ fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null
21
+
22
+ constructor(options: SolanaBindOptions) {
23
+ if (options) {
24
+ this.bind(options)
25
+ }
26
+ global.PROCESSOR_STATE.solanaProcessors.push(this)
27
+ }
28
+
29
+ bind(options: SolanaBindOptions) {
30
+ this.address = options.address
31
+ this.contractName = options.name || ''
32
+ this.processInnerInstruction = options.processInnerInstruction || false
33
+ if (options.startBlock) {
34
+ this.startSlot(options.startBlock)
35
+ }
36
+ if (options.endBlock) {
37
+ this.endBlock(options.endBlock)
38
+ }
39
+ this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'
40
+ }
41
+
42
+ innerInstruction(flag: boolean) {
43
+ this.processInnerInstruction = flag
44
+ return this
45
+ }
46
+
47
+ public onInstruction(instructionName: string, handler: (instruction: Instruction, ctx: SolanaContext) => void) {
48
+ if (!this.isBind()) {
49
+ throw new Error("Processor doesn't bind to an address")
50
+ }
51
+
52
+ this.instructionHanlderMap.set(instructionName, handler)
53
+
54
+ return this
55
+ }
56
+
57
+ public handleInstruction(ins: string | { type: string; info: any }): O11yResult | null {
58
+ const ctx = new SolanaContext(this.address)
59
+ let parsedInstruction: Instruction | null = null
60
+
61
+ if (ins) {
62
+ if ((ins as { type: string; info: any }).info) {
63
+ if (this.fromParsedInstruction == null) {
64
+ return null
65
+ }
66
+ parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })
67
+ } else {
68
+ if (this.decodeInstruction == null) {
69
+ return null
70
+ }
71
+ parsedInstruction = this.decodeInstruction(ins as string)
72
+ }
73
+ if (parsedInstruction) {
74
+ const handler = this.instructionHanlderMap.get(parsedInstruction.name)
75
+ if (handler) {
76
+ handler(parsedInstruction, ctx)
77
+ }
78
+ }
79
+ }
80
+ return {
81
+ gauges: ctx.gauges,
82
+ counters: ctx.counters,
83
+ }
84
+ }
85
+
86
+ public isBind() {
87
+ return this.address !== null
88
+ }
89
+
90
+ public startSlot(startSlot: Long | number) {
91
+ if (typeof startSlot === 'number') {
92
+ startSlot = Long.fromNumber(startSlot)
93
+ }
94
+ this.config.startSlot = startSlot
95
+ return this
96
+ }
97
+
98
+ public endBlock(endBlock: Long | number) {
99
+ if (typeof endBlock === 'number') {
100
+ endBlock = Long.fromNumber(endBlock)
101
+ }
102
+ this.config.endSlot = endBlock
103
+ return this
104
+ }
105
+ }