From 6f9fb548b78cadc05aff43c5aa7689bfb37095d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ram=C3=ADrez?= Date: Mon, 7 Oct 2024 17:07:26 -0300 Subject: [PATCH] fix(request): resolve ens when preparing request tx --- src/consts/interfaces.consts.ts | 1 + src/index.ts | 9 +++++++++ src/request.ts | 13 +++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/consts/interfaces.consts.ts b/src/consts/interfaces.consts.ts index 346bc86..3725624 100644 --- a/src/consts/interfaces.consts.ts +++ b/src/consts/interfaces.consts.ts @@ -596,6 +596,7 @@ export enum EPrepareCreateTxsStatusCodes { ERROR_SETTING_FEE_OPTIONS, ERROR_ESTIMATING_GAS_LIMIT, ERROR_MAKING_DEPOSIT, + ERROR_RESOLVING_ENS_NAME, } export enum ESignAndSubmitTx { diff --git a/src/index.ts b/src/index.ts index b95371b..dae5d9d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2021,6 +2021,13 @@ async function resolveToENSName({ return ensName } +async function resolveFromEnsName({ ensName }: { ensName: string }): Promise { + const provider = await getDefaultProvider('1') + const x = await provider.resolveName(ensName) + + return x ? x : undefined +} + /** * Claims a link through the Peanut API */ @@ -3113,6 +3120,7 @@ const peanut = { trim_decimal_overflow, verifySignature, resolveToENSName, + resolveFromEnsName, makeGaslessDepositPayload, prepareApproveERC20Tx, prepareGaslessDepositTx, @@ -3218,6 +3226,7 @@ export { trim_decimal_overflow, verifySignature, resolveToENSName, + resolveFromEnsName, makeGaslessDepositPayload, prepareGaslessDepositTx, makeGaslessReclaimPayload, diff --git a/src/request.ts b/src/request.ts index 0b82dea..f479073 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,7 +1,7 @@ import { ethers, getDefaultProvider, utils } from 'ethersv5' import { EPeanutLinkType, IPeanutUnsignedTransaction } from './consts/interfaces.consts' import { ERC20_ABI, LATEST_STABLE_BATCHER_VERSION } from './data' -import { config, getSquidRoute, interfaces, prepareApproveERC20Tx } from '.' +import { config, getSquidRoute, interfaces, prepareApproveERC20Tx, resolveFromEnsName } from '.' import { prepareXchainFromAmountCalculation } from './util' // INTERFACES @@ -180,12 +180,21 @@ export async function prepareXchainRequestFulfillmentTransaction({ }: IPrepareXchainRequestFulfillmentTransactionProps): Promise { const linkDetails = await getRequestLinkDetails({ link: link, apiUrl: apiUrl }) let { tokenAddress: destinationToken } = linkDetails - const { + let { chainId: destinationChainId, recipientAddress, tokenAmount: destinationTokenAmount, tokenDecimals: destinationTokenDecimals, } = linkDetails + if (recipientAddress.endsWith('.eth')) { + recipientAddress = await resolveFromEnsName({ ensName: recipientAddress }) + if (undefined === recipientAddress) { + throw new interfaces.SDKStatus( + interfaces.EPrepareCreateTxsStatusCodes.ERROR_RESOLVING_ENS_NAME, + 'Error resolving ENS name' + ) + } + } let txOptions: interfaces.ITxOptions = {} if (!provider) { try {