Skip to content

Commit 8706ada

Browse files
committed
feat: set denom metadata and oracle assets during upgrade
1 parent b5e9c41 commit 8706ada

File tree

6 files changed

+193
-11
lines changed

6 files changed

+193
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ build-image: ## Build Docker image
8181
tools: ## Install development tools
8282
go install github.com/bufbuild/buf/cmd/[email protected]
8383
go install github.com/cosmos/gogoproto/[email protected]
84-
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0
84+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
8585
go install github.com/grpc-ecosystem/grpc-gateway/[email protected]

app/upgrade.go

Lines changed: 182 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ import (
3434
"github.com/cosmos/ibc-go/v7/modules/core/exported"
3535
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations"
3636

37+
"github.com/sentinel-official/sentinelhub/v12/third_party/osmosis/x/poolmanager/client/queryproto"
38+
protorevtypes "github.com/sentinel-official/sentinelhub/v12/third_party/osmosis/x/protorev/types"
39+
oraclekeeper "github.com/sentinel-official/sentinelhub/v12/x/oracle/keeper"
3740
oracletypes "github.com/sentinel-official/sentinelhub/v12/x/oracle/types"
41+
v1oracletypes "github.com/sentinel-official/sentinelhub/v12/x/oracle/types/v1"
3842
)
3943

4044
const (
41-
UpgradeName = "v12_0_0"
45+
preUpgradeProtocolVersion = 11
46+
UpgradeName = "v12_0_0"
4247
)
4348

