@mapprotocol/common-contracts 0.4.0 → 0.4.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapprotocol/common-contracts",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Common contracts for MAP Protocol",
5
5
  "main": "typechain-types/index.js",
6
6
  "types": "typechain-types/index.d.ts",
@@ -71,7 +71,8 @@ async function evmDeployByFactory(ethers, salt, bytecode, constructorArgs = "0x"
71
71
  if (code === "0x")
72
72
  throw new Error("factory not deployed on this chain");
73
73
  const saltHash = ethers.keccak256(ethers.toUtf8Bytes(salt));
74
- const predicted = await factory.getAddress(saltHash);
74
+ // Use getFunction: ethers v6 Contract has a built-in getAddress() that shadows the ABI method
75
+ const predicted = await factory.getFunction("getAddress")(saltHash);
75
76
  const existingCode = await ethers.provider.getCode(predicted);
76
77
  if (existingCode !== "0x") {
77
78
  console.log(`already deployed at ${predicted}`);
@@ -98,7 +99,8 @@ async function evmDeployByFactory(ethers, salt, bytecode, constructorArgs = "0x"
98
99
  async function evmGetFactoryAddress(ethers, salt) {
99
100
  const factory = new ethers.Contract(EVM_FACTORY, EVM_FACTORY_ABI, await ethers.provider);
100
101
  const saltHash = ethers.keccak256(ethers.toUtf8Bytes(salt));
101
- return factory.getAddress(saltHash);
102
+ // Use getFunction: ethers v6 Contract has a built-in getAddress() that shadows the ABI method
103
+ return factory.getFunction("getAddress")(saltHash);
102
104
  }
103
105
  // ============================================================
104
106
  // Tron Factory (CREATE2, tronweb)
@@ -27,7 +27,17 @@ async function verify(hre, opts) {
27
27
  // EVM verification via hardhat-verify
28
28
  // ============================================================
29
29
  async function verifyEvm(hre, opts) {
30
- const contractPath = opts.contractPath || `contracts/${opts.contractName}.sol:${opts.contractName}`;
30
+ // Resolve contractPath from hardhat artifact (authoritative) instead of guessing
31
+ let contractPath = opts.contractPath;
32
+ if (!contractPath) {
33
+ try {
34
+ const artifact = await hre.artifacts.readArtifact(opts.contractName);
35
+ contractPath = `${artifact.sourceName}:${opts.contractName}`;
36
+ }
37
+ catch {
38
+ contractPath = `contracts/${opts.contractName}.sol:${opts.contractName}`;
39
+ }
40
+ }
31
41
  console.log(`verifying ${opts.contractName} at ${opts.address} ...`);
32
42
  try {
33
43
  await hre.run("verify:verify", {
@@ -76,9 +86,10 @@ async function verifyTron(hre, opts) {
76
86
  }
77
87
  else {
78
88
  console.log(`generating flatten for ${opts.contractName}...`);
89
+ let sourcePath = "";
79
90
  try {
80
91
  const artifact = await hre.artifacts.readArtifact(opts.contractName);
81
- const sourcePath = artifact.sourceName;
92
+ sourcePath = artifact.sourceName;
82
93
  let flattenedSource = await hre.run("flatten:get-flattened-sources", {
83
94
  files: [sourcePath],
84
95
  });
@@ -88,7 +99,8 @@ async function verifyTron(hre, opts) {
88
99
  console.log(`flatten saved to: ${flattenPath}`);
89
100
  }
90
101
  catch (e) {
91
- console.log(`flatten failed, generate manually: forge flatten contracts/${opts.contractName}.sol`);
102
+ const hint = sourcePath || `contracts/${opts.contractName}.sol`;
103
+ console.log(`flatten failed, generate manually: npx hardhat flatten ${hint} > ${flattenPath}`);
92
104
  return;
93
105
  }
94
106
  }
package/utils/factory.ts CHANGED
@@ -76,7 +76,8 @@ export async function evmDeployByFactory(
76
76
  if (code === "0x") throw new Error("factory not deployed on this chain");
77
77
 
78
78
  const saltHash = ethers.keccak256(ethers.toUtf8Bytes(salt));
79
- const predicted = await factory.getAddress(saltHash);
79
+ // Use getFunction: ethers v6 Contract has a built-in getAddress() that shadows the ABI method
80
+ const predicted = await factory.getFunction("getAddress")(saltHash);
80
81
 
81
82
  const existingCode = await ethers.provider.getCode(predicted);
82
83
  if (existingCode !== "0x") {
@@ -108,7 +109,8 @@ export async function evmDeployByFactory(
108
109
  export async function evmGetFactoryAddress(ethers: any, salt: string): Promise<string> {
109
110
  const factory = new ethers.Contract(EVM_FACTORY, EVM_FACTORY_ABI, await ethers.provider);
110
111
  const saltHash = ethers.keccak256(ethers.toUtf8Bytes(salt));
111
- return factory.getAddress(saltHash);
112
+ // Use getFunction: ethers v6 Contract has a built-in getAddress() that shadows the ABI method
113
+ return factory.getFunction("getAddress")(saltHash);
112
114
  }
113
115
 
114
116
  // ============================================================
package/utils/verifier.ts CHANGED
@@ -49,7 +49,16 @@ export async function verify(hre: any, opts: VerifyOptions): Promise<void> {
49
49
  // ============================================================
50
50
 
51
51
  async function verifyEvm(hre: any, opts: VerifyOptions): Promise<void> {
52
- const contractPath = opts.contractPath || `contracts/${opts.contractName}.sol:${opts.contractName}`;
52
+ // Resolve contractPath from hardhat artifact (authoritative) instead of guessing
53
+ let contractPath = opts.contractPath;
54
+ if (!contractPath) {
55
+ try {
56
+ const artifact = await hre.artifacts.readArtifact(opts.contractName);
57
+ contractPath = `${artifact.sourceName}:${opts.contractName}`;
58
+ } catch {
59
+ contractPath = `contracts/${opts.contractName}.sol:${opts.contractName}`;
60
+ }
61
+ }
53
62
 
54
63
  console.log(`verifying ${opts.contractName} at ${opts.address} ...`);
55
64
 
@@ -103,9 +112,10 @@ async function verifyTron(hre: any, opts: VerifyOptions): Promise<void> {
103
112
  console.log(`using existing flatten: ${flattenPath}`);
104
113
  } else {
105
114
  console.log(`generating flatten for ${opts.contractName}...`);
115
+ let sourcePath = "";
106
116
  try {
107
117
  const artifact = await hre.artifacts.readArtifact(opts.contractName);
108
- const sourcePath = artifact.sourceName;
118
+ sourcePath = artifact.sourceName;
109
119
  let flattenedSource = await hre.run("flatten:get-flattened-sources", {
110
120
  files: [sourcePath],
111
121
  });
@@ -114,7 +124,8 @@ async function verifyTron(hre: any, opts: VerifyOptions): Promise<void> {
114
124
  fs.writeFileSync(flattenPath, flattenedSource);
115
125
  console.log(`flatten saved to: ${flattenPath}`);
116
126
  } catch (e) {
117
- console.log(`flatten failed, generate manually: forge flatten contracts/${opts.contractName}.sol`);
127
+ const hint = sourcePath || `contracts/${opts.contractName}.sol`;
128
+ console.log(`flatten failed, generate manually: npx hardhat flatten ${hint} > ${flattenPath}`);
118
129
  return;
119
130
  }
120
131
  }