Skip to content

Commit

Permalink
chore!: redistributed the @fuel-ts/interfaces package (#3492)
Browse files Browse the repository at this point in the history
* chore: removed `@fuel-ts/interfaces` package and `AbstractAddress`

* chore: finalize changes

* chore: fix logger test

* chore: changeset

* chore: update changeset

* chore: fixed changeset

* chore: fixed failing tests

* Update packages/logger/test/index.test.ts

* chore: fix import

* chore: fixed import

---------

Co-authored-by: Anderson Arboleya <[email protected]>
Co-authored-by: Sérgio Torres <[email protected]>
  • Loading branch information
3 people authored Jan 7, 2025
1 parent e83b237 commit 0b4c3ab
Show file tree
Hide file tree
Showing 127 changed files with 318 additions and 1,145 deletions.
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
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,7 +4,7 @@ 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: `b256Address`. This property is a string encoded in [`B256`](../types/bits256.md) format.

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; `b256Address`, which is of the [`B256`](./bits256.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; `b256Address`, which is of the [`B256`](./bits256.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 b256 address

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 @@ -25,13 +25,13 @@ This guide demonstrates how to convert between address formats and Sway Standard

## 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
3 changes: 1 addition & 2 deletions packages/abi-coder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"dependencies": {
"@fuel-ts/crypto": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/hasher": "workspace:*",
"@fuel-ts/interfaces": "workspace:*",
"@fuel-ts/hasher": "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 Down Expand Up @@ -369,7 +370,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 @@ -437,7 +438,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 @@ -499,7 +500,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
2 changes: 1 addition & 1 deletion packages/account/src/predicate/utils/getPredicateRoot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { hash } from '@fuel-ts/hasher';
import type { BytesLike } from '@fuel-ts/interfaces';
import { calcRoot } from '@fuel-ts/merkle';
import { chunkAndPadBytes, hexlify, concat, arrayify } from '@fuel-ts/utils';
import type { BytesLike } from '@fuel-ts/utils';

/**
* @hidden
Expand Down
Loading

0 comments on commit 0b4c3ab

Please sign in to comment.