From fdf154eead50b87e7fab28f85a6d37ac59d14d63 Mon Sep 17 00:00:00 2001 From: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com> Date: Wed, 11 Oct 2023 08:26:33 +1100 Subject: [PATCH] Revert "fix: validate addresses during tx broadcast (#5440)" This reverts commit 3c27504aa5f3a4c8d9fa1d9cb8f25a2b8a987d81. --- packages/chain-adapters/src/api.ts | 6 +- .../src/cosmossdk/CosmosSdkBaseAdapter.ts | 16 +---- .../cosmossdk/cosmos/CosmosChainAdapter.ts | 13 +---- .../thorchain/ThorchainChainAdapter.ts | 14 +---- .../chain-adapters/src/evm/EvmBaseAdapter.ts | 24 +------- .../evm/arbitrum/ArbitrumChainAdapter.test.ts | 34 +++-------- .../avalanche/AvalancheChainAdapter.test.ts | 34 +++-------- .../evm/bnbsmartchain/BscChainAdapter.test.ts | 34 +++-------- .../evm/ethereum/EthereumChainAdapter.test.ts | 34 +++-------- .../src/evm/gnosis/GnosisChainAdapter.test.ts | 35 +++-------- .../evm/optimism/OptimismChainAdapter.test.ts | 30 +++------- .../evm/polygon/PolygonChainAdapter.test.ts | 34 +++-------- packages/chain-adapters/src/types.ts | 12 ---- .../src/utils/validateAddress.ts | 41 ------------- .../src/utxo/UtxoBaseAdapter.ts | 30 ++-------- .../utxo/bitcoin/BitcoinChainAdapter.test.ts | 10 +--- .../BitcoinCashChainAdapter.test.ts | 10 +--- .../dogecoin/DogecoinChainAdapter.test.ts | 10 +--- .../litecoin/LitecoinChainAdapter.test.ts | 10 +--- .../hooks/useFormSend/useFormSend.test.tsx | 19 ++---- src/components/Modals/Send/utils.ts | 33 ++++------- .../hooks/useExecuteAllowanceApproval.tsx | 6 +- .../useTradeExecution/useTradeExecution.ts | 54 +++++------------ src/config.ts | 1 + src/context/PluginProvider/PluginProvider.tsx | 2 +- .../fox-farming/hooks/useFoxFarming.ts | 19 +----- .../Deposit/components/Approve.tsx | 6 +- .../Deposit/components/Confirm.tsx | 10 +--- .../Withdraw/components/Confirm.tsx | 10 +--- .../univ2/hooks/useUniV2LiquidityPool.ts | 13 +---- src/lib/investor/investor-foxy/api/api.ts | 18 +----- .../investor/investor-idle/IdleOpportunity.ts | 17 +----- .../investor-yearn/YearnOpportunity.ts | 20 ++----- src/lib/swapper/swapper.ts | 19 ++++++ src/lib/swapper/types.ts | 2 - src/lib/swapper/utils.ts | 26 +++++++++ src/lib/utils/evm.ts | 58 +++---------------- .../useStakingAction/useStakingAction.tsx | 10 +--- src/plugins/index.ts | 4 -- .../utils/EIP155RequestHandlerUtil.ts | 7 +-- 40 files changed, 189 insertions(+), 596 deletions(-) delete mode 100644 packages/chain-adapters/src/utils/validateAddress.ts diff --git a/packages/chain-adapters/src/api.ts b/packages/chain-adapters/src/api.ts index 3053fd700f9..afb84abc23e 100644 --- a/packages/chain-adapters/src/api.ts +++ b/packages/chain-adapters/src/api.ts @@ -3,13 +3,11 @@ import type { BIP44Params, UtxoAccountType } from '@shapeshiftoss/types' import type { Account, - BroadcastTransactionInput, BuildSendTxInput, FeeDataEstimate, GetAddressInput, GetBIP44ParamsInput, GetFeeDataInput, - SignAndBroadcastTransactionInput, SignTx, SignTxInput, SubscribeError, @@ -67,11 +65,11 @@ export type ChainAdapter = { signTransaction(signTxInput: SignTxInput>): Promise - signAndBroadcastTransaction?(input: SignAndBroadcastTransactionInput): Promise + signAndBroadcastTransaction?(signTxInput: SignTxInput>): Promise getFeeData(input: Partial>): Promise> - broadcastTransaction(input: BroadcastTransactionInput): Promise + broadcastTransaction(hex: string): Promise validateAddress(address: string): Promise diff --git a/packages/chain-adapters/src/cosmossdk/CosmosSdkBaseAdapter.ts b/packages/chain-adapters/src/cosmossdk/CosmosSdkBaseAdapter.ts index c4ece07786f..3046d43cc70 100644 --- a/packages/chain-adapters/src/cosmossdk/CosmosSdkBaseAdapter.ts +++ b/packages/chain-adapters/src/cosmossdk/CosmosSdkBaseAdapter.ts @@ -17,14 +17,12 @@ import type { ChainAdapter as IChainAdapter } from '../api' import { ErrorHandler } from '../error/ErrorHandler' import type { Account, - BroadcastTransactionInput, BuildSendApiTxInput, BuildSendTxInput, FeeDataEstimate, GetAddressInput, GetBIP44ParamsInput, GetFeeDataInput, - SignAndBroadcastTransactionInput, SignTx, SignTxInput, SubscribeError, @@ -37,7 +35,6 @@ import type { import { ValidAddressResultType } from '../types' import { toAddressNList, toRootDerivationPath } from '../utils' import { bnOrZero } from '../utils/bignumber' -import { validateAddress } from '../utils/validateAddress' import type { cosmos, thorchain } from './' import type { BuildTransactionInput, @@ -155,7 +152,7 @@ export abstract class CosmosSdkBaseAdapter implement abstract getAddress(input: GetAddressInput): Promise abstract getFeeData(input: Partial>): Promise> abstract signTransaction(signTxInput: SignTxInput>): Promise - abstract signAndBroadcastTransaction(input: SignAndBroadcastTransactionInput): Promise + abstract signAndBroadcastTransaction(signTxInput: SignTxInput>): Promise getChainId(): ChainId { return this.chainId @@ -332,16 +329,7 @@ export abstract class CosmosSdkBaseAdapter implement return { txToSign } } - async broadcastTransaction({ - senderAddress, - receiverAddress, - hex, - }: BroadcastTransactionInput): Promise { - await Promise.all([ - validateAddress(senderAddress), - receiverAddress !== undefined && validateAddress(receiverAddress), - ]) - + broadcastTransaction(hex: string): Promise { try { return this.providers.http.sendTx({ body: { rawTx: hex } }) } catch (err) { diff --git a/packages/chain-adapters/src/cosmossdk/cosmos/CosmosChainAdapter.ts b/packages/chain-adapters/src/cosmossdk/cosmos/CosmosChainAdapter.ts index 43a2da55700..716f8d42e09 100644 --- a/packages/chain-adapters/src/cosmossdk/cosmos/CosmosChainAdapter.ts +++ b/packages/chain-adapters/src/cosmossdk/cosmos/CosmosChainAdapter.ts @@ -17,12 +17,10 @@ import type { FeeDataEstimate, GetAddressInput, GetFeeDataInput, - SignAndBroadcastTransactionInput, SignTxInput, } from '../../types' import { ChainAdapterDisplayName } from '../../types' import { bn, calcFee, toAddressNList } from '../../utils' -import { validateAddress } from '../../utils/validateAddress' import type { ChainAdapterArgs } from '../CosmosSdkBaseAdapter' import { assertIsValidatorAddress, CosmosSdkBaseAdapter } from '../CosmosSdkBaseAdapter' import type { Message, ValidatorAction } from '../types' @@ -282,16 +280,7 @@ export class ChainAdapter extends CosmosSdkBaseAdapter): Promise { - await Promise.all([ - validateAddress(senderAddress), - receiverAddress !== undefined && validateAddress(receiverAddress), - ]) - + async signAndBroadcastTransaction(signTxInput: SignTxInput): Promise { const { wallet } = signTxInput try { if (supportsCosmos(wallet)) { diff --git a/packages/chain-adapters/src/cosmossdk/thorchain/ThorchainChainAdapter.ts b/packages/chain-adapters/src/cosmossdk/thorchain/ThorchainChainAdapter.ts index d6ab58294e5..49bbdca636b 100644 --- a/packages/chain-adapters/src/cosmossdk/thorchain/ThorchainChainAdapter.ts +++ b/packages/chain-adapters/src/cosmossdk/thorchain/ThorchainChainAdapter.ts @@ -14,13 +14,11 @@ import type { FeeDataEstimate, GetAddressInput, GetFeeDataInput, - SignAndBroadcastTransactionInput, SignTxInput, } from '../../types' import { ChainAdapterDisplayName } from '../../types' import { toAddressNList } from '../../utils' import { bnOrZero } from '../../utils/bignumber' -import { validateAddress } from '../../utils/validateAddress' import type { ChainAdapterArgs } from '../CosmosSdkBaseAdapter' import { CosmosSdkBaseAdapter } from '../CosmosSdkBaseAdapter' import type { Message } from '../types' @@ -206,18 +204,8 @@ export class ChainAdapter extends CosmosSdkBaseAdapter): Promise { - await Promise.all([ - validateAddress(senderAddress), - receiverAddress !== undefined && validateAddress(receiverAddress), - ]) - + async signAndBroadcastTransaction(signTxInput: SignTxInput): Promise { const { wallet } = signTxInput - try { if (supportsThorchain(wallet)) { const signedTx = await this.signTransaction(signTxInput) diff --git a/packages/chain-adapters/src/evm/EvmBaseAdapter.ts b/packages/chain-adapters/src/evm/EvmBaseAdapter.ts index 1dd86883bc6..077e10ca842 100644 --- a/packages/chain-adapters/src/evm/EvmBaseAdapter.ts +++ b/packages/chain-adapters/src/evm/EvmBaseAdapter.ts @@ -27,14 +27,12 @@ import type { ChainAdapter as IChainAdapter } from '../api' import { ErrorHandler } from '../error/ErrorHandler' import type { Account, - BroadcastTransactionInput, BuildSendApiTxInput, BuildSendTxInput, FeeDataEstimate, GetAddressInput, GetBIP44ParamsInput, GetFeeDataInput, - SignAndBroadcastTransactionInput, SignMessageInput, SignTx, SignTxInput, @@ -49,7 +47,6 @@ import type { import { ValidAddressResultType } from '../types' import { getAssetNamespace, toAddressNList, toRootDerivationPath } from '../utils' import { bnOrZero } from '../utils/bignumber' -import { validateAddress } from '../utils/validateAddress' import type { arbitrum, avalanche, bnbsmartchain, ethereum, gnosis, optimism, polygon } from '.' import type { BuildCustomApiTxInput, @@ -445,16 +442,7 @@ export abstract class EvmBaseAdapter implements IChainAdap } } - async signAndBroadcastTransaction({ - senderAddress, - receiverAddress, - signTxInput, - }: SignAndBroadcastTransactionInput): Promise { - await Promise.all([ - validateAddress(senderAddress), - receiverAddress !== undefined && validateAddress(receiverAddress), - ]) - + async signAndBroadcastTransaction(signTxInput: SignTxInput): Promise { try { const { txToSign, wallet } = signTxInput @@ -473,15 +461,7 @@ export abstract class EvmBaseAdapter implements IChainAdap } } - async broadcastTransaction({ - senderAddress, - receiverAddress, - hex, - }: BroadcastTransactionInput): Promise { - await Promise.all([ - validateAddress(senderAddress), - receiverAddress !== undefined && validateAddress(receiverAddress), - ]) + broadcastTransaction(hex: string): Promise { return this.providers.http.sendTx({ sendTxBody: { hex } }) } diff --git a/packages/chain-adapters/src/evm/arbitrum/ArbitrumChainAdapter.test.ts b/packages/chain-adapters/src/evm/arbitrum/ArbitrumChainAdapter.test.ts index 67be52666fb..527dcda67cd 100644 --- a/packages/chain-adapters/src/evm/arbitrum/ArbitrumChainAdapter.test.ts +++ b/packages/chain-adapters/src/evm/arbitrum/ArbitrumChainAdapter.test.ts @@ -21,10 +21,6 @@ import { bn } from '../../utils/bignumber' import type { ChainAdapterArgs, EvmChainId } from '../EvmBaseAdapter' import * as arbitrum from './ArbitrumChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const EOA_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' @@ -322,15 +318,11 @@ describe('ArbitrumChainAdapter', () => { wallet.ethSendTx = async () => await Promise.resolve(null) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).rejects.toThrow(/Error signing & broadcasting tx/) + await expect(adapter.signAndBroadcastTransaction(tx)).rejects.toThrow( + /Error signing & broadcasting tx/, + ) }) it('should return the hash returned by wallet.ethSendTx', async () => { @@ -342,15 +334,11 @@ describe('ArbitrumChainAdapter', () => { hash: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', }) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).resolves.toEqual('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331') + await expect(adapter.signAndBroadcastTransaction(tx)).resolves.toEqual( + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ) }) }) @@ -404,11 +392,7 @@ describe('ArbitrumChainAdapter', () => { const adapter = new arbitrum.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(expectedResult) diff --git a/packages/chain-adapters/src/evm/avalanche/AvalancheChainAdapter.test.ts b/packages/chain-adapters/src/evm/avalanche/AvalancheChainAdapter.test.ts index fa2e312d467..3ee819f830a 100644 --- a/packages/chain-adapters/src/evm/avalanche/AvalancheChainAdapter.test.ts +++ b/packages/chain-adapters/src/evm/avalanche/AvalancheChainAdapter.test.ts @@ -26,10 +26,6 @@ import { bn } from '../../utils/bignumber' import type { ChainAdapterArgs, EvmChainId } from '../EvmBaseAdapter' import * as avalanche from './AvalancheChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const EOA_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' @@ -327,15 +323,11 @@ describe('AvalancheChainAdapter', () => { wallet.ethSendTx = async () => await Promise.resolve(null) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).rejects.toThrow(/Error signing & broadcasting tx/) + await expect(adapter.signAndBroadcastTransaction(tx)).rejects.toThrow( + /Error signing & broadcasting tx/, + ) }) it('should return the hash returned by wallet.ethSendTx', async () => { @@ -347,15 +339,11 @@ describe('AvalancheChainAdapter', () => { hash: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', }) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).resolves.toEqual('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331') + await expect(adapter.signAndBroadcastTransaction(tx)).resolves.toEqual( + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ) }) }) @@ -409,11 +397,7 @@ describe('AvalancheChainAdapter', () => { const adapter = new avalanche.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(expectedResult) diff --git a/packages/chain-adapters/src/evm/bnbsmartchain/BscChainAdapter.test.ts b/packages/chain-adapters/src/evm/bnbsmartchain/BscChainAdapter.test.ts index 8fe5f3b9fd7..b28c12c3eeb 100644 --- a/packages/chain-adapters/src/evm/bnbsmartchain/BscChainAdapter.test.ts +++ b/packages/chain-adapters/src/evm/bnbsmartchain/BscChainAdapter.test.ts @@ -21,10 +21,6 @@ import { bn } from '../../utils/bignumber' import type { ChainAdapterArgs, EvmChainId } from '../EvmBaseAdapter' import * as bsc from './BscChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const EOA_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' @@ -304,15 +300,11 @@ describe('BscChainAdapter', () => { wallet.ethSendTx = async () => await Promise.resolve(null) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).rejects.toThrow(/Error signing & broadcasting tx/) + await expect(adapter.signAndBroadcastTransaction(tx)).rejects.toThrow( + /Error signing & broadcasting tx/, + ) }) it('should return the hash returned by wallet.ethSendTx', async () => { @@ -324,15 +316,11 @@ describe('BscChainAdapter', () => { hash: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', }) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).resolves.toEqual('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331') + await expect(adapter.signAndBroadcastTransaction(tx)).resolves.toEqual( + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ) }) }) @@ -386,11 +374,7 @@ describe('BscChainAdapter', () => { const adapter = new bsc.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(expectedResult) diff --git a/packages/chain-adapters/src/evm/ethereum/EthereumChainAdapter.test.ts b/packages/chain-adapters/src/evm/ethereum/EthereumChainAdapter.test.ts index b236a3fbd35..54155a11cd6 100644 --- a/packages/chain-adapters/src/evm/ethereum/EthereumChainAdapter.test.ts +++ b/packages/chain-adapters/src/evm/ethereum/EthereumChainAdapter.test.ts @@ -21,10 +21,6 @@ import { bn } from '../../utils/bignumber' import type { ChainAdapterArgs, EvmChainId } from '../EvmBaseAdapter' import * as ethereum from './EthereumChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const EOA_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' const ENS_NAME = 'vitalik.eth' @@ -361,15 +357,11 @@ describe('EthereumChainAdapter', () => { wallet.ethSendTx = async () => await Promise.resolve(null) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).rejects.toThrow(/Error signing & broadcasting tx/) + await expect(adapter.signAndBroadcastTransaction(tx)).rejects.toThrow( + /Error signing & broadcasting tx/, + ) }) it('should return the hash returned by wallet.ethSendTx', async () => { @@ -381,15 +373,11 @@ describe('EthereumChainAdapter', () => { hash: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', }) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).resolves.toEqual('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331') + await expect(adapter.signAndBroadcastTransaction(tx)).resolves.toEqual( + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ) }) }) @@ -443,11 +431,7 @@ describe('EthereumChainAdapter', () => { const adapter = new ethereum.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(expectedResult) diff --git a/packages/chain-adapters/src/evm/gnosis/GnosisChainAdapter.test.ts b/packages/chain-adapters/src/evm/gnosis/GnosisChainAdapter.test.ts index 7e3ccb86563..f6a3f1d1180 100644 --- a/packages/chain-adapters/src/evm/gnosis/GnosisChainAdapter.test.ts +++ b/packages/chain-adapters/src/evm/gnosis/GnosisChainAdapter.test.ts @@ -21,11 +21,6 @@ import { toAddressNList } from '../../utils' import { bn } from '../../utils/bignumber' import type { ChainAdapterArgs, EvmChainId } from '../EvmBaseAdapter' import * as gnosis from './GnosisChainAdapter' - -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const EOA_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' const testMnemonic = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle' @@ -322,15 +317,11 @@ describe('GnosisChainAdapter', () => { wallet.ethSendTx = async () => await Promise.resolve(null) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).rejects.toThrow(/Error signing & broadcasting tx/) + await expect(adapter.signAndBroadcastTransaction(tx)).rejects.toThrow( + /Error signing & broadcasting tx/, + ) }) it('should return the hash returned by wallet.ethSendTx', async () => { @@ -342,15 +333,11 @@ describe('GnosisChainAdapter', () => { hash: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', }) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).resolves.toEqual('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331') + await expect(adapter.signAndBroadcastTransaction(tx)).resolves.toEqual( + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ) }) }) @@ -404,11 +391,7 @@ describe('GnosisChainAdapter', () => { const adapter = new gnosis.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(expectedResult) diff --git a/packages/chain-adapters/src/evm/optimism/OptimismChainAdapter.test.ts b/packages/chain-adapters/src/evm/optimism/OptimismChainAdapter.test.ts index 11bd4d20b05..c13b8ae3eb2 100644 --- a/packages/chain-adapters/src/evm/optimism/OptimismChainAdapter.test.ts +++ b/packages/chain-adapters/src/evm/optimism/OptimismChainAdapter.test.ts @@ -329,15 +329,11 @@ describe('OptimismChainAdapter', () => { wallet.ethSendTx = async () => await Promise.resolve(null) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).rejects.toThrow(/Error signing & broadcasting tx/) + await expect(adapter.signAndBroadcastTransaction(tx)).rejects.toThrow( + /Error signing & broadcasting tx/, + ) }) it('should return the hash returned by wallet.ethSendTx', async () => { @@ -349,15 +345,11 @@ describe('OptimismChainAdapter', () => { hash: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', }) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).resolves.toEqual('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331') + await expect(adapter.signAndBroadcastTransaction(tx)).resolves.toEqual( + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ) }) }) @@ -411,11 +403,7 @@ describe('OptimismChainAdapter', () => { const adapter = new optimism.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(expectedResult) diff --git a/packages/chain-adapters/src/evm/polygon/PolygonChainAdapter.test.ts b/packages/chain-adapters/src/evm/polygon/PolygonChainAdapter.test.ts index 2f1e1926d84..b6304b5f8de 100644 --- a/packages/chain-adapters/src/evm/polygon/PolygonChainAdapter.test.ts +++ b/packages/chain-adapters/src/evm/polygon/PolygonChainAdapter.test.ts @@ -21,10 +21,6 @@ import { bn } from '../../utils/bignumber' import type { ChainAdapterArgs, EvmChainId } from '../EvmBaseAdapter' import * as polygon from './PolygonChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const EOA_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' @@ -322,15 +318,11 @@ describe('PolygonChainAdapter', () => { wallet.ethSendTx = async () => await Promise.resolve(null) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).rejects.toThrow(/Error signing & broadcasting tx/) + await expect(adapter.signAndBroadcastTransaction(tx)).rejects.toThrow( + /Error signing & broadcasting tx/, + ) }) it('should return the hash returned by wallet.ethSendTx', async () => { @@ -342,15 +334,11 @@ describe('PolygonChainAdapter', () => { hash: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', }) - const signTxInput = { wallet, txToSign: {} } as unknown as SignTxInput + const tx = { wallet, txToSign: {} } as unknown as SignTxInput - await expect( - adapter.signAndBroadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - signTxInput, - }), - ).resolves.toEqual('0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331') + await expect(adapter.signAndBroadcastTransaction(tx)).resolves.toEqual( + '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + ) }) }) @@ -404,11 +392,7 @@ describe('PolygonChainAdapter', () => { const adapter = new polygon.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(expectedResult) diff --git a/packages/chain-adapters/src/types.ts b/packages/chain-adapters/src/types.ts index d055757e8e1..56abdd03b39 100644 --- a/packages/chain-adapters/src/types.ts +++ b/packages/chain-adapters/src/types.ts @@ -321,15 +321,3 @@ export enum ChainAdapterDisplayName { Dogecoin = 'Dogecoin', Litecoin = 'Litecoin', } - -export type BroadcastTransactionInput = { - senderAddress: string - receiverAddress: string | undefined // this is not defined for staking etc - hex: string -} - -export type SignAndBroadcastTransactionInput = { - senderAddress: string - receiverAddress: string | undefined // this is not defined for staking etc - signTxInput: SignTxInput> -} diff --git a/packages/chain-adapters/src/utils/validateAddress.ts b/packages/chain-adapters/src/utils/validateAddress.ts deleted file mode 100644 index 739bfb1565e..00000000000 --- a/packages/chain-adapters/src/utils/validateAddress.ts +++ /dev/null @@ -1,41 +0,0 @@ -import axios from 'axios' - -const TRM_LABS_API_URL = 'https://api.trmlabs.com/public/v1/sanctions/screening' - -const cache: Record> = {} - -const _validateAddress = async (address: string): Promise => { - type trmResponse = [ - { - address: string - isSanctioned: boolean - }, - ] - - const response = await axios.post( - TRM_LABS_API_URL, - [ - { - address, - }, - ], - { - headers: { - Accept: 'application/json', - }, - }, - ) - - return response.data[0].isSanctioned -} - -export const validateAddress = async (address: string): Promise => { - // dedupe and cache promises in memory - if (cache[address] === undefined) { - const newEntry = _validateAddress(address) - cache[address] = newEntry - } - - const result = cache[address] - if (await result) throw Error('Address not supported') -} diff --git a/packages/chain-adapters/src/utxo/UtxoBaseAdapter.ts b/packages/chain-adapters/src/utxo/UtxoBaseAdapter.ts index b8d1dd113ad..c43dbe99109 100644 --- a/packages/chain-adapters/src/utxo/UtxoBaseAdapter.ts +++ b/packages/chain-adapters/src/utxo/UtxoBaseAdapter.ts @@ -19,12 +19,10 @@ import type { ChainAdapter as IChainAdapter } from '../api' import { ErrorHandler } from '../error/ErrorHandler' import type { Account, - BroadcastTransactionInput, BuildSendTxInput, FeeDataEstimate, GetBIP44ParamsInput, GetFeeDataInput, - SignAndBroadcastTransactionInput, SignTx, SignTxInput, SubscribeError, @@ -45,7 +43,6 @@ import { toRootDerivationPath, } from '../utils' import { bnOrZero } from '../utils/bignumber' -import { validateAddress } from '../utils/validateAddress' import type { bitcoin, bitcoincash, dogecoin, litecoin } from './' import type { GetAddressInput } from './types' import { utxoSelect } from './utxoSelect' @@ -423,25 +420,15 @@ export abstract class UtxoBaseAdapter implements IChainAd } } - async signAndBroadcastTransaction({ - senderAddress, - receiverAddress, - signTxInput, - }: SignAndBroadcastTransactionInput): Promise { - await Promise.all([ - validateAddress(senderAddress), - receiverAddress !== undefined && validateAddress(receiverAddress), - ]) - + async signAndBroadcastTransaction(signTxInput: SignTxInput>): Promise { try { const { wallet } = signTxInput if (!supportsBTC(wallet)) { throw new Error(`UtxoBaseAdapter: wallet does not support ${this.coinName}`) } - const hex = await this.signTransaction(signTxInput) - - return this.broadcastTransaction({ senderAddress, receiverAddress, hex }) + const signedTx = await this.signTransaction(signTxInput) + return this.broadcastTransaction(signedTx) } catch (err) { return ErrorHandler(err) } @@ -516,16 +503,7 @@ export abstract class UtxoBaseAdapter implements IChainAd } } - async broadcastTransaction({ - senderAddress, - receiverAddress, - hex, - }: BroadcastTransactionInput): Promise { - await Promise.all([ - validateAddress(senderAddress), - receiverAddress !== undefined && validateAddress(receiverAddress), - ]) - + broadcastTransaction(hex: string): Promise { return this.providers.http.sendTx({ sendTxBody: { hex } }) } diff --git a/packages/chain-adapters/src/utxo/bitcoin/BitcoinChainAdapter.test.ts b/packages/chain-adapters/src/utxo/bitcoin/BitcoinChainAdapter.test.ts index 8379bec282c..a3ef7ee235e 100644 --- a/packages/chain-adapters/src/utxo/bitcoin/BitcoinChainAdapter.test.ts +++ b/packages/chain-adapters/src/utxo/bitcoin/BitcoinChainAdapter.test.ts @@ -16,10 +16,6 @@ import type { Account, BuildSendTxInput, GetFeeDataInput } from '../../types' import type { ChainAdapterArgs, UtxoChainId } from '../UtxoBaseAdapter' import * as bitcoin from './BitcoinChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const testMnemonic = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle' const VALID_CHAIN_ID = 'bip122:000000000019d6689c085ae165831e93' const VALID_ASSET_ID = 'bip122:000000000019d6689c085ae165831e93/slip44:0' @@ -314,11 +310,7 @@ describe('BitcoinChainAdapter', () => { } as any const adapter = new bitcoin.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(sendDataResult) }) diff --git a/packages/chain-adapters/src/utxo/bitcoincash/BitcoinCashChainAdapter.test.ts b/packages/chain-adapters/src/utxo/bitcoincash/BitcoinCashChainAdapter.test.ts index 5873a32507b..0d3da1e2a9b 100644 --- a/packages/chain-adapters/src/utxo/bitcoincash/BitcoinCashChainAdapter.test.ts +++ b/packages/chain-adapters/src/utxo/bitcoincash/BitcoinCashChainAdapter.test.ts @@ -22,10 +22,6 @@ import type { Account, BuildSendTxInput, GetFeeDataInput } from '../../types' import type { ChainAdapterArgs, UtxoChainId } from '../UtxoBaseAdapter' import * as bitcoincash from './BitcoinCashChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const testMnemonic = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle' const VALID_CHAIN_ID = bchChainId const VALID_ASSET_ID = bchAssetId @@ -333,11 +329,7 @@ describe('BitcoinCashChainAdapter', () => { } as any const adapter = new bitcoincash.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(sendDataResult) }) diff --git a/packages/chain-adapters/src/utxo/dogecoin/DogecoinChainAdapter.test.ts b/packages/chain-adapters/src/utxo/dogecoin/DogecoinChainAdapter.test.ts index b8348633699..442086b452c 100644 --- a/packages/chain-adapters/src/utxo/dogecoin/DogecoinChainAdapter.test.ts +++ b/packages/chain-adapters/src/utxo/dogecoin/DogecoinChainAdapter.test.ts @@ -16,10 +16,6 @@ import type { Account, BuildSendTxInput, GetFeeDataInput } from '../../types' import type { ChainAdapterArgs, UtxoChainId } from '../UtxoBaseAdapter' import * as dogecoin from './DogecoinChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const testMnemonic = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle' const VALID_CHAIN_ID = 'bip122:00000000001a91e3dace36e2be3bf030' const VALID_ASSET_ID = 'bip122:00000000001a91e3dace36e2be3bf030/slip44:3' @@ -322,11 +318,7 @@ describe('DogecoinChainAdapter', () => { } as any const adapter = new dogecoin.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(sendDataResult) }) diff --git a/packages/chain-adapters/src/utxo/litecoin/LitecoinChainAdapter.test.ts b/packages/chain-adapters/src/utxo/litecoin/LitecoinChainAdapter.test.ts index e804908e050..7ed78a37ade 100644 --- a/packages/chain-adapters/src/utxo/litecoin/LitecoinChainAdapter.test.ts +++ b/packages/chain-adapters/src/utxo/litecoin/LitecoinChainAdapter.test.ts @@ -17,10 +17,6 @@ import type { Account, BuildSendTxInput, GetFeeDataInput } from '../../types' import type { ChainAdapterArgs, UtxoChainId } from '../UtxoBaseAdapter' import * as litecoin from './LitecoinChainAdapter' -jest.mock('../../utils/validateAddress', () => ({ - validateAddress: jest.fn(), -})) - const testMnemonic = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle' const VALID_CHAIN_ID = ltcChainId const VALID_ASSET_ID = ltcAssetId @@ -320,11 +316,7 @@ describe('LitecoinChainAdapter', () => { } as any const adapter = new litecoin.ChainAdapter(args) const mockTx = '0x123' - const result = await adapter.broadcastTransaction({ - senderAddress: '0x1234', - receiverAddress: '0x1234', - hex: mockTx, - }) + const result = await adapter.broadcastTransaction(mockTx) expect(args.providers.http.sendTx).toHaveBeenCalledWith({ sendTxBody: { hex: mockTx } }) expect(result).toEqual(sendDataResult) }) diff --git a/src/components/Modals/Send/hooks/useFormSend/useFormSend.test.tsx b/src/components/Modals/Send/hooks/useFormSend/useFormSend.test.tsx index e25e0cf5f7f..8067833b3aa 100644 --- a/src/components/Modals/Send/hooks/useFormSend/useFormSend.test.tsx +++ b/src/components/Modals/Send/hooks/useFormSend/useFormSend.test.tsx @@ -110,14 +110,12 @@ const formData: SendInput = { [SendFormFields.FiatAmount]: '3500', [SendFormFields.FiatSymbol]: 'USD', [SendFormFields.SendMax]: false, - [SendFormFields.AccountId]: 'eip155:1:0x3155ba85d5f96b2d030a4966af206230e46849cb', + [SendFormFields.AccountId]: 'eip155:1/erc20:0x3155ba85d5f96b2d030a4966af206230e46849cb', } const formDataEnsAddress = { ...formData, [SendFormFields.To]: 'willywonka.eth' } -const testSendAddress = '0x3155ba85d5f96b2d030a4966af206230e46849cb' - -const testTxToSign = { +const textTxToSign = { addressNList: [2147483692, 2147483708, 2147483648, 0, 0], value: '0x0', to: '0x3155ba85d5f96b2d030a4966af206230e46849cb', @@ -167,8 +165,7 @@ describe.each([ } }) const mockAdapter = { - getAddress: () => Promise.resolve(testSendAddress), - buildSendTransaction: () => Promise.resolve(testTxToSign), + buildSendTransaction: () => Promise.resolve(textTxToSign), signTransaction: () => Promise.resolve(testSignedTx), broadcastTransaction: () => Promise.resolve(expectedTx), } @@ -232,8 +229,7 @@ describe.each([ } }) const mockAdapter = { - getAddress: () => Promise.resolve(testSendAddress), - buildSendTransaction: () => Promise.resolve(testTxToSign), + buildSendTransaction: () => Promise.resolve(textTxToSign), signTransaction: () => Promise.resolve(testSignedTx), broadcastTransaction: () => Promise.resolve(expectedTx), } @@ -294,8 +290,7 @@ describe.each([ } }) const mockAdapter = { - getAddress: () => Promise.resolve(testSendAddress), - buildSendTransaction: () => Promise.resolve(testTxToSign), + buildSendTransaction: () => Promise.resolve(textTxToSign), signAndBroadcastTransaction, } @@ -361,8 +356,7 @@ describe.each([ } }) const mockAdapter = { - getAddress: () => Promise.resolve(testSendAddress), - buildSendTransaction: () => Promise.resolve(testTxToSign), + buildSendTransaction: () => Promise.resolve(textTxToSign), signAndBroadcastTransaction, } @@ -416,7 +410,6 @@ describe.each([ }) const mockAdapter = { - getAddress: () => Promise.resolve(testSendAddress), buildSendTransaction: () => Promise.reject('All these calls failed'), signTransaction: () => Promise.reject('All these calls failed'), broadcastTransaction: () => Promise.reject('All these calls failed'), diff --git a/src/components/Modals/Send/utils.ts b/src/components/Modals/Send/utils.ts index 0d3ac715378..e0db4d925c7 100644 --- a/src/components/Modals/Send/utils.ts +++ b/src/components/Modals/Send/utils.ts @@ -1,18 +1,20 @@ import type { AssetId, ChainId } from '@shapeshiftoss/caip' import { CHAIN_NAMESPACE, fromAccountId, fromAssetId, fromChainId } from '@shapeshiftoss/caip' import type { - ChainAdapter, CosmosSdkBaseAdapter, CosmosSdkChainId, - EvmBaseAdapter, - EvmChainId, - FeeData, FeeDataEstimate, GetFeeDataInput, - UtxoBaseAdapter, - UtxoChainId, } from '@shapeshiftoss/chain-adapters' -import { utxoChainIds } from '@shapeshiftoss/chain-adapters' +import { + type ChainAdapter, + type EvmBaseAdapter, + type EvmChainId, + type FeeData, + type UtxoBaseAdapter, + type UtxoChainId, + utxoChainIds, +} from '@shapeshiftoss/chain-adapters' import type { HDWallet } from '@shapeshiftoss/hdwallet-core' import { supportsETH } from '@shapeshiftoss/hdwallet-core' import type { KnownChainIds } from '@shapeshiftoss/types' @@ -215,22 +217,13 @@ export const handleSend = async ({ const txToSign = result.txToSign - const senderAddress = await adapter.getAddress({ - accountNumber: accountMetadata.bip44Params.accountNumber, - wallet, - }) - const broadcastTXID = await (async () => { if (wallet.supportsOfflineSigning()) { const signedTx = await adapter.signTransaction({ txToSign, wallet, }) - return adapter.broadcastTransaction({ - senderAddress, - receiverAddress: to, - hex: signedTx, - }) + return adapter.broadcastTransaction(signedTx) } else if (wallet.supportsBroadcast()) { /** * signAndBroadcastTransaction is an optional method on the HDWallet interface. @@ -239,11 +232,7 @@ export const handleSend = async ({ if (!adapter.signAndBroadcastTransaction) { throw new Error('signAndBroadcastTransaction undefined for wallet') } - return adapter.signAndBroadcastTransaction({ - senderAddress, - receiverAddress: to, - signTxInput: { txToSign, wallet }, - }) + return adapter.signAndBroadcastTransaction?.({ txToSign, wallet }) } else { throw new Error('Bad hdwallet config') } diff --git a/src/components/MultiHopTrade/hooks/useAllowanceApproval/hooks/useExecuteAllowanceApproval.tsx b/src/components/MultiHopTrade/hooks/useAllowanceApproval/hooks/useExecuteAllowanceApproval.tsx index 630e4e8b149..f4a17312338 100644 --- a/src/components/MultiHopTrade/hooks/useAllowanceApproval/hooks/useExecuteAllowanceApproval.tsx +++ b/src/components/MultiHopTrade/hooks/useAllowanceApproval/hooks/useExecuteAllowanceApproval.tsx @@ -36,11 +36,7 @@ export const useExecuteAllowanceApproval = ( } try { - const txId = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver for this contract call - }) + const txId = await buildAndBroadcast({ buildCustomTxInput, adapter }) setTxId(txId) diff --git a/src/components/MultiHopTrade/hooks/useTradeExecution/useTradeExecution.ts b/src/components/MultiHopTrade/hooks/useTradeExecution/useTradeExecution.ts index f793c0b20f5..083afe4f1eb 100644 --- a/src/components/MultiHopTrade/hooks/useTradeExecution/useTradeExecution.ts +++ b/src/components/MultiHopTrade/hooks/useTradeExecution/useTradeExecution.ts @@ -1,5 +1,5 @@ import type { StdSignDoc } from '@keplr-wallet/types' -import { bchAssetId, CHAIN_NAMESPACE, fromChainId } from '@shapeshiftoss/caip' +import { CHAIN_NAMESPACE, fromChainId } from '@shapeshiftoss/caip' import type { SignMessageInput } from '@shapeshiftoss/chain-adapters' import { toAddressNList } from '@shapeshiftoss/chain-adapters' import type { BuildCustomTxInput } from '@shapeshiftoss/chain-adapters/src/evm/types' @@ -103,12 +103,10 @@ export const useTradeExecution = ({ const { accountType, bip44Params } = accountMetadata const accountNumber = bip44Params.accountNumber - const stepSellAssetChainId = tradeQuote.steps[activeStepOrDefault].sellAsset.chainId - const stepSellAssetAssetId = tradeQuote.steps[activeStepOrDefault].sellAsset.assetId - const stepBuyAssetAssetId = tradeQuote.steps[activeStepOrDefault].buyAsset.assetId + const chainId = tradeQuote.steps[activeStepOrDefault].sellAsset.chainId if (swapperName === SwapperName.CowSwap) { - const adapter = assertGetEvmChainAdapter(stepSellAssetChainId) + const adapter = assertGetEvmChainAdapter(chainId) const from = await adapter.getAddress({ accountNumber, wallet }) const output = await execution.execEvmMessage({ swapperName, @@ -135,18 +133,12 @@ export const useTradeExecution = ({ return } - const { chainNamespace: stepSellAssetChainNamespace } = fromChainId(stepSellAssetChainId) + const { chainNamespace } = fromChainId(chainId) - const receiverAddress = - tradeQuote.receiveAddress && stepBuyAssetAssetId === bchAssetId - ? tradeQuote.receiveAddress.replace('bitcoincash:', '') - : tradeQuote.receiveAddress - - switch (stepSellAssetChainNamespace) { + switch (chainNamespace) { case CHAIN_NAMESPACE.Evm: { - const adapter = assertGetEvmChainAdapter(stepSellAssetChainId) + const adapter = assertGetEvmChainAdapter(chainId) const from = await adapter.getAddress({ accountNumber, wallet }) - const output = await execution.execEvmTransaction({ swapperName, tradeQuote, @@ -159,13 +151,7 @@ export const useTradeExecution = ({ wallet, accountNumber, } as BuildCustomTxInput) - return await signAndBroadcast({ - adapter, - txToSign, - wallet, - senderAddress: from, - receiverAddress, - }) + return await signAndBroadcast({ adapter, txToSign, wallet }) }, }) cancelPollingRef.current = output?.cancelPolling @@ -173,14 +159,8 @@ export const useTradeExecution = ({ } case CHAIN_NAMESPACE.Utxo: { if (accountType === undefined) throw Error('Missing UTXO account type') - const adapter = assertGetUtxoChainAdapter(stepSellAssetChainId) + const adapter = assertGetUtxoChainAdapter(chainId) const { xpub } = await adapter.getPublicKey(wallet, accountNumber, accountType) - const _senderAddress = await adapter.getAddress({ accountNumber, wallet }) - const senderAddress = - stepSellAssetAssetId === bchAssetId - ? _senderAddress.replace('bitcoincash:', '') - : _senderAddress - const output = await execution.execUtxoTransaction({ swapperName, tradeQuote, @@ -193,18 +173,14 @@ export const useTradeExecution = ({ txToSign, wallet, }) - return adapter.broadcastTransaction({ - senderAddress, - receiverAddress, - hex: signedTx, - }) + return adapter.broadcastTransaction(signedTx) }, }) cancelPollingRef.current = output?.cancelPolling return } case CHAIN_NAMESPACE.CosmosSdk: { - const adapter = assertGetCosmosSdkChainAdapter(stepSellAssetChainId) + const adapter = assertGetCosmosSdkChainAdapter(chainId) const from = await adapter.getAddress({ accountNumber, wallet }) const output = await execution.execCosmosSdkTransaction({ swapperName, @@ -232,18 +208,14 @@ export const useTradeExecution = ({ txToSign, wallet, }) - return adapter.broadcastTransaction({ - senderAddress: from, - receiverAddress: tradeQuote.receiveAddress, - hex: signedTx, - }) + return adapter.broadcastTransaction(signedTx) }, }) cancelPollingRef.current = output?.cancelPolling return } default: - assertUnreachable(stepSellAssetChainNamespace) + assertUnreachable(chainNamespace) } }) }, [ @@ -253,8 +225,8 @@ export const useTradeExecution = ({ swapperName, sellAssetAccountId, activeStepOrDefault, - dispatch, slippageTolerancePercentageDecimal, + dispatch, ]) useEffect(() => { diff --git a/src/config.ts b/src/config.ts index 089a2c991ff..2945bad191e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -154,6 +154,7 @@ const validators = { REACT_APP_EXPERIMENTAL_MM_SNAPPY_FINGERS: bool({ default: false }), REACT_APP_SNAP_ID: str(), REACT_APP_FEATURE_FOX_DISCOUNTS: bool({ default: false }), + REACT_APP_TRM_LABS_API_URL: url(), } function reporter({ errors }: envalid.ReporterOptions) { diff --git a/src/context/PluginProvider/PluginProvider.tsx b/src/context/PluginProvider/PluginProvider.tsx index d286a39c83b..136e5b264e8 100644 --- a/src/context/PluginProvider/PluginProvider.tsx +++ b/src/context/PluginProvider/PluginProvider.tsx @@ -62,7 +62,7 @@ export const PluginProvider = ({ children }: PluginProviderProps): JSX.Element = const newChainAdapters: { [k in ChainId]?: () => ChainAdapter } = {} // register providers from each plugin - for (const plugin of pluginManager.values()) { + for (const [, plugin] of pluginManager.entries()) { // Ignore plugins that have their feature flag disabled // If no featureFlag is present, then we assume it's enabled const featureFlagEnabled = diff --git a/src/features/defi/providers/fox-farming/hooks/useFoxFarming.ts b/src/features/defi/providers/fox-farming/hooks/useFoxFarming.ts index 919eab946d5..73dd8d5aa0a 100644 --- a/src/features/defi/providers/fox-farming/hooks/useFoxFarming.ts +++ b/src/features/defi/providers/fox-farming/hooks/useFoxFarming.ts @@ -74,11 +74,7 @@ export const useFoxFarming = ( wallet, }) - const txid = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver for this contract call - }) + const txid = await buildAndBroadcast({ adapter, buildCustomTxInput }) return txid } catch (err) { @@ -119,11 +115,7 @@ export const useFoxFarming = ( wallet, }) - const txid = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver for this contract call - }) + const txid = await buildAndBroadcast({ adapter, buildCustomTxInput }) return txid } catch (err) { @@ -244,7 +236,6 @@ export const useFoxFarming = ( const txid = await buildAndBroadcast({ adapter, - receiverAddress: undefined, // no receiver for this contract call buildCustomTxInput: { accountNumber, to: uniV2LPContract.address, @@ -274,11 +265,7 @@ export const useFoxFarming = ( wallet, }) - const txid = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver for this contract call - }) + const txid = await buildAndBroadcast({ adapter, buildCustomTxInput }) return txid }, [accountNumber, adapter, ethAsset.chainId, contractAddress, foxFarmingContract, skip, wallet]) diff --git a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Approve.tsx b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Approve.tsx index 9533cb1c858..61a0322f514 100644 --- a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Approve.tsx +++ b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Approve.tsx @@ -161,11 +161,7 @@ export const Approve: React.FC = ({ accountId, onNext }) => { wallet, }) - await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver for this contract call - }) + await buildAndBroadcast({ adapter, buildCustomTxInput }) await poll({ fn: () => getErc20Allowance({ diff --git a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Confirm.tsx b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Confirm.tsx index 4416b24f1c9..8480602f67c 100644 --- a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Confirm.tsx +++ b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Deposit/components/Confirm.tsx @@ -557,19 +557,15 @@ export const Confirm: React.FC = ({ accountId, onNext }) => { ]) const handleCustomTx = useCallback(async (): Promise => { - if (!wallet || accountNumber === undefined) return + if (!wallet) return const buildCustomTxInput = await getCustomTxInput() if (!buildCustomTxInput) return const adapter = assertGetEvmChainAdapter(chainId) - const txid = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver for this contract call - }) + const txid = await buildAndBroadcast({ adapter, buildCustomTxInput }) return txid - }, [wallet, accountNumber, getCustomTxInput, chainId]) + }, [wallet, getCustomTxInput, chainId]) const handleMultiTxSend = useCallback(async (): Promise => { if (!wallet) return diff --git a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx index f18f12ccfa9..f6449553708 100644 --- a/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx +++ b/src/features/defi/providers/thorchain-savers/components/ThorchainSaversManager/Withdraw/components/Confirm.tsx @@ -609,19 +609,15 @@ export const Confirm: React.FC = ({ accountId, onNext }) => { ]) const handleCustomTx = useCallback(async (): Promise => { - if (!wallet || accountNumber === undefined) return + if (!wallet) return const buildCustomTxInput = await getCustomTxInput() if (!buildCustomTxInput) return const adapter = assertGetEvmChainAdapter(chainId) - const txid = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver for this contract call - }) + const txid = await buildAndBroadcast({ adapter, buildCustomTxInput }) return txid - }, [wallet, accountNumber, getCustomTxInput, chainId]) + }, [wallet, getCustomTxInput, chainId]) const handleMultiTxSend = useCallback(async (): Promise => { if (!wallet) return diff --git a/src/features/defi/providers/univ2/hooks/useUniV2LiquidityPool.ts b/src/features/defi/providers/univ2/hooks/useUniV2LiquidityPool.ts index 4541e9901f0..bec951f229c 100644 --- a/src/features/defi/providers/univ2/hooks/useUniV2LiquidityPool.ts +++ b/src/features/defi/providers/univ2/hooks/useUniV2LiquidityPool.ts @@ -199,11 +199,7 @@ export const useUniV2LiquidityPool = ({ wallet, }) - const txid = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver - }) + const txid = await buildAndBroadcast({ adapter, buildCustomTxInput }) return txid } catch (err) { @@ -313,11 +309,7 @@ export const useUniV2LiquidityPool = ({ wallet, }) - const txid = await buildAndBroadcast({ - adapter, - buildCustomTxInput, - receiverAddress: undefined, // no receiver - }) + const txid = await buildAndBroadcast({ adapter, buildCustomTxInput }) return txid } catch (err) { @@ -585,7 +577,6 @@ export const useUniV2LiquidityPool = ({ const txid = await buildAndBroadcast({ adapter, - receiverAddress: undefined, // no receiver buildCustomTxInput: { accountNumber, to: contractAddress, diff --git a/src/lib/investor/investor-foxy/api/api.ts b/src/lib/investor/investor-foxy/api/api.ts index 5205a63a638..bb5ab8ebd0c 100644 --- a/src/lib/investor/investor-foxy/api/api.ts +++ b/src/lib/investor/investor-foxy/api/api.ts @@ -142,12 +142,6 @@ export class FoxyApi { accountNumber: payload.bip44Params.accountNumber, ...(shouldUseEIP1559Fees ? { maxFeePerGas, maxPriorityFeePerGas } : { gasPrice }), }) - - const senderAddress = await this.adapter.getAddress({ - accountNumber: payload.bip44Params.accountNumber, - wallet, - }) - if (wallet.supportsOfflineSigning()) { const signedTx = await this.adapter.signTransaction({ txToSign, wallet }) if (dryRun) return signedTx @@ -156,11 +150,7 @@ export class FoxyApi { const sendSignedTx = await this.provider.sendTransaction(signedTx) return sendSignedTx?.blockHash ?? '' } - return this.adapter.broadcastTransaction({ - senderAddress, - receiverAddress: undefined, // no receiver for this contract call - hex: signedTx, - }) + return this.adapter.broadcastTransaction(signedTx) } catch (e) { throw new Error(`Failed to broadcast: ${e}`) } @@ -168,11 +158,7 @@ export class FoxyApi { if (dryRun) { throw new Error(`Cannot perform a dry run with wallet of type ${wallet.getVendor()}`) } - return this.adapter.signAndBroadcastTransaction({ - senderAddress, - receiverAddress: undefined, // no receiver for this contract call - signTxInput: { txToSign, wallet }, - }) + return this.adapter.signAndBroadcastTransaction({ txToSign, wallet }) } else { throw new Error('Invalid HDWallet configuration ') } diff --git a/src/lib/investor/investor-idle/IdleOpportunity.ts b/src/lib/investor/investor-idle/IdleOpportunity.ts index 44ab5e3e6fc..b2ce4bb0dbd 100644 --- a/src/lib/investor/investor-idle/IdleOpportunity.ts +++ b/src/lib/investor/investor-idle/IdleOpportunity.ts @@ -463,28 +463,15 @@ export class IdleOpportunity addressNList: toAddressNList(bip44Params), } - const senderAddress = await chainAdapter.getAddress({ - accountNumber: bip44Params.accountNumber, - wallet, - }) - if (wallet.supportsOfflineSigning()) { const signedTx = await chainAdapter.signTransaction({ txToSign, wallet }) if (this.#internals.dryRun) return signedTx - return chainAdapter.broadcastTransaction({ - senderAddress, - receiverAddress: undefined, // no receiver for this contract call - hex: signedTx, - }) + return chainAdapter.broadcastTransaction(signedTx) } else if (wallet.supportsBroadcast() && chainAdapter.signAndBroadcastTransaction) { if (this.#internals.dryRun) { throw new Error(`Cannot perform a dry run with wallet of type ${wallet.getVendor()}`) } - return chainAdapter.signAndBroadcastTransaction({ - senderAddress, - receiverAddress: undefined, // no receiver for this contract call - signTxInput: { txToSign, wallet }, - }) + return chainAdapter.signAndBroadcastTransaction({ txToSign, wallet }) } else { throw new Error('Invalid HDWallet configuration') } diff --git a/src/lib/investor/investor-yearn/YearnOpportunity.ts b/src/lib/investor/investor-yearn/YearnOpportunity.ts index 29a185251d6..4e4521314d8 100644 --- a/src/lib/investor/investor-yearn/YearnOpportunity.ts +++ b/src/lib/investor/investor-yearn/YearnOpportunity.ts @@ -3,7 +3,8 @@ import type { ChainAdapter } from '@shapeshiftoss/chain-adapters' import { toAddressNList } from '@shapeshiftoss/chain-adapters' import type { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core' import type { BIP44Params, KnownChainIds } from '@shapeshiftoss/types' -import type { ChainId, Vault, VaultMetadata, Yearn } from '@yfi/sdk' +import type { Yearn } from '@yfi/sdk' +import { type ChainId, type Vault, type VaultMetadata } from '@yfi/sdk' import type { BigNumber } from 'bignumber.js' import isNil from 'lodash/isNil' import toLower from 'lodash/toLower' @@ -195,28 +196,15 @@ export class YearnOpportunity addressNList: toAddressNList(bip44Params), } - const senderAddress = await chainAdapter.getAddress({ - accountNumber: bip44Params.accountNumber, - wallet, - }) - if (wallet.supportsOfflineSigning()) { const signedTx = await chainAdapter.signTransaction({ txToSign, wallet }) if (this.#internals.dryRun) return signedTx - return chainAdapter.broadcastTransaction({ - senderAddress, - receiverAddress: undefined, // no receiver for this contract call - hex: signedTx, - }) + return chainAdapter.broadcastTransaction(signedTx) } else if (wallet.supportsBroadcast() && chainAdapter.signAndBroadcastTransaction) { if (this.#internals.dryRun) { throw new Error(`Cannot perform a dry run with wallet of type ${wallet.getVendor()}`) } - return chainAdapter.signAndBroadcastTransaction({ - senderAddress, - receiverAddress: undefined, // no receiver for this contract call - signTxInput: { txToSign, wallet }, - }) + return chainAdapter.signAndBroadcastTransaction({ txToSign, wallet }) } else { throw new Error('Invalid HDWallet configuration') } diff --git a/src/lib/swapper/swapper.ts b/src/lib/swapper/swapper.ts index ea4e7c73535..f61b351ab02 100644 --- a/src/lib/swapper/swapper.ts +++ b/src/lib/swapper/swapper.ts @@ -11,6 +11,7 @@ import type { SwapperName, TradeQuote, } from './types' +import { isValidSwapAddress } from './utils' export const getTradeQuotes = async ( getTradeQuoteInput: GetTradeQuoteInput, @@ -19,6 +20,24 @@ export const getTradeQuotes = async ( if (bnOrZero(getTradeQuoteInput.affiliateBps).lt(0)) return [] if (getTradeQuoteInput.sellAmountIncludingProtocolFeesCryptoBaseUnit === '0') return [] + try { + if (getTradeQuoteInput.sendAddress !== undefined) { + const isSenderValid = await isValidSwapAddress(getTradeQuoteInput.sendAddress) + if (!isSenderValid) { + return [] // no quotes available for this address + } + } + + if (getTradeQuoteInput.sendAddress !== getTradeQuoteInput.receiveAddress) { + const isReceiverValid = await isValidSwapAddress(getTradeQuoteInput.receiveAddress) + if (!isReceiverValid) { + return [] // no quotes available for this address + } + } + } catch (e) { + console.error(e) // log error but don't fail + } + const quotes = await Promise.allSettled( swappers .filter(({ swapperName }) => enabledSwappers.includes(swapperName)) diff --git a/src/lib/swapper/types.ts b/src/lib/swapper/types.ts index 3b2928bd209..48f90ddbaae 100644 --- a/src/lib/swapper/types.ts +++ b/src/lib/swapper/types.ts @@ -215,8 +215,6 @@ export type GetUnsignedCosmosSdkTransactionArgs = CommonGetUnsignedTransactionAr export type UnsignedTx = Nominal, 'UnsignedTx'> export type ExecuteTradeArgs = { - senderAddress: string - receiverAddress: string txToSign: UnsignedTx wallet: HDWallet chainId: ChainId diff --git a/src/lib/swapper/utils.ts b/src/lib/swapper/utils.ts index aea368f58b1..40c2dd53928 100644 --- a/src/lib/swapper/utils.ts +++ b/src/lib/swapper/utils.ts @@ -2,8 +2,10 @@ import type { AssetId } from '@shapeshiftoss/caip' import type { Result } from '@sniptt/monads' import { Err, Ok } from '@sniptt/monads' import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios' +import axios from 'axios' import type { ISetupCache } from 'axios-cache-adapter' import { setupCache } from 'axios-cache-adapter' +import { getConfig } from 'config' import type { FeatureFlags } from 'state/slices/preferencesSlice/preferencesSlice' import { isCrossAccountTradeSupported } from '../../state/helpers' @@ -133,3 +135,27 @@ export const createTradeAmountTooSmallErr = (details?: { message: 'Sell amount is too small', details, }) + +export const isValidSwapAddress = async (address: string): Promise => { + type trmResponse = [ + { + address: string + isSanctioned: boolean + }, + ] + + const response = await axios.post( + getConfig().REACT_APP_TRM_LABS_API_URL, + [ + { + address, + }, + ], + { + headers: { + Accept: 'application/json', + }, + }, + ) + return !response.data[0].isSanctioned +} diff --git a/src/lib/utils/evm.ts b/src/lib/utils/evm.ts index 1f91f2a80fe..1655932085b 100644 --- a/src/lib/utils/evm.ts +++ b/src/lib/utils/evm.ts @@ -34,15 +34,12 @@ type BuildArgs = { } type BroadcastArgs = { - senderAddress: string - receiverAddress: string | undefined adapter: EvmChainAdapter txToSign: SignTx wallet: HDWallet } -type BuildAndBroadcastArgs = BuildArgs & - Omit +type BuildAndBroadcastArgs = BuildArgs & Omit type CreateBuildCustomTxInputArgs = { accountNumber: number @@ -170,49 +167,22 @@ export const createBuildCustomApiTxInput = async ( return { ...args, ...fees } } -export const buildAndBroadcast = async ({ - adapter, - buildCustomTxInput, - receiverAddress, -}: BuildAndBroadcastArgs) => { - const senderAddress = await adapter.getAddress(buildCustomTxInput) +export const buildAndBroadcast = async ({ adapter, buildCustomTxInput }: BuildAndBroadcastArgs) => { const { txToSign } = await adapter.buildCustomTx(buildCustomTxInput) - return signAndBroadcast({ - adapter, - txToSign, - wallet: buildCustomTxInput.wallet, - senderAddress, - receiverAddress, - }) + return signAndBroadcast({ adapter, txToSign, wallet: buildCustomTxInput.wallet }) } -export const signAndBroadcast = async ({ - adapter, - txToSign, - wallet, - senderAddress, - receiverAddress, -}: BroadcastArgs) => { +export const signAndBroadcast = async ({ adapter, txToSign, wallet }: BroadcastArgs) => { if (!wallet) throw new Error('Wallet is required to broadcast EVM Txs') if (wallet.supportsOfflineSigning()) { const signedTx = await adapter.signTransaction({ txToSign, wallet }) - const txid = await adapter.broadcastTransaction({ - senderAddress, - receiverAddress, - hex: signedTx, - }) + const txid = await adapter.broadcastTransaction(signedTx) return txid } if (wallet.supportsBroadcast() && adapter.signAndBroadcastTransaction) { - // note that txToSign.to is often a contract address and not the actual receiver - // TODO: do we want to validate contract addresses too? - const txid = await adapter.signAndBroadcastTransaction({ - senderAddress, - receiverAddress, - signTxInput: { txToSign, wallet }, - }) + const txid = await adapter.signAndBroadcastTransaction({ txToSign, wallet }) return txid } @@ -255,21 +225,9 @@ export const assertGetEvmChainAdapter = (chainId: ChainId | KnownChainIds): EvmC return adapter } -export const executeEvmTrade = ({ - txToSign, - wallet, - chainId, - senderAddress, - receiverAddress, -}: ExecuteTradeArgs) => { +export const executeEvmTrade = ({ txToSign, wallet, chainId }: ExecuteTradeArgs) => { const adapter = assertGetEvmChainAdapter(chainId) - return signAndBroadcast({ - adapter, - wallet, - txToSign: txToSign as ETHSignTx, - senderAddress, - receiverAddress, - }) + return signAndBroadcast({ adapter, wallet, txToSign: txToSign as ETHSignTx }) } export const executeEvmTransaction = ( diff --git a/src/plugins/cosmos/hooks/useStakingAction/useStakingAction.tsx b/src/plugins/cosmos/hooks/useStakingAction/useStakingAction.tsx index 9060631f18a..d4d61059cae 100644 --- a/src/plugins/cosmos/hooks/useStakingAction/useStakingAction.tsx +++ b/src/plugins/cosmos/hooks/useStakingAction/useStakingAction.tsx @@ -60,8 +60,8 @@ export const useStakingAction = () => { const memo = shapeshiftValidators.includes(validator) ? 'Delegated with ShapeShift' : '' - const { accountNumber } = bip44Params const { txToSign } = await (() => { + const { accountNumber } = bip44Params switch (action) { case StakingAction.Claim: return adapter.buildClaimRewardsTransaction({ @@ -93,12 +93,8 @@ export const useStakingAction = () => { throw new Error(`unsupported staking action: ${action}`) } })() - const senderAddress = await adapter.getAddress({ accountNumber, wallet }) - return adapter.signAndBroadcastTransaction({ - senderAddress, - receiverAddress: undefined, // no receiver for this contract call - signTxInput: { txToSign, wallet }, - }) + + return adapter.signAndBroadcastTransaction({ txToSign, wallet }) } catch (error) { console.error(error) } diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 7143d6d01eb..4505b7bd628 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -20,8 +20,4 @@ export class PluginManager { keys() { return [...this.#pluginManager.keys()] } - - values() { - return [...this.#pluginManager.values()] - } } diff --git a/src/plugins/walletConnectToDapps/utils/EIP155RequestHandlerUtil.ts b/src/plugins/walletConnectToDapps/utils/EIP155RequestHandlerUtil.ts index 18a41d21a8e..a672badb4a0 100644 --- a/src/plugins/walletConnectToDapps/utils/EIP155RequestHandlerUtil.ts +++ b/src/plugins/walletConnectToDapps/utils/EIP155RequestHandlerUtil.ts @@ -88,7 +88,6 @@ export const approveEIP155Request = async ({ const didUserChangeNonce = maybeAdvancedParamsNonce && maybeAdvancedParamsNonce !== sendTransaction.nonce const fees = await getFeesForTx(sendTransaction, chainAdapter, accountId) - const senderAddress = await chainAdapter.getAddress({ accountNumber, wallet }) const gasData = getGasData(customTransactionData, fees) const { txToSign: txToSignWithPossibleWrongNonce } = await chainAdapter.buildCustomTx({ wallet, @@ -108,11 +107,7 @@ export const approveEIP155Request = async ({ txToSign, wallet, }) - const txHash = await chainAdapter.broadcastTransaction({ - senderAddress, - receiverAddress: txToSign.to, - hex: signedTx, - }) + const txHash = await chainAdapter.broadcastTransaction(signedTx) return formatJsonRpcResult(id, txHash) }