From 76f5c4b41522b4f890d14bd65fcee9c6db6266c7 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 11:36:09 -0600 Subject: [PATCH 01/13] add upgrade handler for net asset values --- app/upgrades.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/upgrades.go b/app/upgrades.go index 0e477072a1..7f2c6d81be 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -19,6 +19,7 @@ import ( attributetypes "github.com/provenance-io/provenance/x/attribute/types" "github.com/provenance-io/provenance/x/hold" ibchookstypes "github.com/provenance-io/provenance/x/ibchooks/types" + markertypes "github.com/provenance-io/provenance/x/marker/types" msgfeetypes "github.com/provenance-io/provenance/x/msgfees/types" oracletypes "github.com/provenance-io/provenance/x/oracle/types" triggertypes "github.com/provenance-io/provenance/x/trigger/types" @@ -113,6 +114,7 @@ var upgrades = map[string]appUpgrade{ removeInactiveValidatorDelegations(ctx, app) setupICQ(ctx, app) updateMaxSupply(ctx, app) + addMarkerNavs(ctx, app) return vm, nil }, @@ -132,6 +134,7 @@ var upgrades = map[string]appUpgrade{ removeInactiveValidatorDelegations(ctx, app) setupICQ(ctx, app) updateMaxSupply(ctx, app) + addMarkerNavs(ctx, app) return vm, nil }, @@ -340,3 +343,25 @@ func updateMaxSupply(ctx sdk.Context, app *App) { app.MarkerKeeper.SetParams(ctx, params) ctx.Logger().Info("Done updating MaxSupply marker param") } + +// addMarkerNavs adds navs to existing markers +func addMarkerNavs(ctx sdk.Context, app *App) { + ctx.Logger().Info("Adding marker net asset values") + //TODO: Add list of actual net asset values to set (need to get from Figure) + + app.MarkerKeeper.IterateMarkers(ctx, func(record markertypes.MarkerAccountI) bool { + var hasNav bool + app.MarkerKeeper.IterateNetAssetValues(ctx, record.GetAddress(), func(nav markertypes.NetAssetValue) bool { + hasNav = true + return true + }) + if !hasNav { + nav := markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1) + if err := app.MarkerKeeper.AddSetNetAssetValues(ctx, record, []markertypes.NetAssetValue{nav}, "upgrade_handler"); err != nil { + panic(fmt.Sprintf("unable to set net asset value %v: %v", nav, err)) + } + } + return false + }) + ctx.Logger().Info("Done adding marker net asset values") +} From 6e03ecdbf5e38e88837410a4a627d26ed5d362ca Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 11:57:13 -0600 Subject: [PATCH 02/13] add upgrade handler for nav --- app/upgrades.go | 5 +++-- app/upgrades_test.go | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 7f2c6d81be..09843fc663 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -344,10 +344,11 @@ func updateMaxSupply(ctx sdk.Context, app *App) { ctx.Logger().Info("Done updating MaxSupply marker param") } -// addMarkerNavs adds navs to existing markers +// 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) { ctx.Logger().Info("Adding marker net asset values") - //TODO: Add list of actual net asset values to set (need to get from Figure) + //TODO: Add list of actual net asset values to set here app.MarkerKeeper.IterateMarkers(ctx, func(record markertypes.MarkerAccountI) bool { var hasNav bool diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 769330a3b9..1c8e0d042c 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -426,6 +426,8 @@ func (s *UpgradeTestSuite) TestSaffronRC1() { "INF Done updating ICQ params", "INF Updating MaxSupply marker param", "INF Done updating MaxSupply marker param", + "INF Adding marker net asset values", + "INF Done adding marker net asset values", } s.AssertUpgradeHandlerLogs("saffron-rc1", expInLog, nil) @@ -442,6 +444,8 @@ func (s *UpgradeTestSuite) TestSaffron() { "INF Done updating ICQ params", "INF Updating MaxSupply marker param", "INF Done updating MaxSupply marker param", + "INF Adding marker net asset values", + "INF Done adding marker net asset values", } s.AssertUpgradeHandlerLogs("saffron", expInLog, nil) From dc527a507ebdb7086204647db5a40e83b6793e89 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 12:29:37 -0600 Subject: [PATCH 03/13] add upgrade test --- app/upgrades_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 1c8e0d042c..1e12645e88 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -24,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + markertypes "github.com/provenance-io/provenance/x/marker/types" msgfeetypes "github.com/provenance-io/provenance/x/msgfees/types" ) @@ -845,3 +846,22 @@ func (s *UpgradeTestSuite) TestSetAccountDataNameRecord() { s.Require().NoError(err, "setAccountDataNameRecord") s.AssertLogContents(logOutput, expInLog, nil, true, "setAccountDataNameRecord") } + +func (s *UpgradeTestSuite) TestAddMarkerNavs() { + address1 := sdk.AccAddress("address1") + testcoin := markertypes.NewEmptyMarkerAccount("testcoin", + address1.String(), + []markertypes.AccessGrant{}) + testcoin.Supply = sdk.OneInt() + s.Require().NoError(s.app.MarkerKeeper.AddMarkerAccount(s.ctx, testcoin), "AddMarkerAccount() error") + addMarkerNavs(s.ctx, s.app) + netAssetValues := []markertypes.NetAssetValue{} + err := s.app.MarkerKeeper.IterateNetAssetValues(s.ctx, testcoin.GetAddress(), func(state markertypes.NetAssetValue) (stop bool) { + netAssetValues = append(netAssetValues, state) + return false + }) + s.Require().NoError(err, "IterateNetAssetValues err") + s.Assert().Len(netAssetValues, 1, "Should be 1 nav set for testcoin") + s.Assert().Equal(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), netAssetValues[0].Price, "Net asset value price should equal default upgraded price") + s.Assert().Equal(uint64(1), netAssetValues[0].Volume, "Net asset value volume should equal 1") +} From 1ebf48de09ef62d70b3a94832b5b24cb7557bd85 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 12:48:24 -0600 Subject: [PATCH 04/13] add more test cases --- app/upgrades.go | 2 +- app/upgrades_test.go | 63 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 09843fc663..ad4c324dd8 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -359,7 +359,7 @@ func addMarkerNavs(ctx sdk.Context, app *App) { if !hasNav { nav := markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1) if err := app.MarkerKeeper.AddSetNetAssetValues(ctx, record, []markertypes.NetAssetValue{nav}, "upgrade_handler"); err != nil { - panic(fmt.Sprintf("unable to set net asset value %v: %v", nav, err)) + ctx.Logger().Error(fmt.Sprintf("unable to set net asset value %v: %v", nav, err)) } } return false diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 1e12645e88..b895512186 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -854,14 +854,59 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() { []markertypes.AccessGrant{}) testcoin.Supply = sdk.OneInt() s.Require().NoError(s.app.MarkerKeeper.AddMarkerAccount(s.ctx, testcoin), "AddMarkerAccount() error") + + nosupplycoin := markertypes.NewEmptyMarkerAccount("nosupplycoin", + address1.String(), + []markertypes.AccessGrant{}) + s.Require().NoError(s.app.MarkerKeeper.AddMarkerAccount(s.ctx, nosupplycoin), "AddMarkerAccount() error") + + hasnavcoin := markertypes.NewEmptyMarkerAccount("hasnavcoin", + address1.String(), + []markertypes.AccessGrant{}) + hasnavcoin.Supply = sdk.NewInt(100) + s.Require().NoError(s.app.MarkerKeeper.AddMarkerAccount(s.ctx, hasnavcoin), "AddMarkerAccount() error") + 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) - netAssetValues := []markertypes.NetAssetValue{} - err := s.app.MarkerKeeper.IterateNetAssetValues(s.ctx, testcoin.GetAddress(), func(state markertypes.NetAssetValue) (stop bool) { - netAssetValues = append(netAssetValues, state) - return false - }) - s.Require().NoError(err, "IterateNetAssetValues err") - s.Assert().Len(netAssetValues, 1, "Should be 1 nav set for testcoin") - s.Assert().Equal(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), netAssetValues[0].Price, "Net asset value price should equal default upgraded price") - s.Assert().Equal(uint64(1), netAssetValues[0].Volume, "Net asset value volume should equal 1") + + tests := []struct { + name string + markerAddr sdk.AccAddress + expNav *markertypes.NetAssetValue + }{ + { + name: "upgrade adds new default nav", + markerAddr: testcoin.GetAddress(), + expNav: &markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), Volume: uint64(1)}, + }, + { + name: "already has nav", + markerAddr: hasnavcoin.GetAddress(), + expNav: &markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(55)), Volume: uint64(100)}, + }, + { + name: "nav add fails for coin", + markerAddr: nosupplycoin.GetAddress(), + expNav: nil, + }, + } + + for _, tc := range tests { + s.Run(tc.name, func() { + netAssetValues := []markertypes.NetAssetValue{} + err := s.app.MarkerKeeper.IterateNetAssetValues(s.ctx, tc.markerAddr, func(state markertypes.NetAssetValue) (stop bool) { + netAssetValues = append(netAssetValues, state) + return false + }) + s.Require().NoError(err, "IterateNetAssetValues err") + if tc.expNav != nil { + s.Assert().Len(netAssetValues, 1, "Should be 1 nav set for testcoin") + s.Assert().Equal(tc.expNav.Price, netAssetValues[0].Price, "Net asset value price should equal default upgraded price") + s.Assert().Equal(tc.expNav.Volume, netAssetValues[0].Volume, "Net asset value volume should equal 1") + } else { + s.Assert().Len(netAssetValues, 0, "Marker not expected to have nav") + } + }) + } } From 94f8040b15c8398308d743fbd445e4563f16e68c Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 12:51:57 -0600 Subject: [PATCH 05/13] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7452193f9e..31a31ab9c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Bump cometbft to v0.34.29 (from v0.34.28) [PR 1649](https://github.com/provenance-io/provenance/pull/1649). * Add genesis/init for Marker module send deny list addresses. [#1660](https://github.com/provenance-io/provenance/issues/1660) * Add automatic changelog entries for dependabot. [#1674](https://github.com/provenance-io/provenance/issues/1674) +* Add upgrade handler to set net assert values to markers [PR 1712](https://github.com/provenance-io/provenance/pull/1712). * Ensure IBC marker has matching supply [#1706](https://github.com/provenance-io/provenance/issues/1706). ### Bug Fixes From d70a3ab2478e5792f86fa4f597c69e9329c5a712 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 13:03:55 -0600 Subject: [PATCH 06/13] check iterate error --- app/upgrades.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index ad4c324dd8..c6661ef291 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -352,10 +352,14 @@ func addMarkerNavs(ctx sdk.Context, app *App) { app.MarkerKeeper.IterateMarkers(ctx, func(record markertypes.MarkerAccountI) bool { var hasNav bool - app.MarkerKeeper.IterateNetAssetValues(ctx, record.GetAddress(), func(nav markertypes.NetAssetValue) bool { + err := app.MarkerKeeper.IterateNetAssetValues(ctx, record.GetAddress(), func(nav markertypes.NetAssetValue) bool { hasNav = true return true }) + if err != nil { + ctx.Logger().Error(fmt.Sprintf("unable iterate net asset values for marker %v: %v", record, err)) + return false + } if !hasNav { nav := markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1) if err := app.MarkerKeeper.AddSetNetAssetValues(ctx, record, []markertypes.NetAssetValue{nav}, "upgrade_handler"); err != nil { From f3105186896024152cda843423a1c7f4fcb0fe34 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 17:04:39 -0600 Subject: [PATCH 07/13] add custom list processing, add a few examples for testnet --- app/upgrades.go | 33 ++++++++++++++++++++++++++------- app/upgrades_test.go | 15 ++++++++++++++- 2 files changed, 40 insertions(+), 8 deletions(-) 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() { From 2fa12f004cedd9a3b4a0cd7146ddb8f933472a7a Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 17:14:44 -0600 Subject: [PATCH 08/13] fix default logic and change log --- CHANGELOG.md | 2 +- app/upgrades.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 911a5b0f46..32f2a39bd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,7 +70,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Bump cometbft to v0.34.29 (from v0.34.28) [PR 1649](https://github.com/provenance-io/provenance/pull/1649). * Add genesis/init for Marker module send deny list addresses. [#1660](https://github.com/provenance-io/provenance/issues/1660) * Add automatic changelog entries for dependabot. [#1674](https://github.com/provenance-io/provenance/issues/1674) -* Add upgrade handler to set net assert values to markers [PR 1712](https://github.com/provenance-io/provenance/pull/1712). +* Add upgrade handler to set net asset values to markers [PR 1712](https://github.com/provenance-io/provenance/pull/1712). * Ensure IBC marker has matching supply [#1706](https://github.com/provenance-io/provenance/issues/1706). ### Bug Fixes diff --git a/app/upgrades.go b/app/upgrades.go index 2ad9639e73..71e3e1299c 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -122,7 +122,7 @@ var upgrades = map[string]appUpgrade{ "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) + addMarkerNavs(ctx, app, denomToNav, markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1)) setExchangeParams(ctx, app) @@ -148,7 +148,7 @@ var upgrades = map[string]appUpgrade{ denomToNav := map[string]markertypes.NetAssetValue{ // TODO: Add custom mainnet values here } - addMarkerNavs(ctx, app, denomToNav) + addMarkerNavs(ctx, app, denomToNav, markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1)) setExchangeParams(ctx, app) return vm, nil @@ -362,7 +362,7 @@ func updateMaxSupply(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) { +func addMarkerNavs(ctx sdk.Context, app *App, denomToNav map[string]markertypes.NetAssetValue, defaultNav markertypes.NetAssetValue) { ctx.Logger().Info("Adding marker net asset values") for denom, nav := range denomToNav { marker, err := app.MarkerKeeper.GetMarkerByDenom(ctx, denom) @@ -385,9 +385,8 @@ func addMarkerNavs(ctx sdk.Context, app *App, denomToNav map[string]markertypes. return false } if !hasNav { - nav := markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1) - if err := app.MarkerKeeper.AddSetNetAssetValues(ctx, record, []markertypes.NetAssetValue{nav}, "upgrade_handler"); err != nil { - ctx.Logger().Error(fmt.Sprintf("unable to set net asset value %v: %v", nav, err)) + if err := app.MarkerKeeper.AddSetNetAssetValues(ctx, record, []markertypes.NetAssetValue{defaultNav}, "upgrade_handler"); err != nil { + ctx.Logger().Error(fmt.Sprintf("unable to set net asset value %v: %v", defaultNav, err)) } } return false From 30ab272e065fbd6694516079cf982fbd54735def Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Wed, 18 Oct 2023 17:33:19 -0600 Subject: [PATCH 09/13] fix test --- app/upgrades_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/upgrades_test.go b/app/upgrades_test.go index e425eb5a48..e7aff1c562 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -878,8 +878,8 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() { s.Require().NoError(s.app.MarkerKeeper.AddSetNetAssetValues(s.ctx, hasnavcoin, []markertypes.NetAssetValue{presentnav}, "test")) addMarkerNavs(s.ctx, s.app, map[string]markertypes.NetAssetValue{ - "testcoininlist": markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(12345)), Volume: uint64(1)}, - }) + "testcoininlist": {Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(12345)), Volume: uint64(1)}, + }, markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), Volume: uint64(1)}) tests := []struct { name string From 0a1b6189b72e7d826448afcd73f52734e2ba7a37 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Thu, 9 Nov 2023 16:37:23 -0700 Subject: [PATCH 10/13] Add new navs for mainnet in list --- app/navs_mainnet.go | 1 + app/upgrades.go | 37 ++++--------------------------------- app/upgrades_test.go | 7 +------ 3 files changed, 6 insertions(+), 39 deletions(-) diff --git a/app/navs_mainnet.go b/app/navs_mainnet.go index 98b58298d1..d13b9c68b2 100644 --- a/app/navs_mainnet.go +++ b/app/navs_mainnet.go @@ -2,6 +2,7 @@ package app import ( "github.com/cosmos/cosmos-sdk/types" + markertypes "github.com/provenance-io/provenance/x/marker/types" ) diff --git a/app/upgrades.go b/app/upgrades.go index 0c51320e89..180d8fb4bb 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -23,7 +23,6 @@ import ( "github.com/provenance-io/provenance/x/exchange" "github.com/provenance-io/provenance/x/hold" ibchookstypes "github.com/provenance-io/provenance/x/ibchooks/types" - "github.com/provenance-io/provenance/x/marker/types" markertypes "github.com/provenance-io/provenance/x/marker/types" msgfeetypes "github.com/provenance-io/provenance/x/msgfees/types" oracletypes "github.com/provenance-io/provenance/x/oracle/types" @@ -119,15 +118,6 @@ var upgrades = map[string]appUpgrade{ removeInactiveValidatorDelegations(ctx, app) setupICQ(ctx, app) updateMaxSupply(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, markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1)) - setExchangeParams(ctx, app) return vm, nil @@ -175,10 +165,8 @@ var upgrades = map[string]appUpgrade{ setupICQ(ctx, app) updateMaxSupply(ctx, app) - denomToNav := map[string]markertypes.NetAssetValue{ - // TODO: Add custom mainnet values here - } - addMarkerNavs(ctx, app, denomToNav, markertypes.NewNetAssetValue(sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), 1)) + addMarkerNavs(ctx, app, GetDenomToNav()) + setExchangeParams(ctx, app) updateIbcMarkerDenomMetadata(ctx, app) @@ -393,7 +381,7 @@ func updateMaxSupply(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, defaultNav markertypes.NetAssetValue) { +func addMarkerNavs(ctx sdk.Context, app *App, denomToNav map[string]markertypes.NetAssetValue) { ctx.Logger().Info("Adding marker net asset values") for denom, nav := range denomToNav { marker, err := app.MarkerKeeper.GetMarkerByDenom(ctx, denom) @@ -405,23 +393,6 @@ func addMarkerNavs(ctx sdk.Context, app *App, denomToNav map[string]markertypes. 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 { - hasNav = true - return true - }) - if err != nil { - ctx.Logger().Error(fmt.Sprintf("unable iterate net asset values for marker %v: %v", record, err)) - return false - } - if !hasNav { - if err := app.MarkerKeeper.AddSetNetAssetValues(ctx, record, []markertypes.NetAssetValue{defaultNav}, "upgrade_handler"); err != nil { - ctx.Logger().Error(fmt.Sprintf("unable to set net asset value %v: %v", defaultNav, err)) - } - } - return false - }) ctx.Logger().Info("Done adding marker net asset values") } @@ -444,7 +415,7 @@ func setExchangeParams(ctx sdk.Context, app *App) { // TODO: Remove with the saffron handlers. func updateIbcMarkerDenomMetadata(ctx sdk.Context, app *App) { ctx.Logger().Info("Updating ibc marker denom metadata") - app.MarkerKeeper.IterateMarkers(ctx, func(record types.MarkerAccountI) bool { + app.MarkerKeeper.IterateMarkers(ctx, func(record markertypes.MarkerAccountI) bool { if !strings.HasPrefix(record.GetDenom(), "ibc/") { return false } diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 7d98ba133e..8fa38cbdca 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -902,18 +902,13 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() { addMarkerNavs(s.ctx, s.app, map[string]markertypes.NetAssetValue{ "testcoininlist": {Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(12345)), Volume: uint64(1)}, - }, markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), Volume: uint64(1)}) + }) tests := []struct { name string markerAddr sdk.AccAddress expNav *markertypes.NetAssetValue }{ - { - name: "upgrade adds new default nav", - markerAddr: testcoin.GetAddress(), - expNav: &markertypes.NetAssetValue{Price: sdk.NewInt64Coin(markertypes.UsdDenom, int64(150)), Volume: uint64(1)}, - }, { name: "already has nav", markerAddr: hasnavcoin.GetAddress(), From 64e9cb994fb0d950c7b9a5c5ff32d8155c875cd6 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Fri, 10 Nov 2023 09:58:58 -0700 Subject: [PATCH 11/13] Update tests --- app/upgrades_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 8fa38cbdca..88e34fc12e 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -428,8 +428,6 @@ func (s *UpgradeTestSuite) TestSaffronRC1() { "INF Done updating ICQ params", "INF Updating MaxSupply marker param", "INF Done updating MaxSupply marker param", - "INF Adding marker net asset values", - "INF Done adding marker net asset values", "INF Ensuring exchange module params are set.", } From 541f52cd7c65feb0f3328c2cd3b9123db8d7d3b5 Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Fri, 10 Nov 2023 10:06:46 -0700 Subject: [PATCH 12/13] update method comment --- app/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index 180d8fb4bb..abd8663be8 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -380,7 +380,7 @@ func updateMaxSupply(ctx sdk.Context, app *App) { ctx.Logger().Info("Done updating MaxSupply marker param") } -// addMarkerNavs adds navs to existing markers, if denom is not in map it will default to $0.15 cents +// addMarkerNavs adds navs to existing markers func addMarkerNavs(ctx sdk.Context, app *App, denomToNav map[string]markertypes.NetAssetValue) { ctx.Logger().Info("Adding marker net asset values") for denom, nav := range denomToNav { From 5e1d7ef899b04c8a273ed450572430956f43170e Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Fri, 10 Nov 2023 10:23:11 -0700 Subject: [PATCH 13/13] Rename update function, add detailed comments --- app/navs_mainnet.go | 5 ++++- app/upgrades.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/navs_mainnet.go b/app/navs_mainnet.go index d13b9c68b2..3e6bc51a4f 100644 --- a/app/navs_mainnet.go +++ b/app/navs_mainnet.go @@ -6,7 +6,10 @@ import ( markertypes "github.com/provenance-io/provenance/x/marker/types" ) -func GetDenomToNav() map[string]markertypes.NetAssetValue { +// GetPioMainnet1DenomToNav are net asset values for the pio-mainnet-1 taken at blockheight 13631650 +// Source: https://figure.tech/service-pricing-engine/external/api/v1/pricing/marker/new?time=2023-11-07T17:59:59.999722Z +// NOTE: These should not be ran against any other network but pio-mainnet-1 +func GetPioMainnet1DenomToNav() map[string]markertypes.NetAssetValue { return map[string]markertypes.NetAssetValue{ "pm.participation.agreement.1bcslgccejhm9v3higsx7c": markertypes.NewNetAssetValue(types.NewInt64Coin(markertypes.UsdDenom, 1037949704), 1), "pm.participation.agreement.1cag7ztnmm4rdbbtwdrodb": markertypes.NewNetAssetValue(types.NewInt64Coin(markertypes.UsdDenom, 788900239), 1), diff --git a/app/upgrades.go b/app/upgrades.go index abd8663be8..56739f8c95 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -165,7 +165,7 @@ var upgrades = map[string]appUpgrade{ setupICQ(ctx, app) updateMaxSupply(ctx, app) - addMarkerNavs(ctx, app, GetDenomToNav()) + addMarkerNavs(ctx, app, GetPioMainnet1DenomToNav()) setExchangeParams(ctx, app) updateIbcMarkerDenomMetadata(ctx, app)