1+ import assert from 'assert' ;
12import { BaseCoin as CoinConfig } from '@bitgo/statics' ;
23import { TransactionType } from '@bitgo/sdk-core' ;
3- import { decodeFlushTokensData } from '@bitgo/abstract-eth' ;
4+ import { decodeFlushTokensData , flushTokensData } from '@bitgo/abstract-eth' ;
45import { TransactionClause } from '@vechain/sdk-core' ;
56
67import { TransactionBuilder } from './transactionBuilder' ;
8+ import { Transaction } from '../transaction/transaction' ;
79import { FlushTokenTransaction } from '../transaction/flushTokenTransaction' ;
810import utils from '../utils' ;
911
@@ -27,16 +29,16 @@ export class FlushTokenTransactionBuilder extends TransactionBuilder {
2729 }
2830
2931 /**
30- * Gets the address initialization transaction instance.
32+ * Gets the flush token transaction instance.
3133 *
32- * @returns {FlushTokenTransaction } The address initialization transaction
34+ * @returns {FlushTokenTransaction } The flush token transaction
3335 */
3436 get flushTokenTransaction ( ) : FlushTokenTransaction {
3537 return this . _transaction as FlushTokenTransaction ;
3638 }
3739
3840 /**
39- * Gets the transaction type for address initialization .
41+ * Gets the transaction type for flush token .
4042 *
4143 * @returns {TransactionType } The transaction type
4244 */
@@ -45,7 +47,7 @@ export class FlushTokenTransactionBuilder extends TransactionBuilder {
4547 }
4648
4749 /**
48- * Validates the transaction clauses for address initialization .
50+ * Validates the transaction clauses for flush token transaction .
4951 * @param {TransactionClause[] } clauses - The transaction clauses to validate.
5052 * @returns {boolean } - Returns true if the clauses are valid, false otherwise.
5153 */
@@ -61,7 +63,7 @@ export class FlushTokenTransactionBuilder extends TransactionBuilder {
6163 return false ;
6264 }
6365
64- // For address init transactions, value must be exactly '0x0'
66+ // For address init transactions, value must be exactly 0
6567 if ( clause . value !== 0 ) {
6668 return false ;
6769 }
@@ -79,10 +81,10 @@ export class FlushTokenTransactionBuilder extends TransactionBuilder {
7981 }
8082
8183 /**
82- * Sets the base address for this forwarder init tx.
84+ * Sets the token address for this token flush tx.
8385 *
84- * @param {string } address - The base address to be set for the forwarder address
85- * @returns {AddressInitializationBuilder } This transaction builder
86+ * @param {string } address - The token address to be set for the token flush transaction
87+ * @returns {FlushTokenTransaction } This transaction builder
8688 */
8789 tokenAddress ( address : string ) : this {
8890 this . validateAddress ( { address } ) ;
@@ -91,59 +93,38 @@ export class FlushTokenTransactionBuilder extends TransactionBuilder {
9193 }
9294
9395 /** @inheritdoc */
94- validateTransaction ( transaction ?: AddressInitializationTransaction ) : void {
96+ validateTransaction ( transaction ?: FlushTokenTransaction ) : void {
9597 if ( ! transaction ) {
9698 throw new Error ( 'transaction not defined' ) ;
9799 }
98100 assert ( transaction . contract , 'Contract address is required' ) ;
99- assert ( transaction . baseAddress , 'Base address is required' ) ;
100- assert ( transaction . feeAddress , 'Fee address is required' ) ;
101- assert ( transaction . salt , 'Salt is required' ) ;
102- assert ( transaction . initCode , 'Init code is required' ) ;
101+ assert ( transaction . tokenAddress , 'Token address is required' ) ;
103102
104103 this . validateAddress ( { address : transaction . contract } ) ;
105- this . validateAddress ( { address : transaction . baseAddress } ) ;
106- this . validateAddress ( { address : transaction . feeAddress } ) ;
107- if ( ! utils . isValidHex ( transaction . salt , 64 ) ) {
108- throw new Error ( 'Invalid salt' ) ;
109- }
104+ this . validateAddress ( { address : transaction . tokenAddress } ) ;
110105 }
111106
112107 /** @inheritdoc */
113108 protected async buildImplementation ( ) : Promise < Transaction > {
114- const transactionData = this . getAddressInitializationData ( ) ;
109+ const transactionData = this . getFlushTokenTransactionData ( ) ;
115110 this . transaction . type = this . transactionType ;
116- this . addressInitializationTransaction . transactionData = transactionData ;
117- await this . addressInitializationTransaction . build ( ) ;
111+ this . flushTokenTransaction . transactionData = transactionData ;
112+ await this . flushTokenTransaction . build ( ) ;
118113 return this . transaction ;
119114 }
120115
121116 /**
122- * Generates the transaction data for address initialization by encoding the createForwarder method call.
117+ * Generates the transaction data for flush token transaction
123118 *
124119 * @private
125120 * @returns {string } The encoded transaction data as a hex string
126121 */
127- private getAddressInitializationData ( ) : string {
128- const saltBuffer = setLengthLeft ( toBuffer ( this . addressInitializationTransaction . salt ) , 32 ) ;
129- const { createForwarderParams, createForwarderTypes } = getCreateForwarderParamsAndTypes (
130- this . addressInitializationTransaction . baseAddress ,
131- saltBuffer ,
132- this . addressInitializationTransaction . feeAddress
122+ private getFlushTokenTransactionData ( ) : string {
123+ const flushTokenData = flushTokensData (
124+ this . flushTokenTransaction . contract ,
125+ this . flushTokenTransaction . tokenAddress ,
126+ this . flushTokenTransaction . forwarderVersion
133127 ) ;
134- const method = EthereumAbi . methodID ( 'createForwarder' , createForwarderTypes ) ;
135- const args = EthereumAbi . rawEncode ( createForwarderTypes , createForwarderParams ) ;
136- return addHexPrefix ( Buffer . concat ( [ method , args ] ) . toString ( 'hex' ) ) ;
137- }
138-
139- /** @inheritdoc */
140- protected fromImplementation ( rawTransaction : string ) : Transaction {
141- const tx = new AddressInitializationTransaction ( this . _coinConfig ) ;
142- this . validateRawTransaction ( rawTransaction ) ;
143-
144- tx . fromRawTransaction ( rawTransaction ) ;
145- this . initBuilder ( tx ) ;
146- this . validateTransaction ( tx ) ;
147- return this . transaction ;
128+ return flushTokenData ;
148129 }
149130}
0 commit comments