diff --git a/apps/subgraph/.gitignore b/apps/subgraph/.gitignore index 029e16cd9..53614990e 100644 --- a/apps/subgraph/.gitignore +++ b/apps/subgraph/.gitignore @@ -1,4 +1,5 @@ /build /generated /data -.env \ No newline at end of file +.env +subgraph.yaml \ No newline at end of file diff --git a/apps/subgraph/config/base-goerli.json b/apps/subgraph/config/base-goerli.json new file mode 100644 index 000000000..f36807468 --- /dev/null +++ b/apps/subgraph/config/base-goerli.json @@ -0,0 +1,7 @@ +{ + "network": "base-goerli", + "manager": { + "address": "0x550c326d688fD51ae65AC6A2d48749E631023A03", + "startBlock": 6585050 + } +} diff --git a/apps/subgraph/config/base.json b/apps/subgraph/config/base.json new file mode 100644 index 000000000..4b2f5dddf --- /dev/null +++ b/apps/subgraph/config/base.json @@ -0,0 +1,7 @@ +{ + "network": "base", + "manager": { + "address": "0x3ac0e64fe2931f8e082c6bb29283540de9b5371c", + "startBlock": 1991500 + } +} diff --git a/apps/subgraph/config/goerli.json b/apps/subgraph/config/goerli.json new file mode 100644 index 000000000..9ceb97b50 --- /dev/null +++ b/apps/subgraph/config/goerli.json @@ -0,0 +1,7 @@ +{ + "network": "goerli", + "manager": { + "address": "0x0E9F3382Cf2508E3bc83248B5b4707FbA86D7Ee0", + "startBlock": 7810600 + } +} diff --git a/apps/subgraph/config/mainnet.json b/apps/subgraph/config/mainnet.json new file mode 100644 index 000000000..4f69e2b50 --- /dev/null +++ b/apps/subgraph/config/mainnet.json @@ -0,0 +1,7 @@ +{ + "network": "mainnet", + "manager": { + "address": "0xd310a3041dfcf14def5ccbc508668974b5da7174", + "startBlock": 15799000 + } +} diff --git a/apps/subgraph/config/optimism-goerli.json b/apps/subgraph/config/optimism-goerli.json new file mode 100644 index 000000000..842d04418 --- /dev/null +++ b/apps/subgraph/config/optimism-goerli.json @@ -0,0 +1,7 @@ +{ + "network": "optimism-goerli", + "manager": { + "address": "0x5f9c1e7E31875beAa6ba6B0AB573a4AbEcC95d67", + "startBlock": 11032400 + } +} diff --git a/apps/subgraph/config/optimism.json b/apps/subgraph/config/optimism.json new file mode 100644 index 000000000..7a51227f9 --- /dev/null +++ b/apps/subgraph/config/optimism.json @@ -0,0 +1,7 @@ +{ + "network": "optimism", + "manager": { + "address": "0x3ac0E64Fe2931f8e082C6Bb29283540DE9b5371C", + "startBlock": 107290000 + } +} diff --git a/apps/subgraph/config/zora-goerli.json b/apps/subgraph/config/zora-goerli.json new file mode 100644 index 000000000..c842dac15 --- /dev/null +++ b/apps/subgraph/config/zora-goerli.json @@ -0,0 +1,7 @@ +{ + "network": "zora-testnet", + "manager": { + "address": "0xc521f85613985b7e417fccd5b348f64263d79397", + "startBlock": 597700 + } +} diff --git a/apps/subgraph/config/zora.json b/apps/subgraph/config/zora.json new file mode 100644 index 000000000..ca3a84ab3 --- /dev/null +++ b/apps/subgraph/config/zora.json @@ -0,0 +1,7 @@ +{ + "network": "zora-mainnet", + "manager": { + "address": "0x3ac0E64Fe2931f8e082C6Bb29283540DE9b5371C", + "startBlock": 1778012 + } +} diff --git a/apps/subgraph/package.json b/apps/subgraph/package.json index 4ecd607c5..f26408603 100644 --- a/apps/subgraph/package.json +++ b/apps/subgraph/package.json @@ -2,19 +2,35 @@ "name": "nouns-builder-subgraph", "license": "UNLICENSED", "scripts": { + "clean": "rm -rf ./generated ./build subgraph.yaml", "local-node": "docker-compose up", "codegen": "graph codegen", - "build": "pnpm codegen && graph build", - "deploy": "graph deploy --product hosted-service neokry/nouns-builder-goerli", - "create-local": "graph create --node http://localhost:8020/ nouns-builder", - "remove-local": "graph remove --node http://localhost:8020/ nouns-builder", - "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 --network goerli nouns-builder" + "prepare:goerli": "mustache config/goerli.json subgraph.yaml.mustache > subgraph.yaml", + "prepare:mainnet": "mustache config/mainnet.json subgraph.yaml.mustache > subgraph.yaml", + "prepare:base": "mustache config/base.json subgraph.yaml.mustache > subgraph.yaml", + "prepare:base-goerli": "mustache config/base-goerli.json subgraph.yaml.mustache > subgraph.yaml", + "prepare:optimism": "mustache config/optimism.json subgraph.yaml.mustache > subgraph.yaml", + "prepare:optimism-goerli": "mustache config/optimism-goerli.json subgraph.yaml.mustache > subgraph.yaml", + "prepare:zora": "mustache config/zora.json subgraph.yaml.mustache > subgraph.yaml", + "prepare:zora-goerli": "mustache config/zora-goerli.json subgraph.yaml.mustache > subgraph.yaml", + "deploy:goerli": "pnpm clean && pnpm prepare:goerli && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-goerli-testnet/1.0.2", + "deploy:mainnet": "pnpm clean && pnpm prepare:mainnet && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-ethereum-mainnet/1.0.2", + "deploy:base": "pnpm clean && pnpm prepare:base && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-base-mainnet/1.0.2", + "deploy:base-goerli": "pnpm clean && pnpm prepare:base-goerli && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-base-testnet/1.0.2", + "deploy:optimism": "pnpm clean && pnpm prepare:optimism && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-optimism-mainnet/1.0.2", + "deploy:optimism-goerli": "pnpm clean && pnpm prepare:optimism-goerli && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-optimism-testnet/1.0.2", + "deploy:zora": "pnpm clean && pnpm prepare:zora && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-zora-mainnet/1.0.2", + "deploy:zora-goerli": "pnpm clean && pnpm prepare:zora-goerli && pnpm codegen && graph build && goldsky subgraph deploy nouns-builder-zora-testnet/1.0.2", + "create:local": "graph create --node http://localhost:8020/ nouns-builder", + "remove:local": "graph remove --node http://localhost:8020/ nouns-builder", + "deploy:local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 --network goerli nouns-builder" }, "dependencies": { "@graphprotocol/graph-cli": "0.50.1", "@graphprotocol/graph-ts": "0.30.0" }, "devDependencies": { - "matchstick-as": "0.5.0" + "matchstick-as": "0.5.0", + "mustache": "^4.2.0" } } diff --git a/apps/subgraph/src/token.ts b/apps/subgraph/src/token.ts index 80a9399d5..e9b5f34d9 100644 --- a/apps/subgraph/src/token.ts +++ b/apps/subgraph/src/token.ts @@ -26,7 +26,14 @@ export function handleTransfer(event: TransferEvent): void { token = new Token(tokenId) token.name = `${tokenContract.name()} #${event.params.tokenId.toString()}` - token.image = `${metadataContract.rendererBase()}${attributes.value1}` + + // Replace zora renderer with our own until a redirect is setup + const rendererBase = metadataContract + .rendererBase() + .replace('https://api.zora.co', 'https://nouns.build/api') + + token.image = `${rendererBase}${attributes.value1}` + token.tokenContract = event.address token.tokenId = event.params.tokenId token.mintedAt = event.block.timestamp diff --git a/apps/subgraph/subgraph.yaml b/apps/subgraph/subgraph.yaml.mustache similarity index 95% rename from apps/subgraph/subgraph.yaml rename to apps/subgraph/subgraph.yaml.mustache index 491a1fe7c..6d07ecc4e 100644 --- a/apps/subgraph/subgraph.yaml +++ b/apps/subgraph/subgraph.yaml.mustache @@ -4,11 +4,11 @@ schema: dataSources: - kind: ethereum name: Manager - network: goerli + network: {{network}} source: abi: Manager - address: '0x0E9F3382Cf2508E3bc83248B5b4707FbA86D7Ee0' - startBlock: 7810600 + address: '{{manager.address}}' + startBlock: {{manager.startBlock}} mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -32,7 +32,7 @@ dataSources: templates: - kind: ethereum name: Token - network: goerli + network: {{network}} source: abi: Token mapping: @@ -54,7 +54,7 @@ templates: file: ./src/token.ts - kind: ethereum name: Governor - network: goerli + network: {{network}} source: abi: Governor mapping: @@ -85,7 +85,7 @@ templates: file: ./src/governor.ts - kind: ethereum name: MetadataRenderer - network: goerli + network: {{network}} source: abi: MetadataRenderer mapping: @@ -107,7 +107,7 @@ templates: file: ./src/metadata.ts - kind: ethereum name: Auction - network: goerli + network: {{network}} source: abi: Auction mapping: diff --git a/apps/web/next.config.js b/apps/web/next.config.js index 65d3636ac..af16079cb 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -20,6 +20,7 @@ const nextConfig = { 'zora-dev.mypinata.cloud', 'ipfs.zora.co', 'ipfs.decentralized-content.com', + 'nouns.build', ], }, async redirects() { diff --git a/apps/web/src/constants/cacheTimes.ts b/apps/web/src/constants/cacheTimes.ts index 95ae308ac..fbb487da4 100644 --- a/apps/web/src/constants/cacheTimes.ts +++ b/apps/web/src/constants/cacheTimes.ts @@ -40,4 +40,8 @@ export const CACHE_TIMES = { maxAge: ONE_DAY, swr: ONE_WEEK, }, + RENDERER: { + maxAge: ONE_DAY, + swr: ONE_WEEK, + }, } diff --git a/apps/web/src/pages/api/renderer/stack-images.ts b/apps/web/src/pages/api/renderer/stack-images.ts index 932e5e578..9a9d4d4a1 100644 --- a/apps/web/src/pages/api/renderer/stack-images.ts +++ b/apps/web/src/pages/api/renderer/stack-images.ts @@ -3,16 +3,24 @@ import { getFetchableUrl } from 'ipfs-service' import { NextApiRequest, NextApiResponse } from 'next' import sharp from 'sharp' +import { CACHE_TIMES } from 'src/constants/cacheTimes' + const handler = async (req: NextApiRequest, res: NextApiResponse) => { const images = req.query.images if (!images || !images.length) return res.status(400).json({ error: 'No images provided' }) + const { maxAge, swr } = CACHE_TIMES.DAO_FEED + // Handle single image if (typeof images === 'string') { const data = await getImageData(images) + res.setHeader( + 'Cache-Control', + `public, s-maxage=${maxAge}, stale-while-revalidate=${swr}` + ) res.setHeader('Content-Type', 'image/webp') return res.send(data) } @@ -30,6 +38,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { .webp({ quality: 100 }) .toBuffer() + res.setHeader( + 'Cache-Control', + `public, s-maxage=${maxAge}, stale-while-revalidate=${swr}` + ) res.setHeader('Content-Type', 'image/webp') res.send(compositeRes) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ea74b4353..15abae90f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ importers: matchstick-as: specifier: 0.5.0 version: 0.5.0 + mustache: + specifier: ^4.2.0 + version: 4.2.0 apps/web: dependencies: @@ -11906,6 +11909,11 @@ packages: resolution: {integrity: sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==} dev: false + /mustache@4.2.0: + resolution: {integrity: sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==} + hasBin: true + dev: true + /mute-stream@0.0.8: resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} dev: true