safehands-pharos 1.2.6 → 1.4.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 (153) hide show
  1. package/.env.example +64 -26
  2. package/README.md +333 -445
  3. package/dist/cli.d.ts +5 -5
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +124 -98
  6. package/dist/cli.js.map +1 -1
  7. package/dist/demo.d.ts +1 -1
  8. package/dist/demo.js +171 -171
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +138 -87
  11. package/dist/index.js.map +1 -1
  12. package/dist/init.d.ts +1 -1
  13. package/dist/init.js +65 -65
  14. package/dist/lib/auditLog.d.ts +9 -0
  15. package/dist/lib/auditLog.d.ts.map +1 -0
  16. package/dist/lib/auditLog.js +30 -0
  17. package/dist/lib/auditLog.js.map +1 -0
  18. package/dist/lib/constants.d.ts +291 -291
  19. package/dist/lib/constants.js +292 -292
  20. package/dist/lib/dodoApi.d.ts +78 -70
  21. package/dist/lib/dodoApi.d.ts.map +1 -1
  22. package/dist/lib/dodoApi.js +196 -178
  23. package/dist/lib/dodoApi.js.map +1 -1
  24. package/dist/lib/http.d.ts +14 -14
  25. package/dist/lib/http.js +118 -118
  26. package/dist/lib/pharosClient.d.ts +58 -58
  27. package/dist/lib/pharosClient.d.ts.map +1 -1
  28. package/dist/lib/pharosClient.js +63 -53
  29. package/dist/lib/pharosClient.js.map +1 -1
  30. package/dist/lib/policy/actionPolicyEngine.d.ts +53 -53
  31. package/dist/lib/policy/actionPolicyEngine.js +212 -212
  32. package/dist/lib/policy/actionPolicyEngine.js.map +1 -1
  33. package/dist/lib/riskEngine.d.ts +26 -26
  34. package/dist/lib/riskEngine.js +283 -283
  35. package/dist/lib/signer/index.d.ts +24 -24
  36. package/dist/lib/signer/index.d.ts.map +1 -1
  37. package/dist/lib/signer/index.js +88 -89
  38. package/dist/lib/signer/index.js.map +1 -1
  39. package/dist/lib/spendAccumulator.d.ts +10 -0
  40. package/dist/lib/spendAccumulator.d.ts.map +1 -0
  41. package/dist/lib/spendAccumulator.js +54 -0
  42. package/dist/lib/spendAccumulator.js.map +1 -0
  43. package/dist/lib/testDodoLive.d.ts +1 -1
  44. package/dist/lib/testDodoLive.js +104 -104
  45. package/dist/lib/testLiveSafehands.d.ts +1 -1
  46. package/dist/lib/testLiveSafehands.js +92 -92
  47. package/dist/lib/testRpc.d.ts +1 -1
  48. package/dist/lib/testRpc.js +29 -29
  49. package/dist/lib/testRpcLive.d.ts +1 -1
  50. package/dist/lib/testRpcLive.js +88 -88
  51. package/dist/lib/testTools.d.ts +1 -1
  52. package/dist/lib/testTools.js +397 -397
  53. package/dist/lib/testX402Live.d.ts +1 -1
  54. package/dist/lib/testX402Live.js +159 -159
  55. package/dist/lib/toolResponse.d.ts +25 -25
  56. package/dist/lib/toolResponse.js +53 -53
  57. package/dist/lib/wallet/index.d.ts +37 -18
  58. package/dist/lib/wallet/index.d.ts.map +1 -1
  59. package/dist/lib/wallet/index.js +128 -70
  60. package/dist/lib/wallet/index.js.map +1 -1
  61. package/dist/scripts/checkDeploy.d.ts +1 -1
  62. package/dist/scripts/checkDeploy.js +24 -24
  63. package/dist/scripts/deployRegistry.d.ts +1 -1
  64. package/dist/scripts/deployRegistry.js +100 -100
  65. package/dist/scripts/testRegistry.d.ts +1 -1
  66. package/dist/scripts/testRegistry.js +43 -43
  67. package/dist/tools/approveToken.d.ts +45 -46
  68. package/dist/tools/approveToken.d.ts.map +1 -1
  69. package/dist/tools/approveToken.js +85 -83
  70. package/dist/tools/approveToken.js.map +1 -1
  71. package/dist/tools/assessRisk.d.ts +79 -79
  72. package/dist/tools/assessRisk.d.ts.map +1 -1
  73. package/dist/tools/assessRisk.js +104 -93
  74. package/dist/tools/assessRisk.js.map +1 -1
  75. package/dist/tools/checkAllowance.d.ts +43 -36
  76. package/dist/tools/checkAllowance.d.ts.map +1 -1
  77. package/dist/tools/checkAllowance.js +56 -42
  78. package/dist/tools/checkAllowance.js.map +1 -1
  79. package/dist/tools/checkTokenSecurity.d.ts +46 -46
  80. package/dist/tools/checkTokenSecurity.d.ts.map +1 -1
  81. package/dist/tools/checkTokenSecurity.js +95 -88
  82. package/dist/tools/checkTokenSecurity.js.map +1 -1
  83. package/dist/tools/createAgentWallet.d.ts +26 -26
  84. package/dist/tools/createAgentWallet.d.ts.map +1 -1
  85. package/dist/tools/createAgentWallet.js +58 -59
  86. package/dist/tools/createAgentWallet.js.map +1 -1
  87. package/dist/tools/estimateGas.d.ts +79 -79
  88. package/dist/tools/estimateGas.js +124 -124
  89. package/dist/tools/executeSwap.d.ts +61 -59
  90. package/dist/tools/executeSwap.d.ts.map +1 -1
  91. package/dist/tools/executeSwap.js +141 -129
  92. package/dist/tools/executeSwap.js.map +1 -1
  93. package/dist/tools/explainRisk.d.ts +29 -29
  94. package/dist/tools/explainRisk.js +32 -32
  95. package/dist/tools/getAgentWallet.d.ts +21 -21
  96. package/dist/tools/getAgentWallet.js +27 -27
  97. package/dist/tools/getAgentWalletBalance.d.ts +11 -11
  98. package/dist/tools/getAgentWalletBalance.js +70 -70
  99. package/dist/tools/getExecutionHistory.d.ts +49 -51
  100. package/dist/tools/getExecutionHistory.d.ts.map +1 -1
  101. package/dist/tools/getExecutionHistory.js +154 -93
  102. package/dist/tools/getExecutionHistory.js.map +1 -1
  103. package/dist/tools/getGasPrice.d.ts +43 -43
  104. package/dist/tools/getGasPrice.js +59 -59
  105. package/dist/tools/getPoolInfo.d.ts +75 -75
  106. package/dist/tools/getPoolInfo.js +137 -137
  107. package/dist/tools/getTokenPrice.d.ts +113 -113
  108. package/dist/tools/getTokenPrice.js +117 -117
  109. package/dist/tools/getTransactionStatus.d.ts +43 -57
  110. package/dist/tools/getTransactionStatus.d.ts.map +1 -1
  111. package/dist/tools/getTransactionStatus.js +59 -67
  112. package/dist/tools/getTransactionStatus.js.map +1 -1
  113. package/dist/tools/getWalletBalance.d.ts +68 -68
  114. package/dist/tools/getWalletBalance.js +87 -87
  115. package/dist/tools/publishRiskScore.d.ts +63 -63
  116. package/dist/tools/publishRiskScore.d.ts.map +1 -1
  117. package/dist/tools/publishRiskScore.js +88 -85
  118. package/dist/tools/publishRiskScore.js.map +1 -1
  119. package/dist/tools/queryRiskRegistry.d.ts +38 -48
  120. package/dist/tools/queryRiskRegistry.d.ts.map +1 -1
  121. package/dist/tools/queryRiskRegistry.js +55 -60
  122. package/dist/tools/queryRiskRegistry.js.map +1 -1
  123. package/dist/tools/safehandsPreflightCheck.d.ts +77 -77
  124. package/dist/tools/safehandsPreflightCheck.js +47 -47
  125. package/dist/tools/safehandsRiskReport.d.ts +81 -81
  126. package/dist/tools/safehandsRiskReport.js +28 -28
  127. package/dist/tools/safehandsSafeExecute.d.ts +20 -20
  128. package/dist/tools/safehandsSafeExecute.d.ts.map +1 -1
  129. package/dist/tools/safehandsSafeExecute.js +81 -75
  130. package/dist/tools/safehandsSafeExecute.js.map +1 -1
  131. package/dist/tools/safehandsWalletHealth.d.ts +14 -14
  132. package/dist/tools/safehandsWalletHealth.js +103 -103
  133. package/dist/tools/safehandsX402Preflight.d.ts +26 -26
  134. package/dist/tools/safehandsX402Preflight.js +65 -65
  135. package/dist/tools/sendPayment.d.ts +57 -58
  136. package/dist/tools/sendPayment.d.ts.map +1 -1
  137. package/dist/tools/sendPayment.js +117 -108
  138. package/dist/tools/sendPayment.js.map +1 -1
  139. package/dist/tools/simulateTransaction.d.ts +60 -81
  140. package/dist/tools/simulateTransaction.d.ts.map +1 -1
  141. package/dist/tools/simulateTransaction.js +83 -88
  142. package/dist/tools/simulateTransaction.js.map +1 -1
  143. package/dist/tools/tokenRegistryStatus.d.ts +26 -26
  144. package/dist/tools/tokenRegistryStatus.js +96 -96
  145. package/dist/tools/x402PayAndFetch.d.ts +81 -81
  146. package/dist/tools/x402PayAndFetch.d.ts.map +1 -1
  147. package/dist/tools/x402PayAndFetch.js +152 -149
  148. package/dist/tools/x402PayAndFetch.js.map +1 -1
  149. package/dist/x402Server.d.ts +1 -1
  150. package/dist/x402Server.js +252 -252
  151. package/examples/dashboard/index.html +337 -0
  152. package/package.json +83 -82
  153. package/skill/SKILL.md +133 -133
