Skip to content

Commit

Permalink
feat(ProtoRev): Support for CW Pools (#5901)
Browse files Browse the repository at this point in the history
* init

* add new pool weights to upgrade handler

* change log

* add todo for genesis testing

* proto ci

* val basic testing

* e2e test

* main update

* nit
  • Loading branch information
davidterpay committed Jul 28, 2023
1 parent 8bb2ab1 commit 91e56dd
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 45 deletions.
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
9 changes: 9 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,14 @@ 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.PoolWeights{
BalancerWeight: 1,
StableWeight: 4,
ConcentratedWeight: 300,
CosmwasmWeight: 300,
})

return migrations, nil
}
}
3 changes: 3 additions & 0 deletions proto/osmosis/protorev/v1beta1/protorev.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ 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:\"cosmwasm_weight\"" ];
}

// 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

// 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
119 changes: 78 additions & 41 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

0 comments on commit 91e56dd

Please sign in to comment.