@sentio/sdk 1.7.14 → 1.7.15

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 (248) 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/{base-processor-template.js.map → lib/base-processor-template.js.map} +0 -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/{base-processor.js.map → lib/base-processor.js.map} +0 -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/{bind-options.js.map → lib/bind-options.js.map} +0 -0
  10. package/{binds.d.ts → lib/binds.d.ts} +0 -0
  11. package/{binds.js → lib/binds.js} +0 -0
  12. package/{binds.js.map → lib/binds.js.map} +0 -0
  13. package/{builtin → lib/builtin}/erc20/index.d.ts +0 -0
  14. package/{builtin → lib/builtin}/erc20/index.js +0 -0
  15. package/{builtin → lib/builtin}/erc20/index.js.map +0 -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/{builtin → lib/builtin}/erc20/test-utils.js.map +0 -0
  19. package/{builtin → lib/builtin}/internal/Erc20.d.ts +0 -0
  20. package/{builtin → lib/builtin}/internal/Erc20.js +0 -0
  21. package/{builtin → lib/builtin}/internal/Erc20.js.map +0 -0
  22. package/{builtin → lib/builtin}/internal/common.d.ts +0 -0
  23. package/{builtin → lib/builtin}/internal/common.js +0 -0
  24. package/{builtin → lib/builtin}/internal/common.js.map +0 -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/{builtin → lib/builtin}/internal/erc20_processor.js.map +0 -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/{builtin → lib/builtin}/internal/factories/Erc20__factory.js.map +0 -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 +0 -0
  34. package/{builtin → lib/builtin}/internal/index.d.ts +0 -0
  35. package/{builtin → lib/builtin}/internal/index.js +0 -0
  36. package/{builtin → lib/builtin}/internal/index.js.map +0 -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/{chain-config.js.map → lib/chain-config.js.map} +0 -0
  40. package/{cli → lib/cli}/build.d.ts +0 -0
  41. package/{cli → lib/cli}/build.js +0 -0
  42. package/{cli → lib/cli}/build.js.map +0 -0
  43. package/{cli → lib/cli}/cli.d.ts +0 -0
  44. package/{cli → lib/cli}/cli.js +0 -0
  45. package/{cli → lib/cli}/cli.js.map +0 -0
  46. package/{cli → lib/cli}/config.d.ts +0 -0
  47. package/{cli → lib/cli}/config.js +0 -0
  48. package/{cli → lib/cli}/config.js.map +0 -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 +0 -0
  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 +0 -0
  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 +0 -0
  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/{context.js.map → lib/context.js.map} +0 -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} +0 -0
  65. package/{error.d.ts → lib/error.d.ts} +0 -0
  66. package/{error.js → lib/error.js} +0 -0
  67. package/{error.js.map → lib/error.js.map} +0 -0
  68. package/{gen → lib/gen}/builtin.d.ts +0 -0
  69. package/{gen → lib/gen}/builtin.js +0 -0
  70. package/{gen → lib/gen}/builtin.js.map +0 -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/{gen → lib/gen}/google/protobuf/empty.js.map +0 -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/{gen → lib/gen}/processor/protos/processor.js.map +0 -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/{generic-processor.js.map → lib/generic-processor.js.map} +0 -0
  80. package/{index.d.ts → lib/index.d.ts} +0 -0
  81. package/{index.js → lib/index.js} +0 -0
  82. package/{index.js.map → lib/index.js.map} +0 -0
  83. package/{meter.d.ts → lib/meter.d.ts} +0 -0
  84. package/{meter.js → lib/meter.js} +0 -0
  85. package/{meter.js.map → lib/meter.js.map} +0 -0
  86. package/{numberish.d.ts → lib/numberish.d.ts} +0 -0
  87. package/{numberish.js → lib/numberish.js} +0 -0
  88. package/{numberish.js.map → lib/numberish.js.map} +0 -0
  89. package/{numberish.test.d.ts → lib/numberish.test.d.ts} +0 -0
  90. package/{numberish.test.js → lib/numberish.test.js} +0 -0
  91. package/{numberish.test.js.map → lib/numberish.test.js.map} +0 -0
  92. package/{processor-runner.d.ts → lib/processor-runner.d.ts} +0 -0
  93. package/{processor-runner.js → lib/processor-runner.js} +0 -0
  94. package/{processor-runner.js.map → lib/processor-runner.js.map} +0 -0
  95. package/{processor-state.d.ts → lib/processor-state.d.ts} +0 -0
  96. package/{processor-state.js → lib/processor-state.js} +0 -0
  97. package/{processor-state.js.map → lib/processor-state.js.map} +0 -0
  98. package/{promise-or-void.d.ts → lib/promise-or-void.d.ts} +0 -0
  99. package/{promise-or-void.js → lib/promise-or-void.js} +0 -0
  100. package/{promise-or-void.js.map → lib/promise-or-void.js.map} +0 -0
  101. package/{provider.d.ts → lib/provider.d.ts} +0 -0
  102. package/{provider.js → lib/provider.js} +0 -0
  103. package/{provider.js.map → lib/provider.js.map} +0 -0
  104. package/{release.config.js → lib/release.config.js} +0 -0
  105. package/{service.d.ts → lib/service.d.ts} +0 -0
  106. package/{service.js → lib/service.js} +0 -0
  107. package/{service.js.map → lib/service.js.map} +0 -0
  108. package/{solana → lib/solana}/builtin/index.d.ts +0 -0
  109. package/{solana → lib/solana}/builtin/index.js +0 -0
  110. package/{solana → lib/solana}/builtin/index.js.map +0 -0
  111. package/{solana → lib/solana}/builtin/spl-token-processor.d.ts +0 -0
  112. package/{solana → lib/solana}/builtin/spl-token-processor.js +0 -0
  113. package/{solana → lib/solana}/builtin/spl-token-processor.js.map +0 -0
  114. package/{solana → lib/solana}/builtin/types.d.ts +0 -0
  115. package/{solana → lib/solana}/builtin/types.js +0 -0
  116. package/{solana → lib/solana}/builtin/types.js.map +0 -0
  117. package/{solana → lib/solana}/builtin/wormhole-processor.d.ts +0 -0
  118. package/{solana → lib/solana}/builtin/wormhole-processor.js +0 -0
  119. package/{solana → lib/solana}/builtin/wormhole-processor.js.map +0 -0
  120. package/{solana-processor.d.ts → lib/solana-processor.d.ts} +0 -0
  121. package/{solana-processor.js → lib/solana-processor.js} +0 -0
  122. package/{solana-processor.js.map → lib/solana-processor.js.map} +0 -0
  123. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.d.ts +0 -0
  124. package/{target-ethers-sentio → lib/target-ethers-sentio}/codegen.js +0 -0
  125. package/lib/target-ethers-sentio/codegen.js.map +1 -0
  126. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.d.ts +0 -0
  127. package/{target-ethers-sentio → lib/target-ethers-sentio}/index.js +0 -0
  128. package/lib/target-ethers-sentio/index.js.map +1 -0
  129. package/{test → lib/test}/codegen.test.d.ts +0 -0
  130. package/{test → lib/test}/codegen.test.js +1 -1
  131. package/{test → lib/test}/codegen.test.js.map +1 -1
  132. package/{test → lib/test}/erc20-template.d.ts +0 -0
  133. package/{test → lib/test}/erc20-template.js +0 -0
  134. package/{test → lib/test}/erc20-template.js.map +0 -0
  135. package/{test → lib/test}/erc20-template.test.d.ts +0 -0
  136. package/{test → lib/test}/erc20-template.test.js +0 -0
  137. package/{test → lib/test}/erc20-template.test.js.map +0 -0
  138. package/{test → lib/test}/erc20.d.ts +0 -0
  139. package/{test → lib/test}/erc20.js +0 -0
  140. package/{test → lib/test}/erc20.js.map +0 -0
  141. package/{test → lib/test}/erc20.test.d.ts +0 -0
  142. package/{test → lib/test}/erc20.test.js +0 -0
  143. package/{test → lib/test}/erc20.test.js.map +0 -0
  144. package/{test → lib/test}/generic-processor.test.d.ts +0 -0
  145. package/{test → lib/test}/generic-processor.test.js +0 -0
  146. package/{test → lib/test}/generic-processor.test.js.map +0 -0
  147. package/{test → lib/test}/index.d.ts +0 -0
  148. package/{test → lib/test}/index.js +0 -0
  149. package/{test → lib/test}/index.js.map +0 -0
  150. package/{test → lib/test}/metric-utils.d.ts +0 -0
  151. package/{test → lib/test}/metric-utils.js +0 -0
  152. package/{test → lib/test}/metric-utils.js.map +0 -0
  153. package/{test → lib/test}/mirrorworld.d.ts +0 -0
  154. package/{test → lib/test}/mirrorworld.js +0 -0
  155. package/{test → lib/test}/mirrorworld.js.map +0 -0
  156. package/{test → lib/test}/solana.test.d.ts +0 -0
  157. package/{test → lib/test}/solana.test.js +0 -0
  158. package/{test → lib/test}/solana.test.js.map +0 -0
  159. package/{test → lib/test}/test-processor-server.d.ts +0 -0
  160. package/{test → lib/test}/test-processor-server.js +0 -0
  161. package/{test → lib/test}/test-processor-server.js.map +0 -0
  162. package/{test → lib/test}/types/game_wallet.d.ts +0 -0
  163. package/{test → lib/test}/types/game_wallet.js +0 -0
  164. package/{test → lib/test}/types/game_wallet.js.map +0 -0
  165. package/{test → lib/test}/types/game_wallet_processor.d.ts +0 -0
  166. package/{test → lib/test}/types/game_wallet_processor.js +0 -0
  167. package/{test → lib/test}/types/game_wallet_processor.js.map +0 -0
  168. package/{test → lib/test}/wormhole-token-bridge.d.ts +0 -0
  169. package/{test → lib/test}/wormhole-token-bridge.js +0 -0
  170. package/{test → lib/test}/wormhole-token-bridge.js.map +0 -0
  171. package/{utils → lib/utils}/chainmap.d.ts +0 -0
  172. package/{utils → lib/utils}/chainmap.js +0 -0
  173. package/{utils → lib/utils}/chainmap.js.map +0 -0
  174. package/{utils → lib/utils}/convert.d.ts +0 -0
  175. package/{utils → lib/utils}/convert.js +0 -0
  176. package/{utils → lib/utils}/convert.js.map +0 -0
  177. package/{utils → lib/utils}/index.d.ts +0 -0
  178. package/{utils → lib/utils}/index.js +0 -0
  179. package/{utils → lib/utils}/index.js.map +0 -0
  180. package/package.json +47 -6
  181. package/src/abis/erc20.json +198 -0
  182. package/src/base-processor-template.ts +92 -0
  183. package/src/base-processor.ts +128 -0
  184. package/src/bind-options.ts +41 -0
  185. package/src/binds.ts +73 -0
  186. package/src/builtin/erc20/index.ts +6 -0
  187. package/src/builtin/erc20/test-utils.ts +49 -0
  188. package/src/builtin/internal/Erc20.ts +356 -0
  189. package/src/builtin/internal/common.ts +46 -0
  190. package/src/builtin/internal/erc20_processor.ts +295 -0
  191. package/src/builtin/internal/factories/Erc20__factory.ts +216 -0
  192. package/src/builtin/internal/factories/index.ts +4 -0
  193. package/src/builtin/internal/index.ts +6 -0
  194. package/src/chain-config.ts +6 -0
  195. package/src/cli/build.ts +180 -0
  196. package/src/cli/cli.ts +217 -0
  197. package/src/cli/config.ts +43 -0
  198. package/src/cli/key.ts +43 -0
  199. package/src/cli/solana-code-gen.ts +16 -0
  200. package/src/cli/upload.ts +86 -0
  201. package/src/cli/webpack.config.js +42 -0
  202. package/src/context.ts +93 -0
  203. package/src/contract-namer.ts +17 -0
  204. package/src/error.ts +43 -0
  205. package/src/gen/builtin.ts +22 -0
  206. package/src/gen/google/protobuf/empty.ts +70 -0
  207. package/src/gen/processor/protos/processor.ts +3071 -0
  208. package/src/generic-processor.ts +38 -0
  209. package/src/index.ts +19 -0
  210. package/src/meter.ts +122 -0
  211. package/src/numberish.test.ts +82 -0
  212. package/src/numberish.ts +99 -0
  213. package/src/processor-runner.ts +75 -0
  214. package/src/processor-state.ts +24 -0
  215. package/src/promise-or-void.ts +1 -0
  216. package/src/provider.ts +74 -0
  217. package/src/service.ts +434 -0
  218. package/src/solana/builtin/index.ts +2 -0
  219. package/src/solana/builtin/spl-token-processor.ts +164 -0
  220. package/src/solana/builtin/types.ts +268 -0
  221. package/src/solana/builtin/wormhole-processor.ts +178 -0
  222. package/src/solana-processor.ts +105 -0
  223. package/src/target-ethers-sentio/codegen.ts +289 -0
  224. package/src/target-ethers-sentio/index.ts +50 -0
  225. package/src/target-ethers-sentio/tsconfig.json +9 -0
  226. package/src/test/abis/evm/anyswapRouter.json +490 -0
  227. package/src/test/abis/solana/mirrorworld.json +1392 -0
  228. package/src/test/codegen.test.ts +26 -0
  229. package/src/test/erc20-template.test.ts +39 -0
  230. package/src/test/erc20-template.ts +25 -0
  231. package/src/test/erc20.test.ts +92 -0
  232. package/src/test/erc20.ts +48 -0
  233. package/src/test/generic-processor.test.ts +72 -0
  234. package/src/test/index.ts +1 -0
  235. package/src/test/metric-utils.ts +49 -0
  236. package/src/test/mirrorworld.ts +40 -0
  237. package/src/test/sentio.yaml +4 -0
  238. package/src/test/solana.test.ts +93 -0
  239. package/src/test/test-processor-server.ts +210 -0
  240. package/src/test/types/game_wallet.ts +1392 -0
  241. package/src/test/types/game_wallet_processor.ts +113 -0
  242. package/src/test/wormhole-token-bridge.ts +21 -0
  243. package/src/types/global.d.ts +17 -0
  244. package/src/utils/chainmap.ts +95 -0
  245. package/src/utils/convert.ts +6 -0
  246. package/src/utils/index.ts +2 -0
  247. package/target-ethers-sentio/codegen.js.map +0 -1
  248. package/target-ethers-sentio/index.js.map +0 -1
