Skip to content

Commit

Permalink
Merge pull request #154 from peanutprotocol/fix/ens-on-request-create
Browse files Browse the repository at this point in the history
fix: resolve ens when preparing request xchain
  • Loading branch information
Hugo0 authored Oct 9, 2024
2 parents e8479ff + 6f9fb54 commit 030a1f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/consts/interfaces.consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,13 @@ async function resolveToENSName({
return ensName
}

async function resolveFromEnsName({ ensName }: { ensName: string }): Promise<string | undefined> {
const provider = await getDefaultProvider('1')
const x = await provider.resolveName(ensName)

return x ? x : undefined
}

/**
* Claims a link through the Peanut API
*/
Expand Down Expand Up @@ -3113,6 +3120,7 @@ const peanut = {
trim_decimal_overflow,
verifySignature,
resolveToENSName,
resolveFromEnsName,
makeGaslessDepositPayload,
prepareApproveERC20Tx,
prepareGaslessDepositTx,
Expand Down Expand Up @@ -3218,6 +3226,7 @@ export {
trim_decimal_overflow,
verifySignature,
resolveToENSName,
resolveFromEnsName,
makeGaslessDepositPayload,
prepareGaslessDepositTx,
makeGaslessReclaimPayload,
Expand Down
13 changes: 11 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -180,12 +180,21 @@ export async function prepareXchainRequestFulfillmentTransaction({
}: IPrepareXchainRequestFulfillmentTransactionProps): Promise<interfaces.IPrepareXchainRequestFulfillmentTransactionProps> {
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 {
Expand Down

0 comments on commit 030a1f4

Please sign in to comment.