-
Notifications
You must be signed in to change notification settings - Fork 575
/
msgs.go
106 lines (88 loc) · 2.72 KB
/
msgs.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
106
package balancer
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/osmosis-labs/osmosis/v25/x/gamm/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v25/x/poolmanager/types"
)
const (
TypeMsgCreateBalancerPool = "create_balancer_pool"
)
var (
_ sdk.Msg = &MsgCreateBalancerPool{}
_ poolmanagertypes.CreatePoolMsg = &MsgCreateBalancerPool{}
)
func NewMsgCreateBalancerPool(
sender sdk.AccAddress,
poolParams PoolParams,
poolAssets []PoolAsset,
futurePoolGovernor string,
) MsgCreateBalancerPool {
return MsgCreateBalancerPool{
Sender: sender.String(),
PoolParams: &poolParams,
PoolAssets: poolAssets,
FuturePoolGovernor: futurePoolGovernor,
}
}
func (msg MsgCreateBalancerPool) Route() string { return types.RouterKey }
func (msg MsgCreateBalancerPool) Type() string { return TypeMsgCreateBalancerPool }
func (msg MsgCreateBalancerPool) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err)
}
err = validateUserSpecifiedPoolAssets(msg.PoolAssets)
if err != nil {
return err
}
err = msg.PoolParams.Validate(msg.PoolAssets)
if err != nil {
return err
}
// validation for future owner
if err = types.ValidateFutureGovernor(msg.FuturePoolGovernor); err != nil {
return err
}
return nil
}
func (msg MsgCreateBalancerPool) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
func (msg MsgCreateBalancerPool) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
/// Implement the CreatePoolMsg interface
func (msg MsgCreateBalancerPool) PoolCreator() sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return sender
}
func (msg MsgCreateBalancerPool) Validate(ctx sdk.Context) error {
return msg.ValidateBasic()
}
func (msg MsgCreateBalancerPool) InitialLiquidity() sdk.Coins {
var coins sdk.Coins
for _, asset := range msg.PoolAssets {
coins = append(coins, asset.Token)
}
if coins == nil {
panic("InitialLiquidity coins is equal to nil - this shouldn't happen")
}
coins = coins.Sort()
return coins
}
func (msg MsgCreateBalancerPool) CreatePool(ctx sdk.Context, poolID uint64) (poolmanagertypes.PoolI, error) {
poolI, err := NewBalancerPool(poolID, *msg.PoolParams, msg.PoolAssets, msg.FuturePoolGovernor, ctx.BlockTime())
return &poolI, err
}
func (msg MsgCreateBalancerPool) GetPoolType() poolmanagertypes.PoolType {
return poolmanagertypes.Balancer
}