Skip to content

Commit dbd813e

Browse files
committed
handle burned case
1 parent b34e7e9 commit dbd813e

File tree

3 files changed

+88
-85
lines changed

3 files changed

+88
-85
lines changed

app/[locale]/10years/_components/CurrentTorchHolderCard.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "@/lib/torch"
2525

2626
interface CurrentTorchHolderCardProps {
27-
currentHolder: TorchHolderMetadata
27+
currentHolder: TorchHolderMetadata | null
2828
className?: string
2929
}
3030

@@ -93,7 +93,15 @@ const CurrentTorchHolderCard = ({
9393
</div>
9494
</div>
9595
) : (
96-
<div className="text-lg">No current holder</div>
96+
<div className="flex flex-col items-center gap-4 text-center">
97+
<div className="text-2xl font-bold text-red-500">
98+
🔥 Torch Burned 🔥
99+
</div>
100+
<div className="text-lg">
101+
The Ethereum Torch has been burned to celebrate the 10-year
102+
anniversary!
103+
</div>
104+
</div>
97105
)}
98106
</CardContent>
99107
<CardFooter className="justify-center pt-4">

app/[locale]/10years/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const Page = async ({ params }: { params: Promise<{ locale: Lang }> }) => {
9797
)
9898

9999
const currentHolderAddress = await getCurrentHolderAddress()
100-
const currentHolder = torchHolderMap[currentHolderAddress.toLowerCase()]
100+
const isBurned =
101+
currentHolderAddress === "0x0000000000000000000000000000000000000000"
102+
const currentHolder = isBurned
103+
? null
104+
: torchHolderMap[currentHolderAddress.toLowerCase()]
101105
const torchHolders = await getHolders(torchHolderMap)
102106