@@ -0,0 +1,113 @@
1
+ import { BorshInstructionCoder, Instruction, Idl, BN } from '@project-serum/anchor'
2
+ import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from "@sentio/sdk"
3
+ import { game_wallet_idl } from "./game_wallet"
4
+ import bs58 from 'bs58'
5
+ import { PublicKey } from '@solana/web3.js'
6
+
7
+ export class GameWalletProcessor extends SolanaBaseProcessor {
8
+ static bind(options: SolanaBindOptions): GameWalletProcessor {
9
+ if (options && !options.name) {
10
+ options.name = 'GameWallet'
11
+ }
12
+ return new GameWalletProcessor(options)
13
+ }
14
+
15
+ decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {
16
+ const instructionCoder = new BorshInstructionCoder(game_wallet_idl as Idl)
17
+ const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))
18
+ return decodedIns
19
+ }
20
+
21
+
22
+ onInitializeTokenConfig(handler: (args: { tokenDecimal: number, isPaused: boolean, canDeposit: boolean, canWithdraw: boolean, canSpend: boolean, canDistribute: boolean, isWithdrawServiceFeeEnable: boolean, withdrawServiceFeePercentage: BN, isSpendServiceFeeEnable: boolean, spendServiceFeePercentage: BN, isDistributionServiceFeeEnable: boolean, distributionServiceFeePercentage: BN, isMinWithdrawEnable: boolean, isMaxWithdrawEnable: boolean, minWithdraw: BN, maxWithdraw: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
23
+ this.onInstruction('initializeTokenConfig', (ins: Instruction, ctx) => {
24
+ if (ins) {
25
+ handler(ins.data as { tokenDecimal: number, isPaused: boolean, canDeposit: boolean, canWithdraw: boolean, canSpend: boolean, canDistribute: boolean, isWithdrawServiceFeeEnable: boolean, withdrawServiceFeePercentage: BN, isSpendServiceFeeEnable: boolean, spendServiceFeePercentage: BN, isDistributionServiceFeeEnable: boolean, distributionServiceFeePercentage: BN, isMinWithdrawEnable: boolean, isMaxWithdrawEnable: boolean, minWithdraw: BN, maxWithdraw: BN }, ctx)
26
+ }
27
+ })
28
+ return this
29
+ }
30
+
31
+ onDeposit(handler: (args: { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, amount: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
32
+ this.onInstruction('deposit', (ins: Instruction, ctx) => {
33
+ if (ins) {
34
+ handler(ins.data as { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, amount: BN }, ctx)
35
+ }
36
+ })
37
+ return this
38
+ }
39
+
40
+ onWithdraw(handler: (args: { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, userTokenConfigBump: number, amount: BN, nonce: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
41
+ this.onInstruction('withdraw', (ins: Instruction, ctx) => {
42
+ if (ins) {
43
+ handler(ins.data as { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, userTokenConfigBump: number, amount: BN, nonce: BN }, ctx)
44
+ }
45
+ })
46
+ return this
47
+ }
48
+
49
+ onSpend(handler: (args: { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, userTokenConfigBump: number, amount: BN, nonce: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
50
+ this.onInstruction('spend', (ins: Instruction, ctx) => {
51
+ if (ins) {
52
+ handler(ins.data as { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, userTokenConfigBump: number, amount: BN, nonce: BN }, ctx)
53
+ }
54
+ })
55
+ return this
56
+ }
57
+
58
+ onSpendWithoutUser(handler: (args: { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, userTokenConfigBump: number, amount: BN, nonce: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
59
+ this.onInstruction('spendWithoutUser', (ins: Instruction, ctx) => {
60
+ if (ins) {
61
+ handler(ins.data as { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, userTokenConfigBump: number, amount: BN, nonce: BN }, ctx)
62
+ }
63
+ })
64
+ return this
65
+ }
66
+
67
+ onAddDistributeSupply(handler: (args: { tokenConfigBump: number, distributionPoolBump: number, distributionPoolTokenAccountBump: number, amount: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
68
+ this.onInstruction('addDistributeSupply', (ins: Instruction, ctx) => {
69
+ if (ins) {
70
+ handler(ins.data as { tokenConfigBump: number, distributionPoolBump: number, distributionPoolTokenAccountBump: number, amount: BN }, ctx)
71
+ }
72
+ })
73
+ return this
74
+ }
75
+
76
+ onDistribute(handler: (args: { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, distributionPoolBump: number, distributionPoolTokenAccountBump: number, amount: BN, nonce: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
77
+ this.onInstruction('distribute', (ins: Instruction, ctx) => {
78
+ if (ins) {
79
+ handler(ins.data as { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, distributionPoolBump: number, distributionPoolTokenAccountBump: number, amount: BN, nonce: BN }, ctx)
80
+ }
81
+ })
82
+ return this
83
+ }
84
+
85
+ onDistributeWithoutUser(handler: (args: { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, distributionPoolBump: number, distributionPoolTokenAccountBump: number, amount: BN, nonce: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
86
+ this.onInstruction('distributeWithoutUser', (ins: Instruction, ctx) => {
87
+ if (ins) {
88
+ handler(ins.data as { tokenConfigBump: number, depositPoolBump: number, depositPoolTokenAccountBump: number, distributionPoolBump: number, distributionPoolTokenAccountBump: number, amount: BN, nonce: BN }, ctx)
89
+ }
90
+ })
91
+ return this
92
+ }
93
+
94
+ onUpdateTokenConfig(handler: (args: { tokenConfigBump: number, tokenDecimal: number, isPaused: boolean, canDeposit: boolean, canWithdraw: boolean, canSpend: boolean, canDistribute: boolean, isWithdrawServiceFeeEnable: boolean, withdrawServiceFeePercentage: BN, isSpendServiceFeeEnable: boolean, spendServiceFeePercentage: BN, isDistributionServiceFeeEnable: boolean, distributionServiceFeePercentage: BN, isMinWithdrawEnable: boolean, isMaxWithdrawEnable: boolean, minWithdraw: BN, maxWithdraw: BN }, ctx: SolanaContext) => void): GameWalletProcessor {
95
+ this.onInstruction('updateTokenConfig', (ins: Instruction, ctx) => {
96
+ if (ins) {
97
+ handler(ins.data as { tokenConfigBump: number, tokenDecimal: number, isPaused: boolean, canDeposit: boolean, canWithdraw: boolean, canSpend: boolean, canDistribute: boolean, isWithdrawServiceFeeEnable: boolean, withdrawServiceFeePercentage: BN, isSpendServiceFeeEnable: boolean, spendServiceFeePercentage: BN, isDistributionServiceFeeEnable: boolean, distributionServiceFeePercentage: BN, isMinWithdrawEnable: boolean, isMaxWithdrawEnable: boolean, minWithdraw: BN, maxWithdraw: BN }, ctx)
98
+ }
99
+ })
100
+ return this
101
+ }
102
+
103
+ onUpdateUserTokenConfig(handler: (args: { tokenConfigBump: number, userTokenConfigBump: number, isActive: boolean, canDeposit: boolean, canWithdraw: boolean, canSpend: boolean, canDistribute: boolean }, ctx: SolanaContext) => void): GameWalletProcessor {
104
+ this.onInstruction('updateUserTokenConfig', (ins: Instruction, ctx) => {
105
+ if (ins) {
106
+ handler(ins.data as { tokenConfigBump: number, userTokenConfigBump: number, isActive: boolean, canDeposit: boolean, canWithdraw: boolean, canSpend: boolean, canDistribute: boolean }, ctx)
107
+ }
108
+ })
109
+ return this
110
+ }
111
+
112
+ }
113
+
@@ -0,0 +1,21 @@
1
+ import { TokenBridgeProcessor } from '../solana/builtin/wormhole-processor'
2
+ import { SPLTokenProcessor } from '../solana/builtin'
3
+
4
+ TokenBridgeProcessor.bind({
5
+ address: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
6
+ }).onTransferNative((args, ctx) => {
7
+ ctx.meter.Counter('total_transfer_amount').add(args.amount)
8
+ })
9
+
10
+ SPLTokenProcessor.bind({ address: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb' })
11
+ .onMintTo((data, ctx) => {
12
+ if (data.mint === '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs') {
13
+ ctx.meter.Counter('totalWeth_supply').add(data.amount as number)
14
+ }
15
+ })
16
+ .onBurn((data, ctx) => {
17
+ if (data.mint === '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs') {
18
+ ctx.meter.Counter('totalWeth_supply').sub(data.amount as number)
19
+ }
20
+ })
21
+ .innerInstruction(true)
@@ -0,0 +1,17 @@
1
+ import { BaseContract } from 'ethers'
2
+ import { BaseProcessor, BaseProcessorTemplate, SolanaBaseProcessor, TemplateInstance, ProcessorState } from '..'
3
+ import { Provider } from '@ethersproject/providers'
4
+ import { ContractView } from 'context'
5
+
6
+ declare global {
7
+ // var Processors: BaseProcessor<BaseContract, ContractView<BaseContract>>[]
8
+ // var Templates: BaseProcessorTemplate<BaseContract, ContractView<BaseContract>>[]
9
+ // var TemplatesInstances: TemplateInstance[]
10
+ // var SentioProvider: Map<number, Provider>
11
+ // var SolanaProcessors: SolanaBaseProcessor[]
12
+
13
+ var PROCESSOR_STATE: ProcessorState
14
+ var sentio_sdk: any
15
+ }
16
+
17
+ // processorState = new ProcessorState()
@@ -0,0 +1,95 @@
1
+ // copy from https://github.com/DefiLlama/chainlist/blob/main/constants/chainIds.js
2
+ // and https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/
3
+
4
+ export const CHAIN_MAP: Record<string, string> = {
5
+ 'SOL:mainnet': 'solana',
6
+ 'SOL:devnet': 'solana-dev',
7
+ 'SOL:testnet': 'solana-test',
8
+ 0: 'kardia',
9
+ 1: 'ethereum',
10
+ 2: 'expanse',
11
+ 3: 'ropsten',
12
+ 4: 'rinkeby',
13
+ 5: 'goerli',
14
+ 6: 'kotti',
15
+ 8: 'ubiq',
16
+ 10: 'optimism',
17
+ 19: 'songbird',
18
+ 20: 'elastos',
19
+ 25: 'cronos',
20
+ 30: 'rsk',
21
+ 40: 'telos',
22
+ 50: 'xdc',
23
+ 52: 'csc',
24
+ 55: 'zyx',
25
+ 56: 'binance',
26
+ 57: 'syscoin',
27
+ 60: 'gochain',
28
+ 61: 'ethclassic',
29
+ 63: 'mordor',
30
+ 66: 'okexchain',
31
+ 70: 'hoo',
32
+ 82: 'meter',
33
+ 88: 'tomochain',
34
+ 100: 'xdai',
35
+ 106: 'velas',
36
+ 108: 'thundercore',
37
+ 122: 'fuse',
38
+ 128: 'heco',
39
+ 137: 'polygon',
40
+ 200: 'xdaiarb',
41
+ 212: 'astor',
42
+ 246: 'energyweb',
43
+ 250: 'fantom',
44
+ 269: 'hpb',
45
+ 288: 'boba',
46
+ 321: 'kucoin',
47
+ 336: 'shiden',
48
+ 361: 'theta',
49
+ 416: 'sx',
50
+ 534: 'candle',
51
+ 592: 'astar',
52
+ 820: 'callisto',
53
+ 888: 'wanchain',
54
+ 1088: 'metis',
55
+ 1246: 'omchain',
56
+ 1284: 'moonbeam',
57
+ 1285: 'moonriver',
58
+ 2018: 'dev',
59
+ 2020: 'ronin',
60
+ 2222: 'kava',
61
+ 2612: 'ezchain',
62
+ 4181: 'phi',
63
+ 4689: 'iotex',
64
+ 5050: 'xlc',
65
+ 5551: 'nahmii',
66
+ 7777: 'nmactest',
67
+ 8217: 'klaytn',
68
+ 9001: 'evmos',
69
+ 10000: 'smartbch',
70
+ 103090: 'crystaleum',
71
+ 32659: 'fusion',
72
+ 42161: 'arbitrum',
73
+ 42220: 'celo',
74
+ 42262: 'oasis',
75
+ 43114: 'avalanche',
76
+ 71402: 'godwoken',
77
+ 200625: 'akroma',
78
+ 333999: 'polis',
79
+ 11155111: 'sepolia',
80
+ 1313161554: 'aurora',
81
+ 1666600000: 'harmony',
82
+ 11297108109: 'palm',
83
+ 836542336838601: 'curio',
84
+ }
85
+
86
+ export function getChainName(chainId: string | number): string {
87
+ if (typeof chainId === 'number') {
88
+ chainId = chainId.toString()
89
+ }
90
+ const name = CHAIN_MAP[chainId]
91
+ if (name) {
92
+ return name
93
+ }
94
+ return chainId
95
+ }
@@ -0,0 +1,6 @@
1
+ import { BigNumber } from 'ethers'
2
+ import { BigDecimal } from '@sentio/sdk'
3
+
4
+ export function toBigDecimal(n: BigNumber) {
5
+ return new BigDecimal(n.toString())
6
+ }
@@ -0,0 +1,2 @@
1
+ export { getChainName } from './chainmap'
2
+ export { toBigDecimal } from './convert'
@@ -1 +0,0 @@
1
- {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/target-ethers-sentio/codegen.ts"],"names":[],"mappings":";;;AAAA,yCAMkB;AAElB,2FAAsF;AACtF,mEAA4E;AAC5E,gEAA0E;AAE1E,SAAgB,YAAY,CAAC,QAAkB;IAC7C,OAAO;+BACsB,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE;+BAC3B,QAAQ,CAAC,IAAI;GACzC,CAAA;AACH,CAAC;AALD,oCAKC;AAED,SAAgB,iBAAiB,CAAC,QAAkB;IAClD,MAAM,MAAM,GAAG;6BACY,QAAQ,CAAC,IAAI;;iBAEzB,QAAQ,CAAC,IAAI,qCAAqC,QAAQ,CAAC,IAAI;6BACnD,QAAQ,CAAC,IAAI;;;;MAIpC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;SAChC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,oCAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC/C,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,IAAI,MAAM,CAAC,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;SACtF,IAAI,CAAC,IAAI,CAAC;;;iBAGA,QAAQ,CAAC,IA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EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAC5G;;iCAE+B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;;;;GAMnH,CAAA;AACH,CAAC;AAED,SAAS,4BAA4B,CAAC,KAAuB,EAAE,YAAoB,EAAE,eAAwB;IAC3G,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC1B,IAAI,sBAAsB,GAAG,KAAK,CAAC,IAAI,CAAA;IACvC,IAAI,eAAe,EAAE;QACnB,SAAS,GAAG,IAAA,4CAAgC,EAAC,KAAK,CAAC,GAAG,GAAG,CAAA;QACzD,sBAAsB,GAAG,IAAA,qCAAwB,EAAC,KAAK,CAAC,CAAA;KACzD;IAED,OAAO;0BACiB,SAAS,uCAAuC,SAAS;4BACvD,YAAY;;mDAEW,sBAAsB;;;;;;;;;;GAUtE,CAAA;AACH,CAAC","sourcesContent":["import {\n Contract,\n createImportsForUsedIdentifiers,\n EventDeclaration,\n FunctionDeclaration,\n getFullSignatureAsSymbolForEvent,\n} from 'typechain'\n\nimport { reservedKeywords } from '@typechain/ethers-v5/dist/codegen/reserved-keywords'\nimport { generateInputTypes } from '@typechain/ethers-v5/dist/codegen/types'\nimport { getFullSignatureForEvent } from 'typechain/dist/utils/signatures'\n\nexport function codeGenIndex(contract: Contract): string {\n return ` \n export * from '../internal/${contract.name.toLowerCase()}_processor'\n export * from '../internal/${contract.name}'\n `\n}\n\nexport function codeGenSentioFile(contract: Contract): string {\n const source = `\n const templateContract = ${contract.name}__factory.connect(\"\", DummyProvider)\n\n export class ${contract.name}ContractView extends ContractView<${contract.name}> {\n constructor (contract: ${contract.name}) {\n super(contract);\n }\n\n ${Object.values(contract.functions)\n .filter((f) => !reservedKeywords.has(f[0].name))\n .flatMap((v) => v.filter((f) => f.stateMutability == 'view').map(generateViewFunction))\n .join('\\n')}\n }\n \n export class ${contract.name}BoundContractView extends BoundContractView<${contract.name}, ${\n contract.name\n }ContractView> {\n // constructor (contract: ${contract.name}) {\n // super(contract);\n // }\n\n ${Object.values(contract.functions)\n .filter((f) => !reservedKeywords.has(f[0].name))\n .flatMap((v) => v.filter((f) => f.stateMutability == 'view').map(generateBoundViewFunction))\n .join('\\n')}\n }\n\n export type ${contract.name}Context = Context<${contract.name}, ${contract.name}BoundContractView>\n\n export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${contract.name}, ${\n contract.name\n }BoundContractView> {\n bindInternal(options: BindOptions) {\n let processor = getProcessor(\"${contract.name}\", options) as ${contract.name}Processor\n if (!processor) {\n const finalOptions = Object.assign({}, options)\n finalOptions.name = getContractName(\"${contract.name}\", options.name, options.address, options.network)\n processor = new ${contract.name}Processor(finalOptions)\n addProcessor(\"${contract.name}\", options, processor)\n }\n return processor\n }\n\n ${Object.values(contract.events)\n .map((events) => {\n if (events.length === 1) {\n return generateOnEventFunction(events[0], contract.name, false)\n } else {\n return events.map((e) => generateOnEventFunction(e, contract.name, true)).join('\\n')\n }\n })\n .join('\\n')}\n }\n\n export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {\n ${Object.values(contract.events)\n .map((events) => {\n if (events.length === 1) {\n return generateOnEventFunction(events[0], contract.name, false)\n } else {\n return events.map((e) => generateOnEventFunction(e, contract.name, true)).join('\\n')\n }\n })\n .join('\\n')}\n\n public static filters = templateContract.filters\n \n protected CreateBoundContractView(): ${contract.name}BoundContractView {\n const view = get${contract.name}Contract(this.config.address, this.config.network)\n return new ${contract.name}BoundContractView(view)\n }\n\n public static bind(options: BindOptions): ${contract.name}Processor {\n let processor = getProcessor(\"${contract.name}\", options) as ${contract.name}Processor\n if (!processor) {\n // const wrapper = get${contract.name}Contract(options.address, options.network)\n\n const finalOptions = Object.assign({}, options)\n finalOptions.name = getContractName(\"${contract.name}\", options.name, options.address, options.network)\n processor = new ${contract.name}Processor(finalOptions)\n addProcessor(\"${contract.name}\", options, processor)\n }\n return processor\n }\n }\n\n export function get${contract.name}Contract(address: string, network: Networkish = 1): ${contract.name}ContractView {\n let contract = getContractByABI(\"${contract.name}\", address, network) as ${contract.name}ContractView\n if (!contract) {\n const rawContract = ${contract.name}__factory.connect(address, getProvider(network))\n contract = new ${contract.name}ContractView(rawContract)\n addContractByABI(\"${contract.name}\", address, network, contract)\n }\n return contract\n }\n `\n\n const imports = createImportsForUsedIdentifiers(\n {\n ethers: ['BigNumber', 'BigNumberish', 'CallOverrides', 'BytesLike'],\n '@ethersproject/providers': ['Networkish'],\n '@sentio/sdk': [\n 'addContractByABI',\n 'getContractByABI',\n 'addProcessor',\n 'getProcessor',\n 'getProvider',\n 'transformEtherError',\n 'BindOptions',\n 'BaseProcessor',\n 'BaseProcessorTemplate',\n 'BoundContractView',\n 'Context',\n 'ContractView',\n 'DummyProvider',\n 'getContractName',\n ],\n './common': ['PromiseOrValue'],\n './index': [`${contract.name}`, `${contract.name}__factory`],\n [`./${contract.name}`]: (<string[]>[]).concat(\n ...Object.values(contract.events).map((events) => {\n if (events.length === 1) {\n return [`${events[0].name}Event`, `${events[0].name}EventFilter`]\n } else {\n return events.flatMap((e) => [\n `${getFullSignatureAsSymbolForEvent(e)}_Event`,\n `${getFullSignatureAsSymbolForEvent(e)}_EventFilter`,\n ])\n }\n })\n ),\n },\n source\n )\n\n return imports + source\n}\n\nexport function codeGenTestUtilsFile(contract: Contract): string {\n const source = `\n const mockField = {\n blockHash:\n \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n blockNumber: 0,\n logIndex: 0,\n removed: false,\n transactionHash:\n \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n transactionIndex: 0,\n }\n ${Object.values(contract.events)\n .map((events) => {\n if (events.length === 1) {\n return generateMockEventLogFunction(events[0], contract.name, false)\n } else {\n return events.map((e) => generateMockEventLogFunction(e, contract.name, true)).join('\\n')\n }\n })\n .join('\\n')}\n `\n\n const imports = createImportsForUsedIdentifiers(\n {\n '@ethersproject/providers': ['Log'],\n '.': [\n `get${contract.name}Contract`,\n ...Object.values(contract.events).flatMap((events) => {\n if (events.length === 1) {\n return `${events[0].name}EventObject`\n } else {\n return events.flatMap((e) => `${getFullSignatureAsSymbolForEvent(e)}_EventObject`)\n }\n }),\n ],\n },\n source\n )\n\n return imports + source\n}\n\nfunction generateOnEventFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {\n let eventName = event.name\n if (includeArgTypes) {\n eventName = getFullSignatureAsSymbolForEvent(event) + '_'\n }\n\n const filterName = getFullSignatureForEvent(event)\n\n return `\n on${eventName}(\n handler: (event: ${eventName}Event, ctx: ${contractName}Context) => void,\n filter?: ${eventName}EventFilter | ${eventName}EventFilter[]\n ) {\n if (!filter) {\n filter = ${contractName}Processor.filters['${filterName}'](${event.inputs.map(() => 'null').join(',')})\n }\n return super.onEvent(handler, filter)\n }\n `\n}\n\nfunction generateViewFunction(func: FunctionDeclaration): string {\n return `\n async ${func.name}(${generateInputTypes(func.inputs, { useStructs: true })}overrides?: CallOverrides) {\n try {\n if (overrides) {\n return await this.contract.${func.name}(${\n func.inputs.length > 0 ? func.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } overrides)\n } else {\n return await this.contract.${func.name}(${func.inputs\n .map((input, index) => input.name || `arg${index}`)\n .join(',')})\n }\n } catch (e) {\n throw transformEtherError(e, undefined)\n }\n }\n `\n}\n\nfunction generateBoundViewFunction(func: FunctionDeclaration): string {\n return `\n async ${func.name}(${generateInputTypes(func.inputs, { useStructs: true })}overrides?: CallOverrides) {\n try {\n if (!overrides && this.context) {\n overrides = {\n blockTag: this.context.blockNumber.toNumber(),\n }\n }\n if (overrides) {\n return await this.view.${func.name}(${\n func.inputs.length > 0 ? func.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } overrides)\n } else {\n return await this.view.${func.name}(${func.inputs.map((input, index) => input.name || `arg${index}`).join(',')})\n }\n } catch (e) {\n throw transformEtherError(e, this.context)\n }\n }\n `\n}\n\nfunction generateMockEventLogFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {\n let eventName = event.name\n let eventNameWithSignature = event.name\n if (includeArgTypes) {\n eventName = getFullSignatureAsSymbolForEvent(event) + '_'\n eventNameWithSignature = getFullSignatureForEvent(event)\n }\n\n return `\n export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): Log {\n const contract = get${contractName}Contract(contractAddress)\n const encodedLog = contract.rawContract.interface.encodeEventLog(\n contract.rawContract.interface.getEvent('${eventNameWithSignature}'),\n Object.values(event)\n )\n return {\n ...mockField,\n address: contractAddress,\n data: encodedLog.data,\n topics: encodedLog.topics,\n }\n }\n `\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/target-ethers-sentio/index.ts"],"names":[],"mappings":";;;;;AAAA,qEAAyC;AACzC,yCAAqH;AACrH,+BAA8C;AAC9C,uCAAiF;AAEjF,MAAqB,YAAa,SAAQ,mBAAM;IAC9C,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;SAC/C;QACD,KAAK,CAAC,MAAM,CAAC,CAAA;IACf,CAAC;IAED,kEAAkE;IACzD,0BAA0B,CAAC,IAAqB;QACvD,MAAM,GAAG,GAAG,IAAA,sBAAU,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACrC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;YACpB,OAAM;SACP;QAED,MAAM,aAAa,GAAG,IAAA,gCAAoB,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAEzD,MAAM,QAAQ,GAAG,IAAA,eAA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, parse, shortenFullJsonFilePath } from 'typechain'\nimport { dirname, join, relative } from 'path'\nimport { codeGenIndex, codeGenSentioFile, codeGenTestUtilsFile } from './codegen'\n\nexport default class EthersSentio extends Ethers {\n constructor(config: Config) {\n if (!config.outDir) {\n throw new Error('Out put path not specificed')\n }\n super(config)\n }\n\n // TODO(pc): also have to override transformBinFile, transformFile\n override transformAbiOrFullJsonFile(file: FileDescription): FileDescription[] | void {\n const abi = extractAbi(file.contents)\n if (abi.length === 0) {\n return\n }\n\n const documentation = extractDocumentation(file.contents)\n\n const jsonPath = relative(this.cfg.inputDir, shortenFullJsonFilePath(file.path, this.cfg.allFiles))\n const contract = parse(abi, jsonPath, documentation)\n const files = super.transformAbiOrFullJsonFile(file)\n\n if (files !== undefined) {\n // files.forEach(this.transformFilePath)\n // for (const file of files) {\n // this.transformFilePath(file)\n // }\n\n return [\n ...files,\n {\n path: join(dirname(files[0].path), `${contract.name.toLowerCase()}_processor.ts`),\n contents: codeGenSentioFile(contract),\n },\n {\n path: join(dirname(files[0].path), '..', contract.name.toLowerCase(), 'index.ts'),\n contents: codeGenIndex(contract),\n },\n {\n path: join(dirname(files[0].path), '..', contract.name.toLowerCase(), 'test-utils.ts'),\n contents: codeGenTestUtilsFile(contract),\n },\n ]\n }\n }\n}\n"]}