Skip to content

Commit

Permalink
Backport: 1830 (commitments CLI), 1831 (force transfer), 1833 (nhash-…
Browse files Browse the repository at this point in the history
…per-usd-mil), 1835 (transfer agents), 1843 (bid prices), 1846 (restricted coins/fee collector), 1848 (sdk to v0.46.13-pio-3). (#1849)

* Require new force_transfer access to do forced transfers. (#1831)

* [1829]: Add ACCESS_FORCE_TRANSFER entry to the Access enum.

* [1829]: Add some clarifications to the access entries.

* [1829]: Check the new force-transfer permission when doing a forced transfer.

* [1829]: Add changelog entry.

* [1892]: Clarify the deposit and withdraw permissions a bit.

* Add exchange commitments to CLI. (#1830)

* [1789]: Update cli for existing stuff that got some new fields.

* [1789]: Create the commit-funds command and the helper stuff for AccountAmount and NetAssetPrice entries.

* [1789]: Write the market-commitment-settle command.

* [1789]: Create the market-release-commitments command.

* [1789]: Create the market-accepting-commitments command.

* [1789]: Create the gov-close-market command.

* [1789]: Fix the placement of the accepting-orders stuff.

* [1789]: Create the market-intermediary-denom command.

* [1789]: Add a test helper to check if some events are in another list of events.

* [1789]: Unit tests on the commit funds command.

* [1789]: Add TODOs for the query commands.

* [1789]: Write all the query commands.

* [1789]: Unit tests on the rest of the cmd setups/makers.

* [1789]: Allow providing the commitment settlement as a file.

* [1789]: Unit tests on the query commands. Alter the commitment settlement fee calc setup to not require an admin arg when --file is provided.

* [1789]: Unit tests on the tx commands.

* [1789]: Add changelog entry.

* [1789]: Fix --inputs and --outputs flag description.

* [1789]: Add some flags missing from the market settle setup test case.

* [1789]: A couple small tweaks to the cli tests.

* Update msg-fees param nhash per mil to 40,000,000 ($0.025/hash). (#1833)

* In the tourmaline upgrade, update the msg-fees nhash/usd-mil to 40,000,000 = -bash.025/hash (currently 25,000,000 = -bash.04/hash).

* Update the comments on the MsgFees Params message to include the conversion formulas too.

* Update TestTourmaline to check for module migrations and inactive delegations log entries.

* Fix capitalization and punctuation of log messages in removeInactiveValidatorDelegations.

* Add punctuation to the log messages from convertNavUnits and add a done message.

* Add changelog entry.

* Allow bid order prices to not be evenly divisible by buyer settlement fee ratios. (#1843)

* Allow the bid price to not be evenly applicable to a fee ratio.

* Fix unit tests that broke because we loosened the bid order fee/price stuff.

* Add changelog entry.

* Update spec docs.

* Allow transfer agents to do exchange settlements with restricted coins. (#1835)

* [1834]: Add tourmaline-rc2 upgrade handler since I'm about to make a state-breaking change that'll require an upgrade.

* [1834]: Add context functions for passing in the transfer agent.

* [1834]: Pay attention to the newly available transfer agent in the send restriction. Move the deposit check to SendRestrictionFn (from validateSendDenom) since don't need to repeat that check for every denom. Add a check for withdraw on the from addr since that might now be a marker account. Tweak a couple error messages to distinguish them from eachother. In the transfer endpoint, if the destination is also a marker, check for deposit access on that marker.

* [1834]: Switch the TestAccountKeeperMintBurnCoins fix to provide the transfer agent instead of just bypassing the send restrictions.

* [1834]: If no force transfer, and coming from a marker, make sure the admin has withdraw on that marker. Unit tests on the TransferCoin function.

* [1834]: Unit tests on the send restriction function.

* [1834]: Set the transfer agent in the exchange stuff that does bank stuff.

* [1834]: Fix the unit tests that broke and add a couple new ones.

* [1834]: tiny tweak to a couple unit tests.

* [1834]: In AddSetNetAssetValues, emit the nav event even when the price denom's marker isn't found.

* [1834]: Tweak TestKeeper_WithdrawMarketFunds again to make it a little easier on test setup.

* [1834]: lint (kind of since it's in a test file that isn't linted, but whatever).

* [1834]: Add access validator functions to the marker to standardize the errors when an address doesn't have a certain role.

* [1834]: Remove redundant 'access' from error about not having access (the enum name starts with ACCESS_).

* [1834]: Standardize the no-access errors. In WithdrawCoins, if going to a marker, make sure they've got deposit on that marker. Require a marker to be active in ordr to send its funds.

* [1834]: Update TransferCoin. Add comment above authzHandler with the reason we don't check for withdraw and remove the check for withdraw.

* [1834]: Fix the error in validateSendDenom for sends to a marker to reference the correct denom and address.

* [1834]: Fix the tests that broke because I changed the error messages.

* [1834]: Update AddSetNetAssetValues. Try all entries even if an earlier one has an error. If the price marker does not exist, only emit the event if the nav is valid. Put some unit tests on that thing.

* [1834]: Add unit test on send restriction when we can't get attributes.

* [1834]: Fix some comments in the mocks, add a unit test making sure force-transfer access is ignored in the send restriction, and add force transfer to a couple access unit tests.

* [1834]: Update marker spec docs with all the recent chagnes.

* [1834]: For the exchange stuff, pay attention to blocked addresses in the off-chance one gets used.

* [1834]: Check that a marker is active before allowing a transfer.

* [1834]: In WithdrawCoins, make sure the recipient is not a bank blocked address.

* [1834]: Some tweaks to the spec docs to fix some typos, grammer, and flowchart stuff.

* [1834]: Redo the flows so that denied is on the left for all of them. Add some links between flows.

* [1834]: Fix the names of a bunch of keeper unit tests that claim to be testing account stuff.

* [1834]: Unit tests on WithdrawCoins and on Transfer of non-active coins.

* [1834]: Fix unit tests on WithdrawMarketFunds that broke because a call to BlockedAddr is now being made that wasn't expected previously. Add test for when the address is blocked.

* [1834]: Fix TestKeeper_SettleCommitments that broke because of the added calls to BlockedAddr that weren't previously expected.

* [1834]: Fix TestKeeper_DoTransfer that broke because we added calls to BlockedAddr that weren't listed as expected. Add a test for when an address is blocked.

* [1834]: Fix TestKeeper_SettleOrders that broke when I added calls to BlockedAddr.

* [1834]: Fix the FillAsks and FillBids unit tests that broke when I started calling BlockedAddr.

* [1834]: Remove TODO that's TODONE (unit tests on blocked addresses).

* [1834]: Update the exchange spec docs to include stuff about the transfer agent as well as a commitment settlement fee calc example.

* [1834]: Add changelog entries.

* Prevent restricted coins from ending up in the fee collector account. (#1846)

* [1845]: Update the marker SendRestrictionFn to not allow restricted coins to be sent to the fee collector account.

* [1845]: Add changelog entry.

* [1845]: Fix some exchange unit tests that broke because they were using restricted coins for the fees.

* [1845]: Update marker spec doc flowcharts.

* Bump cosmos-sdk to v0.46.13-pio-3 (from v0.46.13-pio-2). (#1848)

* Bump cosmos-sdk to v0.46.13-pio-3 (from v0.46.13-pio-2).

* Add changelog entry.
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
SpicyLemon authored Feb 22, 2024
1 parent a3904bd commit 07803b1
Show file tree
Hide file tree
Showing 66 changed files with 8,370 additions and 889 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Features

* In the marker module's `SendRestrictionFn`, allow a transfer agent to be identified through the context [#1834](https://github.com/provenance-io/provenance/issues/1834).
* In the exchange module, provide the admin as the transfer agent when attepting to move funds [#1834](https://github.com/provenance-io/provenance/issues/1834).

### Improvements

* Add an empty `tourmaline-rc2` upgrade handler [#1834](https://github.com/provenance-io/provenance/issues/1834).
* Add new force_transfer access that is required for an account to do a forced transfer ([#1829](https://github.com/provenance-io/provenance/issues/1829)).
* Add exchange commitment stuff to CLI [PR 1830](https://github.com/provenance-io/provenance/pull/1830).
* Update the MsgFees Params to set the nhash per usd-mil to 40,000,000 ($0.025/hash) [#1833](https://github.com/provenance-io/provenance/pull/1833).
* Bid order prices are no longer restricted to amounts that can be evenly applied to a buyer settlement fee ratio [1834](https://github.com/provenance-io/provenance/pull/1843).
* In the marker and exchange modules, help ensure funds don't get sent to blocked addresses [#1834](https://github.com/provenance-io/provenance/issues/1834).
* Update marker and exchange spec docs to include info about transfer agents [#1834](https://github.com/provenance-io/provenance/issues/1834).
* Prevent restricted markers from being sent to the fee collector account [#1845](https://github.com/provenance-io/provenance/issues/1845).

### Bug Fixes

* Prevent funds from going to or from a marker without the transfer agent having deposit or withdraw access (respectively) [#1834](https://github.com/provenance-io/provenance/issues/1834).

### API Breaking

* Accounts that have transfer access in a marker are no longer allowed to do forced transfers ([#1829](https://github.com/provenance-io/provenance/issues/1829)).
Accounts must now have the force_transfer access for that.

### Dependencies

- Bump `codecov/codecov-action` from 3 to 4 ([#1828](https://github.com/provenance-io/provenance/pull/1828))
Expand All @@ -48,6 +73,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- Bump `serde-json-wasm` from 0.5.1 to 0.5.2 in /testutil/contracts/echo ([#1838](https://github.com/provenance-io/provenance/pull/1838))
- Bump `golangci/golangci-lint-action` from 3 to 4 ([#1840](https://github.com/provenance-io/provenance/pull/1840))
- Bump `google.golang.org/grpc` from 1.61.0 to 1.61.1 ([#1842](https://github.com/provenance-io/provenance/pull/1842))
- Bump `cosmos-sdk` from v0.46.13-pio-2 to v0.46.13-pio-3 ([#1848](https://github.com/provenance-io/provenance/pull/1848))

---

Expand Down
35 changes: 25 additions & 10 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var upgrades = map[string]appUpgrade{
return vm, nil
},
},
"tourmaline-rc2": {}, // upgrade for v1.18.0-rc2
"tourmaline": { // upgrade for v1.18.0
Added: []string{ibcratelimit.ModuleName},
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
Expand All @@ -144,6 +145,9 @@ var upgrades = map[string]appUpgrade{
removeInactiveValidatorDelegations(ctx, app)
convertNavUnits(ctx, app)

// This isn't in an rc because it was handled via gov prop for testnet.
updateMsgFeesNhashPerMil(ctx, app)

return vm, nil
},
},
Expand Down Expand Up @@ -234,33 +238,33 @@ var _ = runModuleMigrations
// This should be applied in most upgrades.
func removeInactiveValidatorDelegations(ctx sdk.Context, app *App) {
unbondingTimeParam := app.StakingKeeper.GetParams(ctx).UnbondingTime
ctx.Logger().Info(fmt.Sprintf("removing all delegations from validators that have been inactive (unbonded) for %d days", int64(unbondingTimeParam.Hours()/24)))
ctx.Logger().Info(fmt.Sprintf("Removing all delegations from validators that have been inactive (unbonded) for %d days.", int64(unbondingTimeParam.Hours()/24)))
removalCount := 0
validators := app.StakingKeeper.GetAllValidators(ctx)
for _, validator := range validators {
if validator.IsUnbonded() {
inactiveDuration := ctx.BlockTime().Sub(validator.UnbondingTime)
if inactiveDuration >= unbondingTimeParam {
ctx.Logger().Info(fmt.Sprintf("validator %v has been inactive (unbonded) for %d days and will be removed", validator.OperatorAddress, int64(inactiveDuration.Hours()/24)))
ctx.Logger().Info(fmt.Sprintf("Validator %v has been inactive (unbonded) for %d days and will be removed.", validator.OperatorAddress, int64(inactiveDuration.Hours()/24)))
valAddress, err := sdk.ValAddressFromBech32(validator.OperatorAddress)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("invalid operator address: %s: %v", validator.OperatorAddress, err))
ctx.Logger().Error(fmt.Sprintf("Invalid operator address: %s: %v.", validator.OperatorAddress, err))
continue
}
delegations := app.StakingKeeper.GetValidatorDelegations(ctx, valAddress)
for _, delegation := range delegations {
ctx.Logger().Info(fmt.Sprintf("undelegate delegator %v from validator %v of all shares (%v)", delegation.DelegatorAddress, validator.OperatorAddress, delegation.GetShares()))
ctx.Logger().Info(fmt.Sprintf("Undelegate delegator %v from validator %v of all shares (%v).", delegation.DelegatorAddress, validator.OperatorAddress, delegation.GetShares()))
_, err = app.StakingKeeper.Undelegate(ctx, delegation.GetDelegatorAddr(), valAddress, delegation.GetShares())
if err != nil {
ctx.Logger().Error(fmt.Sprintf("failed to undelegate delegator %s from validator %s: %v", delegation.GetDelegatorAddr().String(), valAddress.String(), err))
ctx.Logger().Error(fmt.Sprintf("Failed to undelegate delegator %s from validator %s: %v.", delegation.GetDelegatorAddr().String(), valAddress.String(), err))
continue
}
}
removalCount++
}
}
}
ctx.Logger().Info(fmt.Sprintf("a total of %d inactive (unbonded) validators have had all their delegators removed", removalCount))
ctx.Logger().Info(fmt.Sprintf("A total of %d inactive (unbonded) validators have had all their delegators removed.", removalCount))
}

// setupICQ sets the correct default values for ICQKeeper.
Expand Down Expand Up @@ -354,24 +358,35 @@ func updateIbcMarkerDenomMetadata(ctx sdk.Context, app *App) {

// convertNavUnits iterates all the net asset values and updates their units if they are using usd.
func convertNavUnits(ctx sdk.Context, app *App) {
ctx.Logger().Info("Converting NAV units")
ctx.Logger().Info("Converting NAV units.")
err := app.MarkerKeeper.IterateAllNetAssetValues(ctx, func(markerAddr sdk.AccAddress, nav markertypes.NetAssetValue) (stop bool) {
if nav.Price.Denom == markertypes.UsdDenom {
nav.Price.Amount = nav.Price.Amount.Mul(math.NewInt(10))
marker, err := app.MarkerKeeper.GetMarker(ctx, markerAddr)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Unable to get marker for address: %s, error: %s", markerAddr, err))
ctx.Logger().Error(fmt.Sprintf("Unable to get marker for address: %s, error: %s.", markerAddr, err))
return false
}
err = app.MarkerKeeper.SetNetAssetValue(ctx, marker, nav, "upgrade")
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Unable to set net asset value for marker: %s, error: %s", markerAddr, err))
ctx.Logger().Error(fmt.Sprintf("Unable to set net asset value for marker: %s, error: %s.", markerAddr, err))
return false
}
}
return false
})
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Unable to iterate all net asset values error: %s", err))
ctx.Logger().Error(fmt.Sprintf("Unable to iterate all net asset values error: %s.", err))
}
ctx.Logger().Info("Done converting NAV units.")
}

// updateMsgFeesNhashPerMil updates the MsgFees Params to set the NhashPerUsdMil to 40,000,000.
func updateMsgFeesNhashPerMil(ctx sdk.Context, app *App) {
var newVal uint64 = 40_000_000
ctx.Logger().Info(fmt.Sprintf("Setting MsgFees Params NhashPerUsdMil to %d.", newVal))
params := app.MsgFeesKeeper.GetParams(ctx)
params.NhashPerUsdMil = newVal
app.MsgFeesKeeper.SetParams(ctx, params)
ctx.Logger().Info("Done setting MsgFees Params NhashPerUsdMil.")
}
Loading

0 comments on commit 07803b1

Please sign in to comment.