Skip to content

Commit

Permalink
Merge pull request #24 from s29papi/raribleIngestor
Browse files Browse the repository at this point in the history
raribleIngestor
  • Loading branch information
chrismaddern authored Aug 27, 2024
2 parents c8af734 + ef5ea79 commit 31d6265
Show file tree
Hide file tree
Showing 17 changed files with 777 additions and 63 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
TENDERLY_ACCOUNT_SLUG: ${{ secrets.TENDERLY_ACCOUNT_SLUG }}
TENDERLY_PROJECT_SLUG: ${{ secrets.TENDERLY_PROJECT_SLUG }}
TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
RARIBLE_API_KEY: ${{ secrets.RARIBLE_API_KEY }}
run: yarn install --userconfig=/dev/null && yarn test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ dist
.yarn/install-state.gz
.pnp.*
.DS_Store
**/.DS_Store
**/.DS_Store


1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"alchemy-sdk": "^3.3.1",
"axios": "^1.7.4",
"dotenv": "^16.4.5",
"ethers": "^6.13.1",
"np": "^10.0.6",
"ts-node": "10.9.1",
"tslib": "^2.6.3"
Expand Down
4 changes: 2 additions & 2 deletions src/ingestors/fxhash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FxHashIngestor implements MintIngestor {
}
return true;
}

async createMintForContract(resources: MintIngestorResources, contract: MintContractOptions): Promise<MintTemplate> {
const mintBuilder = new MintTemplateBuilder()
.setMintInstructionType(MintInstructionType.EVM_MINT)
Expand Down Expand Up @@ -76,7 +76,7 @@ export class FxHashIngestor implements MintIngestor {
.setLiveDate(liveDate);

return mintBuilder.build();
}
}

async createMintTemplateForUrl(resources: MintIngestorResources, url: string): Promise<MintTemplate> {
const isCompatible = await this.supportsUrl(resources, url);
Expand Down
2 changes: 1 addition & 1 deletion src/ingestors/fxhash/offchain-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const getFxHashMintsBySlug = async (resources: MintIngestorResources, slu
return cur;
}
return acc;
}, '');
}, '');

