diff --git a/packages/widget/src/controllers/transfers/evm/build.ts b/packages/widget/src/controllers/transfers/evm/build.ts index e1bf0d9b..8eb55928 100644 --- a/packages/widget/src/controllers/transfers/evm/build.ts +++ b/packages/widget/src/controllers/transfers/evm/build.ts @@ -13,6 +13,13 @@ import type { UnsignedTransaction, BigNumber } from 'ethers'; import { constants, utils } from 'ethers'; import type { Eip1193Provider } from '../../../interfaces'; +type BuildEvmFungibleTransactionsArtifacts = { + pendingEvmApprovalTransactions: UnsignedTransaction[]; + pendingTransferTransaction: UnsignedTransaction; + fee: EvmFee; + resourceAmount: BigNumber; +}; + /** * @dev If we did proper validation this shouldn't throw. * Not sure how to handle if it throws :shrug: @@ -42,12 +49,7 @@ export async function buildEvmFungibleTransactions({ pendingTransferTransaction: UnsignedTransaction; sourceNetwork: Domain | null; fee: EvmFee; -}): Promise<{ - pendingEvmApprovalTransactions: UnsignedTransaction[]; - pendingTransferTransaction: UnsignedTransaction; - fee: EvmFee; - resourceAmount: BigNumber; -}> { +}): Promise { const evmTransfer = new EVMAssetTransfer(); await evmTransfer.init(new Web3Provider(provider, providerChainId), env); diff --git a/packages/widget/src/controllers/transfers/evm/execute.ts b/packages/widget/src/controllers/transfers/evm/execute.ts index 7f9c2e8b..edd0763c 100644 --- a/packages/widget/src/controllers/transfers/evm/execute.ts +++ b/packages/widget/src/controllers/transfers/evm/execute.ts @@ -2,9 +2,9 @@ import { Web3Provider, type TransactionRequest } from '@ethersproject/providers'; -import type { UnsignedTransaction } from 'ethers'; +import type { PopulatedTransaction } from 'ethers'; import type { Eip1193Provider } from '../../../interfaces'; -import { estimateEvmGas } from '../../../utils/gas'; +import { estimateEvmTransactionsGasCost } from '../../../utils/gas'; import { FungibleTransferState, type FungibleTokenTransferController @@ -38,11 +38,11 @@ export async function executeNextEvmTransaction( this.pendingTransferTransaction ); - this.estimatedGas = await estimateEvmGas( + this.estimatedGas = await estimateEvmTransactionsGasCost( this.sourceNetwork?.chainId as number, this.walletContext.value?.evmWallet?.provider as Eip1193Provider, this.walletContext.value?.evmWallet?.address as string, - transactions as UnsignedTransaction[] + transactions as PopulatedTransaction[] ); } catch (e) { console.log(e); @@ -51,11 +51,11 @@ export async function executeNextEvmTransaction( this.waitingUserConfirmation = false; this.waitingTxExecution = false; this.host.requestUpdate(); - await estimateEvmGas( + await estimateEvmTransactionsGasCost( this.sourceNetwork?.chainId as number, this.walletContext.value?.evmWallet?.provider as Eip1193Provider, this.walletContext.value?.evmWallet?.address as string, - transactions as UnsignedTransaction[] + transactions as PopulatedTransaction[] ); } return; diff --git a/packages/widget/src/controllers/transfers/fungible-token-transfer.ts b/packages/widget/src/controllers/transfers/fungible-token-transfer.ts index bc8bef28..f7804a93 100644 --- a/packages/widget/src/controllers/transfers/fungible-token-transfer.ts +++ b/packages/widget/src/controllers/transfers/fungible-token-transfer.ts @@ -14,7 +14,11 @@ import { } from '@buildwithsygma/sygma-sdk-core'; import { ContextConsumer } from '@lit/context'; import { ethers } from 'ethers'; -import type { UnsignedTransaction, BigNumber } from 'ethers'; +import type { + UnsignedTransaction, + BigNumber, + PopulatedTransaction +} from 'ethers'; import type { ReactiveController, ReactiveElement } from 'lit'; import type { SubmittableExtrinsic } from '@polkadot/api/types'; import type { ApiPromise, SubmittableResult } from '@polkadot/api'; @@ -29,7 +33,10 @@ import { validateAddress } from '../../utils'; import type { Eip1193Provider } from '../../interfaces'; import { SdkInitializedEvent } from '../../interfaces'; import { substrateProviderContext } from '../../context/wallet'; -import { estimateEvmGas, estimateSubstrateGas } from '../../utils/gas'; +import { + estimateEvmTransactionsGasCost, + estimateSubstrateGas +} from '../../utils/gas'; import { buildEvmFungibleTransactions, executeNextEvmTransaction } from './evm'; import { buildSubstrateFungibleTransactions, @@ -77,7 +84,6 @@ export class FungibleTokenTransferController implements ReactiveController { public estimatedGas: BigNumber | undefined; //Evm transfer - protected buildEvmTransactions = buildEvmFungibleTransactions; protected executeNextEvmTransaction = executeNextEvmTransaction; protected pendingEvmApprovalTransactions: UnsignedTransaction[] = []; public pendingTransferTransaction?: @@ -548,7 +554,7 @@ export class FungibleTokenTransferController implements ReactiveController { this.isBuildingTransactions = true; try { - const evmTransferArtifacts = await this.buildEvmTransactions({ + const evmTransferArtifacts = await buildEvmFungibleTransactions({ address: address!, chainId: this.destinationNetwork!.chainId, destinationAddress: this.destinationAddress!, @@ -580,11 +586,11 @@ export class FungibleTokenTransferController implements ReactiveController { transactions.push(this.pendingTransferTransaction); } - this.estimatedGas = await estimateEvmGas( + this.estimatedGas = await estimateEvmTransactionsGasCost( this.sourceNetwork?.chainId as number, this.walletContext.value?.evmWallet?.provider as Eip1193Provider, this.walletContext.value?.evmWallet?.address as string, - transactions + transactions as PopulatedTransaction[] ); } catch (error) { console.error('Error Building transactions: ', error); diff --git a/packages/widget/src/controllers/transfers/substrate/build.ts b/packages/widget/src/controllers/transfers/substrate/build.ts index 37591a01..c7260825 100644 --- a/packages/widget/src/controllers/transfers/substrate/build.ts +++ b/packages/widget/src/controllers/transfers/substrate/build.ts @@ -5,6 +5,12 @@ import type { ApiPromise } from '@polkadot/api'; import type { BigNumber } from 'ethers'; import type { SubstrateTransaction } from '../fungible-token-transfer'; +type BuildSubstrateFungibleTransactionsArtifacts = { + pendingTransferTransaction: SubstrateTransaction; + resourceAmount: BigNumber; + fee: SubstrateFee; +}; + export async function buildSubstrateFungibleTransactions({ address, substrateProvider, @@ -25,11 +31,7 @@ export async function buildSubstrateFungibleTransactions({ resourceAmount: BigNumber; pendingTransferTransaction: SubstrateTransaction; fee: SubstrateFee; -}): Promise<{ - pendingTransferTransaction: SubstrateTransaction; - resourceAmount: BigNumber; - fee: SubstrateFee; -}> { +}): Promise { const substrateTransfer = new SubstrateAssetTransfer(); await substrateTransfer.init(substrateProvider, env); diff --git a/packages/widget/src/utils/gas.ts b/packages/widget/src/utils/gas.ts index c1dba696..2ecb140e 100644 --- a/packages/widget/src/utils/gas.ts +++ b/packages/widget/src/utils/gas.ts @@ -32,22 +32,6 @@ export async function estimateEvmTransactionsGasCost( return gasPrice.mul(cost); } -export async function estimateEvmGas( - chainId: number, - provider: Eip1193Provider, - address: string, - transactions: UnsignedTransaction[] -): Promise { - const estimatedGas = await estimateEvmTransactionsGasCost( - chainId, - provider, - address, - transactions as PopulatedTransaction[] - ); - - return estimatedGas; -} - export async function estimateSubstrateGas( signerAddress: string, pendingTransferTransaction: SubstrateTransaction diff --git a/packages/widget/src/utils/index.ts b/packages/widget/src/utils/index.ts index 7d76017b..08fec79e 100644 --- a/packages/widget/src/utils/index.ts +++ b/packages/widget/src/utils/index.ts @@ -87,7 +87,7 @@ export const validateAddress = ( export const debounceAmountChange = ( cb: (args: Args) => void, - delay?: number + delay: number ): ((value: Args) => void) => { let timeout: NodeJS.Timeout; return (args: Args): void => {