Skip to content

Commit

Permalink
Merge branch 'main' into g/net-74-add-new-create-space-with-prepay-fu…
Browse files Browse the repository at this point in the history
…nction-to-architect
  • Loading branch information
giuseppecrj committed Sep 9, 2024
2 parents a9f61e5 + 2d8c5d3 commit 9343cdc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
35 changes: 35 additions & 0 deletions contracts/src/utils/libraries/CustomRevert.sol
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
5 changes: 5 additions & 0 deletions packages/stream-metadata/src/environment.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down Expand Up @@ -52,6 +53,10 @@ function makeConfig() {
pretty: envMain.LOG_PRETTY,
},
aws: envAws?.success ? envAws.data : undefined,
instance: {
id: v4(),
deployedAt: new Date().toISOString(),
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stream-metadata/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const pinoOptions: LoggerOptions = {
const baseLogger = pino(pinoOptions)

export function getLogger(name: string, meta: Record<string, unknown> = {}) {
return baseLogger.child({ name, ...meta })
return baseLogger.child({ name, instance: config.instance, ...meta })
}
14 changes: 9 additions & 5 deletions packages/stream-metadata/src/opensea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}

Expand All @@ -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, {
Expand Down

0 comments on commit 9343cdc

Please sign in to comment.