create-dubhe 1.2.0-pre.98 → 2.0.0

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 (361) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/cli.js.map +1 -1
  3. package/package.json +16 -16
  4. package/templates/101/sui-template/docker-compose.testnet.yml +73 -0
  5. package/templates/101/sui-template/packages/client/src/app/page.tsx +545 -41
  6. package/templates/101/sui-template/packages/client/src/app/providers.tsx +12 -4
  7. package/templates/101/sui-template/packages/contracts/Pub.localnet.toml +4 -4
  8. package/templates/101/sui-template/packages/contracts/counter.lock.json +20 -0
  9. package/templates/101/sui-template/packages/contracts/deployment.ts +8 -3
  10. package/templates/101/sui-template/packages/contracts/dubhe.config.json +59 -13
  11. package/templates/101/sui-template/packages/contracts/dubhe.config.ts +1 -4
  12. package/templates/101/sui-template/packages/contracts/metadata.json +1015 -68
  13. package/templates/101/sui-template/packages/contracts/package.json +7 -4
  14. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
  15. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/error.move +8 -0
  16. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
  17. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
  18. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +198 -0
  19. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2withkey.move +90 -0
  20. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/value.move +30 -20
  21. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
  22. package/templates/101/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -11
  23. package/templates/101/sui-template/packages/contracts/src/counter/sources/systems/counter.move +23 -11
  24. package/templates/101/sui-template/packages/contracts/src/counter/sources/tests/counter.move +15 -14
  25. package/templates/101/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
  26. package/templates/101/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
  27. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
  28. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
  29. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
  30. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
  31. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
  32. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
  33. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
  34. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
  35. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
  36. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
  37. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
  38. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
  39. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
  40. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
  41. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
  42. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
  43. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
  44. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
  45. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
  46. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
  47. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
  48. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
  49. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
  50. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
  51. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
  52. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
  53. package/templates/contract/sui-template/dubhe.config.ts +0 -1
  54. package/templates/contract/sui-template/package.json +3 -3
  55. package/templates/contract/sui-template/src/dubhe/Move.lock +33 -30
  56. package/templates/contract/sui-template/src/dubhe/Move.toml +8 -3
  57. package/templates/contract/sui-template/src/dubhe/sources/codegen/dapp_key.move +45 -31
  58. package/templates/contract/sui-template/src/dubhe/sources/codegen/error.move +170 -0
  59. package/templates/contract/sui-template/src/dubhe/sources/codegen/genesis.move +16 -13
  60. package/templates/contract/sui-template/src/dubhe/sources/codegen/init_test.move +8 -14
  61. package/templates/contract/sui-template/src/dubhe/sources/core/account_key.move +1 -3
  62. package/templates/contract/sui-template/src/dubhe/sources/core/dapp_service.move +1776 -137
  63. package/templates/contract/sui-template/src/dubhe/sources/core/data_key.move +1 -20
  64. package/templates/contract/sui-template/src/dubhe/sources/core/events.move +864 -25
  65. package/templates/contract/sui-template/src/dubhe/sources/scripts/deploy_hook.move +15 -16
  66. package/templates/contract/sui-template/src/dubhe/sources/scripts/migrate.move +0 -3
  67. package/templates/contract/sui-template/src/dubhe/sources/systems/address_system.move +25 -17
  68. package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +2802 -343
  69. package/templates/contract/sui-template/src/dubhe/sources/systems/utils.move +1 -1
  70. package/templates/contract/sui-template/src/dubhe/sources/tests/address.move +173 -55
  71. package/templates/contract/sui-template/src/dubhe/sources/tests/dapp_test.move +769 -0
  72. package/templates/contract/sui-template/src/dubhe/sources/tests/fee_test.move +2965 -0
  73. package/templates/contract/sui-template/src/dubhe/sources/tests/integration_test.move +303 -0
  74. package/templates/contract/sui-template/src/dubhe/sources/tests/listing_test.move +1422 -0
  75. package/templates/contract/sui-template/src/dubhe/sources/tests/scene_session_test.move +269 -0
  76. package/templates/contract/sui-template/src/dubhe/sources/tests/session_test.move +624 -0
  77. package/templates/contract/sui-template/src/dubhe/sources/tests/storage_test.move +700 -0
  78. package/templates/contract/sui-template/src/dubhe/sources/tests/typed_object_test.move +177 -0
  79. package/templates/contract/sui-template/src/dubhe/sources/tests/typed_scene_test.move +452 -0
  80. package/templates/contract/sui-template/src/dubhe/sources/tests/user_storage_test.move +160 -0
  81. package/templates/contract/sui-template/src/dubhe/sources/utils/math.move +4 -3
  82. package/templates/contract/sui-template/src/dubhe/sources/utils/type_info.move +2 -2
  83. package/templates/contract/sui-template/src/template/Move.toml +12 -0
  84. package/templates/contract/sui-template/src/template/sources/codegen/dapp_key.move +47 -0
  85. package/templates/contract/sui-template/src/template/sources/codegen/genesis.move +34 -0
  86. package/templates/contract/sui-template/src/template/sources/codegen/init_test.move +23 -0
  87. package/templates/contract/sui-template/src/template/sources/codegen/user_storage_init.move +27 -0
  88. package/templates/contract/sui-template/src/template/sources/scripts/deploy_hook.move +13 -0
  89. package/templates/contract/sui-template/src/template/sources/scripts/migrate.move +7 -0
  90. package/templates/nextjs/sui-card-duel/.gitignore_ +51 -0
  91. package/templates/nextjs/sui-card-duel/README.md +213 -0
  92. package/templates/nextjs/sui-card-duel/docker-compose.yml +34 -0
  93. package/templates/nextjs/sui-card-duel/mprocs.yaml +17 -0
  94. package/templates/nextjs/sui-card-duel/package.json +43 -0
  95. package/templates/nextjs/sui-card-duel/packages/client/.gitignore_ +48 -0
  96. package/templates/nextjs/sui-card-duel/packages/client/.prettierignore +1 -0
  97. package/templates/nextjs/sui-card-duel/packages/client/.prettierrc.json +8 -0
  98. package/templates/nextjs/sui-card-duel/packages/client/eslint.config.mjs +22 -0
  99. package/templates/nextjs/sui-card-duel/packages/client/next.config.mjs +8 -0
  100. package/templates/nextjs/sui-card-duel/packages/client/package.json +47 -0
  101. package/templates/nextjs/sui-card-duel/packages/client/postcss.config.mjs +8 -0
  102. package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/ArenaPanel.tsx +307 -0
  103. package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/page.tsx +622 -0
  104. package/templates/nextjs/sui-card-duel/packages/client/src/app/brawl/[id]/page.tsx +559 -0
  105. package/templates/nextjs/sui-card-duel/packages/client/src/app/collection/page.tsx +202 -0
  106. package/templates/nextjs/sui-card-duel/packages/client/src/app/components/CardView.tsx +66 -0
  107. package/templates/nextjs/sui-card-duel/packages/client/src/app/components/GameShell.tsx +294 -0
  108. package/templates/nextjs/sui-card-duel/packages/client/src/app/components/icons.tsx +101 -0
  109. package/templates/nextjs/sui-card-duel/packages/client/src/app/duel/[id]/page.tsx +477 -0
  110. package/templates/nextjs/sui-card-duel/packages/client/src/app/favicon.ico +0 -0
  111. package/templates/nextjs/sui-card-duel/packages/client/src/app/globals.css +85 -0
  112. package/templates/nextjs/sui-card-duel/packages/client/src/app/hooks/useGame.ts +313 -0
  113. package/templates/nextjs/sui-card-duel/packages/client/src/app/layout.tsx +24 -0
  114. package/templates/nextjs/sui-card-duel/packages/client/src/app/leaderboard/page.tsx +123 -0
  115. package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/game.ts +77 -0
  116. package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/scenes.ts +226 -0
  117. package/templates/nextjs/sui-card-duel/packages/client/src/app/market/page.tsx +418 -0
  118. package/templates/nextjs/sui-card-duel/packages/client/src/app/page.tsx +427 -0
  119. package/templates/nextjs/sui-card-duel/packages/client/src/app/providers.tsx +69 -0
  120. package/templates/nextjs/sui-card-duel/packages/client/tailwind.config.ts +21 -0
  121. package/templates/nextjs/sui-card-duel/packages/client/tsconfig.json +30 -0
  122. package/templates/nextjs/sui-card-duel/packages/contracts/.gitignore_ +51 -0
  123. package/templates/nextjs/sui-card-duel/packages/contracts/.prettierignore +1 -0
  124. package/templates/nextjs/sui-card-duel/packages/contracts/.prettierrc.json +8 -0
  125. package/templates/nextjs/sui-card-duel/packages/contracts/Dockerfile +5 -0
  126. package/templates/nextjs/sui-card-duel/packages/contracts/Pub.localnet.toml +13 -0
  127. package/templates/nextjs/sui-card-duel/packages/contracts/card_duel.lock.json +66 -0
  128. package/templates/nextjs/sui-card-duel/packages/contracts/docker-compose.yml +34 -0
  129. package/templates/nextjs/sui-card-duel/packages/contracts/dubhe.config.ts +150 -0
  130. package/templates/nextjs/sui-card-duel/packages/contracts/logs/combined.log +31383 -0
  131. package/templates/nextjs/sui-card-duel/packages/contracts/package.json +49 -0
  132. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/config.ts +17 -0
  133. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-brawl.ts +270 -0
  134. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-duel.ts +272 -0
  135. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-lobby.ts +177 -0
  136. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-market.ts +219 -0
  137. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-session.ts +342 -0
  138. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
  139. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/seed.ts +92 -0
  140. package/templates/nextjs/sui-card-duel/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
  141. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/Move.toml +15 -0
  142. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/dapp_key.move +46 -0
  143. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/card_kind.move +47 -0
  144. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/match_state.move +37 -0
  145. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/rarity.move +37 -0
  146. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/error.move +126 -0
  147. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/genesis.move +33 -0
  148. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/init_test.move +23 -0
  149. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/objects/arena.move +137 -0
  150. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/brawl_permit.move +125 -0
  151. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/duel_permit.move +125 -0
  152. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/battle_state.move +255 -0
  153. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/card.move +282 -0
  154. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/deck.move +64 -0
  155. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/game_config.move +267 -0
  156. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/gold.move +205 -0
  157. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/profile.move +255 -0
  158. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/brawl.move +313 -0
  159. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/duel.move +313 -0
  160. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/user_storage_init.move +26 -0
  161. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/deploy_hook.move +32 -0
  162. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/migrate.move +7 -0
  163. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/arena_system.move +57 -0
  164. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/brawl_system.move +559 -0
  165. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/card_system.move +146 -0
  166. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/duel_system.move +515 -0
  167. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/market_system.move +115 -0
  168. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/player_system.move +37 -0
  169. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/brawl_tests.move +385 -0
  170. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/duel_tests.move +656 -0
  171. package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/test_helpers.move +31 -0
  172. package/templates/nextjs/sui-card-duel/packages/contracts/sui-indexer-schema.graphql +5973 -0
  173. package/templates/nextjs/sui-card-duel/pnpm-workspace.yaml +2 -0
  174. package/templates/nextjs/sui-farm/.gitignore_ +51 -0
  175. package/templates/nextjs/sui-farm/README.md +15 -0
  176. package/templates/nextjs/sui-farm/UPGRADE_NOTES.md +97 -0
  177. package/templates/nextjs/sui-farm/docker-compose.yml +34 -0
  178. package/templates/nextjs/sui-farm/mprocs.yaml +17 -0
  179. package/templates/nextjs/sui-farm/package.json +43 -0
  180. package/templates/nextjs/sui-farm/packages/client/.gitignore_ +48 -0
  181. package/templates/nextjs/sui-farm/packages/client/.prettierignore +1 -0
  182. package/templates/nextjs/sui-farm/packages/client/.prettierrc.json +8 -0
  183. package/templates/nextjs/sui-farm/packages/client/eslint.config.mjs +22 -0
  184. package/templates/nextjs/sui-farm/packages/client/next.config.mjs +8 -0
  185. package/templates/nextjs/sui-farm/packages/client/package.json +47 -0
  186. package/templates/nextjs/sui-farm/packages/client/postcss.config.mjs +8 -0
  187. package/templates/nextjs/sui-farm/packages/client/src/app/admin/page.tsx +618 -0
  188. package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmLand.tsx +526 -0
  189. package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmPlotCard.tsx +215 -0
  190. package/templates/nextjs/sui-farm/packages/client/src/app/components/PetAvatar.tsx +868 -0
  191. package/templates/nextjs/sui-farm/packages/client/src/app/components/PetPanel.tsx +1360 -0
  192. package/templates/nextjs/sui-farm/packages/client/src/app/components/PlantModal.tsx +147 -0
  193. package/templates/nextjs/sui-farm/packages/client/src/app/components/ProxyCard.tsx +684 -0
  194. package/templates/nextjs/sui-farm/packages/client/src/app/components/RanchLand.tsx +822 -0
  195. package/templates/nextjs/sui-farm/packages/client/src/app/components/ResourceHUD.tsx +125 -0
  196. package/templates/nextjs/sui-farm/packages/client/src/app/components/ShopPanel.tsx +232 -0
  197. package/templates/nextjs/sui-farm/packages/client/src/app/components/icons/GameIcons.tsx +574 -0
  198. package/templates/nextjs/sui-farm/packages/client/src/app/favicon.ico +0 -0
  199. package/templates/nextjs/sui-farm/packages/client/src/app/globals.css +423 -0
  200. package/templates/nextjs/sui-farm/packages/client/src/app/hooks/useWorldPermitId.ts +66 -0
  201. package/templates/nextjs/sui-farm/packages/client/src/app/layout.tsx +23 -0
  202. package/templates/nextjs/sui-farm/packages/client/src/app/leaderboard/page.tsx +185 -0
  203. package/templates/nextjs/sui-farm/packages/client/src/app/lib/crops.ts +97 -0
  204. package/templates/nextjs/sui-farm/packages/client/src/app/market/page.tsx +763 -0
  205. package/templates/nextjs/sui-farm/packages/client/src/app/page.tsx +1173 -0
  206. package/templates/nextjs/sui-farm/packages/client/src/app/providers.tsx +69 -0
  207. package/templates/nextjs/sui-farm/packages/client/src/app/state/index.tsx +5 -0
  208. package/templates/nextjs/sui-farm/packages/client/tailwind.config.ts +25 -0
  209. package/templates/nextjs/sui-farm/packages/client/tsconfig.json +30 -0
  210. package/templates/nextjs/sui-farm/packages/contracts/.gitignore_ +51 -0
  211. package/templates/nextjs/sui-farm/packages/contracts/.prettierignore +1 -0
  212. package/templates/nextjs/sui-farm/packages/contracts/.prettierrc.json +8 -0
  213. package/templates/nextjs/sui-farm/packages/contracts/Dockerfile +5 -0
  214. package/templates/nextjs/sui-farm/packages/contracts/Pub.localnet.toml +13 -0
  215. package/templates/nextjs/sui-farm/packages/contracts/counter.lock.json +14 -0
  216. package/templates/nextjs/sui-farm/packages/contracts/docker-compose.yml +34 -0
  217. package/templates/nextjs/sui-farm/packages/contracts/dubhe.config.ts +178 -0
  218. package/templates/nextjs/sui-farm/packages/contracts/harvest.lock.json +120 -0
  219. package/templates/nextjs/sui-farm/packages/contracts/package.json +48 -0
  220. package/templates/nextjs/sui-farm/packages/contracts/scripts/config.ts +17 -0
  221. package/templates/nextjs/sui-farm/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
  222. package/templates/nextjs/sui-farm/packages/contracts/scripts/read-permit.ts +72 -0
  223. package/templates/nextjs/sui-farm/packages/contracts/scripts/seed.ts +85 -0
  224. package/templates/nextjs/sui-farm/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
  225. package/templates/nextjs/sui-farm/packages/contracts/src/counter/Move.toml +14 -0
  226. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/dapp_key.move +31 -0
  227. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/error.move +10 -0
  228. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/genesis.move +33 -0
  229. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/init_test.move +23 -0
  230. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter1.move +64 -0
  231. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter2.move +70 -0
  232. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
  233. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/deploy_hook.move +8 -0
  234. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/migrate.move +8 -0
  235. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/systems/counter.move +13 -0
  236. package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/tests/counter.move +28 -0
  237. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/Move.toml +14 -0
  238. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/dapp_key.move +46 -0
  239. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/crop_type.move +47 -0
  240. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/egg_type.move +42 -0
  241. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_rarity.move +37 -0
  242. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_species.move +52 -0
  243. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/error.move +110 -0
  244. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/genesis.move +33 -0
  245. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/init_test.move +23 -0
  246. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/permits/world.move +125 -0
  247. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot.move +136 -0
  248. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot_seed.move +80 -0
  249. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/common_egg.move +136 -0
  250. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn.move +136 -0
  251. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn_seed.move +80 -0
  252. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_charges.move +162 -0
  253. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_damage.move +207 -0
  254. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/farm_plot.move +261 -0
  255. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/gold.move +80 -0
  256. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet.move +467 -0
  257. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_config.move +372 -0
  258. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_hatch.move +162 -0
  259. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slot_index.move +83 -0
  260. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slots.move +64 -0
  261. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/profile.move +162 -0
  262. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin.move +136 -0
  263. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin_seed.move +80 -0
  264. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/rare_egg.move +136 -0
  265. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/scarecrow.move +64 -0
  266. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_config.move +197 -0
  267. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_stats.move +64 -0
  268. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/seasonal_egg.move +136 -0
  269. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/shop_config.move +267 -0
  270. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/trophy.move +245 -0
  271. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat.move +136 -0
  272. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat_seed.move +80 -0
  273. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/world_permit_id.move +64 -0
  274. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/user_storage_init.move +26 -0
  275. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/deploy_hook.move +45 -0
  276. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/migrate.move +7 -0
  277. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/crow_system.move +96 -0
  278. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/farm_system.move +182 -0
  279. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/market_system.move +172 -0
  280. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/pet_system.move +495 -0
  281. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/season_system.move +70 -0
  282. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/shop_system.move +112 -0
  283. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/world_system.move +34 -0
  284. package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/tests/farm_tests.move +1192 -0
  285. package/templates/nextjs/sui-farm/pnpm-workspace.yaml +2 -0
  286. package/templates/nextjs/sui-template/packages/client/src/app/components/ProxyCard.tsx +683 -0
  287. package/templates/nextjs/sui-template/packages/client/src/app/page.tsx +510 -5
  288. package/templates/nextjs/sui-template/packages/client/src/app/providers.tsx +13 -5
  289. package/templates/nextjs/sui-template/packages/contracts/Pub.localnet.toml +4 -4
  290. package/templates/nextjs/sui-template/packages/contracts/counter.lock.json +14 -0
  291. package/templates/nextjs/sui-template/packages/contracts/deployment.ts +8 -3
  292. package/templates/nextjs/sui-template/packages/contracts/dubhe.config.json +9 -9
  293. package/templates/nextjs/sui-template/packages/contracts/dubhe.config.ts +0 -4
  294. package/templates/nextjs/sui-template/packages/contracts/metadata.json +180 -124
  295. package/templates/nextjs/sui-template/packages/contracts/package.json +8 -4
  296. package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.toml +4 -0
  297. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
  298. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/error.move +10 -0
  299. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
  300. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
  301. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter1.move +30 -20
  302. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +35 -24
  303. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
  304. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -10
  305. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/systems/counter.move +7 -20
  306. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/tests/counter.move +14 -27
  307. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
  308. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
  309. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
  310. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
  311. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
  312. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
  313. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
  314. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
  315. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
  316. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
  317. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
  318. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
  319. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
  320. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
  321. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
  322. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
  323. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
  324. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
  325. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
  326. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
  327. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
  328. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
  329. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
  330. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
  331. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
  332. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
  333. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
  334. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
  335. package/templates/101/sui-template/packages/contracts/src/counter/Move.lock +0 -41
  336. package/templates/101/sui-template/packages/contracts/src/counter/Published.toml +0 -9
  337. package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
  338. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
  339. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
  340. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
  341. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
  342. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
  343. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
  344. package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
  345. package/templates/contract/sui-template/src/dubhe/sources/codegen/errors.move +0 -140
  346. package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
  347. package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
  348. package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
  349. package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
  350. package/templates/contract/sui-template/src/dubhe/sources/core/dapp_store.move +0 -29
  351. package/templates/contract/sui-template/src/dubhe/sources/systems/session_system.move +0 -44
  352. package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.lock +0 -47
  353. package/templates/nextjs/sui-template/packages/contracts/src/counter/Published.toml +0 -9
  354. package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
  355. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
  356. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
  357. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
  358. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
  359. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
  360. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
  361. package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "contracts",
