Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
Osmosis_Sync
Commits
3e45a2ca
Commit
3e45a2ca
authored
2 years ago
by
Bradley Lostak
Browse files
Options
Download
Email Patches
Plain Diff
remove SybilResistantFee interface
parent
2a00eee5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
x/gamm/types/msg_swap.go
+59
-0
x/gamm/types/msg_swap.go
x/gamm/types/msg_sybil.go
+0
-97
x/gamm/types/msg_sybil.go
x/gamm/types/msgs_test.go
+4
-4
x/gamm/types/msgs_test.go
x/txfees/keeper/feedecorator.go
+2
-2
x/txfees/keeper/feedecorator.go
x/txfees/keeper/feetokens.go
+0
-5
x/txfees/keeper/feetokens.go
x/txfees/keeper/feetokens_test.go
+1
-1
x/txfees/keeper/feetokens_test.go
with
66 additions
and
109 deletions
+66
-109
x/gamm/types/msg_swap.go
+
59
-
0
View file @
3e45a2ca
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
}
This diff is collapsed.
Click to expand it.
x/gamm/types/msg_sybil.go
deleted
100644 → 0
+
0
-
97
View file @
2a00eee5
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
}
This diff is collapsed.
Click to expand it.
x/gamm/types/msgs_test.go
+
4
-
4
View file @
3e45a2ca
...
...
@@ -47,7 +47,7 @@ func TestMsgSwapExactAmountIn(t *testing.T) {
tests
:=
[]
struct
{
name
string
msg
S
ybilResistantFe
e
msg
S
wapMsgRout
e
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
.
Get
TokenDenomsOnPath
()
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
S
ybilResistantFe
e
msg
S
wapMsgRout
e
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
.
Get
TokenDenomsOnPath
()
denomPath
:=
test
.
msg
.
TokenDenomsOnPath
()
poolIdPath
:=
test
.
msg
.
GetPoolIdOnPath
()
token
:=
test
.
msg
.
GetTokenToFee
()
...
...
This diff is collapsed.
Click to expand it.
x/txfees/keeper/feedecorator.go
+
2
-
2
View file @
3e45a2ca
...
...
@@ -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
.
S
ybilResistantFe
e
)
msg
,
canSybil
:=
tx
.
GetMsgs
()[
0
]
.
(
gammtypes
.
S
wapMsgRout
e
)
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
.
Get
TokenDenomsOnPath
(),
token
)
feesPaid
,
err
:=
mfd
.
TxFeesKeeper
.
GetFeesPaid
(
ctx
,
msg
.
GetPoolIdOnPath
(),
msg
.
TokenDenomsOnPath
(),
token
)
if
err
!=
nil
{
return
Sybil
{},
err
}
...
...
This diff is collapsed.
Click to expand it.
x/txfees/keeper/feetokens.go
+
0
-
5
View file @
3e45a2ca
...
...
@@ -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
])
...
...
This diff is collapsed.
Click to expand it.
x/txfees/keeper/feetokens_test.go
+
1
-
1
View file @
3e45a2ca
...
...
@@ -336,7 +336,7 @@ func (suite *KeeperTestSuite) TestGetTotalSwapFeeForSwapInBalancerPool() {
suite
.
Require
()
.
NotEmpty
(
poolIds
)
// get denomPath from test msg
denomPath
:=
test
.
msg
.
Get
TokenDenomsOnPath
()
denomPath
:=
test
.
msg
.
TokenDenomsOnPath
()
suite
.
Require
()
.
NotEmpty
(
denomPath
)
// check denom path is longer than pool ids by 1
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets