diff --git a/.changeset/chatty-camels-wave.md b/.changeset/chatty-camels-wave.md new file mode 100644 index 00000000000..cf8cb8f06f7 --- /dev/null +++ b/.changeset/chatty-camels-wave.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": minor +--- + +fix!: remove unnecessary nonce from message gql queries \ No newline at end of file diff --git a/.changeset/many-rings-joke.md b/.changeset/many-rings-joke.md new file mode 100644 index 00000000000..d087a211fa9 --- /dev/null +++ b/.changeset/many-rings-joke.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": minor +--- + +chore!: mandate `abi` in `Predicate` constructor diff --git a/.changeset/orange-panthers-lay.md b/.changeset/orange-panthers-lay.md new file mode 100644 index 00000000000..c87f6bfe52a --- /dev/null +++ b/.changeset/orange-panthers-lay.md @@ -0,0 +1,4 @@ +--- +--- + +chore: use typegen'd outputs in some fuel-gauge tests diff --git a/.changeset/smart-olives-attend.md b/.changeset/smart-olives-attend.md new file mode 100644 index 00000000000..1a850a4ec23 --- /dev/null +++ b/.changeset/smart-olives-attend.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": minor +--- + +chore!: remove `blockId` in transaction list responses diff --git a/.changeset/thirty-waves-grin.md b/.changeset/thirty-waves-grin.md new file mode 100644 index 00000000000..bd59a9a36d5 --- /dev/null +++ b/.changeset/thirty-waves-grin.md @@ -0,0 +1,5 @@ +--- +"fuels": patch +--- + +fix: bump proxy contract versions diff --git a/.changeset/yellow-trees-talk.md b/.changeset/yellow-trees-talk.md new file mode 100644 index 00000000000..8556e240630 --- /dev/null +++ b/.changeset/yellow-trees-talk.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/transactions": patch +"@fuel-ts/account": patch +--- + +chore: fix receipts properties and deprecate incorrect ones diff --git a/.changeset/young-steaks-brake.md b/.changeset/young-steaks-brake.md new file mode 100644 index 00000000000..34c0c351b5e --- /dev/null +++ b/.changeset/young-steaks-brake.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": minor +--- + +chore!: optimize coin gql queries diff --git a/apps/docs-snippets/src/guide/contracts/add-transfer.test.ts b/apps/docs-snippets/src/guide/contracts/add-transfer.test.ts deleted file mode 100644 index 78d2cb5de16..00000000000 --- a/apps/docs-snippets/src/guide/contracts/add-transfer.test.ts +++ /dev/null @@ -1,83 +0,0 @@ -import type { TransferParams } from 'fuels'; -import { Wallet } from 'fuels'; -import { ASSET_A, ASSET_B, launchTestNode } from 'fuels/test-utils'; - -import { EchoValuesFactory } from '../../../test/typegen'; - -/** - * @group node - * @group browser - */ -describe('Add Transfer', () => { - it('should successfully execute addTransfer for one recipient', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: EchoValuesFactory, - }, - ], - }); - const { - provider, - contracts: [contract], - } = launched; - // #region add-transfer-1 - const recipient = Wallet.generate({ provider }); - - const { waitForResult } = await contract.functions - .echo_u64(100) - .addTransfer({ - destination: recipient.address, - amount: 100, - assetId: provider.getBaseAssetId(), - }) - .call(); - - await waitForResult(); - // #endregion add-transfer-1 - - const recipientBalance = await recipient.getBalance(provider.getBaseAssetId()); - - expect(recipientBalance.toNumber()).toBe(100); - }); - - it('should successfully execute multiple addTransfer for multiple recipients', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: EchoValuesFactory, - }, - ], - }); - const { - provider, - contracts: [contract], - } = launched; - // #region add-transfer-2 - const recipient1 = Wallet.generate({ provider }); - const recipient2 = Wallet.generate({ provider }); - - const transferParams: TransferParams[] = [ - { destination: recipient1.address, amount: 100, assetId: provider.getBaseAssetId() }, - { destination: recipient1.address, amount: 400, assetId: ASSET_A }, - { destination: recipient2.address, amount: 300, assetId: ASSET_B }, - ]; - - const { waitForResult } = await contract.functions - .echo_u64(100) - .addBatchTransfer(transferParams) - .call(); - - await waitForResult(); - // #endregion add-transfer-2 - - const recipient1BalanceBaseAsset = await recipient1.getBalance(provider.getBaseAssetId()); - const recipient1BalanceAssetA = await recipient1.getBalance(ASSET_A); - - const recipient2BalanceAssetB = await recipient2.getBalance(ASSET_B); - - expect(recipient1BalanceBaseAsset.toNumber()).toBe(100); - expect(recipient1BalanceAssetA.toNumber()).toBe(400); - expect(recipient2BalanceAssetB.toNumber()).toBe(300); - }); -}); diff --git a/apps/docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts b/apps/docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts deleted file mode 100644 index 8aef10c18c4..00000000000 --- a/apps/docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { Contract } from 'fuels'; -import { launchTestNode } from 'fuels/test-utils'; - -import { CounterFactory } from '../../../test/typegen'; - -/** - * @group node - * @group browser - */ -describe('Interacting with Contracts', () => { - it('should successfully use "get" to read from the blockchain', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [counterContract], - provider, - } = launched; - - const { waitForResult } = await counterContract.functions.increment_counter(1).call(); - await waitForResult(); - - const { id: contractId, interface: abi } = counterContract; - - // #region interacting-with-contracts-1 - const contract = new Contract(contractId, abi, provider); - - const { value } = await contract.functions.get_count().get(); - // #endregion interacting-with-contracts-1 - expect(value.toNumber()).toBeGreaterThanOrEqual(1); - }); - - it('should successfully use "dryRun" to validate a TX without a wallet', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [counterContract], - provider, - } = launched; - - const { id: contractId, interface: abi } = counterContract; - - // #region interacting-with-contracts-2 - const contract = new Contract(contractId, abi, provider); - - const { value } = await contract.functions.increment_counter(1).dryRun(); - // #endregion interacting-with-contracts-2 - expect(value.toNumber()).toBeGreaterThanOrEqual(1); - }); - - it('should successfully use "simulate" to validate if wallet can pay for transaction', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [counterContract], - wallets: [fundedWallet], - } = launched; - - const { id: contractId, interface: abi } = counterContract; - - // #region interacting-with-contracts-3 - const contract = new Contract(contractId, abi, fundedWallet); - - const { value } = await contract.functions.increment_counter(10).simulate(); - // #endregion interacting-with-contracts-3 - expect(value.toNumber()).toBeGreaterThanOrEqual(10); - }); - - it('should successfully execute a contract call without a wallet [call]', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [contract], - } = launched; - - // #region interacting-with-contracts-4 - const { transactionId, waitForResult } = await contract.functions.increment_counter(10).call(); - - const { value } = await waitForResult(); - // #endregion interacting-with-contracts-4 - - expect(transactionId).toBeDefined(); - expect(value.toNumber()).toBeGreaterThanOrEqual(10); - }); - - it('should successfully execute a contract call without a wallet [call]', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [contract], - } = launched; - - // #region interacting-with-contracts-5 - const { waitForResult } = await contract.functions.increment_counter(10).call(); - const { value } = await waitForResult(); - // #endregion interacting-with-contracts-5 - - expect(value.toNumber()).toBeGreaterThanOrEqual(10); - }); -}); diff --git a/apps/docs-snippets/src/guide/contracts/is-function-readonly.test.ts b/apps/docs-snippets/src/guide/contracts/is-function-readonly.test.ts deleted file mode 100644 index d4f2925933a..00000000000 --- a/apps/docs-snippets/src/guide/contracts/is-function-readonly.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { launchTestNode } from 'fuels/test-utils'; - -import { CounterFactory } from '../../../test/typegen'; - -/** - * @group node - * @group browser - */ -test('isReadOnly returns true for read-only functions', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [contract], - } = launched; - - // #region is-function-readonly-1 - - const isReadOnly = contract.functions.get_count.isReadOnly(); - - if (isReadOnly) { - await contract.functions.get_count().get(); - } else { - const { waitForResult } = await contract.functions.get_count().call(); - await waitForResult(); - } - // #endregion is-function-readonly-1 - - expect(isReadOnly).toBe(true); -}); diff --git a/apps/docs-snippets/src/guide/contracts/minted-token-asset-id.test.ts b/apps/docs-snippets/src/guide/contracts/minted-token-asset-id.test.ts deleted file mode 100644 index 670566742bc..00000000000 --- a/apps/docs-snippets/src/guide/contracts/minted-token-asset-id.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import type { AssetId } from 'fuels'; -import { bn, getMintedAssetId, createAssetId } from 'fuels'; -import { launchTestNode } from 'fuels/test-utils'; - -import { EchoAssetIdFactory, TokenFactory } from '../../../test/typegen'; - -/** - * @group node - * @group browser - */ -describe('Minted Token Asset Id', () => { - it('should successfully execute contract call with forwarded amount', async () => { - using launched = await launchTestNode({ - contractsConfigs: [{ factory: TokenFactory }], - }); - - const { - contracts: [contract], - } = launched; - - // #region minted-token-asset-id-2 - // #import { bn, getMintedAssetId }; - - // Any valid bits256 string can be used as a sub ID - const subID = '0xc7fd1d987ada439fc085cfa3c49416cf2b504ac50151e3c2335d60595cb90745'; - const mintAmount = bn(1000); - - const { waitForResult } = await contract.functions.mint_coins(subID, mintAmount).call(); - const txResult = await waitForResult(); - - const mintedAssetId = getMintedAssetId(contract.id.toB256(), subID); - // #endregion minted-token-asset-id-2 - - expect(mintedAssetId).toBeDefined(); - expect(txResult.transactionResult.isStatusSuccess).toBeTruthy(); - }); - - it('should create valid asset ID', async () => { - using launched = await launchTestNode({ - contractsConfigs: [{ factory: EchoAssetIdFactory }], - }); - - const { - contracts: [contract], - } = launched; - - // #region create-asset-id-1 - // #import { createAssetId, AssetId }; - - const subID = '0xc7fd1d987ada439fc085cfa3c49416cf2b504ac50151e3c2335d60595cb90745'; - - const assetId: AssetId = createAssetId(contract.id.toB256(), subID); - // #endregion create-asset-id-1 - const { value } = await contract.functions.echo_asset_id_input(assetId).simulate(); - - expect(assetId).toBeDefined(); - expect(value).toEqual(assetId); - }); -}); diff --git a/apps/docs-snippets/src/guide/contracts/multicalls.test.ts b/apps/docs-snippets/src/guide/contracts/multicalls.test.ts deleted file mode 100644 index 728cec3b09a..00000000000 --- a/apps/docs-snippets/src/guide/contracts/multicalls.test.ts +++ /dev/null @@ -1,141 +0,0 @@ -import { bn, BN } from 'fuels'; -import { launchTestNode } from 'fuels/test-utils'; - -import { CounterFactory, EchoValuesFactory, ReturnContextFactory } from '../../../test/typegen'; - -/** - * @group node - * @group browser - */ -describe('Multicalls', () => { - it('should successfully submit multiple calls from the same contract function', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [counterContract], - } = launched; - - // #region multicall-1 - const { waitForResult } = await counterContract - .multiCall([ - counterContract.functions.get_count(), - counterContract.functions.increment_counter(2), - counterContract.functions.increment_counter(4), - ]) - .call(); - - const { value: results } = await waitForResult(); - - expect(results[0].toNumber()).toBe(0); - expect(results[1].toNumber()).toBe(2); - expect(results[2].toNumber()).toBe(6); - // #endregion multicall-1 - }); - - it('should successfully submit multiple calls from different contracts functions', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: EchoValuesFactory, - }, - { - factory: CounterFactory, - }, - ], - }); - - const { - contracts: [echoContract, counterContract], - } = launched; - - // #region multicall-2 - const { waitForResult } = await echoContract - .multiCall([ - echoContract.functions.echo_u8(17), - counterContract.functions.get_count(), - counterContract.functions.increment_counter(5), - ]) - .call(); - - const { value: results } = await waitForResult(); - - expect(results[0]).toEqual(17); - expect(results[1].toNumber()).toBe(0); - expect(results[2].toNumber()).toBe(5); - // #endregion multicall-2 - }); - - it('should successfully submit multiple calls from different contracts functions', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: ReturnContextFactory, - }, - { - factory: EchoValuesFactory, - }, - ], - }); - - const { - contracts: [contextContract, echoContract], - provider, - } = launched; - - // #region multicall-3 - const { waitForResult } = await contextContract - .multiCall([ - echoContract.functions.echo_u8(10), - contextContract.functions.return_context_amount().callParams({ - forward: [100, provider.getBaseAssetId()], - }), - ]) - .call(); - - const { value: results } = await waitForResult(); - - const echoedValue = results[0]; - const fowardedValue = new BN(results[1]).toNumber(); - - expect(echoedValue).toEqual(10); - expect(fowardedValue).toEqual(100); - // #endregion multicall-3 - }); - - it('should successfully submit multiple read-only calls', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: CounterFactory, - }, - { - factory: EchoValuesFactory, - }, - ], - }); - - const { - contracts: [counterContract, echoValuesContract], - } = launched; - - // #region multicall-4 - const { value: results } = await counterContract - .multiCall([ - counterContract.functions.get_count(), - echoValuesContract.functions.echo_u8(10), - echoValuesContract.functions.echo_str('Fuel'), - ]) - .get(); - - expect(results[0].toNumber()).toBe(bn(0).toNumber()); - expect(results[1]).toBe(10); - expect(results[2]).toBe('Fuel'); - // #endregion multicall-4 - }); -}); diff --git a/apps/docs-snippets/src/guide/contracts/variable-outputs.test.ts b/apps/docs-snippets/src/guide/contracts/variable-outputs.test.ts deleted file mode 100644 index 2d7de39e0bd..00000000000 --- a/apps/docs-snippets/src/guide/contracts/variable-outputs.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { getMintedAssetId, getRandomB256, Wallet } from 'fuels'; -import { launchTestNode } from 'fuels/test-utils'; - -import { TokenFactory } from '../../../test/typegen'; - -/** - * @group node - * @group browser - */ -describe('Variable Outputs', () => { - it('should successfully execute contract call with variable outputs', async () => { - using launched = await launchTestNode({ - contractsConfigs: [ - { - factory: TokenFactory, - }, - ], - }); - - const { - contracts: [contract], - } = launched; - - const subId = getRandomB256(); - - const call1 = await contract.functions.mint_coins(subId, 100).call(); - await call1.waitForResult(); - - const address = { bits: Wallet.generate().address.toB256() }; - const assetId = { bits: getMintedAssetId(contract.id.toB256(), subId) }; - - // #region variable-outputs-2 - const { waitForResult } = await contract.functions - .transfer_to_address(address, assetId, 100) - .txParams({ - variableOutputs: 1, - }) - .call(); - - const { transactionResult } = await waitForResult(); - // #endregion variable-outputs-2 - - expect(transactionResult.isStatusSuccess).toBeTruthy(); - }); -}); diff --git a/apps/docs-snippets/test/fixtures/forc-projects/echo-values/src/main.sw b/apps/docs-snippets/test/fixtures/forc-projects/echo-values/src/main.sw index 87bb47a673d..03a7ca5247b 100644 --- a/apps/docs-snippets/test/fixtures/forc-projects/echo-values/src/main.sw +++ b/apps/docs-snippets/test/fixtures/forc-projects/echo-values/src/main.sw @@ -1,4 +1,3 @@ -// #region understanding-fuel-binary-file contract; use std::b512::B512; @@ -45,4 +44,3 @@ impl EchoValues for Contract { value } } -// #endregion understanding-fuel-binary-file diff --git a/apps/docs-snippets/test/fixtures/forc-projects/token/src/main.sw b/apps/docs-snippets/test/fixtures/forc-projects/token/src/main.sw index 65084202343..fe27fa75290 100644 --- a/apps/docs-snippets/test/fixtures/forc-projects/token/src/main.sw +++ b/apps/docs-snippets/test/fixtures/forc-projects/token/src/main.sw @@ -11,7 +11,6 @@ abi Token { } impl Token for Contract { - // #region variable-outputs-1 fn transfer_to_address(recipient: Address, asset_id: AssetId, amount: u64) { transfer(Identity::Address(recipient), asset_id, amount); } @@ -19,7 +18,7 @@ impl Token for Contract { fn transfer_to_contract(target: ContractId, asset_id: AssetId, amount: u64) { transfer(Identity::ContractId(target), asset_id, amount); } - // #endregion variable-outputs-1 + fn mint_coins(sub_id: b256, mint_amount: u64) { mint(sub_id, mint_amount); } diff --git a/apps/docs-snippets2/src/contracts/methods/call.ts b/apps/docs-snippets2/src/contracts/methods/call.ts new file mode 100644 index 00000000000..f589ec945a3 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/methods/call.ts @@ -0,0 +1,19 @@ +// #region interacting-with-contracts-4 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await CounterFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +// Perform the transaction +const { waitForResult } = await contract.functions.increment_count(10).call(); + +const { value } = await waitForResult(); +// #endregion interacting-with-contracts-4 + +console.log('Value should equal 10', value.toNumber() === 10); diff --git a/apps/docs-snippets2/src/contracts/methods/dry-run.ts b/apps/docs-snippets2/src/contracts/methods/dry-run.ts new file mode 100644 index 00000000000..9d0e9c1c8d0 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/methods/dry-run.ts @@ -0,0 +1,17 @@ +// #region interacting-with-contracts-2 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await CounterFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +// Perform a dry-run of the transaction +const { value } = await contract.functions.increment_count(1).dryRun(); +// #endregion interacting-with-contracts-2 + +console.log('Value should equal 1', value.toNumber() === 1); diff --git a/apps/docs-snippets2/src/contracts/methods/get.ts b/apps/docs-snippets2/src/contracts/methods/get.ts new file mode 100644 index 00000000000..21683065fd9 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/methods/get.ts @@ -0,0 +1,18 @@ +// #region interacting-with-contracts-1 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await CounterFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +// Read from the blockchain +const { value } = await contract.functions.get_count().get(); +// 0 +// #endregion interacting-with-contracts-1 + +console.log('Value should equal 0', value.toNumber() === 0); diff --git a/apps/docs-snippets2/src/contracts/methods/is-read-only.ts b/apps/docs-snippets2/src/contracts/methods/is-read-only.ts new file mode 100644 index 00000000000..edab7d83c8d --- /dev/null +++ b/apps/docs-snippets2/src/contracts/methods/is-read-only.ts @@ -0,0 +1,26 @@ +// #region is-function-readonly-1 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await CounterFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +const isReadOnly = contract.functions.get_count.isReadOnly(); + +if (isReadOnly) { + await contract.functions.get_count().get(); +} else { + const { waitForResult } = await contract.functions.get_count().call(); + await waitForResult(); +} +// #endregion is-function-readonly-1 + +console.log( + 'isReadOnly should be true for get_count method', + isReadOnly === true +); diff --git a/apps/docs-snippets2/src/contracts/methods/simulate.ts b/apps/docs-snippets2/src/contracts/methods/simulate.ts new file mode 100644 index 00000000000..a702c1f84c0 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/methods/simulate.ts @@ -0,0 +1,17 @@ +// #region interacting-with-contracts-3 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await CounterFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +// Simulate the transaction +const { value } = await contract.functions.increment_count(10).simulate(); +// #endregion interacting-with-contracts-3 + +console.log('Value should equal 10', value.toNumber() === 10); diff --git a/apps/docs-snippets2/src/contracts/multi-call/different-contracts-chain-methods.ts b/apps/docs-snippets2/src/contracts/multi-call/different-contracts-chain-methods.ts new file mode 100644 index 00000000000..2a2ee1da752 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/multi-call/different-contracts-chain-methods.ts @@ -0,0 +1,31 @@ +// #region multicall-3 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { EchoValuesFactory, ReturnContextFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const echoContractTx = await EchoValuesFactory.deploy(deployer); +const { contract: echoContract } = await echoContractTx.waitForResult(); +const returnContextTx = await ReturnContextFactory.deploy(deployer); +const { contract: returnContextContract } = + await returnContextTx.waitForResult(); + +const { waitForResult } = await echoContract + .multiCall([ + echoContract.functions.echo_u8(10), + returnContextContract.functions.return_context_amount().callParams({ + forward: [100, provider.getBaseAssetId()], + }), + ]) + .call(); + +const { value: results } = await waitForResult(); +// results[0] == 10 +// results[1] == BN <100> +// #endregion multicall-3 + +console.log('result[0]', results[0] === 10); +console.log('result[1]', results[1].toNumber() === 100); diff --git a/apps/docs-snippets2/src/contracts/multi-call/different-contracts-readonly.ts b/apps/docs-snippets2/src/contracts/multi-call/different-contracts-readonly.ts new file mode 100644 index 00000000000..e8e3930543f --- /dev/null +++ b/apps/docs-snippets2/src/contracts/multi-call/different-contracts-readonly.ts @@ -0,0 +1,31 @@ +// #region multicall-4 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory, EchoValuesFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const counterContractTx = await CounterFactory.deploy(deployer); +const { contract: counterContract } = await counterContractTx.waitForResult(); +const echoContractTx = await EchoValuesFactory.deploy(deployer); +const { contract: echoContract } = await echoContractTx.waitForResult(); + +const { waitForResult } = await echoContract + .multiCall([ + counterContract.functions.get_count(), + echoContract.functions.echo_u8(10), + echoContract.functions.echo_str('Fuel'), + ]) + .call(); + +const { value: results } = await waitForResult(); +// results[0] == BN <0> +// results[1] == 10 +// results[2] == 'Fuel' +// #endregion multicall-4 + +console.log('result[0]', results[0].toNumber() === 0); +console.log('result[1]', results[1] === 10); +console.log('result[2]', results[2] === 'Fuel'); diff --git a/apps/docs-snippets2/src/contracts/multi-call/different-contracts.ts b/apps/docs-snippets2/src/contracts/multi-call/different-contracts.ts new file mode 100644 index 00000000000..e8eb3d7b98d --- /dev/null +++ b/apps/docs-snippets2/src/contracts/multi-call/different-contracts.ts @@ -0,0 +1,31 @@ +// #region multicall-2 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory, EchoValuesFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const counterContractTx = await CounterFactory.deploy(deployer); +const { contract: counterContract } = await counterContractTx.waitForResult(); +const echoContractTx = await EchoValuesFactory.deploy(deployer); +const { contract: echoContract } = await echoContractTx.waitForResult(); + +const { waitForResult } = await echoContract + .multiCall([ + echoContract.functions.echo_u8(17), + counterContract.functions.get_count(), + counterContract.functions.increment_count(5), + ]) + .call(); + +const { value: results } = await waitForResult(); +// results[0] == 17 +// results[1] == BN <0> +// results[2] == BN <5> +// #endregion multicall-2 + +console.log('result[0]', results[0] === 17); +console.log('result[1]', results[1].toNumber() === 0); +console.log('result[2]', results[2].toNumber() === 5); diff --git a/apps/docs-snippets2/src/contracts/multi-call/same-contract.ts b/apps/docs-snippets2/src/contracts/multi-call/same-contract.ts new file mode 100644 index 00000000000..0e316acfb27 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/multi-call/same-contract.ts @@ -0,0 +1,29 @@ +// #region multicall-1 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { CounterFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const counterContractTx = await CounterFactory.deploy(deployer); +const { contract: counterContract } = await counterContractTx.waitForResult(); + +const { waitForResult } = await counterContract + .multiCall([ + counterContract.functions.get_count(), + counterContract.functions.increment_count(2), + counterContract.functions.increment_count(4), + ]) + .call(); + +const { value: results } = await waitForResult(); +// results[0] == 0 +// results[1] == 2 +// results[2] == 6 +// #endregion multicall-1 + +console.log('result[0]', results[0].toNumber() === 0); +console.log('result[1]', results[1].toNumber() === 2); +console.log('result[2]', results[2].toNumber() === 6); diff --git a/apps/docs-snippets2/src/contracts/storage-slots/override-storage-slots-inline.ts b/apps/docs-snippets2/src/contracts/storage-slots/override-storage-slots-inline.ts new file mode 100644 index 00000000000..a7f3939ceba --- /dev/null +++ b/apps/docs-snippets2/src/contracts/storage-slots/override-storage-slots-inline.ts @@ -0,0 +1,43 @@ +// #region contract-deployment-storage-slots-inline +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { StorageTestContractFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deploymentTx = await StorageTestContractFactory.deploy(deployer, { + storageSlots: [ + { + key: '02dac99c283f16bc91b74f6942db7f012699a2ad51272b15207b9cc14a70dbae', + value: '0000000000000001000000000000000000000000000000000000000000000000', + }, + { + key: '6294951dcb0a9111a517be5cf4785670ff4e166fb5ab9c33b17e6881b48e964f', + value: '0000000000000001000000000000003200000000000000000000000000000000', + }, + { + key: 'b48b753af346966d0d169c0b2e3234611f65d5cfdb57c7b6e7cd6ca93707bee0', + value: '000000000000001e000000000000000000000000000000000000000000000000', + }, + { + key: 'de9090cb50e71c2588c773487d1da7066d0c719849a7e58dc8b6397a25c567c0', + value: '0000000000000014000000000000000000000000000000000000000000000000', + }, + { + key: 'f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed', + value: '000000000000000a000000000000000000000000000000000000000000000000', + }, + ], +}); + +await deploymentTx.waitForResult(); +// #endregion contract-deployment-storage-slots-inline + +const { contract, transactionResult } = await deploymentTx.waitForResult(); +console.log('Contract should be defined', contract); +console.log( + 'Deployment transaction should be successful', + transactionResult.isStatusSuccess +); diff --git a/apps/docs-snippets2/src/contracts/storage-slots/override-storage-slots.ts b/apps/docs-snippets2/src/contracts/storage-slots/override-storage-slots.ts new file mode 100644 index 00000000000..486979bbf45 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/storage-slots/override-storage-slots.ts @@ -0,0 +1,25 @@ +// #region contract-deployment-storage-slots +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { + StorageTestContract, + StorageTestContractFactory, +} from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deploymentTx = await StorageTestContractFactory.deploy(deployer, { + storageSlots: StorageTestContract.storageSlots, +}); + +await deploymentTx.waitForResult(); +// #endregion contract-deployment-storage-slots + +const { contract, transactionResult } = await deploymentTx.waitForResult(); +console.log('Contract should be defined', contract); +console.log( + 'Deployment transaction should be successful', + transactionResult.isStatusSuccess +); diff --git a/apps/docs-snippets2/src/contracts/utilities/add-transfer-multiple-recipients.ts b/apps/docs-snippets2/src/contracts/utilities/add-transfer-multiple-recipients.ts new file mode 100644 index 00000000000..94e17866dc0 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/utilities/add-transfer-multiple-recipients.ts @@ -0,0 +1,47 @@ +// #region add-transfer-2 +import type { TransferParams } from 'fuels'; +import { Provider, Wallet } from 'fuels'; +import { ASSET_A, ASSET_B } from 'fuels/test-utils'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { EchoValuesFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await EchoValuesFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +const recipient1 = Wallet.generate({ provider }); +const recipient2 = Wallet.generate({ provider }); + +const transferParams: TransferParams[] = [ + { + destination: recipient1.address, + amount: 100, + assetId: provider.getBaseAssetId(), + }, + { destination: recipient1.address, amount: 400, assetId: ASSET_A }, + { destination: recipient2.address, amount: 300, assetId: ASSET_B }, +]; + +const { waitForResult } = await contract.functions + .echo_u64(100) + .addBatchTransfer(transferParams) + .call(); + +await waitForResult(); +// #endregion add-transfer-2 + +const recipientBalanceBaseAsset = await recipient1.getBalance( + provider.getBaseAssetId() +); +const recipientBalanceAssetA = await recipient1.getBalance(ASSET_A); +const recipientBalanceAssetB = await recipient2.getBalance(ASSET_B); + +console.log( + 'Recipient 1 balance (base asset)', + recipientBalanceBaseAsset.toNumber() +); +console.log('Recipient 1 balance (asset A)', recipientBalanceAssetA.toNumber()); +console.log('Recipient 2 balance (asset B)', recipientBalanceAssetB.toNumber()); diff --git a/apps/docs-snippets2/src/contracts/utilities/add-transfer-single-recipient.ts b/apps/docs-snippets2/src/contracts/utilities/add-transfer-single-recipient.ts new file mode 100644 index 00000000000..4cec79601b7 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/utilities/add-transfer-single-recipient.ts @@ -0,0 +1,31 @@ +// #region add-transfer-1 +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { EchoValuesFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await EchoValuesFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +const recipient = Wallet.generate({ provider }); + +const { waitForResult } = await contract.functions + .echo_u64(100) + .addTransfer({ + destination: recipient.address, + amount: 100, + assetId: provider.getBaseAssetId(), + }) + .call(); + +await waitForResult(); +// #endregion add-transfer-1 + +const recipientBalance = await recipient.getBalance(provider.getBaseAssetId()); +console.log( + 'Recipient balance should equal 100', + recipientBalance.toNumber() === 100 +); diff --git a/apps/docs-snippets2/src/contracts/utilities/create-asset-id.ts b/apps/docs-snippets2/src/contracts/utilities/create-asset-id.ts new file mode 100644 index 00000000000..7f1a3276ac3 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/utilities/create-asset-id.ts @@ -0,0 +1,19 @@ +// #region create-asset-id-1 +import type { AssetId, B256Address } from 'fuels'; +import { createAssetId } from 'fuels'; + +const contractId: B256Address = + '0x67eb6a384151a30e162c26d2f3e81ca2023dfa1041000210caed42ead32d63c0'; +const subID: B256Address = + '0xc7fd1d987ada439fc085cfa3c49416cf2b504ac50151e3c2335d60595cb90745'; + +const assetId: AssetId = createAssetId(contractId, subID); +// { +// bits: '0x16c1cb95e999d0c74806f97643af158e821a0063a0c8ea61183bad2497b57478' +// } +// #endregion create-asset-id-1 + +const expectedAssetId = + '0x16c1cb95e999d0c74806f97643af158e821a0063a0c8ea61183bad2497b57478'; + +console.log('Asset ID should be equal', assetId.bits === expectedAssetId); diff --git a/apps/docs-snippets2/src/contracts/utilities/minted-token-asset-id.ts b/apps/docs-snippets2/src/contracts/utilities/minted-token-asset-id.ts new file mode 100644 index 00000000000..fcced21cef1 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/utilities/minted-token-asset-id.ts @@ -0,0 +1,32 @@ +// #region minted-token-asset-id-2 +import { bn, getMintedAssetId, Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { TokenFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await TokenFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +// Any valid bits256 string can be used as a sub ID +const subID = + '0xc7fd1d987ada439fc085cfa3c49416cf2b504ac50151e3c2335d60595cb90745'; +const mintAmount = bn(1000); + +const { waitForResult } = await contract.functions + .mint_coins(subID, mintAmount) + .call(); +await waitForResult(); + +// Get the minted +const mintedAssetId = getMintedAssetId(contract.id.toB256(), subID); +// #endregion minted-token-asset-id-2 + +console.log('Minted asset ID should be defined', mintedAssetId); +const { transactionResult } = await waitForResult(); +console.log( + 'Transaction should be successful', + transactionResult.isStatusSuccess +); diff --git a/apps/docs-snippets2/src/contracts/utilities/using-different-wallet.ts b/apps/docs-snippets2/src/contracts/utilities/using-different-wallet.ts new file mode 100644 index 00000000000..603885541e7 --- /dev/null +++ b/apps/docs-snippets2/src/contracts/utilities/using-different-wallet.ts @@ -0,0 +1,21 @@ +// #region using-different-wallet +import { Provider, Wallet } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { ReturnContextFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await ReturnContextFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +// Update the wallet +const newWallet = Wallet.generate({ provider }); +contract.account = newWallet; +// #endregion using-different-wallet + +console.log( + 'Contract account should equal the new wallet address', + contract.account.address.toB256() === newWallet.address.toB256() +); diff --git a/apps/docs-snippets2/src/contracts/utilities/variable-outputs.ts b/apps/docs-snippets2/src/contracts/utilities/variable-outputs.ts new file mode 100644 index 00000000000..9a31af550cb --- /dev/null +++ b/apps/docs-snippets2/src/contracts/utilities/variable-outputs.ts @@ -0,0 +1,35 @@ +// #region variable-outputs-2 +import { Provider, Wallet, getMintedAssetId, getRandomB256 } from 'fuels'; + +import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../env'; +import { TokenFactory } from '../../typegend'; + +const provider = await Provider.create(LOCAL_NETWORK_URL); +const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); + +const deployContract = await TokenFactory.deploy(deployer); +const { contract } = await deployContract.waitForResult(); + +const subId = getRandomB256(); + +const call1 = await contract.functions.mint_coins(subId, 100).call(); +await call1.waitForResult(); + +const address = { bits: Wallet.generate().address.toB256() }; +const assetId = { bits: getMintedAssetId(contract.id.toB256(), subId) }; + +const { waitForResult } = await contract.functions + .transfer_to_address(address, assetId, 100) + .txParams({ + variableOutputs: 1, + }) + .call(); + +await waitForResult(); +// #endregion variable-outputs-2 + +const { transactionResult } = await waitForResult(); +console.log( + 'Transaction should be successful', + transactionResult.isStatusSuccess +); diff --git a/apps/docs-snippets2/sway/Forc.toml b/apps/docs-snippets2/sway/Forc.toml index c0d77ce6ba3..a8a0b44e2ca 100644 --- a/apps/docs-snippets2/sway/Forc.toml +++ b/apps/docs-snippets2/sway/Forc.toml @@ -3,10 +3,6 @@ members = [ "bytecode-input", "configurable-pin", "counter", - "log-values", - "my-contract", - "echo-values", - "script-transfer-to-contract", "echo-asset-id", "echo-bytes", "echo-configurables", @@ -15,22 +11,28 @@ members = [ "echo-evm-address", "echo-raw-slice", "echo-std-string", + "echo-values", "employee-data", "input-output-types", "liquidity-pool", - "predicate-signing", - "return-script", - "script-signing", + "log-values", + "my-contract", "predicate-main-args-struct", "predicate-multi-args", + "predicate-signing", + "return-context", + "return-script", "return-true-predicate", + "script-signing", "script-sum", + "script-transfer-to-contract", "simple-predicate", "simple-token", "simple-token-abi", + "storage-test-contract", "sum-option-u8", + "token", "token-depositor", - "return-context", "transfer-to-address", "whitelisted-address-predicate", ] diff --git a/apps/docs-snippets2/sway/storage-test-contract/Forc.toml b/apps/docs-snippets2/sway/storage-test-contract/Forc.toml new file mode 100644 index 00000000000..c13ea4684e9 --- /dev/null +++ b/apps/docs-snippets2/sway/storage-test-contract/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "storage-test-contract" + +[dependencies] diff --git a/apps/docs-snippets2/sway/storage-test-contract/src/main.sw b/apps/docs-snippets2/sway/storage-test-contract/src/main.sw new file mode 100644 index 00000000000..7613b90c52e --- /dev/null +++ b/apps/docs-snippets2/sway/storage-test-contract/src/main.sw @@ -0,0 +1,95 @@ +contract; + +use std::storage::storage_api::{read, write}; + +struct StructValidation { + v1: bool, + v2: u64, +} + +storage { + var1: u64 = 0, + var2: u32 = 20, + var3: u16 = 30, + var4: bool = true, + var5: StructValidation = StructValidation { + v1: true, + v2: 50, + }, +} + +abi StorageTestContract { + #[storage(write)] + fn initialize_counter(value: u64) -> u64; + #[storage(read, write)] + fn increment_counter(amount: u64) -> u64; + #[storage(read)] + fn counter() -> u64; + #[storage(read)] + fn return_b256() -> b256; + #[storage(read)] + fn return_var1() -> u64; + #[storage(read)] + fn return_var2() -> u32; + #[storage(read)] + fn return_var3() -> u16; + #[storage(read)] + fn return_var4() -> bool; + #[storage(read)] + fn return_var5() -> StructValidation; + fn return_true() -> bool; +} + +const COUNTER_KEY: b256 = 0x0000000000000000000000000000000000000000000000000000000000000000; +const VALUE_B256: b256 = 0x0000000000000000000000000000000000000000000000000000000000000001; + +impl StorageTestContract for Contract { + #[storage(write)] + fn initialize_counter(value: u64) -> u64 { + write(COUNTER_KEY, 0, value); + value + } + #[storage(read, write)] + fn increment_counter(amount: u64) -> u64 { + let value: Option = read::(COUNTER_KEY, 0); + let value = value.unwrap_or(0) + amount; + write(COUNTER_KEY, 0, value); + value + } + #[storage(read)] + fn counter() -> u64 { + let value: Option = read::(COUNTER_KEY, 0); + let value = value.unwrap_or(0); + value + } + // Return values from storage + // This is used to test storage initialization, on contract deployment + #[storage(read)] + fn return_b256() -> b256 { + let value: Option = read::(VALUE_B256, 0); + value.unwrap_or(VALUE_B256) + } + #[storage(read)] + fn return_var1() -> u64 { + storage.var1.read() + } + #[storage(read)] + fn return_var2() -> u32 { + storage.var2.read() + } + #[storage(read)] + fn return_var3() -> u16 { + storage.var3.read() + } + #[storage(read)] + fn return_var4() -> bool { + storage.var4.read() + } + #[storage(read)] + fn return_var5() -> StructValidation { + storage.var5.read() + } + fn return_true() -> bool { + true + } +} diff --git a/apps/docs-snippets2/sway/token/Forc.toml b/apps/docs-snippets2/sway/token/Forc.toml new file mode 100644 index 00000000000..5be8d04f8cf --- /dev/null +++ b/apps/docs-snippets2/sway/token/Forc.toml @@ -0,0 +1,7 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "token" + +[dependencies] diff --git a/apps/docs-snippets2/sway/token/src/main.sw b/apps/docs-snippets2/sway/token/src/main.sw new file mode 100644 index 00000000000..65084202343 --- /dev/null +++ b/apps/docs-snippets2/sway/token/src/main.sw @@ -0,0 +1,31 @@ +// #region minted-token-asset-id-1 +contract; + +use std::asset::{burn, mint, transfer}; + +abi Token { + fn transfer_to_address(target: Address, asset_id: AssetId, coins: u64); + fn transfer_to_contract(recipient: ContractId, asset_id: AssetId, coins: u64); + fn mint_coins(sub_id: b256, mint_amount: u64); + fn burn_coins(sub_id: b256, burn_amount: u64); +} + +impl Token for Contract { + // #region variable-outputs-1 + fn transfer_to_address(recipient: Address, asset_id: AssetId, amount: u64) { + transfer(Identity::Address(recipient), asset_id, amount); + } + + fn transfer_to_contract(target: ContractId, asset_id: AssetId, amount: u64) { + transfer(Identity::ContractId(target), asset_id, amount); + } + // #endregion variable-outputs-1 + fn mint_coins(sub_id: b256, mint_amount: u64) { + mint(sub_id, mint_amount); + } + + fn burn_coins(sub_id: b256, burn_amount: u64) { + burn(sub_id, burn_amount); + } +} +// #endregion minted-token-asset-id-1 diff --git a/apps/docs/src/guide/contracts/methods.md b/apps/docs/src/guide/contracts/methods.md index ccd5f04baa8..a5a4c2b27a8 100644 --- a/apps/docs/src/guide/contracts/methods.md +++ b/apps/docs/src/guide/contracts/methods.md @@ -6,13 +6,13 @@ There are 4 ways to interact with contracts: `get`, `dryRun`, `simulate`, `call` The `get` method should be used to read data from the blockchain without using resources. It can be used with an unfunded wallet or even without a wallet at all: -<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-1{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/methods/get.ts#interacting-with-contracts-1{ts:line-numbers} ## `dryRun` The `dryRun` method should be used to dry-run a contract call. It does not spend resources and can be used with an unfunded wallet or even without a wallet at all: -<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-2{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/methods/dry-run.ts#interacting-with-contracts-2{ts:line-numbers} ## `simulate` @@ -20,7 +20,7 @@ The `simulate` method should be used to dry-run a contract call, ensuring that t A funded wallet it's required: -<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-3{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/methods/simulate.ts#interacting-with-contracts-3{ts:line-numbers} ## `call` @@ -28,13 +28,13 @@ The `call` method submits a real contract call transaction to the node, resolvin Real resources are consumed, and any operations executed by the contract function will be processed on the blockchain. -<<< @/../../docs-snippets/src/guide/contracts/interacting-with-contracts.test.ts#interacting-with-contracts-4{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/methods/call.ts#interacting-with-contracts-4{ts:line-numbers} ## `isReadOnly` (utility) If you want to figure out whether a function is read-only, you can use the `isReadOnly` method: -<<< @/../../docs-snippets/src/guide/contracts/is-function-readonly.test.ts#is-function-readonly-1{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/methods/is-read-only.ts#is-function-readonly-1{ts:line-numbers} If the function is read-only, you can use the `get` method to retrieve onchain data without spending gas. diff --git a/apps/docs/src/guide/contracts/minted-token-asset-id.md b/apps/docs/src/guide/contracts/minted-token-asset-id.md index 091e7a26eaa..abd77637a9c 100644 --- a/apps/docs/src/guide/contracts/minted-token-asset-id.md +++ b/apps/docs/src/guide/contracts/minted-token-asset-id.md @@ -11,11 +11,11 @@ The process involves applying a SHA-256 hash algorithm to the combination of the Consider the following simplified token contract: -<<< @/../../docs-snippets/test/fixtures/forc-projects/token/src/main.sw#minted-token-asset-id-1{rs:line-numbers} +<<< @/../../docs-snippets2/sway/token/src/main.sw#minted-token-asset-id-1{rs:line-numbers} Imagine that this contract is already deployed and we are about to mint some coins: -<<< @/../../docs-snippets/src/guide/contracts/minted-token-asset-id.test.ts#minted-token-asset-id-2{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/utilities/minted-token-asset-id.ts#minted-token-asset-id-2{ts:line-numbers} ## Obtaining the Asset ID @@ -25,4 +25,4 @@ Since the asset ID depends on the contract ID, which is always dynamic (unlike t The SDK provides a helper named `createAssetId` which takes the contract ID and sub ID as parameters. This helper internally calls `getMintedAssetId` and returns the Sway native parameter [AssetId](https://docs.fuel.network/docs/fuels-ts/interfaces/#assetid), ready to be used in a Sway program invocation: -<<< @/../../docs-snippets/src/guide/contracts/minted-token-asset-id.test.ts#create-asset-id-1{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/utilities/create-asset-id.ts#create-asset-id-1{ts:line-numbers} diff --git a/apps/docs/src/guide/contracts/multi-contract-calls.md b/apps/docs/src/guide/contracts/multi-contract-calls.md index b1ab73165d4..f9c6b7e4c6c 100644 --- a/apps/docs/src/guide/contracts/multi-contract-calls.md +++ b/apps/docs/src/guide/contracts/multi-contract-calls.md @@ -16,17 +16,17 @@ Use the `multiCall` method to call multiple functions on the same contract in a -<<< @/../../docs-snippets/src/guide/contracts/multicalls.test.ts#multicall-1{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/multi-call/same-contract.ts#multicall-1{ts:line-numbers} ## Different Contracts Multi Calls The `multiCall` method also allows you to execute multiple contract calls to distinct contracts within a single transaction: -<<< @/../../docs-snippets/src/guide/contracts/multicalls.test.ts#multicall-2{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/multi-call/different-contracts.ts#multicall-2{ts:line-numbers} You can also chain supported contract call methods, like `callParams`, for each contract call: -<<< @/../../docs-snippets/src/guide/contracts/multicalls.test.ts#multicall-3{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/multi-call/different-contracts-chain-methods.ts#multicall-3{ts:line-numbers} When using `multiCall`, the contract calls are queued and executed only after invoking one of the following methods: `.get`, `.simulate`, or `.call`. @@ -34,4 +34,4 @@ When using `multiCall`, the contract calls are queued and executed only after in When you need to read data from multiple contracts, the `multiCall` method can perform multiple [read-only](./methods.md#get) calls in a single transaction. This minimizes the number of requests sent to the network and consolidates data retrieval, making your dApp interactions more efficient. -<<< @/../../docs-snippets/src/guide/contracts/multicalls.test.ts#multicall-4{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/multi-call/different-contracts-readonly.ts#multicall-4{ts:line-numbers} diff --git a/apps/docs/src/guide/contracts/storage-slots.md b/apps/docs/src/guide/contracts/storage-slots.md index 3064d8f8436..c1475e31c1d 100644 --- a/apps/docs/src/guide/contracts/storage-slots.md +++ b/apps/docs/src/guide/contracts/storage-slots.md @@ -2,7 +2,7 @@ When deploying a contract, you can specify the custom storage slots that you want to use. -<<< @/../../../packages/fuel-gauge/src/storage-test-contract.test.ts#contract-deployment-storage-slots{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/storage-slots/override-storage-slots.ts#contract-deployment-storage-slots{ts:line-numbers} ## Using plain JavaScript @@ -10,7 +10,7 @@ In the above example, we directly imported the storage slots from a JSON file ge Instead of importing from a file, you can also specify the custom storage slots directly in your code: -<<< @/../../../packages/fuel-gauge/src/storage-test-contract.test.ts#contract-deployment-storage-slots-inline{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/storage-slots/override-storage-slots-inline.ts#contract-deployment-storage-slots-inline{ts:line-numbers} ## Auto-load of Storage Slots diff --git a/apps/docs/src/guide/contracts/transferring-assets.md b/apps/docs/src/guide/contracts/transferring-assets.md index eeae1dd343b..6550a83f193 100644 --- a/apps/docs/src/guide/contracts/transferring-assets.md +++ b/apps/docs/src/guide/contracts/transferring-assets.md @@ -4,7 +4,7 @@ Consider a scenario where you're interacting with a smart contract and need to t The `addTransfer` method allows you to append an asset transfer to your contract call transaction. You can use it is shown in the following example: -<<< @/../../docs-snippets/src/guide/contracts/add-transfer.test.ts#add-transfer-1{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/utilities/add-transfer-single-recipient.ts#add-transfer-1{ts:line-numbers} In the previous example, we first use a contract call to the `echo_u64` function. Following this, `addTransfer` is added to chain call to include a transfer of `100` units of the `BaseAssetId` in the transaction. @@ -12,4 +12,4 @@ In the previous example, we first use a contract call to the `echo_u64` function You can add a batch of transfers into a single transaction by using `addBatchTransfer`: -<<< @/../../docs-snippets/src/guide/contracts/add-transfer.test.ts#add-transfer-2{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/utilities/add-transfer-multiple-recipients.ts#add-transfer-2{ts:line-numbers} diff --git a/apps/docs/src/guide/contracts/understanding-the-fuelvm-binary-file.md b/apps/docs/src/guide/contracts/understanding-the-fuelvm-binary-file.md index 3ddda4c13ad..a30b335a877 100644 --- a/apps/docs/src/guide/contracts/understanding-the-fuelvm-binary-file.md +++ b/apps/docs/src/guide/contracts/understanding-the-fuelvm-binary-file.md @@ -4,7 +4,7 @@ When you compile your Sway code using the `forc build` command, it generates a b For example, consider the following smart contract: -<<< @/../../docs-snippets/test/fixtures/forc-projects/echo-values/src/main.sw#understanding-fuel-binary-file{ts:line-numbers} +<<< @/../../docs-snippets2/sway/echo-values/src/main.sw#understanding-fuel-binary-file{ts:line-numbers} After running `forc build`, a binary file will be generated with the following content: diff --git a/apps/docs/src/guide/contracts/using-different-wallets.md b/apps/docs/src/guide/contracts/using-different-wallets.md index 94d8185849f..5c6bfe4b249 100644 --- a/apps/docs/src/guide/contracts/using-different-wallets.md +++ b/apps/docs/src/guide/contracts/using-different-wallets.md @@ -6,7 +6,7 @@ This guide demonstrates how to make contract calls using different wallets and p To change the wallet associated with a contract instance, assign a new wallet to the instance's `account` property. This allows you to make contract calls with different wallets in a concise manner: -<<< @/../../docs-snippets/src/guide/contracts/calls-with-different-wallets.test.ts#calls-with-different-wallets-1{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/utilities/using-different-wallet.ts#using-different-wallet{ts:line-numbers} ## Changing Providers diff --git a/apps/docs/src/guide/contracts/variable-outputs.md b/apps/docs/src/guide/contracts/variable-outputs.md index cfcc8520aca..912e67f9b08 100644 --- a/apps/docs/src/guide/contracts/variable-outputs.md +++ b/apps/docs/src/guide/contracts/variable-outputs.md @@ -8,7 +8,7 @@ For instance, if a contract function calls a Sway transfer function 3 times, it ## Example: Sway functions that requires `Output Variable` -<<< @/../../docs-snippets/test/fixtures/forc-projects/token/src/main.sw#variable-outputs-1{ts:line-numbers} +<<< @/../../docs-snippets2/sway/token/src/main.sw#variable-outputs-1{ts:line-numbers} ## Adding Variable Outputs to the contract call @@ -16,7 +16,7 @@ When your contract invokes any of these functions, or if it calls a function tha This can be done as shown in the following example: -<<< @/../../docs-snippets/src/guide/contracts/variable-outputs.test.ts#variable-outputs-2{ts:line-numbers} +<<< @/../../docs-snippets2/src/contracts/utilities/variable-outputs.ts#variable-outputs-2{ts:line-numbers} In the TypeScript SDK, the Output Variables are automatically added to the transaction's list of outputs. diff --git a/packages/account/src/predicate/predicate.ts b/packages/account/src/predicate/predicate.ts index 3282657f542..3d8957f883b 100644 --- a/packages/account/src/predicate/predicate.ts +++ b/packages/account/src/predicate/predicate.ts @@ -32,7 +32,7 @@ export type PredicateParams< > = { bytecode: BytesLike; provider: Provider; - abi?: JsonAbi; + abi: JsonAbi; data?: TData; configurableConstants?: TConfigurables; loaderBytecode?: BytesLike; @@ -54,7 +54,7 @@ export class Predicate< > extends Account { bytes: Uint8Array; predicateData: TData = [] as unknown as TData; - interface?: Interface; + interface: Interface; loaderBytecode: BytesLike = ''; /** @@ -168,20 +168,17 @@ export class Predicate< */ private static processPredicateData( bytes: BytesLike, - jsonAbi?: JsonAbi, + jsonAbi: JsonAbi, configurableConstants?: { [name: string]: unknown } ) { let predicateBytes = arrayify(bytes); - let abiInterface: Interface | undefined; + const abiInterface: Interface = new Interface(jsonAbi); - if (jsonAbi) { - abiInterface = new Interface(jsonAbi); - if (abiInterface.functions.main === undefined) { - throw new FuelError( - ErrorCode.ABI_MAIN_METHOD_MISSING, - 'Cannot use ABI without "main" function.' - ); - } + if (abiInterface.functions.main === undefined) { + throw new FuelError( + ErrorCode.ABI_MAIN_METHOD_MISSING, + 'Cannot use ABI without "main" function.' + ); } if (configurableConstants && Object.keys(configurableConstants).length) { @@ -246,19 +243,12 @@ export class Predicate< private static setConfigurableConstants( bytes: Uint8Array, configurableConstants: { [name: string]: unknown }, - abiInterface?: Interface, + abiInterface: Interface, loaderBytecode?: BytesLike ) { const mutatedBytes = bytes; try { - if (!abiInterface) { - throw new FuelError( - ErrorCode.INVALID_CONFIGURABLE_CONSTANTS, - 'Cannot validate configurable constants because the Predicate was instantiated without a JSON ABI' - ); - } - if (Object.keys(abiInterface.configurables).length === 0) { throw new FuelError( ErrorCode.INVALID_CONFIGURABLE_CONSTANTS, diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index a4cbed37adb..97f5bb2916c 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -12,9 +12,6 @@ fragment SubmittedStatusFragment on SubmittedStatus { fragment SuccessStatusFragment on SuccessStatus { type: __typename - block { - id - } time programState { returnType @@ -27,11 +24,15 @@ fragment SuccessStatusFragment on SuccessStatus { totalFee } -fragment FailureStatusFragment on FailureStatus { - type: __typename +fragment SuccessStatusWithBlockIdFragment on SuccessStatus { + ...SuccessStatusFragment block { id } +} + +fragment FailureStatusFragment on FailureStatus { + type: __typename totalGas totalFee time @@ -41,6 +42,13 @@ fragment FailureStatusFragment on FailureStatus { } } +fragment FailureStatusWithBlockIdFragment on FailureStatus { + ...FailureStatusFragment + block { + id + } +} + fragment SqueezedOutStatusFragment on SqueezedOutStatus { type: __typename reason @@ -106,13 +114,13 @@ fragment transactionStatusSubscriptionFragment on TransactionStatus { ...SubmittedStatusFragment } ... on SuccessStatus { - ...SuccessStatusFragment + ...SuccessStatusWithBlockIdFragment transaction { ...malleableTransactionFieldsFragment } } ... on FailureStatus { - ...FailureStatusFragment + ...FailureStatusWithBlockIdFragment transaction { ...malleableTransactionFieldsFragment } @@ -243,7 +251,6 @@ fragment blockFragment on Block { fragment coinFragment on Coin { type: __typename utxoId - owner amount assetId blockCreated @@ -265,10 +272,14 @@ fragment messageFragment on Message { sender recipient data - nonce daHeight } +fragment getMessageFragment on Message { + ...messageFragment + nonce +} + fragment messageProofFragment on MessageProof { messageProof { proofSet @@ -312,7 +323,6 @@ fragment messageProofFragment on MessageProof { } sender recipient - nonce amount data } @@ -479,7 +489,22 @@ query getTransaction($transactionId: TransactionId!) { query getTransactionWithReceipts($transactionId: TransactionId!) { transaction(id: $transactionId) { - ...transactionFragment + id + rawPayload + status { + ... on SubmittedStatus { + ...SubmittedStatusFragment + } + ... on SuccessStatus { + ...SuccessStatusWithBlockIdFragment + } + ... on FailureStatus { + ...FailureStatusWithBlockIdFragment + } + ... on SqueezedOutStatus { + ...SqueezedOutStatusFragment + } + } } } @@ -579,6 +604,7 @@ query getBlocks($after: String, $before: String, $first: Int, $last: Int) { query getCoin($coinId: UtxoId!) { coin(utxoId: $coinId) { ...coinFragment + owner } } @@ -698,7 +724,7 @@ query getMessages( } edges { node { - ...messageFragment + ...getMessageFragment } } } diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index f8791c58505..226c6642e00 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -365,6 +365,10 @@ describe('Provider', () => { val1: bn(186), val2: bn(0), val3: bn(0), + ra: bn(202), + rb: bn(186), + rc: bn(0), + rd: bn(0), pc: bn(0x2888), is: bn(0x2880), }, diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index c143a3bbee5..6eabf92c7e1 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1418,7 +1418,7 @@ Supported fuel-core version: ${supportedVersion}.` id: node.utxoId, assetId: node.assetId, amount: bn(node.amount), - owner: Address.fromAddressOrString(node.owner), + owner: ownerAddress, blockCreated: bn(node.blockCreated), txCreatedIdx: bn(node.txCreatedIdx), })); @@ -1486,7 +1486,7 @@ Supported fuel-core version: ${supportedVersion}.` id: coin.utxoId, amount: bn(coin.amount), assetId: coin.assetId, - owner: Address.fromAddressOrString(coin.owner), + owner: ownerAddress, blockCreated: bn(coin.blockCreated), txCreatedIdx: bn(coin.txCreatedIdx), } as Coin; @@ -2068,13 +2068,13 @@ Supported fuel-core version: ${supportedVersion}.` messageId: InputMessageCoder.getMessageId({ sender: rawMessage.sender, recipient: rawMessage.recipient, - nonce: rawMessage.nonce, + nonce, amount: bn(rawMessage.amount), data: rawMessage.data, }), sender: Address.fromAddressOrString(rawMessage.sender), recipient: Address.fromAddressOrString(rawMessage.recipient), - nonce: rawMessage.nonce, + nonce, amount: bn(rawMessage.amount), data: InputMessageCoder.decodeData(rawMessage.data), daHeight: bn(rawMessage.daHeight), diff --git a/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts b/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts index 5bf84d661b0..f8cf0ff777b 100644 --- a/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts +++ b/packages/account/src/providers/transaction-summary/assemble-transaction-summary.test.ts @@ -86,7 +86,7 @@ describe('TransactionSummary', () => { const expected = { id, - blockId: MOCK_SUCCESS_STATUS.block.id, + blockId: MOCK_SUCCESS_STATUS.block?.id, fee: expect.any(BN), gasUsed: expect.any(BN), isTypeCreate: false, @@ -113,7 +113,7 @@ describe('TransactionSummary', () => { const expected = { id, - blockId: MOCK_FAILURE_STATUS.block.id, + blockId: MOCK_FAILURE_STATUS.block?.id, fee: expect.any(BN), gasUsed: expect.any(BN), isTypeCreate: false, diff --git a/packages/account/src/providers/transaction-summary/operations.test.ts b/packages/account/src/providers/transaction-summary/operations.test.ts index 9a00406afc2..b6d7cae9b70 100644 --- a/packages/account/src/providers/transaction-summary/operations.test.ts +++ b/packages/account/src/providers/transaction-summary/operations.test.ts @@ -882,6 +882,7 @@ describe('operations', () => { amount: bn('0x5f5e100'), assetId: '0x0000000000000000000000000000000000000000000000000000000000000000', from: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', + id: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', is: bn('0x4370'), pc: bn('0x57dc'), to: '0x3e7ddda4d0d3f8307ae5f1aed87623992c1c4decefec684936960775181b2302', diff --git a/packages/account/src/providers/transaction-summary/status.ts b/packages/account/src/providers/transaction-summary/status.ts index aa5c6ced2b1..d919c6efb50 100644 --- a/packages/account/src/providers/transaction-summary/status.ts +++ b/packages/account/src/providers/transaction-summary/status.ts @@ -52,7 +52,7 @@ export const processGraphqlStatus = (gqlTransactionStatus?: GraphqlTransactionSt switch (gqlTransactionStatus.type) { case 'SuccessStatus': time = gqlTransactionStatus.time; - blockId = gqlTransactionStatus.block.id; + blockId = gqlTransactionStatus.block?.id; isStatusSuccess = true; totalFee = bn(gqlTransactionStatus.totalFee); totalGas = bn(gqlTransactionStatus.totalGas); @@ -60,7 +60,7 @@ export const processGraphqlStatus = (gqlTransactionStatus?: GraphqlTransactionSt case 'FailureStatus': time = gqlTransactionStatus.time; - blockId = gqlTransactionStatus.block.id; + blockId = gqlTransactionStatus.block?.id; isStatusFailure = true; totalFee = bn(gqlTransactionStatus.totalFee); totalGas = bn(gqlTransactionStatus.totalGas); diff --git a/packages/account/src/providers/transaction-summary/types.ts b/packages/account/src/providers/transaction-summary/types.ts index 5ce748bffeb..e8913be7e9a 100644 --- a/packages/account/src/providers/transaction-summary/types.ts +++ b/packages/account/src/providers/transaction-summary/types.ts @@ -3,28 +3,60 @@ import type { B256Address } from '@fuel-ts/interfaces'; import type { BN, BNInput } from '@fuel-ts/math'; import type { Input, Output, Transaction, TransactionType } from '@fuel-ts/transactions'; -import type { - GqlFailureStatusFragment, - GqlGetTransactionQuery, - GqlSqueezedOutStatusFragment, - GqlSubmittedStatusFragment, - GqlSuccessStatusFragment, -} from '../__generated__/operations'; +import type { GqlReceiptFragment, GqlSuccessStatusFragment } from '../__generated__/operations'; import type { TransactionResultReceipt } from '../transaction-response'; -export type GqlTransaction = NonNullable; +export type SubmittedStatus = { + type: 'SubmittedStatus'; + time: string; +}; -export type GraphqlTransactionStatus = GqlTransaction['status']; +export type SuccessStatus = { + type: 'SuccessStatus'; + time: string; + programState?: GqlSuccessStatusFragment['programState']; + block?: { + id: string; + }; + receipts: GqlReceiptFragment[]; + totalGas: string; + totalFee: string; +}; -export type SuccessStatus = GqlSuccessStatusFragment; -export type FailureStatus = GqlFailureStatusFragment; -export type SubmittedStatus = GqlSubmittedStatusFragment; -export type SqueezedOutStatus = GqlSqueezedOutStatusFragment; +export type FailureStatus = { + type: 'FailureStatus'; + time: string; + reason: string; + block?: { + id: string; + }; + receipts: GqlReceiptFragment[]; + totalGas: string; + totalFee: string; +}; + +export type SqueezedOutStatus = { + type: 'SqueezedOutStatus'; + reason: string; +}; + +export type GraphqlTransactionStatus = + | SubmittedStatus + | SuccessStatus + | FailureStatus + | SqueezedOutStatus + | null; + +export type GqlTransaction = { + id: string; + rawPayload: string; + status?: GraphqlTransactionStatus; +}; export type Reason = FailureStatus['reason']; export type ProgramState = SuccessStatus['programState']; export type Time = SubmittedStatus['time'] | SuccessStatus['time'] | FailureStatus['time']; -export type BlockId = SuccessStatus['block']['id'] | FailureStatus['block']['id']; +export type BlockId = string; /** * @hidden diff --git a/packages/account/src/providers/utils/receipts.ts b/packages/account/src/providers/utils/receipts.ts index bfc1ec9b85f..f2cd9deacf7 100644 --- a/packages/account/src/providers/utils/receipts.ts +++ b/packages/account/src/providers/utils/receipts.ts @@ -66,9 +66,11 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { switch (receiptType) { case GqlReceiptType.Call: { + const id = hexOrZero(receipt.id || receipt.contractId); const callReceipt: ReceiptCall = { type: ReceiptType.Call, - from: hexOrZero(receipt.id || receipt.contractId), + id, + from: id, to: hexOrZero(receipt?.to), amount: bn(receipt.amount), assetId: hexOrZero(receipt.assetId), @@ -134,13 +136,22 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.Log: { + const ra = bn(receipt.ra); + const rb = bn(receipt.rb); + const rc = bn(receipt.rc); + const rd = bn(receipt.rd); + const logReceipt: ReceiptLog = { type: ReceiptType.Log, id: hexOrZero(receipt.id || receipt.contractId), - val0: bn(receipt.ra), - val1: bn(receipt.rb), - val2: bn(receipt.rc), - val3: bn(receipt.rd), + ra, + rb, + rc, + rd, + val0: ra, + val1: rb, + val2: rc, + val3: rd, pc: bn(receipt.pc), is: bn(receipt.is), }; @@ -149,11 +160,15 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.LogData: { + const ra = bn(receipt.ra); + const rb = bn(receipt.rb); const logDataReceipt: ReceiptLogData = { type: ReceiptType.LogData, id: hexOrZero(receipt.id || receipt.contractId), - val0: bn(receipt.ra), - val1: bn(receipt.rb), + ra, + rb, + val0: ra, + val1: rb, ptr: bn(receipt.ptr), len: bn(receipt.len), digest: hexOrZero(receipt.digest), @@ -165,9 +180,11 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.Transfer: { + const id = hexOrZero(receipt.id || receipt.contractId); const transferReceipt: ReceiptTransfer = { type: ReceiptType.Transfer, - from: hexOrZero(receipt.id || receipt.contractId), + id, + from: id, to: hexOrZero(receipt.toAddress || receipt?.to), amount: bn(receipt.amount), assetId: hexOrZero(receipt.assetId), @@ -179,9 +196,11 @@ export function assembleReceiptByType(receipt: GqlReceiptFragment) { } case GqlReceiptType.TransferOut: { + const id = hexOrZero(receipt.id || receipt.contractId); const transferOutReceipt: ReceiptTransferOut = { type: ReceiptType.TransferOut, - from: hexOrZero(receipt.id || receipt.contractId), + id, + from: id, to: hexOrZero(receipt.toAddress || receipt.to), amount: bn(receipt.amount), assetId: hexOrZero(receipt.assetId), diff --git a/packages/account/test/fixtures/messageProof.ts b/packages/account/test/fixtures/messageProof.ts index 4d08d5ca574..6221d9c47f0 100644 --- a/packages/account/test/fixtures/messageProof.ts +++ b/packages/account/test/fixtures/messageProof.ts @@ -56,7 +56,6 @@ export const MESSAGE_PROOF_RAW_RESPONSE: GqlGetMessageProofQuery['messageProof'] }, sender: '0x79c54219a5c910979e5e4c2728df163fa654a1fe03843e6af59daa2c3fcd42ea', recipient: '0x00000000000000000000000047ba61eec8e5e65247d717ff236f504cf3b0a263', - nonce: '0x3e87e0f44613cabecd1aad381ad41a433afb12ec5c54c172de3db25b1b4d1b53', amount: '10', data: '0x', }; @@ -110,7 +109,7 @@ export const MESSAGE_PROOF: MessageProof = { }, sender: Address.fromAddressOrString(MESSAGE_PROOF_RAW_RESPONSE.sender), recipient: Address.fromAddressOrString(MESSAGE_PROOF_RAW_RESPONSE.recipient), - nonce: MESSAGE_PROOF_RAW_RESPONSE.nonce, + nonce: '0xb33895e6fdf23b5a62c92a1d45c71a11579027f9e5c4dda73c26cf140bcd6895', amount: bn(MESSAGE_PROOF_RAW_RESPONSE.amount), data: MESSAGE_PROOF_RAW_RESPONSE.data, }; diff --git a/packages/account/test/fixtures/transaction-summary.ts b/packages/account/test/fixtures/transaction-summary.ts index 10054eef528..9ed7e2bd689 100644 --- a/packages/account/test/fixtures/transaction-summary.ts +++ b/packages/account/test/fixtures/transaction-summary.ts @@ -109,6 +109,7 @@ export const MOCK_OUTPUT_CONTRACT_CREATED: OutputContractCreated = { export const MOCK_RECEIPT_CALL: TransactionResultCallReceipt = { type: ReceiptType.Call, from: '0x0000000000000000000000000000000000000000000000000000000000000000', + id: '0x0000000000000000000000000000000000000000000000000000000000000000', to: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', amount: bn(100000000), assetId: '0x0000000000000000000000000000000000000000000000000000000000000000', @@ -129,6 +130,7 @@ export const MOCK_RECEIPT_RETURN: TransactionResultReturnReceipt = { export const MOCK_RECEIPT_TRANSFER: TransactionResultTransferReceipt = { type: ReceiptType.Transfer, + id: '0x0000000000000000000000000000000000000000000000000000000000000000', from: '0x0000000000000000000000000000000000000000000000000000000000000000', to: '0xaab4884920fa4d3a35fc2977cc442b0caddf87e001ef62321b6c02f5ab0f4115', amount: bn(988), @@ -139,6 +141,7 @@ export const MOCK_RECEIPT_TRANSFER: TransactionResultTransferReceipt = { export const MOCK_RECEIPT_TRANSFER_OUT: TransactionResultTransferOutReceipt = { type: ReceiptType.TransferOut, + id: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', from: '0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1', to: '0x3e7ddda4d0d3f8307ae5f1aed87623992c1c4decefec684936960775181b2302', amount: bn(100000000), diff --git a/packages/account/test/predicate-functions.test.ts b/packages/account/test/predicate-functions.test.ts index cf6d5dec061..88d385e02de 100644 --- a/packages/account/test/predicate-functions.test.ts +++ b/packages/account/test/predicate-functions.test.ts @@ -18,6 +18,7 @@ describe('Predicate', () => { const predicate = new Predicate({ bytecode: predicateBytecode, + abi: predicateAbi, provider, }); expect(predicate.address.toB256()).toEqual(predicateAddress); diff --git a/packages/fuel-gauge/src/advanced-logging.test.ts b/packages/fuel-gauge/src/advanced-logging.test.ts index ad7f42a0616..44d6b51d469 100644 --- a/packages/fuel-gauge/src/advanced-logging.test.ts +++ b/packages/fuel-gauge/src/advanced-logging.test.ts @@ -1,5 +1,5 @@ import type { FuelError } from '@fuel-ts/errors'; -import { Script, bn } from 'fuels'; +import { bn } from 'fuels'; import { launchTestNode } from 'fuels/test-utils'; import { @@ -280,7 +280,7 @@ describe('Advanced Logging', () => { wallets: [wallet], } = launched; - const script = new Script(ScriptCallContract.bytecode, ScriptCallContract.abi, wallet); + const script = new ScriptCallContract(wallet); const { waitForResult } = await script.functions .main(advancedLogContract.id.toB256(), otherAdvancedLogContract.id.toB256(), amount) @@ -305,7 +305,7 @@ describe('Advanced Logging', () => { wallets: [wallet], } = launched; - const script = new Script(ScriptCallContract.bytecode, ScriptCallContract.abi, wallet); + const script = new ScriptCallContract(wallet); const request = await script.functions .main(advancedLogContract.id.toB256(), otherAdvancedLogContract.id.toB256(), amount) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index fc962e6a78e..37a4e9f717d 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -10,7 +10,6 @@ import { transactionRequestify, Wallet, ContractFactory, - Predicate, PolicyType, buildFunctionResult, ReceiptType, @@ -879,10 +878,7 @@ describe('Contract', () => { const amountToContract = 200; const amountToPredicate = 500_000; - const predicate = new Predicate({ - bytecode: PredicateTrue.bytecode, - provider, - }); + const predicate = new PredicateTrue({ provider }); const tx1 = await wallet.transfer( predicate.address, diff --git a/packages/fuel-gauge/src/doc-examples.test.ts b/packages/fuel-gauge/src/doc-examples.test.ts index e718077f1ef..535e6378ae7 100644 --- a/packages/fuel-gauge/src/doc-examples.test.ts +++ b/packages/fuel-gauge/src/doc-examples.test.ts @@ -249,6 +249,7 @@ describe('Doc Examples', () => { const { provider } = launched; const predicate = new Predicate({ bytecode: PredicateTrue.bytecode, + abi: PredicateTrue.abi, provider, }); diff --git a/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts b/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts index e50a9da0905..582f757e1a2 100644 --- a/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts @@ -1,4 +1,4 @@ -import { getRandomB256, WalletUnlocked, Predicate, FuelError } from 'fuels'; +import { getRandomB256, WalletUnlocked, FuelError } from 'fuels'; import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils'; import { PredicateTrue, PredicateWithConfigurable } from '../../test/typegen'; @@ -26,9 +26,7 @@ describe('Predicate', () => { wallets: [wallet], } = launched; - const predicate = new Predicate({ - abi: PredicateWithConfigurable.abi, - bytecode: PredicateWithConfigurable.bytecode, + const predicate = new PredicateWithConfigurable({ provider: wallet.provider, data: [defaultValues.FEE, defaultValues.ADDRESS], // set predicate input data to be the same as default configurable value }); @@ -69,9 +67,7 @@ describe('Predicate', () => { const configurableConstants = { FEE: 35 }; expect(configurableConstants.FEE).not.toEqual(defaultValues.FEE); - const predicate = new Predicate({ - abi: PredicateWithConfigurable.abi, - bytecode: PredicateWithConfigurable.bytecode, + const predicate = new PredicateWithConfigurable({ provider, data: [configurableConstants.FEE, defaultValues.ADDRESS], configurableConstants, @@ -114,9 +110,7 @@ describe('Predicate', () => { const configurableConstants = { ADDRESS: getRandomB256() }; expect(configurableConstants.ADDRESS).not.toEqual(defaultValues.ADDRESS); - const predicate = new Predicate({ - abi: PredicateWithConfigurable.abi, - bytecode: PredicateWithConfigurable.bytecode, + const predicate = new PredicateWithConfigurable({ provider, data: [defaultValues.FEE, configurableConstants.ADDRESS], configurableConstants, @@ -163,9 +157,7 @@ describe('Predicate', () => { expect(configurableConstants.FEE).not.toEqual(defaultValues.FEE); expect(configurableConstants.ADDRESS).not.toEqual(defaultValues.ADDRESS); - const predicate = new Predicate({ - abi: PredicateWithConfigurable.abi, - bytecode: PredicateWithConfigurable.bytecode, + const predicate = new PredicateWithConfigurable({ provider, data: [configurableConstants.FEE, configurableConstants.ADDRESS], configurableConstants, @@ -245,9 +237,7 @@ describe('Predicate', () => { wallets: [wallet], } = launched; - const predicate = new Predicate({ - abi: PredicateWithConfigurable.abi, - bytecode: PredicateWithConfigurable.bytecode, + const predicate = new PredicateWithConfigurable({ provider, }); @@ -269,11 +259,9 @@ describe('Predicate', () => { await expectToThrowFuelError( () => - new Predicate({ - bytecode: PredicateTrue.bytecode, - abi: PredicateTrue.abi, + new PredicateTrue({ provider, - data: ['NADA'], + // @ts-expect-error testing invalid configurable configurableConstants: { constant: 'NADA', }, @@ -292,12 +280,10 @@ describe('Predicate', () => { await expectToThrowFuelError( () => - new Predicate({ - bytecode: PredicateWithConfigurable.bytecode, - abi: PredicateWithConfigurable.abi, + new PredicateWithConfigurable({ provider, - data: ['NADA'], configurableConstants: { + // @ts-expect-error testing invalid configurable NOPE: 'NADA', }, }), @@ -307,27 +293,5 @@ describe('Predicate', () => { ) ); }); - - it('throws when setting a configurable with no ABI', async () => { - using launched = await launchTestNode(); - - const { provider } = launched; - - await expectToThrowFuelError( - () => - new Predicate({ - bytecode: PredicateWithConfigurable.bytecode, - provider, - data: ['NADA'], - configurableConstants: { - NOPE: 'NADA', - }, - }), - new FuelError( - FuelError.CODES.INVALID_CONFIGURABLE_CONSTANTS, - `Error setting configurable constants: Cannot validate configurable constants because the Predicate was instantiated without a JSON ABI.` - ) - ); - }); }); }); diff --git a/packages/fuel-gauge/src/storage-test-contract.test.ts b/packages/fuel-gauge/src/storage-test-contract.test.ts index f428fcdfa82..f34b4ef0c45 100644 --- a/packages/fuel-gauge/src/storage-test-contract.test.ts +++ b/packages/fuel-gauge/src/storage-test-contract.test.ts @@ -17,9 +17,6 @@ describe('StorageTestContract', () => { const { storageSlots } = StorageTestContract; - // #region contract-deployment-storage-slots - // #context import storageSlots from '../your-sway-project/out/debug/your-sway-project-storage_slots.json'; - const factory = new ContractFactory( StorageTestContractFactory.bytecode, StorageTestContract.abi, @@ -30,7 +27,6 @@ describe('StorageTestContract', () => { }); const { contract } = await deploy.waitForResult(); - // #endregion contract-deployment-storage-slots // Call contract const call1 = await contract.functions.initialize_counter(1300).call(); @@ -61,7 +57,6 @@ describe('StorageTestContract', () => { StorageTestContract.abi, wallet ); - // #region contract-deployment-storage-slots-inline const { waitForResult } = await factory.deploy({ storageSlots: [ { @@ -87,7 +82,7 @@ describe('StorageTestContract', () => { ], }); const { contract } = await waitForResult(); - // #endregion contract-deployment-storage-slots-inline + const call1 = await contract.functions.initialize_counter(1300).call(); const { value: initializeResult } = await call1.waitForResult(); expect(initializeResult.toHex()).toEqual(toHex(1300)); diff --git a/packages/fuel-gauge/src/transaction-summary.test.ts b/packages/fuel-gauge/src/transaction-summary.test.ts index 4943039e24f..c8476575a2d 100644 --- a/packages/fuel-gauge/src/transaction-summary.test.ts +++ b/packages/fuel-gauge/src/transaction-summary.test.ts @@ -52,7 +52,7 @@ function convertBnsToHex(value: unknown): unknown { * @group browser */ describe('TransactionSummary', () => { - const verifyTransactionSummary = (params: { + const validateTxSummary = (params: { transaction: TransactionResult | TransactionSummary; isRequest?: boolean; }) => { @@ -71,7 +71,6 @@ describe('TransactionSummary', () => { expect(transaction.isStatusSuccess).toBe(!isRequest); expect(transaction.isStatusPending).toBe(false); if (!isRequest) { - expect(transaction.blockId).toEqual(expect.any(String)); expect(transaction.time).toEqual(expect.any(String)); expect(transaction.status).toEqual(expect.any(String)); expect(transaction.date).toEqual(expect.any(Date)); @@ -83,42 +82,34 @@ describe('TransactionSummary', () => { const { provider, - wallets: [adminWallet], + wallets: [sender, destination], } = launched; - const destination = Wallet.generate({ + const tx = await sender.transfer(destination.address, 1000, provider.getBaseAssetId()); + const submittedTxResult = await tx.waitForResult(); + + const laterFetchedResult = await getTransactionSummary({ + id: tx.id, provider, }); - const amountToTransfer = 100; - - const request = new ScriptTransactionRequest({ - gasLimit: 10000, + validateTxSummary({ + transaction: submittedTxResult, }); - request.addCoinOutput(destination.address, amountToTransfer, provider.getBaseAssetId()); - - const txCost = await adminWallet.getTransactionCost(request); - - request.gasLimit = txCost.gasUsed; - request.maxFee = txCost.maxFee; - - await adminWallet.fund(request, txCost); - - const tx = await adminWallet.sendTransaction(request); - - const transactionResponse = await tx.waitForResult(); - - const transactionSummary = await getTransactionSummary({ - id: tx.id, - provider, + validateTxSummary({ + transaction: laterFetchedResult, }); - verifyTransactionSummary({ - transaction: transactionSummary, - }); + /** + * Ensure both the original response and the subsequently fetched singular response + * contain the blockId + */ + expect(submittedTxResult.blockId).toBeDefined(); + expect(laterFetchedResult.blockId).toBeDefined(); - expect(convertBnsToHex(transactionResponse)).toStrictEqual(convertBnsToHex(transactionSummary)); + // Ensure the two responses are the same + expect(convertBnsToHex(submittedTxResult)).toStrictEqual(convertBnsToHex(laterFetchedResult)); }); it('should ensure getTransactionsSummaries executes just fine', async () => { @@ -126,35 +117,22 @@ describe('TransactionSummary', () => { const { provider, - wallets: [adminWallet], + wallets: [sender, destination], } = launched; - const sender = Wallet.generate({ - provider, - }); - - const tx1 = await adminWallet.transfer(sender.address, 500_000, provider.getBaseAssetId(), { - gasLimit: 10_000, - }); - const transactionResponse1 = await tx1.waitForResult(); - const amountToTransfer = 100; - const destination = Wallet.generate({ - provider, - }); + const tx1 = await sender.transfer(sender.address, amountToTransfer, provider.getBaseAssetId()); + const txResult1 = await tx1.waitForResult(); const tx2 = await sender.transfer( destination.address, - amountToTransfer, - provider.getBaseAssetId(), - { - gasLimit: 10_000, - } + amountToTransfer * 2, + provider.getBaseAssetId() ); - const transactionResponse2 = await tx2.waitForResult(); + const txResult2 = await tx2.waitForResult(); - const { transactions } = await getTransactionsSummaries({ + const { transactions: submittedTxResult } = await getTransactionsSummaries({ provider, filters: { first: 2, @@ -162,44 +140,57 @@ describe('TransactionSummary', () => { }, }); - expect(transactions.length).toBe(2); + expect(submittedTxResult.length).toBe(2); - transactions.forEach((transactionSummary) => { - verifyTransactionSummary({ + submittedTxResult.forEach((transactionSummary) => { + validateTxSummary({ transaction: transactionSummary, }); }); - expect(convertBnsToHex(transactions[0])).toStrictEqual(convertBnsToHex(transactionResponse1)); - expect(convertBnsToHex(transactions[1])).toStrictEqual(convertBnsToHex(transactionResponse2)); + expect(txResult1.blockId).toBeDefined(); + expect(txResult2.blockId).toBeDefined(); + + /** + * When fetching list of transactions, the blockId is not returned + */ + expect(convertBnsToHex(submittedTxResult[0])).toStrictEqual({ + ...(convertBnsToHex(txResult1) as TransactionResult), + blockId: undefined, + }); + expect(convertBnsToHex(submittedTxResult[1])).toStrictEqual({ + ...(convertBnsToHex(txResult2) as TransactionResult), + blockId: undefined, + }); }); - it('should ensure getTransactionSummaryFromRequest executes just fine', async () => { + it('should ensure getTransactionSummaryFromRequest executes just fine [TX REQUEST]', async () => { using launched = await launchTestNode(); const { provider, - wallets: [adminWallet], + wallets: [sender], } = launched; const request = new ScriptTransactionRequest({ gasLimit: 10000, }); - const txCost = await adminWallet.getTransactionCost(request); + const txCost = await sender.getTransactionCost(request); request.gasLimit = txCost.gasUsed; request.maxFee = txCost.maxFee; - await adminWallet.fund(request, txCost); + await sender.fund(request, txCost); - const transactionRequest = await adminWallet.populateTransactionWitnessesSignature(request); + const transactionRequest = await sender.populateTransactionWitnessesSignature(request); const transactionSummary = await getTransactionSummaryFromRequest({ provider, transactionRequest, }); - verifyTransactionSummary({ + + validateTxSummary({ transaction: transactionSummary, isRequest: true, }); @@ -207,6 +198,53 @@ describe('TransactionSummary', () => { expect(transactionSummary.transaction).toStrictEqual(transactionRequest.toTransaction()); }); + it('should ensure submitted transaction returns block ID', async () => { + using launched = await launchTestNode(); + + const { + wallets: [adminWallet, receiver], + } = launched; + + const submitted = await adminWallet.transfer(receiver.address, 1000, ASSET_A); + const response = await submitted.waitForResult(); + + validateTxSummary({ + transaction: response, + }); + + expect(response.blockId).toBeDefined(); + expect(response.blockId).toEqual(expect.any(String)); + }); + + it('should ensure listed TX summaries do not include block ID', async () => { + using launched = await launchTestNode(); + + const { + provider, + wallets: [sender, receiver], + } = launched; + + const length = 5; + + for (let i = 0; i < length; i++) { + const submitted = await sender.transfer(receiver.address, 1000, ASSET_A); + await submitted.waitForResult(); + } + + const { transactions } = await getTransactionsSummaries({ + provider, + filters: { + owner: sender.address.toB256(), + first: 50, + }, + }); + + expect(transactions).toHaveLength(length); + transactions.forEach((transaction) => { + expect(transaction.blockId).toBeUndefined(); + }); + }); + describe('Transfer Operations', () => { const validateTransferOperation = (params: { operations: Operation[]; @@ -225,9 +263,9 @@ describe('TransactionSummary', () => { expect(operations[index].to?.address).toBe(address.toB256()); expect(operations[index].assetsSent).toHaveLength(quantities.length); - quantities.forEach(({ amount, assetId }, qunatitiesIndex) => { - expect(Number(operations[index].assetsSent?.[qunatitiesIndex].amount)).toBe(amount); - expect(operations[index].assetsSent?.[qunatitiesIndex].assetId).toBe(assetId); + quantities.forEach(({ amount, assetId }, quantitiesIndex) => { + expect(Number(operations[index].assetsSent?.[quantitiesIndex].amount)).toBe(amount); + expect(operations[index].assetsSent?.[quantitiesIndex].assetId).toBe(assetId); }); }); }; @@ -268,7 +306,7 @@ describe('TransactionSummary', () => { const transferAmount = 1233; const minorAmount = 1000; const majorAmount = 100_000_000_000; - const tranferBackAmount = majorAmount - 10_000; + const transferBackAmount = majorAmount - 10_000; using launched = await launchTestNode({ walletsConfig: { @@ -303,11 +341,11 @@ describe('TransactionSummary', () => { }); request.addResources([...majorResources, ...minorResources]); - // Add tranfer to recipient + // Add transfer to recipient request.addCoinOutput(recipient.address, transferAmount, provider.getBaseAssetId()); // Add transfer to self - request.addCoinOutput(majorWallet.address, tranferBackAmount, provider.getBaseAssetId()); + request.addCoinOutput(majorWallet.address, transferBackAmount, provider.getBaseAssetId()); // Explicitly setting the Output Change address to the recipient const index = request.outputs.findIndex((output) => output.type === OutputType.Change); @@ -331,7 +369,7 @@ describe('TransactionSummary', () => { }, { address: majorWallet.address, - quantities: [{ amount: tranferBackAmount, assetId: provider.getBaseAssetId() }], + quantities: [{ amount: transferBackAmount, assetId: provider.getBaseAssetId() }], }, ], }); diff --git a/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxy.ts b/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxy.ts index fbb824b1e33..ceaf03af0ee 100644 --- a/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxy.ts +++ b/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxy.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.96.0 + Fuels version: 0.96.1 */ import { Contract, Interface } from "../../../../.."; diff --git a/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxyFactory.ts b/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxyFactory.ts index fb154d531f7..c51e0bd0930 100644 --- a/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxyFactory.ts +++ b/packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxyFactory.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.96.0 + Fuels version: 0.96.1 */ import { Contract, ContractFactory, decompressBytecode } from "../../../../.."; diff --git a/packages/fuels/src/cli/commands/deploy/proxy/types/common.d.ts b/packages/fuels/src/cli/commands/deploy/proxy/types/common.d.ts index c95fb406118..0620f9d4b29 100644 --- a/packages/fuels/src/cli/commands/deploy/proxy/types/common.d.ts +++ b/packages/fuels/src/cli/commands/deploy/proxy/types/common.d.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.96.0 + Fuels version: 0.96.1 */ /** diff --git a/packages/fuels/src/cli/commands/deploy/proxy/types/index.ts b/packages/fuels/src/cli/commands/deploy/proxy/types/index.ts index 8e1185e2092..15580357b5e 100644 --- a/packages/fuels/src/cli/commands/deploy/proxy/types/index.ts +++ b/packages/fuels/src/cli/commands/deploy/proxy/types/index.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.96.0 + Fuels version: 0.96.1 */ export { Src14OwnedProxy } from './Src14OwnedProxy'; diff --git a/packages/transactions/src/coders/receipt.test.ts b/packages/transactions/src/coders/receipt.test.ts index 77b185c1957..7199104f06e 100644 --- a/packages/transactions/src/coders/receipt.test.ts +++ b/packages/transactions/src/coders/receipt.test.ts @@ -19,6 +19,7 @@ describe('ReceiptCoder', () => { it('Can encode Call', () => { const receipt: Receipt = { type: ReceiptType.Call, + id: B256, from: B256, to: B256, amount: bn(0), @@ -134,6 +135,10 @@ describe('ReceiptCoder', () => { const receipt: Receipt = { type: ReceiptType.Log, id: B256, + ra: bn(0), + rb: bn(0), + rc: bn(0), + rd: bn(0), val0: bn(0), val1: bn(0), val2: bn(0), @@ -158,6 +163,8 @@ describe('ReceiptCoder', () => { const receipt: Receipt = { type: ReceiptType.LogData, id: B256, + ra: bn(0), + rb: bn(0), val0: bn(0), val1: bn(0), ptr: bn(0), @@ -183,6 +190,7 @@ describe('ReceiptCoder', () => { it('Can encode Transfer', () => { const receipt: Receipt = { type: ReceiptType.Transfer, + id: B256, from: B256, to: B256, amount: bn(0), @@ -206,6 +214,7 @@ describe('ReceiptCoder', () => { it('Can encode TransferOut', () => { const receipt: Receipt = { type: ReceiptType.TransferOut, + id: B256, from: B256, to: B256, amount: bn(0), diff --git a/packages/transactions/src/coders/receipt.ts b/packages/transactions/src/coders/receipt.ts index f5ce228dd69..722cc1ad92c 100644 --- a/packages/transactions/src/coders/receipt.ts +++ b/packages/transactions/src/coders/receipt.ts @@ -26,8 +26,12 @@ export enum ReceiptType /* u8 */ { export type ReceiptCall = { type: ReceiptType.Call; - /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `id` instead. + */ from: string; + /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + id: string; /** Contract ID of called contract (b256) */ to: string; /** Amount of coins to forward, i.e. $rB (u64) */ @@ -77,7 +81,7 @@ export class ReceiptCallCoder extends Coder { let o = offset; [decoded, o] = new B256Coder().decode(data, o); - const from = decoded; + const id = decoded; [decoded, o] = new B256Coder().decode(data, o); const to = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); @@ -98,7 +102,8 @@ export class ReceiptCallCoder extends Coder { return [ { type: ReceiptType.Call, - from, + id, + from: id, to, amount, assetId, @@ -377,14 +382,30 @@ export type ReceiptLog = { type: ReceiptType.Log; /** Contract ID of current context if in an internal context, zero otherwise (b256) */ id: string; - /** Value of register $rA (u64) */ + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `ra` instead. + */ val0: BN; - /** Value of register $rB (u64) */ + /** Value of register $rA (u64) */ + ra: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rb` instead. + */ val1: BN; - /** Value of register $rC (u64) */ + /** Value of register $rB (u64) */ + rb: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rc` instead. + */ val2: BN; - /** Value of register $rD (u64) */ + /** Value of register $rC (u64) */ + rc: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rd` instead. + */ val3: BN; + /** Value of register $rD (u64) */ + rd: BN; /** Value of register $pc (u64) */ pc: BN; /** Value of register $is (u64) */ @@ -422,13 +443,13 @@ export class ReceiptLogCoder extends Coder { [decoded, o] = new B256Coder().decode(data, o); const id = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val0 = decoded; + const ra = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val1 = decoded; + const rb = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val2 = decoded; + const rc = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val3 = decoded; + const rd = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); const pc = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); @@ -438,10 +459,14 @@ export class ReceiptLogCoder extends Coder { { type: ReceiptType.Log, id, - val0, - val1, - val2, - val3, + ra, + rb, + rc, + rd, + val0: ra, + val1: rb, + val2: rc, + val3: rd, pc, is, }, @@ -455,8 +480,16 @@ export type ReceiptLogData = { /** Contract ID of current context if in an internal context, zero otherwise (b256) */ id: string; /** Value of register $rA (u64) */ + ra: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `ra` instead. + */ val0: BN; /** Value of register $rB (u64) */ + rb: BN; + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `rb` instead. + */ val1: BN; /** Value of register $rC (u64) */ ptr: BN; @@ -505,9 +538,9 @@ export class ReceiptLogDataCoder extends Coder { [decoded, o] = new B256Coder().decode(data, o); const id = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val0 = decoded; + const ra = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); - const val1 = decoded; + const rb = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); const ptr = decoded; [decoded, o] = new BigNumberCoder('u64').decode(data, o); @@ -525,8 +558,10 @@ export class ReceiptLogDataCoder extends Coder { { type: ReceiptType.LogData, id, - val0, - val1, + ra, + rb, + val0: ra, + val1: rb, ptr, len, digest, @@ -541,8 +576,12 @@ export class ReceiptLogDataCoder extends Coder { export type ReceiptTransfer = { type: ReceiptType.Transfer; - /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + /** + * @deprecated This property is deprecated and it will be removed soon. Use property `id` instead. + */ from: string; + /** Contract ID of current context if in an internal context, zero otherwise (b256) */ + id: string; /** Contract ID of contract to transfer coins to (b256) */ to: string; /** Amount of coins transferred (u64) */ @@ -583,7 +622,7 @@ export class ReceiptTransferCoder extends Coder