Skip to content

Commit

Permalink
chore: deprecate network URLs, add asset ID and chain ID for mainnet (#…
Browse files Browse the repository at this point in the history
…3107)

* export `MAINNET_NETWORK_URL`

* add chainid and assetid for mainnet

* add changeset

* update changeset

* update changeset

* remove constant, add deprecation notice

* update changeset

* replace all url constant instances w hardcoded values

* fix test

* rename variable

* move constants inside `@internal/utils`

* fix test

* re-use tsup config

* Delete vite.config.ts.timestamp-1725856816588-3e7d000dce87b.mjs

* update changeset

Co-authored-by: Peter Smith <[email protected]>

---------

Co-authored-by: Peter Smith <[email protected]>
  • Loading branch information
Dhaiwat10 and petertonysmith94 authored Sep 11, 2024
1 parent 65f3e04 commit c98461f
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .changeset/silent-bees-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": patch
"create-fuels": patch
---

chore: deprecate network URLs, add asset ID and chain ID for mainnet
4 changes: 2 additions & 2 deletions apps/create-fuels-counter-guide/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, BN, TESTNET_NETWORK_URL } from 'fuels';
import { Account, BN } from 'fuels';

// #region deploying-dapp-to-testnet-lib-current-environment
// The two environments for the dapp are local and testnet.
Expand All @@ -21,7 +21,7 @@ export const CURRENT_ENVIRONMENT: Environment =
export const NODE_URL =
CURRENT_ENVIRONMENT === Environments.LOCAL
? `http://127.0.0.1:${process.env.VITE_FUEL_NODE_PORT || 4000}/v1/graphql`
: TESTNET_NETWORK_URL;
: 'https://testnet.fuel.network/v1/graphql';

export interface AppWallet {
wallet?: Account;
Expand Down
22 changes: 10 additions & 12 deletions apps/docs-snippets/src/guide/contracts/deploying-contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-shadow */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Provider, TESTNET_NETWORK_URL, Wallet, ContractFactory, hexlify } from 'fuels';
import { Provider, Wallet, ContractFactory, hexlify } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import { EchoValuesFactory as TypegenFactory, EchoValues } from '../../../test/typegen';
Expand All @@ -14,12 +12,12 @@ describe('Deploying Contracts', () => {
using launched = await launchTestNode();

const { provider: testProvider } = launched;
const TESTNET_NETWORK_URL = testProvider.url;
const providerUrl = testProvider.url;

// #region get-contract-max-size
// #import { Provider, TESTNET_NETWORK_URL };
// #import { Provider };

const provider = await Provider.create(TESTNET_NETWORK_URL);
const provider = await Provider.create(providerUrl);
const { consensusParameters } = provider.getChain();
const contractSizeLimit = consensusParameters.contractParameters.contractMaxSize;
// #endregion get-contract-max-size
Expand All @@ -33,16 +31,16 @@ describe('Deploying Contracts', () => {
provider: testProvider,
wallets: [testWallet],
} = launched;
const TESTNET_NETWORK_URL = testProvider.url;
const providerUrl = testProvider.url;
const WALLET_PVT_KEY = testWallet.privateKey;
const bytecode = TypegenFactory.bytecode;

// #region setup
// #import { Provider, TESTNET_NETWORK_URL, Wallet };
// #import { Provider, Wallet };
// #context import { WALLET_PVT_KEY } from 'path/to/my/env/file';
// #context import { TypegenFactory } from 'path/to/typegen/outputs';

const provider = await Provider.create(TESTNET_NETWORK_URL);
const provider = await Provider.create(providerUrl);
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
const factory = new TypegenFactory(wallet);
// #endregion setup
Expand Down Expand Up @@ -77,17 +75,17 @@ describe('Deploying Contracts', () => {
provider: testProvider,
wallets: [testWallet],
} = launched;
const TESTNET_NETWORK_URL = testProvider.url;
const providerUrl = testProvider.url;
const WALLET_PVT_KEY = testWallet.privateKey;
const abi = EchoValues.abi;
const bytecode = TypegenFactory.bytecode;

// #region blobs
// #import { Provider, TESTNET_NETWORK_URL, Wallet, ContractFactory };
// #import { Provider, Wallet, ContractFactory };
// #context import { WALLET_PVT_KEY } from 'path/to/my/env/file';
// #context import { bytecode, abi } from 'path/to/typegen/outputs';

const provider = await Provider.create(TESTNET_NETWORK_URL);
const provider = await Provider.create(providerUrl);
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
const factory = new ContractFactory(bytecode, abi, wallet);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TESTNET_NETWORK_URL, Provider, Wallet, WalletUnlocked } from 'fuels';
import { Provider, Wallet, WalletUnlocked } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

/**
Expand Down Expand Up @@ -37,10 +37,10 @@ describe('Getting started', () => {
vi.spyOn(Provider, 'create').mockResolvedValueOnce(mockedProvider);

// #region connecting-to-the-testnet
// #import { Provider, Wallet, TESTNET_NETWORK_URL };
// #import { Provider, Wallet };

// Create a provider, with the Latest Testnet URL.
const provider = await Provider.create(TESTNET_NETWORK_URL);
const provider = await Provider.create('https://testnet.fuel.network/v1/graphql');

// Create our wallet (with a private key).
const PRIVATE_KEY = 'a1447cd75accc6b71a976fd3401a1f6ce318d27ba660b0315ee6ac347bf39568';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Provider, ScriptTransactionRequest, Wallet, TESTNET_NETWORK_URL } from 'fuels';
import { Provider, ScriptTransactionRequest, Wallet } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import { ConfigurablePin as PredicateFactory } from '../../../test/typegen';
Expand All @@ -19,19 +18,19 @@ describe('Predicate Custom Transactions', () => {

const SENDER_PVT_KEY = testSender.privateKey;
const RECEIVER_ADDRESS = testReceiver.address;
// eslint-disable-next-line @typescript-eslint/no-shadow
const TESTNET_NETWORK_URL = testProvider.url;

const providerUrl = testProvider.url;

const initialRecieverBalance = await testReceiver.getBalance(testProvider.getBaseAssetId());

// #region predicate-custom-transaction
// #import { Provider, ScriptTransactionRequest, TESTNET_NETWORK_URL, Wallet };
// #import { Provider, ScriptTransactionRequest, Wallet };
// #context import { PredicateFactory } from 'path/to/typegen/outputs';
// #context import type { PredicateInputs } from 'path/to/typegen/outputs';
// #context import { SENDER_PVT_KEY, RECEIVER_ADDRESS } from 'path/to/my/env/file';

// Setup
const provider = await Provider.create(TESTNET_NETWORK_URL);
const provider = await Provider.create(providerUrl);
const sender = Wallet.fromPrivateKey(SENDER_PVT_KEY, provider);
const receiver = Wallet.fromAddress(RECEIVER_ADDRESS, provider);
const assetId = provider.getBaseAssetId();
Expand Down
1 change: 1 addition & 0 deletions internal/utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This package contains some internal utilities used by the SDK, which we don't want to export to our users.
26 changes: 26 additions & 0 deletions internal/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"private": true,
"name": "@internal/utils",
"version": "0.0.1",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"postbuild": "tsx ../../scripts/postbuild.ts"
},
"license": "Apache-2.0",
"devDependencies": {
"@internal/tsup": "workspace:*"
}
}
2 changes: 2 additions & 0 deletions internal/utils/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const DEVNET_NETWORK_URL = 'https://devnet.fuel.network/v1/graphql';
export const TESTNET_NETWORK_URL = 'https://testnet.fuel.network/v1/graphql';
1 change: 1 addition & 0 deletions internal/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './constants';
7 changes: 7 additions & 0 deletions internal/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["src"]
}
3 changes: 3 additions & 0 deletions internal/utils/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { index } from '@internal/tsup';

export default index;
3 changes: 2 additions & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"@graphql-codegen/typescript-generic-sdk": "^4.0.1",
"@graphql-codegen/typescript-operations": "^4.2.3",
"@types/ramda": "^0.30.2",
"get-graphql-schema": "^2.1.2"
"get-graphql-schema": "^2.1.2",
"@internal/utils": "workspace:*"
}
}
6 changes: 4 additions & 2 deletions packages/account/src/configs.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from '@internal/utils';

/**
* @group node
* @group browser
*/
describe('Configs', () => {
it('exports DEVNET_NETWORK_URL', async () => {
const configs = await import('./configs');
expect(configs.DEVNET_NETWORK_URL).toBe('https://devnet.fuel.network/v1/graphql');
expect(configs.DEVNET_NETWORK_URL).toBe(DEVNET_NETWORK_URL);
});

it('exports TESTNET_NETWORK_URL', async () => {
const configs = await import('./configs');
expect(configs.TESTNET_NETWORK_URL).toBe('https://testnet.fuel.network/v1/graphql');
expect(configs.TESTNET_NETWORK_URL).toBe(TESTNET_NETWORK_URL);
});
});
9 changes: 7 additions & 2 deletions packages/account/src/configs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/**
* @deprecated This export is deprecated and will be removed in the future.
*/
export const DEVNET_NETWORK_URL = 'https://devnet.fuel.network/v1/graphql';

/**
* @deprecated This export is deprecated and will be removed in the future.
*/
export const TESTNET_NETWORK_URL = 'https://testnet.fuel.network/v1/graphql';
// TODO: replace placeholder with mainnet network url
// export const NETWORK_URL = '';
6 changes: 6 additions & 0 deletions packages/account/src/providers/assets/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export const rawAssets: Assets = [
chainId: CHAIN_IDS.fuel.testnet,
decimals: 9,
assetId: '0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07'
},
{
type: 'fuel',
chainId: CHAIN_IDS.fuel.mainnet,
decimals: 9,
assetId: '0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07',
}
],
},
Expand Down
1 change: 1 addition & 0 deletions packages/account/src/providers/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export const CHAIN_IDS = {
fuel: {
devnet: 0,
testnet: 0,
mainnet: 9889,
},
};
5 changes: 3 additions & 2 deletions packages/account/test/fuel-wallet-connector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils';
import type { AbstractAddress, BytesLike } from '@fuel-ts/interfaces';
import type { BN } from '@fuel-ts/math';
import { bn } from '@fuel-ts/math';
import { TESTNET_NETWORK_URL } from '@internal/utils';
import { EventEmitter } from 'events';

import type { ProviderOptions } from '../src';
Expand Down Expand Up @@ -180,7 +181,7 @@ describe('Fuel Connector', () => {
storage: null,
connectors: [new MockConnector()],
}).init();
const networkUrl = 'https://testnet.fuel.network';
const networkUrl = TESTNET_NETWORK_URL;
const newNetwork = {
url: networkUrl,
chainId: 0,
Expand Down Expand Up @@ -208,7 +209,7 @@ describe('Fuel Connector', () => {
connectors: [new MockConnector()],
}).init();
const newNetwork = {
url: 'https://testnet.fuel.network/',
url: TESTNET_NETWORK_URL,
chainId: 0,
};

Expand Down
3 changes: 2 additions & 1 deletion packages/fuel-gauge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@fuel-ts/account": "workspace:*",
"@internal/forc": "workspace:*",
"@fuel-ts/utils": "workspace:*",
"@fuel-ts/errors": "workspace:*"
"@fuel-ts/errors": "workspace:*",
"@internal/utils": "workspace:*"
}
}
12 changes: 2 additions & 10 deletions packages/fuel-gauge/src/e2e-script.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
/* eslint-disable no-console */
import {
DEVNET_NETWORK_URL,
TESTNET_NETWORK_URL,
Provider,
TransactionType,
WalletUnlocked,
CHAIN_IDS,
rawAssets,
assets,
} from 'fuels';
import { DEVNET_NETWORK_URL, TESTNET_NETWORK_URL } from '@internal/utils';
import { Provider, TransactionType, WalletUnlocked, CHAIN_IDS, rawAssets, assets } from 'fuels';

import { ScriptMainArgBool } from '../test/typegen';

Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions templates/nextjs/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, BN, TESTNET_NETWORK_URL } from 'fuels';
import { Account, BN } from 'fuels';

// The two environments for the dapp are local and testnet.
export const Environments = {
Expand All @@ -19,7 +19,7 @@ export const CURRENT_ENVIRONMENT: Environment =
export const NODE_URL =
CURRENT_ENVIRONMENT === Environments.LOCAL
? `http://127.0.0.1:${process.env.NEXT_PUBLIC_FUEL_NODE_PORT || 4000}/v1/graphql`
: TESTNET_NETWORK_URL;
: 'https://testnet.fuel.network/v1/graphql';

export interface AppWallet {
wallet?: Account;
Expand Down
4 changes: 2 additions & 2 deletions templates/vite/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, BN, TESTNET_NETWORK_URL } from 'fuels';
import { Account, BN } from 'fuels';

// The two environments for the dapp are local and testnet.
export const Environments = {
Expand All @@ -19,7 +19,7 @@ export const CURRENT_ENVIRONMENT: Environment =
export const NODE_URL =
CURRENT_ENVIRONMENT === Environments.LOCAL
? `http://127.0.0.1:${process.env.VITE_FUEL_NODE_PORT || 4000}/v1/graphql`
: TESTNET_NETWORK_URL;
: 'https://testnet.fuel.network/v1/graphql';

export interface AppWallet {
wallet?: Account;
Expand Down

0 comments on commit c98461f

Please sign in to comment.