-
Notifications
You must be signed in to change notification settings - Fork 47
/
events.go
70 lines (60 loc) · 2.39 KB
/
events.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
package types
import (
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
TypeEvtPoolJoined = "pool_joined"
TypeEvtPoolExited = "pool_exited"
TypeEvtPoolCreated = "pool_created"
TypeEvtTokenSwapped = "token_swapped"
AttributeValueCategory = ModuleName
AttributeKeyPoolId = "pool_id"
AttributeKeyTokensIn = "tokens_in"
AttributeKeyTokensOut = "tokens_out"
AttributeKeyRecipient = "recipient"
)
func EmitSwapEvent(ctx sdk.Context, sender, recipient sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) {
ctx.EventManager().EmitEvents(sdk.Events{
NewSwapEvent(sender, recipient, poolId, input, output),
})
}
func EmitAddLiquidityEvent(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, liquidity sdk.Coins) {
ctx.EventManager().EmitEvents(sdk.Events{
NewAddLiquidityEvent(sender, poolId, liquidity),
})
}
func EmitRemoveLiquidityEvent(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, liquidity sdk.Coins) {
ctx.EventManager().EmitEvents(sdk.Events{
NewRemoveLiquidityEvent(sender, poolId, liquidity),
})
}
func NewSwapEvent(sender, recipient sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) sdk.Event {
return sdk.NewEvent(
TypeEvtTokenSwapped,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, sender.String()),
sdk.NewAttribute(AttributeKeyRecipient, recipient.String()),
sdk.NewAttribute(AttributeKeyPoolId, strconv.FormatUint(poolId, 10)),
sdk.NewAttribute(AttributeKeyTokensIn, input.String()),
sdk.NewAttribute(AttributeKeyTokensOut, output.String()),
)
}
func NewAddLiquidityEvent(sender sdk.AccAddress, poolId uint64, liquidity sdk.Coins) sdk.Event {
return sdk.NewEvent(
TypeEvtPoolJoined,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, sender.String()),
sdk.NewAttribute(AttributeKeyPoolId, strconv.FormatUint(poolId, 10)),
sdk.NewAttribute(AttributeKeyTokensIn, liquidity.String()),
)
}
func NewRemoveLiquidityEvent(sender sdk.AccAddress, poolId uint64, liquidity sdk.Coins) sdk.Event {
return sdk.NewEvent(
TypeEvtPoolExited,
sdk.NewAttribute(sdk.AttributeKeyModule, AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, sender.String()),
sdk.NewAttribute(AttributeKeyPoolId, strconv.FormatUint(poolId, 10)),
sdk.NewAttribute(AttributeKeyTokensOut, liquidity.String()),
)
}