@@ -14,18 +14,27 @@ import {
14
14
FixedRateExchangeSwap ,
15
15
FixedRateExchangeUpdate
16
16
} from '../@types/schema'
17
- import { getFixedRateExchange , getUpdateOrSwapId } from './utils/fixedRateUtils'
17
+ import {
18
+ getFixedRateExchange ,
19
+ getUpdateOrSwapId ,
20
+ getFixedRateGraphID ,
21
+ updateFixedRateExchangeSupply
22
+ } from './utils/fixedRateUtils'
18
23
import { weiToDecimal } from './utils/generic'
19
24
import { addFixedRateExchange } from './utils/globalUtils'
20
25
import { getToken } from './utils/tokenUtils'
21
26
import { getUser } from './utils/userUtils'
22
27
23
28
export function handleExchangeCreated ( event : ExchangeCreated ) : void {
24
- const fixedRateExchange = new FixedRateExchange (
25
- event . params . exchangeId . toHexString ( )
29
+ const fixedRateId = getFixedRateGraphID (
30
+ event . params . exchangeId . toHexString ( ) ,
31
+ event . address
26
32
)
33
+ const fixedRateExchange = new FixedRateExchange ( fixedRateId )
27
34
const user = getUser ( event . params . exchangeOwner . toHexString ( ) )
28
35
fixedRateExchange . owner = user . id
36
+ fixedRateExchange . contract = event . address . toHexString ( )
37
+ fixedRateExchange . exchangeId = event . params . exchangeId . toHexString ( )
29
38
fixedRateExchange . datatoken = getToken ( event . params . datatoken , true ) . id
30
39
fixedRateExchange . baseToken = getToken ( event . params . baseToken , false ) . id
31
40
@@ -40,17 +49,18 @@ export function handleExchangeCreated(event: ExchangeCreated): void {
40
49
fixedRateExchange . save ( )
41
50
42
51
addFixedRateExchange ( )
52
+ updateFixedRateExchangeSupply ( event . params . exchangeId , event . address )
43
53
}
44
54
45
55
export function handleRateChange ( event : ExchangeRateChanged ) : void {
46
- const fixedRateExchange = getFixedRateExchange (
47
- event . params . exchangeId . toHex ( )
56
+ const fixedRateId = getFixedRateGraphID (
57
+ event . params . exchangeId . toHexString ( ) ,
58
+ event . address
48
59
)
60
+
61
+ const fixedRateExchange = getFixedRateExchange ( fixedRateId )
49
62
const newExchangeUpdate = new FixedRateExchangeUpdate (
50
- getUpdateOrSwapId (
51
- event . transaction . hash . toHex ( ) ,
52
- event . params . exchangeId . toHex ( )
53
- )
63
+ getUpdateOrSwapId ( event . transaction . hash . toHex ( ) , fixedRateId )
54
64
)
55
65
newExchangeUpdate . oldPrice = fixedRateExchange . price
56
66
newExchangeUpdate . createdTimestamp = event . block . timestamp . toI32 ( )
@@ -68,24 +78,25 @@ export function handleRateChange(event: ExchangeRateChanged): void {
68
78
}
69
79
70
80
export function handleMintStateChanged ( event : ExchangeMintStateChanged ) : void {
71
- const fixedRateExchange = getFixedRateExchange (
72
- event . params . exchangeId . toHex ( )
81
+ const fixedRateId = getFixedRateGraphID (
82
+ event . params . exchangeId . toHexString ( ) ,
83
+ event . address
73
84
)
85
+ const fixedRateExchange = getFixedRateExchange ( fixedRateId )
74
86
fixedRateExchange . withMint = event . params . withMint
75
87
fixedRateExchange . save ( )
76
88
}
77
89
78
90
// TODO: implement fre updates/history for changes
79
91
80
92
export function handleActivated ( event : ExchangeActivated ) : void {
81
- const fixedRateExchange = getFixedRateExchange (
82
- event . params . exchangeId . toHex ( )
93
+ const fixedRateId = getFixedRateGraphID (
94
+ event . params . exchangeId . toHexString ( ) ,
95
+ event . address
83
96
)
97
+ const fixedRateExchange = getFixedRateExchange ( fixedRateId )
84
98
const newExchangeUpdate = new FixedRateExchangeUpdate (
85
- getUpdateOrSwapId (
86
- event . transaction . hash . toHex ( ) ,
87
- event . params . exchangeId . toHex ( )
88
- )
99
+ getUpdateOrSwapId ( event . transaction . hash . toHex ( ) , fixedRateId )
89
100
)
90
101
newExchangeUpdate . oldActive = fixedRateExchange . active
91
102
newExchangeUpdate . newActive = true
@@ -100,14 +111,13 @@ export function handleActivated(event: ExchangeActivated): void {
100
111
}
101
112
102
113
export function handleDeactivated ( event : ExchangeDeactivated ) : void {
103
- const fixedRateExchange = getFixedRateExchange (
104
- event . params . exchangeId . toHex ( )
114
+ const fixedRateId = getFixedRateGraphID (
115
+ event . params . exchangeId . toHexString ( ) ,
116
+ event . address
105
117
)
118
+ const fixedRateExchange = getFixedRateExchange ( fixedRateId )
106
119
const newExchangeUpdate = new FixedRateExchangeUpdate (
107
- getUpdateOrSwapId (
108
- event . transaction . hash . toHex ( ) ,
109
- event . params . exchangeId . toHex ( )
110
- )
120
+ getUpdateOrSwapId ( event . transaction . hash . toHex ( ) , fixedRateId )
111
121
)
112
122
newExchangeUpdate . oldActive = fixedRateExchange . active
113
123
newExchangeUpdate . newActive = false
@@ -124,14 +134,13 @@ export function handleDeactivated(event: ExchangeDeactivated): void {
124
134
export function handleAllowedSwapperChanged (
125
135
event : ExchangeAllowedSwapperChanged
126
136
) : void {
127
- const fixedRateExchange = getFixedRateExchange (
128
- event . params . exchangeId . toHex ( )
137
+ const fixedRateId = getFixedRateGraphID (
138
+ event . params . exchangeId . toHexString ( ) ,
139
+ event . address
129
140
)
141
+ const fixedRateExchange = getFixedRateExchange ( fixedRateId )
130
142
const newExchangeUpdate = new FixedRateExchangeUpdate (
131
- getUpdateOrSwapId (
132
- event . transaction . hash . toHex ( ) ,
133
- event . params . exchangeId . toHex ( )
134
- )
143
+ getUpdateOrSwapId ( event . transaction . hash . toHex ( ) , fixedRateId )
135
144
)
136
145
137
146
newExchangeUpdate . createdTimestamp = event . block . timestamp . toI32 ( )
@@ -147,21 +156,20 @@ export function handleAllowedSwapperChanged(
147
156
148
157
// TODO: implement market fee, opf fee
149
158
export function handleSwap ( event : Swapped ) : void {
150
- const fixedRateExchange = getFixedRateExchange (
151
- event . params . exchangeId . toHex ( )
159
+ const fixedRateId = getFixedRateGraphID (
160
+ event . params . exchangeId . toHexString ( ) ,
161
+ event . address
152
162
)
163
+ const fixedRateExchange = getFixedRateExchange ( fixedRateId )
153
164
154
165
const swap = new FixedRateExchangeSwap (
155
- getUpdateOrSwapId (
156
- event . transaction . hash . toHex ( ) ,
157
- event . params . exchangeId . toHex ( )
158
- )
166
+ getUpdateOrSwapId ( event . transaction . hash . toHex ( ) , fixedRateId )
159
167
)
160
168
swap . createdTimestamp = event . block . timestamp . toI32 ( )
161
169
swap . tx = event . transaction . hash . toHex ( )
162
170
swap . block = event . block . number . toI32 ( )
163
171
164
- swap . exchangeId = event . params . exchangeId . toHex ( )
172
+ swap . exchangeId = fixedRateId
165
173
swap . by = getUser ( event . params . by . toHex ( ) ) . id
166
174
167
175
// we need to fetch the decimals of the base token
@@ -179,14 +187,17 @@ export function handleSwap(event: Swapped): void {
179
187
)
180
188
181
189
swap . save ( )
190
+ updateFixedRateExchangeSupply ( event . params . exchangeId , event . address )
182
191
}
183
192
184
193
export function handlePublishMarketFeeChanged (
185
194
event : PublishMarketFeeChanged
186
195
) : void {
187
- const fixedRateExchange = getFixedRateExchange (
188
- event . params . exchangeId . toHex ( )
196
+ const fixedRateId = getFixedRateGraphID (
197
+ event . params . exchangeId . toHexString ( ) ,
198
+ event . address
189
199
)
200
+ const fixedRateExchange = getFixedRateExchange ( fixedRateId )
190
201
if ( fixedRateExchange ) {
191
202
fixedRateExchange . publishMarketFeeAddress =
192
203
event . params . newMarketCollector . toHexString ( )
0 commit comments