-
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 branch 'main' into raribleIngestor
- Loading branch information
Showing
11 changed files
with
579 additions
and
15 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
File renamed without changes.
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,42 @@ | ||
export const TRANSIENT_BASE_ABI = [ | ||
{ | ||
inputs: [], | ||
name: 'protocolFee', | ||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: 'address', name: 'nftAddress', type: 'address' }, | ||
{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }, | ||
{ internalType: 'address', name: 'recipient', type: 'address' }, | ||
{ internalType: 'uint256', name: 'numberToMint', type: 'uint256' }, | ||
{ internalType: 'uint256', name: 'presaleNumberCanMint', type: 'uint256' }, | ||
{ internalType: 'bytes32[]', name: 'proof', type: 'bytes32[]' }, | ||
], | ||
name: 'purchase', | ||
outputs: [{ internalType: 'uint256', name: 'refundAmount', type: 'uint256' }], | ||
stateMutability: 'payable', | ||
type: 'function', | ||
}, | ||
]; | ||
|
||
/** | ||
* This ABI also works for ERC721TL contracts | ||
*/ | ||
export const TRANSIENT_ERC7160TL_ABI = [ | ||
{ | ||
inputs: [ | ||
{ internalType: 'address', name: 'nftAddress', type: 'address' }, | ||
{ internalType: 'address', name: 'recipient', type: 'address' }, | ||
{ internalType: 'uint256', name: 'numberToMint', type: 'uint256' }, | ||
{ internalType: 'uint256', name: 'presaleNumberCanMint', type: 'uint256' }, | ||
{ internalType: 'bytes32[]', name: 'proof', type: 'bytes32[]' }, | ||
], | ||
name: 'purchase', | ||
outputs: [{ internalType: 'uint256', name: 'refundAmount', type: 'uint256' }], | ||
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,122 @@ | ||
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 { TRANSIENT_BASE_ABI, TRANSIENT_ERC7160TL_ABI } from './abi'; | ||
import { | ||
getTransientBaseMintByAddressAndChain, | ||
getTransientBaseMintByURL, | ||
transientSupports, | ||
} from './offchain-metadata'; | ||
|
||
import { BigNumber } from 'alchemy-sdk'; | ||
import { MintTemplateBuilder } from '../../lib/builder/mint-template-builder'; | ||
import { getTransientProtocolFeeInEth } from './onchain-metadata'; | ||
|
||
export class TransientIngestor implements MintIngestor { | ||
configuration = { | ||
supportsContractIsExpensive: true, | ||
}; | ||
|
||
async supportsUrl(resources: MintIngestorResources, url: string): Promise<boolean> { | ||
if (new URL(url).hostname !== 'www.transient.xyz') { | ||
return false; | ||
} | ||
try { | ||
const { chainId, contractAddress } = await getTransientBaseMintByURL(resources, url); | ||
return !!chainId && !!contractAddress; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
async supportsContract(resources: MintIngestorResources, contract: MintContractOptions): Promise<boolean> { | ||
const { chainId, contractAddress } = contract; | ||
if (!chainId || !contractAddress) { | ||
return false; | ||
} | ||
return await transientSupports(contract, resources); | ||
} | ||
|
||
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 getTransientBaseMintByURL(resources, 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 mintBuilder = new MintTemplateBuilder() | ||
.setMintInstructionType(MintInstructionType.EVM_MINT) | ||
.setPartnerName('Transient'); | ||
|
||
if (contract.url) { | ||
mintBuilder.setMarketingUrl(contract.url); | ||
} | ||
|
||
// asides name and image no other metadata we need is onchain so we can just use the offchain metadata | ||
const { | ||
name, | ||
image, | ||
description, | ||
priceInWei, | ||
mintAddress, | ||
public_sale_start_at, | ||
public_sale_end_at, | ||
token_id, | ||
contract_type, | ||
user, | ||
} = await getTransientBaseMintByAddressAndChain(resources, contract.chainId, contract.contractAddress); | ||
|
||
mintBuilder.setName(name).setDescription(description).setFeaturedImageUrl(image); | ||
const protocolFee = await getTransientProtocolFeeInEth(chainId, mintAddress, resources.alchemy); | ||
const totalPrice = BigNumber.from(priceInWei).add(BigNumber.from(protocolFee)).toString(); | ||
|
||
mintBuilder.setMintOutputContract({ | ||
chainId, | ||
address: contractAddress, | ||
}); | ||
|
||
mintBuilder.setCreator({ | ||
name: user.name, | ||
imageUrl: user.image, | ||
websiteUrl: user.website, | ||
}); | ||
|
||
mintBuilder.setMintInstructions({ | ||
chainId, | ||
contractAddress: mintAddress, | ||
contractMethod: 'purchase', | ||
contractParams: | ||
contract_type == 'ERC1155TL' | ||
? `["${contractAddress}", ${token_id}, address, 1, 0, []]` | ||
: `["${contractAddress}", address, 1, 0, []]`, | ||
abi: contract_type == 'ERC1155TL' ? TRANSIENT_BASE_ABI : TRANSIENT_ERC7160TL_ABI, | ||
priceWei: totalPrice, | ||
}); | ||
|
||
const startDate = public_sale_start_at ? new Date(public_sale_start_at) : new Date(); | ||
const endDate = public_sale_end_at ? new Date(public_sale_end_at) : null; | ||
|
||
const liveDate = new Date() > startDate ? new Date() : startDate; | ||
mintBuilder | ||
.setAvailableForPurchaseEnd(endDate || new Date('2030-01-01')) | ||
.setAvailableForPurchaseStart(startDate || new Date()) | ||
.setLiveDate(liveDate); | ||
|
||
const output = mintBuilder.build(); | ||
return output; | ||
} | ||
} |
Oops, something went wrong.