movehat 0.0.1-alpha.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 (170) hide show
  1. package/README.md +236 -0
  2. package/bin/movehat.js +21 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +93 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/compile.d.ts +2 -0
  8. package/dist/commands/compile.d.ts.map +1 -0
  9. package/dist/commands/compile.js +71 -0
  10. package/dist/commands/compile.js.map +1 -0
  11. package/dist/commands/fork/create.d.ts +11 -0
  12. package/dist/commands/fork/create.d.ts.map +1 -0
  13. package/dist/commands/fork/create.js +56 -0
  14. package/dist/commands/fork/create.js.map +1 -0
  15. package/dist/commands/fork/fund.d.ts +12 -0
  16. package/dist/commands/fork/fund.d.ts.map +1 -0
  17. package/dist/commands/fork/fund.js +42 -0
  18. package/dist/commands/fork/fund.js.map +1 -0
  19. package/dist/commands/fork/list.d.ts +5 -0
  20. package/dist/commands/fork/list.d.ts.map +1 -0
  21. package/dist/commands/fork/list.js +61 -0
  22. package/dist/commands/fork/list.js.map +1 -0
  23. package/dist/commands/fork/serve.d.ts +10 -0
  24. package/dist/commands/fork/serve.d.ts.map +1 -0
  25. package/dist/commands/fork/serve.js +64 -0
  26. package/dist/commands/fork/serve.js.map +1 -0
  27. package/dist/commands/fork/view-resource.d.ts +11 -0
  28. package/dist/commands/fork/view-resource.d.ts.map +1 -0
  29. package/dist/commands/fork/view-resource.js +34 -0
  30. package/dist/commands/fork/view-resource.js.map +1 -0
  31. package/dist/commands/init.d.ts +2 -0
  32. package/dist/commands/init.d.ts.map +1 -0
  33. package/dist/commands/init.js +90 -0
  34. package/dist/commands/init.js.map +1 -0
  35. package/dist/commands/run.d.ts +2 -0
  36. package/dist/commands/run.d.ts.map +1 -0
  37. package/dist/commands/run.js +51 -0
  38. package/dist/commands/run.js.map +1 -0
  39. package/dist/commands/test.d.ts +2 -0
  40. package/dist/commands/test.d.ts.map +1 -0
  41. package/dist/commands/test.js +35 -0
  42. package/dist/commands/test.js.map +1 -0
  43. package/dist/core/config.d.ts +15 -0
  44. package/dist/core/config.d.ts.map +1 -0
  45. package/dist/core/config.js +121 -0
  46. package/dist/core/config.js.map +1 -0
  47. package/dist/core/contract.d.ts +20 -0
  48. package/dist/core/contract.d.ts.map +1 -0
  49. package/dist/core/contract.js +59 -0
  50. package/dist/core/contract.js.map +1 -0
  51. package/dist/core/deployments.d.ts +32 -0
  52. package/dist/core/deployments.d.ts.map +1 -0
  53. package/dist/core/deployments.js +122 -0
  54. package/dist/core/deployments.js.map +1 -0
  55. package/dist/core/shell.d.ts +25 -0
  56. package/dist/core/shell.d.ts.map +1 -0
  57. package/dist/core/shell.js +56 -0
  58. package/dist/core/shell.js.map +1 -0
  59. package/dist/errors.d.ts +12 -0
  60. package/dist/errors.d.ts.map +1 -0
  61. package/dist/errors.js +24 -0
  62. package/dist/errors.js.map +1 -0
  63. package/dist/fork/api.d.ts +33 -0
  64. package/dist/fork/api.d.ts.map +1 -0
  65. package/dist/fork/api.js +98 -0
  66. package/dist/fork/api.js.map +1 -0
  67. package/dist/fork/manager.d.ts +52 -0
  68. package/dist/fork/manager.d.ts.map +1 -0
  69. package/dist/fork/manager.js +221 -0
  70. package/dist/fork/manager.js.map +1 -0
  71. package/dist/fork/server.d.ts +55 -0
  72. package/dist/fork/server.d.ts.map +1 -0
  73. package/dist/fork/server.js +274 -0
  74. package/dist/fork/server.js.map +1 -0
  75. package/dist/fork/storage.d.ts +63 -0
  76. package/dist/fork/storage.d.ts.map +1 -0
  77. package/dist/fork/storage.js +183 -0
  78. package/dist/fork/storage.js.map +1 -0
  79. package/dist/fork/test.d.ts +75 -0
  80. package/dist/fork/test.d.ts.map +1 -0
  81. package/dist/fork/test.js +157 -0
  82. package/dist/fork/test.js.map +1 -0
  83. package/dist/helpers/assertions.d.ts +7 -0
  84. package/dist/helpers/assertions.d.ts.map +1 -0
  85. package/dist/helpers/assertions.js +17 -0
  86. package/dist/helpers/assertions.js.map +1 -0
  87. package/dist/helpers/banner.d.ts +3 -0
  88. package/dist/helpers/banner.d.ts.map +1 -0
  89. package/dist/helpers/banner.js +38 -0
  90. package/dist/helpers/banner.js.map +1 -0
  91. package/dist/helpers/index.d.ts +11 -0
  92. package/dist/helpers/index.d.ts.map +1 -0
  93. package/dist/helpers/index.js +7 -0
  94. package/dist/helpers/index.js.map +1 -0
  95. package/dist/helpers/setup.d.ts +10 -0
  96. package/dist/helpers/setup.d.ts.map +1 -0
  97. package/dist/helpers/setup.js +28 -0
  98. package/dist/helpers/setup.js.map +1 -0
  99. package/dist/index.d.ts +11 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +12 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/runtime.d.ts +26 -0
  104. package/dist/runtime.d.ts.map +1 -0
  105. package/dist/runtime.js +247 -0
  106. package/dist/runtime.js.map +1 -0
  107. package/dist/templates/.env.example +9 -0
  108. package/dist/templates/.mocharc.json +8 -0
  109. package/dist/templates/README.md +92 -0
  110. package/dist/templates/move/Counter.move +64 -0
  111. package/dist/templates/move/Move.toml +16 -0
  112. package/dist/templates/movehat.config.ts +37 -0
  113. package/dist/templates/package.json +24 -0
  114. package/dist/templates/scripts/deploy-counter.ts +48 -0
  115. package/dist/templates/tests/Counter.test.ts +75 -0
  116. package/dist/templates/tsconfig.json +15 -0
  117. package/dist/templates/types/movehat.d.ts +104 -0
  118. package/dist/types/config.d.ts +35 -0
  119. package/dist/types/config.d.ts.map +1 -0
  120. package/dist/types/config.js +2 -0
  121. package/dist/types/config.js.map +1 -0
  122. package/dist/types/fork.d.ts +37 -0
  123. package/dist/types/fork.d.ts.map +1 -0
  124. package/dist/types/fork.js +5 -0
  125. package/dist/types/fork.js.map +1 -0
  126. package/dist/types/runtime.d.ts +28 -0
  127. package/dist/types/runtime.d.ts.map +1 -0
  128. package/dist/types/runtime.js +2 -0
  129. package/dist/types/runtime.js.map +1 -0
  130. package/package.json +66 -0
  131. package/src/cli.ts +106 -0
  132. package/src/commands/compile.ts +84 -0
  133. package/src/commands/fork/create.ts +70 -0
  134. package/src/commands/fork/fund.ts +57 -0
  135. package/src/commands/fork/list.ts +67 -0
  136. package/src/commands/fork/serve.ts +77 -0
  137. package/src/commands/fork/view-resource.ts +46 -0
  138. package/src/commands/init.ts +150 -0
  139. package/src/commands/run.ts +59 -0
  140. package/src/commands/test.ts +42 -0
  141. package/src/core/config.ts +151 -0
  142. package/src/core/contract.ts +97 -0
  143. package/src/core/deployments.ts +164 -0
  144. package/src/core/shell.ts +66 -0
  145. package/src/errors.ts +21 -0
  146. package/src/fork/api.ts +117 -0
  147. package/src/fork/manager.ts +264 -0
  148. package/src/fork/server.ts +311 -0
  149. package/src/fork/storage.ts +224 -0
  150. package/src/fork/test.ts +195 -0
  151. package/src/helpers/assertions.ts +29 -0
  152. package/src/helpers/banner.ts +47 -0
  153. package/src/helpers/index.ts +26 -0
  154. package/src/helpers/setup.ts +49 -0
  155. package/src/index.ts +17 -0
  156. package/src/runtime.ts +322 -0
  157. package/src/templates/.env.example +9 -0
  158. package/src/templates/.mocharc.json +8 -0
  159. package/src/templates/README.md +92 -0
  160. package/src/templates/move/Counter.move +64 -0
  161. package/src/templates/move/Move.toml +16 -0
  162. package/src/templates/movehat.config.ts +37 -0
  163. package/src/templates/package.json +24 -0
  164. package/src/templates/scripts/deploy-counter.ts +48 -0
  165. package/src/templates/tests/Counter.test.ts +75 -0
  166. package/src/templates/tsconfig.json +15 -0
  167. package/src/templates/types/movehat.d.ts +104 -0
  168. package/src/types/config.ts +36 -0
  169. package/src/types/fork.ts +41 -0
  170. package/src/types/runtime.ts +49 -0
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "strict": true,
10
+ "resolveJsonModule": true,
11
+ "outDir": "./dist"
12
+ },
13
+ "include": ["tests/**/*", "scripts/**/*", "movehat.config.ts"],
14
+ "exclude": ["node_modules", "dist", "move"]
15
+ }
@@ -0,0 +1,104 @@
1
+ // Type declarations for movehat package
2
+ // This file is only for IDE support during template development
3
+ // It will NOT be copied to user projects
4
+
5
+ declare module 'movehat' {
6
+ import { Aptos, Account } from '@aptos-labs/ts-sdk';
7
+
8
+ export interface NetworkInfo {
9
+ name: string;
10
+ rpc: string;
11
+ chainId?: string;
12
+ }
13
+
14
+ export interface MovehatConfig {
15
+ network: string;
16
+ rpc: string;
17
+ privateKey: string;
18
+ profile: string;
19
+ moveDir: string;
20
+ account: string;
21
+ namedAddresses?: Record<string, string>;
22
+ }
23
+
24
+ export interface DeploymentInfo {
25
+ address: string;
26
+ moduleName: string;
27
+ network: string;
28
+ deployer: string;
29
+ timestamp: number;
30
+ txHash?: string;
31
+ blockNumber?: string;
32
+ }
33
+
34
+ export interface MovehatRuntime {
35
+ config: MovehatConfig;
36
+ network: NetworkInfo;
37
+ aptos: Aptos;
38
+ account: Account;
39
+ accounts: Account[];
40
+ getContract: (address: string, moduleName: string) => any;
41
+ deployContract: (
42
+ moduleName: string,
43
+ options?: {
44
+ packageDir?: string;
45
+ }
46
+ ) => Promise<DeploymentInfo>;
47
+ getDeployment: (moduleName: string) => DeploymentInfo | null;
48
+ getDeployments: () => Record<string, DeploymentInfo>;
49
+ getDeploymentAddress: (moduleName: string) => string | null;
50
+ createAccount: () => Account;
51
+ getAccount: (privateKey: string) => Account;
52
+ getAccountByIndex: (index: number) => Account;
53
+ switchNetwork: (networkName: string) => Promise<void>;
54
+ }
55
+
56
+ export function getMovehat(): Promise<MovehatRuntime>;
57
+ export function initRuntime(configOverride?: Partial<MovehatConfig>): Promise<MovehatRuntime>;
58
+ export function getRuntime(): MovehatRuntime;
59
+
60
+ export const mh: {
61
+ readonly runtime: MovehatRuntime;
62
+ };
63
+ }
64
+
65
+ declare module 'movehat/helpers' {
66
+ import { Account, Aptos } from '@aptos-labs/ts-sdk';
67
+
68
+ export interface TestEnvironment {
69
+ aptos: Aptos;
70
+ account: Account;
71
+ config: any;
72
+ }
73
+
74
+ export class MoveContract {
75
+ constructor(aptos: Aptos, address: string, moduleName: string);
76
+ call(sender: Account, functionName: string, args: any[]): Promise<any>;
77
+ view<T>(functionName: string, args: any[]): Promise<T>;
78
+ }
79
+
80
+ export interface TransactionResult {
81
+ hash: string;
82
+ success: boolean;
83
+ }
84
+
85
+ export interface DeploymentInfo {
86
+ address: string;
87
+ moduleName: string;
88
+ network: string;
89
+ deployer: string;
90
+ timestamp: number;
91
+ txHash?: string;
92
+ blockNumber?: string;
93
+ }
94
+
95
+ export function setupTestEnvironment(): Promise<TestEnvironment>;
96
+ export function createTestAccount(): Account;
97
+ export function getContract(aptos: Aptos, address: string, moduleName: string): MoveContract;
98
+ export function assertTransactionSuccess(result: TransactionResult): void;
99
+ export function assertTransactionFailed(result: TransactionResult): void;
100
+ export function saveDeployment(deployment: DeploymentInfo): void;
101
+ export function loadDeployment(network: string, moduleName: string): DeploymentInfo | null;
102
+ export function getAllDeployments(network: string): Record<string, DeploymentInfo>;
103
+ export function getDeployedAddress(network: string, moduleName: string): string | null;
104
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Configuration for a single network
3
+ */
4
+ export interface NetworkConfig {
5
+ url: string;
6
+ accounts?: string[];
7
+ chainId?: string;
8
+ profile?: string;
9
+ namedAddresses?: Record<string, string>;
10
+ }
11
+ /**
12
+ * User configuration (what users write in movehat.config.ts)
13
+ */
14
+ export interface MovehatUserConfig {
15
+ defaultNetwork?: string;
16
+ networks: Record<string, NetworkConfig>;
17
+ accounts?: string[];
18
+ moveDir?: string;
19
+ namedAddresses?: Record<string, string>;
20
+ }
21
+ /**
22
+ * Resolved configuration (internal use - what runtime uses)
23
+ */
24
+ export interface MovehatConfig {
25
+ network: string;
26
+ rpc: string;
27
+ privateKey: string;
28
+ allAccounts: string[];
29
+ profile: string;
30
+ moveDir: string;
31
+ account: string;
32
+ namedAddresses: Record<string, string>;
33
+ networkConfig: NetworkConfig;
34
+ }
35
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Fork system types for MoveHat
3
+ */
4
+ export interface ForkMetadata {
5
+ network: string;
6
+ nodeUrl: string;
7
+ chainId: number;
8
+ ledgerVersion: string;
9
+ timestamp: string;
10
+ epoch: string;
11
+ blockHeight: string;
12
+ createdAt: string;
13
+ }
14
+ export interface AccountState {
15
+ sequenceNumber: string;
16
+ authenticationKey: string;
17
+ }
18
+ export interface LedgerInfo {
19
+ chain_id: number;
20
+ epoch: string;
21
+ ledger_version: string;
22
+ oldest_ledger_version: string;
23
+ ledger_timestamp: string;
24
+ node_role: string;
25
+ oldest_block_height: string;
26
+ block_height: string;
27
+ git_hash?: string;
28
+ }
29
+ export interface AccountData {
30
+ sequence_number: string;
31
+ authentication_key: string;
32
+ }
33
+ export interface AccountResource {
34
+ type: string;
35
+ data: any;
36
+ }
37
+ //# sourceMappingURL=fork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fork.d.ts","sourceRoot":"","sources":["../../src/types/fork.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;CACX"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Fork system types for MoveHat
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=fork.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fork.js","sourceRoot":"","sources":["../../src/types/fork.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,28 @@
1
+ import { Aptos, Account } from "@aptos-labs/ts-sdk";
2
+ import { MovehatConfig } from "./config.js";
3
+ import { MoveContract } from "../core/contract.js";
4
+ import { DeploymentInfo } from "../core/deployments.js";
5
+ export interface NetworkInfo {
6
+ name: string;
7
+ rpc: string;
8
+ chainId?: string;
9
+ }
10
+ export interface MovehatRuntime {
11
+ config: MovehatConfig;
12
+ network: NetworkInfo;
13
+ aptos: Aptos;
14
+ account: Account;
15
+ accounts: Account[];
16
+ getContract: (address: string, moduleName: string) => MoveContract;
17
+ deployContract: (moduleName: string, options?: {
18
+ packageDir?: string;
19
+ }) => Promise<DeploymentInfo>;
20
+ getDeployment: (moduleName: string) => DeploymentInfo | null;
21
+ getDeployments: () => Record<string, DeploymentInfo>;
22
+ getDeploymentAddress: (moduleName: string) => string | null;
23
+ createAccount: () => Account;
24
+ getAccount: (privateKey: string) => Account;
25
+ getAccountByIndex: (index: number) => Account;
26
+ switchNetwork: (networkName: string) => Promise<void>;
27
+ }
28
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/types/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAE7B,MAAM,EAAE,aAAa,CAAC;IAGtB,OAAO,EAAE,WAAW,CAAC;IAGrB,KAAK,EAAE,KAAK,CAAC;IAGb,OAAO,EAAE,OAAO,CAAC;IAGjB,QAAQ,EAAE,OAAO,EAAE,CAAC;IAGpB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,YAAY,CAAC;IAGnE,cAAc,EAAE,CACd,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,KACE,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7B,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,cAAc,GAAG,IAAI,CAAC;IAC7D,cAAc,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACrD,oBAAoB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAG5D,aAAa,EAAE,MAAM,OAAO,CAAC;IAC7B,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAG9C,aAAa,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/types/runtime.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "movehat",
3
+ "version": "0.0.1-alpha.0",
4
+ "type": "module",
5
+ "description": "Hardhat-like development framework for Movement L1 and Aptos Move smart contracts",
6
+ "bin": {
7
+ "movehat": "./bin/movehat.js"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./helpers": {
15
+ "types": "./dist/helpers/index.d.ts",
16
+ "import": "./dist/helpers/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "tsc && npm run copy-templates",
21
+ "copy-templates": "cp -r src/templates dist/",
22
+ "dev": "tsc --watch",
23
+ "clean": "rm -rf dist",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src",
29
+ "bin"
30
+ ],
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/gilbertsahumada/movehat.git"
34
+ },
35
+ "homepage": "https://github.com/gilbertsahumada/movehat#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/gilbertsahumada/movehat/issues"
38
+ },
39
+ "keywords": [
40
+ "move",
41
+ "aptos",
42
+ "movement",
43
+ "blockchain",
44
+ "smart-contracts",
45
+ "hardhat",
46
+ "framework",
47
+ "web3",
48
+ "dapp"
49
+ ],
50
+ "author": "Gilberts Ahumada",
51
+ "license": "MIT",
52
+ "dependencies": {
53
+ "@aptos-labs/ts-sdk": "^5.1.5",
54
+ "commander": "^14.0.2",
55
+ "dotenv": "^17.2.3",
56
+ "js-yaml": "^4.1.1",
57
+ "prompts": "^2.4.2",
58
+ "tsx": "^4.7.0"
59
+ },
60
+ "devDependencies": {
61
+ "@types/js-yaml": "^4.0.9",
62
+ "@types/node": "^24.10.1",
63
+ "@types/prompts": "^2.4.9",
64
+ "typescript": "^5.9.3"
65
+ }
66
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ import { Command, InvalidOptionArgumentError } from 'commander';
3
+ import testCommand from './commands/test.js';
4
+ import compileCommand from './commands/compile.js';
5
+ import initCommand from './commands/init.js';
6
+ import runCommand from './commands/run.js';
7
+ import forkCreateCommand from './commands/fork/create.js';
8
+ import forkViewResourceCommand from './commands/fork/view-resource.js';
9
+ import forkFundCommand from './commands/fork/fund.js';
10
+ import forkListCommand from './commands/fork/list.js';
11
+ import forkServeCommand from './commands/fork/serve.js';
12
+
13
+ /**
14
+ * Parse and validate port number
15
+ */
16
+ function parsePort(value: string): number {
17
+ const port = Number.parseInt(value, 10);
18
+ if (isNaN(port) || port < 1 || port > 65535) {
19
+ throw new InvalidOptionArgumentError('Port must be an integer between 1 and 65535');
20
+ }
21
+ return port;
22
+ }
23
+
24
+ const program = new Command();
25
+
26
+ program
27
+ .name('movehat')
28
+ .description('A CLI tool for managing Move smart contracts')
29
+ .version('0.0.1')
30
+ .option('--network <name>', 'Network to use (testnet, mainnet, local, etc.)')
31
+ .option('--redeploy', 'Force redeploy even if already deployed')
32
+ .hook('preAction', (thisCommand) => {
33
+ // Store network option in environment for commands to access
34
+ const options = thisCommand.opts();
35
+ if (options.network) {
36
+ process.env.MH_CLI_NETWORK = options.network;
37
+ }
38
+ if (options.redeploy) {
39
+ process.env.MH_CLI_REDEPLOY = 'true';
40
+ }
41
+ });
42
+
43
+ program
44
+ .command('init [project-name]')
45
+ .description('Initialize a new Move project in the current directory')
46
+ .action((projectName) => {
47
+ initCommand(projectName);
48
+ });
49
+
50
+ program
51
+ .command('compile')
52
+ .description('Compile Move smart contracts using Movement CLI')
53
+ .action(compileCommand);
54
+
55
+ program
56
+ .command('run <script>')
57
+ .description('Run a TypeScript/JavaScript script (e.g., deployment script)')
58
+ .action(runCommand);
59
+
60
+ program
61
+ .command('test')
62
+ .description('Run TypeScript tests with Mocha')
63
+ .action(testCommand);
64
+
65
+ // Fork commands
66
+ const fork = program
67
+ .command('fork')
68
+ .description('Manage local forks of Movement/Aptos networks');
69
+
70
+ fork
71
+ .command('create')
72
+ .description('Create a new fork from a network')
73
+ .option('-n, --name <name>', 'Name for the fork')
74
+ .option('-p, --path <path>', 'Custom path for the fork')
75
+ .action((options) => forkCreateCommand(options));
76
+
77
+ fork
78
+ .command('view-resource')
79
+ .description('View a resource from the fork')
80
+ .option('-f, --fork <path>', 'Path to the fork')
81
+ .requiredOption('-a, --account <address>', 'Account address')
82
+ .requiredOption('-r, --resource <type>', 'Resource type')
83
+ .action((options) => forkViewResourceCommand(options));
84
+
85
+ fork
86
+ .command('fund')
87
+ .description('Fund an account in the fork')
88
+ .option('-f, --fork <path>', 'Path to the fork')
89
+ .requiredOption('-a, --account <address>', 'Account address')
90
+ .requiredOption('--amount <amount>', 'Amount to fund')
91
+ .option('--coin-type <type>', 'Coin type', '0x1::aptos_coin::AptosCoin')
92
+ .action((options) => forkFundCommand(options));
93
+
94
+ fork
95
+ .command('list')
96
+ .description('List all available forks')
97
+ .action(() => forkListCommand());
98
+
99
+ fork
100
+ .command('serve')
101
+ .description('Start a local RPC server serving the fork')
102
+ .option('-f, --fork <path>', 'Path to the fork')
103
+ .option('-p, --port <port>', 'Port to listen on (default: 8080)', parsePort, 8080)
104
+ .action((options) => forkServeCommand(options));
105
+
106
+ program.parse(process.argv);
@@ -0,0 +1,84 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { exec } from "child_process";
4
+ import { loadUserConfig } from "../core/config.js";
5
+ import { validateAndEscapePath, escapeShellArg } from "../core/shell.js";
6
+
7
+ function run(command: string, cwd: string) {
8
+ return new Promise<void>((resolve, reject) => {
9
+ exec(command, { cwd }, (error, stdout, stderr) => {
10
+ if (stdout) console.log(stdout.trim());
11
+ if (stderr) console.error(stderr.trim());
12
+ if (error) {
13
+ reject(error);
14
+ return;
15
+ }
16
+ resolve();
17
+ });
18
+ });
19
+ }
20
+
21
+ export default async function compileCommand() {
22
+ try {
23
+ // Compile is network-independent - only uses global config
24
+ const userConfig = await loadUserConfig();
25
+
26
+ console.log("šŸ“¦ Compiling Move contracts (network-independent)...");
27
+
28
+ const moveDir = path.resolve(process.cwd(), userConfig.moveDir || "./move");
29
+ if (!fs.existsSync(moveDir)) {
30
+ console.error(`āŒ Move directory not found: ${moveDir}`);
31
+ console.error(` Update movehat.config.ts -> moveDir`);
32
+ return;
33
+ }
34
+
35
+ // Validate and escape to prevent command injection
36
+ const safeMoveDir = validateAndEscapePath(moveDir, "Move directory");
37
+
38
+ // Use global named addresses for compilation
39
+ const namedAddresses = userConfig.namedAddresses ?? {};
40
+ let namedAddressesArg = "";
41
+
42
+ if (Object.keys(namedAddresses).length > 0) {
43
+ // Validate and escape each address name and value
44
+ const escapedAddresses = Object.entries(namedAddresses)
45
+ .map(([k, v]) => {
46
+ // Validate address name (alphanumeric, underscore only)
47
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)) {
48
+ throw new Error(
49
+ `Invalid named address "${k}". ` +
50
+ `Names must start with a letter or underscore and contain only alphanumeric characters and underscores.`
51
+ );
52
+ }
53
+
54
+ // Validate address value (should be hex address)
55
+ if (!/^0x[a-fA-F0-9]+$/.test(v)) {
56
+ throw new Error(
57
+ `Invalid address value for "${k}": "${v}". ` +
58
+ `Address values must be hex strings starting with "0x".`
59
+ );
60
+ }
61
+
62
+ // No need to escape since we validated the format
63
+ return `${k}=${v}`;
64
+ })
65
+ .join(",");
66
+
67
+ namedAddressesArg = `--named-addresses ${escapeShellArg(escapedAddresses)}`;
68
+ }
69
+
70
+ const command = `movement move build --package-dir ${safeMoveDir} ${namedAddressesArg}`.trim();
71
+
72
+ console.log(` Move directory: ${moveDir}`);
73
+ if (Object.keys(namedAddresses).length > 0) {
74
+ console.log(` Named addresses: ${Object.keys(namedAddresses).join(", ")}`);
75
+ }
76
+ console.log();
77
+
78
+ await run(command, moveDir);
79
+ console.log("āœ… Compilation finished successfully.");
80
+ } catch (err: any) {
81
+ console.error("āŒ Compilation failed:", err.message ?? err);
82
+ process.exit(1);
83
+ }
84
+ }
@@ -0,0 +1,70 @@
1
+ import { join } from 'path';
2
+ import { existsSync } from 'fs';
3
+ import prompts from 'prompts';
4
+ import { loadUserConfig, resolveNetworkConfig } from '../../core/config.js';
5
+ import { ForkManager } from '../../fork/manager.js';
6
+
7
+ interface ForkCreateOptions {
8
+ network?: string;
9
+ path?: string;
10
+ name?: string;
11
+ }
12
+
13
+ /**
14
+ * Fork create command: Create a local fork of a Movement/Aptos network
15
+ */
16
+ export default async function forkCreateCommand(options: ForkCreateOptions = {}) {
17
+ try {
18
+ // Load MoveHat config
19
+ const userConfig = await loadUserConfig();
20
+ const networkName = options.network || process.env.MH_CLI_NETWORK || userConfig.defaultNetwork || 'testnet';
21
+ const networkConfig = await resolveNetworkConfig(userConfig, networkName);
22
+
23
+ // Determine fork name and path
24
+ const forkName = options.name || `${networkName}-fork`;
25
+ const forkPath = options.path || join(process.cwd(), '.movehat', 'forks', forkName);
26
+
27
+ console.log(`\nšŸ“¦ Creating fork of ${networkName}`);
28
+ console.log(` Network: ${networkConfig.rpc}`);
29
+ console.log(` Fork path: ${forkPath}`);
30
+
31
+ // Check if fork already exists
32
+ if (existsSync(forkPath)) {
33
+ const { overwrite } = await prompts({
34
+ type: 'confirm',
35
+ name: 'overwrite',
36
+ message: `Fork already exists at ${forkPath}. Overwrite?`,
37
+ initial: false,
38
+ });
39
+
40
+ if (!overwrite) {
41
+ console.log('āŒ Fork creation cancelled');
42
+ return;
43
+ }
44
+ }
45
+
46
+ // Create fork manager
47
+ const forkManager = new ForkManager(forkPath);
48
+
49
+ // Initialize fork
50
+ console.log(`\nāš™ļø Initializing fork...`);
51
+ await forkManager.initialize(networkConfig.rpc, networkName);
52
+
53
+ const metadata = forkManager.getMetadata();
54
+
55
+ console.log(`\nāœ… Fork created successfully!\n`);
56
+ console.log(`Fork Details:`);
57
+ console.log(` Chain ID: ${metadata.chainId}`);
58
+ console.log(` Ledger Version: ${metadata.ledgerVersion}`);
59
+ console.log(` Block Height: ${metadata.blockHeight}`);
60
+ console.log(` Epoch: ${metadata.epoch}`);
61
+ console.log(`\nUsage:`);
62
+ console.log(` movehat fork view-resource --fork ${forkPath} --account <ADDRESS> --resource <TYPE>`);
63
+ console.log(` movehat fork fund --fork ${forkPath} --account <ADDRESS> --amount <AMOUNT>`);
64
+ console.log(` movehat fork list\n`);
65
+
66
+ } catch (error: any) {
67
+ console.error(`\nāŒ Error: ${error.message}\n`);
68
+ process.exit(1);
69
+ }
70
+ }
@@ -0,0 +1,57 @@
1
+ import { join } from 'path';
2
+ import { ForkManager } from '../../fork/manager.js';
3
+
4
+ interface ForkFundOptions {
5
+ fork?: string;
6
+ account: string;
7
+ amount: string;
8
+ coinType?: string;
9
+ }
10
+
11
+ /**
12
+ * Fork fund command: Fund an account in the fork
13
+ */
14
+ export default async function forkFundCommand(options: ForkFundOptions) {
15
+ try {
16
+ if (!options.account) {
17
+ throw new Error('--account is required');
18
+ }
19
+
20
+ if (!options.amount) {
21
+ throw new Error('--amount is required');
22
+ }
23
+
24
+ const amount = parseInt(options.amount, 10);
25
+ if (isNaN(amount) || amount <= 0) {
26
+ throw new Error('--amount must be a positive number');
27
+ }
28
+
29
+ // Determine fork path
30
+ const forkPath = options.fork || join(process.cwd(), '.movehat', 'forks', 'testnet-fork');
31
+ const coinType = options.coinType || '0x1::aptos_coin::AptosCoin';
32
+
33
+ console.log(`\nšŸ’° Funding account in fork`);
34
+ console.log(` Fork: ${forkPath}`);
35
+ console.log(` Account: ${options.account}`);
36
+ console.log(` Amount: ${amount}`);
37
+ console.log(` Coin Type: ${coinType}\n`);
38
+
39
+ // Load fork
40
+ const forkManager = new ForkManager(forkPath);
41
+ forkManager.load();
42
+
43
+ // Fund account
44
+ await forkManager.fundAccount(options.account, amount, coinType);
45
+
46
+ // Verify
47
+ const resourceType = `0x1::coin::CoinStore<${coinType}>`;
48
+ const coinStore = await forkManager.getResource(options.account, resourceType);
49
+
50
+ console.log(`\nāœ… Account funded successfully!`);
51
+ console.log(` New balance: ${coinStore.coin.value}\n`);
52
+
53
+ } catch (error: any) {
54
+ console.error(`\nāŒ Error: ${error.message}\n`);
55
+ process.exit(1);
56
+ }
57
+ }