Skip to content

Commit

Permalink
Merge pull request #46 from floornfts/chris/quantity-zora-rodeo
Browse files Browse the repository at this point in the history
Add quantity support for Rodeo & regular Zora mints
  • Loading branch information
chrismaddern authored Aug 27, 2024
2 parents 7d98b28 + e471e3b commit 2f0f985
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/ingestors/rodeo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ export class RodeoIngestor implements MintIngestor {
chainId,
contractAddress: mintAddress,
contractMethod: 'mintFromFixedPriceSale',
contractParams: `[${sale_terms_id}, 1, address, "${user.address}"]`,
contractParams: `[${sale_terms_id}, quantity, address, "${user.address}"]`,
abi: RODEO_ABI,
priceWei: totalPrice,
mintFeePerTokenWei: totalPrice,
supportsQuantity: true,
});

const startDate = public_sale_start_at ? new Date(public_sale_start_at) : new Date();
Expand Down
1 change: 1 addition & 0 deletions src/ingestors/zora-internal/zora-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export class ZoraMetadataProvider {
abi = ZORA_FIXED_PRICE_ABI;
contractAddress = tokenDetails.collection.address;
method = 'mint';
supportsQuantity = true;
params = `["${ZORA_FIXED_PRICE_STRATEGY_ADDRESS}", tokenId, quantity, ["${FLOOR_REFERRER_REWARDS_ADDRESS}"], encodedAddress]`;
}

Expand Down
12 changes: 8 additions & 4 deletions src/lib/simulation/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const simulateEVMTransactionWithAlchemy = async (
quantity: number,
blockNumber?: string,
): Promise<{ message: string; success: boolean; rawSimulationResult: any }> => {
const amount = mintInstructions.supportsQuantity
? (BigInt(quantity) * BigInt(mintInstructions.mintFeePerTokenWei)).toString()
: mintInstructions.mintFeePerTokenWei || mintInstructions.priceWei || '0';
const network = NETWORKS[mintInstructions.chainId];
if (!network) {
console.log(`Unsupported chainId: ${mintInstructions.chainId}. Defaulting to success for now.`);
Expand All @@ -35,9 +38,7 @@ export const simulateEVMTransactionWithAlchemy = async (
to: mintInstructions.contractAddress,
from: SIGNER1_WALLET,
data: data,
value: BigNumber.from(mintInstructions.priceWei || '0')
.toHexString()
.replace('0x0', '0x'),
value: BigNumber.from(amount).toHexString().replace('0x0', '0x'),
};

const simResult = await alchemy.transact.simulateExecution(tx, blockNumber ? blockNumber : undefined);
Expand Down Expand Up @@ -79,12 +80,15 @@ export const simulateEVMTransactionWithTenderly = async (
blockNumber?: string,
): Promise<{ message: string; success: boolean; rawSimulationResult: any }> => {
const tenderly = new Tenderly();
const amount = mintInstructions.supportsQuantity
? (BigInt(quantity) * BigInt(mintInstructions.mintFeePerTokenWei)).toString()
: mintInstructions.mintFeePerTokenWei || mintInstructions.priceWei || '0';

const tx = {
to: mintInstructions.contractAddress,
from: SIGNER1_WALLET,
data: dataForMintInstructions(mintInstructions, quantity),
value: BigNumber.from(mintInstructions.priceWei || '0')
value: BigNumber.from(amount || '0')
.toHexString()
.replace('0x0', '0x'),
chainId: mintInstructions.chainId,
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/mint-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type EVMMintInstructionsInput = {
priceWei: string;
supportsQuantity?: boolean | undefined;
defaultQuantity?: number | undefined;
mintFeePerTokenWei?: string | undefined;
};

export type EVMMintInstructions = EVMMintInstructionsInput & {
Expand Down
25 changes: 18 additions & 7 deletions test/ingestors/rodeo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ describe('Rodeo', function () {
'https://rodeo.club/post/0x68227a4390c15AcEf9265d9B8F65d3fb5cD9f85B/1',
'https://rodeo.club/post/0x6511cB5ec4dbe28a6F2cbc40d2d1030b6CaBC911/10',
],
failureUrls: ['https://rodeo.club/post/0x68227a4390c15AcEf9265d9B8F65d3fb5cD9f85', 'https://www.transient.xyz/stacks'],
failureUrls: [
'https://rodeo.club/post/0x68227a4390c15AcEf9265d9B8F65d3fb5cD9f85',
'https://www.transient.xyz/stacks',
],
successContracts: [
{ chainId: 8453, contractAddress: '0x68227a4390c15AcEf9265d9B8F65d3fb5cD9f85B', tokenId: '1' },
{ chainId: 8453, contractAddress: '0x6511cB5ec4dbe28a6F2cbc40d2d1030b6CaBC911', tokenId: '10' },
Expand Down Expand Up @@ -44,7 +47,7 @@ describe('Rodeo', function () {
description: null,
contractAddress: '0x132363a3bbf47E06CF642dd18E9173E364546C99',
contractMethod: 'mintFromFixedPriceSale',
contractParams: `[5562, 1, address, "0x18FfAD7FEc51119C55368607e43E6a986edaa831"]`,
contractParams: `[5562, quantity, address, "0x18FfAD7FEc51119C55368607e43E6a986edaa831"]`,
priceWei: '100000000000000',
featuredImageUrlPattern: /https:\/\/f8n-production-collection-ass.+/,
availableForPurchaseStart: '2024-08-06T05:47:19',
Expand Down Expand Up @@ -77,8 +80,12 @@ describe('Rodeo', function () {
expect(template.featuredImageUrl).to.match(expected.featuredImageUrlPattern);

expect(template.marketingUrl).to.equal(input.url);
expect(template.availableForPurchaseStart?.getTime()).to.equal(new Date(expected.availableForPurchaseStart).getTime());
expect(template.availableForPurchaseEnd?.getTime()).to.equal(new Date(expected.availableForPurchaseEnd).getTime());
expect(template.availableForPurchaseStart?.getTime()).to.equal(
new Date(expected.availableForPurchaseStart).getTime(),
);
expect(template.availableForPurchaseEnd?.getTime()).to.equal(
new Date(expected.availableForPurchaseEnd).getTime(),
);
});
});
});
Expand All @@ -91,7 +98,7 @@ describe('Rodeo', function () {
chainId: testCase.chainId,
contractAddress: testCase.expected.outputContractAddress,
url: testCase.input.url,
tokenId: testCase.input.tokenId
tokenId: testCase.input.tokenId,
};
const template = await ingestor.createMintForContract(resources, contract);

Expand All @@ -113,8 +120,12 @@ describe('Rodeo', function () {
expect(template.featuredImageUrl?.length).to.be.greaterThan(0);

expect(template.marketingUrl).to.equal(contract.url);
expect(template.availableForPurchaseStart?.getTime()).to.equal(new Date(testCase.expected.availableForPurchaseStart).getTime());
expect(template.availableForPurchaseEnd?.getTime()).to.equal(new Date(testCase.expected.availableForPurchaseEnd).getTime());
expect(template.availableForPurchaseStart?.getTime()).to.equal(
new Date(testCase.expected.availableForPurchaseStart).getTime(),
);
expect(template.availableForPurchaseEnd?.getTime()).to.equal(
new Date(testCase.expected.availableForPurchaseEnd).getTime(),
);
});
}
});
Expand Down

0 comments on commit 2f0f985

Please sign in to comment.