@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 CHANGED
@@ -3685,54 +3685,38 @@ async function getContractBytecode(address, networkConfig) {
3685
3685
 
3686
3686
  // src/abi/sourcify.ts
3687
3687
  var import_ui_builder_utils27 = require("@openzeppelin/ui-builder-utils");
3688
- var SOURCIFY_BASE = "https://repo.sourcify.dev";
3689
- function buildSourcifyAbiUrlCandidates(chainId, address) {
3690
- const addrLower = address.toLowerCase();
3691
- const addrOriginal = address;
3692
- const categories = ["full_match", "partial_match"];
3693
- const addrs = [addrLower, addrOriginal];
3694
- const urls = [];
3695
- for (const category of categories) {
3696
- for (const addr of addrs) {
3697
- urls.push(`${SOURCIFY_BASE}/contracts/${category}/${chainId}/${addr}/metadata.json`);
3698
- }
3699
- }
3700
- return urls;
3688
+ var SOURCIFY_APP_BASE = "https://sourcify.dev";
3689
+ function getSourcifyContractAppUrl(chainId, address) {
3690
+ const normalizedAddress = address.toLowerCase();
3691
+ return `${SOURCIFY_APP_BASE}/status/${chainId}/${normalizedAddress}`;
3701
3692
  }
3702
- function getSourcifyRepoContractUrl(chainId, address) {
3703
- return `${SOURCIFY_BASE}/${chainId}/${address}`;
3693
+ var SOURCIFY_API_BASE = "https://sourcify.dev/server/v2";
3694
+ function buildSourcifyApiUrl(chainId, address) {
3695
+ const normalizedAddress = address.toLowerCase();
3696
+ const url = new URL(
3697
+ `${SOURCIFY_API_BASE}/contract/${chainId}/${normalizedAddress}?fields=abi,metadata`
3698
+ );
3699
+ return url.toString();
3704
3700
  }
3705
3701
  async function loadAbiFromSourcify(address, networkConfig, timeoutMs = 4e3) {
3706
- const candidates = buildSourcifyAbiUrlCandidates(networkConfig.chainId, address);
3707
3702
  const controller = new AbortController();
3708
3703
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
3709
3704
  try {
3710
- let lastError = null;
3711
- for (const url of candidates) {
3712
- try {
3713
- import_ui_builder_utils27.logger.info("loadAbiFromSourcify", `Fetching metadata from ${url}`);
3714
- const response = await fetch(url, { signal: controller.signal });
3715
- if (!response.ok) {
3716
- lastError = new Error(
3717
- `Sourcify request failed: ${response.status} ${response.statusText} (${url})`
3718
- );
3719
- continue;
3720
- }
3721
- const metadata = await response.json();
3722
- const abi = metadata?.output?.abi;
3723
- if (!abi || !Array.isArray(abi)) {
3724
- lastError = new Error("Sourcify metadata did not include a valid ABI array");
3725
- continue;
3726
- }
3727
- const contractName = metadata.contractName || `Contract_${address.substring(0, 6)}`;
3728
- const schema = transformAbiToSchema(abi, contractName, address);
3729
- return { schema, originalAbi: JSON.stringify(abi) };
3730
- } catch (inner) {
3731
- lastError = inner;
3732
- continue;
3733
- }
3705
+ const url = buildSourcifyApiUrl(networkConfig.chainId, address);
3706
+ import_ui_builder_utils27.logger.info("loadAbiFromSourcify", `Fetching contract from ${url}`);
3707
+ const response = await fetch(url, { signal: controller.signal });
3708
+ if (!response.ok) {
3709
+ throw new Error(`Sourcify request failed: ${response.status} ${response.statusText}`);
3710
+ }
3711
+ const payload = await response.json();
3712
+ const abi = payload.abi ?? payload.metadata?.output?.abi;
3713
+ if (!abi || !Array.isArray(abi)) {
3714
+ throw new Error("Sourcify metadata did not include a valid ABI array");
3734
3715
  }
3735
- throw lastError ?? new Error("Sourcify metadata not found for any candidate URL");
3716
+ const normalizedAddress = address.toLowerCase();
3717
+ const contractName = payload.metadata?.contractName || `Contract_${normalizedAddress.substring(0, 6).toUpperCase()}`;
3718
+ const schema = transformAbiToSchema(abi, contractName, address);
3719
+ return { schema, originalAbi: JSON.stringify(abi) };
3736
3720
  } catch (error) {
3737
3721
  import_ui_builder_utils27.logger.warn("loadAbiFromSourcify", `Failed to fetch ABI from Sourcify: ${String(error)}`);
3738
3722
  throw error;
@@ -3814,7 +3798,7 @@ function buildContractResult(contractAddress, abiResult, networkConfig, sourcePr
3814
3798
  if (sourceProvider === EvmProviderKeys.Etherscan) {
3815
3799
  fetchedFrom = getEvmExplorerAddressUrl(contractAddress, networkConfig) || void 0;
3816
3800
  } else if (sourceProvider === EvmProviderKeys.Sourcify) {
3817
- fetchedFrom = getSourcifyRepoContractUrl(networkConfig.chainId, contractAddress);
3801
+ fetchedFrom = getSourcifyContractAppUrl(networkConfig.chainId, contractAddress);
3818
3802
  } else {
3819
3803
  fetchedFrom = getEvmExplorerAddressUrl(contractAddress, networkConfig) || void 0;
3820
3804
  }