-
Notifications
You must be signed in to change notification settings - Fork 33
/
topics.go
105 lines (80 loc) · 3.19 KB
/
topics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package bridge
import (
"bytes"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/services/explorer/types/bridge"
"strings"
)
func init() {
var err error
parsedBridge, err := abi.JSON(strings.NewReader(SynapseBridgeMetaData.ABI))
if err != nil {
panic(err)
}
// we do this here to throw a compile error if the event is not found
DepositTopic = parsedBridge.Events["TokenDeposit"].ID
RedeemTopic = parsedBridge.Events["TokenRedeem"].ID
WithdrawTopic = parsedBridge.Events["TokenWithdraw"].ID
MintTopic = parsedBridge.Events["TokenMint"].ID
DepositAndSwapTopic = parsedBridge.Events["TokenDepositAndSwap"].ID
RedeemAndSwapTopic = parsedBridge.Events["TokenRedeemAndSwap"].ID
RedeemAndRemoveTopic = parsedBridge.Events["TokenRedeemAndRemove"].ID
MintAndSwapTopic = parsedBridge.Events["TokenMintAndSwap"].ID
WithdrawAndRemoveTopic = parsedBridge.Events["TokenWithdrawAndRemove"].ID
RedeemV2Topic = parsedBridge.Events["TokenRedeemV2"].ID
}
// DepositTopic is the topic used for token deposits.
var DepositTopic common.Hash
// RedeemTopic is the topic used for token redeems.
var RedeemTopic common.Hash
// WithdrawTopic is the topic used for token withdraws (called by bridge).
var WithdrawTopic common.Hash
// MintTopic is the topic used for token mints (called by bridge).
var MintTopic common.Hash
// DepositAndSwapTopic is the topic used for token deposits->swaps.
var DepositAndSwapTopic common.Hash
// RedeemAndSwapTopic is the topic used for redeems->swaps.
var RedeemAndSwapTopic common.Hash
// RedeemAndRemoveTopic is the topic used for redeems->swaps/burn.
var RedeemAndRemoveTopic common.Hash
// MintAndSwapTopic is the topic used for mint and swaps (called by bridge).
var MintAndSwapTopic common.Hash
// WithdrawAndRemoveTopic is the topic used for withdraw and removes (called by bridge).
var WithdrawAndRemoveTopic common.Hash
// RedeemV2Topic is the topic used for redeems to a non-evm chain.
var RedeemV2Topic common.Hash
// TopicMap maps events to topics.
// this is returned as a function to assert immutability.
func TopicMap() map[bridge.EventType]common.Hash {
return map[bridge.EventType]common.Hash{
bridge.DepositEvent: DepositTopic,
bridge.RedeemEvent: RedeemTopic,
bridge.WithdrawEvent: WithdrawTopic,
bridge.MintEvent: MintTopic,
bridge.DepositAndSwapEvent: DepositAndSwapTopic,
bridge.MintAndSwapEvent: MintAndSwapTopic,
bridge.RedeemAndSwapEvent: RedeemAndSwapTopic,
bridge.RedeemAndRemoveEvent: RedeemAndRemoveTopic,
bridge.WithdrawAndRemoveEvent: WithdrawAndRemoveTopic,
bridge.RedeemV2Event: RedeemV2Topic,
}
}
// EventTypeFromTopic gets the event type from the topic
// returns nil if the topic is not found.
func EventTypeFromTopic(ogTopic common.Hash) *bridge.EventType {
for eventType, topic := range TopicMap() {
if bytes.Equal(ogTopic.Bytes(), topic.Bytes()) {
return &eventType
}
}
return nil
}
// Topic gets the topic from the event type.
func Topic(eventType bridge.EventType) common.Hash {
topicHash, ok := TopicMap()[bridge.EventType(eventType.Int())]
if !ok {
panic("unknown event")
}
return topicHash
}