generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
513 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,8 @@ node_modules | |
.vscode | ||
.idea | ||
.vercel | ||
|
||
graph-node | ||
data | ||
bin | ||
types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
{ | ||
"sepolia": { | ||
"LoogieAuction": { | ||
"address": "0x210b3B8cc13720cCbb8208Ab4d328Ff488E49112", | ||
"startBlock": 5539160 | ||
}, | ||
"Loogie": { | ||
"address": "0x83296AFF01553E6386fAe17d50118E0659f82678" | ||
}, | ||
"WETH": { | ||
"address": "0xf7d541135a61b54BD2F79acD7cB1b2223dC9EB8F" | ||
} | ||
}, | ||
"localhost": { | ||
"YourContract": { | ||
"Loogie": { | ||
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3" | ||
}, | ||
"LoogieAuction": { | ||
"address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" | ||
}, | ||
"WETH": { | ||
"address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,149 @@ | ||
import { BigInt, Address } from "@graphprotocol/graph-ts"; | ||
import { LoogieCreated, Transfer } from "./types/Loogie/Loogie"; | ||
import { Loogie, TransferEvent, Bid, Auction, Account } from "./types/schema"; | ||
import { getOrCreateAccount } from "./util/helper"; | ||
import { | ||
YourContract, | ||
GreetingChange, | ||
} from "../generated/YourContract/YourContract"; | ||
import { Greeting, Sender } from "../generated/schema"; | ||
|
||
export function handleGreetingChange(event: GreetingChange): void { | ||
let senderString = event.params.greetingSetter.toHexString(); | ||
|
||
let sender = Sender.load(senderString); | ||
|
||
if (sender === null) { | ||
sender = new Sender(senderString); | ||
sender.address = event.params.greetingSetter; | ||
sender.createdAt = event.block.timestamp; | ||
sender.greetingCount = BigInt.fromI32(1); | ||
} else { | ||
sender.greetingCount = sender.greetingCount.plus(BigInt.fromI32(1)); | ||
AuctionBid, | ||
AuctionCreated, | ||
AuctionExtended, | ||
AuctionSettled, | ||
} from "./types/LoogieAuction/LoogieAuction"; | ||
import { log } from "@graphprotocol/graph-ts"; | ||
|
||
export function handleCreatedLoogie(event: LoogieCreated): void { | ||
let loogieId = event.params.tokenId.toString(); | ||
|
||
let loogie = Loogie.load(loogieId); | ||
if (loogie == null) { | ||
log.critical("[handleCreatedLoogie] Loogie #{} not found. Hash: {}", [ | ||
loogieId, | ||
event.transaction.hash.toHex(), | ||
]); | ||
return; | ||
} | ||
loogie.chubbiness = event.params.chubbiness; | ||
loogie.color = event.params.color; | ||
loogie.mouthLength = event.params.mouthLength; | ||
loogie.save(); | ||
} | ||
export function handleTransfer(event: Transfer): void { | ||
// Get the sender and receiver accounts | ||
let fromAccount = getOrCreateAccount(event.params.from.toHexString()); | ||
let toAccount = getOrCreateAccount(event.params.to.toHexString()); | ||
|
||
// Get the transferred Loogie ID | ||
let transferredLoogieId = event.params.tokenId.toString(); | ||
|
||
// Load the Loogie entity | ||
let loogie = Loogie.load(transferredLoogieId); | ||
|
||
// Check if the Loogie exists | ||
if (loogie == null) { | ||
log.error("[handleTransfer] Loogie #{} not found. Hash: {}", [ | ||
transferredLoogieId, | ||
event.transaction.hash.toHex(), | ||
]); | ||
return; | ||
} | ||
|
||
let greeting = new Greeting( | ||
event.transaction.hash.toHex() + "-" + event.logIndex.toString() | ||
// Update ownership status | ||
loogie.owner = toAccount.id; | ||
|
||
// Save changes to the Loogie entity | ||
loogie.save(); | ||
|
||
// Create a new TransferEvent entity | ||
let transferEvent = new TransferEvent( | ||
event.transaction.hash.toHexString() + "_" + transferredLoogieId | ||
); | ||
transferEvent.blockNumber = event.block.number; | ||
transferEvent.blockTimestamp = event.block.timestamp; | ||
transferEvent.loogie = transferredLoogieId; | ||
transferEvent.previousHolder = fromAccount.id; | ||
transferEvent.newHolder = toAccount.id; | ||
transferEvent.save(); | ||
} | ||
|
||
export function handleAuctionCreated(event: AuctionCreated): void { | ||
const loogieId = event.params.loogieId.toString(); | ||
|
||
let loogie = Loogie.load(loogieId); | ||
if (loogie == null) { | ||
log.error("[handleAuctionCreated] Loogie #{} not found. Hash: {}", [ | ||
loogieId, | ||
event.transaction.hash.toHex(), | ||
]); | ||
return; | ||
} | ||
|
||
let auction = new Auction(loogieId); | ||
auction.loogie = loogie.id; | ||
auction.amount = BigInt.fromI32(0); | ||
auction.startTime = event.params.startTime; | ||
auction.endTime = event.params.endTime; | ||
auction.settled = false; | ||
auction.save(); | ||
} | ||
|
||
greeting.greeting = event.params.newGreeting; | ||
greeting.sender = senderString; | ||
greeting.premium = event.params.premium; | ||
greeting.value = event.params.value; | ||
greeting.createdAt = event.block.timestamp; | ||
greeting.transactionHash = event.transaction.hash.toHex(); | ||
export function handleAuctionBid(event: AuctionBid): void { | ||
let loogieId = event.params.loogieId.toString(); | ||
let bidderAddress = event.params.sender.toHex(); | ||
|
||
let bidder = getOrCreateAccount(bidderAddress); | ||
|
||
let auction = Auction.load(loogieId); | ||
if (auction == null) { | ||
log.error("[handleAuctionBid] Auction not found for Loogie #{}. Hash: {}", [ | ||
loogieId, | ||
event.transaction.hash.toHex(), | ||
]); | ||
return; | ||
} | ||
|
||
auction.amount = event.params.value; | ||
auction.bidder = bidder.id; | ||
auction.save(); | ||
|
||
// Save Bid | ||
let bid = new Bid(event.transaction.hash.toHex()); | ||
bid.bidder = bidder.id; | ||
bid.amount = auction.amount; | ||
bid.loogie = auction.loogie; | ||
bid.txIndex = event.transaction.index; | ||
bid.blockNumber = event.block.number; | ||
bid.blockTimestamp = event.block.timestamp; | ||
bid.auction = auction.id; | ||
bid.save(); | ||
} | ||
|
||
export function handleAuctionExtended(event: AuctionExtended): void { | ||
let loogieId = event.params.loogieId.toString(); | ||
|
||
let auction = Auction.load(loogieId); | ||
if (auction == null) { | ||
log.error( | ||
"[handleAuctionExtended] Auction not found for Loogie #{}. Hash: {}", | ||
[loogieId, event.transaction.hash.toHex()] | ||
); | ||
return; | ||
} | ||
|
||
auction.endTime = event.params.endTime; | ||
auction.save(); | ||
} | ||
|
||
export function handleAuctionSettled(event: AuctionSettled): void { | ||
let loogieId = event.params.loogieId.toString(); | ||
|
||
let auction = Auction.load(loogieId); | ||
if (auction == null) { | ||
log.error( | ||
"[handleAuctionSettled] Auction not found for Noun #{}. Hash: {}", | ||
[loogieId, event.transaction.hash.toHex()] | ||
); | ||
return; | ||
} | ||
|
||
greeting.save(); | ||
sender.save(); | ||
auction.settled = true; | ||
auction.save(); | ||
} |
Oops, something went wrong.