Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade ethers v5 -> v6 #1255

Merged
merged 41 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
63a5750
feat: upgrade ethers sha package
danielbate Sep 14, 2023
7f1b245
feat: upgrade ethers pbkdf2 package
danielbate Sep 14, 2023
f4c005a
feat: upgrade ethers network package
danielbate Sep 14, 2023
c40ba20
feat: upgrade ethers basex package
danielbate Sep 14, 2023
51f4d0b
feat: upgrade ethers in abi coder package
danielbate Sep 14, 2023
05d72c4
feat: upgrade ethers in root dir
danielbate Sep 14, 2023
5901208
feat: upgrade BytesLike to ethers v6
danielbate Sep 15, 2023
c084049
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
danielbate Sep 15, 2023
135d430
chore: regen lock file
danielbate Sep 15, 2023
35f059f
Merge branch 'master' into db/feat/upgrade-ethers-v6
Dhaiwat10 Sep 21, 2023
4d4b5ad
resolve merge conflicts
Dhaiwat10 Sep 21, 2023
3edd36c
fix lint errors
Dhaiwat10 Sep 21, 2023
f5a1ab4
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
danielbate Oct 4, 2023
808f96e
chore: linting
danielbate Oct 4, 2023
47a8941
feat: migrate hexDataSlice to v6 dataSlice
danielbate Oct 4, 2023
e69e082
feat: migrate hexlify to ethers v6
danielbate Oct 4, 2023
4f4a34d
feat: migrate hexlify v6 in fuel gauge and docs
danielbate Oct 4, 2023
3f9016a
feat: migrate concat to v6 and introduce concatBytes helper
danielbate Oct 4, 2023
464f908
refactor: migrate from `arrayify` to `getBytes` (#1315)
Dhaiwat10 Oct 5, 2023
bcd4fa0
feat: alter arrayify mock to use getBytes
danielbate Oct 5, 2023
20d3841
feat: purge ethers project dep
danielbate Oct 5, 2023
14a8ea3
chore: regen lock file
danielbate Oct 5, 2023
667dda1
feat: migrate arrayify to getBytes in hdwallet
danielbate Oct 5, 2023
29bad9e
feat: introduce hex with prefix function
danielbate Oct 5, 2023
d2be0be
feat: resolve mnemonic return types
danielbate Oct 5, 2023
da5e080
feat: resolve address test in docs snippet
danielbate Oct 5, 2023
84a16fb
feat: pass address as b256 rather than address object in tests plus t…
danielbate Oct 5, 2023
25250c4
feat: add signer recover pub key return type
danielbate Oct 5, 2023
79672b0
feat: remove redundant todo
danielbate Oct 5, 2023
d5dfeb8
feat: modify concat bytes to take num array
danielbate Oct 5, 2023
00a03fa
feat: reintroduce the Bytes type
danielbate Oct 5, 2023
ecdf5e4
feat: add missing address to id conversions
danielbate Oct 5, 2023
82cd516
feat: use getBytesCopy in place of getBytes
danielbate Oct 6, 2023
8316663
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
danielbate Oct 6, 2023
39e411c
feat: move bytes like to fuels rather than ethers in fuel-gauge
danielbate Oct 6, 2023
9499a59
feat: split up ethers exports in fuels
danielbate Oct 6, 2023
0673075
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
danielbate Oct 6, 2023
033dcc0
feat: rename getBytesCopyFromBech32 to getBytesFromBech32
danielbate Oct 6, 2023
82d6aff
Merge branch 'master' into db/feat/upgrade-ethers-v6
danielbate Oct 10, 2023
87c7bca
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into db…
danielbate Oct 13, 2023
21e80f3
Merge branch 'master' into db/feat/upgrade-ethers-v6
danielbate Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changeset/rare-foxes-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@fuel-ts/docs-snippets": patch
"@fuel-ts/abi-coder": patch
"@fuel-ts/abi-typegen": patch
"@fuel-ts/address": patch
"@fuel-ts/contract": patch
"@fuel-ts/crypto": patch
"fuels": patch
"@fuel-ts/hasher": patch
"@fuel-ts/hdwallet": patch
"@fuel-ts/merkle": patch
"@fuel-ts/mnemonic": patch
"@fuel-ts/predicate": patch
"@fuel-ts/program": patch
"@fuel-ts/providers": patch
"@fuel-ts/script": patch
"@fuel-ts/signer": patch
"@fuel-ts/transactions": patch
"@fuel-ts/utils": patch
"@fuel-ts/wallet": patch
---

refactor: purge usage of `arrayify` from ethers v5 in favor of `getBytes` from ethers v6
2 changes: 1 addition & 1 deletion apps/docs-snippets/src/guide/types/conversion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe(__filename, () => {
expect(address3.toB256()).toEqual(assetId);

// consistent bytes conversion
expect(arrayify(assetId)).toEqual(arrayify(address1));
expect(arrayify(assetId)).toEqual(arrayify(address1.toB256()));
// #endregion conversion-4
});
});
5 changes: 2 additions & 3 deletions jest.env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hexlify } from '@ethersproject/bytes';
import { hexlify } from 'ethers';

import faucets from './.fuel-core/configs/faucets.json';

Expand Down Expand Up @@ -28,8 +28,7 @@ const getPrivateKeyForCurrentWorker = () => {
throw new Error(`At most ${faucets.length} workers are supported.`);
}

const privateKey = hexlify([workerId]);

const privateKey = hexlify(Uint8Array.from([workerId]));
return privateKey;
danielbate marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"devDependencies": {
"@changesets/cli": "^2.25.0",
"@changesets/get-github-info": "^0.5.2",
"@ethersproject/bytes": "^5.7.0",
"@fuel-ts/forc": "workspace:*",
"@fuel-ts/fuel-core": "workspace:*",
"@internal/tsup": "workspace:*",
Expand All @@ -71,6 +70,7 @@
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-tsdoc": "^0.2.17",
"ethers": "^6.7.1",
"glob": "^10.2.6",
"jest": "^29.5.0",
"jest-text-transformer": "^1.0.4",
Expand Down
8 changes: 2 additions & 6 deletions packages/abi-coder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@
},
"license": "Apache-2.0",
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/properties": "^5.7.0",
"@ethersproject/sha2": "^5.7.0",
"@ethersproject/strings": "^5.7.0",
"@fuel-ts/crypto": "workspace:*",
"@fuel-ts/math": "workspace:*",
"@fuel-ts/versions": "workspace:*",
"@fuel-ts/utils": "workspace:*",
danielbate marked this conversation as resolved.
Show resolved Hide resolved
"@fuel-ts/errors": "workspace:*",
"ethers": "^6.7.1",
"type-fest": "^3.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/abi-coder/src/coders/abstract-coder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BytesLike } from '@ethersproject/bytes';
import { FuelError, type ErrorCode } from '@fuel-ts/errors';
import type { BN } from '@fuel-ts/math';
import type { BytesLike } from 'ethers';

import type { Option } from './option';

Expand Down
4 changes: 2 additions & 2 deletions packages/abi-coder/src/coders/b256.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { arrayify } from '@ethersproject/bytes';
import { ErrorCode } from '@fuel-ts/errors';
import { bn, toHex } from '@fuel-ts/math';
import { getBytesCopy } from 'ethers';

import { Coder } from './abstract-coder';

