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

Ensure gauges can only be created for assets that exist on-chain #855

Merged
merged 4 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions proto/osmosis/lockup/lock.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ enum LockQueryType {
}

message QueryCondition {
LockQueryType lock_query_type = 1; // type of lock query, ByLockDuration | ByLockTime
string denom = 2; // What token denomination are we looking for lockups of
// type of lock query, ByLockDuration | ByLockTime
Copy link
Member

Choose a reason for hiding this comment

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

Nice change, as we found out these don't get into the go docs. Can you also make an issue in this repo to update all of our proto files for this? (Moving comments above the line they affect, rather than in the same line, to the side?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created one here: #863

LockQueryType lock_query_type = 1;
// What token denomination are we looking for lockups of
string denom = 2;
// valid when query condition is ByDuration
google.protobuf.Duration duration = 3 [
(gogoproto.stdduration) = true,
Expand Down
12 changes: 12 additions & 0 deletions x/incentives/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func TestPerpetualGaugeNotExpireAfterDistribution(t *testing.T) {
Denom: "lptoken",
Duration: time.Second,
}

// mints coins so supply exists on chain
mintLPtokens := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)}
err = simapp.FundAccount(app.BankKeeper, ctx, addr, mintLPtokens)
require.NoError(t, err)

Comment on lines +35 to +38
Copy link
Member

Choose a reason for hiding this comment

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

Why are we minting / funding account here? I understand why it should be happening in setupGaugeForLPIncentives but I dont understand why we're minting LP Tokens here(Don't have opinions btw, really just curious)

Copy link
Contributor Author

@AlpinYukseloglu AlpinYukseloglu Feb 17, 2022

Choose a reason for hiding this comment

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

I think maybe the denom lptoken might be a bit misleading - I didn't pick apart what the entire test is doing and whether or not it is necessary for it to create a gauge that distributes to the denom lptoken, but since it does, we have to make sure the denom has supply on-chain since otherwise, CreateGauge fails due to the new check we've added. It shouldn't affect the test's direct functionality - it just makes sure that the test is compliant with the new constraint that we've added to CreateGauge.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, makes sense!

_, err = app.IncentivesKeeper.CreateGauge(ctx, true, addr, coins, distrTo, time.Now(), 1)
require.NoError(t, err)

Expand Down Expand Up @@ -62,6 +68,12 @@ func TestNonPerpetualGaugeExpireAfterDistribution(t *testing.T) {
Denom: "lptoken",
Duration: time.Second,
}

// mints coins so supply exists on chain
mintLPtokens := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)}
err = simapp.FundAccount(app.BankKeeper, ctx, addr, mintLPtokens)
require.NoError(t, err)

_, err = app.IncentivesKeeper.CreateGauge(ctx, false, addr, coins, distrTo, time.Now(), 1)
require.NoError(t, err)

Expand Down
6 changes: 6 additions & 0 deletions x/incentives/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func TestIncentivesExportGenesis(t *testing.T) {
startTime := time.Now()
err := simapp.FundAccount(app.BankKeeper, ctx, addr, coins)
require.NoError(t, err)

// mints coins so supply exists on chain
mintLPtokens := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)}
err = simapp.FundAccount(app.BankKeeper, ctx, addr, mintLPtokens)
require.NoError(t, err)

gaugeID, err := app.IncentivesKeeper.CreateGauge(ctx, true, addr, coins, distrTo, startTime, 1)
require.NoError(t, err)

Expand Down
8 changes: 8 additions & 0 deletions x/incentives/keeper/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"encoding/json"
"fmt"
"strings"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -100,6 +101,8 @@ func (k Keeper) SetGaugeWithRefKey(ctx sdk.Context, gauge *types.Gauge) error {

// CreateGauge create a gauge and send coins to the gauge
func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddress, coins sdk.Coins, distrTo lockuptypes.QueryCondition, startTime time.Time, numEpochsPaidOver uint64) (uint64, error) {

// Ensure that this gauge's duration is one of the allowed durations on chain
durations := k.GetLockableDurations(ctx)
if distrTo.LockQueryType == lockuptypes.ByDuration {
durationOk := false
Expand All @@ -114,6 +117,11 @@ func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddr
}
}

