-
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): swap router messages and wiring (#3070)
* feat(CL): swap router messages and wiring * fix lint
- Loading branch information
Showing
9 changed files
with
1,931 additions
and
26 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
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,72 @@ | ||
syntax = "proto3"; | ||
package osmosis.swaprouter.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/osmosis/v12/x/swaprouter/types"; | ||
|
||
service Msg { | ||
rpc SwapExactAmountIn(MsgSwapExactAmountIn) | ||
returns (MsgSwapExactAmountInResponse); | ||
rpc SwapExactAmountOut(MsgSwapExactAmountOut) | ||
returns (MsgSwapExactAmountOutResponse); | ||
} | ||
|
||
// ===================== MsgSwapExactAmountIn | ||
message SwapAmountInRoute { | ||
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ]; | ||
string token_out_denom = 2 | ||
[ (gogoproto.moretags) = "yaml:\"token_out_denom\"" ]; | ||
} | ||
|
||
message MsgSwapExactAmountIn { | ||
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; | ||
repeated SwapAmountInRoute routes = 2 [ (gogoproto.nullable) = false ]; | ||
cosmos.base.v1beta1.Coin token_in = 3 [ | ||
(gogoproto.moretags) = "yaml:\"token_in\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
string token_out_min_amount = 4 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"token_out_min_amount\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
message MsgSwapExactAmountInResponse { | ||
string token_out_amount = 1 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"token_out_amount\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
// ===================== MsgSwapExactAmountOut | ||
message SwapAmountOutRoute { | ||
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ]; | ||
string token_in_denom = 2 | ||
[ (gogoproto.moretags) = "yaml:\"token_out_denom\"" ]; | ||
} | ||
|
||
message MsgSwapExactAmountOut { | ||
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; | ||
repeated SwapAmountOutRoute routes = 2 [ (gogoproto.nullable) = false ]; | ||
string token_in_max_amount = 3 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"token_in_max_amount\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
cosmos.base.v1beta1.Coin token_out = 4 [ | ||
(gogoproto.moretags) = "yaml:\"token_out\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} | ||
|
||
message MsgSwapExactAmountOutResponse { | ||
string token_in_amount = 1 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.moretags) = "yaml:\"token_in_amount\"", | ||
(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
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,72 @@ | ||
package swaprouter | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/osmosis/v12/x/swaprouter/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) SwapExactAmountIn(goCtx context.Context, msg *types.MsgSwapExactAmountIn) (*types.MsgSwapExactAmountInResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// TODO: will be propagated to actual swaps | ||
_, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tokenOutAmount, err := server.keeper.RouteExactAmountIn(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Swap event is handled elsewhere | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), | ||
), | ||
}) | ||
|
||
return &types.MsgSwapExactAmountInResponse{TokenOutAmount: tokenOutAmount}, nil | ||
} | ||
|
||
// TODO: spec and tests, including events | ||
func (server msgServer) SwapExactAmountOut(goCtx context.Context, msg *types.MsgSwapExactAmountOut) (*types.MsgSwapExactAmountOutResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
_, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tokenInAmount, err := server.keeper.RouteExactAmountOut(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Swap event is handled elsewhere | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), | ||
), | ||
}) | ||
|
||
return &types.MsgSwapExactAmountOutResponse{TokenInAmount: tokenInAmount}, 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,15 @@ | ||
package swaprouter | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// TODO: spec and tests | ||
func (k Keeper) RouteExactAmountIn(ctx sdk.Context) (tokenOutAmount sdk.Int, err error) { | ||
return sdk.ZeroInt(), nil | ||
} | ||
|
||
// TODO: spec and tests | ||
func (k Keeper) RouteExactAmountOut(ctx sdk.Context) (tokenInAmount sdk.Int, err error) { | ||
return sdk.ZeroInt(), 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,5 @@ | ||
package types | ||
|
||
const ( | ||
AttributeValueCategory = ModuleName | ||
) |
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,7 @@ | ||
package types | ||
|
||
const ( | ||
StoreKey = ModuleName | ||
|
||
ModuleName = "swaprouter" | ||
) |
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,5 @@ | ||
package types | ||
|
||
// TODO: godoc | ||
type SwapI interface { | ||
} |
Oops, something went wrong.