From 631274e942b9b17d98fa9c725b8cafd0faee0fe3 Mon Sep 17 00:00:00 2001 From: Clayton Neal Date: Wed, 29 Jan 2025 17:37:25 +0000 Subject: [PATCH] chore: backport (#1770) --- docs/contracts.md | 3 +- docs/examples/contracts/contract-clauses.ts | 3 +- .../examples/transactions/multiple-clauses.ts | 3 +- docs/transactions.md | 3 +- packages/core/src/transaction/Clause.ts | 24 ++++---- .../tests/transaction/Clause.unit.test.ts | 55 ++++++++----------- .../hardhat-provider/hardhat-provider.ts | 2 +- .../vechain-abstract-signer.ts | 4 +- 8 files changed, 40 insertions(+), 57 deletions(-) diff --git a/docs/contracts.md b/docs/contracts.md index 7906a8d5b..bed3d6cce 100644 --- a/docs/contracts.md +++ b/docs/contracts.md @@ -37,8 +37,7 @@ const transferVetClause = Clause.transferVET( // 2. Transfer VTHO -const transferVTHOClause = Clause.transferToken( - Address.of(VTHO_ADDRESS), +const transferVTHOClause = Clause.transferVTHOToken( Address.of('0xf02f557c753edf5fcdcbfe4c1c3a448b3cc84d54'), VTHO.of(300n, Units.wei) ); diff --git a/docs/examples/contracts/contract-clauses.ts b/docs/examples/contracts/contract-clauses.ts index 7bd603675..ab157b999 100644 --- a/docs/examples/contracts/contract-clauses.ts +++ b/docs/examples/contracts/contract-clauses.ts @@ -18,8 +18,7 @@ const transferVetClause = Clause.transferVET( // 2. Transfer VTHO -const transferVTHOClause = Clause.transferToken( - Address.of(VTHO_ADDRESS), +const transferVTHOClause = Clause.transferVTHOToken( Address.of('0xf02f557c753edf5fcdcbfe4c1c3a448b3cc84d54'), VTHO.of(300n, Units.wei) ); diff --git a/docs/examples/transactions/multiple-clauses.ts b/docs/examples/transactions/multiple-clauses.ts index 3cfd258e6..d024e3a11 100644 --- a/docs/examples/transactions/multiple-clauses.ts +++ b/docs/examples/transactions/multiple-clauses.ts @@ -21,8 +21,7 @@ const clauses: TransactionClause[] = [ Address.of('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed'), VET.of(10000) ) as TransactionClause, - Clause.transferToken( - Address.of(VTHO_ADDRESS), + Clause.transferVTHOToken( Address.of('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed'), VTHO.of(10000) ) as TransactionClause diff --git a/docs/transactions.md b/docs/transactions.md index 26bbcfa32..ace8a8231 100644 --- a/docs/transactions.md +++ b/docs/transactions.md @@ -74,8 +74,7 @@ const clauses: TransactionClause[] = [ Address.of('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed'), VET.of(10000) ) as TransactionClause, - Clause.transferToken( - Address.of(VTHO_ADDRESS), + Clause.transferVTHOToken( Address.of('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed'), VTHO.of(10000) ) as TransactionClause diff --git a/packages/core/src/transaction/Clause.ts b/packages/core/src/transaction/Clause.ts index 850c05865..3ad5b9db0 100644 --- a/packages/core/src/transaction/Clause.ts +++ b/packages/core/src/transaction/Clause.ts @@ -3,10 +3,10 @@ import { ERC721_ABI, VIP180_ABI } from '../utils'; import { ABI, ABIContract, + Address, FixedPointNumber, VET, type ABIFunction, - type Address, type HexUInt, type VTHO } from '../vcdm'; @@ -15,6 +15,7 @@ import { HexInt } from '../vcdm/HexInt'; import type { ClauseOptions } from './ClauseOptions'; import type { DeployParams } from './DeployParams'; import type { TransactionClause } from './TransactionClause'; +import { VTHO_ADDRESS } from '../utils/const/network'; /** * This class represent a transaction clause. @@ -43,7 +44,7 @@ class Clause implements TransactionClause { private static readonly TRANSFER_NFT_FUNCTION = 'transferFrom'; /** - * Used internally in {@link Clause.transferToken} method. + * Used internally in {@link Clause.transferVTHOToken} method. */ private static readonly TRANSFER_TOKEN_FUNCTION = 'transfer'; @@ -59,7 +60,7 @@ class Clause implements TransactionClause { * token in {@link Units.wei} to transfer to the destination. * * @see {Clause.callFunction} - * @see {Clause.transferToken} + * @see {Clause.transferVTHOToken} * @see {Clause.transferVET} */ readonly value: string; @@ -215,9 +216,7 @@ class Clause implements TransactionClause { } /** - * Return a new clause to transfers the specified amount of - * [VIP180](https://docs.vechain.org/introduction-to-vechain/dual-token-economic-model/vethor-vtho#vip180-vechains-fungible-token-standard) - * token. + * Return a new clause to transfers the specified amount of VTHO * * @param {Address} tokenAddress - The address of the VIP180 token. * @param {Address} recipientAddress - The address of the recipient. @@ -228,25 +227,24 @@ class Clause implements TransactionClause { * * @see VTHO.transferTokenTo */ - public static transferToken( - tokenAddress: Address, + public static transferVTHOToken( recipientAddress: Address, - amount: VTHO, - clauseOptions?: ClauseOptions + amount: VTHO ): Clause { if (amount.value.isFinite() && amount.value.isPositive()) { + const vthoAddress = Address.of(VTHO_ADDRESS); return this.callFunction( - tokenAddress, + vthoAddress, ABIContract.ofAbi(VIP180_ABI).getFunction( Clause.TRANSFER_TOKEN_FUNCTION ), [recipientAddress.toString(), amount.wei], undefined, - clauseOptions + { comment: 'Transfer VTHO' } ); } throw new InvalidDataType( - 'Clause.transferToken', + 'Clause.transferVTHOToken', 'not positive integer amount', { amount: `${amount.value}` } ); diff --git a/packages/core/tests/transaction/Clause.unit.test.ts b/packages/core/tests/transaction/Clause.unit.test.ts index c7e7a8d5c..d7208322f 100644 --- a/packages/core/tests/transaction/Clause.unit.test.ts +++ b/packages/core/tests/transaction/Clause.unit.test.ts @@ -11,7 +11,8 @@ import { type ClauseOptions, type DeployParams, type TransactionClause, - ABIContract + ABIContract, + VTHO_ADDRESS } from '../../src'; const ClauseFixture = { @@ -195,20 +196,20 @@ describe('Clause class tests', () => { }); }); - describe('transferToken method tests', () => { + describe('transferVTHOToken method tests', () => { test('Return Clause <- 1 wei VTHO', () => { const expected = { - to: ClauseFixture.token.address.toString().toLowerCase(), + to: Address.of(VTHO_ADDRESS).toString().toLowerCase(), value: `0x0`, data: `0xa9059cbb000000000000000000000000${ClauseFixture.to .toString() .toLowerCase() .slice( 2 - )}0000000000000000000000000000000000000000000000000000000000000001` + )}0000000000000000000000000000000000000000000000000000000000000001`, + comment: 'Transfer VTHO' } satisfies TransactionClause; - const actual = Clause.transferToken( - ClauseFixture.token.address, + const actual = Clause.transferVTHOToken( ClauseFixture.to, VTHO.of(1, Units.wei) ); @@ -217,17 +218,17 @@ describe('Clause class tests', () => { test('Return Clause <- 100 wei VTHO', () => { const expected = { - to: ClauseFixture.token.address.toString().toLowerCase(), + to: Address.of(VTHO_ADDRESS).toString().toLowerCase(), value: `0x0`, data: `0xa9059cbb000000000000000000000000${ClauseFixture.to .toString() .toLowerCase() .slice( 2 - )}0000000000000000000000000000000000000000000000000000000000000064` + )}0000000000000000000000000000000000000000000000000000000000000064`, + comment: 'Transfer VTHO' } satisfies TransactionClause; - const actual = Clause.transferToken( - ClauseFixture.token.address, + const actual = Clause.transferVTHOToken( ClauseFixture.to, VTHO.of(0.1, Units.kwei) ); @@ -236,17 +237,17 @@ describe('Clause class tests', () => { test('Return Clause <- 1 VTHO', () => { const expected = { - to: ClauseFixture.token.address.toString().toLowerCase(), + to: Address.of(VTHO_ADDRESS).toString().toLowerCase(), value: `0x0`, data: `0xa9059cbb000000000000000000000000${ClauseFixture.to .toString() .toLowerCase() .slice( 2 - )}0000000000000000000000000000000000000000000000000de0b6b3a7640000` + )}0000000000000000000000000000000000000000000000000de0b6b3a7640000`, + comment: 'Transfer VTHO' } satisfies TransactionClause; - const actual = Clause.transferToken( - ClauseFixture.token.address, + const actual = Clause.transferVTHOToken( ClauseFixture.to, VTHO.of(1) ); @@ -255,17 +256,17 @@ describe('Clause class tests', () => { test('Return Clause <- 500000000 VTHO', () => { const expected = { - to: ClauseFixture.token.address.toString().toLowerCase(), + to: Address.of(VTHO_ADDRESS).toString().toLowerCase(), value: `0x0`, data: `0xa9059cbb000000000000000000000000${ClauseFixture.to .toString() .toLowerCase() .slice( 2 - )}0000000000000000000000000000000000000000019d971e4fe8401e74000000` + )}0000000000000000000000000000000000000000019d971e4fe8401e74000000`, + comment: 'Transfer VTHO' } satisfies TransactionClause; - const actual = Clause.transferToken( - ClauseFixture.token.address, + const actual = Clause.transferVTHOToken( ClauseFixture.to, VTHO.of(500000000n) ); @@ -274,31 +275,19 @@ describe('Clause class tests', () => { test('Throw error <- negative amount VTHO', () => { expect(() => { - Clause.transferToken( - ClauseFixture.token.address, - ClauseFixture.to, - VTHO.of(-100) - ); + Clause.transferVTHOToken(ClauseFixture.to, VTHO.of(-100)); }).toThrow(InvalidDataType); }); test('Throw <- infinite amount VTHO', () => { expect(() => { - Clause.transferToken( - ClauseFixture.token.address, - ClauseFixture.to, - VTHO.of(Infinity) - ); + Clause.transferVTHOToken(ClauseFixture.to, VTHO.of(Infinity)); }).toThrow(InvalidDataType); }); test('Throw <- NaN amount VTHO', () => { expect(() => { - Clause.transferToken( - ClauseFixture.token.address, - ClauseFixture.to, - VTHO.of(NaN) - ); + Clause.transferVTHOToken(ClauseFixture.to, VTHO.of(NaN)); }).toThrow(InvalidDataType); }); }); diff --git a/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts b/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts index 6c4813d67..af22fd9a2 100644 --- a/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts +++ b/packages/network/src/provider/providers/hardhat-provider/hardhat-provider.ts @@ -77,7 +77,7 @@ class HardhatVeChainProvider extends VeChainProvider { } /** - * Overload off the send method + * Overload of the send method * * @param method - The method to call. * @param params - The parameters to pass to the method. diff --git a/packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts b/packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts index 4ceb062ba..a51fd591e 100644 --- a/packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts +++ b/packages/network/src/signer/signers/vechain-abstract-signer/vechain-abstract-signer.ts @@ -195,8 +195,8 @@ abstract class VeChainAbstractSigner implements VeChainSigner { /** * Estimates the required gas required to execute //tx// on the Blockchain. This - * will be the expected amount a transaction will require - * to successfully run all the necessary computations and store the needed state + * will be the expected amount a transaction will need + * to successfully run all the necessary computations and store the changed state * that the transaction intends. * * @param transactionToEstimate - The transaction to estimate gas for