diff --git a/app/upgrades.go b/app/upgrades.go index 599b9120d9..2ad9639e73 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -115,7 +115,15 @@ var upgrades = map[string]appUpgrade{ removeInactiveValidatorDelegations(ctx, app) setupICQ(ctx, app) updateMaxSupply(ctx, app) - addMarkerNavs(ctx, app) + + denomToNav := map[string]markertypes.NetAssetValue{ + "usd.deposit": markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, 1000), 1), + "tp13gc5xe8375msm7y6jhf752e5hcrjypmcpf9wldsjprhnpzlkhqaqawxujf.investment": markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, 10), 1), + "tp1cxuqqyjjf5x66jvlmtvj3juppn370ev7rr5cja3ml65nzhxgvpkszfuvtw.investment": markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, 10), 33600000), + "pm.sale.pool.7v2gsuvnudyfvuig50r3k3": markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, 19026640), 1), + } + addMarkerNavs(ctx, app, denomToNav) + setExchangeParams(ctx, app) return vm, nil @@ -136,7 +144,11 @@ var upgrades = map[string]appUpgrade{ removeInactiveValidatorDelegations(ctx, app) setupICQ(ctx, app) updateMaxSupply(ctx, app) - addMarkerNavs(ctx, app) + + denomToNav := map[string]markertypes.NetAssetValue{ + // TODO: Add custom mainnet values here + } + addMarkerNavs(ctx, app, denomToNav) setExchangeParams(ctx, app) return vm, nil @@ -349,12 +361,19 @@ func updateMaxSupply(ctx sdk.Context, app *App) { ctx.Logger().Info("Done updating MaxSupply marker param") } -// addMarkerNavs adds navs to existing markers with default value of 15 cents -// TODO: Need to get a list of current markers and their values to set as a manual script -func addMarkerNavs(ctx sdk.Context, app *App) { +// addMarkerNavs adds navs to existing markers, if denom is not in map it will default to $0.15 cents +func addMarkerNavs(ctx sdk.Context, app *App, denomToNav map[string]markertypes.NetAssetValue) { ctx.Logger().Info("Adding marker net asset values") - //TODO: Add list of actual net asset values to set here - + for denom, nav := range denomToNav { + marker, err := app.MarkerKeeper.GetMarkerByDenom(ctx, denom) + if err != nil { + ctx.Logger().Error(fmt.Sprintf("unable to get marker %v: %v", denom, err)) + continue + } + if err := app.MarkerKeeper.AddSetNetAssetValues(ctx, marker, []markertypes.NetAssetValue{nav}, "upgrade_handler"); err != nil { + ctx.Logger().Error(fmt.Sprintf("unable to set net asset value %v: %v", nav, err)) + } + } app.MarkerKeeper.IterateMarkers(ctx, func(record markertypes.MarkerAccountI) bool { var hasNav bool err := app.MarkerKeeper.IterateNetAssetValues(ctx, record.GetAddress(), func(nav markertypes.NetAssetValue) bool { diff --git a/app/upgrades_test.go b/app/upgrades_test.go index de09e1e52f..e425eb5a48 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -858,6 +858,12 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() { testcoin.Supply = sdk.OneInt() s.Require().NoError(s.app.MarkerKeeper.AddMarkerAccount(s.ctx, testcoin), "AddMarkerAccount() error") + testcoinInList := markertypes.NewEmptyMarkerAccount("testcoininlist", + address1.String(), + []markertypes.AccessGrant{}) + testcoinInList.Supply = sdk.OneInt() + s.Require().NoError(s.app.MarkerKeeper.AddMarkerAccount(s.ctx, testcoinInList), "AddMarkerAccount() error") + nosupplycoin := markertypes.NewEmptyMarkerAccount("nosupplycoin", address1.String(), []markertypes.AccessGrant{}) @@ -871,7 +877,9 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() { presentnav := markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(55)), uint64(100)) s.Require().NoError(s.app.MarkerKeeper.AddSetNetAssetValues(s.ctx, hasnavcoin, []markertypes.NetAssetValue{presentnav}, "test")) - addMarkerNavs(s.ctx, s.app) + addMarkerNavs(s.ctx, s.app, map[string]markertypes.NetAssetValue{ + "testcoininlist": markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(12345)), Volume: uint64(1)}, + }) tests := []struct { name string @@ -893,6 +901,11 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() { markerAddr: nosupplycoin.GetAddress(), expNav: nil, }, + { + name: "nav set from custom config", + markerAddr: testcoinInList.GetAddress(), + expNav: &markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(12345)), Volume: uint64(1)}, + }, } for _, tc := range tests { s.Run(tc.name, func() {