@openzeppelin/ui-builder-adapter-evm 0.10.0 → 0.11.1
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/dist/index.cjs +26 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -42
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/provenanceLinks.test.ts +2 -2
- package/src/__tests__/providerSelection.test.ts +6 -4
- package/src/__tests__/timeouts.test.ts +1 -1
- package/src/abi/loader.ts +2 -2
- package/src/abi/sourcify.ts +39 -51
package/dist/index.js
CHANGED
|
@@ -3710,54 +3710,38 @@ async function getContractBytecode(address, networkConfig) {
|
|
|
3710
3710
|
|
|
3711
3711
|
// src/abi/sourcify.ts
|
|
3712
3712
|
import { logger as logger24 } from "@openzeppelin/ui-builder-utils";
|
|
3713
|
-
var
|
|
3714
|
-
function
|
|
3715
|
-
const
|
|
3716
|
-
|
|
3717
|
-
const categories = ["full_match", "partial_match"];
|
|
3718
|
-
const addrs = [addrLower, addrOriginal];
|
|
3719
|
-
const urls = [];
|
|
3720
|
-
for (const category of categories) {
|
|
3721
|
-
for (const addr of addrs) {
|
|
3722
|
-
urls.push(`${SOURCIFY_BASE}/contracts/${category}/${chainId}/${addr}/metadata.json`);
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
return urls;
|
|
3713
|
+
var SOURCIFY_APP_BASE = "https://sourcify.dev";
|
|
3714
|
+
function getSourcifyContractAppUrl(chainId, address) {
|
|
3715
|
+
const normalizedAddress = address.toLowerCase();
|
|
3716
|
+
return `${SOURCIFY_APP_BASE}/status/${chainId}/${normalizedAddress}`;
|
|
3726
3717
|
}
|
|
3727
|
-
|
|
3728
|
-
|
|
3718
|
+
var SOURCIFY_API_BASE = "https://sourcify.dev/server/v2";
|
|
3719
|
+
function buildSourcifyApiUrl(chainId, address) {
|
|
3720
|
+
const normalizedAddress = address.toLowerCase();
|
|
3721
|
+
const url = new URL(
|
|
3722
|
+
`${SOURCIFY_API_BASE}/contract/${chainId}/${normalizedAddress}?fields=abi,metadata`
|
|
3723
|
+
);
|
|
3724
|
+
return url.toString();
|
|
3729
3725
|
}
|
|
3730
3726
|
async function loadAbiFromSourcify(address, networkConfig, timeoutMs = 4e3) {
|
|
3731
|
-
const candidates = buildSourcifyAbiUrlCandidates(networkConfig.chainId, address);
|
|
3732
3727
|
const controller = new AbortController();
|
|
3733
3728
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
3734
3729
|
try {
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
}
|
|
3746
|
-
const metadata = await response.json();
|
|
3747
|
-
const abi = metadata?.output?.abi;
|
|
3748
|
-
if (!abi || !Array.isArray(abi)) {
|
|
3749
|
-
lastError = new Error("Sourcify metadata did not include a valid ABI array");
|
|
3750
|
-
continue;
|
|
3751
|
-
}
|
|
3752
|
-
const contractName = metadata.contractName || `Contract_${address.substring(0, 6)}`;
|
|
3753
|
-
const schema = transformAbiToSchema(abi, contractName, address);
|
|
3754
|
-
return { schema, originalAbi: JSON.stringify(abi) };
|
|
3755
|
-
} catch (inner) {
|
|
3756
|
-
lastError = inner;
|
|
3757
|
-
continue;
|
|
3758
|
-
}
|
|
3730
|
+
const url = buildSourcifyApiUrl(networkConfig.chainId, address);
|
|
3731
|
+
logger24.info("loadAbiFromSourcify", `Fetching contract from ${url}`);
|
|
3732
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
3733
|
+
if (!response.ok) {
|
|
3734
|
+
throw new Error(`Sourcify request failed: ${response.status} ${response.statusText}`);
|
|
3735
|
+
}
|
|
3736
|
+
const payload = await response.json();
|
|
3737
|
+
const abi = payload.abi ?? payload.metadata?.output?.abi;
|
|
3738
|
+
if (!abi || !Array.isArray(abi)) {
|
|
3739
|
+
throw new Error("Sourcify metadata did not include a valid ABI array");
|
|
3759
3740
|
}
|
|
3760
|
-
|
|
3741
|
+
const normalizedAddress = address.toLowerCase();
|
|
3742
|
+
const contractName = payload.metadata?.contractName || `Contract_${normalizedAddress.substring(0, 6).toUpperCase()}`;
|
|
3743
|
+
const schema = transformAbiToSchema(abi, contractName, address);
|
|
3744
|
+
return { schema, originalAbi: JSON.stringify(abi) };
|
|
3761
3745
|
} catch (error) {
|
|
3762
3746
|
logger24.warn("loadAbiFromSourcify", `Failed to fetch ABI from Sourcify: ${String(error)}`);
|
|
3763
3747
|
throw error;
|
|
@@ -3839,7 +3823,7 @@ function buildContractResult(contractAddress, abiResult, networkConfig, sourcePr
|
|
|
3839
3823
|
if (sourceProvider === EvmProviderKeys.Etherscan) {
|
|
3840
3824
|
fetchedFrom = getEvmExplorerAddressUrl(contractAddress, networkConfig) || void 0;
|
|
3841
3825
|
} else if (sourceProvider === EvmProviderKeys.Sourcify) {
|
|
3842
|
-
fetchedFrom =
|
|
3826
|
+
fetchedFrom = getSourcifyContractAppUrl(networkConfig.chainId, contractAddress);
|
|
3843
3827
|
} else {
|
|
3844
3828
|
fetchedFrom = getEvmExplorerAddressUrl(contractAddress, networkConfig) || void 0;
|
|
3845
3829
|
}
|