-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from s29papi/raribleIngestor
raribleIngestor
- Loading branch information
Showing
17 changed files
with
777 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,4 +129,6 @@ dist | |
.yarn/install-state.gz | ||
.pnp.* | ||
.DS_Store | ||
**/.DS_Store | ||
**/.DS_Store | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.