Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ProtoRev): Support for CW Pools #5901

Merged
merged 10 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#5532](https://github.com/osmosis-labs/osmosis/pull/5532) fix: Fix x/tokenfactory genesis import denoms reset x/bank existing denom metadata
* [#5874](https://github.com/osmosis-labs/osmosis/pull/5874) Remove Partial Migration from superfluid migration to CL
* [#5901](https://github.com/osmosis-labs/osmosis/pull/5901) Adding support for CW pools in ProtoRev

### BugFix

Expand Down
4 changes: 4 additions & 0 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/osmosis-labs/osmosis/v17/app/keepers"
"github.com/osmosis-labs/osmosis/v17/app/upgrades"
"github.com/osmosis-labs/osmosis/v17/x/protorev/types"
)

func CreateUpgradeHandler(
Expand All @@ -23,6 +24,9 @@ func CreateUpgradeHandler(
return nil, err
}

// Reset the pool weights upon upgrade. This will add support for CW pools on ProtoRev.
keepers.ProtoRevKeeper.SetPoolWeights(ctx, types.DefaultPoolWeights)

return migrations, nil
}
}
2 changes: 2 additions & 0 deletions proto/osmosis/protorev/v1beta1/protorev.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ message PoolWeights {
// The weight of a concentrated pool
uint64 concentrated_weight = 3
[ (gogoproto.moretags) = "yaml:\"concentrated_weight\"" ];
// The weight of a cosmwasm pool
uint64 cosmwasm_weight = 4 [ (gogoproto.moretags) = "yaml:\"cw_weight\"" ];
NotJeremyLiu marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

@ValarDragon ValarDragon Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to make this dynamic based on address in the future?

I guess gas metering may also handle this for us?
(I'm in support of merging this, and discussing in an issue / spec doc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea totally agree. Ill add some tasks to the ProtoRev v17 issue tracker.

}

// BaseDenom represents a single base denom that the module uses for its
Expand Down
Empty file removed x/protorev/keeper/atom
Empty file.
6 changes: 6 additions & 0 deletions x/protorev/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func (s *KeeperTestSuite) SetupTest() {
sdk.NewCoin("hook", sdk.NewInt(9000000000000000000)),
sdk.NewCoin("eth", sdk.NewInt(9000000000000000000)),
sdk.NewCoin("gamm/pool/1", sdk.NewInt(9000000000000000000)),
sdk.NewCoin(apptesting.DefaultTransmuterDenomA, sdk.NewInt(9000000000000000000)),
sdk.NewCoin(apptesting.DefaultTransmuterDenomB, sdk.NewInt(9000000000000000000)),
)
s.fundAllAccountsWith()
s.Commit()
Expand Down Expand Up @@ -896,6 +898,10 @@ func (s *KeeperTestSuite) setUpPools() {
// Pool 49
s.PrepareConcentratedPoolWithCoinsAndFullRangePosition("epochTwo", "uosmo")

// Create a cosmwasm pool for testing
// Pool 50
s.PrepareCosmWasmPool()

// Set all of the pool info into the stores
err := s.App.ProtoRevKeeper.UpdatePools(s.Ctx)
s.Require().NoError(err)
Expand Down
7 changes: 6 additions & 1 deletion x/protorev/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ func (s *KeeperTestSuite) TestMsgSetPoolWeights() {
StableWeight: 1,
BalancerWeight: 2,
ConcentratedWeight: 3,
CosmwasmWeight: 4,
},
false,
false,
Expand All @@ -492,6 +493,7 @@ func (s *KeeperTestSuite) TestMsgSetPoolWeights() {
StableWeight: 0,
BalancerWeight: 2,
ConcentratedWeight: 1,
CosmwasmWeight: 4,
},
false,
false,
Expand All @@ -500,7 +502,8 @@ func (s *KeeperTestSuite) TestMsgSetPoolWeights() {
"Invalid message (unset pool weight)",
s.adminAccount.String(),
types.PoolWeights{
StableWeight: 1,
StableWeight: 1,
CosmwasmWeight: 4,
},
false,
false,
Expand All @@ -512,6 +515,7 @@ func (s *KeeperTestSuite) TestMsgSetPoolWeights() {
StableWeight: 1,
BalancerWeight: 2,
ConcentratedWeight: 3,
CosmwasmWeight: 4,
},
true,
false,
Expand All @@ -523,6 +527,7 @@ func (s *KeeperTestSuite) TestMsgSetPoolWeights() {
StableWeight: 1,
BalancerWeight: 2,
ConcentratedWeight: 3,
CosmwasmWeight: 4,
},
true,
true,
Expand Down
2 changes: 1 addition & 1 deletion x/protorev/keeper/posthandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (s *KeeperTestSuite) TestAnteHandle() {
params: param{
trades: []types.Trade{
{
Pool: 50,
Pool: 51,
TokenOut: "ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7",
TokenIn: "uosmo",
},
Expand Down
2 changes: 2 additions & 0 deletions x/protorev/keeper/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func (k Keeper) CalculateRoutePoolPoints(ctx sdk.Context, route poolmanagertypes
totalWeight += poolWeights.StableWeight
case poolmanagertypes.Concentrated:
totalWeight += poolWeights.ConcentratedWeight
case poolmanagertypes.CosmWasm:
totalWeight += poolWeights.CosmwasmWeight
default:
return 0, fmt.Errorf("invalid pool type")
}
Expand Down
19 changes: 18 additions & 1 deletion x/protorev/keeper/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,29 @@ func (s *KeeperTestSuite) TestCalculateRoutePoolPoints() {
expectedRoutePoolPoints: 11,
expectedPass: false,
},
{
description: "Valid route with a cosmwasm pool",
route: []poolmanagertypes.SwapAmountInRoute{{PoolId: 1, TokenOutDenom: ""}, {PoolId: 50, TokenOutDenom: ""}, {PoolId: 2, TokenOutDenom: ""}},
expectedRoutePoolPoints: 8,
expectedPass: true,
},
{
description: "Valid route with cw pool, balancer, stable swap and cl pool",
route: []poolmanagertypes.SwapAmountInRoute{{PoolId: 1, TokenOutDenom: ""}, {PoolId: 50, TokenOutDenom: ""}, {PoolId: 40, TokenOutDenom: ""}, {PoolId: 49, TokenOutDenom: ""}},
expectedRoutePoolPoints: 10,
expectedPass: true,
},
}

for _, tc := range cases {
s.Run(tc.description, func() {
s.SetupTest()
s.App.ProtoRevKeeper.SetPoolWeights(s.Ctx, types.PoolWeights{StableWeight: 3, BalancerWeight: 2, ConcentratedWeight: 1})
s.App.ProtoRevKeeper.SetPoolWeights(s.Ctx, types.PoolWeights{
StableWeight: 3,
BalancerWeight: 2,
ConcentratedWeight: 1,
CosmwasmWeight: 4,
})

routePoolPoints, err := s.App.ProtoRevKeeper.CalculateRoutePoolPoints(s.Ctx, tc.route)
if tc.expectedPass {
Expand Down
4 changes: 4 additions & 0 deletions x/protorev/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var (
StableWeight: 5, // it takes around 5 ms to simulate and execute a stable swap
BalancerWeight: 2, // it takes around 2 ms to simulate and execute a balancer swap
ConcentratedWeight: 2, // it takes around 2 ms to simulate and execute a concentrated swap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since in upgrade we are resetting pool weights to the defaults, can we match the defaults to what's on mainnet today? (BalancerWeight is 1, ConcentratedWeight is 300 -- essentially turning it off)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CL issue should go away in the upgrade right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! There is an outstanding task (which we will open a PR for in the next few days) that will bound protorev search better for CL pools and allow it to work on mainnet.

Copy link
Contributor Author

@davidterpay davidterpay Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the pool weights in the update PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ValarDragon Yeah the issue will go away, but I'd like to change the pool points in the PR that makes the issue go away rather than in this PR


// TODO: This is a temporary weight until we can get a more accurate weight for cosmwasm swaps
// ref: https://github.com/osmosis-labs/osmosis/issues/5858
CosmwasmWeight: 5, // it takes around 5 ms to simulate and execute a cosmwasm swap
}
DefaultDaysSinceModuleGenesis = uint64(0)
DefaultDeveloperFees = []sdk.Coin{}
Expand Down
3 changes: 3 additions & 0 deletions x/protorev/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ func TestMsgSetPoolWeights(t *testing.T) {
BalancerWeight: 1,
StableWeight: 1,
ConcentratedWeight: 1,
CosmwasmWeight: 1,
},
false,
},
Expand All @@ -530,6 +531,7 @@ func TestMsgSetPoolWeights(t *testing.T) {
BalancerWeight: 0,
StableWeight: 1,
ConcentratedWeight: 1,
CosmwasmWeight: 1,
},
false,
},
Expand All @@ -540,6 +542,7 @@ func TestMsgSetPoolWeights(t *testing.T) {
BalancerWeight: 1,
StableWeight: 1,
ConcentratedWeight: 1,
CosmwasmWeight: 1,
},
true,
},
Expand Down
123 changes: 80 additions & 43 deletions x/protorev/types/protorev.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/protorev/types/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (pw *PoolWeights) Validate() error {
return fmt.Errorf("pool weights cannot be nil")
}

if pw.BalancerWeight == 0 || pw.StableWeight == 0 || pw.ConcentratedWeight == 0 {
if pw.BalancerWeight == 0 || pw.StableWeight == 0 || pw.ConcentratedWeight == 0 || pw.CosmwasmWeight == 0 {
return fmt.Errorf("pool weights cannot be 0")
}

Expand Down