@@ -6,10 +6,10 @@ import { getPublicClient } from "@wagmi/core"
6
6
import Torch from "@/data/Torch.json"
7
7
8
8
import { config } from "./config"
9
+ import { fetchTorchTransfersFromEtherscan } from "./etherscan"
9
10
10
11
const TORCH_CONTRACT_ADDRESS = Torch . address as Address
11
12
const TORCH_ABI = Torch . abi
12
- const TORCH_BLOCK_NUMBER = Torch . blockNumber
13
13
14
14
// Addresses to filter from the UI (show as "Unknown Holder")
15
15
const FILTERED_ADDRESSES : string [ ] = [
@@ -50,54 +50,7 @@ export type TorchHolderEvent = TorchHolder & {
50
50
51
51
export const getTransferEvents = cache (
52
52
async ( ) => {
53
- const publicClient = getPublicClient ( config )
54
-
55
- // Get the current block number to ensure consistent results
56
- const currentBlock = await publicClient . getBlockNumber ( )
57
-
58
- // Get Transfer events from the contract
59
- // ERC721 Transfer event signature: Transfer(address indexed from, address indexed to, uint256 indexed tokenId)
60
- const logs = await publicClient . getLogs ( {
61
- address : TORCH_CONTRACT_ADDRESS ,
62
- event : {
63
- type : "event" ,
64
- name : "Transfer" ,
65
- inputs : [
66
- { name : "from" , type : "address" , indexed : true } ,
67
- { name : "to" , type : "address" , indexed : true } ,
68
- { name : "tokenId" , type : "uint256" , indexed : true } ,
69
- ] ,
70
- } ,
71
- args : {
72
- tokenId : BigInt ( 1 ) , // Torch NFT token ID is always 1
73
- } ,
74
- fromBlock : BigInt ( TORCH_BLOCK_NUMBER ) || "earliest" ,
75
- toBlock : currentBlock ,
76
- } )
77
-
78
- // Process logs and get timestamps
79
- const transferEvents : TransferEvent [ ] = [ ]
80
-
81
- for ( const log of logs ) {
82
- if ( log . args ?. from && log . args ?. to ) {
83
- // Get block details to get timestamp
84
- const block = await publicClient . getBlock ( {
85
- blockNumber : log . blockNumber ,
86
- } )
87
-
88
- transferEvents . push ( {
89
- from : log . args . from as Address ,
90
- to : log . args . to as Address ,
91
- blockNumber : Number ( log . blockNumber ) ,
92
- transactionHash : log . transactionHash ,
93
- timestamp : Number ( block . timestamp ) ,
94
- } )
95
- }
96
- }
97
-
98
- // Sort by block number (oldest first)
99
- transferEvents . sort ( ( a , b ) => a . blockNumber - b . blockNumber )
100
-
53
+ const transferEvents = await fetchTorchTransfersFromEtherscan ( )
101
54
return transferEvents
102
55
} ,
103
56
[ "torch-transfer-events" ] ,
0 commit comments