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

bank supply offsets #923

Merged
merged 4 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20220221090813-bc8e132da48f

github.com/cosmos/iavl => github.com/osmosis-labs/iavl v0.17.3-osmo-v3
// Use osmosis fork of ibc-go
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20220221090813-bc8e132da48f h1:IPutMMmYqxRTjEVTA15cINks9zANGE2Grf7nWACxfko=
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20220221090813-bc8e132da48f/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=
Expand Down
3 changes: 3 additions & 0 deletions x/superfluid/keeper/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,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
Expand Down Expand Up @@ -353,6 +354,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
}

Expand Down
37 changes: 36 additions & 1 deletion x/superfluid/keeper/stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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] {
Expand All @@ -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(), "")
Expand Down Expand Up @@ -690,6 +714,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)
Expand Down Expand Up @@ -724,11 +749,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{}
Expand Down
3 changes: 3 additions & 0 deletions x/superfluid/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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
}
Expand Down