Skip to content

Commit

Permalink
refactor: upgrade ethers dependency in libs
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-ds committed Mar 26, 2024
1 parent 7481112 commit 97f25c6
Show file tree
Hide file tree
Showing 28 changed files with 108 additions and 644 deletions.
1 change: 0 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"dependencies": {
"@bandada/credentials": "2.1.1",
"@bandada/utils": "2.1.1",
"@ethersproject/hash": "^5.7.0",
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/mapped-types": "^1.2.2",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/admins/admins.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* istanbul ignore file */
import { id } from "@ethersproject/hash"

import { Injectable } from "@nestjs/common"
import { InjectRepository } from "@nestjs/typeorm"
import { FindOptionsWhere, Repository } from "typeorm"
import { id } from "ethers"
import { CreateAdminDTO } from "./dto/create-admin.dto"
import { Admin } from "./entities/admin.entity"

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Web2Context,
BlockchainContext
} from "@bandada/credentials"
import { id } from "@ethersproject/hash"
import {
BadRequestException,
forwardRef,
Expand All @@ -18,6 +17,7 @@ import {
import { InjectRepository } from "@nestjs/typeorm"
import { Repository } from "typeorm"
import { v4 } from "uuid"
import { id } from "ethers"
import { GroupsService } from "../groups/groups.service"
import { OAuthAccount } from "./entities/credentials-account.entity"
import { OAuthState } from "./types"
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/groups/groups.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// import { BandadaContract, getBandadaContract, Network } from "@bandada/utils"
import { id } from "@ethersproject/hash"
import {
BadRequestException,
forwardRef,
Expand All @@ -13,6 +12,7 @@ import { InjectRepository } from "@nestjs/typeorm"
import { Group as CachedGroup } from "@semaphore-protocol/group"
import { Repository } from "typeorm"
import { v4 } from "uuid"
import { id } from "ethers"
import { InvitesService } from "../invites/invites.service"
import { CreateGroupDto } from "./dto/create-group.dto"
import { UpdateGroupDto } from "./dto/update-group.dto"
Expand Down
5 changes: 1 addition & 4 deletions apps/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"lint": "solhint 'contracts/**/*.sol'"
},
"devDependencies": {
"@ethersproject/abi": "^5.4.7",
"@ethersproject/bytes": "^5.4.7",
"@ethersproject/providers": "^5.4.7",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "latest",
Expand All @@ -35,7 +32,7 @@
"@types/node": ">=12.0.0",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
"ethers": "^5.4.7",
"ethers": "^6.11.1",
"hardhat": "^2.11.0",
"hardhat-dependency-compiler": "^1.1.3",
"hardhat-gas-reporter": "^1.0.8",
Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/tasks/deploy-bandada-semaphore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract } from "ethers"
import type { Contract } from "ethers"
import { task, types } from "hardhat/config"

task("deploy:bandada-semaphore", "Deploy a BandadaSemaphore contract")
Expand Down
2 changes: 1 addition & 1 deletion apps/contracts/tasks/deploy-bandada.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract } from "ethers"
import type { Contract } from "ethers"
import { task, types } from "hardhat/config"

task("deploy:bandada", "Deploy a Bandada contract")
Expand Down
6 changes: 3 additions & 3 deletions apps/contracts/test/Bandada.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Group } from "@semaphore-protocol/group"
import { Identity } from "@semaphore-protocol/identity"
import { expect } from "chai"
import { BigNumber, utils } from "ethers"
import { ethers } from "ethers"
import { run } from "hardhat"
// @ts-ignore: typechain folder will be generated after contracts compilation.
// eslint-disable-next-line import/extensions
Expand All @@ -10,9 +10,9 @@ import { Bandada } from "../typechain-types"
describe("Bandada", () => {
let bandada: Bandada

const groupId = utils.formatBytes32String("Name")
const groupId = ethers.encodeBytes32String("Name")
const identities = [0, 1].map((i) => new Identity(i.toString()))
const group = new Group(BigNumber.from(groupId).toBigInt(), 20)
const group = new Group(BigInt(groupId), 20)

group.addMembers(identities.map(({ commitment }) => commitment))

Expand Down
8 changes: 4 additions & 4 deletions apps/contracts/test/BandadaSemaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Group } from "@semaphore-protocol/group"
import { Identity } from "@semaphore-protocol/identity"
import { FullProof, generateProof } from "@semaphore-protocol/proof"
import { expect } from "chai"
import { BigNumber, utils } from "ethers"
import { ethers } from "ethers"
import { run } from "hardhat"
// @ts-ignore: typechain folder will be generated after contracts compilation.
// eslint-disable-next-line import/extensions
Expand All @@ -12,9 +12,9 @@ describe("BandadaSemaphore", () => {
let bandada: Bandada
let bandadaSemaphore: BandadaSemaphore

const groupId = utils.formatBytes32String("Name")
const groupId = ethers.encodeBytes32String("Name")
const identities = [0, 1].map((i) => new Identity(i.toString()))
const group = new Group(BigNumber.from(groupId).toBigInt())
const group = new Group(BigInt(groupId))

group.addMembers(identities.map(({ commitment }) => commitment))

Expand All @@ -40,7 +40,7 @@ describe("BandadaSemaphore", () => {
const wasmFilePath = `../../snark-artifacts/semaphore.wasm`
const zkeyFilePath = `../../snark-artifacts/semaphore.zkey`

const signal = utils.formatBytes32String("Hello World")
const signal = ethers.encodeBytes32String("Hello World")

let fullProof: FullProof

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@fontsource-variable/unbounded": "^5.0.5",
"@rainbow-me/rainbowkit": "^0.12.8",
"@semaphore-protocol/data": "3.10.0",
"ethers": "5.5.1",
"ethers": "^6.11.1",
"framer-motion": "^10.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { formatBytes32String } from "@ethersproject/strings"
import { getSemaphoreContract } from "@bandada/utils"
import { Box, Button, Heading, HStack, VStack } from "@chakra-ui/react"
import { useCallback, useState } from "react"
import { useNavigate } from "react-router-dom"
import { useSigner } from "wagmi"
import { encodeBytes32String } from "ethers"
import * as bandadaAPI from "../../api/bandadaAPI"
import image3 from "../../assets/image3.svg"
import GroupCard from "../group-card"
Expand All @@ -30,7 +30,7 @@ export default function FinalPreviewStep({

await semaphore.createGroup(group.name, group.treeDepth, admin)

const groupId = BigInt(formatBytes32String(group.name))
const groupId = BigInt(encodeBytes32String(group.name))
navigate(`/groups/on-chain/${groupId}`)
} catch (error) {
setLoading(false)
Expand Down
6 changes: 2 additions & 4 deletions apps/dashboard/src/utils/parseGroupName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, utils } from "ethers"
import { ethers } from "ethers"

/**
* It converts a group name as a big number to a string.
Expand All @@ -7,9 +7,7 @@ import { BigNumber, utils } from "ethers"
*/
export default function parseGroupName(groupNameBN: string) {
try {
return utils.parseBytes32String(
BigNumber.from(groupNameBN).toHexString()
)
return ethers.decodeBytes32String(BigInt(groupNameBN).toString())
} catch (error) {
// If not parse-able as a string, it returns the original value.
return groupNameBN
Expand Down
2 changes: 1 addition & 1 deletion libs/credentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@bandada/utils": "2.1.1",
"ethers": "5.7.0"
"ethers": "^6.11.1"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.0.0",
Expand Down
4 changes: 2 additions & 2 deletions libs/credentials/src/getJsonRpcProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { providers } from "ethers"
import { ethers } from "ethers"

export default function getJsonRpcProvider(url: string): any {
const jsonRpcProvider = new providers.JsonRpcProvider(url)
const jsonRpcProvider = new ethers.JsonRpcProvider(url)
return jsonRpcProvider
}
5 changes: 3 additions & 2 deletions libs/credentials/src/providers/blockchain/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { utils, BigNumberish } from "ethers"
import { ethers } from "ethers"
import type { BigNumberish } from "ethers"
import { BlockchainProvider } from "../.."
import getJsonRpcProvider from "../../getJsonRpcProvider"

Expand All @@ -9,7 +10,7 @@ const provider: BlockchainProvider = {
message: string,
signature: string
): Promise<BigNumberish> {
const address = await utils.verifyMessage(message, signature)
const address = await ethers.verifyMessage(message, signature)

return address
},
Expand Down
2 changes: 1 addition & 1 deletion libs/credentials/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumberish } from "ethers"
import type { BigNumberish } from "ethers"

export enum EASNetworks {
ETHEREUM = "ethereum",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from "ethers"
import { validateCredentials } from "../.."
import blockchainBalance from "./index"

Expand All @@ -8,7 +7,7 @@ describe("BlockchainBalance", () => {
}

it("Should return true if an account has a balance greater than or equal to 10", async () => {
jsonRpcProviderMocked.getBalance.mockReturnValue(BigNumber.from(12))
jsonRpcProviderMocked.getBalance.mockReturnValue(BigInt(12))

const result = await validateCredentials(
{
Expand All @@ -27,7 +26,7 @@ describe("BlockchainBalance", () => {
})

it("Should return true if an account has a balance greater than or equal to 10 using the block number", async () => {
jsonRpcProviderMocked.getBalance.mockReturnValue(BigNumber.from(12))
jsonRpcProviderMocked.getBalance.mockReturnValue(BigInt(12))

const result = await validateCredentials(
{
Expand Down
3 changes: 1 addition & 2 deletions libs/credentials/src/validators/blockchainBalance/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from "ethers"
import { BlockchainContext, Validator } from "../.."

export type Criteria = {
Expand Down Expand Up @@ -39,7 +38,7 @@ const validator: Validator = {
(context as BlockchainContext).address,
blockNumber
)
return balance >= BigNumber.from(criteria.minBalance)
return balance >= BigInt(criteria.minBalance)
}
throw new Error("No address value found")
}
Expand Down
8 changes: 4 additions & 4 deletions libs/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"access": "public"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@rollup/plugin-typescript": "^11.0.0",
"ethers": "^5.4.7",
"ethers": "^6.11.1",
"hardhat": "^2.11.0",
"rimraf": "^4.1.2",
"rollup": "^3.17.2",
Expand All @@ -40,9 +40,9 @@
},
"peerDependencies": {
"@bandada/contracts": "2.1.1",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@semaphore-protocol/contracts": "3.4.0",
"ethers": "^5.4.7",
"ethers": "^6.11.1",
"hardhat": "^2.11.0"
},
"dependencies": {
Expand Down
9 changes: 2 additions & 7 deletions libs/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@
"typescript": "^4.9.5"
},
"dependencies": {
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@ethersproject/strings": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"axios": "^1.3.3"
"axios": "^1.3.3",
"ethers": "^6.11.1"
}
}
7 changes: 3 additions & 4 deletions libs/utils/src/getBandadaContract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* istanbul ignore file */

import { Signer } from "@ethersproject/abstract-signer"
import { Contract, ContractReceipt } from "@ethersproject/contracts"
import type { Contract, Signer, ContractTransactionReceipt } from "ethers"
import getContract from "./getContract"
import { Network, OnchainBandadaGroup } from "./types"

Expand All @@ -14,7 +13,7 @@ export class BandadaContract {

async updateGroups(
groups: OnchainBandadaGroup[]
): Promise<ContractReceipt> {
): Promise<ContractTransactionReceipt> {
const transaction = await this.contract.updateGroups(groups)

return transaction.wait(1)
Expand All @@ -33,7 +32,7 @@ export class BandadaContract {
async updateFingerprintDuration(
groupId: BigInt,
fingerprintDuration: BigInt
): Promise<ContractReceipt> {
): Promise<ContractTransactionReceipt> {
const transaction = await this.contract.updateFingerprintDuration(
groupId,
fingerprintDuration
Expand Down
8 changes: 3 additions & 5 deletions libs/utils/src/getContract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* istanbul ignore file */

import { Signer } from "@ethersproject/abstract-signer"
import { Contract } from "@ethersproject/contracts"
import { Provider } from "@ethersproject/providers"
import { type Contract, type Signer, type Provider, ethers } from "ethers"
import { getContractAddresses } from "./contractAddresses"
import { abi as SemaphoreABI } from "./contractArtifacts/Semaphore.json"
import { abi as BandadaABI } from "./contractArtifacts/Bandada.json"
Expand Down Expand Up @@ -32,9 +30,9 @@ export default function getContract(

switch (contractName) {
case "Bandada":
return new Contract(contractAddress, BandadaABI, providerOrWallet)
return new ethers.Contract(contractAddress, BandadaABI, providerOrWallet)
case "Semaphore":
return new Contract(contractAddress, SemaphoreABI, providerOrWallet)
return new ethers.Contract(contractAddress, SemaphoreABI, providerOrWallet)
default:
throw new TypeError(`'${contractName}' contract does not exist`)
}
Expand Down
6 changes: 3 additions & 3 deletions libs/utils/src/getProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* istanbul ignore file */

import { InfuraProvider, JsonRpcProvider } from "@ethersproject/providers"
import { ethers, type JsonRpcProvider } from "ethers"
import { Network } from "./types"

export default function getProvider(
Expand All @@ -9,9 +9,9 @@ export default function getProvider(
): JsonRpcProvider {
switch (network) {
case "localhost":
return new JsonRpcProvider("http://127.0.0.1:8545")
return new ethers.JsonRpcProvider("http://127.0.0.1:8545")
case "sepolia":
return new InfuraProvider(network, apiKey)
return new ethers.InfuraProvider(network, apiKey)
default:
throw new TypeError(`'${network}' network is not supported`)
}
Expand Down
Loading

0 comments on commit 97f25c6

Please sign in to comment.