@@ -243,6 +243,45 @@ function getContractAddress(chainId: string, version: string) {
243243 return contractAddress
244244}
245245
246+ function getContractAbi ( version : string ) : any {
247+ let contractAbi : any
248+ switch ( version ) {
249+ case 'v4' :
250+ contractAbi = PEANUT_ABI_V4
251+ break
252+ case 'v4.2' :
253+ contractAbi = PEANUT_ABI_V4_2
254+ break
255+ case 'v4.3' :
256+ contractAbi = PEANUT_ABI_V4_3
257+ break
258+ case 'v4.4' :
259+ contractAbi = PEANUT_ABI_V4_4
260+ break
261+ case 'Bv4' :
262+ contractAbi = PEANUT_BATCHER_ABI_V4
263+ break
264+ case 'Bv4.3' :
265+ contractAbi = PEANUT_BATCHER_ABI_V4_3
266+ break
267+ case 'Bv4.4' :
268+ contractAbi = PEANUT_BATCHER_ABI_V4_4
269+ break
270+ case 'Bv4.2' :
271+ contractAbi = PEANUT_BATCHER_ABI_V4_2
272+ break
273+ case 'Rv4.2' :
274+ contractAbi = PEANUT_ROUTER_ABI_V4_2
275+ break
276+ case 'Rv4.3' :
277+ contractAbi = PEANUT_ABI_V4_3
278+ break
279+ default :
280+ throw new Error ( 'Unable to find Peanut contract for this version, check for correct version or updated SDK' )
281+ }
282+ return contractAbi
283+ }
284+
246285async function getContract ( chainId : string , signerOrProvider : any , version = null ) {
247286 if ( signerOrProvider == null ) {
248287 config . verbose && console . log ( 'signerOrProvider is null, getting default provider...' )
@@ -2008,6 +2047,94 @@ async function getLinkDetails({ link, provider }: interfaces.IGetLinkDetailsPara
20082047 }
20092048}
20102049
2050+ /**
2051+ * Gets the details of a Link: what token it is, how much it holds, etc.
2052+ */
2053+ function extractLinkDetails ( { params, deposit, tokenDetails } : any ) {
2054+ let tokenAddress = deposit . tokenAddress
2055+ const tokenType = deposit . contractType
2056+ const senderAddress = deposit . senderAddress
2057+
2058+ let claimed = false
2059+ if ( [ 'v2' , 'v4' ] . includes ( params . contractVersion ) ) {
2060+ if ( deposit . pubKey20 == '0x0000000000000000000000000000000000000000' ) {
2061+ claimed = true
2062+ }
2063+ config . verbose && console . log ( 'Pre-4.2 claim checking behaviour, claimed:' , claimed )
2064+ } else {
2065+ // v4.2+
2066+ claimed = deposit . claimed
2067+ config . verbose && console . log ( 'v4.2+ claim checking behaviour, claimed:' , claimed )
2068+ }
2069+
2070+ let depositDate : Date | null = null
2071+ if ( VAULT_CONTRACTS_V4_ANDUP . includes ( params . contractVersion ) ) {
2072+ if ( deposit . timestamp ) {
2073+ depositDate = new Date ( deposit . timestamp * 1000 )
2074+ if ( deposit . timestamp == 0 ) {
2075+ depositDate = null
2076+ }
2077+ } else {
2078+ config . verbose && console . log ( 'No timestamp found in deposit for version' , params . contractVersion )
2079+ }
2080+ }
2081+
2082+ let tokenAmount = '0'
2083+ let tokenDecimals = null
2084+ let symbol = null
2085+ let name = null
2086+ let tokenURI = null
2087+ let metadata = null
2088+
2089+ if ( tokenType == interfaces . EPeanutLinkType . native ) {
2090+ config . verbose && console . log ( 'tokenType is 0, setting tokenAddress to zero address' )
2091+ tokenAddress = ethers . constants . AddressZero
2092+ }
2093+ if ( tokenType == interfaces . EPeanutLinkType . native || tokenType == interfaces . EPeanutLinkType . erc20 ) {
2094+ config . verbose &&
2095+ console . log ( 'finding token details for token with address: ' , tokenAddress , ' on chain: ' , params . chainId )
2096+ const chainDetails = TOKEN_DETAILS . find ( ( chain ) => chain . chainId === params . chainId )
2097+ if ( ! chainDetails ) {
2098+ throw new Error ( "Couldn't find details for this token" )
2099+ }
2100+
2101+ symbol = tokenDetails . symbol
2102+ name = tokenDetails . name
2103+ tokenDecimals = tokenDetails . decimals
2104+ tokenAmount = ethers . utils . formatUnits ( deposit . amount , tokenDecimals )
2105+ }
2106+
2107+ // format deposit to string values
2108+ const depositCopy = { }
2109+ for ( const key in deposit ) {
2110+ if ( isNaN ( Number ( key ) ) ) {
2111+ // Only copy named properties
2112+ depositCopy [ key ] = deposit [ key ] . toString ( )
2113+ }
2114+ }
2115+
2116+ return {
2117+ chainId : params . chainId ,
2118+ depositIndex : params . depositIdx ,
2119+ contractVersion : params . contractVersion ,
2120+ senderAddress : senderAddress ,
2121+ tokenType : deposit . contractType ,
2122+ tokenAddress : deposit . tokenAddress ,
2123+ tokenDecimals : tokenDecimals ,
2124+ tokenSymbol : symbol ,
2125+ tokenName : name ,
2126+ tokenAmount : tokenAmount ,
2127+ tokenId : ethers . BigNumber . from ( deposit . tokenId ) . toNumber ( ) ,
2128+ claimed : claimed ,
2129+ depositDate : depositDate ,
2130+ tokenURI : tokenURI ,
2131+ metadata : metadata ,
2132+ rawOnchainDepositInfo : depositCopy ,
2133+ recipient : deposit . recipient ,
2134+ reclaimableAfter : deposit . reclaimableAfter ,
2135+ }
2136+ }
2137+
20112138async function resolveToENSName ( {
20122139 address,
20132140 provider = null ,
@@ -3082,13 +3209,15 @@ const peanut = {
30823209 getAllUnclaimedDepositsWithIdxForAddress,
30833210 getContract,
30843211 getContractAddress,
3212+ getContractAbi,
30853213 getDefaultProvider,
30863214 getDefaultProviderUrl,
30873215 getDepositIdx,
30883216 getDepositIdxs,
30893217 getEIP1559Tip,
30903218 getLatestContractVersion,
30913219 getLinkDetails,
3220+ extractLinkDetails,
30923221 getLinkFromParams,
30933222 getLinksFromMultilink,
30943223 isShortenedLink,
@@ -3187,13 +3316,15 @@ export {
31873316 getAllUnclaimedDepositsWithIdxForAddress ,
31883317 getContract ,
31893318 getContractAddress ,
3319+ getContractAbi ,
31903320 getDefaultProvider ,
31913321 getDefaultProviderUrl ,
31923322 getDepositIdx ,
31933323 getDepositIdxs ,
31943324 getEIP1559Tip ,
31953325 getLatestContractVersion ,
31963326 getLinkDetails ,
3327+ extractLinkDetails ,
31973328 getLinkFromParams ,
31983329 getLinksFromMultilink ,
31993330 isShortenedLink ,
0 commit comments