From 4b24ddd4c2fce81dd3c309d8cc5ebafcfc8ac790 Mon Sep 17 00:00:00 2001 From: borcherd Date: Fri, 19 Apr 2024 16:41:39 +0200 Subject: [PATCH 1/3] fix: check tokentype in validateLinkDetails --- src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 9021834..72dfec2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1160,7 +1160,11 @@ async function validateLinkDetails( ): Promise { linkDetails.tokenAddress = linkDetails.tokenAddress ?? '0x0000000000000000000000000000000000000000' - if (linkDetails.tokenDecimals == undefined || linkDetails.tokenType == undefined) { + if ( + (linkDetails.tokenType == interfaces.EPeanutLinkType.erc20 || + linkDetails.tokenType == interfaces.EPeanutLinkType.native) && + (linkDetails.tokenDecimals == undefined || linkDetails.tokenType == undefined) + ) { try { const contractDetails = await getTokenContractDetails({ address: linkDetails.tokenAddress, From 84b0df193848be0398a7fe3fa01456b052bfeb12 Mon Sep 17 00:00:00 2001 From: borcherd Date: Mon, 22 Apr 2024 14:15:57 +0200 Subject: [PATCH 2/3] chore: update validateLinkDetails decimal check --- src/index.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/index.ts b/src/index.ts index 72dfec2..c9176e0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1160,21 +1160,23 @@ async function validateLinkDetails( ): Promise { linkDetails.tokenAddress = linkDetails.tokenAddress ?? '0x0000000000000000000000000000000000000000' - if ( - (linkDetails.tokenType == interfaces.EPeanutLinkType.erc20 || - linkDetails.tokenType == interfaces.EPeanutLinkType.native) && - (linkDetails.tokenDecimals == undefined || linkDetails.tokenType == undefined) - ) { - try { - const contractDetails = await getTokenContractDetails({ - address: linkDetails.tokenAddress, - provider: provider, - }) + if (linkDetails.tokenDecimals == undefined || linkDetails.tokenType == undefined) { + if ( + linkDetails.tokenType == interfaces.EPeanutLinkType.erc20 || + linkDetails.tokenType == interfaces.EPeanutLinkType.native || + linkDetails.tokenType == undefined + ) { + try { + const contractDetails = await getTokenContractDetails({ + address: linkDetails.tokenAddress, + provider: provider, + }) - linkDetails.tokenType = contractDetails.type - contractDetails.decimals && (linkDetails.tokenDecimals = contractDetails.decimals) - } catch (error) { - throw new Error('Contract type not supported') + linkDetails.tokenType = contractDetails.type + contractDetails.decimals && (linkDetails.tokenDecimals = contractDetails.decimals) + } catch (error) { + throw new Error('Contract type not supported') + } } } From 5f10a77bc7dec49af9cab5218d52be1278ed7c1b Mon Sep 17 00:00:00 2001 From: borcherd Date: Mon, 22 Apr 2024 14:40:52 +0200 Subject: [PATCH 3/3] chore: update validateLinkDetails --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c9176e0..cd70b15 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1152,6 +1152,10 @@ async function getTxReceiptFromHash( return txReceipt } +/** + * function that validates all the details of the link. + * TODO: rename to something that indicates that it also updates the linkDetails + */ async function validateLinkDetails( linkDetails: interfaces.IPeanutLinkDetails, passwords: string[], @@ -1160,6 +1164,7 @@ async function validateLinkDetails( ): Promise { linkDetails.tokenAddress = linkDetails.tokenAddress ?? '0x0000000000000000000000000000000000000000' + // TODO: this should be rewritten to be more efficient/clear if (linkDetails.tokenDecimals == undefined || linkDetails.tokenType == undefined) { if ( linkDetails.tokenType == interfaces.EPeanutLinkType.erc20 || @@ -1226,7 +1231,7 @@ async function validateLinkDetails( linkDetails.tokenType == interfaces.EPeanutLinkType.erc1155 ) || linkDetails.tokenDecimals != null, 'tokenDecimals must be provided for ERC20 and ERC1155 tokens' - ) + ) // this can be removed since we do the check at the top for decimals and if ( linkDetails.tokenType !== interfaces.EPeanutLinkType.native &&