Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix highlight ingestor #64

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
74 changes: 41 additions & 33 deletions src/ingestors/highlight/index.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
import { MintContractOptions, MintIngestor, MintIngestorResources } from '../../lib/types/mint-ingestor';
import { MintIngestionErrorName, MintIngestorError } from '../../lib/types/mint-ingestor-error';
import { MintInstructionType, MintTemplate } from '../../lib/types/mint-template';
import { MintTemplateBuilder } from '../../lib/builder/mint-template-builder';
import { getHighlightMetadata, getHighlightMintPriceInWei } from './onchain-metadata';
import {
getHighlightCollectionByAddress,
getHighlightCollectionById,
getHighlightCollectionOwnerDetails,
getHighlightUrlForAddress,
getHighlightVectorId,
} from './offchain-metadata';
import { getHighlightMetadata, getHighlightMintPriceInWei } from './onchain-metadata';

import { MINT_CONTRACT_ABI } from './abi';
import { MintTemplateBuilder } from '../../lib/builder/mint-template-builder';

const CONTRACT_ADDRESS = '0x8087039152c472Fa74F47398628fF002994056EA';

export class HighlightIngestor implements MintIngestor {
async supportsUrl(resources: MintIngestorResources, url: string): Promise<boolean> {
return false;
// const id = url.split('/').pop();
// if (!id) {
// return false;
// }

// const collection = await getHighlightCollectionById(resources, id);

// if (!collection || collection.chainId !== 8453) {
// return false;
// }

// const urlPattern = /^https:\/\/highlight\.xyz\/mint\/[a-f0-9]{24}$/;
// return (
// new URL(url).hostname === 'www.highlight.xyz' || new URL(url).hostname === 'highlight.xyz' || urlPattern.test(url)
// );
const match = url.match(/\/mint\/([^\/]+)/);
const id = match ? match[1] : null;
if (!id) {
return false;
}
// accept
const collection = await getHighlightCollectionById(resources, id);

if (!collection || collection.chainId !== 8453) {
return false;
}

const urlPattern = /^https:\/\/highlight\.xyz\/mint\/[a-f0-9]{24}$/;
return (
new URL(url).hostname === 'www.highlight.xyz' || new URL(url).hostname === 'highlight.xyz' || urlPattern.test(url)
);
}

async supportsContract(resources: MintIngestorResources, contractOptions: MintContractOptions): Promise<boolean> {
return false;
// if (contractOptions.chainId !== 8453) {
// return false;
// }
// const collection = await getHighlightCollectionByAddress(resources, contractOptions);
// if (!collection) {
// return false;
// }
// return true;
if (contractOptions.chainId !== 8453) {
return false;
}
const collection = await getHighlightCollectionByAddress(resources, contractOptions);
if (!collection) {
return false;
}
return true;
}

async createMintForContract(
Expand Down Expand Up @@ -82,7 +83,10 @@ export class HighlightIngestor implements MintIngestor {
throw new MintIngestorError(MintIngestionErrorName.MissingRequiredData, 'Error finding creator');
}

const collectionId = collection.highlightCollection?.id || collection.id;
const url = await getHighlightUrlForAddress(resources, contractOptions.contractAddress);

const match = url.match(/\/mint\/([^\/]+)/);
const collectionId = match ? match[1] : null;

if (!collectionId) {
throw new MintIngestorError(MintIngestionErrorName.MissingRequiredData, 'Collection id not available');
Expand All @@ -95,7 +99,7 @@ export class HighlightIngestor implements MintIngestor {
imageUrl: creator?.creatorAccountSettings?.displayAvatar,
});

mintBuilder.setMintOutputContract({ chainId: 8453, address: collection.highlightCollection.address });
mintBuilder.setMintOutputContract({ chainId: 8453, address: collection.primaryContract });

const vectorId = await getHighlightVectorId(resources, collectionId);

Expand Down Expand Up @@ -143,9 +147,10 @@ export class HighlightIngestor implements MintIngestor {
}

// Example URL: https://highlight.xyz/mint/665fa33f07b3436991e55632
const splits = url.split('/');
const id = splits.pop();
const chain = splits.pop();
const match = url.match(/\/mint\/([^\/]+)/);
const id = match ? match[1] : null;

const tokenId = url.split('/t/')[1];

if (!id) {
throw new MintIngestorError(MintIngestionErrorName.CouldNotResolveMint, 'Url error');
Expand All @@ -160,7 +165,10 @@ export class HighlightIngestor implements MintIngestor {
return this.createMintForContract(resources, {
chainId: collection.chainId,
contractAddress: collection.address,
url,
url: `https://highlight.xyz/mint/base:${collection.address}${
collection.editionId == '1' ? ':' + collection.editionId : ''
}${tokenId ? '/t/' + tokenId : ''}`,
tokenId,
});
}
}
26 changes: 22 additions & 4 deletions src/ingestors/highlight/offchain-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MintContractOptions, MintIngestorResources } from 'src/lib';
import { Collection, CollectionByAddress, CollectionByAddress1 } from './types';
import { MintContractOptions, MintIngestorResources } from 'src/lib';

export const getHighlightCollectionById = async (
resources: MintIngestorResources,
Expand Down Expand Up @@ -31,6 +31,7 @@ export const getHighlightCollectionById = async (
status
baseUri
onChainBaseUri
editionId
}
}
`,
Expand Down Expand Up @@ -68,7 +69,10 @@ export const getHighlightCollectionByAddress = async (
} catch (error) {}
};

export const getHighlightVectorId = async (resources: MintIngestorResources, id: string): Promise<string | undefined> => {
export const getHighlightVectorId = async (
resources: MintIngestorResources,
id: string,
): Promise<string | undefined> => {
const url = 'https://api.highlight.xyz:8080/';

const headers = {
Expand Down Expand Up @@ -114,7 +118,8 @@ export const getHighlightVectorId = async (resources: MintIngestorResources, id:
).onchainMintVectorId;
const vectorId = vectorString.split(':').pop();
return vectorId;
} catch (error) {}
} catch (error) {
}
};

export const getHighlightCollectionOwnerDetails = async (resources: MintIngestorResources, id: string) => {
Expand Down Expand Up @@ -152,8 +157,21 @@ export const getHighlightCollectionOwnerDetails = async (resources: MintIngestor
try {
const resp = await resources.fetcher.post(url, data, { headers });
if (resp.data.errors) {
throw new Error("Error fetching owner");
throw new Error('Error fetching owner');
}
return resp.data.data.getPublicCollectionDetails;
} catch (error) {}
};

export const getHighlightUrlForAddress = async (resources: MintIngestorResources, address: string) => {
// try to get it by edition 1 or edition 0
let edition1Id = `base:${address}:1`;
let edition0Id = `base:${address}`;

let promises = [getHighlightCollectionById(resources, edition1Id), getHighlightCollectionById(resources, edition0Id)];

let data = (await Promise.all(promises)) as Collection[];
let record = data.filter((d) => !!d)[0];

return `https://highlight.xyz/mint/base:${record.address}${record.editionId === '1' ? ':1' : ''}`;
};
5 changes: 2 additions & 3 deletions src/ingestors/highlight/onchain-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Alchemy, Contract } from 'alchemy-sdk';

