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

chore!: redistributed the @fuel-ts/interfaces package #3492

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
20 changes: 20 additions & 0 deletions .changeset/wild-dots-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@internal/check-imports": patch
"@fuel-ts/transactions": patch
"@fuel-ts/abi-typegen": patch
"@fuel-ts/abi-coder": patch
"@fuel-ts/contract": patch
"@fuel-ts/account": patch
"@fuel-ts/address": patch
"@fuel-ts/program": patch
"@fuel-ts/recipes": patch
"@fuel-ts/crypto": patch
"@fuel-ts/errors": patch
"@fuel-ts/hasher": patch
"@fuel-ts/logger": patch
"@fuel-ts/script": patch
"fuels": minor
"@fuel-ts/utils": patch
---

chore!: redistributed the `@fuel-ts/interfaces` package
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nedsalk @Torres-ssf Do you remember why we couldn't do this in the past? I think it was some cyclic dependencies or something, and I wonder if we're missing something here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that there were some cyclic dependencies with regards to accounts and providers but they might have been resolved with the merger of those packages into the single @fuel-ts/account package. I feel like the removal of AbstractProgram should've also caused some issues, but perhaps we have refactored out the logic which depended on its existence.

All in all, if the CI is green then IMO we can proceed reviewing and ultimately merging it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arboleya This became possible with the removal of the AbstractAddress class and the use of the Address class in its place.

But I wonder why the AbstractAddress class was created in the first place.

cc @luizstacio

1 change: 0 additions & 1 deletion apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ ABI
ABI's
abigen
ABIs
AbstractAddress
ALU
ANDs
API's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ To interact with a deployed contract using the SDK without redeploying it, you o

## Contract ID

The `contractId` property from the [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) class is of type [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), an abstract class that is exclusively extended by the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class.
The `contractId` property from the [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) class is an instance of the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class.

The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class wraps all methods from the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class and adds a single property: `bech32Address`. This property is a string encoded in [`Bech32`](../types/bech32.md) format, recognizable by the human-readable prefix `fuel` followed by the separator `1`.
The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class has a few helper methods and adds a single property: `bech32Address`. This property is a string encoded in [`Bech32`](../types/bech32.md) format, recognizable by the human-readable prefix `fuel` followed by the separator `1`.

> [!NOTE] Note
> `Bech32` addresses like `fuel1..` are now deprecated; please switch to B256 format, for more details see [here](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256).
Expand Down
10 changes: 2 additions & 8 deletions apps/docs/src/guide/types/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

In Sway, the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) type serves as a type-safe wrapper around the primitive `b256` type. The SDK takes a different approach and has its own abstraction for the [Address](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) type.

## `AbstractAddress` Class

The SDK defines the [AbstractAddress](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class, which provides a set of utility functions for easy manipulation and conversion between address formats.

<<< @/../../../packages/interfaces/src/index.ts#address-1{ts:line-numbers}

## Address Class

Besides conforming to the interface of the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also defines one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type.
The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also provides a set of utility functions for easy manipulation and conversion between address formats along with one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type.

<<< @/../../../packages/address/src/address.ts#address-2{ts:line-numbers}

## Creating an Address

Thanks to the utility functions provided by the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class, there are several ways to create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) instance:
There are several ways to create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) instance:

### From a `Bech32` Address

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/guide/types/bech32.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You can read more about the `Bech32` type [here](https://thebitcoinmanual.com/ar

A `Bech32` address consists of an HRP (Human-Readable Part) followed by the number `1`, which acts as a separator:

<<< @/../../../packages/interfaces/src/index.ts#bech32-1{ts:line-numbers}
<<< @/../../../packages/address/src/types.ts#bech32-1{ts:line-numbers}

A complete `Bech32` address will resemble the following:

Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/utilities/address-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ And by using the `isB256` and `toBech32` utilities:

## Converting a Contract ID

The Contract `id` property has the [`AbstractAddress`](../types/address.md#abstractaddress-class) type. Therefore, it can be converted using the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class functions such as `toAddress` and `toB256`:
The Contract `id` property is an instance of the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class. Therefore, it can be converted using the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class functions such as `toAddress` and `toB256`:

<<< @./snippets/address-conversion/contract.ts#conversion-2{ts:line-numbers}

## Converting a Wallet Address

Similarly, the Wallet `address` property is also of type [`AbstractAddress`](../types/address.md#abstractaddress-class) and can therefore use the same [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class functions for conversion:
Similarly, the Wallet `address` property is also of type [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) and can therefore use the same [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class functions for conversion:

<<< @./snippets/address-conversion/wallet.ts#conversion-3{ts:line-numbers}

Expand Down
1 change: 0 additions & 1 deletion internal/check-imports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@fuel-ts/crypto": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/hasher": "workspace:*",
"@fuel-ts/interfaces": "workspace:*",
"@fuel-ts/math": "workspace:*",
"@fuel-ts/merkle": "workspace:*",
"@fuel-ts/program": "workspace:*",
Expand Down
2 changes: 0 additions & 2 deletions internal/check-imports/src/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as errors from '@fuel-ts/errors';
// forc-bin
// fuels-gauge
import * as hasher from '@fuel-ts/hasher';
import * as interfaces from '@fuel-ts/interfaces';
import * as math from '@fuel-ts/math';
import * as merkle from '@fuel-ts/merkle';
import * as program from '@fuel-ts/program';
Expand All @@ -28,7 +27,6 @@ log([
errors,
fuels,
hasher,
interfaces,
crypto,
math,
merkle,
Expand Down
1 change: 0 additions & 1 deletion packages/abi-coder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@fuel-ts/crypto": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/hasher": "workspace:^",
"@fuel-ts/interfaces": "workspace:*",
"@fuel-ts/math": "workspace:*",
"@fuel-ts/utils": "workspace:*",
"type-fest": "^4.26.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-coder/src/FunctionFragment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { bufferFromString } from '@fuel-ts/crypto';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { sha256 } from '@fuel-ts/hasher';
import type { BytesLike } from '@fuel-ts/interfaces';
import { bn } from '@fuel-ts/math';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify } from '@fuel-ts/utils';

import { AbiCoder } from './AbiCoder';
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-coder/src/Interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import type { BytesLike } from '@fuel-ts/interfaces';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify } from '@fuel-ts/utils';

import { AbiCoder } from './AbiCoder';
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-coder/src/encoding/coders/AbstractCoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BytesLike } from '@fuel-ts/interfaces';
import type { BN } from '@fuel-ts/math';
import type { BytesLike } from '@fuel-ts/utils';

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

Expand Down
1 change: 1 addition & 0 deletions packages/abi-coder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export {
calculateVmTxMemory,
ENCODING_V1,
} from './utils/constants';
export type { Bytes, RawSlice, StdString, StrSlice } from './utils/types';
4 changes: 4 additions & 0 deletions packages/abi-coder/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type Bytes = Uint8Array | number[];
export type RawSlice = Uint8Array | number[];
export type StdString = string;
export type StrSlice = string;
1 change: 0 additions & 1 deletion packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"license": "Apache-2.0",
"dependencies": {
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/interfaces": "workspace:^",
"@fuel-ts/utils": "workspace:*",
"@fuel-ts/versions": "workspace:*",
"commander": "12.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/abi-typegen/src/templates/contract/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
Provider,
Account,
StorageSlot,
AbstractAddress,
Address,
{{#each imports}}
{{this}},
{{/each}}
Expand Down Expand Up @@ -81,7 +81,7 @@ export class {{capitalizedName}} extends Contract {
};

constructor(
id: string | AbstractAddress,
id: string | Address,
accountOrProvider: Account | Provider,
) {
super(id, abi, accountOrProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
Provider,
Account,
StorageSlot,
AbstractAddress,
Address,
BigNumberish,
FunctionFragment,
InvokeFunction,
Expand Down Expand Up @@ -197,7 +197,7 @@ export class MyContract extends Contract {
};

constructor(
id: string | AbstractAddress,
id: string | Address,
accountOrProvider: Account | Provider,
) {
super(id, abi, accountOrProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
Provider,
Account,
StorageSlot,
AbstractAddress,
Address,
BigNumberish,
BN,
Bytes,
Expand Down Expand Up @@ -1248,7 +1248,7 @@ export class MyContract extends Contract {
};

constructor(
id: string | AbstractAddress,
id: string | Address,
accountOrProvider: Account | Provider,
) {
super(id, abi, accountOrProvider);
Expand Down
1 change: 0 additions & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@fuel-ts/crypto": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/hasher": "workspace:*",
"@fuel-ts/interfaces": "workspace:*",
"@fuel-ts/math": "workspace:*",
"@fuel-ts/merkle": "workspace:*",
"@fuel-ts/transactions": "workspace:*",
Expand Down
23 changes: 12 additions & 11 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UTXO_ID_LEN } from '@fuel-ts/abi-coder';
import type { WithAddress } from '@fuel-ts/address';
import { Address } from '@fuel-ts/address';
import { randomBytes } from '@fuel-ts/crypto';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { AbstractAccount } from '@fuel-ts/interfaces';
import type { AbstractAddress, BytesLike } from '@fuel-ts/interfaces';
import type { BigNumberish, BN } from '@fuel-ts/math';
import { bn } from '@fuel-ts/math';
import { InputType } from '@fuel-ts/transactions';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify, hexlify, isDefined } from '@fuel-ts/utils';
import { clone } from 'ramda';

Expand Down Expand Up @@ -46,6 +46,7 @@ import {
isRequestInputResource,
} from './providers/transaction-request/helpers';
import { mergeQuantities } from './providers/utils/merge-quantities';
import { AbstractAccount } from './types';
import { assembleTransferToContractScript } from './utils/formatTransferToContractScriptData';

export type TxParamsType = Pick<
Expand All @@ -54,13 +55,13 @@ export type TxParamsType = Pick<
>;

export type TransferParams = {
destination: string | AbstractAddress;
destination: string | Address;
amount: BigNumberish;
assetId?: BytesLike;
};

export type ContractTransferParams = {
contractId: string | AbstractAddress;
contractId: string | Address;
amount: BigNumberish;
assetId?: BytesLike;
};
Expand All @@ -76,11 +77,11 @@ export type FakeResources = Partial<Coin> & Required<Pick<Coin, 'amount' | 'asse
/**
* `Account` provides an abstraction for interacting with accounts or wallets on the network.
*/
export class Account extends AbstractAccount {
export class Account extends AbstractAccount implements WithAddress {
/**
* The address associated with the account.
*/
readonly address: AbstractAddress;
readonly address: Address;

/**
* The provider used to interact with the network.
Expand All @@ -99,7 +100,7 @@ export class Account extends AbstractAccount {
* @param provider - A Provider instance (optional).
* @param connector - A FuelConnector instance (optional).
*/
constructor(address: string | AbstractAddress, provider?: Provider, connector?: FuelConnector) {
constructor(address: string | Address, provider?: Provider, connector?: FuelConnector) {
super();
this._provider = provider;
this._connector = connector;
Expand Down Expand Up @@ -341,7 +342,7 @@ export class Account extends AbstractAccount {
* @returns A promise that resolves to the prepared transaction request.
*/
async createTransfer(
destination: string | AbstractAddress,
destination: string | Address,
amount: BigNumberish,
assetId?: BytesLike,
txParams: TxParamsType = {}
Expand All @@ -362,7 +363,7 @@ export class Account extends AbstractAccount {
* @returns A promise that resolves to the transaction response.
*/
async transfer(
destination: string | AbstractAddress,
destination: string | Address,
amount: BigNumberish,
assetId?: BytesLike,
txParams: TxParamsType = {}
Expand Down Expand Up @@ -435,7 +436,7 @@ export class Account extends AbstractAccount {
* @returns A promise that resolves to the transaction response.
*/
async transferToContract(
contractId: string | AbstractAddress,
contractId: string | Address,
amount: BigNumberish,
assetId?: BytesLike,
txParams: TxParamsType = {}
Expand Down Expand Up @@ -497,7 +498,7 @@ export class Account extends AbstractAccount {
* @returns A promise that resolves to the transaction response.
*/
async withdrawToBaseLayer(
recipient: string | AbstractAddress,
recipient: string | Address,
amount: BigNumberish,
txParams: TxParamsType = {}
): Promise<TransactionResponse> {
Expand Down
9 changes: 3 additions & 6 deletions packages/account/src/connectors/fuel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Address } from '@fuel-ts/address';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import type { AbstractAddress } from '@fuel-ts/interfaces';

import { Account } from '../account';
import { Provider } from '../providers';
Expand Down Expand Up @@ -62,10 +62,7 @@ interface FuelSdk {
hasWallet(): Promise<boolean>;
// #endregion connector-manager-method-hasWallet
// #region connector-manager-method-getWallet
getWallet(
address: string | AbstractAddress,
providerOrNetwork?: Provider | Network
): Promise<Account>;
getWallet(address: string | Address, providerOrNetwork?: Provider | Network): Promise<Account>;
// #endregion connector-manager-method-getWallet
// #region connector-manager-method-unsubscribe
unsubscribe(): void;
Expand Down Expand Up @@ -465,7 +462,7 @@ export class Fuel extends FuelConnector implements FuelSdk {
* connectors.
*/
async getWallet(
address: string | AbstractAddress,
address: string | Address,
providerOrNetwork?: Provider | Network
): Promise<Account> {
const provider = await this._getProvider(providerOrNetwork);
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/hdwallet/hdwallet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { computeHmac, ripemd160 } from '@fuel-ts/crypto';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { sha256 } from '@fuel-ts/hasher';
import type { BytesLike } from '@fuel-ts/interfaces';
import { bn, toBytes, toHex } from '@fuel-ts/math';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify, hexlify, concat, dataSlice, encodeBase58, decodeBase58 } from '@fuel-ts/utils';

import { Mnemonic } from '../mnemonic';
Expand Down
1 change: 1 addition & 0 deletions packages/account/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './account';
export * from './types';
export * from './wallet';
export * from './hdwallet';
export * from './mnemonic';
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/mnemonic/mnemonic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomBytes, pbkdf2, computeHmac } from '@fuel-ts/crypto';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { sha256 } from '@fuel-ts/hasher';
import type { BytesLike } from '@fuel-ts/interfaces';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify, hexlify, concat, dataSlice, encodeBase58, toUtf8Bytes } from '@fuel-ts/utils';

import { english } from '../wordlists';
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/mnemonic/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import { sha256 } from '@fuel-ts/hasher';
import type { BytesLike } from '@fuel-ts/interfaces';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify } from '@fuel-ts/utils';

/* Mnemonic phrase composed by words from the provided wordlist it can be a text or a array of words */
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/predicate/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { JsonAbi, InputValue } from '@fuel-ts/abi-coder';
import { Interface } from '@fuel-ts/abi-coder';
import { Address } from '@fuel-ts/address';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
import type { BytesLike } from '@fuel-ts/interfaces';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify, hexlify } from '@fuel-ts/utils';

import type { FakeResources } from '../account';
Expand Down
Loading
Loading