Skip to content

Commit

Permalink
Merge pull request #362 from ourzora/remove-ethers
Browse files Browse the repository at this point in the history
Remove ethers
  • Loading branch information
neokry authored May 10, 2024
2 parents cf88f47 + 8ea0a6b commit 5d80d0d
Show file tree
Hide file tree
Showing 52 changed files with 384 additions and 554 deletions.
65 changes: 32 additions & 33 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["typescript", "typescriptreact"],
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/node_modules": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.validate": ["typescript", "typescriptreact"],
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/node_modules": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
2 changes: 2 additions & 0 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const nextConfig = {
sideEffects: false,
})

config.resolve.fallback = { fs: false, net: false, tls: false }

return {
...config,
// Hot-fix for $RefreshReg issues: https://github.com/vanilla-extract-css/vanilla-extract/issues/679#issuecomment-1402839249
Expand Down
3 changes: 0 additions & 3 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"generate-abis": "node ./scripts/generate-abis.js"
},
"dependencies": {
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@farcaster/hub-nodejs": "^0.8.0",
"@fontsource/inter": "4.5.10",
"@fontsource/londrina-solid": "^4.5.9",
Expand All @@ -35,7 +33,6 @@
"bignumber.js": "^9.1.0",
"blocklist": "workspace:*",
"dayjs": "^1.11.3",
"ethers": "^5.6.9",
"flatpickr": "^4.6.13",
"formik": "^2.2.9",
"framer-motion": "^6.3.3",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/Fields/SmartInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormikProps } from 'formik'
import { motion } from 'framer-motion'
import React, { ChangeEventHandler, ReactElement, WheelEvent } from 'react'
import useSWR from 'swr'
import { Address } from 'wagmi'

