diff --git a/go.mod b/go.mod index ee8730e1d84..db1690f28f1 100644 --- a/go.mod +++ b/go.mod @@ -128,7 +128,7 @@ require ( replace ( github.com/CosmWasm/wasmd => github.com/osmosis-labs/wasmd v0.22.0-osmo-alpha-0 // Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk v0.45.0x-osmo-v7 - github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220220082240-1b4ae82744ea + github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220221115656-75545ea8cb2d github.com/cosmos/iavl => github.com/osmosis-labs/iavl v0.17.3-osmo-v3 // Use osmosis fork of ibc-go diff --git a/go.sum b/go.sum index 7136a993e45..fcfede0a4a5 100644 --- a/go.sum +++ b/go.sum @@ -777,8 +777,8 @@ github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnh github.com/ory/dockertest/v3 v3.6.2/go.mod h1:EFLcVUOl8qCwp9NyDAcCDtq/QviLtYswW/VbWzUnTNE= github.com/osmosis-labs/bech32-ibc v0.2.0-rc2 h1:7xy1pLtNiF2KaRSkolayZf4z3OfCJsO3eqBtEAXg2VA= github.com/osmosis-labs/bech32-ibc v0.2.0-rc2/go.mod h1:0JCaioRNOVUiw7c3MngmKACnumaQ2sjPenXCnwxCttI= -github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220220082240-1b4ae82744ea h1:blDrOjZ2V46JEYWYr6Ikffc8euk/8uvL61hKC8zwAvQ= -github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220220082240-1b4ae82744ea/go.mod h1:HsD/JxengDcevHFRA+wlWgeM78Og3ZwYM+cya3yOa7c= +github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220221115656-75545ea8cb2d h1:Y0JpKFb4n04ViTMUGm7SO4OobWKr6dBB/l3cvuBe6EY= +github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220221115656-75545ea8cb2d/go.mod h1:HsD/JxengDcevHFRA+wlWgeM78Og3ZwYM+cya3yOa7c= github.com/osmosis-labs/iavl v0.17.3-osmo-v3 h1:q2Qv3+DK52w5b68I96VApHI05jBu7HeQK/YDttKh/jY= github.com/osmosis-labs/iavl v0.17.3-osmo-v3/go.mod h1:lJEOIlsd3sVO0JDyXWIXa9/Ur5FBscP26zJx0KxHjto= github.com/osmosis-labs/ibc-go/v2 v2.0.2-osmo h1:XyYyDTjPIu7qX2nhQp9mboj7Pa9FEnjg1RXw73Ctv5U= diff --git a/x/superfluid/keeper/stake.go b/x/superfluid/keeper/stake.go index 793d6558a6d..4004dc8bb50 100644 --- a/x/superfluid/keeper/stake.go +++ b/x/superfluid/keeper/stake.go @@ -275,6 +275,7 @@ func (k Keeper) mintOsmoTokensAndDelegate(ctx sdk.Context, osmoAmount sdk.Int, i if err != nil { return err } + k.bk.AddSupplyOffset(ctx, bondDenom, osmoAmount.Neg()) err = k.bk.SendCoinsFromModuleToAccount(ctx, types.ModuleName, intermediaryAccount.GetAccAddress(), coins) if err != nil { return err @@ -318,6 +319,8 @@ func (k Keeper) forceUndelegateAndBurnOsmoTokens(ctx sdk.Context, return err } err = k.bk.BurnCoins(ctx, types.ModuleName, undelegatedCoins) + bondDenom := k.sk.BondDenom(ctx) + k.bk.AddSupplyOffset(ctx, bondDenom, undelegatedCoins.AmountOf(bondDenom)) return err } diff --git a/x/superfluid/keeper/stake_test.go b/x/superfluid/keeper/stake_test.go index 7a8fbcbbfb8..99f8178f15e 100644 --- a/x/superfluid/keeper/stake_test.go +++ b/x/superfluid/keeper/stake_test.go @@ -207,16 +207,29 @@ func (suite *KeeperTestSuite) TestSuperfluidDelegate() { poolId := suite.createGammPool([]string{appparams.BaseCoinUnit, "foo"}) suite.Require().Equal(poolId, uint64(1)) + bondDenom := suite.app.StakingKeeper.BondDenom(suite.ctx) // Generate delegator addresses delAddrs := CreateRandomAccounts(1) // setup validators valAddrs := suite.SetupValidators(tc.validatorStats) + + // get pre-superfluid delgations osmo supply and supplyWithOffset + presupply := suite.app.BankKeeper.GetSupply(suite.ctx, bondDenom) + presupplyWithOffset := suite.app.BankKeeper.GetSupplyWithOffset(suite.ctx, bondDenom) + + // setup superfluid delegations intermediaryAccs, locks := suite.SetupSuperfluidDelegations(delAddrs, valAddrs, tc.superDelegations) + + // ensure post-superfluid delegations osmo supplywithoffset is the same while supply is not + postsupply := suite.app.BankKeeper.GetSupply(suite.ctx, bondDenom) + postsupplyWithOffset := suite.app.BankKeeper.GetSupplyWithOffset(suite.ctx, bondDenom) + suite.Require().False(postsupply.IsEqual(presupply), "presupply: %s postsupply: %s", presupply, postsupply) + suite.Require().True(postsupplyWithOffset.IsEqual(presupplyWithOffset)) + unbondingDuration := suite.app.StakingKeeper.GetParams(suite.ctx).UnbondingTime - // setup superfluid delegations for index, del := range tc.superDelegations { lock := locks[index] valAddr := valAddrs[del.valIndex] @@ -359,6 +372,7 @@ func (suite *KeeperTestSuite) TestSuperfluidUndelegate() { poolId := suite.createGammPool([]string{appparams.BaseCoinUnit, "foo"}) suite.Require().Equal(poolId, uint64(1)) + bondDenom := suite.app.StakingKeeper.BondDenom(suite.ctx) // Generate delegator addresses delAddrs := CreateRandomAccounts(1) @@ -393,6 +407,10 @@ func (suite *KeeperTestSuite) TestSuperfluidUndelegate() { lock = &lockuptypes.PeriodLock{} } + // get pre-superfluid delgations osmo supply and supplyWithOffset + presupply := suite.app.BankKeeper.GetSupply(suite.ctx, bondDenom) + presupplyWithOffset := suite.app.BankKeeper.GetSupplyWithOffset(suite.ctx, bondDenom) + // superfluid undelegate err = suite.app.SuperfluidKeeper.SuperfluidUndelegate(suite.ctx, lock.Owner, lockId) if tc.expSuperUnbondingErr[index] { @@ -401,6 +419,12 @@ func (suite *KeeperTestSuite) TestSuperfluidUndelegate() { } suite.Require().NoError(err) + // ensure post-superfluid delegations osmo supplywithoffset is the same while supply is not + postsupply := suite.app.BankKeeper.GetSupply(suite.ctx, bondDenom) + postsupplyWithOffset := suite.app.BankKeeper.GetSupplyWithOffset(suite.ctx, bondDenom) + suite.Require().False(postsupply.IsEqual(presupply), "presupply: %s postsupply: %s", presupply, postsupply) + suite.Require().True(postsupplyWithOffset.IsEqual(presupplyWithOffset)) + // check lockId and intermediary account connection deletion addr := suite.app.SuperfluidKeeper.GetLockIdIntermediaryAccountConnection(suite.ctx, lockId) suite.Require().Equal(addr.String(), "") @@ -689,6 +713,7 @@ func (suite *KeeperTestSuite) TestRefreshIntermediaryDelegationAmounts() { params := suite.app.SuperfluidKeeper.GetParams(suite.ctx) poolId := suite.createGammPool([]string{appparams.BaseCoinUnit, "foo"}) suite.Require().Equal(poolId, uint64(1)) + bondDenom := suite.app.StakingKeeper.BondDenom(suite.ctx) // Generate delegator addresses delAddrs := CreateRandomAccounts(1) @@ -723,11 +748,21 @@ func (suite *KeeperTestSuite) TestRefreshIntermediaryDelegationAmounts() { CurrentEpoch: 2, }) + // get pre-superfluid delgations osmo supply and supplyWithOffset + presupply := suite.app.BankKeeper.GetSupply(suite.ctx, bondDenom) + presupplyWithOffset := suite.app.BankKeeper.GetSupplyWithOffset(suite.ctx, bondDenom) + // refresh intermediary account delegations suite.NotPanics(func() { suite.app.SuperfluidKeeper.RefreshIntermediaryDelegationAmounts(suite.ctx) }) + // ensure post-superfluid delegations osmo supplywithoffset is the same while supply is not + postsupply := suite.app.BankKeeper.GetSupply(suite.ctx, bondDenom) + postsupplyWithOffset := suite.app.BankKeeper.GetSupplyWithOffset(suite.ctx, bondDenom) + suite.Require().False(postsupply.IsEqual(presupply), "presupply: %s postsupply: %s", presupply, postsupply) + suite.Require().True(postsupplyWithOffset.IsEqual(presupplyWithOffset)) + originTwap := sdk.NewDec(20) targetDelegations := []sdk.Dec{} targetAmounts := []sdk.Int{} diff --git a/x/superfluid/types/expected_keepers.go b/x/superfluid/types/expected_keepers.go index 02ff695660f..3801e536263 100644 --- a/x/superfluid/types/expected_keepers.go +++ b/x/superfluid/types/expected_keepers.go @@ -47,6 +47,9 @@ type BankKeeper interface { GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error + GetSupplyOffset(ctx sdk.Context, denom string) sdk.Int + AddSupplyOffset(ctx sdk.Context, denom string, offsetAmount sdk.Int) + GetSupplyWithOffset(ctx sdk.Context, denom string) sdk.Coin SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error }