Skip to content

Commit

Permalink
add custom list processing, add a few examples for testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Oct 18, 2023
1 parent 0dd98c1 commit f310518
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
33 changes: 26 additions & 7 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))
}

Check warning on line 375 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L374-L375

Added lines #L374 - L375 were not covered by tests
}
app.MarkerKeeper.IterateMarkers(ctx, func(record markertypes.MarkerAccountI) bool {
var hasNav bool
err := app.MarkerKeeper.IterateNetAssetValues(ctx, record.GetAddress(), func(nav markertypes.NetAssetValue) bool {
Expand Down
15 changes: 14 additions & 1 deletion app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit f310518

Please sign in to comment.