-
Notifications
You must be signed in to change notification settings - Fork 40
/
msg_server_create_pool.go
49 lines (41 loc) · 1.54 KB
/
msg_server_create_pool.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
package keeper
import (
"context"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
)
// CreatePool attempts to create a pool returning the newly created pool ID or an error upon failure.
// The pool creation fee is used to fund the community pool.
// It will create a dedicated module account for the pool and sends the initial liquidity to the created module account.
func (k msgServer) CreatePool(goCtx context.Context, msg *types.MsgCreatePool) (*types.MsgCreatePoolResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// Pay pool creation fee
sender := sdk.MustAccAddressFromBech32(msg.Sender)
params := k.GetParams(ctx)
if !params.PoolCreationFee.IsNil() && params.PoolCreationFee.IsPositive() {
feeCoins := sdk.Coins{sdk.NewCoin(ptypes.Elys, params.PoolCreationFee)}
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, feeCoins); err != nil {
return nil, err
}
}
poolId, err := k.Keeper.CreatePool(ctx, msg)
if err != nil {
return &types.MsgCreatePoolResponse{}, err
}
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.TypeEvtPoolCreated,
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(poolId, 10)),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSigners()[0].String()),
),
})
return &types.MsgCreatePoolResponse{
PoolID: poolId,
}, nil
}