@@ -1,71 +1,129 @@
1
- // ─── WalletStore ────────────────────────────────────────────────────────
2
- // Abstraction for storing managed testnet agent wallets.
3
- // Private keys are XOR-obfuscated with encryption key before storage.
4
- // NOT mainnet-grade encryption testnet only.
5
- // ────────────────────────────────────────────────────────────────────────
6
- import { readFileSync, writeFileSync, existsSync } from "fs";
7
- // ─── In-Memory Store (tests + default) ─────────────────────────────────
8
- class InMemoryWalletStore {
9
- store = new Map();
10
- async get(agentId) {
11
- return this.store.get(agentId) ?? null;
12
- }
13
- async set(agentId, wallet) {
14
- this.store.set(agentId, wallet);
15
- }
16
- async has(agentId) {
17
- return this.store.has(agentId);
18
- }
19
- }
20
- // ─── File Store (local dev) ─────────────────────────────────────────────
21
- class FileWalletStore {
22
- path;
23
- data = {};
24
- constructor(path) {
25
- this.path = path;
26
- if (existsSync(path)) {
27
- try {
28
- this.data = JSON.parse(readFileSync(path, "utf-8"));
29
- }
30
- catch {
31
- this.data = {};
32
- }
33
- }
34
- }
35
- async get(agentId) {
36
- return this.data[agentId] ?? null;
37
- }
38
- async set(agentId, wallet) {
39
- this.data[agentId] = wallet;
40
- writeFileSync(this.path, JSON.stringify(this.data, null, 2));
41
- }
42
- async has(agentId) {
43
- return agentId in this.data;
44
- }
45
- }
46
- // ─── Key Obfuscation (testnet only) ────────────────────────────────────
47
- export function obfuscateKey(privateKey, encryptionKey) {
48
- const keyBytes = Buffer.from(encryptionKey.padEnd(32, "0").slice(0, 32));
49
- const pkBytes = Buffer.from(privateKey.replace("0x", ""), "hex");
50
- const result = Buffer.alloc(pkBytes.length);
51
- for (let i = 0; i < pkBytes.length; i++) {
52
- result[i] = pkBytes[i] ^ keyBytes[i % keyBytes.length];
53
- }
54
- return "0x" + result.toString("hex");
55
- }
56
- export function deobfuscateKey(obfuscated, encryptionKey) {
57
- return obfuscateKey(obfuscated, encryptionKey); // XOR is symmetric
58
- }
59
- // ─── Factory ────────────────────────────────────────────────────────────
60
- function createWalletStore() {
61
- const storePath = process.env.WALLET_STORE_PATH;
62
- if (storePath) {
63
- return new FileWalletStore(storePath);
64
- }
65
- return new InMemoryWalletStore();
66
- }
67
- export function usesPersistentWalletStore() {
68
- return Boolean(process.env.WALLET_STORE_PATH);
69
- }
70
- export const walletStore = createWalletStore();
1
+ // ─── WalletStore ────────────────────────────────────────────────────────
2
+ // Abstraction for storing managed testnet agent wallets.
3
+ // Private keys are AES-256-GCM encrypted before storage.
4
+ // Legacy XOR-obfuscated keys (starting with "0x") are transparently migrated
5
+ // on first read. NOT mainnet-grade KMS — testnet only.
6
+ // ────────────────────────────────────────────────────────────────────────
7
+ import { readFileSync, writeFileSync, renameSync, existsSync } from "fs";
8
+ import { randomBytes, createCipheriv, createDecipheriv, createHash } from "node:crypto";
9
+ // ─── In-Memory Store (tests + default) ─────────────────────────────────
10
+ class InMemoryWalletStore {
11
+ store = new Map();
12
+ async get(agentId) {
13
+ return this.store.get(agentId) ?? null;
14
+ }
15
+ async set(agentId, wallet) {
16
+ this.store.set(agentId, wallet);
17
+ }
18
+ async has(agentId) {
19
+ return this.store.has(agentId);
20
+ }
21
+ }
22
+ // ─── File Store (local dev) ─────────────────────────────────────────────
23
+ class FileWalletStore {
24
+ path;
25
+ data = {};
26
+ constructor(path) {
27
+ this.path = path;
28
+ if (existsSync(path)) {
29
+ try {
30
+ this.data = JSON.parse(readFileSync(path, "utf-8"));
31
+ }
32
+ catch {
33
+ this.data = {};
34
+ }
35
+ }
36
+ }
37
+ async get(agentId) {
38
+ return this.data[agentId] ?? null;
39
+ }
40
+ async set(agentId, wallet) {
41
+ this.data[agentId] = wallet;
42
+ // Atomic write: write to .tmp then rename to avoid corruption on crash
43
+ const tmpPath = `${this.path}.tmp`;
44
+ writeFileSync(tmpPath, JSON.stringify(this.data, null, 2), "utf-8");
45
+ renameSync(tmpPath, this.path);
46
+ }
47
+ async has(agentId) {
48
+ return agentId in this.data;
49
+ }
50
+ }
51
+ // ─── AES-256-GCM Encryption ────────────────────────────────────────────
52
+ function deriveKey(encryptionKey) {
53
+ return createHash("sha256").update(encryptionKey).digest();
54
+ }
55
+ /**
56
+ * Encrypts a private key with AES-256-GCM.
57
+ * Output format: <iv(12B)><tag(16B)><ciphertext> as hex string (no 0x prefix).
58
+ */
59
+ export function encryptKey(privateKey, encryptionKey) {
60
+ const key = deriveKey(encryptionKey);
61
+ const iv = randomBytes(12);
62
+ const cipher = createCipheriv("aes-256-gcm", key, iv);
63
+ const plain = Buffer.from(privateKey.replace(/^0x/, ""), "hex");
64
+ const encrypted = Buffer.concat([cipher.update(plain), cipher.final()]);
65
+ const tag = cipher.getAuthTag();
66
+ return Buffer.concat([iv, tag, encrypted]).toString("hex");
67
+ }
68
+ /**
69
+ * Decrypts a private key. Handles both:
70
+ * - New AES-256-GCM format (pure hex, no 0x prefix)
71
+ * - Legacy XOR format (starts with "0x") — transparently supported for migration
72
+ */
73
+ export function decryptKey(encrypted, encryptionKey) {
74
+ if (encrypted.startsWith("0x")) {
75
+ // Legacy XOR path — symmetric, same operation
76
+ return _xorObfuscate(encrypted, encryptionKey);
77
+ }
78
+ const key = deriveKey(encryptionKey);
79
+ const data = Buffer.from(encrypted, "hex");
80
+ const iv = data.subarray(0, 12);
81
+ const tag = data.subarray(12, 28);
82
+ const ciphertext = data.subarray(28);
83
+ const decipher = createDecipheriv("aes-256-gcm", key, iv);
84
+ decipher.setAuthTag(tag);
85
+ const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
86
+ return "0x" + decrypted.toString("hex");
87
+ }
88
+ // ─── Legacy XOR helpers (kept for migration read path only) ────────────
89
+ function _xorObfuscate(privateKey, encryptionKey) {
90
+ const keyBytes = Buffer.from(encryptionKey.padEnd(32, "0").slice(0, 32));
91
+ const pkBytes = Buffer.from(privateKey.replace("0x", ""), "hex");
92
+ const result = Buffer.alloc(pkBytes.length);
93
+ for (let i = 0; i < pkBytes.length; i++) {
94
+ result[i] = pkBytes[i] ^ keyBytes[i % keyBytes.length];
95
+ }
96
+ return "0x" + result.toString("hex");
97
+ }
98
+ /** @deprecated Use encryptKey / decryptKey. Kept for callers that haven't migrated yet. */
99
+ export function obfuscateKey(privateKey, encryptionKey) {
100
+ return _xorObfuscate(privateKey, encryptionKey);
101
+ }
102
+ /** @deprecated Use decryptKey. */
103
+ export function deobfuscateKey(obfuscated, encryptionKey) {
104
+ return _xorObfuscate(obfuscated, encryptionKey);
105
+ }
106
+ // ─── Encryption key resolution ─────────────────────────────────────────
107
+ // Random per-process fallback key — never hardcoded, never reused across restarts
108
+ const IN_MEMORY_FALLBACK_KEY = randomBytes(32).toString("hex");
109
+ /**
110
+ * Returns the effective encryption key.
111
+ * - Persistent store: WALLET_ENCRYPTION_KEY must be set (wallets won't survive restarts otherwise).
112
+ * - In-memory store: falls back to a random per-process key.
113
+ */
114
+ export function getEffectiveEncryptionKey() {
115
+ return process.env.WALLET_ENCRYPTION_KEY || IN_MEMORY_FALLBACK_KEY;
116
+ }
117
+ // ─── Factory ────────────────────────────────────────────────────────────
118
+ function createWalletStore() {
119
+ const storePath = process.env.WALLET_STORE_PATH;
120
+ if (storePath) {
121
+ return new FileWalletStore(storePath);
122
+ }
123
+ return new InMemoryWalletStore();
124
+ }
125
+ export function usesPersistentWalletStore() {
126
+ return Boolean(process.env.WALLET_STORE_PATH);
127
+ }
128
+ export const walletStore = createWalletStore();
71
129
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/wallet/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yDAAyD;AACzD,sEAAsE;AACtE,+CAA+C;AAC/C,2EAA2E;AAE3E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAkB7D,0EAA0E;AAE1E,MAAM,mBAAmB;IACf,KAAK,GAAG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AS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAChD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,EAAE,CAAC"}
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=checkDeploy.d.ts.map
@@ -1,25 +1,25 @@
1
- // Quick script to fetch the receipt for the deploy tx
2
- import { publicClient } from "../lib/pharosClient.js";
3
- import { readFileSync, writeFileSync } from "fs";
4
- import { resolve } from "path";
5
- const TX_HASH = "0x7f2106b5bc8c5eddcd2ea7782669ccb0b4a107da4943cffd5d49357ab5820d2e";
6
- async function main() {
7
- console.log("Fetching receipt for deploy tx...");
8
- console.log(`TX: ${TX_HASH}`);
9
- const receipt = await publicClient.getTransactionReceipt({ hash: TX_HASH });
10
- console.log(`Status: ${receipt.status}`);
11
- console.log(`Contract: ${receipt.contractAddress}`);
12
- console.log(`Block: ${receipt.blockNumber}`);
13
- console.log(`Gas Used: ${receipt.gasUsed}`);
14
- if (receipt.contractAddress) {
15
- // Update .env
16
- const envPath = resolve(process.cwd(), ".env");
17
- let envContent = readFileSync(envPath, "utf-8");
18
- envContent = envContent.replace(/\nRISK_REGISTRY_ADDRESS=.*/, "");
19
- envContent = envContent.trimEnd() + `\n\n# Risk Registry\nRISK_REGISTRY_ADDRESS=${receipt.contractAddress}\n`;
20
- writeFileSync(envPath, envContent);
21
- console.log(`\n✅ .env updated with RISK_REGISTRY_ADDRESS=${receipt.contractAddress}`);
22
- }
23
- }
24
- main().catch(console.error);
1
+ // Quick script to fetch the receipt for the deploy tx
2
+ import { publicClient } from "../lib/pharosClient.js";
3
+ import { readFileSync, writeFileSync } from "fs";
4
+ import { resolve } from "path";
5
+ const TX_HASH = "0x7f2106b5bc8c5eddcd2ea7782669ccb0b4a107da4943cffd5d49357ab5820d2e";
6
+ async function main() {
7
+ console.log("Fetching receipt for deploy tx...");
8
+ console.log(`TX: ${TX_HASH}`);
9
+ const receipt = await publicClient.getTransactionReceipt({ hash: TX_HASH });
10
+ console.log(`Status: ${receipt.status}`);
11
+ console.log(`Contract: ${receipt.contractAddress}`);
12
+ console.log(`Block: ${receipt.blockNumber}`);
13
+ console.log(`Gas Used: ${receipt.gasUsed}`);
14
+ if (receipt.contractAddress) {
15
+ // Update .env
16
+ const envPath = resolve(process.cwd(), ".env");
17
+ let envContent = readFileSync(envPath, "utf-8");
18
+ envContent = envContent.replace(/\nRISK_REGISTRY_ADDRESS=.*/, "");
19
+ envContent = envContent.trimEnd() + `\n\n# Risk Registry\nRISK_REGISTRY_ADDRESS=${receipt.contractAddress}\n`;
20
+ writeFileSync(envPath, envContent);
21
+ console.log(`\n✅ .env updated with RISK_REGISTRY_ADDRESS=${receipt.contractAddress}`);
22
+ }
23
+ }
24
+ main().catch(console.error);
25
25
  //# sourceMappingURL=checkDeploy.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=deployRegistry.d.ts.map
@@ -1,101 +1,101 @@
1
- // ─── Compile & Deploy RiskRegistry ─────────────────────────────────────
2
- // Compiles the Solidity contract with solc and deploys to Pharos Atlantic.
3
- // ────────────────────────────────────────────────────────────────────────
4
- import { readFileSync, writeFileSync } from "fs";
5
- import { resolve } from "path";
6
- import solc from "solc";
7
- import { createPharosWalletClient, publicClient } from "../lib/pharosClient.js";
8
- // ─── Load .env ─────────────────────────────────────────────────────────
9
- function loadEnv() {
10
- const envPath = resolve(process.cwd(), ".env");
11
- const envFile = readFileSync(envPath, "utf-8");
12
- const vars = {};
13
- for (const line of envFile.split("\n")) {
14
- const trimmed = line.trim();
15
- if (!trimmed || trimmed.startsWith("#"))
16
- continue;
17
- const eqIdx = trimmed.indexOf("=");
18
- if (eqIdx === -1)
19
- continue;
20
- vars[trimmed.slice(0, eqIdx).trim()] = trimmed.slice(eqIdx + 1).trim();
21
- }
22
- return vars;
23
- }
24
- const env = loadEnv();
25
- const PRIVATE_KEY = env.PRIVATE_KEY;
26
- if (!PRIVATE_KEY) {
27
- console.error("❌ PRIVATE_KEY not found in .env");
28
- process.exit(1);
29
- }
30
- // ─── Compile ───────────────────────────────────────────────────────────
31
- console.log("📝 Compiling RiskRegistry.sol...");
32
- const contractPath = resolve(process.cwd(), "contracts", "RiskRegistry.sol");
33
- const source = readFileSync(contractPath, "utf-8");
34
- const input = JSON.stringify({
35
- language: "Solidity",
36
- sources: {
37
- "RiskRegistry.sol": { content: source },
38
- },
39
- settings: {
40
- outputSelection: {
41
- "*": {
42
- "*": ["abi", "evm.bytecode.object"],
43
- },
44
- },
45
- optimizer: { enabled: true, runs: 200 },
46
- },
47
- });
48
- const output = JSON.parse(solc.compile(input));
49
- if (output.errors) {
50
- const errors = output.errors.filter((e) => e.severity === "error");
51
- if (errors.length > 0) {
52
- console.error("❌ Compilation errors:");
53
- errors.forEach((e) => console.error(e.formattedMessage));
54
- process.exit(1);
55
- }
56
- }
57
- const contract = output.contracts["RiskRegistry.sol"]["RiskRegistry"];
58
- const abi = contract.abi;
59
- const bytecode = `0x${contract.evm.bytecode.object}`;
60
- console.log("✅ Compiled successfully");
61
- console.log(` ABI: ${abi.length} functions/events`);
62
- console.log(` Bytecode: ${bytecode.length} chars`);
63
- // Save ABI for reference
64
- const artifactPath = resolve(process.cwd(), "contracts", "RiskRegistry.json");
65
- writeFileSync(artifactPath, JSON.stringify({ abi, bytecode }, null, 2));
66
- console.log(` Artifact saved: contracts/RiskRegistry.json`);
67
- // ─── Deploy ────────────────────────────────────────────────────────────
68
- console.log("\n🚀 Deploying to Pharos Atlantic Testnet...");
69
- const wallet = createPharosWalletClient(PRIVATE_KEY);
70
- const account = wallet.account;
71
- console.log(` Deployer: ${account.address}`);
72
- const balance = await publicClient.getBalance({ address: account.address });
73
- console.log(` Balance: ${Number(balance) / 1e18} PHRS`);
74
- // Deploy using viem
75
- const hash = await wallet.deployContract({
76
- abi,
77
- bytecode,
78
- args: [],
79
- });
80
- console.log(` TX Hash: ${hash}`);
81
- console.log(" Waiting for confirmation...");
82
- const receipt = await publicClient.waitForTransactionReceipt({ hash });
83
- if (receipt.status !== "success") {
84
- console.error("❌ Deployment failed!");
85
- process.exit(1);
86
- }
87
- const contractAddress = receipt.contractAddress;
88
- console.log(`\n✅ RiskRegistry deployed successfully!`);
89
- console.log(` Contract: ${contractAddress}`);
90
- console.log(` Block: ${receipt.blockNumber}`);
91
- console.log(` Gas Used: ${receipt.gasUsed}`);
92
- console.log(` Explorer: https://atlantic.pharosscan.xyz/tx/${hash}`);
93
- // ─── Update .env ───────────────────────────────────────────────────────
94
- const envPath = resolve(process.cwd(), ".env");
95
- let envContent = readFileSync(envPath, "utf-8");
96
- // Remove old entry if exists
97
- envContent = envContent.replace(/\nRISK_REGISTRY_ADDRESS=.*/, "");
98
- envContent = envContent.trimEnd() + `\n\n# Risk Registry\nRISK_REGISTRY_ADDRESS=${contractAddress}\n`;
99
- writeFileSync(envPath, envContent);
100
- console.log(`\n📝 Updated .env with RISK_REGISTRY_ADDRESS=${contractAddress}`);
1
+ // ─── Compile & Deploy RiskRegistry ─────────────────────────────────────
2
+ // Compiles the Solidity contract with solc and deploys to Pharos Atlantic.
3
+ // ────────────────────────────────────────────────────────────────────────
4
+ import { readFileSync, writeFileSync } from "fs";
5
+ import { resolve } from "path";
6
+ import solc from "solc";
7
+ import { createPharosWalletClient, publicClient } from "../lib/pharosClient.js";
8
+ // ─── Load .env ─────────────────────────────────────────────────────────
9
+ function loadEnv() {
10
+ const envPath = resolve(process.cwd(), ".env");
11
+ const envFile = readFileSync(envPath, "utf-8");
12
+ const vars = {};
13
+ for (const line of envFile.split("\n")) {
14
+ const trimmed = line.trim();
15
+ if (!trimmed || trimmed.startsWith("#"))
16
+ continue;
17
+ const eqIdx = trimmed.indexOf("=");
18
+ if (eqIdx === -1)
19
+ continue;
20
+ vars[trimmed.slice(0, eqIdx).trim()] = trimmed.slice(eqIdx + 1).trim();
21
+ }
22
+ return vars;
23
+ }
24
+ const env = loadEnv();
25
+ const PRIVATE_KEY = env.PRIVATE_KEY;
26
+ if (!PRIVATE_KEY) {
27
+ console.error("❌ PRIVATE_KEY not found in .env");
28
+ process.exit(1);
29
+ }
30
+ // ─── Compile ───────────────────────────────────────────────────────────
31
+ console.log("📝 Compiling RiskRegistry.sol...");
32
+ const contractPath = resolve(process.cwd(), "contracts", "RiskRegistry.sol");
33
+ const source = readFileSync(contractPath, "utf-8");
34
+ const input = JSON.stringify({
35
+ language: "Solidity",
36
+ sources: {
37
+ "RiskRegistry.sol": { content: source },
38
+ },
39
+ settings: {
40
+ outputSelection: {
41
+ "*": {
42
+ "*": ["abi", "evm.bytecode.object"],
43
+ },
44
+ },
45
+ optimizer: { enabled: true, runs: 200 },
46
+ },
47
+ });
48
+ const output = JSON.parse(solc.compile(input));
49
+ if (output.errors) {
50
+ const errors = output.errors.filter((e) => e.severity === "error");
51
+ if (errors.length > 0) {
52
+ console.error("❌ Compilation errors:");
53
+ errors.forEach((e) => console.error(e.formattedMessage));
54
+ process.exit(1);
55
+ }
56
+ }
57
+ const contract = output.contracts["RiskRegistry.sol"]["RiskRegistry"];
58
+ const abi = contract.abi;
59
+ const bytecode = `0x${contract.evm.bytecode.object}`;
60
+ console.log("✅ Compiled successfully");
61
+ console.log(` ABI: ${abi.length} functions/events`);
62
+ console.log(` Bytecode: ${bytecode.length} chars`);
63
+ // Save ABI for reference
64
+ const artifactPath = resolve(process.cwd(), "contracts", "RiskRegistry.json");
65
+ writeFileSync(artifactPath, JSON.stringify({ abi, bytecode }, null, 2));
66
+ console.log(` Artifact saved: contracts/RiskRegistry.json`);
67
+ // ─── Deploy ────────────────────────────────────────────────────────────
68
+ console.log("\n🚀 Deploying to Pharos Atlantic Testnet...");
69
+ const wallet = createPharosWalletClient(PRIVATE_KEY);
70
+ const account = wallet.account;
71
+ console.log(` Deployer: ${account.address}`);
72
+ const balance = await publicClient.getBalance({ address: account.address });
73
+ console.log(` Balance: ${Number(balance) / 1e18} PHRS`);
74
+ // Deploy using viem
75
+ const hash = await wallet.deployContract({
76
+ abi,
77
+ bytecode,
78
+ args: [],
79
+ });
80
+ console.log(` TX Hash: ${hash}`);
81
+ console.log(" Waiting for confirmation...");
82
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
83
+ if (receipt.status !== "success") {
84
+ console.error("❌ Deployment failed!");
85
+ process.exit(1);
86
+ }
87
+ const contractAddress = receipt.contractAddress;
88
+ console.log(`\n✅ RiskRegistry deployed successfully!`);
89
+ console.log(` Contract: ${contractAddress}`);
90
+ console.log(` Block: ${receipt.blockNumber}`);
91
+ console.log(` Gas Used: ${receipt.gasUsed}`);
92
+ console.log(` Explorer: https://atlantic.pharosscan.xyz/tx/${hash}`);
93
+ // ─── Update .env ───────────────────────────────────────────────────────
94
+ const envPath = resolve(process.cwd(), ".env");
95
+ let envContent = readFileSync(envPath, "utf-8");
96
+ // Remove old entry if exists
97
+ envContent = envContent.replace(/\nRISK_REGISTRY_ADDRESS=.*/, "");
98
+ envContent = envContent.trimEnd() + `\n\n# Risk Registry\nRISK_REGISTRY_ADDRESS=${contractAddress}\n`;
99
+ writeFileSync(envPath, envContent);
100
+ console.log(`\n📝 Updated .env with RISK_REGISTRY_ADDRESS=${contractAddress}`);
101
101
  //# sourceMappingURL=deployRegistry.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=testRegistry.d.ts.map