import { Icon } from 'src/components/Icon'
import SWR_KEYS from 'src/constants/swrKeys'
Expand Down Expand Up @@ -63,7 +64,7 @@ const SmartInput: React.FC<SmartInputProps> = ({
}) => {
const { data: ensName } = useSWR(
isAddress ? [SWR_KEYS.ENS, value] : null,
async () => await getEnsName(value as string)
async () => await getEnsName(value as Address)
)

/*
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Fields/yup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ethers } from 'ethers'
import { isAddress } from 'viem'

export function isValidAddress(this: any, message: any) {
return this.test('isValidAddress', message, (value: string) => {
const { path, createError } = this

if (!ethers.utils.isAddress(value)) {
if (!isAddress(value)) {
return createError({ path, message: message ?? 'address provided is invalid.' })
}

Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/data/contract/requests/getDAOAddresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ethers } from 'ethers'
import { readContract } from 'wagmi/actions'

import { PUBLIC_MANAGER_ADDRESS } from 'src/constants/addresses'
import { NULL_ADDRESS, PUBLIC_MANAGER_ADDRESS } from 'src/constants/addresses'
import { AddressType, CHAIN_ID } from 'src/typings'
import { unpackOptionalArray } from 'src/utils/helpers'

Expand All @@ -18,9 +17,7 @@ const getDAOAddresses = async (chainId: CHAIN_ID, tokenAddress: AddressType) =>

const [metadata, auction, treasury, governor] = unpackOptionalArray(addresses, 4)

const hasMissingAddresses = Object.values(addresses).includes(
ethers.constants.AddressZero
)
const hasMissingAddresses = Object.values(addresses).includes(NULL_ADDRESS)
if (hasMissingAddresses) return null

return {
Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/hooks/useIsContract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ethers } from 'ethers'
import useSWRImmutable from 'swr/immutable'

import { RPC_URL } from 'src/constants/rpc'
import { AddressType, CHAIN_ID } from 'src/typings'
import { getProvider } from 'src/utils/provider'

export const useIsContract = ({
address,
Expand All @@ -12,7 +11,7 @@ export const useIsContract = ({
chainId?: CHAIN_ID
}) => {
return useSWRImmutable(address ? [address, chainId] : undefined, async (address) => {
const provider = new ethers.providers.JsonRpcProvider(RPC_URL[chainId])
return await provider.getCode(address).then((x) => x !== '0x')
const provider = getProvider(chainId)
return await provider.getBytecode({ address }).then((x) => x !== '0x')
})
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dayjs from 'dayjs'
import { ethers } from 'ethers'
import { useRouter } from 'next/router'
import React, { Fragment, useState } from 'react'
import { formatEther } from 'viem'
import { useContractRead } from 'wagmi'

import { auctionAbi } from 'src/data/contract/abis'
Expand Down Expand Up @@ -59,7 +59,7 @@ export const CurrentAuction = ({
}

const isOver = !!endTime ? dayjs.unix(Date.now() / 1000) >= dayjs.unix(endTime) : true
const formattedBid = bid ? ethers.utils.formatEther(bid) : ''
const formattedBid = bid ? formatEther(bid) : ''

// Set the referral if auction version is != 1 and query.referral is present
const referral =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const PlaceBid = ({
addresses.token
? [SWR_KEYS.AVERAGE_WINNING_BID, chain.id, addresses.token]
: undefined,
() => averageWinningBid(chain.id, addresses.token as Address),
() => averageWinningBid(chain.id, addresses.token as Address)
)

const isMinBid = Number(bidAmount) >= minBidAmount
Expand Down Expand Up @@ -124,11 +124,11 @@ export const PlaceBid = ({
if (tx?.hash) await waitForTransaction({ hash: tx.hash })

await mutate([SWR_KEYS.AUCTION_BIDS, chain.id, addresses.token, tokenId], () =>
getBids(chain.id, addresses.token!, tokenId),
getBids(chain.id, addresses.token!, tokenId)
)

await mutate([SWR_KEYS.AVERAGE_WINNING_BID, chain.id, addresses.token], () =>
averageWinningBid(chain.id, addresses.token as Address),
averageWinningBid(chain.id, addresses.token as Address)
)
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -216,7 +216,9 @@ export const PlaceBid = ({
const network = PUBLIC_IS_TESTNET
? 'https://testnet.nouns.build'
: 'https://nouns.build'
const baseUrl = `${network}/dao/${chain.name.toLowerCase()}/${addresses.token}`
const baseUrl = `${network}/dao/${chain.name.toLowerCase()}/${
addresses.token
}`
if (address === undefined) {
await navigator.clipboard.writeText(baseUrl)
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Box, Flex, atoms } from '@zoralabs/zord'
import { ethers } from 'ethers'
import { getFetchableUrl } from 'ipfs-service'
import React, { useState } from 'react'
import { getAddress, parseEther } from 'viem'
import {
decodeEventLog,
encodeAbiParameters,
getAddress,
parseAbiParameters,
parseEther,
toHex,
} from 'viem'
import { useAccount, useContractRead } from 'wagmi'
import {
WriteContractUnpreparedArgs,
Expand Down Expand Up @@ -103,22 +109,21 @@ export const ReviewAndDeploy: React.FC<ReviewAndDeploy> = ({ title }) => {
vestExpiry: BigInt(Math.floor(new Date(endDate).getTime() / 1000)),
}))

const abiCoder = new ethers.utils.AbiCoder()
const tokenParamsHex = abiCoder.encode(
['string', 'string', 'string', 'string', 'string', 'string'],
const tokenParamsHex = encodeAbiParameters(
parseAbiParameters(
'string name, string symbol, string description, string daoImage, string daoWebsite, string baseRenderer'
),
[
sanitizeStringForJSON(general?.daoName),
general?.daoSymbol.replace('$', ''),
sanitizeStringForJSON(setUpArtwork?.projectDescription),
general?.daoAvatar,
general?.daoAvatar || '',
sanitizeStringForJSON(general?.daoWebsite || ''),
'https://api.zora.co/renderer/stack-images',
]
)

const tokenParams = {
initStrings: ethers.utils.hexlify(tokenParamsHex) as AddressType,
}
const tokenParams = { initStrings: toHex(tokenParamsHex) as AddressType }

const auctionParams = {
reservePrice: auctionSettings.auctionReservePrice
Expand Down Expand Up @@ -213,8 +218,6 @@ export const ReviewAndDeploy: React.FC<ReviewAndDeploy> = ({ title }) => {
return
}

const managerInterface = new ethers.utils.Interface(managerAbi)

//keccak256 hashed value of DAODeployed(address,address,address,address,address)
const deployEvent = transaction?.logs.find(
(log) =>
Expand All @@ -224,9 +227,11 @@ export const ReviewAndDeploy: React.FC<ReviewAndDeploy> = ({ title }) => {

let parsedEvent
try {
parsedEvent = managerInterface.parseLog({
parsedEvent = decodeEventLog({
abi: managerAbi,
eventName: 'DAODeployed',
topics: deployEvent?.topics || [],
data: deployEvent?.data || '',
data: deployEvent?.data || '0x',
})
} catch {}

Expand All @@ -238,13 +243,7 @@ export const ReviewAndDeploy: React.FC<ReviewAndDeploy> = ({ title }) => {
return
}

setDeployedDao({
token: deployedAddresses[0],
metadata: deployedAddresses[1],
auction: deployedAddresses[2],
treasury: deployedAddresses[3],
governor: deployedAddresses[4],
})
setDeployedDao(deployedAddresses)
setIsPendingTransaction(false)
setFulfilledSections(title)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import axios from 'axios'
import { Field, FieldProps, Formik } from 'formik'
import { useRouter } from 'next/router'
import React, { useState } from 'react'
import { toHex } from 'viem'
import { useAccount, useContractRead } from 'wagmi'
import { prepareWriteContract, waitForTransaction, writeContract } from 'wagmi/actions'

Expand Down Expand Up @@ -117,7 +118,7 @@ export const ReviewProposalForm = ({
treasuryAddress: addresses?.treasury,
chainId: chain.id,
calldatas: calldata,
values: transactionValues.map((x) => x.toString()),
values: transactionValues.map((x) => toHex(x)),
targets,
})
.then((res) => res.data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen, within } from '@testing-library/react'
import { ethers } from 'ethers'
import { Formik } from 'formik'
import { parseEther } from 'viem'
import { vi } from 'vitest'

import { TransactionType } from '../../constants/transactionType'
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('List of transactions', () => {
success: false,
simulationId: 'id-1',
simulationUrl: 'url-1',
gasUsed: ethers.utils.parseUnits('0.1', 'ether'),
gasUsed: parseEther('0.1').toString(),
},
]}
/>
Expand Down Expand Up @@ -136,21 +136,21 @@ describe('List of transactions', () => {
success: false,
simulationId: 'id-0',
simulationUrl: 'url-0',
gasUsed: ethers.utils.parseUnits('0.1', 'ether'),
gasUsed: parseEther('0.1').toString(),
},
{
index: 1,
success: false,
simulationId: 'id-1',
simulationUrl: 'url-1',
gasUsed: ethers.utils.parseUnits('0.1', 'ether'),
gasUsed: parseEther('0.1').toString(),
},
{
index: 2,
success: false,
simulationId: 'id-2',
simulationUrl: 'url-3',
gasUsed: ethers.utils.parseUnits('0.1', 'ether'),
gasUsed: parseEther('0.1').toString(),
},
]}
/>
Expand Down
Loading

0 comments on commit 5d80d0d

Please sign in to comment.