ourzora / zora-protocol

Monorepo for Zora Protocol (contracts & sdks)
MIT License
116 stars 72 forks source link

Incorrect result when checking if the secondary market is active for a token #452

Open AlexRFD opened 1 day ago

AlexRFD commented 1 day ago

When checking if the secondary market is active with the collectorClient.getToken( ... ) method I get incorrect results.

Example for token 0x07b72045a5997e51ef4f701cd06542ef1cdc7536 and tokenId 143

const collectorClient = createCollectorClient({
    chainId: zora.id,
    publicClient
});

const result = await collectorClient.getToken({
    tokenContract: '0x07b72045a5997e51ef4f701cd06542ef1cdc7536',
    mintType: '1155',
    tokenId: 143
});

console.log(result);
// Response
// {
//  token: {
//      contract: {
//          address: '0x07b72045a5997e51ef4f701cd06542ef1cdc7536',
//          name: 'Zora Posts',
//          URI: 'https://zora.co/api/metadata/0x003173f6804e8fc9078ba365fd730c5f0bcfd30e.json'
//      },
//      tokenURI:
//          'ipfs://bafybeibph2diisaor54olaqdi6tji45cdwlvp4u3755exh2d5cgjy2zpiu',
//      tokenId: '143',
//      mintType: '1155',
//      creator: '0xf1cf4e07e4e9ea602f3bf5fc4e247d16ad724c2e',
//      totalMinted: '336',
//      maxSupply: '18446744073709551615',
//      contractVersion: '2.12.3'
//  },
//  primaryMintActive: false,
//  secondaryMarketActive: false
// }

If I do a custom read contract operation on the timed strategy deployed contract I get the correct result

const { data } = useReadContract({
    chainId: zora.id,
    abi: zoraTimedSaleStrategyABI,
    address: zoraTimedSaleStrategyAddress[zora.id],
    functionName: 'sale',
    args: ['0x07b72045a5997e51ef4f701cd06542ef1cdc7536', BigInt(143)]
});
// Response
// {
//  "erc20zAddress": "0x26B03fF1d953cCBAB1f1bf038e353F39D743Eb1f",
//  "saleStart": "1727870581",
//  "poolAddress": "0xF5F842f2844b19Ba89E5ef3aB024b6D4DFfeBe61",
//  "saleEnd": "1727991189",
//  "secondaryActivated": true
// }

I checked the network operation going out when i call client.getToken( ... ) and it's also returning the correct info so I drilled down on how the response is parsed and I think I've identified the problem. In the lines I've linked below, there's an initial filter that first gets rid of all the saleStrategies that have saleActive set to false. This ends up returning an empty array for valid strategies even though secondaryMarketActive is true so that results in all the downstream calls to mark this token as unavailable to mint or buy on secondary.

https://github.com/ourzora/zora-protocol/blob/54ceed4b00337aa7894c097c2e03b80e987099bf/packages/protocol-sdk/src/mint/subgraph-mint-getter.ts#L177-L189

iainnash commented 1 day ago

Good catch! I've written your proposed fix and will get it in the next release.

AlexRFD commented 1 day ago

Thank you @iainnash