import { MINT_CONTRACT_ABI } from './abi';

const CONTRACT_ADDRESS = '0x8087039152c472Fa74F47398628fF002994056EA';
Expand All @@ -19,9 +20,7 @@ export const getHighlightMintPriceInWei = async (vectorId: number, alchemy: Alch
const totalFee = parseInt(pricePerToken.toString()) + fee;

return `${totalFee}`;
} catch (error) {
console.log(error);
}
} catch (error) {}
};

export const getHighlightMetadata = async (
Expand Down
2 changes: 2 additions & 0 deletions src/ingestors/highlight/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type Collection = {
chainId: number;
status: string;
baseUri: string;
editionId: string;
};

export type CollectionByAddress1 = {
Expand All @@ -24,6 +25,7 @@ export type CollectionByAddress1 = {
description: string;
sampleImages: string[];
creator: string;
primaryContract: string;
};

export type CollectionByAddress2 = {
Expand Down
14 changes: 7 additions & 7 deletions test/ingestors/highlight.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai';
import { HighlightIngestor } from '../../src/ingestors/highlight';
import { mintIngestorResources } from '../../src/lib/resources';
import { EVMMintInstructions } from '../../src/lib/types/mint-template';
import { HighlightIngestor } from '../../src/ingestors/highlight';
import { MintTemplateBuilder } from '../../src/lib/builder/mint-template-builder';
import { basicIngestorTests } from '../shared/basic-ingestor-tests';
import { expect } from 'chai';
import { mintIngestorResources } from '../../src/lib/resources';

const resources = mintIngestorResources();

describe.skip('highlight', function () {
describe('highlight', function () {
basicIngestorTests(
new HighlightIngestor(),
resources,
Expand Down Expand Up @@ -52,7 +52,7 @@ describe.skip('highlight', function () {

it('createMintTemplateForUrl: Returns a mint template for a supported URL', async function () {
const ingestor = new HighlightIngestor();
const url = 'https://highlight.xyz/mint/66856628ff8a01fdccc132f4';
const url = 'https://highlight.xyz/mint/base:0x0E5DDe3De7cf2761d8a81Ee68F48410425e2dBbA';
const resources = mintIngestorResources();
const template = await ingestor.createMintTemplateForUrl(resources, url);

Expand All @@ -65,7 +65,7 @@ describe.skip('highlight', function () {
const mintInstructions = template.mintInstructions as EVMMintInstructions;

expect(mintInstructions.contractAddress).to.equal('0x8087039152c472Fa74F47398628fF002994056EA');
expect(template.mintOutputContract?.address).to.equal('0x0E5DDe3De7cf2761d8a81Ee68F48410425e2dBbA');
expect(template.mintOutputContract?.address).to.equal('0x0e5dde3de7cf2761d8a81ee68f48410425e2dbba');
expect(mintInstructions.contractMethod).to.equal('vectorMint721');
expect(mintInstructions.contractParams).to.equal('[1176, quantity, address]');
expect(mintInstructions.priceWei).to.equal('800000000000000');
Expand All @@ -89,7 +89,7 @@ describe.skip('highlight', function () {

it.skip('createMintTemplateForUrl: Returns a mint template for a supported URL with free price', async function () {
const ingestor = new HighlightIngestor();
const url = 'https://highlight.xyz/mint/66744e64e610ed36adeb1a64';
const url = 'https://highlight.xyz/mint/base:0x30d745EDC90E92b4fdCE50c5239962Cf3407B12B';
const resources = mintIngestorResources();
const template = await ingestor.createMintTemplateForUrl(resources, url);

Expand Down