103107
return (

src/lib/torch/index.ts

Lines changed: 73 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import blockies from "ethereum-blockies-base64"
22
import type { Address } from "viem"
3-
import { sepolia } from "viem/chains"
3+
import { hardhat } from "viem/chains"
44
import { createConfig, getPublicClient, http } from "@wagmi/core"
55

66
import Torch from "@/data/Torch.json"
77

88
const TORCH_CONTRACT_ADDRESS = Torch.address as Address
99
const TORCH_ABI = Torch.abi
10+
const TORCH_BLOCK_NUMBER = Torch.blockNumber
1011

1112
export const config = createConfig({
12-
chains: [sepolia],
13+
chains: [hardhat],
1314
transports: {
14-
[sepolia.id]: http(
15-
`https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
16-
),
15+
// [sepolia.id]: http(
16+
// `https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
17+
// ),
18+
[hardhat.id]: http("http://127.0.0.1:8545"),
1719
},
1820
})
1921

@@ -41,82 +43,31 @@ export type TorchHolderEvent = TorchHolder & {
4143
event: TransferEvent
4244
}
4345

44-
const mockLogs = [
45-
{
46-
eventName: "Transfer",
47-
args: {
48-
from: "0x0000000000000000000000000000000000000000",
49-
to: "0x0e972f52C49e353Dc88C9f7F8e200c1cFE0d27b7",
50-
tokenId: BigInt(1),
51-
},
52-
address: "0xbcb60ff26412d7a27dde9b61f0655a207eae80ed",
53-
blockHash:
54-
"0x204c90926c265abbe78d321cbfa2e97a2185aa3804a46cab3960fe15652a90de",
55-
blockNumber: BigInt(8605647),
56-
data: "0x",
57-
logIndex: 121,
58-
removed: false,
59-
topics: [
60-
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
61-
"0x0000000000000000000000000000000000000000000000000000000000000000",
62-
"0x0000000000000000000000000e972f52c49e353dc88c9f7f8e200c1cfe0d27b7",
63-
"0x0000000000000000000000000000000000000000000000000000000000000001",
64-
],
65-
transactionHash:
66-
"0xb549dc9540ec1c1146a5b9b7c6f9d62a207db8d1ebeb049687a74c53239fe323",
67-
transactionIndex: 87,
68-
},
69-
{
70-
eventName: "Transfer",
71-
args: {
72-
from: "0x0e972f52C49e353Dc88C9f7F8e200c1cFE0d27b7",
73-
to: "0x7bc34Ec96a2da5FbC3c0cA0530d989821241516D",
74-
tokenId: BigInt(1),
75-
},
76-
address: "0xbcb60ff26412d7a27dde9b61f0655a207eae80ed",
77-
blockHash:
78-
"0xfc9c50c6a7180a425e92d1774a88ee58dacb92a2a4554a013ec72ef14acfbe98",
79-
blockNumber: BigInt(8610141),
80-
data: "0x",
81-
logIndex: 30,
82-
removed: false,
83-
topics: [
84-
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
85-
"0x0000000000000000000000000e972f52c49e353dc88c9f7f8e200c1cfe0d27b7",
86-
"0x0000000000000000000000007bc34ec96a2da5fbc3c0ca0530d989821241516d",
87-
"0x0000000000000000000000000000000000000000000000000000000000000001",
88-
],
89-
transactionHash:
90-
"0xac1ff7552b6844dfcd46424d7ed6a5bd32316cccd88bc280721f0ece96501219",
91-
transactionIndex: 19,
92-
},
93-
]
94-
9546
export const getTransferEvents = async () => {
9647
const publicClient = getPublicClient(config)
9748

49+
// Get the current block number to ensure consistent results
50+
const currentBlock = await publicClient.getBlockNumber()
51+
9852
// Get Transfer events from the contract
9953
// ERC721 Transfer event signature: Transfer(address indexed from, address indexed to, uint256 indexed tokenId)
100-
// const logs = await publicClient.getLogs({
101-
// address: TORCH_CONTRACT_ADDRESS,
102-
// event: {
103-
// type: "event",
104-
// name: "Transfer",
105-
// inputs: [
106-
// { name: "from", type: "address", indexed: true },
107-
// { name: "to", type: "address", indexed: true },
108-
// { name: "tokenId", type: "uint256", indexed: true },
109-
// ],
110-
// },
111-
// args: {
112-
// tokenId: BigInt(1), // Torch NFT token ID is always 1
113-
// },
114-
// fromBlock: "earliest",
115-
// toBlock: "latest",
116-
// })
117-
118-
// TODO: Remove mock logs
119-
const logs = mockLogs
54+
const logs = await publicClient.getLogs({
55+
address: TORCH_CONTRACT_ADDRESS,
56+
event: {
57+
type: "event",
58+
name: "Transfer",
59+
inputs: [
60+
{ name: "from", type: "address", indexed: true },
61+
{ name: "to", type: "address", indexed: true },
62+
{ name: "tokenId", type: "uint256", indexed: true },
63+
],
64+
},
65+
args: {
66+
tokenId: BigInt(1), // Torch NFT token ID is always 1
67+
},
68+
fromBlock: BigInt(TORCH_BLOCK_NUMBER) || "earliest",
69+
toBlock: currentBlock,
70+
})
12071

12172
// Process logs and get timestamps
12273
const transferEvents: TransferEvent[] = []
@@ -150,8 +101,32 @@ const getHolderEvents = async (
150101
) => {
151102
return transferEvents.map<TorchHolderEvent>((event) => {
152103
const holderMetadata = torchHolderMap[event.to.toLowerCase()]
104+
105+
// If the torch was transferred to the zero address (burned), create a special holder entry
106+
if (event.to === "0x0000000000000000000000000000000000000000") {
107+
return {
108+
address: event.to,
109+
name: "Burned",
110+
role: "Torch has been burned",
111+
twitter: "",
112+
event,
113+
}
114+
}
115+
116+
// If we have metadata for this holder, use it
117+
if (holderMetadata) {
118+
return {
119+
...holderMetadata,
120+
event,
121+
}
122+
}
123+
124+
// If no metadata found, create a fallback entry
153125
return {
154-
...holderMetadata,
126+
address: event.to,
127+
name: `Unknown Holder (${formatAddress(event.to)})`,
128+
role: "Previous torch holder",
129+
twitter: "",
155130
event,
156131
}
157132
})
@@ -166,16 +141,20 @@ export const getHolders = async (
166141
transferEvents
167142
)
168143

169-
return torchHoldersEvents.map((event) => {
170-
return {
171-
...event,
172-
}
173-
})
144+
return torchHoldersEvents
174145
}
175146

176147
export const getCurrentHolderAddress = async () => {
177148
const publicClient = getPublicClient(config)
178149

150+
// First check if the torch is burned
151+
const isBurned = await isTorchBurned()
152+
153+
if (isBurned) {
154+
return "0x0000000000000000000000000000000000000000" as Address
155+
}
156+
157+
// If not burned, get the current holder
179158
const currentHolderAddress = (await publicClient.readContract({
180159
address: TORCH_CONTRACT_ADDRESS,
181160
abi: TORCH_ABI,
@@ -185,6 +164,18 @@ export const getCurrentHolderAddress = async () => {
185164
return currentHolderAddress
186165
}
187166

167+
export const isTorchBurned = async () => {
168+
const publicClient = getPublicClient(config)
169+
170+
const isBurned = (await publicClient.readContract({
171+
address: TORCH_CONTRACT_ADDRESS,
172+
abi: TORCH_ABI,
173+
functionName: "isBurned",
174+
})) as boolean
175+
176+
return isBurned
177+
}
178+
188179
export const getBlockieImage = (address: Address) => {
189180
return blockies(address)
190181
}

0 commit comments

Comments
 (0)