diff --git a/src/core/EVM/EVMStepExecutor.ts b/src/core/EVM/EVMStepExecutor.ts index 0f09c9e..9304625 100644 --- a/src/core/EVM/EVMStepExecutor.ts +++ b/src/core/EVM/EVMStepExecutor.ts @@ -36,7 +36,7 @@ import { parseEVMErrors } from './parseEVMErrors.js' import { type PermitSignature, signPermitMessage } from './signPermitMessage.js' import { switchChain } from './switchChain.js' import { isRelayerStep } from './typeguards.js' -import { getMaxPriorityFeePerGas } from './utils.js' +import { convertExtendedChain, getMaxPriorityFeePerGas } from './utils.js' import { type WalletCallReceipt, waitForBatchTransactionReceipt, @@ -86,7 +86,9 @@ export class EVMStepExecutor extends BaseStepExecutor { )(undefined)) as GetAddressesReturnType accountAddress = accountAddresses?.[0] } - if (accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase()) { + if ( + accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase() + ) { let processToUpdate = process if (!processToUpdate) { // We need to create some process if we don't have one so we can show the error @@ -533,14 +535,15 @@ export class EVMStepExecutor extends BaseStepExecutor { sendTransaction, 'sendTransaction' )({ - to: transactionRequest.to, + to: transactionRequest.to as Address, account: this.client.account!, - data: transactionRequest.data, + data: transactionRequest.data as Hex, value: transactionRequest.value, gas: transactionRequest.gas, gasPrice: transactionRequest.gasPrice, maxFeePerGas: transactionRequest.maxFeePerGas, maxPriorityFeePerGas: transactionRequest.maxPriorityFeePerGas, + chain: convertExtendedChain(fromChain), } as SendTransactionParameters) } } diff --git a/src/core/EVM/utils.ts b/src/core/EVM/utils.ts index 17b3964..7c0a52a 100644 --- a/src/core/EVM/utils.ts +++ b/src/core/EVM/utils.ts @@ -1,9 +1,60 @@ -import type { ChainId } from '@lifi/types' -import type { Address, Client, Transaction } from 'viem' +import type { ChainId, ExtendedChain } from '@lifi/types' +import type { Address, Chain, Client, Transaction } from 'viem' import { getBlock } from 'viem/actions' import { config } from '../../config.js' import { median } from '../../utils/median.js' +type ChainBlockExplorer = { + name: string + url: string +} + +type ChainBlockExplorers = { + [key: string]: ChainBlockExplorer + default: ChainBlockExplorer +} + +export const convertExtendedChain = (chain: ExtendedChain): Chain => ({ + ...chain, + ...chain.metamask, + blockExplorers: chain.metamask.blockExplorerUrls.reduce( + (blockExplorers, blockExplorer, index) => { + blockExplorers[index === 0 ? 'default' : `${index}`] = { + name: blockExplorer, + url: blockExplorer, + } + return blockExplorers + }, + {} as ChainBlockExplorers + ), + name: chain.metamask.chainName, + rpcUrls: { + default: { http: chain.metamask.rpcUrls }, + public: { http: chain.metamask.rpcUrls }, + }, + contracts: { + ...(chain.multicallAddress + ? { multicall3: { address: chain.multicallAddress as Address } } + : undefined), + }, +}) + +export function isExtendedChain(chain: any): chain is ExtendedChain { + return ( + typeof chain === 'object' && + chain !== null && + 'key' in chain && + 'chainType' in chain && + 'coin' in chain && + 'mainnet' in chain && + 'logoURI' in chain && + typeof chain.metamask === 'object' && + chain.metamask !== null && + typeof chain.nativeToken === 'object' && + chain.nativeToken !== null + ) +} + export const getMaxPriorityFeePerGas = async ( client: Client ): Promise => { diff --git a/src/index.ts b/src/index.ts index 638dbb4..8de8644 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ export { setTokenAllowance, } from './core/EVM/setAllowance.js' export { isEVM } from './core/EVM/types.js' +export { isExtendedChain, convertExtendedChain } from './core/EVM/utils.js' export { isRelayerStep } from './core/EVM/typeguards.js' export type { EVMProvider,