4449
var (
@@ -57,6 +62,9 @@ func UpgradeHandler(
5762
cdc codec.Codec, mm *sdkmodule.Manager, configurator sdkmodule.Configurator, keepers Keepers,
5863
) upgradetypes.UpgradeHandler {
5964
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM sdkmodule.VersionMap) (sdkmodule.VersionMap, error) {
65+
versionSetter := keepers.UpgradeKeeper.GetVersionSetter()
66+
versionSetter.SetProtocolVersion(preUpgradeProtocolVersion)
67+
6068
keyTables := map[string]paramstypes.KeyTable{
6169
// Cosmos SDK subspaces
6270
authtypes.ModuleName: authtypes.ParamKeyTable(),
@@ -105,6 +113,13 @@ func UpgradeHandler(
105113
return nil, err
106114
}
107115

116+
mintParams := keepers.MintKeeper.GetParams(ctx)
117+
118+
mintParams.BlocksPerYear = (365.25 * 24 * 60 * 60) / 3
119+
if err := keepers.MintKeeper.SetParams(ctx, mintParams); err != nil {
120+
return nil, err
121+
}
122+
108123
stakingParams := keepers.StakingKeeper.GetParams(ctx)
109124

110125
stakingParams.MinCommissionRate = sdkmath.LegacyNewDecWithPrec(5, 2)
@@ -147,6 +162,14 @@ func UpgradeHandler(
147162
return nil, err
148163
}
149164

165+
if err := setDenomMetadata(ctx, keepers.BankKeeper); err != nil {
166+
return nil, err
167+
}
168+
169+
if err := setOracleAssets(ctx, keepers.OracleKeeper); err != nil {
170+
return nil, err
171+
}
172+
150173
return newVM, nil
151174
}
152175
}
@@ -308,7 +331,7 @@ func migrateFoundationAccount(
308331
ak.SetAccount(ctx, vestingAccount)
309332

310333
// Transfer spendable coins to new address
311-
toAddr, err := sdk.AccAddressFromBech32("")
334+
toAddr, err := sdk.AccAddressFromBech32("") // TODO: set addr
312335
if err != nil {
313336
return err
314337
}
@@ -323,3 +346,160 @@ func migrateFoundationAccount(
323346

324347
return nil
325348
}
349+
350+
func setDenomMetadata(ctx sdk.Context, k bankkeeper.Keeper) error {
351+
items := []banktypes.Metadata{
352+
{
353+
Description: "The native staking token of Sentinel Hub",
354+
DenomUnits: []*banktypes.DenomUnit{
355+
{Denom: "udvpn", Exponent: 0},
356+
{Denom: "mdvpn", Exponent: 3},
357+
{Denom: "dvpn", Exponent: 6},
358+
},
359+
Base: "udvpn",
360+
Display: "P2P",
361+
Name: "Sentinel",
362+
Symbol: "P2P",
363+
},
364+
{
365+
DenomUnits: []*banktypes.DenomUnit{
366+
{
367+
Denom: "ibc/A8C2D23A1E6F95DA4E48BA349667E322BD7A6C996D8A4AAE8BA72E190F3D1477",
368+
Exponent: 0,
369+
Aliases: []string{"uatom"},
370+
},
371+
},
372+
Base: "ibc/A8C2D23A1E6F95DA4E48BA349667E322BD7A6C996D8A4AAE8BA72E190F3D1477",
373+
Display: "ATOM",
374+
Name: "Cosmos",
375+
Symbol: "ATOM",
376+
},
377+
{
378+
DenomUnits: []*banktypes.DenomUnit{
379+
{
380+
Denom: "ibc/B1C0DDB14F25279A2026BC8794E12B259F8BDA546A3C5132CCAEE4431CE36783",
381+
Exponent: 0,
382+
Aliases: []string{"udec"},
383+
},
384+
},
385+
Base: "ibc/B1C0DDB14F25279A2026BC8794E12B259F8BDA546A3C5132CCAEE4431CE36783",
386+
Display: "DEC",
387+
Name: "Decentr",
388+
Symbol: "DEC",
389+
},
390+
{
391+
DenomUnits: []*banktypes.DenomUnit{
392+
{
393+
Denom: "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518",
394+
Exponent: 0,
395+
Aliases: []string{"uosmo"},
396+
},
397+
},
398+
Base: "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518",
399+
Display: "OSMO",
400+
Name: "Osmosis",
401+
Symbol: "OSMO",
402+
},
403+
{
404+
DenomUnits: []*banktypes.DenomUnit{
405+
{
406+
Denom: "ibc/31FEE1A2A9F9C01113F90BD0BBCCE8FD6BBB8585FAF109A2101827DD1D5B95B8",
407+
Exponent: 0,
408+
Aliases: []string{"uscrt"},
409+
},
410+
},
411+
Base: "ibc/31FEE1A2A9F9C01113F90BD0BBCCE8FD6BBB8585FAF109A2101827DD1D5B95B8",
412+
Display: "SCRT",
413+
Name: "Secret",
414+
Symbol: "SCRT",
415+
},
416+
}
417+
418+
for _, item := range items {
419+
k.SetDenomMetaData(ctx, item)
420+
}
421+
422+
return nil
423+
}
424+
425+
func setOracleAssets(ctx sdk.Context, k oraclekeeper.Keeper) error {
426+
// ATOM -> "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"
427+
// DEC -> "ibc/9BCB27203424535B6230D594553F1659C77EC173E36D9CF4759E7186EE747E84"
428+
// OSMO -> "uosmo"
429+
// P2P -> "ibc/9712DBB13B9631EDFA9BF61B55F1B2D290B2ADB67E3A4EB3A875F3B6081B3B84"
430+
// SCRT -> "ibc/0954E1C28EB7AF5B72D24F3BC2B47BBB2FDF91BDDFD57B74B99E133AED40972A"
431+
// USDC -> "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4"
432+
items := []v1oracletypes.Asset{
433+
{
434+
Denom: "udvpn",
435+
Decimals: 6,
436+
ProtoRevPoolRequest: protorevtypes.QueryGetProtoRevPoolRequest{
437+
BaseDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
438+
OtherDenom: "ibc/9712DBB13B9631EDFA9BF61B55F1B2D290B2ADB67E3A4EB3A875F3B6081B3B84",
439+
},
440+
SpotPriceRequest: queryproto.SpotPriceRequest{
441+
BaseAssetDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
442+
QuoteAssetDenom: "ibc/9712DBB13B9631EDFA9BF61B55F1B2D290B2ADB67E3A4EB3A875F3B6081B3B84",
443+
},
444+
SpotPrice: sdkmath.LegacyZeroDec(),
445+
},
446+
{
447+
Denom: "ibc/A8C2D23A1E6F95DA4E48BA349667E322BD7A6C996D8A4AAE8BA72E190F3D1477",
448+
Decimals: 6,
449+
ProtoRevPoolRequest: protorevtypes.QueryGetProtoRevPoolRequest{
450+
BaseDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
451+
OtherDenom: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
452+
},
453+
SpotPriceRequest: queryproto.SpotPriceRequest{
454+
BaseAssetDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
455+
QuoteAssetDenom: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
456+
},
457+
SpotPrice: sdkmath.LegacyZeroDec(),
458+
},
459+
{
460+
Denom: "ibc/B1C0DDB14F25279A2026BC8794E12B259F8BDA546A3C5132CCAEE4431CE36783",
461+
Decimals: 6,
462+
ProtoRevPoolRequest: protorevtypes.QueryGetProtoRevPoolRequest{
463+
BaseDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
464+
OtherDenom: "ibc/9BCB27203424535B6230D594553F1659C77EC173E36D9CF4759E7186EE747E84",
465+
},
466+
SpotPriceRequest: queryproto.SpotPriceRequest{
467+
BaseAssetDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
468+
QuoteAssetDenom: "ibc/9BCB27203424535B6230D594553F1659C77EC173E36D9CF4759E7186EE747E84",
469+
},
470+
SpotPrice: sdkmath.LegacyZeroDec(),
471+
},
472+
{
473+
Denom: "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518",
474+
Decimals: 6,
475+
ProtoRevPoolRequest: protorevtypes.QueryGetProtoRevPoolRequest{
476+
BaseDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
477+
OtherDenom: "uosmo",
478+
},
479+
SpotPriceRequest: queryproto.SpotPriceRequest{
480+
BaseAssetDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
481+
QuoteAssetDenom: "uosmo",
482+
},
483+
SpotPrice: sdkmath.LegacyZeroDec(),
484+
},
485+
{
486+
Denom: "ibc/31FEE1A2A9F9C01113F90BD0BBCCE8FD6BBB8585FAF109A2101827DD1D5B95B8",
487+
Decimals: 6,
488+
ProtoRevPoolRequest: protorevtypes.QueryGetProtoRevPoolRequest{
489+
BaseDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
490+
OtherDenom: "ibc/0954E1C28EB7AF5B72D24F3BC2B47BBB2FDF91BDDFD57B74B99E133AED40972A",
491+
},
492+
SpotPriceRequest: queryproto.SpotPriceRequest{
493+
BaseAssetDenom: "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
494+
QuoteAssetDenom: "ibc/0954E1C28EB7AF5B72D24F3BC2B47BBB2FDF91BDDFD57B74B99E133AED40972A",
495+
},
496+
SpotPrice: sdkmath.LegacyZeroDec(),
497+
},
498+
}
499+
500+
for _, item := range items {
501+
k.SetAsset(ctx, item)
502+
}
503+
504+
return nil
505+
}

cmd/sentinelhub/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func NewRootCmd(homeDir string) *cobra.Command {
8888
if err := overwriteTendermintConfig(); err != nil {
8989
return err
9090
}
91+
9192
if err := overwriteAppConfig(); err != nil {
9293
return err
9394
}

types/v1/price.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
sdk "github.com/cosmos/cosmos-sdk/types"
1212
)
1313

14-
// QuotePriceFunc defines a function signature for converting a base price to a quote price.
15-
type QuotePriceFunc func(ctx context.Context, basePrice sdk.DecCoin) (sdk.Coin, error)
14+
// GetQuotePriceFunc defines a function signature for converting a base price to a quote price.
15+
type GetQuotePriceFunc func(ctx context.Context, basePrice sdk.DecCoin) (sdk.Coin, error)
1616

1717
// NewPriceFromString parses a string like "denom:base,quote" into a Price.
1818
func NewPriceFromString(s string) (Price, error) {
@@ -218,7 +218,7 @@ func (p Price) Sub(v Price) Price {
218218
}
219219

220220
// UpdateQuoteValue applies a pricing function to compute a new quote value from the base.
221-
func (p Price) UpdateQuoteValue(ctx context.Context, fn QuotePriceFunc) (Price, error) {
221+
func (p Price) UpdateQuoteValue(ctx context.Context, fn GetQuotePriceFunc) (Price, error) {
222222
// If BaseValue is zero, return the original Price
223223
if p.BaseValue.IsZero() {
224224
return p, nil
@@ -228,21 +228,21 @@ func (p Price) UpdateQuoteValue(ctx context.Context, fn QuotePriceFunc) (Price,
228228
basePrice := p.BasePrice()
229229

230230
// Compute the new quote value using the provided function
231-
newQuote, err := fn(ctx, basePrice)
231+
quotePrice, err := fn(ctx, basePrice)
232232
if err != nil {
233233
return Price{}, err
234234
}
235235

236-
// If newQuote is zero, return the original Price
237-
if newQuote.IsZero() {
236+
// If quotePrice is zero, return the original Price
237+
if quotePrice.IsZero() {
238238
return p, nil
239239
}
240240

241241
// Return a new Price instance with the updated QuoteValue
242242
return Price{
243243
Denom: p.Denom,
244244
BaseValue: p.BaseValue,
245-
QuoteValue: newQuote.Amount,
245+
QuoteValue: quotePrice.Amount,
246246
}, nil
247247
}
248248

x/provider/client/cli/query.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func queryProviders() *cobra.Command {
7171
cmd.Context(),
7272
v2.NewQueryProvidersRequest(status, pagination),
7373
)
74-
7574
if err != nil {
7675
return err
7776
}

x/swap/types/v1/params.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (m *Params) ParamSetPairs() paramstypes.ParamSetPairs {
7373
if value == "" {
7474
return errors.New("value cannot be empty")
7575
}
76+
7677
if err := sdk.ValidateDenom(value); err != nil {
7778
return fmt.Errorf("invalid value %s: %w", value, err)
7879
}
@@ -92,6 +93,7 @@ func (m *Params) ParamSetPairs() paramstypes.ParamSetPairs {
9293
if value == "" {
9394
return errors.New("value cannot be empty")
9495
}
96+
9597
if _, err := sdk.AccAddressFromBech32(value); err != nil {
9698
return fmt.Errorf("invalid value %s: %w", value, err)
9799
}

0 commit comments

Comments
 (0)