Commit 3e45a2ca authored by Bradley Lostak's avatar Bradley Lostak
Browse files

remove SybilResistantFee interface

parent 2a00eee5
Showing with 66 additions and 109 deletions
+66 -109
package types
import sdk "github.com/cosmos/cosmos-sdk/types"
// SwapMsg defines a simple interface for getting the token denoms on a swap message route.
type SwapMsgRoute interface {
TokenInDenom() string
TokenOutDenom() string
TokenDenomsOnPath() []string
GetTokenToFee() sdk.Coin
GetPoolIdOnPath() []uint64
}
var (
......@@ -21,6 +25,14 @@ func (msg MsgSwapExactAmountOut) TokenOutDenom() string {
}
func (msg MsgSwapExactAmountOut) TokenDenomsOnPath() []string {
if msg.Routes == nil {
return []string{}
}
if len(msg.Routes) == 0 {
return []string{}
}
denoms := make([]string, 0, len(msg.Routes)+1)
for i := 0; i < len(msg.Routes); i++ {
denoms = append(denoms, msg.Routes[i].TokenInDenom)
......@@ -29,6 +41,25 @@ func (msg MsgSwapExactAmountOut) TokenDenomsOnPath() []string {
return denoms
}
func (msg MsgSwapExactAmountOut) GetTokenToFee() sdk.Coin {
if msg.TokenOut.Amount.LT(sdk.ZeroInt()) {
return sdk.Coin{}
}
if _, ok := sdk.NewIntFromString(msg.TokenOut.Denom); ok == true {
return sdk.Coin{}
}
return msg.TokenOut
}
func (msg MsgSwapExactAmountOut) GetPoolIdOnPath() []uint64 {
ids := make([]uint64, 0, len(msg.Routes))
for i := 0; i < len(msg.Routes); i++ {
ids = append(ids, msg.Routes[i].PoolId)
}
return ids
}
func (msg MsgSwapExactAmountIn) TokenInDenom() string {
return msg.TokenIn.Denom
}
......@@ -39,6 +70,14 @@ func (msg MsgSwapExactAmountIn) TokenOutDenom() string {
}
func (msg MsgSwapExactAmountIn) TokenDenomsOnPath() []string {
if msg.Routes == nil {
return []string{}
}
if len(msg.Routes) == 0 {
return []string{}
}
denoms := make([]string, 0, len(msg.Routes)+1)
denoms = append(denoms, msg.TokenInDenom())
for i := 0; i < len(msg.Routes); i++ {
......@@ -46,3 +85,23 @@ func (msg MsgSwapExactAmountIn) TokenDenomsOnPath() []string {
}
return denoms
}
func (msg MsgSwapExactAmountIn) GetTokenToFee() sdk.Coin {
if msg.TokenIn.Amount.LT(sdk.ZeroInt()) {
return sdk.Coin{}
}
if _, ok := sdk.NewIntFromString(msg.TokenIn.Denom); ok == true {
return sdk.Coin{}
}
return msg.TokenIn
}
func (msg MsgSwapExactAmountIn) GetPoolIdOnPath() []uint64 {
ids := make([]uint64, 0, len(msg.Routes))
for i := 0; i < len(msg.Routes); i++ {
ids = append(ids, msg.Routes[i].PoolId)
}
return ids
}
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// SybilResistantFee Swap Msg defines an interface for getting
// - poolIds on a swap msg route
// - token to apply the sybil resistant fees to
type SybilResistantFee interface {
GetTokenDenomsOnPath() []string
GetPoolIdOnPath() []uint64
GetTokenToFee() sdk.Coin
}
var (
_ SybilResistantFee = MsgSwapExactAmountOut{}
_ SybilResistantFee = MsgSwapExactAmountIn{}
)
// MsgSwapExactAmountOut implements SybilResistantFee
func (msg MsgSwapExactAmountOut) GetTokenDenomsOnPath() []string {
if msg.Routes == nil {
return []string{}
}
if len(msg.Routes) == 0 {
return []string{}
}
denoms := make([]string, 0, len(msg.Routes)+1)
for i := 0; i < len(msg.Routes); i++ {
denoms = append(denoms, msg.Routes[i].TokenInDenom)
}
denoms = append(denoms, msg.TokenOutDenom())
return denoms
}
func (msg MsgSwapExactAmountOut) GetTokenToFee() sdk.Coin {
if msg.TokenOut.Amount.LT(sdk.ZeroInt()) {
return sdk.Coin{}
}
if _, ok := sdk.NewIntFromString(msg.TokenOut.Denom); ok == true {
return sdk.Coin{}
}
return msg.TokenOut
}
func (msg MsgSwapExactAmountOut) GetPoolIdOnPath() []uint64 {
ids := make([]uint64, 0, len(msg.Routes))
for i := 0; i < len(msg.Routes); i++ {
ids = append(ids, msg.Routes[i].PoolId)
}
return ids
}
// MsgSwapExactAmountIn implements SybilResistantFee
func (msg MsgSwapExactAmountIn) GetTokenDenomsOnPath() []string {
if msg.Routes == nil {
return []string{}
}
if len(msg.Routes) == 0 {
return []string{}
}
denoms := make([]string, 0, len(msg.Routes)+1)
denoms = append(denoms, msg.TokenInDenom())
for i := 0; i < len(msg.Routes); i++ {
denoms = append(denoms, msg.Routes[i].TokenOutDenom)
}
return denoms
}
func (msg MsgSwapExactAmountIn) GetTokenToFee() sdk.Coin {
if msg.TokenIn.Amount.LT(sdk.ZeroInt()) {
return sdk.Coin{}
}
if _, ok := sdk.NewIntFromString(msg.TokenIn.Denom); ok == true {
return sdk.Coin{}
}
return msg.TokenIn
}
func (msg MsgSwapExactAmountIn) GetPoolIdOnPath() []uint64 {
ids := make([]uint64, 0, len(msg.Routes))
for i := 0; i < len(msg.Routes); i++ {
ids = append(ids, msg.Routes[i].PoolId)
}
return ids
}
......@@ -47,7 +47,7 @@ func TestMsgSwapExactAmountIn(t *testing.T) {
tests := []struct {
name string
msg SybilResistantFee
msg SwapMsgRoute
expectDenomPath []string
expectPoolIdPath []uint64
expectToken sdk.Coin
......@@ -175,7 +175,7 @@ func TestMsgSwapExactAmountIn(t *testing.T) {
require.Error(t, msg.ValidateBasic(), "test: %v", test.name)
}
denomPath := test.msg.GetTokenDenomsOnPath()
denomPath := test.msg.TokenDenomsOnPath()
poolIdPath := test.msg.GetPoolIdOnPath()
token := test.msg.GetTokenToFee()
......@@ -221,7 +221,7 @@ func TestMsgSwapExactAmountOut(t *testing.T) {
tests := []struct {
name string
msg SybilResistantFee
msg SwapMsgRoute
expectDenomPath []string
expectPoolIdPath []uint64
expectToken sdk.Coin
......@@ -353,7 +353,7 @@ func TestMsgSwapExactAmountOut(t *testing.T) {
require.Error(t, msg.ValidateBasic(), "test: %v", test.name)
}
denomPath := test.msg.GetTokenDenomsOnPath()
denomPath := test.msg.TokenDenomsOnPath()
poolIdPath := test.msg.GetPoolIdOnPath()
token := test.msg.GetTokenToFee()
......
......@@ -165,7 +165,7 @@ func (mfd MempoolFeeDecorator) GetMinBaseGasPriceForTx(ctx sdk.Context, baseDeno
}
// Check if message qualifies for sybil resistant fees
msg, canSybil := tx.GetMsgs()[0].(gammtypes.SybilResistantFee)
msg, canSybil := tx.GetMsgs()[0].(gammtypes.SwapMsgRoute)
if !canSybil {
return sybil, nil
}
......@@ -179,7 +179,7 @@ func (mfd MempoolFeeDecorator) GetMinBaseGasPriceForTx(ctx sdk.Context, baseDeno
}
// Get fees paid in swap fee
feesPaid, err := mfd.TxFeesKeeper.GetFeesPaid(ctx, msg.GetPoolIdOnPath(), msg.GetTokenDenomsOnPath(), token)
feesPaid, err := mfd.TxFeesKeeper.GetFeesPaid(ctx, msg.GetPoolIdOnPath(), msg.TokenDenomsOnPath(), token)
if err != nil {
return Sybil{}, err
}
......
......@@ -181,11 +181,6 @@ func (k Keeper) GetTotalSwapFee(ctx sdk.Context, poolIds []uint64, denomPath []s
prefixStore := k.GetFeeTokensStore(ctx)
swapFees := sdk.ZeroDec()
// Join/Exit pool support
// if len(denomPath) == 1 {
// return k.gammKeeper.GetSwapFeeFromPoolId(ctx, poolIds[0])
// }
// Get swap fees from pools
for i := range poolIds {
// Get swap fee
swapFee, err := k.gammKeeper.GetSwapFeeFromPoolId(ctx, poolIds[i])
......
......@@ -336,7 +336,7 @@ func (suite *KeeperTestSuite) TestGetTotalSwapFeeForSwapInBalancerPool() {
suite.Require().NotEmpty(poolIds)
// get denomPath from test msg
denomPath := test.msg.GetTokenDenomsOnPath()
denomPath := test.msg.TokenDenomsOnPath()
suite.Require().NotEmpty(denomPath)
// check denom path is longer than pool ids by 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment