Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions src/app/api/v1/custom-sourcify-abi-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,60 +50,6 @@ export class CustomSourcifyABILoader extends whatsabi.loaders.SourcifyABILoader
this.baseURL = config?.baseURL ?? 'https://sourcify.dev/server';
}

/* async loadContract(url: string): Promise<whatsabi.loaders.ContractResult> {
try {
const r = await fetchJSON(url);
const files: Array<{ name: string; path: string; content: string }> = r.files ?? r;

// Metadata is usually the first one
const metadata = files.find((f) => f.name === 'metadata.json');
if (metadata === undefined)
throw new whatsabi.loaders.SourcifyABILoaderError('metadata.json not found');

// Note: Sometimes metadata.json contains sources, but not always. So we can't rely on just the metadata.json
const m = JSON.parse(metadata.content) as whatsabi.loaders.SourcifyContractMetadata;

// Sourcify includes a title from the Natspec comments
let name = m.output.devdoc?.title;
if (!name && m.settings.compilationTarget) {
// Try to use the compilation target name as a fallback
const targetNames = Object.values(m.settings.compilationTarget);
if (targetNames.length > 0) {
name = targetNames[0];
}
}

return {
abi: m.output.abi,
name: name ?? null,
evmVersion: m.settings.evmVersion,
compilerVersion: m.compiler.version,
runs: m.settings.optimizer.runs,

// TODO: Paths will have a sourcify prefix, do we want to strip it to help normalize? It doesn't break anything keeping the prefix, so not sure.
// E.g. /contracts/full_match/1/0x1F98431c8aD98523631AE4a59f267346ea31F984/sources/contracts/interfaces/IERC20Minimal.sol
// Can use stripPathPrefix helper to do this, but maybe we want something like getSources({ normalize: true })?
getSources: async () =>
files.map(({ path, content }) => {
return { path, content };
}),

ok: true,
loader: this,
loaderResult: m
};
} catch (err: any) {
if (isSourcifyNotFound(err)) return emptyContractResult;
throw new whatsabi.loaders.SourcifyABILoaderError(
'SourcifyABILoader load contract error: ' + err.message,
{
context: { url },
cause: err
}
);
}
} */

async loadContract(url: string): Promise<whatsabi.loaders.ContractResult> {
try {
const r = await fetchJSON(url);
Expand Down Expand Up @@ -154,24 +100,6 @@ export class CustomSourcifyABILoader extends whatsabi.loaders.SourcifyABILoader
}
}

/* async getContract(address: string): Promise<whatsabi.loaders.ContractResult> {
{
// Full match index includes verification settings that matches exactly
const url = `${this.baseURL}/files/${this.chainId}/${address}`;
const r = await this.loadContract(url);
if (r.ok) return r;
}

{
// Partial match index is for verified contracts whose settings didn't match exactly
const url = `${this.baseURL}/files/${this.chainId}/${address}`;
const r = await this.loadContract(url);
if (r.ok) return r;
}

return emptyContractResult;
} */

async getContract(address: string): Promise<whatsabi.loaders.ContractResult> {
// Full match index includes verification settings that matches exactly
const url = `${this.baseURL}/v2/contract/${this.chainId}/${address}?fields=all`;
Expand All @@ -181,46 +109,6 @@ export class CustomSourcifyABILoader extends whatsabi.loaders.SourcifyABILoader
return emptyContractResult;
}

/* async loadABI(address: string): Promise<any[]> {
{
// Full match index includes verification settings that matches exactly
const url = `${this.baseURL}/repository/contracts/full_match/${this.chainId}/${address}/metadata.json`;
try {
return (await fetchJSON(url)).output.abi;
} catch (err: any) {
if (!isSourcifyNotFound(err)) {
throw new whatsabi.loaders.SourcifyABILoaderError(
'SourcifyABILoader loadABI error: ' + err.message,
{
context: { address, url },
cause: err
}
);
}
}
}

{
// Partial match index is for verified contracts whose settings didn't match exactly
const url = `${this.baseURL}/repository/contracts/partial_match/${this.chainId}/${address}/metadata.json`;
try {
return (await fetchJSON(url)).output.abi;
} catch (err: any) {
if (!isSourcifyNotFound(err)) {
throw new whatsabi.loaders.SourcifyABILoaderError(
'SourcifyABILoader loadABI error: ' + err.message,
{
context: { address, url },
cause: err
}
);
}
}
}

return [];
} */

async loadABI(address: string): Promise<any[]> {
const url = `${this.baseURL}/v2/contract/${this.chainId}/${address}?fields=abi`;
try {
Expand Down
Loading