@@ -48,37 +48,36 @@ import * as stakingBalancesContract from '../abis/StakingBalances.sol/StakingBal
4848// ----- autogen:imports:end -----
4949
5050import {
51- AUTH_METHOD_TYPE_VALUES ,
5251 AUTH_METHOD_SCOPE_VALUES ,
53- METAMASK_CHAIN_INFO_BY_NETWORK ,
54- NETWORK_CONTEXT_BY_NETWORK ,
55- LIT_NETWORK_VALUES ,
56- RPC_URL_BY_NETWORK ,
57- HTTP_BY_NETWORK ,
52+ AUTH_METHOD_TYPE_VALUES ,
5853 CENTRALISATION_BY_NETWORK ,
59- LIT_NETWORK ,
6054 HTTP ,
6155 HTTPS ,
56+ HTTP_BY_NETWORK ,
6257 InitError ,
63- NetworkError ,
64- WrongNetworkException ,
65- ParamsMissingError ,
6658 InvalidArgumentException ,
59+ LIT_NETWORK ,
60+ LIT_NETWORK_VALUES ,
61+ METAMASK_CHAIN_INFO_BY_NETWORK ,
62+ NETWORK_CONTEXT_BY_NETWORK ,
63+ ParamsMissingError ,
64+ RPC_URL_BY_NETWORK ,
6765 TransactionError ,
66+ WrongNetworkException ,
6867} from '@lit-protocol/constants' ;
6968import { LogManager , Logger } from '@lit-protocol/logger' ;
69+ import { derivedAddresses } from '@lit-protocol/misc' ;
7070import { TokenInfo } from '@lit-protocol/types' ;
7171import { computeAddress } from 'ethers/lib/utils' ;
7272import { IPubkeyRouter } from '../abis/PKPNFT.sol/PKPNFT' ;
73- import { derivedAddresses } from '@lit-protocol/misc' ;
7473import { getAuthIdByAuthMethod , stringToArrayify } from './auth-utils' ;
7574import {
7675 CIDParser ,
7776 IPFSHash ,
7877 getBytes32FromMultihash ,
7978} from './helpers/getBytes32FromMultihash' ;
80- import { calculateUTCMidnightExpiration , requestsToKilosecond } from './utils' ;
8179import { ValidatorStruct } from './types' ;
80+ import { calculateUTCMidnightExpiration , requestsToKilosecond } from './utils' ;
8281
8382// const DEFAULT_RPC = 'https://lit-protocol.calderachain.xyz/replica-http';
8483// const DEFAULT_READ_RPC = 'https://lit-protocol.calderachain.xyz/replica-http';
@@ -748,7 +747,8 @@ export class LitContracts {
748747 ) : Promise < string > {
749748 let address : string = '' ;
750749 switch ( contract ) {
751- case 'Allowlist' || 'AllowList' :
750+ case 'Allowlist' :
751+ case 'AllowList' :
752752 address = await resolverContract [ 'getContract' ] (
753753 await resolverContract [ 'ALLOWLIST_CONTRACT' ] ( ) ,
754754 environment
@@ -2870,6 +2870,106 @@ https://developer.litprotocol.com/v3/sdk/wallets/auth-methods/#auth-method-scope
28702870
28712871 return tx ;
28722872 } ,
2873+ /**
2874+ * Prune expired Capacity Credits NFT (RLI) tokens for a specified owner address.
2875+ * This function burns all expired RLI tokens owned by the target address, helping to clean up the blockchain.
2876+ * Anyone can call this function to prune expired tokens for any address.
2877+ *
2878+ * @param {string } ownerAddress - The address of the owner to prune expired tokens for.
2879+ * @returns {Promise<PruneExpiredCapacityCreditsRes> } - A promise that resolves to the pruning response with transaction details.
2880+ * @throws {Error } - If the input parameters are invalid or an error occurs during the pruning process.
2881+ */
2882+ pruneExpired : async (
2883+ ownerAddress : string
2884+ ) : Promise < {
2885+ txHash : string ;
2886+ actualTokensBurned : number ;
2887+ } > => {
2888+ this . log ( 'Pruning expired Capacity Credits NFTs...' ) ;
2889+
2890+ // Validate input: ownerAddress must be a valid Ethereum address
2891+ if ( ! ownerAddress || ! ethers . utils . isAddress ( ownerAddress ) ) {
2892+ throw new InvalidArgumentException (
2893+ {
2894+ info : {
2895+ ownerAddress,
2896+ } ,
2897+ } ,
2898+ `A valid owner address is required to prune expired tokens`
2899+ ) ;
2900+ }
2901+
2902+ this . log ( `Target owner address: ${ ownerAddress } ` ) ;
2903+
2904+ try {
2905+ // Hardcoded ABI for pruneExpired function
2906+ const pruneExpiredABI = [
2907+ {
2908+ inputs : [
2909+ {
2910+ internalType : 'address' ,
2911+ name : 'owner' ,
2912+ type : 'address' ,
2913+ } ,
2914+ ] ,
2915+ name : 'pruneExpired' ,
2916+ outputs : [ ] ,
2917+ stateMutability : 'nonpayable' ,
2918+ type : 'function' ,
2919+ } ,
2920+ ] ;
2921+
2922+ // Create contract instance with the hardcoded ABI
2923+ const contractAddress = this . rateLimitNftContract . read . address ;
2924+ const contract = new ethers . Contract (
2925+ contractAddress ,
2926+ pruneExpiredABI ,
2927+ this . signer
2928+ ) ;
2929+
2930+ // Call the pruneExpired function
2931+ const res = await contract [ 'pruneExpired' ] ( ownerAddress ) ;
2932+
2933+ const txHash = res . hash ;
2934+ this . log ( `Prune transaction submitted: ${ txHash } ` ) ;
2935+
2936+ const tx = await res . wait ( ) ;
2937+ this . log ( 'Prune transaction confirmed:' , tx ) ;
2938+
2939+ // Count the burned tokens from Transfer events (transfers to zero address)
2940+ const burnEvents = tx . logs . filter ( ( log : any ) => {
2941+ try {
2942+ const parsedLog =
2943+ this . rateLimitNftContract . read . interface . parseLog ( log ) ;
2944+ return (
2945+ parsedLog . name === 'Transfer' &&
2946+ parsedLog . args [ 'to' ] === ethers . constants . AddressZero
2947+ ) ;
2948+ } catch {
2949+ return false ;
2950+ }
2951+ } ) ;
2952+
2953+ const actualTokensBurned = burnEvents . length ;
2954+ this . log ( `Successfully burned ${ actualTokensBurned } expired tokens` ) ;
2955+ this . log ( `Gas used: ${ tx . gasUsed . toString ( ) } ` ) ;
2956+
2957+ return {
2958+ txHash,
2959+ actualTokensBurned,
2960+ } ;
2961+ } catch ( e ) {
2962+ throw new TransactionError (
2963+ {
2964+ info : {
2965+ ownerAddress,
2966+ } ,
2967+ cause : e ,
2968+ } ,
2969+ 'Pruning expired capacity credits NFTs failed'
2970+ ) ;
2971+ }
2972+ } ,
28732973 } ,
28742974 } ;
28752975
0 commit comments