Expand All @@ -12,7 +12,7 @@ export class B256Coder extends Coder<string, string> {
encode(value: string): Uint8Array {
let encodedValue;
try {
encodedValue = arrayify(value);
encodedValue = getBytesCopy(value);
} catch (error) {
danielbate marked this conversation as resolved.
Show resolved Hide resolved
this.throwError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-coder/src/coders/b512.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { arrayify } from '@ethersproject/bytes';
import { ErrorCode } from '@fuel-ts/errors';
import { bn, toHex } from '@fuel-ts/math';
import { getBytesCopy } from 'ethers';

import { Coder } from './abstract-coder';

Expand All @@ -12,7 +12,7 @@ export class B512Coder extends Coder<string, string> {
encode(value: string): Uint8Array {
let encodedValue;
try {
encodedValue = arrayify(value);
encodedValue = getBytesCopy(value);
} catch (error) {
this.throwError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-coder/src/coders/byte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { arrayify, concat } from '@ethersproject/bytes';
import { ErrorCode } from '@fuel-ts/errors';
import { bn } from '@fuel-ts/math';
import { concatBytes } from '@fuel-ts/utils';

import { WORD_SIZE } from '../constants';
import type { Uint8ArrayWithDynamicData } from '../utilities';
Expand Down Expand Up @@ -43,14 +43,14 @@ export class ByteCoder extends Coder<number[], Uint8Array> {
}

#getPaddedData(value: number[]): Uint8Array {
const data: Uint8Array[] = [arrayify(value)];
const data: Uint8Array[] = [Uint8Array.from(value)];

const paddingLength = (WORD_SIZE - (value.length % WORD_SIZE)) % WORD_SIZE;
if (paddingLength) {
data.push(new Uint8Array(paddingLength));
}

return concat(data);
return concatBytes(data);
}
danielbate marked this conversation as resolved.
Show resolved Hide resolved

decode(data: Uint8Array, offset: number): [Uint8Array, number] {
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-coder/src/coders/enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { concat } from '@ethersproject/bytes';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { toNumber } from '@fuel-ts/math';
import { concatBytes } from '@fuel-ts/utils';
import type { RequireExactlyOne } from 'type-fest';

import { concatWithDynamicData } from '../utilities';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class EnumCoder<TCoders extends Record<string, Coder>> extends Coder<
const caseIndex = Object.keys(this.coders).indexOf(value);

const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
return concatBytes([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
}

encode(value: InputValueOf<TCoders>): Uint8Array {
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-coder/src/coders/stdString.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { concat } from '@ethersproject/bytes';
import { toUtf8Bytes, toUtf8String } from '@ethersproject/strings';
import { bn } from '@fuel-ts/math';
import { concatBytes } from '@fuel-ts/utils';
import { toUtf8Bytes, toUtf8String } from 'ethers';

import { WORD_SIZE } from '../constants';
import type { Uint8ArrayWithDynamicData } from '../utilities';
Expand Down Expand Up @@ -46,7 +46,7 @@ export class StdStringCoder extends Coder<string, string> {
data.push(new Uint8Array(paddingLength));
}

return concat(data);
return concatBytes(data);
}

decode(data: Uint8Array, offset: number): [string, number] {
Expand Down
6 changes: 3 additions & 3 deletions packages/abi-coder/src/coders/string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { concat } from '@ethersproject/bytes';
import { toUtf8Bytes, toUtf8String } from '@ethersproject/strings';
import { ErrorCode } from '@fuel-ts/errors';
import { concatBytes } from '@fuel-ts/utils';
import { toUtf8Bytes, toUtf8String } from 'ethers';

import { Coder } from './abstract-coder';

Expand All @@ -23,7 +23,7 @@ export class StringCoder<TLength extends number = number> extends Coder<string,

const encoded = toUtf8Bytes(value);
const padding = new Uint8Array(this.#paddingLength);
return concat([encoded, padding]);
return concatBytes([encoded, padding]);
}

decode(data: Uint8Array, offset: number): [string, number] {
Expand Down
9 changes: 4 additions & 5 deletions packages/abi-coder/src/function-fragment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { BytesLike } from '@ethersproject/bytes';
import { arrayify } from '@ethersproject/bytes';
import { sha256 } from '@ethersproject/sha2';
import { bufferFromString } from '@fuel-ts/crypto';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { bn } from '@fuel-ts/math';
import type { BytesLike } from 'ethers';
import { sha256, getBytesCopy } from 'ethers';

import { AbiCoder } from './abi-coder';
import type { DecodedValue, InputValue } from './coders/abstract-coder';
Expand Down Expand Up @@ -144,7 +143,7 @@ export class FunctionFragment<
}

decodeArguments(data: BytesLike) {
const bytes = arrayify(data);
const bytes = getBytesCopy(data);
const nonEmptyInputs = this.jsonFn.inputs.filter(
(x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== '()'
);
Expand Down Expand Up @@ -193,7 +192,7 @@ export class FunctionFragment<
);
if (outputAbiType.type === '()') return [undefined, 0];

const bytes = arrayify(data);
const bytes = getBytesCopy(data);
const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);

if (outputAbiType.type === 'raw untyped slice') {
Expand Down
5 changes: 2 additions & 3 deletions packages/abi-coder/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { BytesLike } from '@ethersproject/bytes';
import { arrayify } from '@ethersproject/bytes';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { getBytesCopy, type BytesLike } from 'ethers';

import { AbiCoder } from './abi-coder';
import type { InputValue } from './coders/abstract-coder';
Expand Down Expand Up @@ -98,7 +97,7 @@ export class Interface<TAbi extends JsonAbi = JsonAbi> {

const { loggedType } = findOrThrow(this.jsonAbi.loggedTypes, (type) => type.logId === logId);

return AbiCoder.decode(this.jsonAbi, loggedType, arrayify(data), 0);
return AbiCoder.decode(this.jsonAbi, loggedType, getBytesCopy(data), 0);
}

updateExternalLoggedTypes(id: string, loggedTypes: Interface) {
Expand Down
Loading
Loading