-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CL): CreatePosition and WithdrawPosition messages (#3139)
* feat(CL): CreatePosition and WithdrawPosition messages * lint
- Loading branch information
Showing
7 changed files
with
1,727 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
syntax = "proto3"; | ||
package osmosis.concentratedliquidity.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v12/x/concentrated-liquidity/types"; | ||
|
||
service Msg { | ||
rpc CreatePosition(MsgCreatePosition) returns (MsgCreatePositionResponse); | ||
rpc WithdrawPosition(MsgWithdrawPosition) | ||
returns (MsgWithdrawPositionResponse); | ||
} | ||
|
||
// ===================== MsgCreatePosition | ||
message MsgCreatePosition { | ||
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ]; | ||
string sender = 2 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; | ||
int64 lower_tick = 3 [ (gogoproto.moretags) = "yaml:\"lower_tick\"" ]; | ||
int64 upper_tick = 4 [ (gogoproto.moretags) = "yaml:\"upper_tick\"" ]; | ||
cosmos.base.v1beta1.Coin token_desired0 = 5 [ | ||
(gogoproto.moretags) = "yaml:\"token_desired0\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
cosmos.base.v1beta1.Coin token_desired1 = 6 [ | ||
(gogoproto.moretags) = "yaml:\"token_desired1\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
string token_min_amount0 = 7 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"token_min_amount0\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
string token_min_amount1 = 8 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"token_min_amount1\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
message MsgCreatePositionResponse { | ||
string amount0 = 1 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"amount0\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
string amount1 = 2 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"amount1\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
// ===================== MsgWithdrawPosition | ||
message MsgWithdrawPosition { | ||
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ]; | ||
string sender = 2 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; | ||
int64 lower_tick = 3 [ (gogoproto.moretags) = "yaml:\"lower_tick\"" ]; | ||
int64 upper_tick = 4 [ (gogoproto.moretags) = "yaml:\"upper_tick\"" ]; | ||
string liquidity_amount = 5 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"liquidity_amount\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
message MsgWithdrawPositionResponse { | ||
string amount0 = 1 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"amount0\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
string amount1 = 2 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"amount1\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package concentrated_liquidity | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
cltypes "github.com/osmosis-labs/osmosis/v12/x/concentrated-liquidity/types" | ||
) | ||
|
||
// OrderInitialPoolDenoms sets the pool denoms of a cl pool | ||
func OrderInitialPoolDenoms(denom0, denom1 string) (string, string, error) { | ||
return cltypes.OrderInitialPoolDenoms(denom0, denom1) | ||
} | ||
|
||
func (k Keeper) CreatePosition(ctx sdk.Context, poolId uint64, owner sdk.AccAddress, amount0Desired, amount1Desired, amount0Min, amount1Min sdk.Int, lowerTick, upperTick int64) (amtDenom0, amtDenom1 sdk.Int, err error) { | ||
return k.createPosition(ctx, poolId, owner, amount0Desired, amount1Desired, amount0Min, amount1Min, lowerTick, upperTick) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package concentrated_liquidity | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/osmosis/v12/x/concentrated-liquidity/types" | ||
) | ||
|
||
type msgServer struct { | ||
keeper *Keeper | ||
} | ||
|
||
func NewMsgServerImpl(keeper *Keeper) types.MsgServer { | ||
return &msgServer{ | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
// TODO: spec and tests, including events | ||
func (server msgServer) CreatePosition(goCtx context.Context, msg *types.MsgCreatePosition) (*types.MsgCreatePositionResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
sender, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
actualAmount0, actualAmount1, err := server.keeper.createPosition(ctx, msg.PoolId, sender, msg.TokenDesired0.Amount, msg.TokenDesired1.Amount, msg.TokenMinAmount0, msg.TokenMinAmount1, msg.LowerTick, msg.UpperTick) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), | ||
), | ||
sdk.NewEvent( | ||
types.TypeEvtWithdrawPosition, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), | ||
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(msg.PoolId, 10)), | ||
sdk.NewAttribute(types.AttributeAmount0, actualAmount0.String()), | ||
sdk.NewAttribute(types.AttributeAmount1, actualAmount1.String()), | ||
sdk.NewAttribute(types.AttributeLowerTick, strconv.FormatInt(msg.LowerTick, 10)), | ||
sdk.NewAttribute(types.AttributeUpperTick, strconv.FormatInt(msg.UpperTick, 10)), | ||
), | ||
}) | ||
|
||
return &types.MsgCreatePositionResponse{Amount0: actualAmount0, Amount1: actualAmount1}, nil | ||
} | ||
|
||
// TODO: spec and tests, including events | ||
func (server msgServer) WithdrawPosition(goCtx context.Context, msg *types.MsgWithdrawPosition) (*types.MsgWithdrawPositionResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
sender, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
amount0, amount1, err := server.keeper.withdrawPosition(ctx, msg.PoolId, sender, msg.LowerTick, msg.UpperTick, msg.LiquidityAmount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), | ||
), | ||
sdk.NewEvent( | ||
types.TypeEvtWithdrawPosition, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), | ||
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(msg.PoolId, 10)), | ||
sdk.NewAttribute(types.AttributeLiquidity, msg.LiquidityAmount.String()), | ||
sdk.NewAttribute(types.AttributeAmount0, amount0.String()), | ||
sdk.NewAttribute(types.AttributeAmount1, amount1.String()), | ||
sdk.NewAttribute(types.AttributeLowerTick, strconv.FormatInt(msg.LowerTick, 10)), | ||
sdk.NewAttribute(types.AttributeUpperTick, strconv.FormatInt(msg.UpperTick, 10)), | ||
), | ||
}) | ||
|
||
return &types.MsgWithdrawPositionResponse{Amount0: amount0, Amount1: amount1}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package types | ||
|
||
const ( | ||
TypeEvtCreatePosition = "create_position" | ||
TypeEvtWithdrawPosition = "withdraw_position" | ||
|
||
AttributeValueCategory = ModuleName | ||
AttributeKeyPoolId = "pool_id" | ||
AttributeAmount0 = "amount0" | ||
AttributeAmount1 = "amount1" | ||
AttributeLiquidity = "liquidity" | ||
AttributeLowerTick = "lower_tick" | ||
AttributeUpperTick = "upper_tick" | ||
) |
Oops, something went wrong.