Skip to content

Commit f407274

Browse files
committed
chore: update to ethers v6
Signed-off-by: Tomás Migone <[email protected]>
1 parent 5c3a0e3 commit f407274

File tree

8 files changed

+96
-496
lines changed

8 files changed

+96
-496
lines changed

packages/common-ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"bs58": "5.0.0",
2424
"cors": "2.8.5",
2525
"cross-fetch": "4.0.0",
26-
"ethers": "5.7.0",
26+
"ethers": "6.13.5",
2727
"express": "4.18.2",
2828
"graphql": "16.8.0",
2929
"graphql-tag": "2.12.6",

packages/common-ts/src/attestations/attestations.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
recoverAttestation,
66
} from './attestations'
77
import { Wallet } from 'ethers'
8-
import { utils } from 'ethers'
8+
import { hexlify } from 'ethers'
99
import * as bs58 from 'bs58'
1010

1111
describe('Attestations', () => {
@@ -16,12 +16,12 @@ describe('Attestations', () => {
1616
const receipt = {
1717
requestCID: '0xd902c18a1b3590a3d2a8ae4439db376764fda153ca077e339d0427bf776bd463',
1818
responseCID: '0xbe0b5ae5f598fdf631133571d59ef16b443b2fe02e35ca2cb807158069009db9',
19-
subgraphDeploymentID: utils.hexlify(
19+
subgraphDeploymentID: hexlify(
2020
bs58.decode('QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9').slice(2),
2121
),
2222
}
2323

24-
const signer = Wallet.fromMnemonic(mnemonic)
24+
const signer = Wallet.fromPhrase(mnemonic)
2525
const attestation = await createAttestation(
2626
signer.privateKey,
2727
1,
@@ -44,7 +44,7 @@ describe('Attestations', () => {
4444
const receipt = {
4545
requestCID: '0xd902c18a1b3590a3d2a8ae4439db376764fda153ca077e339d0427bf776bd463',
4646
responseCID: '0xbe0b5ae5f598fdf631133571d59ef16b443b2fe02e35ca2cb807158069009db9',
47-
subgraphDeploymentID: utils.hexlify(
47+
subgraphDeploymentID: hexlify(
4848
bs58.decode('QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9').slice(2),
4949
),
5050
}
@@ -66,12 +66,12 @@ describe('Attestations', () => {
6666
const receipt = {
6767
requestCID: '0xd902c18a1b3590a3d2a8ae4439db376764fda153ca077e339d0427bf776bd463',
6868
responseCID: '0xbe0b5ae5f598fdf631133571d59ef16b443b2fe02e35ca2cb807158069009db9',
69-
subgraphDeploymentID: utils.hexlify(
69+
subgraphDeploymentID: hexlify(
7070
bs58.decode('QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9').slice(2),
7171
),
7272
}
7373

74-
const signer = Wallet.fromMnemonic(mnemonic)
74+
const signer = Wallet.fromPhrase(mnemonic)
7575
const chainID = 1
7676
const contractAddress = '0x0000000000000000000000000000000000000000'
7777
const attestation = await createAttestation(

packages/common-ts/src/attestations/attestations.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import { utils } from 'ethers'
2-
import * as eip712 from './eip712'
3-
4-
const {
5-
defaultAbiCoder: abi,
6-
arrayify,
1+
import {
2+
AbiCoder,
3+
getBytes,
74
concat,
85
hexlify,
9-
splitSignature,
10-
joinSignature,
11-
} = utils
6+
BytesLike,
7+
keccak256,
8+
SigningKey,
9+
Signature,
10+
recoverAddress,
11+
} from 'ethers'
12+
import * as eip712 from './eip712'
1213

1314
const SIG_SIZE_BYTES = 161
1415
const RECEIPT_SIZE_BYTES = 96
1516
const RECEIPT_TYPE_HASH = eip712.typeHash(
1617
'Receipt(bytes32 requestCID,bytes32 responseCID,bytes32 subgraphDeploymentID)',
1718
)
19+
const abi = AbiCoder.defaultAbiCoder()
1820

1921
export interface Receipt {
2022
requestCID: string
@@ -56,7 +58,7 @@ export const getDomainSeparator = (
5658
}
5759

5860
export const createAttestation = async (
59-
signer: utils.BytesLike,
61+
signer: BytesLike,
6062
chainId: number,
6163
disputeManagerAddress: string,
6264
receipt: Receipt,
@@ -65,9 +67,9 @@ export const createAttestation = async (
6567
const domainSeparator = getDomainSeparator(chainId, disputeManagerAddress, version)
6668
const encodedReceipt = encodeReceipt(receipt)
6769
const message = eip712.encode(domainSeparator, encodedReceipt)
68-
const messageHash = utils.keccak256(message)
69-
const signingKey = new utils.SigningKey(signer)
70-
const { r, s, v } = signingKey.signDigest(messageHash)
70+
const messageHash = keccak256(message)
71+
const signingKey = new SigningKey(signer)
72+
const { r, s, v } = signingKey.sign(messageHash)
7173

7274
return {
7375
requestCID: receipt.requestCID,
@@ -80,18 +82,18 @@ export const createAttestation = async (
8082
}
8183

8284
export const encodeAttestation = (attestation: Attestation): string => {
83-
const data = arrayify(
85+
const data = getBytes(
8486
abi.encode(
8587
['bytes32', 'bytes32', 'bytes32'],
8688
[attestation.requestCID, attestation.responseCID, attestation.subgraphDeploymentID],
8789
),
8890
)
89-
const sig = joinSignature(attestation)
91+
const sig = Signature.from(attestation).serialized
9092
return hexlify(concat([data, sig]))
9193
}
9294

9395
export const decodeAttestation = (attestationData: string): Attestation => {
94-
const attestationBytes = arrayify(attestationData)
96+
const attestationBytes = getBytes(attestationData)
9597
if (attestationBytes.length !== SIG_SIZE_BYTES) {
9698
throw new Error('Invalid signature length')
9799
}
@@ -100,8 +102,8 @@ export const decodeAttestation = (attestationData: string): Attestation => {
100102
['bytes32', 'bytes32', 'bytes32'],
101103
attestationBytes,
102104
)
103-
const sig = splitSignature(
104-
attestationBytes.slice(RECEIPT_SIZE_BYTES, RECEIPT_SIZE_BYTES + SIG_SIZE_BYTES),
105+
const sig = Signature.from(
106+
hexlify(attestationBytes.slice(RECEIPT_SIZE_BYTES, RECEIPT_SIZE_BYTES + SIG_SIZE_BYTES))
105107
)
106108

107109
return {
@@ -128,9 +130,9 @@ export const recoverAttestation = (
128130
}
129131
const encodedReceipt = encodeReceipt(receipt)
130132
const message = eip712.encode(domainSeparator, encodedReceipt)
131-
const messageHash = utils.keccak256(message)
132-
return utils.recoverAddress(
133+
const messageHash = keccak256(message)
134+
return recoverAddress(
133135
messageHash,
134-
joinSignature({ r: attestation.r, s: attestation.s, v: attestation.v }),
136+
Signature.from({ r: attestation.r, s: attestation.s, v: attestation.v }).serialized,
135137
)
136138
}

packages/common-ts/src/attestations/eip712.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { utils } from 'ethers'
1+
import { AbiCoder, keccak256, toUtf8Bytes } from 'ethers'
22

33
// Hashes a type signature based on the `typeHash` defined on
44
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md#definition-of-hashstruct.
55
//
66
// The type signature is expected to follow the `encodeType` format described on
77
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md#definition-of-encodetype.
88
export const typeHash = (typeSignature: string): string =>
9-
utils.keccak256(utils.toUtf8Bytes(typeSignature))
9+
keccak256(toUtf8Bytes(typeSignature))
1010

1111
// Encodes a list of values according to the given types.
1212
//
@@ -21,14 +21,14 @@ const encodeData = (types: string[], values: any[]): string => {
2121
for (let i = 0; i < types.length; i++) {
2222
if (types[i] === 'string' || types[i] === 'bytes') {
2323
transformedTypes[i] = 'bytes32'
24-
transformedValues[i] = utils.keccak256(utils.toUtf8Bytes(values[i]))
24+
transformedValues[i] = keccak256(toUtf8Bytes(values[i]))
2525
} else {
2626
transformedTypes[i] = types[i]
2727
transformedValues[i] = values[i]
2828
}
2929
}
3030

31-
return utils.defaultAbiCoder.encode(transformedTypes, transformedValues)
31+
return AbiCoder.defaultAbiCoder().encode(transformedTypes, transformedValues)
3232
}
3333

3434
// Hashes a struct based on the hash of a type signature (see `typeHash`),
@@ -37,7 +37,7 @@ const encodeData = (types: string[], values: any[]): string => {
3737
// NOTE: Does not support recursion yet.
3838
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3939
export const hashStruct = (typeHash: string, types: string[], values: any[]): string => {
40-
return utils.keccak256(encodeData(['bytes32', ...types], [typeHash, ...values]))
40+
return keccak256(encodeData(['bytes32', ...types], [typeHash, ...values]))
4141
}
4242

4343
const EIP712_DOMAIN_TYPE_HASH = typeHash(
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { BigNumber, BigNumberish } from 'ethers'
2-
import { parseUnits, formatUnits } from 'ethers/lib/utils'
1+
import { BigNumberish, formatUnits, parseUnits } from 'ethers'
32

43
export const formatGRT = (value: BigNumberish): string => formatUnits(value, 18)
54

6-
export const parseGRT = (grt: string): BigNumber => parseUnits(grt, 18)
5+
export const parseGRT = (grt: string): bigint => parseUnits(grt, 18)

packages/common-ts/src/subgraphs/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { utils } from 'ethers'
1+
import { hexlify, getBytes } from 'ethers'
22
import base58 from 'bs58'
33

44
export class SubgraphName {
@@ -28,7 +28,7 @@ export class SubgraphDeploymentID {
2828
let value
2929
// Security: Input validation
3030
if (multiHashCheck.test(id)) {
31-
value = utils.hexlify(base58.decode(id).slice(2))
31+
value = hexlify(base58.decode(id).slice(2))
3232
} else if (bytes32Check.test(id)) {
3333
value = id
3434
}
@@ -56,7 +56,7 @@ export class SubgraphDeploymentID {
5656
}
5757

5858
get ipfsHash(): string {
59-
return base58.encode([0x12, 0x20, ...utils.arrayify(this.value)])
59+
return base58.encode([0x12, 0x20, ...getBytes(this.value)])
6060
}
6161
}
6262

packages/common-ts/src/util/addresses.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { utils } from 'ethers'
1+
import { getAddress } from 'ethers'
22

33
/**
44
* A normalized address in checksum format.
@@ -9,4 +9,4 @@ export type Address = string & { _isAddress: void }
99
* Converts an address to checksum format and returns a typed instance.
1010
*/
1111
export const toAddress = (s: Address | string): Address =>
12-
typeof s === 'string' ? (utils.getAddress(s) as Address) : s
12+
typeof s === 'string' ? (getAddress(s) as Address) : s

0 commit comments

Comments
 (0)