3
+ "version": "1.0.0",
4
+ "scripts": {
5
+ "account:gen": "pnpm dubhe generate-key",
6
+ "check-balance": "pnpm dubhe check-balance --network",
7
+ "config:store": "pnpm dubhe store-config --output-ts-path ./deployment.ts --network",
8
+ "deploy": "pnpm dubhe publish --network",
9
+ "faucet": "pnpm dubhe faucet --network",
10
+ "format": "prettier --write .",
11
+ "format:check": "prettier --check .",
12
+ "generate": "pnpm dubhe generate",
13
+ "graphql": "docker-compose up --remove-orphans",
14
+ "indexer": "dubhe-indexer --database-url postgres://postgres:postgres@localhost:5432/postgres --checkpoint-url .chk --config-json dubhe.config.json",
15
+ "indexer:testnet": "dubhe-indexer --database-url postgres://postgres:postgres@localhost:5432/postgres --checkpoint-url https://checkpoints.testnet.sui.io --config-json dubhe.config.json",
16
+ "prod:localnet": "pnpm config:store localnet && pnpm run indexer",
17
+ "prod:testnet": "pnpm config:store testnet && pnpm run indexer:testnet",
18
+ "seed:localnet": "pnpm tsx seed.ts localnet",
19
+ "seed:testnet": "pnpm tsx seed.ts testnet",
20
+ "setup:localnet": "pnpm account:gen && pnpm faucet localnet && pnpm run deploy localnet && pnpm run config:store localnet && pnpm run indexer --force",
21
+ "setup:testnet": "pnpm account:gen && pnpm check-balance testnet && pnpm run deploy testnet && pnpm run config:store testnet && pnpm run indexer:testnet --force",
22
+ "start:localnet": "pnpm dubhe node",
23
+ "test": "pnpm dubhe test",
24
+ "type-check": "tsc --noEmit",
25
+ "upgrade": "pnpm dubhe upgrade --network",
26
+ "validate": "pnpm format:check && pnpm type-check"
27
+ },
28
+ "dependencies": {
29
+ "@0xobelisk/sui-cli": "{{dubhe-version}}",
30
+ "@0xobelisk/sui-client": "{{dubhe-version}}",
31
+ "@0xobelisk/sui-common": "{{dubhe-version}}",
32
+ "dotenv": "^16.4.5",
33
+ "sonner": "^1.5.0",
34
+ "viem": "2.21.19"
35
+ },
36
+ "devDependencies": {
37
+ "@eslint/eslintrc": "^3",
38
+ "@types/node": "^18",
39
+ "eslint": "^8.56.0",
40
+ "eslint-config-prettier": "^9.1.0",
41
+ "mprocs": "^0.7.1",
42
+ "postcss": "^8",
43
+ "prettier": "3.3.3",
44
+ "tailwindcss": "^3.4.1",
45
+ "tsx": "^4.0.0",
46
+ "typescript": "^5",
47
+ "wait-on": "^8.0.3"
48
+ }
49
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Single source of truth for scripts — reads values from deployment.ts.
3
+ * Handles tsx CJS/ESM interop: when tsx compiles a .ts file as CJS,
4
+ * ESM namespace imports put all exports under `default`.
5
+ */
6
+ import * as _mod from '../deployment.ts';
7
+
8
+ // Under tsx CJS interop, named exports are on `default`; fall back to namespace itself for ESM.
9
+ const dep: Record<string, any> = ((_mod as any).default ?? _mod) as Record<string, any>;
10
+
11
+ export const Network: string = dep['Network'];
12
+ export const PackageId: string = dep['PackageId'];
13
+ export const OriginalPackageId: string = dep['OriginalPackageId'];
14
+ export const DappKey: string = dep['DappKey'];
15
+ export const DappHubId: string = dep['DappHubId'];
16
+ export const DappStorageId: string = dep['DappStorageId'];
17
+ export const FrameworkPackageId: string | undefined = dep['FrameworkPackageId'];
@@ -0,0 +1,270 @@
1
+ /**
2
+ * e2e-brawl.ts — End-to-end brawl flow on localnet (open-invite room).
3
+ *
4
+ * Usage:
5
+ * cd templates/nextjs/sui-card-duel/packages/contracts
6
+ * pnpm tsx scripts/e2e-brawl.ts
7
+ *
8
+ * Flow: onboarding x2 -> create_brawl -> join_brawl -> start_brawl
9
+ * -> brawl_attack until elimination -> finish_brawl -> cleanup_brawl
10
+ * -> open_pack (Random) -> verify balances via indexer.
11
+ */
12
+
13
+ import {
14
+ Dubhe,
15
+ Transaction,
16
+ getFullnodeUrl,
17
+ Ed25519Keypair,
18
+ loadMetadata
19
+ } from '@0xobelisk/sui-client';
20
+ import { PackageId, DappHubId, DappStorageId, FrameworkPackageId } from './config.ts';
21
+
22
+ const NETWORK = 'localnet' as const;
23
+ const GRAPHQL = 'http://127.0.0.1:4000/graphql';
24
+ const CLOCK = '0x6';
25
+ const RANDOM = '0x8';
26
+ const ENTRY_FEE = 30n;
27
+
28
+ function newDubhe(metadata: any, secretKey: string) {
29
+ return new Dubhe({
30
+ networkType: NETWORK,
31
+ packageId: PackageId,
32
+ metadata,
33
+ secretKey,
34
+ suiRpcUrl: getFullnodeUrl(NETWORK),
35
+ dappHubId: DappHubId,
36
+ dappStorageId: DappStorageId,
37
+ frameworkPackageId: FrameworkPackageId
38
+ });
39
+ }
40
+
41
+ async function gql(query: string): Promise<any> {
42
+ const res = await fetch(GRAPHQL, {
43
+ method: 'POST',
44
+ headers: { 'Content-Type': 'application/json' },
45
+ body: JSON.stringify({ query })
46
+ });
47
+ const json = await res.json();
48
+ if (json.errors) throw new Error(JSON.stringify(json.errors));
49
+ return json.data;
50
+ }
51
+
52
+ async function send(dubhe: Dubhe, label: string, build: (tx: Transaction) => void) {
53
+ const tx = new Transaction();
54
+ build(tx);
55
+ const result = await dubhe.signAndSendTxn({ tx });
56
+ const status = (result as any).effects?.status?.status;
57
+ if (status !== 'success') {
58
+ throw new Error(`${label} failed: ${JSON.stringify((result as any).effects?.status)}`);
59
+ }
60
+ await dubhe.waitForTransaction(result.digest);
61
+ console.log(` ✓ ${label} (${result.digest})`);
62
+ return result as any;
63
+ }
64
+
65
+ async function main() {
66
+ const metadata = await loadMetadata(NETWORK, PackageId);
67
+
68
+ const A = newDubhe(metadata, new Ed25519Keypair().getSecretKey());
69
+ const B = newDubhe(metadata, new Ed25519Keypair().getSecretKey());
70
+ const addrA = A.getAddress();
71
+ const addrB = B.getAddress();
72
+ console.log(`Host A: ${addrA}`);
73
+ console.log(`Joiner B: ${addrB}`);
74
+
75
+ // ── 1. Onboarding ─────────────────────────────────────────────────────────
76
+ console.log('\n[1] Onboarding');
77
+ await A.requestFaucet(addrA, NETWORK);
78
+ await B.requestFaucet(addrB, NETWORK);
79
+ await new Promise((r) => setTimeout(r, 2000));
80
+
81
+ const userStorageIds: Record<string, string> = {};
82
+ for (const [who, dubhe] of [
83
+ ['A', A],
84
+ ['B', B]
85
+ ] as const) {
86
+ const result = await send(dubhe, `init_user_storage (${who})`, (tx) => {
87
+ tx.moveCall({
88
+ target: `${PackageId}::user_storage_init::init_user_storage`,
89
+ arguments: [tx.object(DappHubId), tx.object(DappStorageId)]
90
+ });
91
+ });
92
+ const usId = (result.objectChanges ?? []).find(
93
+ (c: any) => c.type === 'created' && c.objectType?.endsWith('::dapp_service::UserStorage')
94
+ )?.objectId;
95
+ if (!usId) throw new Error(`UserStorage not found for ${who}`);
96
+ userStorageIds[who] = usId;
97
+ await send(dubhe, `register (${who})`, (tx) => {
98
+ tx.moveCall({
99
+ target: `${PackageId}::player_system::register`,
100
+ arguments: [tx.object(DappStorageId), tx.object(usId)]
101
+ });
102
+ });
103
+ }
104
+ const usA = userStorageIds['A'];
105
+ const usB = userStorageIds['B'];
106
+
107
+ const readDeck = async (addr: string): Promise<string[]> => {
108
+ for (let i = 0; i < 30; i++) {
109
+ const data = await gql(`{ decks { nodes { entityId cardIds } } }`);
110
+ const row = data.decks.nodes.find((n: any) => n.entityId === addr);
111
+ let ids = row?.cardIds;
112
+ if (typeof ids === 'string') ids = JSON.parse(ids);
113
+ if (Array.isArray(ids) && ids.length === 5) return ids.map(String);
114
+ await new Promise((r) => setTimeout(r, 2000));
115
+ }
116
+ throw new Error(`deck for ${addr} not indexed in time`);
117
+ };
118
+ const deckA = await readDeck(addrA);
119
+ const deckB = await readDeck(addrB);
120
+ // Deck order: Strike, Strike, Strike, Fireball(18), Shield
121
+ const fireballA = deckA[3];
122
+ const fireballB = deckB[3];
123
+
124
+ // ── 2. Open the room (open-invite permit) ────────────────────────────────
125
+ console.log('\n[2] create_brawl');
126
+ const createResult = await send(A, 'create_brawl (fee 30, max 4)', (tx) => {
127
+ tx.moveCall({
128
+ target: `${PackageId}::brawl_system::create_brawl`,
129
+ arguments: [
130
+ tx.object(DappStorageId),
131
+ tx.object(usA),
132
+ tx.pure.u64(ENTRY_FEE),
133
+ tx.pure.u64(4n),
134
+ tx.object(CLOCK)
135
+ ]
136
+ });
137
+ });
138
+ const created = (createResult.objectChanges ?? []).filter((c: any) => c.type === 'created');
139
+ const sceneId = created.find((c: any) => c.objectType?.includes('SceneStorage<'))?.objectId;
140
+ const permitId = created.find((c: any) => c.objectType?.includes('ScenePermit<'))?.objectId;
141
+ if (!sceneId || !permitId) throw new Error('scene/permit not found');
142
+ console.log(` Scene: ${sceneId}`);
143
+ console.log(` Permit: ${permitId}`);
144
+
145
+ // ── 3. B joins through the open permit, host starts ──────────────────────
146
+ console.log('\n[3] join + start');
147
+ await send(B, 'join_brawl (B pays 30)', (tx) => {
148
+ tx.moveCall({
149
+ target: `${PackageId}::brawl_system::join_brawl`,
150
+ arguments: [tx.object(DappStorageId), tx.object(usB), tx.object(permitId), tx.object(sceneId)]
151
+ });
152
+ });
153
+ await send(A, 'start_brawl', (tx) => {
154
+ tx.moveCall({
155
+ target: `${PackageId}::brawl_system::start_brawl`,
156
+ arguments: [
157
+ tx.object(DappStorageId),
158
+ tx.object(usA),
159
+ tx.object(permitId),
160
+ tx.object(sceneId),
161
+ tx.object(CLOCK)
162
+ ]
163
+ });
164
+ });
165
+
166
+ // ── 4. Combat (cards are reusable in brawls) ─────────────────────────────
167
+ console.log('\n[4] Combat');
168
+ const attack = (dubhe: Dubhe, mine: string, theirs: string, cardId: string, label: string) =>
169
+ send(dubhe, label, (tx) => {
170
+ tx.moveCall({
171
+ target: `${PackageId}::brawl_system::brawl_attack`,
172
+ arguments: [
173
+ tx.object(DappStorageId),
174
+ tx.object(mine),
175
+ tx.object(theirs),
176
+ tx.object(permitId),
177
+ tx.object(sceneId),
178
+ tx.pure.address(cardId),
179
+ tx.object(CLOCK)
180
+ ]
181
+ });
182
+ });
183
+ await attack(A, usA, usB, fireballA, 'A fireballs B (30→12)');
184
+ await attack(B, usB, usA, fireballB, 'B fireballs A (30→12)');
185
+ await attack(A, usA, usB, fireballA, 'A fireballs B (12→0, eliminated — A wins)');
186
+
187
+ // ── 5. Settlement ─────────────────────────────────────────────────────────
188
+ console.log('\n[5] Settlement');
189
+ const arenaData = await gql(`{ dubheObjectStorages { nodes { objectId objectType } } }`);
190
+ const arenaId = arenaData.dubheObjectStorages.nodes.find((n: any) =>
191
+ n.objectType?.toLowerCase().includes('arena')
192
+ )?.objectId;
193
+ if (!arenaId) throw new Error('arena not found');
194
+
195
+ await send(A, 'finish_brawl (A collects pot 60 - rake 1)', (tx) => {
196
+ tx.moveCall({
197
+ target: `${PackageId}::brawl_system::finish_brawl`,
198
+ arguments: [
199
+ tx.object(DappStorageId),
200
+ tx.object(usA),
201
+ tx.object(permitId),
202
+ tx.object(sceneId),
203
+ tx.object(arenaId)
204
+ ]
205
+ });
206
+ });
207
+ await send(B, 'leave_finished_brawl (B)', (tx) => {
208
+ tx.moveCall({
209
+ target: `${PackageId}::brawl_system::leave_finished_brawl`,
210
+ arguments: [tx.object(permitId), tx.object(sceneId), tx.object(usB)]
211
+ });
212
+ });
213
+ await send(A, 'cleanup_brawl (destroy scene + permit)', (tx) => {
214
+ tx.moveCall({
215
+ target: `${PackageId}::brawl_system::cleanup_brawl`,
216
+ arguments: [tx.object(sceneId), tx.object(permitId)]
217
+ });
218
+ });
219
+
220
+ // ── 6. open_pack exercises sui::random on localnet ───────────────────────
221
+ console.log('\n[6] open_pack (Random)');
222
+ await send(A, 'open_pack (A pays 100 gold)', (tx) => {
223
+ tx.moveCall({
224
+ target: `${PackageId}::card_system::open_pack`,
225
+ arguments: [tx.object(DappStorageId), tx.object(usA), tx.object(RANDOM)]
226
+ });
227
+ });
228
+
229
+ // ── 7. Verify via indexer ─────────────────────────────────────────────────
230
+ // A: 500 - 30(fee) + 59(pot-rake) - 100(pack) = 429, 1 win, 6 cards
231
+ // B: 500 - 30(fee) = 470, 1 loss, 5 cards
232
+ console.log('\n[7] Verify');
233
+ let ok = false;
234
+ for (let i = 0; i < 30; i++) {
235
+ const data = await gql(
236
+ `{ golds { nodes { entityId amount } }
237
+ profiles { nodes { entityId wins losses rating } }
238
+ cards { nodes { entityId isDeleted } } }`
239
+ );
240
+ const goldA = BigInt(data.golds.nodes.find((n: any) => n.entityId === addrA)?.amount ?? 0);
241
+ const goldB = BigInt(data.golds.nodes.find((n: any) => n.entityId === addrB)?.amount ?? 0);
242
+ const profA = data.profiles.nodes.find((n: any) => n.entityId === addrA) ?? {};
243
+ const profB = data.profiles.nodes.find((n: any) => n.entityId === addrB) ?? {};
244
+ const cardsA = data.cards.nodes.filter((n: any) => n.entityId === addrA && !n.isDeleted).length;
245
+ if (goldA === 429n && goldB === 470n && Number(profA.wins) === 1 && cardsA === 6) {
246
+ console.log(` A gold=${goldA} cards=${cardsA} profile=${JSON.stringify(profA)}`);
247
+ console.log(` B gold=${goldB} profile=${JSON.stringify(profB)}`);
248
+ ok = true;
249
+ break;
250
+ }
251
+ if (i === 29) {
252
+ console.log(` LAST STATE: A gold=${goldA} cards=${cardsA} B gold=${goldB}`);
253
+ console.log(` A profile=${JSON.stringify(profA)} B profile=${JSON.stringify(profB)}`);
254
+ }
255
+ await new Promise((r) => setTimeout(r, 2000));
256
+ }
257
+ if (!ok) throw new Error('indexer state did not converge to expected values');
258
+
259
+ const idx = await gql(`{ dubheSceneStorages { nodes { sceneId isDestroyed } } }`);
260
+ const sceneRow = idx.dubheSceneStorages.nodes.find((n: any) => n.sceneId === sceneId);
261
+ if (!sceneRow?.isDestroyed) throw new Error('brawl scene should be destroyed');
262
+ console.log(` Scene row: ${JSON.stringify(sceneRow)}`);
263
+
264
+ console.log('\n✅ E2E brawl flow passed!');
265
+ }
266
+
267
+ main().catch((err) => {
268
+ console.error(err);
269
+ process.exit(1);
270
+ });
@@ -0,0 +1,272 @@
1
+ /**
2
+ * e2e-duel.ts — End-to-end duel flow on localnet (two simulated players).
3
+ *
4
+ * Usage:
5
+ * cd templates/nextjs/sui-card-duel/packages/contracts
6
+ * pnpm tsx scripts/e2e-duel.ts
7
+ *
8
+ * Flow: faucet -> init_user_storage -> register -> create_duel -> accept_duel
9
+ * -> attack x3 (knockout) -> finish_duel (rake to arena) -> leave_duel
10
+ * -> cleanup_duel -> verify profiles / gold / indexer rows.
11
+ */
12
+
13
+ import {
14
+ Dubhe,
15
+ Transaction,
16
+ getFullnodeUrl,
17
+ Ed25519Keypair,
18
+ loadMetadata
19
+ } from '@0xobelisk/sui-client';
20
+ import { PackageId, DappHubId, DappStorageId, FrameworkPackageId } from './config.ts';
21
+
22
+ const NETWORK = 'localnet' as const;
23
+ const GRAPHQL = 'http://127.0.0.1:4000/graphql';
24
+ const CLOCK = '0x6';
25
+ const STAKE = 50n;
26
+
27
+ function newDubhe(metadata: any, secretKey: string) {
28
+ return new Dubhe({
29
+ networkType: NETWORK,
30
+ packageId: PackageId,
31
+ metadata,
32
+ secretKey,
33
+ suiRpcUrl: getFullnodeUrl(NETWORK),
34
+ dappHubId: DappHubId,
35
+ dappStorageId: DappStorageId,
36
+ frameworkPackageId: FrameworkPackageId
37
+ });
38
+ }
39
+
40
+ async function gql(query: string): Promise<any> {
41
+ const res = await fetch(GRAPHQL, {
42
+ method: 'POST',
43
+ headers: { 'Content-Type': 'application/json' },
44
+ body: JSON.stringify({ query })
45
+ });
46
+ const json = await res.json();
47
+ if (json.errors) throw new Error(JSON.stringify(json.errors));
48
+ return json.data;
49
+ }
50
+
51
+ async function send(dubhe: Dubhe, label: string, build: (tx: Transaction) => void) {
52
+ const tx = new Transaction();
53
+ build(tx);
54
+ const result = await dubhe.signAndSendTxn({ tx });
55
+ const status = (result as any).effects?.status?.status;
56
+ if (status !== 'success') {
57
+ throw new Error(`${label} failed: ${JSON.stringify((result as any).effects?.status)}`);
58
+ }
59
+ await dubhe.waitForTransaction(result.digest);
60
+ console.log(` ✓ ${label} (${result.digest})`);
61
+ return result as any;
62
+ }
63
+
64
+ async function main() {
65
+ const metadata = await loadMetadata(NETWORK, PackageId);
66
+
67
+ const keyA = new Ed25519Keypair();
68
+ const keyB = new Ed25519Keypair();
69
+ const A = newDubhe(metadata, keyA.getSecretKey());
70
+ const B = newDubhe(metadata, keyB.getSecretKey());
71
+ const addrA = A.getAddress();
72
+ const addrB = B.getAddress();
73
+ console.log(`Player A: ${addrA}`);
74
+ console.log(`Player B: ${addrB}`);
75
+
76
+ // ── 1. Fund both players ──────────────────────────────────────────────────
77
+ console.log('\n[1] Faucet');
78
+ await A.requestFaucet(addrA, NETWORK);
79
+ await B.requestFaucet(addrB, NETWORK);
80
+ await new Promise((r) => setTimeout(r, 2000));
81
+
82
+ // ── 2. UserStorage + register ─────────────────────────────────────────────
83
+ console.log('\n[2] Onboarding');
84
+ const userStorageIds: Record<string, string> = {};
85
+ for (const [who, dubhe] of [
86
+ ['A', A],
87
+ ['B', B]
88
+ ] as const) {
89
+ const result = await send(dubhe, `init_user_storage (${who})`, (tx) => {
90
+ tx.moveCall({
91
+ target: `${PackageId}::user_storage_init::init_user_storage`,
92
+ arguments: [tx.object(DappHubId), tx.object(DappStorageId)]
93
+ });
94
+ });
95
+ const usId = (result.objectChanges ?? []).find(
96
+ (c: any) => c.type === 'created' && c.objectType?.endsWith('::dapp_service::UserStorage')
97
+ )?.objectId;
98
+ if (!usId) throw new Error(`UserStorage not found in init tx for ${who}`);
99
+ userStorageIds[who] = usId;
100
+ }
101
+ const usA = userStorageIds['A'];
102
+ const usB = userStorageIds['B'];
103
+ console.log(` UserStorage A: ${usA}`);
104
+ console.log(` UserStorage B: ${usB}`);
105
+
106
+ for (const [who, dubhe, us] of [
107
+ ['A', A, usA],
108
+ ['B', B, usB]
109
+ ] as const) {
110
+ await send(dubhe, `register (${who})`, (tx) => {
111
+ tx.moveCall({
112
+ target: `${PackageId}::player_system::register`,
113
+ arguments: [tx.object(DappStorageId), tx.object(us)]
114
+ });
115
+ });
116
+ }
117
+
118
+ // ── 3. Read starter decks via the indexer (order: 3x Strike, Fireball, Shield)
119
+ console.log('\n[3] Starter decks (via indexer)');
120
+ const readDeck = async (addr: string): Promise<string[]> => {
121
+ for (let i = 0; i < 30; i++) {
122
+ const data = await gql(`{ decks { nodes { entityId cardIds } } }`);
123
+ const row = data.decks.nodes.find((n: any) => n.entityId === addr);
124
+ const ids = row?.cardIds;
125
+ if (Array.isArray(ids) && ids.length === 5) return ids.map(String);
126
+ if (typeof ids === 'string') {
127
+ const parsed = JSON.parse(ids);
128
+ if (Array.isArray(parsed) && parsed.length === 5) return parsed.map(String);
129
+ }
130
+ await new Promise((r) => setTimeout(r, 2000));
131
+ }
132
+ throw new Error(`deck for ${addr} not indexed in time`);
133
+ };
134
+ const deckA = await readDeck(addrA);
135
+ const deckB = await readDeck(addrB);
136
+ console.log(` Deck A: ${deckA.length} cards`);
137
+ console.log(` Deck B: ${deckB.length} cards`);
138
+
139
+ // ── 4. A challenges B ─────────────────────────────────────────────────────
140
+ console.log('\n[4] create_duel');
141
+ const createResult = await send(A, 'create_duel (A → B, stake 50)', (tx) => {
142
+ tx.moveCall({
143
+ target: `${PackageId}::duel_system::create_duel`,
144
+ arguments: [
145
+ tx.object(DappStorageId),
146
+ tx.object(usA),
147
+ tx.pure.address(addrB),
148
+ tx.pure.u64(STAKE),
149
+ tx.object(CLOCK)
150
+ ]
151
+ });
152
+ });
153
+ const created = (createResult.objectChanges ?? []).filter((c: any) => c.type === 'created');
154
+ const sceneId = created.find((c: any) => c.objectType?.includes('SceneStorage<'))?.objectId;
155
+ const permitId = created.find((c: any) => c.objectType?.includes('ScenePermit<'))?.objectId;
156
+ if (!sceneId || !permitId) throw new Error('scene/permit not found in object changes');
157
+ console.log(` Scene: ${sceneId}`);
158
+ console.log(` Permit: ${permitId}`);
159
+
160
+ // ── 5. B accepts ──────────────────────────────────────────────────────────
161
+ console.log('\n[5] accept_duel');
162
+ await send(B, 'accept_duel (B)', (tx) => {
163
+ tx.moveCall({
164
+ target: `${PackageId}::duel_system::accept_duel`,
165
+ arguments: [
166
+ tx.object(DappStorageId),
167
+ tx.object(usB),
168
+ tx.object(permitId),
169
+ tx.object(sceneId),
170
+ tx.object(CLOCK)
171
+ ]
172
+ });
173
+ });
174
+
175
+ // ── 6. Combat: A strike(12) → B strike(12) → A fireball(18) = KO ─────────
176
+ console.log('\n[6] Combat');
177
+ const attack = (dubhe: Dubhe, mine: string, theirs: string, cardId: string, label: string) =>
178
+ send(dubhe, label, (tx) => {
179
+ tx.moveCall({
180
+ target: `${PackageId}::duel_system::attack`,
181
+ arguments: [
182
+ tx.object(DappStorageId),
183
+ tx.object(mine),
184
+ tx.object(theirs),
185
+ tx.object(permitId),
186
+ tx.object(sceneId),
187
+ tx.pure.address(cardId),
188
+ tx.object(CLOCK)
189
+ ]
190
+ });
191
+ });
192
+ await attack(A, usA, usB, deckA[0], 'A strikes (12 dmg, B: 30→18)');
193
+ await attack(B, usB, usA, deckB[0], 'B strikes (12 dmg, A: 30→18)');
194
+ await attack(A, usA, usB, deckA[3], 'A fireballs (18 dmg, B: 18→0 KO)');
195
+
196
+ // ── 7. Settlement ─────────────────────────────────────────────────────────
197
+ console.log('\n[7] Settlement');
198
+ const arenaData = await gql(`{ dubheObjectStorages { nodes { objectId objectType } } }`);
199
+ const arenaId = arenaData.dubheObjectStorages.nodes.find((n: any) =>
200
+ n.objectType?.toLowerCase().includes('arena')
201
+ )?.objectId;
202
+ if (!arenaId) throw new Error('arena object not found via GraphQL');
203
+ console.log(` Arena: ${arenaId}`);
204
+
205
+ await send(A, 'finish_duel (A collects pot, 3% rake)', (tx) => {
206
+ tx.moveCall({
207
+ target: `${PackageId}::duel_system::finish_duel`,
208
+ arguments: [
209
+ tx.object(DappStorageId),
210
+ tx.object(usA),
211
+ tx.object(permitId),
212
+ tx.object(sceneId),
213
+ tx.object(arenaId)
214
+ ]
215
+ });
216
+ });
217
+ await send(B, 'leave_duel (B)', (tx) => {
218
+ tx.moveCall({
219
+ target: `${PackageId}::duel_system::leave_duel`,
220
+ arguments: [tx.object(permitId), tx.object(sceneId), tx.object(usB)]
221
+ });
222
+ });
223
+ await send(A, 'cleanup_duel (destroy scene + permit)', (tx) => {
224
+ tx.moveCall({
225
+ target: `${PackageId}::duel_system::cleanup_duel`,
226
+ arguments: [tx.object(sceneId), tx.object(permitId)]
227
+ });
228
+ });
229
+
230
+ // ── 8. Verify results via the indexer ─────────────────────────────────────
231
+ console.log('\n[8] Verify (waiting for indexer)');
232
+ let goldA = 0n;
233
+ let goldB = 0n;
234
+ let profA: any = {};
235
+ let profB: any = {};
236
+ for (let i = 0; i < 30; i++) {
237
+ const data = await gql(
238
+ `{ golds { nodes { entityId amount } } profiles { nodes { entityId wins losses rating } } }`
239
+ );
240
+ goldA = BigInt(data.golds.nodes.find((n: any) => n.entityId === addrA)?.amount ?? 0);
241
+ goldB = BigInt(data.golds.nodes.find((n: any) => n.entityId === addrB)?.amount ?? 0);
242
+ profA = data.profiles.nodes.find((n: any) => n.entityId === addrA) ?? {};
243
+ profB = data.profiles.nodes.find((n: any) => n.entityId === addrB) ?? {};
244
+ if (goldA === 547n && Number(profA.wins) === 1) break;
245
+ await new Promise((r) => setTimeout(r, 2000));
246
+ }
247
+ console.log(` A gold=${goldA} profile=${JSON.stringify(profA)}`);
248
+ console.log(` B gold=${goldB} profile=${JSON.stringify(profB)}`);
249
+
250
+ // pot=100, rake=3, winner nets +47, loser -50
251
+ if (goldA !== 547n) throw new Error(`A gold expected 547, got ${goldA}`);
252
+ if (goldB !== 450n) throw new Error(`B gold expected 450, got ${goldB}`);
253
+ if (Number(profA.wins) !== 1 || Number(profA.rating) !== 1225)
254
+ throw new Error(`A profile wrong: ${JSON.stringify(profA)}`);
255
+ if (Number(profB.losses) !== 1 || Number(profB.rating) !== 1175)
256
+ throw new Error(`B profile wrong: ${JSON.stringify(profB)}`);
257
+
258
+ // ── 9. Verify scene lifecycle in the indexer ──────────────────────────────
259
+ console.log('\n[9] Scene row');
260
+ const idx = await gql(`{ dubheSceneStorages { nodes { sceneId sceneType isDestroyed } } }`);
261
+ const sceneRow = idx.dubheSceneStorages.nodes.find((n: any) => n.sceneId === sceneId);
262
+ console.log(` Scene row: ${JSON.stringify(sceneRow)}`);
263
+ if (!sceneRow) throw new Error('scene not indexed');
264
+ if (!sceneRow.isDestroyed) throw new Error('scene should be marked destroyed after cleanup');
265
+
266
+ console.log('\n✅ E2E duel flow passed!');
267
+ }
268
+
269
+ main().catch((err) => {
270
+ console.error(err);
271
+ process.exit(1);
272
+ });