@@ -1,44 +1,44 @@
1
- // ─── Quick test: RiskRegistry publish + query ──────────────────────────
2
- import { readFileSync } from "fs";
3
- import { resolve } from "path";
4
- import { handleAssessRisk } from "../tools/assessRisk.js";
5
- import { handleQueryRiskRegistry } from "../tools/queryRiskRegistry.js";
6
- function loadEnv() {
7
- const envPath = resolve(process.cwd(), ".env");
8
- const envFile = readFileSync(envPath, "utf-8");
9
- const vars = {};
10
- for (const line of envFile.split("\n")) {
11
- const trimmed = line.trim();
12
- if (!trimmed || trimmed.startsWith("#"))
13
- continue;
14
- const eqIdx = trimmed.indexOf("=");
15
- if (eqIdx === -1)
16
- continue;
17
- vars[trimmed.slice(0, eqIdx).trim()] = trimmed.slice(eqIdx + 1).trim();
18
- }
19
- return vars;
20
- }
21
- const env = loadEnv();
22
- async function main() {
23
- console.log("🧪 Testing RiskRegistry: assess + publish + query\n");
24
- // 1. assess_risk WITH privateKey → auto-publishes
25
- console.log("1️⃣ assess_risk with auto-publish...");
26
- const assessment = await handleAssessRisk({
27
- action: "swap",
28
- tokenIn: "PHRS",
29
- tokenOut: "USDC",
30
- amount: "1",
31
- walletAddress: env.WALLET_ADDRESS,
32
- privateKey: env.PRIVATE_KEY,
33
- });
34
- console.log(JSON.stringify(assessment, null, 2));
35
- // 2. query_risk_registry
36
- console.log("\n2️⃣ query_risk_registry...");
37
- const query = await handleQueryRiskRegistry({
38
- walletAddress: env.WALLET_ADDRESS,
39
- });
40
- console.log(JSON.stringify(query, null, 2));
41
- console.log("\n✅ RiskRegistry end-to-end test complete!");
42
- }
43
- main().catch(console.error);
1
+ // ─── Quick test: RiskRegistry publish + query ──────────────────────────
2
+ import { readFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ import { handleAssessRisk } from "../tools/assessRisk.js";
5
+ import { handleQueryRiskRegistry } from "../tools/queryRiskRegistry.js";
6
+ function loadEnv() {
7
+ const envPath = resolve(process.cwd(), ".env");
8
+ const envFile = readFileSync(envPath, "utf-8");
9
+ const vars = {};
10
+ for (const line of envFile.split("\n")) {
11
+ const trimmed = line.trim();
12
+ if (!trimmed || trimmed.startsWith("#"))
13
+ continue;
14
+ const eqIdx = trimmed.indexOf("=");
15
+ if (eqIdx === -1)
16
+ continue;
17
+ vars[trimmed.slice(0, eqIdx).trim()] = trimmed.slice(eqIdx + 1).trim();
18
+ }
19
+ return vars;
20
+ }
21
+ const env = loadEnv();
22
+ async function main() {
23
+ console.log("🧪 Testing RiskRegistry: assess + publish + query\n");
24
+ // 1. assess_risk WITH privateKey → auto-publishes
25
+ console.log("1️⃣ assess_risk with auto-publish...");
26
+ const assessment = await handleAssessRisk({
27
+ action: "swap",
28
+ tokenIn: "PHRS",
29
+ tokenOut: "USDC",
30
+ amount: "1",
31
+ walletAddress: env.WALLET_ADDRESS,
32
+ privateKey: env.PRIVATE_KEY,
33
+ });
34
+ console.log(JSON.stringify(assessment, null, 2));
35
+ // 2. query_risk_registry
36
+ console.log("\n2️⃣ query_risk_registry...");
37
+ const query = await handleQueryRiskRegistry({
38
+ walletAddress: env.WALLET_ADDRESS,
39
+ });
40
+ console.log(JSON.stringify(query, null, 2));
41
+ console.log("\n✅ RiskRegistry end-to-end test complete!");
42
+ }
43
+ main().catch(console.error);
44
44
  //# sourceMappingURL=testRegistry.js.map