events.gno
3.77 Kb · 100 lines
1package memba_market_core
2
3// Frozen cross-engine event schema. Every settlement event an engine emits MUST
4// be built here so name + ordered key set are identical across engines and the
5// indexer/frontend parse one schema. Append "schemaVersion" last on every event.
6// Engines call: chain.Emit(SaleEvent, SaleArgs(...)...).
7
8const SaleEvent = "Sale"
9
10// SaleArgs builds the ONE canonical settlement event for a completed sale, keyed
11// by `via` ("buy" | "offer" | "auction" | "sweep"). Key order matches
12// memba_nft_market_v3.emitSale verbatim, with "schemaVersion" appended, so the
13// existing indexer parses v3 and future engines identically.
14func SaleArgs(via, collection, tokenID, seller, buyer string, price, fee, royalty int64, royaltyRecipient string, sellerAmount int64, denom string) []string {
15 return []string{
16 "via", via,
17 "collection", collection,
18 "tokenId", tokenID,
19 "seller", seller,
20 "buyer", buyer,
21 "price", itoa(price),
22 "fee", itoa(fee),
23 "royalty", itoa(royalty),
24 "royaltyRecipient", royaltyRecipient,
25 "sellerAmount", itoa(sellerAmount),
26 "denom", denom,
27 "schemaVersion", SchemaVersion,
28 }
29}
30
31// ── Offer lifecycle (Phase 2). Accepted offers emit SaleEvent via SaleArgs("offer",…). ──
32// NOTE: The live memba_nft_market_v3 realm already emits OfferMade/OfferCancelled events.
33// Engines using these builders are a DIFFERENT realm (distinct pkg_path) and stamp schemaVersion,
34// so the indexer disambiguates by pkg_path + schemaVersion.
35
36const (
37 OfferMadeEvent = "OfferMade"
38 OfferAcceptedEvent = "OfferAccepted" // reserved; accept emits SaleEvent (via="offer")
39 OfferCancelledEvent = "OfferCancelled"
40)
41
42func OfferMadeArgs(collection, tokenID, buyer string, amount int64, denom string, expiryBlock int64) []string {
43 return []string{
44 "collection", collection, "tokenId", tokenID, "buyer", buyer,
45 "amount", itoa(amount), "denom", denom, "expiryBlock", itoa(expiryBlock),
46 "schemaVersion", SchemaVersion,
47 }
48}
49
50func OfferCancelledArgs(collection, tokenID, buyer string, amount int64) []string {
51 return []string{
52 "collection", collection, "tokenId", tokenID, "buyer", buyer, "amount", itoa(amount),
53 "schemaVersion", SchemaVersion,
54 }
55}
56
57// ── Auction lifecycle (Phase 3). Settled auctions emit SaleEvent via SaleArgs("auction",…). ──
58
59const (
60 AuctionCreatedEvent = "AuctionCreated"
61 BidPlacedEvent = "BidPlaced"
62 BidRefundedEvent = "BidRefunded"
63 AuctionExtendedEvent = "AuctionExtended"
64 AuctionSettledEvent = "AuctionSettled" // reserved; settle emits SaleEvent (via="auction")
65)
66
67func AuctionCreatedArgs(collection, tokenID, seller string, reserve int64, denom string, endBlock int64) []string {
68 return []string{
69 "collection", collection, "tokenId", tokenID, "seller", seller,
70 "reserve", itoa(reserve), "denom", denom, "endBlock", itoa(endBlock),
71 "schemaVersion", SchemaVersion,
72 }
73}
74
75func BidPlacedArgs(collection, tokenID, bidder string, amount int64, denom string, newEndBlock int64) []string {
76 return []string{
77 "collection", collection, "tokenId", tokenID, "bidder", bidder,
78 "amount", itoa(amount), "denom", denom, "newEndBlock", itoa(newEndBlock),
79 "schemaVersion", SchemaVersion,
80 }
81}
82
83func BidRefundedArgs(collection, tokenID, bidder string, amount int64, denom string) []string {
84 return []string{
85 "collection", collection, "tokenId", tokenID, "bidder", bidder,
86 "amount", itoa(amount), "denom", denom,
87 "schemaVersion", SchemaVersion,
88 }
89}
90
91// ── Sweep summary (Phase 2). Each filled unit also emits SaleEvent via SaleArgs("sweep",…). ──
92
93const SweepExecutedEvent = "SweepExecuted"
94
95func SweepExecutedArgs(buyer string, count int, totalSpent int64, denom string) []string {
96 return []string{
97 "buyer", buyer, "count", itoa(int64(count)), "totalSpent", itoa(totalSpent),
98 "denom", denom, "schemaVersion", SchemaVersion,
99 }
100}