emits.gno
4.69 Kb · 119 lines
1package impl
2
3import (
4 "chain"
5
6 plimit "gno.land/p/gnoswap/order/limit/v0"
7 "gno.land/p/gnoswap/utils/v1"
8)
9
10func emitOrderCreated(prevAddr address, prevRealm string, order *plimit.Order, baseToken string) {
11 chain.Emit(
12 "LimitOrderCreated",
13 "prevAddr", prevAddr.String(), "prevRealm", prevRealm,
14 "owner", order.Owner().String(), "orderId", utils.FormatUint(order.ID()),
15 "tokenIn", order.TokenIn(), "tokenOut", order.TokenOut(),
16 "baseToken", baseToken,
17 "makingAmount", utils.FormatInt(order.MakingAmount()), "takingAmount", utils.FormatInt(order.TakingAmount()),
18 "slippageBps", utils.FormatInt(order.SlippageBps()),
19 "createdAt", utils.FormatInt(order.CreatedAt()), "expiresAt", utils.FormatInt(order.ExpiresAt()),
20 "executionFeeRate", utils.FormatInt(order.ExecutionFeeRate()),
21 )
22}
23
24func emitOrderFilled(prevAddr address, prevRealm string, order *plimit.Order, route string, amountIn, poolOutput, executionFee int64) {
25 chain.Emit(
26 "LimitOrderFilled",
27 "prevAddr", prevAddr.String(), "prevRealm", prevRealm,
28 "owner", order.Owner().String(), "orderId", utils.FormatUint(order.ID()),
29 "route", route,
30 "tokenIn", order.TokenIn(), "tokenOut", order.TokenOut(),
31 "amountIn", utils.FormatInt(amountIn), "poolOutput", utils.FormatInt(poolOutput),
32 "userOutput", utils.FormatInt(poolOutput-executionFee), "executionFee", utils.FormatInt(executionFee),
33 "filledInput", utils.FormatInt(order.FilledInput()), "remainingInput", utils.FormatInt(order.RemainingInput()),
34 "refundedInput", utils.FormatInt(order.RefundedInput()),
35 "grossOutput", utils.FormatInt(order.GrossOutput()), "cumulativeExecutionFee", utils.FormatInt(order.ExecutionFee()),
36 )
37}
38
39func emitExecutionFeeCollected(
40 prevAddr address,
41 prevRealm string,
42 orderID uint64,
43 tokenPath string,
44 executionFeeAmount int64,
45 forwardedAmount int64,
46 pendingAmount int64,
47) {
48 chain.Emit(
49 "LimitExecutionFeeCollected",
50 "prevAddr", prevAddr.String(),
51 "prevRealm", prevRealm,
52 "orderId", utils.FormatUint(orderID),
53 "tokenPath", tokenPath,
54 "executionFeeAmount", utils.FormatInt(executionFeeAmount),
55 "forwardedAmount", utils.FormatInt(forwardedAmount),
56 "pendingAmount", utils.FormatInt(pendingAmount),
57 )
58}
59
60func emitOrderCompleted(prevAddr address, prevRealm string, order *plimit.Order) {
61 chain.Emit(
62 "LimitOrderCompleted",
63 "prevAddr", prevAddr.String(), "prevRealm", prevRealm,
64 "owner", order.Owner().String(), "orderId", utils.FormatUint(order.ID()),
65 "filledInput", utils.FormatInt(order.FilledInput()), "refundedInput", utils.FormatInt(order.RefundedInput()),
66 "grossOutput", utils.FormatInt(order.GrossOutput()), "cumulativeExecutionFee", utils.FormatInt(order.ExecutionFee()),
67 "userOutput", utils.FormatInt(order.GrossOutput()-order.ExecutionFee()),
68 )
69}
70
71func emitOrderRefunded(prevAddr address, prevRealm string, order *plimit.Order, refund int64, expired bool) {
72 name := "LimitOrderCancelled"
73 if expired {
74 name = "LimitOrderExpired"
75 }
76
77 emitOrderInputRefunded(name, prevAddr, prevRealm, order, refund)
78}
79
80func emitOrderInputRefunded(name string, prevAddr address, prevRealm string, order *plimit.Order, refund int64) {
81 chain.Emit(
82 name,
83 "prevAddr", prevAddr.String(), "prevRealm", prevRealm,
84 "owner", order.Owner().String(), "orderId", utils.FormatUint(order.ID()),
85 "tokenIn", order.TokenIn(), "tokenOut", order.TokenOut(),
86 "refundIn", utils.FormatInt(refund), "refundedInput", utils.FormatInt(order.RefundedInput()),
87 "filledInput", utils.FormatInt(order.FilledInput()), "remainingInput", utils.FormatInt(order.RemainingInput()),
88 "grossOutput", utils.FormatInt(order.GrossOutput()), "cumulativeExecutionFee", utils.FormatInt(order.ExecutionFee()),
89 "userOutput", utils.FormatInt(order.GrossOutput()-order.ExecutionFee()),
90 )
91}
92
93func emitOrderCleanupInsufficientBalance(prevAddr address, prevRealm string, order *plimit.Order, refund, balance int64) {
94 chain.Emit(
95 "LimitOrderCleanupInsufficientBalance",
96 "prevAddr", prevAddr.String(), "prevRealm", prevRealm,
97 "owner", order.Owner().String(), "orderId", utils.FormatUint(order.ID()),
98 "tokenIn", order.TokenIn(),
99 "refundAmount", utils.FormatInt(refund), "balance", utils.FormatInt(balance),
100 )
101}
102
103func emitConfigUpdated(prevAddr address, prevRealm, key, previous, next string) {
104 chain.Emit(
105 "LimitOrderConfigUpdated",
106 "prevAddr", prevAddr.String(), "prevRealm", prevRealm,
107 "key", key, "prevValue", previous, "newValue", next,
108 )
109}
110
111func emitExecutionFeeRateChanged(prevAddr address, prevRealm string, previousExecutionFeeRate int64, executionFeeRate int64) {
112 chain.Emit(
113 "LimitExecutionFeeRateChanged",
114 "prevAddr", prevAddr.String(),
115 "prevRealm", prevRealm,
116 "previousExecutionFeeRate", utils.FormatInt(previousExecutionFeeRate),
117 "executionFeeRate", utils.FormatInt(executionFeeRate),
118 )
119}