diff --git a/contracts/src/utils/libraries/CustomRevert.sol b/contracts/src/utils/libraries/CustomRevert.sol new file mode 100644 index 000000000..09f3f455f --- /dev/null +++ b/contracts/src/utils/libraries/CustomRevert.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +/// @title Library for reverting with custom errors efficiently +/// @notice Contains functions for reverting with custom errors with different argument types efficiently +/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with +/// `CustomError.selector.revertWith()` +/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately +library CustomRevert { + /// @dev Reverts with the selector of a custom error in the scratch space + function revertWith(bytes4 selector) internal pure { + assembly ("memory-safe") { + mstore(0, selector) + revert(0, 0x04) + } + } + + /// @dev Reverts with a custom error with a uint256 argument in the scratch space + function revertWith(bytes4 selector, uint256 value) internal pure { + assembly ("memory-safe") { + mstore(0, selector) + mstore(0x04, value) + revert(0, 0x24) + } + } + + /// @dev Reverts with a custom error with an address argument in the scratch space + function revertWith(bytes4 selector, address addr) internal pure { + assembly ("memory-safe") { + mstore(0, selector) + mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff)) + revert(0, 0x24) + } + } +} diff --git a/packages/stream-metadata/src/environment.ts b/packages/stream-metadata/src/environment.ts index 732feb6ab..dd461beb5 100644 --- a/packages/stream-metadata/src/environment.ts +++ b/packages/stream-metadata/src/environment.ts @@ -1,6 +1,7 @@ import * as dotenv from 'dotenv' import { getWeb3Deployment } from '@river-build/web3' import { z } from 'zod' +import { v4 } from 'uuid' dotenv.config({ path: ['.env', '.env.local'], @@ -52,6 +53,10 @@ function makeConfig() { pretty: envMain.LOG_PRETTY, }, aws: envAws?.success ? envAws.data : undefined, + instance: { + id: v4(), + deployedAt: new Date().toISOString(), + }, } } diff --git a/packages/stream-metadata/src/logger.ts b/packages/stream-metadata/src/logger.ts index b19463d8d..28bc8beb2 100644 --- a/packages/stream-metadata/src/logger.ts +++ b/packages/stream-metadata/src/logger.ts @@ -18,5 +18,5 @@ const pinoOptions: LoggerOptions = { const baseLogger = pino(pinoOptions) export function getLogger(name: string, meta: Record = {}) { - return baseLogger.child({ name, ...meta }) + return baseLogger.child({ name, instance: config.instance, ...meta }) } diff --git a/packages/stream-metadata/src/opensea.ts b/packages/stream-metadata/src/opensea.ts index 0e05376d5..1a81179b8 100644 --- a/packages/stream-metadata/src/opensea.ts +++ b/packages/stream-metadata/src/opensea.ts @@ -5,16 +5,20 @@ import { FastifyBaseLogger } from 'fastify' import { config } from './environment' import { spaceDapp } from './contract-utils' -const getOpenSeaAPIUrl = (space: SpaceInfo) => { +const getOpenSeaAPIUrl = (logger: FastifyBaseLogger, space: SpaceInfo) => { const spaceOwnerAddress = config.web3Config.base.addresses.spaceOwner + const chainId = config.web3Config.base.chainId const tokenId = BigNumber.from(space.tokenId).toString() - if (space.networkId === String(BASE_MAINNET)) { + if (chainId === BASE_MAINNET) { return `https://api.opensea.io/api/v2/chain/base/contract/${spaceOwnerAddress}/nfts/${tokenId}/refresh` - } else if (space.networkId === String(BASE_SEPOLIA)) { + } else if (chainId === BASE_SEPOLIA) { + return `https://testnets-api.opensea.io/api/v2/chain/base_sepolia/contract/${spaceOwnerAddress}/nfts/${tokenId}/refresh` + } else if (chainId === 31337) { return `https://testnets-api.opensea.io/api/v2/chain/base_sepolia/contract/${spaceOwnerAddress}/nfts/${tokenId}/refresh` } else { - throw new Error('Unsupported network') + logger.error({ chainId }, 'Unsupported network') + throw new Error(`Unsupported network ${chainId}`) } } @@ -40,7 +44,7 @@ export const refreshOpenSea = async ({ throw new Error('Space not found') } - const url = getOpenSeaAPIUrl(space) + const url = getOpenSeaAPIUrl(logger, space) logger.info({ url, spaceAddress }, 'refreshing openSea') const response = await fetch(url, {