From 7a1cd8cb0ed3824d8dd839d861bf5d3dac117892 Mon Sep 17 00:00:00 2001 From: Eric Bolten Date: Thu, 14 Dec 2023 14:26:20 -0800 Subject: [PATCH] Further v7 upgrade updates (#246) * manually call Validate on the genesis states * point to gravity v4.0.0 release * fix casing for some cellars, add Turbo EETH * update slices sizes with new cellar added * log the ICA host param update * actually validate the minimum USD value parameter * normalize cellars with eth mainnet chain ID prefix * add arbitrum test cellar to pubsub * Add test arbitrum cellar to axelarcork * some comments * loosen ProofURL validation * fix auction params test * set LastUpdatedBlock for token prices in v7 upgrade * ledger support for cork * GetSignBytes for cork * appease linter --- app/upgrades/v7/upgrades.go | 97 ++++++++++++++++++++++++---------- go.mod | 2 +- go.sum | 2 + x/auction/keeper/keeper.go | 2 + x/auction/types/params.go | 4 ++ x/auction/types/params_test.go | 4 ++ x/cork/types/codec.go | 24 +++++++++ x/cork/types/msgs.go | 2 +- x/pubsub/types/proposal.go | 7 +-- 9 files changed, 110 insertions(+), 34 deletions(-) diff --git a/app/upgrades/v7/upgrades.go b/app/upgrades/v7/upgrades.go index c229cabb..e87c352f 100644 --- a/app/upgrades/v7/upgrades.go +++ b/app/upgrades/v7/upgrades.go @@ -1,6 +1,7 @@ package v7 import ( + "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -33,6 +34,7 @@ func CreateUpgradeHandler( // Now that we're on IBC V6, we can update the ICA host module to allow all message types rather than // the list we specified in the v6 upgrade -- a default of HostEnabled: true and the string "*" for messages + ctx.Logger().Info("v7 upgrade: setting ICA host params to allow all messages") icaParams := icahosttypes.DefaultParams() icaHostKeeper.SetParams(ctx, icaParams) @@ -48,7 +50,6 @@ func CreateUpgradeHandler( ctx.Logger().Info("v7 upgrading: setting cellarfees default params") cellarfeesKeeper.SetParams(ctx, cellarfeestypes.DefaultParams()) - //TODO(bolten): verify that the default params are fine or if we need to customize them for auction and pubsub ctx.Logger().Info("v7 upgrade: initializing auction genesis state") auctionInitGenesis(ctx, auctionKeeper) @@ -72,8 +73,8 @@ func auctionInitGenesis(ctx sdk.Context, auctionKeeper auctionkeeper.Keeper) { btc52WeekHigh := sdk.MustNewDecFromStr("44202.18") oneDollar := sdk.MustNewDecFromStr("1.0") - // TODO(bolten): update LastUpdatedBlock to the upgrade height when finalized - var lastUpdatedBlock uint64 = 1 + // Setting this to a block on 12/14/23 -- just means token price will get stale 4 days faster post-upgrade + var lastUpdatedBlock uint64 = 12187266 usommPrice := auctiontypes.TokenPrice{ Denom: "usomm", @@ -136,6 +137,10 @@ func auctionInitGenesis(ctx sdk.Context, auctionKeeper auctionkeeper.Keeper) { &wbtcPrice, } + if err := genesisState.Validate(); err != nil { + panic(fmt.Errorf("auction genesis state invalid: %s", err)) + } + auctionkeeper.InitGenesis(ctx, auctionKeeper, genesisState) } @@ -186,6 +191,34 @@ func axelarcorkInitGenesis(ctx sdk.Context, axelarcorkKeeper axelarcorkkeeper.Ke }, } + // InitGenesis reads through each chain configuration in order and sets the cellar ID set + // for it based on index, so this list must be of the same size and order as the respective + // chain configurations above + genesisState.CellarIds = []*axelarcorktypes.CellarIDSet{ + { + Ids: []string{"0x438087f7c226A89762a791F187d7c3D4a0e95ae6"}, // arbitrum test cellar + }, + { + Ids: []string{}, + }, + { + Ids: []string{}, + }, + { + Ids: []string{}, + }, + { + Ids: []string{}, + }, + { + Ids: []string{}, + }, + } + + if err := genesisState.Validate(); err != nil { + panic(fmt.Errorf("axelarcork genesis state invalid: %s", err)) + } + axelarcorkkeeper.InitGenesis(ctx, axelarcorkKeeper, genesisState) } @@ -204,33 +237,35 @@ func pubsubInitGenesis(ctx sdk.Context, pubsubKeeper pubsubkeeper.Keeper) { publishers := []*pubsubtypes.Publisher{&publisher} cellars := []string{ - "0x7bAD5DF5E11151Dc5Ee1a648800057C5c934c0d5", // Aave V2 - "0x03df2A53Cbed19B824347D6a45d09016C2D1676a", // DeFi Stars - "0x6c51041A91C91C86f3F08a72cB4D3F67f1208897", // ETH Trend Growth - "0x6b7f87279982d919bbf85182ddeab179b366d8f2", // ETH-BTC Trend - "0x6e2dac3b9e9adc0cbbae2d0b9fd81952a8d33872", // ETH-BTC Momentum - "0xDBe19d1c3F21b1bB250ca7BDaE0687A97B5f77e6", // Fraximal - "0xC7b69E15D86C5c1581dacce3caCaF5b68cd6596F", // Real Yield 1INCH - "0x0274a704a6D9129F90A62dDC6f6024b33EcDad36", // Real Yield BTC - "0x18ea937aba6053bC232d9Ae2C42abE7a8a2Be440", // Real Yield ENS - "0xb5b29320d2Dde5BA5BAFA1EbcD270052070483ec", // Real Yield ETH - "0x4068BDD217a45F8F668EF19F1E3A1f043e4c4934", // Real Yield LINK - "0xcBf2250F33c4161e18D4A2FA47464520Af5216b5", // Real Yield SNX - "0x6A6AF5393DC23D7e3dB28D28Ef422DB7c40932B6", // Real Yield UNI - "0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", // Real Yield USD - "0x3F07A84eCdf494310D397d24c1C78B041D2fa622", // Steady ETH - "0x4986fD36b6b16f49b43282Ee2e24C5cF90ed166d", // Steady BTC - "0x05641a27C82799AaF22b436F20A3110410f29652", // Steady MATIC - "0x6f069f711281618467dae7873541ecc082761b33", // Steady UNI - "0x0C190DEd9Be5f512Bd72827bdaD4003e9Cc7975C", // Turbo GHO - "0x5195222f69c5821f8095ec565E71e18aB6A2298f", // Turbo SOMM - "0xc7372Ab5dd315606dB799246E8aA112405abAeFf", // Turbo stETH (stETH deposit) - "0xfd6db5011b171B05E1Ea3b92f9EAcaEEb055e971", // Turbo stETH (WETH deposit) - "0xd33dAd974b938744dAC81fE00ac67cb5AA13958E", // Turbo swETH + "1:0x7bAD5DF5E11151Dc5Ee1a648800057C5c934c0d5", // Aave V2 + "1:0x03df2A53Cbed19B824347D6a45d09016C2D1676a", // DeFi Stars + "1:0x6c51041A91C91C86f3F08a72cB4D3F67f1208897", // ETH Trend Growth + "1:0x6b7f87279982d919Bbf85182DDeAB179B366D8f2", // ETH-BTC Trend + "1:0x6E2dAc3b9E9ADc0CbbaE2D0B9Fd81952a8D33872", // ETH-BTC Momentum + "1:0xDBe19d1c3F21b1bB250ca7BDaE0687A97B5f77e6", // Fraximal + "1:0xC7b69E15D86C5c1581dacce3caCaF5b68cd6596F", // Real Yield 1INCH + "1:0x0274a704a6D9129F90A62dDC6f6024b33EcDad36", // Real Yield BTC + "1:0x18ea937aba6053bC232d9Ae2C42abE7a8a2Be440", // Real Yield ENS + "1:0xb5b29320d2Dde5BA5BAFA1EbcD270052070483ec", // Real Yield ETH + "1:0x4068BDD217a45F8F668EF19F1E3A1f043e4c4934", // Real Yield LINK + "1:0xcBf2250F33c4161e18D4A2FA47464520Af5216b5", // Real Yield SNX + "1:0x6A6AF5393DC23D7e3dB28D28Ef422DB7c40932B6", // Real Yield UNI + "1:0x97e6E0a40a3D02F12d1cEC30ebfbAE04e37C119E", // Real Yield USD + "1:0x3F07A84eCdf494310D397d24c1C78B041D2fa622", // Steady ETH + "1:0x4986fD36b6b16f49b43282Ee2e24C5cF90ed166d", // Steady BTC + "1:0x05641a27C82799AaF22b436F20A3110410f29652", // Steady MATIC + "1:0x6F069F711281618467dAe7873541EcC082761B33", // Steady UNI + "1:0x9a7b4980C6F0FCaa50CD5f288Ad7038f434c692e", // Turbo EETH + "1:0x0C190DEd9Be5f512Bd72827bdaD4003e9Cc7975C", // Turbo GHO + "1:0x5195222f69c5821f8095ec565E71e18aB6A2298f", // Turbo SOMM + "1:0xc7372Ab5dd315606dB799246E8aA112405abAeFf", // Turbo stETH (stETH deposit) + "1:0xfd6db5011b171B05E1Ea3b92f9EAcaEEb055e971", // Turbo stETH (WETH deposit) + "1:0xd33dAd974b938744dAC81fE00ac67cb5AA13958E", // Turbo swETH + "42161:0x438087f7c226A89762a791F187d7c3D4a0e95ae6", // Arbitrum test cellar } // Set 7seas publisher intents for existing cellars - publisherIntents := make([]*pubsubtypes.PublisherIntent, 23) + publisherIntents := make([]*pubsubtypes.PublisherIntent, 25) for _, cellar := range cellars { publisherIntents = append(publisherIntents, &pubsubtypes.PublisherIntent{ SubscriptionId: cellar, @@ -241,7 +276,7 @@ func pubsubInitGenesis(ctx sdk.Context, pubsubKeeper pubsubkeeper.Keeper) { } // Set default subscriptions for 7seas as the publisher for existing cellars - defaultSubscriptions := make([]*pubsubtypes.DefaultSubscription, 23) + defaultSubscriptions := make([]*pubsubtypes.DefaultSubscription, 25) for _, cellar := range cellars { defaultSubscriptions = append(defaultSubscriptions, &pubsubtypes.DefaultSubscription{ SubscriptionId: cellar, @@ -251,7 +286,7 @@ func pubsubInitGenesis(ctx sdk.Context, pubsubKeeper pubsubkeeper.Keeper) { // Create subscribers and intents for existing validators subscribers := createSubscribers() - subscriberIntents := make([]*pubsubtypes.SubscriberIntent, 805) + subscriberIntents := make([]*pubsubtypes.SubscriberIntent, 875) for _, subscriber := range subscribers { for _, cellar := range cellars { subscriberIntents = append(subscriberIntents, &pubsubtypes.SubscriberIntent{ @@ -268,6 +303,10 @@ func pubsubInitGenesis(ctx sdk.Context, pubsubKeeper pubsubkeeper.Keeper) { genesisState.Subscribers = subscribers genesisState.SubscriberIntents = subscriberIntents + if err := genesisState.Validate(); err != nil { + panic(fmt.Errorf("pubsub genesis state invalid: %s", err)) + } + pubsubkeeper.InitGenesis(ctx, pubsubKeeper, genesisState) } diff --git a/go.mod b/go.mod index 6e7653c6..b5ad5ff1 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/ory/dockertest/v3 v3.10.0 - github.com/peggyjv/gravity-bridge/module/v4 v4.0.0-20231211214131-bf2a31eb986f + github.com/peggyjv/gravity-bridge/module/v4 v4.0.0 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 github.com/spf13/cast v1.5.0 diff --git a/go.sum b/go.sum index 762108e5..7eb30ae3 100644 --- a/go.sum +++ b/go.sum @@ -846,6 +846,8 @@ github.com/peggyjv/gravity-bridge/module/v4 v4.0.0-20231130211750-e1fa9902c9d9 h github.com/peggyjv/gravity-bridge/module/v4 v4.0.0-20231130211750-e1fa9902c9d9/go.mod h1:biwoVDKWggMYtzuUZOuqaJD8B40XHrXg3zOJjeAhT78= github.com/peggyjv/gravity-bridge/module/v4 v4.0.0-20231211214131-bf2a31eb986f h1:xaVjypGpS3+VUXzEb2YFaTK632Id6jVWY1ViS4nljJs= github.com/peggyjv/gravity-bridge/module/v4 v4.0.0-20231211214131-bf2a31eb986f/go.mod h1:n8Jj3X+w6q0Xz19w8feRRl2sfIGV+3FGU4anzXBQGbA= +github.com/peggyjv/gravity-bridge/module/v4 v4.0.0 h1:jH10FodlMxzGdbxAxeNpsql9qhYDlmwqciwOuwuU0LQ= +github.com/peggyjv/gravity-bridge/module/v4 v4.0.0/go.mod h1:n8Jj3X+w6q0Xz19w8feRRl2sfIGV+3FGU4anzXBQGbA= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index 49edb1de..b3390f78 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -224,6 +224,8 @@ func (k Keeper) BeginAuction(ctx sdk.Context, // determine how many usomm each sale token min unit costs saleTokenPriceInUsomm := saleTokenMinUnitValue.Quo(usommMinUnitValue) + // TODO(bolten): we are not inspecting the MinimumSaleTokensUsdValue param and using it -- implement later? + auctionID := k.GetLastAuctionID(ctx) + 1 auction := types.Auction{ Id: auctionID, diff --git a/x/auction/types/params.go b/x/auction/types/params.go index 7338b5f4..c6d35537 100644 --- a/x/auction/types/params.go +++ b/x/auction/types/params.go @@ -54,6 +54,10 @@ func (p *Params) ValidateBasic() error { return err } + if err := validateMinimumSaleTokensUSDValue(p.MinimumSaleTokensUsdValue); err != nil { + return err + } + if err := validateAuctionMaxBlockAge(p.AuctionMaxBlockAge); err != nil { return err } diff --git a/x/auction/types/params_test.go b/x/auction/types/params_test.go index e60abf87..cc28c74f 100644 --- a/x/auction/types/params_test.go +++ b/x/auction/types/params_test.go @@ -26,6 +26,7 @@ func TestParamsValidate(t *testing.T) { params: Params{ PriceMaxBlockAge: uint64(1000), MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), }, @@ -37,6 +38,7 @@ func TestParamsValidate(t *testing.T) { params: Params{ PriceMaxBlockAge: uint64(0), MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), }, @@ -48,6 +50,7 @@ func TestParamsValidate(t *testing.T) { params: Params{ PriceMaxBlockAge: uint64(1000), MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("-0.01"), }, @@ -59,6 +62,7 @@ func TestParamsValidate(t *testing.T) { params: Params{ PriceMaxBlockAge: uint64(1000), MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("1.1"), }, diff --git a/x/cork/types/codec.go b/x/cork/types/codec.go index 4665a007..37661eeb 100644 --- a/x/cork/types/codec.go +++ b/x/cork/types/codec.go @@ -1,12 +1,36 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) +// RegisterLegacyAminoCodec registers the vesting interfaces and concrete types on the +// provided LegacyAmino codec. These types are used for Amino JSON serialization +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgScheduleCorkRequest{}, "cork/MsgScheduleCorkRequest", nil) +} + +var ( + amino = codec.NewLegacyAmino() + // ModuleCdc Note, the codec should ONLY be used in certain instances of tests and for + // JSON encoding as Amino is still used for that purpose. + // + // The actual codec used for serialization should be provided to x/staking and + // defined at the application level. + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + amino.Seal() +} + // RegisterInterfaces registers the cork proto files func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( diff --git a/x/cork/types/msgs.go b/x/cork/types/msgs.go index 56eca780..2bb8e5d2 100644 --- a/x/cork/types/msgs.go +++ b/x/cork/types/msgs.go @@ -49,7 +49,7 @@ func (m *MsgScheduleCorkRequest) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (m *MsgScheduleCorkRequest) GetSignBytes() []byte { - panic("amino support disabled") + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) } // GetSigners implements sdk.Msg diff --git a/x/pubsub/types/proposal.go b/x/pubsub/types/proposal.go index a073f70f..89bb990e 100644 --- a/x/pubsub/types/proposal.go +++ b/x/pubsub/types/proposal.go @@ -90,9 +90,10 @@ func ValidateProofURL(proofURL string, domain string, address string) error { return err } - validProofURL := fmt.Sprintf("https://%s/%s/cacert.pem", domain, address) - if proofURL != validProofURL { - return fmt.Errorf("invalid proof URL format, should be: %s", validProofURL) + validProofURL := fmt.Sprintf("%s/%s/cacert.pem", domain, address) + validProofURLWithHTTPS := fmt.Sprintf("https://%s", validProofURL) + if proofURL != validProofURL && proofURL != validProofURLWithHTTPS { + return fmt.Errorf("invalid proof URL format, should be: %s", validProofURLWithHTTPS) } return nil