Skip to content

Commit

Permalink
chore(lint): fix all linter issues; add return check; re-enable in CI…
Browse files Browse the repository at this point in the history
… (backport #6112) (#6243)

Co-authored-by: Roman <[email protected]>
  • Loading branch information
mergify[bot] and p0mvn authored Sep 1, 2023
1 parent 51c14ba commit 5e781a8
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 175 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ jobs:
-
name: Check out repository code
uses: actions/checkout@v3
-
uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
.github/**
Makefile
-
name: 🐿 Setup Golang
uses: actions/setup-go@v4
with:
go-version: ${{env.GO_VERSION}}
-
uses: technote-space/[email protected]
if: env.GIT_DIFF
with:
PATTERNS: |
**/**.go
go.mod
go.sum
.github/**
Makefile

-
name: Run golangci-lint
if: env.GIT_DIFF
Expand Down
11 changes: 10 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ linters:
enable:
- asciicheck
- bidichk
- depguard
- durationcheck
- errcheck
- errname
Expand Down Expand Up @@ -41,6 +40,16 @@ linters:
- unused
- whitespace
- unparam
- revive

linters-settings:
revive:
rules:
- name: function-result-limit
severity: warning
disabled: false
# limits the number of returns to 4
arguments: [4]

issues:
exclude-rules:
Expand Down
44 changes: 28 additions & 16 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import (
poolmanagertypes "github.com/osmosis-labs/osmosis/v18/x/poolmanager/types"
)

// clPoolCreationInfo encapsulates the returns from CL pool
// creation function.
type clPoolCreationInfo struct {
id uint64
denom string
migrationLink gammmigration.BalancerToConcentratedPoolLink
}

const (
mainnetChainID = "osmosis-1"
e2eChainA = "osmo-test-a"
Expand Down Expand Up @@ -82,26 +90,26 @@ func CreateUpgradeHandler(
fullRangeCoinsUsed := sdk.Coins{}

for _, assetPair := range assetPairs {
clPoolDenom, clPoolId, poolLink, coinsUsed, err := createCLPoolWithCommunityPoolPosition(ctx, keepers, assetPair, communityPoolAddress)
clPoolCreationInfo, coinsUsed, err := createCLPoolWithCommunityPoolPosition(ctx, keepers, assetPair, communityPoolAddress)
if errors.Is(err, notEnoughLiquidityForSwapErr) {
continue
} else if err != nil {
return nil, err
}

// Track pool link created and coins used for the community pool.
poolLinks = append(poolLinks, poolLink)
poolLinks = append(poolLinks, clPoolCreationInfo.migrationLink)
fullRangeCoinsUsed = fullRangeCoinsUsed.Add(coinsUsed...)

if assetPair.Superfluid {
ctx.Logger().Info(fmt.Sprintf("gammPoolId %d is superfluid enabled, enabling %s as a superfluid asset", assetPair.LinkedClassicPool, clPoolDenom))
err := authorizeSuperfluid(ctx, keepers, clPoolDenom)
ctx.Logger().Info(fmt.Sprintf("gammPoolId %d is superfluid enabled, enabling %s as a superfluid asset", assetPair.LinkedClassicPool, clPoolCreationInfo.denom))
err := authorizeSuperfluid(ctx, keepers, clPoolCreationInfo.denom)
if err != nil {
return nil, err
}
}

err = manuallySetTWAPRecords(ctx, keepers, clPoolId)
err = manuallySetTWAPRecords(ctx, keepers, clPoolCreationInfo.id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -138,7 +146,7 @@ func CreateUpgradeHandler(
}

// createCLPoolWithCommunityPoolPosition creates a CL pool for a given balancer pool and adds a full range position with the community pool.
func createCLPoolWithCommunityPoolPosition(ctx sdk.Context, keepers *keepers.AppKeepers, assetPair AssetPair, communityPoolAddress sdk.AccAddress) (clPoolDenom string, clPoolId uint64, poolLink gammmigration.BalancerToConcentratedPoolLink, coinsUsed sdk.Coins, err error) {
func createCLPoolWithCommunityPoolPosition(ctx sdk.Context, keepers *keepers.AppKeepers, assetPair AssetPair, communityPoolAddress sdk.AccAddress) (clPoolCreationInfo, sdk.Coins, error) {
// Determine if base or quote asset is OSMO and save the non-OSMO asset.
osmoIn := sdk.NewCoin(OSMO, sdk.NewInt(100000))
nonOsmoAsset := ""
Expand All @@ -152,24 +160,24 @@ func createCLPoolWithCommunityPoolPosition(ctx sdk.Context, keepers *keepers.App
// If not, skip the pool.
linkedClassicPool, err := keepers.PoolManagerKeeper.GetPool(ctx, assetPair.LinkedClassicPool)
if err != nil {
return "", 0, gammmigration.BalancerToConcentratedPoolLink{}, nil, err
return clPoolCreationInfo{}, sdk.Coins{}, err
}
_, err = keepers.GAMMKeeper.CalcOutAmtGivenIn(ctx, linkedClassicPool, osmoIn, nonOsmoAsset, assetPair.SpreadFactor)
if err != nil {
return "", 0, gammmigration.BalancerToConcentratedPoolLink{}, nil, err
return clPoolCreationInfo{}, sdk.Coins{}, err
}

// Create a concentrated liquidity pool for asset pair.
ctx.Logger().Info(fmt.Sprintf("Creating CL pool from poolID (%d), baseAsset (%s), quoteAsset (%s) spreadFactor (%s), tickSpacing (%d)", assetPair.LinkedClassicPool, assetPair.BaseAsset, assetPair.QuoteAsset, assetPair.SpreadFactor, TickSpacing))
clPool, err := keepers.GAMMKeeper.CreateConcentratedPoolFromCFMM(ctx, assetPair.LinkedClassicPool, assetPair.BaseAsset, assetPair.SpreadFactor, TickSpacing)
if err != nil {
return "", 0, gammmigration.BalancerToConcentratedPoolLink{}, nil, err
return clPoolCreationInfo{}, sdk.Coins{}, err
}
clPoolId = clPool.GetId()
clPoolDenom = cltypes.GetConcentratedLockupDenomFromPoolId(clPoolId)
clPoolId := clPool.GetId()
clPoolDenom := cltypes.GetConcentratedLockupDenomFromPoolId(clPoolId)

// Create pool link object.
poolLink = gammmigration.BalancerToConcentratedPoolLink{
poolLink := gammmigration.BalancerToConcentratedPoolLink{
BalancerPoolId: assetPair.LinkedClassicPool,
ClPoolId: clPoolId,
}
Expand All @@ -182,7 +190,7 @@ func createCLPoolWithCommunityPoolPosition(ctx sdk.Context, keepers *keepers.App
// Swap 0.1 OSMO for nonOsmoAsset from the community pool.
respectiveNonOsmoAssetInt, err := keepers.GAMMKeeper.SwapExactAmountIn(ctx, communityPoolAddress, linkedClassicPool, osmoIn, nonOsmoAsset, sdk.ZeroInt(), linkedClassicPool.GetSpreadFactor(ctx))
if err != nil {
return "", 0, gammmigration.BalancerToConcentratedPoolLink{}, nil, err
return clPoolCreationInfo{}, sdk.Coins{}, err
}
ctx.Logger().Info(fmt.Sprintf("Swapped %s for %s%s from the community pool", osmoIn.String(), respectiveNonOsmoAssetInt.String(), nonOsmoAsset))

Expand All @@ -192,7 +200,7 @@ func createCLPoolWithCommunityPoolPosition(ctx sdk.Context, keepers *keepers.App
fullRangeCoins := sdk.NewCoins(respectiveNonOsmoAsset, osmoIn)
_, err = keepers.ConcentratedLiquidityKeeper.CreateFullRangePosition(ctx, clPoolId, communityPoolAddress, fullRangeCoins)
if err != nil {
return "", 0, gammmigration.BalancerToConcentratedPoolLink{}, nil, err
return clPoolCreationInfo{}, sdk.Coins{}, err
}

// Get community pool balance after swap and position creation
Expand All @@ -203,9 +211,13 @@ func createCLPoolWithCommunityPoolPosition(ctx sdk.Context, keepers *keepers.App
// While we can be fairly certain the diff between these two is 0.2 OSMO, if for whatever reason
// some baseAsset dust remains in the community pool and we don't account for it, when updating the
// fee pool balance later, we will be off by that amount and will cause a panic.
coinsUsed = commPoolBalancePre.Sub(commPoolBalancePost)
coinsUsed := commPoolBalancePre.Sub(commPoolBalancePost)

return clPoolDenom, clPoolId, poolLink, coinsUsed, nil
return clPoolCreationInfo{
id: clPoolId,
denom: clPoolDenom,
migrationLink: poolLink,
}, coinsUsed, nil
}

// authorizeSuperfluid authorizes superfluid for the provided CL pool.
Expand Down
24 changes: 21 additions & 3 deletions tests/e2e/configurer/chain/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ import (
epochstypes "github.com/osmosis-labs/osmosis/x/epochs/types"
)

// PropTallyResult is the result of a proposal tally.
type PropTallyResult struct {
Yes sdk.Int
No sdk.Int
Abstain sdk.Int
NoWithVeto sdk.Int
}

// QueryProtoRevNumberOfTrades gets the number of trades the protorev module has executed.
func (n *NodeConfig) QueryProtoRevNumberOfTrades() (sdk.Int, error) {
path := "/osmosis/protorev/number_of_trades"
Expand Down Expand Up @@ -443,21 +451,31 @@ func (n *NodeConfig) QueryWasmSmartArray(contract string, msg string) (resultArr
return resultArray, nil
}

func (n *NodeConfig) QueryPropTally(proposalNumber int) (sdk.Int, sdk.Int, sdk.Int, sdk.Int, error) {
func (n *NodeConfig) QueryPropTally(proposalNumber int) (PropTallyResult, error) {
path := fmt.Sprintf("cosmos/gov/v1beta1/proposals/%d/tally", proposalNumber)
bz, err := n.QueryGRPCGateway(path)
require.NoError(n.t, err)

var balancesResp govtypes.QueryTallyResultResponse
if err := util.Cdc.UnmarshalJSON(bz, &balancesResp); err != nil {
return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), err
return PropTallyResult{
Yes: sdk.ZeroInt(),
No: sdk.ZeroInt(),
Abstain: sdk.ZeroInt(),
NoWithVeto: sdk.ZeroInt(),
}, err
}
noTotal := balancesResp.Tally.No
yesTotal := balancesResp.Tally.Yes
noWithVetoTotal := balancesResp.Tally.NoWithVeto
abstainTotal := balancesResp.Tally.Abstain

return noTotal, yesTotal, noWithVetoTotal, abstainTotal, nil
return PropTallyResult{
Yes: yesTotal,
No: noTotal,
Abstain: abstainTotal,
NoWithVeto: noWithVetoTotal,
}, nil
}

func (n *NodeConfig) QueryPropStatus(proposalNumber int) (string, error) {
Expand Down
9 changes: 5 additions & 4 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,11 +1001,11 @@ func (s *IntegrationTestSuite) SuperfluidVoting() {

s.Eventually(
func() bool {
noTotal, yesTotal, noWithVetoTotal, abstainTotal, err := chainABNode.QueryPropTally(propNumber)
propTally, err := chainABNode.QueryPropTally(propNumber)
if err != nil {
return false
}
if abstainTotal.Int64()+noTotal.Int64()+noWithVetoTotal.Int64()+yesTotal.Int64() <= 0 {
if propTally.Abstain.Int64()+propTally.No.Int64()+propTally.NoWithVeto.Int64()+propTally.Yes.Int64() <= 0 {
return false
}
return true
Expand All @@ -1014,8 +1014,9 @@ func (s *IntegrationTestSuite) SuperfluidVoting() {
10*time.Millisecond,
"Osmosis node failed to retrieve prop tally",
)
noTotal, _, _, _, _ := chainABNode.QueryPropTally(propNumber)
noTotalFinal, err := strconv.Atoi(noTotal.String())
propTally, err := chainABNode.QueryPropTally(propNumber)
s.Require().NoError(err)
noTotalFinal, err := strconv.Atoi(propTally.No.String())
s.NoError(err)

s.Eventually(
Expand Down
4 changes: 2 additions & 2 deletions x/concentrated-liquidity/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (k Keeper) ComputeOutAmtGivenIn(
spreadFactor sdk.Dec,
priceLimit sdk.Dec,

) (calcTokenIn, calcTokenOut sdk.Coin, poolUpdates PoolUpdates, totalSpreadRewards sdk.Dec, err error) {
) (swapResult SwapResult, poolUpdates PoolUpdates, err error) {
return k.computeOutAmtGivenIn(ctx, poolId, tokenInMin, tokenOutDenom, spreadFactor, priceLimit)
}

Expand All @@ -95,7 +95,7 @@ func (k Keeper) ComputeInAmtGivenOut(
priceLimit sdk.Dec,
poolId uint64,

) (calcTokenIn, calcTokenOut sdk.Coin, poolUpdates PoolUpdates, totalSpreadRewards sdk.Dec, err error) {
) (swapResult SwapResult, poolUpdates PoolUpdates, err error) {
return k.computeInAmtGivenOut(ctx, desiredTokenOut, tokenInDenom, spreadFactor, priceLimit, poolId)
}

Expand Down
Loading

0 comments on commit 5e781a8

Please sign in to comment.