Skip to content

Commit

Permalink
refactor: remove initia-labs dependencies (#203)
Browse files Browse the repository at this point in the history
## Description

This PR removes the `initia-labs/initia` and `initia-labs/opinit`
dependencies as they are no longer necessary.

Closes: MILK-153

<!-- Add a description of the changes that this PR introduces and the
files that
are the most critical to review. -->

---

### Author Checklist

*All items are required. Please add a note to the item if the item is
not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR
Targeting](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building
modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [ ] included the necessary unit and integration
[tests](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go
code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable
and please add
your handle next to the items reviewed if you only reviewed selected
items.*

I have...

- [ ] confirmed the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
RiccardoM authored Nov 26, 2024
1 parent bdf81e3 commit 7340f3c
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# most precedence.

# Primary repo maintainers
* @initia-labs/core
* @milkyway-labs/core
109 changes: 13 additions & 96 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@ package milkyway

import (
"encoding/json"
"time"

sdkmath "cosmossdk.io/math"
"github.com/cometbft/cometbft/crypto/secp256k1"
tmtypes "github.com/cometbft/cometbft/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/testutil/mock"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/initia-labs/initia/app/genesis_markets"
"slices"

"github.com/skip-mev/connect/v2/cmd/constants/marketmaps"
marketmaptypes "github.com/skip-mev/connect/v2/x/marketmap/types"
oracletypes "github.com/skip-mev/connect/v2/x/oracle/types"

Expand Down Expand Up @@ -48,17 +38,21 @@ func (genState GenesisState) AddMarketData(cdc codec.JSONCodec) GenesisState {
cdc.MustUnmarshalJSON(genState[marketmaptypes.ModuleName], &marketGenState)

// Load initial markets
markets, err := genesis_markets.ReadMarketsFromFile(genesis_markets.GenesisMarkets)
if err != nil {
panic(err)
coreMarkets := marketmaps.CoreMarketMap
markets := coreMarkets.Markets

// Sort keys so we can deterministically iterate over map items.
keys := make([]string, 0, len(markets))
for name := range markets {
keys = append(keys, name)
}
marketGenState.MarketMap = genesis_markets.ToMarketMap(markets)
slices.Sort(keys)

// Initialize all markets
var id uint64
currencyPairGenesis := make([]oracletypes.CurrencyPairGenesis, len(markets))
for i, market := range markets {
currencyPairGenesis[i] = oracletypes.CurrencyPairGenesis{
for _, market := range markets {
currencyPairGenesis[id] = oracletypes.CurrencyPairGenesis{
CurrencyPair: market.Ticker.CurrencyPair,
CurrencyPairPrice: nil,
Nonce: 0,
Expand Down Expand Up @@ -93,80 +87,3 @@ func (genState GenesisState) ConfigureIBCAllowedClients(cdc codec.JSONCodec) Gen

return genState
}

// NewDefaultGenesisStateWithValidator generates the default application state with a validator.
func NewDefaultGenesisStateWithValidator(cdc codec.Codec, mbm module.BasicManager) GenesisState {
privVal := mock.NewPV()
pubKey, _ := privVal.GetPubKey()
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
senderPrivKey.PubKey().Address()
acc := authtypes.NewBaseAccountWithAddress(senderPrivKey.PubKey().Address().Bytes())

//////////////////////
var balances []banktypes.Balance
genesisState := NewDefaultGenesisState(cdc, mbm)
genAccs := []authtypes.GenesisAccount{acc}
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = cdc.MustMarshalJSON(authGenesis)

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := sdk.DefaultPowerReduction

for _, val := range valSet.Validators {
pk, _ := cryptocodec.FromCmtPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: sdkmath.LegacyNewDec(1),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec()),
MinSelfDelegation: sdkmath.ZeroInt(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String(), sdkmath.LegacyNewDec(1)))
}
// set validators and delegations
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)
genesisState[stakingtypes.ModuleName] = cdc.MustMarshalJSON(stakingGenesis)

totalSupply := sdk.NewCoins()
for _, b := range balances {
// add genesis acc tokens to total supply
totalSupply = totalSupply.Add(b.Coins...)
}

for range delegations {
// add delegated tokens to total supply
totalSupply = totalSupply.Add(sdk.NewCoin(sdk.DefaultBondDenom, bondAmt))
}

// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, bondAmt)},
})

// update total supply
bankGenesis := banktypes.NewGenesisState(
banktypes.DefaultGenesisState().Params,
balances,
totalSupply,
[]banktypes.Metadata{},
[]banktypes.SendEnabled{},
)
genesisState[banktypes.ModuleName] = cdc.MustMarshalJSON(bankGenesis)

return genesisState
}
207 changes: 0 additions & 207 deletions app/test_helpers.go

This file was deleted.

6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ require (
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/go-metrics v0.5.3
github.com/initia-labs/OPinit v0.5.1
github.com/initia-labs/initia v0.5.1
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.20.5
github.com/rakyll/statik v0.1.7
Expand Down Expand Up @@ -161,6 +159,7 @@ require (
github.com/firefart/nonamedreturns v1.0.5 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fzipp/gocyclo v0.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/ghostiam/protogetter v0.3.6 // indirect
github.com/go-critic/go-critic v0.11.4 // indirect
Expand All @@ -169,6 +168,7 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-toolsmith/astcast v1.1.0 // indirect
github.com/go-toolsmith/astcopy v1.1.0 // indirect
github.com/go-toolsmith/astequal v1.2.0 // indirect
Expand All @@ -179,6 +179,7 @@ require (
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gobwas/ws v1.1.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gofrs/flock v0.12.1 // indirect
Expand Down Expand Up @@ -218,6 +219,7 @@ require (
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
Expand Down
Loading

0 comments on commit 7340f3c

Please sign in to comment.