// Ensure that the denom this gauge pays out to exists on-chain
if !k.bk.HasSupply(ctx, distrTo.Denom) && !strings.Contains(distrTo.Denom, "osmovaloper") {
return 0, fmt.Errorf("denom does not exist: %s", distrTo.Denom)
}

gauge := types.Gauge{
Id: k.getLastGaugeID(ctx) + 1,
IsPerpetual: isPerpetual,
Expand Down
17 changes: 17 additions & 0 deletions x/incentives/keeper/gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ func (suite *KeeperTestSuite) TestInvalidDurationGaugeCreationValidation() {
suite.Require().NoError(err)
}

func (suite *KeeperTestSuite) TestNonExistentDenomGaugeCreation() {
suite.SetupTest()

addrNoSupply := sdk.AccAddress([]byte("Gauge_Creation_Addr_"))
addrs := suite.SetupManyLocks(1, defaultLiquidTokens, defaultLPTokens, defaultLockDuration)
distrTo := lockuptypes.QueryCondition{
LockQueryType: lockuptypes.ByDuration,
Denom: defaultLPDenom,
Duration: defaultLockDuration,
}
_, err := suite.app.IncentivesKeeper.CreateGauge(suite.ctx, false, addrNoSupply, defaultLiquidTokens, distrTo, time.Time{}, 1)
suite.Require().Error(err)

_, err = suite.app.IncentivesKeeper.CreateGauge(suite.ctx, false, addrs[0], defaultLiquidTokens, distrTo, time.Time{}, 1)
suite.Require().NoError(err)
}

// TODO: Make this test table driven
// OR if it needs to be script based,
// remove lots of boilerplate so this can actually be followed
Expand Down
6 changes: 6 additions & 0 deletions x/incentives/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func (suite *KeeperTestSuite) setupNewGaugeWithDuration(isPerpetual bool, coins
Denom: "lptoken",
Duration: duration,
}

// mints coins so supply exists on chain
mintCoins := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)}
err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr, mintCoins)
suite.Require().NoError(err)

numEpochsPaidOver := uint64(2)
if isPerpetual {
numEpochsPaidOver = uint64(1)
Expand Down
2 changes: 2 additions & 0 deletions x/incentives/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
type BankKeeper interface {
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins

HasSupply(ctx sdk.Context, denom string) bool

SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToManyAccounts(
ctx sdk.Context, senderModule string, recipientAddrs []sdk.AccAddress, amts []sdk.Coins,
Expand Down
6 changes: 6 additions & 0 deletions x/mint/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ func setupGaugeForLPIncentives(t *testing.T, app *osmoapp.OsmosisApp, ctx sdk.Co
Denom: "lptoken",
Duration: time.Second,
}

// mints coins so supply exists on chain
mintLPtokens := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)}
err = simapp.FundAccount(app.BankKeeper, ctx, addr, mintLPtokens)
require.NoError(t, err)

_, err = app.IncentivesKeeper.CreateGauge(ctx, true, addr, coins, distrTo, time.Now(), 1)
require.NoError(t, err)
}
6 changes: 6 additions & 0 deletions x/mint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func (suite *KeeperTestSuite) TestDistrAssetToDeveloperRewardsAddrWhenNotEmpty()
Denom: "lptoken",
Duration: time.Second,
}

// mints coins so supply exists on chain
mintLPtokens := sdk.Coins{sdk.NewInt64Coin(distrTo.Denom, 200)}
err = simapp.FundAccount(suite.app.BankKeeper, suite.ctx, gaugeCreator, mintLPtokens)
suite.Require().NoError(err)

gaugeId, err := suite.app.IncentivesKeeper.CreateGauge(suite.ctx, true, gaugeCreator, coins, distrTo, time.Now(), 1)
Comment on lines +87 to 91
Copy link
Member

Choose a reason for hiding this comment

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

Why are we minting / funding account here? I understand why it should be happening in setupGaugeForLPIncentives but I dont understand why we're minting LP Tokens here(Don't have opinions btw, really just curous)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

suite.NoError(err)
err = suite.app.PoolIncentivesKeeper.UpdateDistrRecords(suite.ctx, poolincentivestypes.DistrRecord{
Expand Down