@@ -788,12 +788,6 @@ export class Sol extends BaseCoin {
788788 let totalFee = new BigNumber ( 0 ) ;
789789 let totalFeeForTokenRecovery = new BigNumber ( 0 ) ;
790790
791- if ( params . durableNonce ) {
792- const durableNonceInfo = await this . getAccountInfo ( params . durableNonce . publicKey ) ;
793- blockhash = durableNonceInfo . blockhash ;
794- authority = durableNonceInfo . authority ;
795- }
796-
797791 // check for possible token recovery, recover the token provide by user
798792 if ( params . tokenContractAddress ) {
799793 const tokenAccounts = await this . getTokenAccountsByOwner ( bs58EncodedPublicKey ) ;
@@ -876,6 +870,10 @@ export class Sol extends BaseCoin {
876870 }
877871
878872 if ( params . durableNonce ) {
873+ const durableNonceInfo = await this . getAccountInfo ( params . durableNonce . publicKey ) ;
874+ blockhash = durableNonceInfo . blockhash ;
875+ authority = durableNonceInfo . authority ;
876+
879877 txBuilder . nonce ( blockhash , {
880878 walletNonceAddress : params . durableNonce . publicKey ,
881879 authWalletAddress : authority ,
@@ -886,13 +884,43 @@ export class Sol extends BaseCoin {
886884 const unsignedTransactionWithoutFee = ( await txBuilder . build ( ) ) as Transaction ;
887885 const serializedMessage = unsignedTransactionWithoutFee . solTransaction . serializeMessage ( ) . toString ( 'base64' ) ;
888886
889- const feePerSignature = await this . getFeeForMessage ( serializedMessage ) ;
890- const baseFee = params . durableNonce ? feePerSignature * 2 : feePerSignature ;
887+ const baseFee = await this . getFeeForMessage ( serializedMessage ) ;
888+ const feePerSignature = params . durableNonce ? baseFee / 2 : baseFee ;
891889 totalFee = totalFee . plus ( new BigNumber ( baseFee ) ) ;
892890 totalFeeForTokenRecovery = totalFeeForTokenRecovery . plus ( new BigNumber ( baseFee ) ) ;
893891 if ( totalFee . gt ( balance ) ) {
894892 throw Error ( 'Did not find address with funds to recover' ) ;
895893 }
894+
895+ if ( params . tokenContractAddress ) {
896+ // Check if there is sufficient native solana to recover tokens
897+ if ( new BigNumber ( balance ) . lt ( totalFeeForTokenRecovery ) ) {
898+ throw Error (
899+ 'Not enough funds to pay for recover tokens fees, have: ' +
900+ balance +
901+ ' need: ' +
902+ totalFeeForTokenRecovery . toString ( )
903+ ) ;
904+ }
905+ txBuilder . fee ( { amount : feePerSignature } ) ;
906+ } else {
907+ const netAmount = new BigNumber ( balance ) . minus ( totalFee ) ;
908+ txBuilder = factory
909+ . getTransferBuilder ( )
910+ . nonce ( blockhash )
911+ . sender ( bs58EncodedPublicKey )
912+ . send ( { address : params . recoveryDestination , amount : netAmount . toString ( ) } )
913+ . feePayer ( bs58EncodedPublicKey )
914+ . fee ( { amount : feePerSignature } ) ;
915+
916+ if ( params . durableNonce ) {
917+ txBuilder . nonce ( blockhash , {
918+ walletNonceAddress : params . durableNonce . publicKey ,
919+ authWalletAddress : authority ,
920+ } ) ;
921+ }
922+ }
923+
896924 if ( ! isUnsignedSweep ) {
897925 // Sign the txn
898926 if ( ! params . userKey ) {
@@ -907,25 +935,6 @@ export class Sol extends BaseCoin {
907935 throw new Error ( 'missing wallet passphrase' ) ;
908936 }
909937
910- if ( params . tokenContractAddress ) {
911- totalFeeForTokenRecovery = totalFeeForTokenRecovery . plus ( new BigNumber ( baseFee ) ) ;
912- // Check if there is sufficient native solana to recover tokens
913- if ( new BigNumber ( balance ) . lt ( totalFeeForTokenRecovery ) ) {
914- throw Error (
915- 'Not enough funds to pay for recover tokens fees, have: ' +
916- balance +
917- ' need: ' +
918- totalFeeForTokenRecovery . toString ( )
919- ) ;
920- }
921- txBuilder . fee ( { amount : feePerSignature } ) ;
922- } else {
923- totalFee = new BigNumber ( baseFee ) ;
924- const netAmount = new BigNumber ( balance ) . minus ( totalFee ) ;
925- txBuilder
926- . send ( { address : params . recoveryDestination , amount : netAmount . toString ( ) } )
927- . fee ( { amount : feePerSignature } ) ;
928- }
929938 // build the transaction with fee
930939 const unsignedTransaction = ( await txBuilder . build ( ) ) as Transaction ;
931940
0 commit comments