try {
const graphQLRes = await resources.fetcher({
Expand Down
2 changes: 2 additions & 0 deletions src/ingestors/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MintIngestor } from '../lib/types/mint-ingestor';
import { ProhibitionDailyIngestor } from './prohibition-daily';
import { RaribleIngestor } from './rarible';
import { FxHashIngestor } from './fxhash';
import { HighlightIngestor } from './highlight';
import { TransientIngestor } from './transient-base';
Expand All @@ -14,6 +15,7 @@ export type MintIngestionMap = {
export const ALL_MINT_INGESTORS: MintIngestionMap = {
'prohibition-daily': new ProhibitionDailyIngestor(),
fxhash: new FxHashIngestor(),
rarible: new RaribleIngestor(),
highlight: new HighlightIngestor(),
transient: new TransientIngestor(),
foundation: new FoundationIngestor(),
Expand Down
3 changes: 2 additions & 1 deletion src/ingestors/prohibition-daily/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ProhibitionDailyIngestor implements MintIngestor {
if (!chainId || !contractAddress) {
throw new MintIngestorError(MintIngestionErrorName.MissingRequiredData, 'Missing required data');
}

return this.createMintForContract(resources, { chainId, contractAddress, url });
}

Expand Down Expand Up @@ -77,6 +77,7 @@ export class ProhibitionDailyIngestor implements MintIngestor {
contractParams: '[address, 1]',
abi: PROHIBITION_DAILY_ABI,
priceWei: totalPriceWei,

});

const liveDate = new Date() > startDate ? new Date() : startDate;
Expand Down
2 changes: 1 addition & 1 deletion src/ingestors/prohibition-daily/onchain-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const getContract = async (chainId: number, contractAddress: string, alchemy: Al
const contract = new Contract(contractAddress, PROHIBITION_DAILY_ABI, ethersProvider);
return contract;
};

export const getProhibitionContractMetadata = async (
chainId: number,
contractAddress: string,
Expand Down
179 changes: 179 additions & 0 deletions src/ingestors/rarible/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
export const RARIBLE_ABI = [
{
inputs:[],
name:"claimCondition",
outputs: [
{
internalType: "uint256",
name: "currentStartId",
type: "uint256"
},
{
internalType: "uint256",
name: "count",
type: "uint256"
}
],
stateMutability: "view",
type:"function"
},
{
inputs: [
{
internalType:"uint256",
name:"_conditionId",
type:"uint256"
}
],
name: "getClaimConditionById",
outputs: [
{
components:[
{
internalType: "uint256",
name: "startTimestamp",
type: "uint256"
},
{
internalType: "uint256",
name: "maxClaimableSupply",
type: "uint256"
},
{
internalType: "uint256",
name: "supplyClaimed",
type: "uint256"
},
{
internalType: "uint256",
name: "quantityLimitPerWallet",
type: "uint256"
},
{
internalType:"bytes32",
name: "merkleRoot",
type: "bytes32"
},
{
internalType: "uint256",
name: "pricePerToken",
type: "uint256"
},
{
internalType: "address",
name: "currency",
type: "address"
},
{
internalType: "string",
name: "metadata",
type: "string"
}
],
internalType: "struct IClaimCondition.ClaimCondition",
name: "condition",
type:"tuple"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "owner",
outputs: [
{
internalType: "address",
name: "",
type: "address"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "contractURI",
outputs: [
{
internalType: "string",
name: "",
type: "string"
}
],
stateMutability: "view",
type: "function"
},
{
inputs:[],
name: "getActiveClaimConditionId",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "_receiver",
type: "address"
},
{
internalType: "uint256",
name: "_quantity",
type: "uint256"
},
{
internalType: "address",
name: "_currency",
type: "address"
},
{
internalType: "uint256",
name: "_pricePerToken",
type: "uint256"
},
{
components: [
{
internalType: "bytes32[]",
name: "proof",
type: "bytes32[]"
},
{ internalType: "uint256",
name: "quantityLimitPerWallet",
type: "uint256"
},
{ internalType: "uint256",
name: "pricePerToken",
type: "uint256"
},
{
internalType: "address",
name: "currency",
type: "address"
}
],
internalType: "struct IDrop.AllowlistProof",
name: "_allowlistProof",
type: "tuple"
},
{
internalType: "bytes",
name: "_data",
type: "bytes"
}
],
name: "claim",
outputs: [],
stateMutability: "payable",
type: "function"
}
]

111 changes: 111 additions & 0 deletions src/ingestors/rarible/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { MintContractOptions, MintIngestorResources } from "../../lib/types/mint-ingestor";
import { MintInstructionType } from "../../lib/types/mint-template";
import { MintTemplate } from "../../lib/types/mint-template";
import { MintTemplateBuilder } from "../../lib/builder/mint-template-builder";
import { raribleOnchainDataFromUrl, raribleUrlForValidBaseEthCollection, raribleCreatorProfileDataGetter } from "./offchain-metadata";
import { raribleContractMetadataGetter} from "./onchain-metadata";
import { MintIngestionErrorName, MintIngestorError } from "../../lib/types/mint-ingestor-error";
import { RARIBLE_ABI } from "./abi";

export class RaribleIngestor {
async supportsUrl(_resources: MintIngestorResources, url: string): Promise<boolean> {
if (new URL(url).hostname !== "www.rarible.com" && new URL(url).hostname !== "rarible.com") {
return false;
}

const { chainId, contractAddress } = await raribleOnchainDataFromUrl(url)
return !!chainId && !!contractAddress
}

async supportsContract(resources: MintIngestorResources, contract: MintContractOptions): Promise<boolean> {
const { chainId, contractAddress } = contract;
if (!chainId || !contractAddress) {
return false;
}
const url = await raribleUrlForValidBaseEthCollection(chainId, contractAddress, resources.alchemy);
return !!url;
}


async createMintTemplateForUrl(resources: MintIngestorResources, url: string): Promise<MintTemplate> {
const isCompatible = await this.supportsUrl(resources, url);
if (!isCompatible) {
throw new MintIngestorError(MintIngestionErrorName.IncompatibleUrl, "Incompatible URL");
}

const { chainId, contractAddress } = await raribleOnchainDataFromUrl(url);
if (!chainId || !contractAddress) {
throw new MintIngestorError(MintIngestionErrorName.MissingRequiredData, "Missing required data");
}

return this.createMintForContract(resources, { chainId, contractAddress, url });
}

async createMintForContract(resources: MintIngestorResources, contract: MintContractOptions): Promise<MintTemplate> {
const { chainId, contractAddress } = contract;
if (!chainId || !contractAddress) {
throw new MintIngestorError(MintIngestionErrorName.MissingRequiredData, "Missing required data");
}

const isValid = await raribleUrlForValidBaseEthCollection(chainId, contractAddress, resources.alchemy)
if (!isValid) {
throw new MintIngestorError(MintIngestionErrorName.CouldNotResolveMint, "Project not found");
}

const mintBuilder = new MintTemplateBuilder()
.setMintInstructionType(MintInstructionType.EVM_MINT)
.setPartnerName("Rarible");

if (contract.url) {
mintBuilder.setMarketingUrl(contract.url);
}

const {
name,
description,
imageURI,
unitMintPrice,
unitMintTokenAddress,
unitPerWallet,
conditionProof,
ownerAddress,
startDate,
stopDate
} = await raribleContractMetadataGetter(chainId, contractAddress, resources.alchemy)

const {
pName,
pImageUrl,
pDescription,
pWebsiteUrl,
} = await raribleCreatorProfileDataGetter(ownerAddress);

mintBuilder.setName(name).setDescription(description).setFeaturedImageUrl(imageURI);
mintBuilder.setMintOutputContract({ chainId: chainId, address: contractAddress });
mintBuilder.setCreator({
name: pName,
imageUrl: pImageUrl,
description: pDescription,
websiteUrl: pWebsiteUrl,
walletAddress: ownerAddress,
});

mintBuilder.setMintInstructions({
chainId,
contractAddress,
contractMethod: "claim",
contractParams: `[address, 1, "${unitMintTokenAddress}", "${unitMintPrice.toString()}", [["${conditionProof}"], ${unitPerWallet}, "${unitMintPrice.toString()}", "${unitMintTokenAddress}"], "${"0x"}"]`,
abi: RARIBLE_ABI,
priceWei: unitMintPrice.toString(),
});

const liveDate = new Date() > startDate ? new Date() : startDate;

mintBuilder
.setAvailableForPurchaseEnd(stopDate)
.setAvailableForPurchaseStart(startDate)
.setLiveDate(liveDate);

return mintBuilder.build();
}
}
Loading

0 comments on commit 31d6265

Please sign in to comment.