Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have exchange module update marker net-asset-value entries #1741

Merged
merged 15 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,48 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Improvements

* When the exchange module settles orders, update the marker net-asset-values ([#1736](https://github.com/provenance-io/provenance/pull/1736).

### Bug Fixes

* Fixed denom metadata source chain-id retrieval for new ibc markers [#1726](https://github.com/provenance-io/provenance/issues/1726).

### Dependencies

- Bump `bufbuild/buf-setup-action` from 1.27.1 to 1.27.2 ([#1724](https://github.com/provenance-io/provenance/pull/1724))
- Bump `github.com/google/uuid` from 1.3.1 to 1.4.0 ([#1723](https://github.com/provenance-io/provenance/pull/1723))
- Bump `github.com/gorilla/mux` from 1.8.0 to 1.8.1 ([#1734](https://github.com/provenance-io/provenance/pull/1734))
- Bump `golang.org/x/text` from 0.13.0 to 0.14.0 ([#1735](https://github.com/provenance-io/provenance/pull/1735))
- Bump `github.com/spf13/cobra` from 1.7.0 to 1.8.0 ([#1733](https://github.com/provenance-io/provenance/pull/1733))

---

## [v1.17.0-rc2](https://github.com/provenance-io/provenance/releases/tag/v1.17.0-rc2) - 2023-11-03

### Features

* Add the (empty) `saffron-rc2` upgrade [#1699](https://github.com/provenance-io/provenance/issues/1699).
* Add the `saffron-rc2` upgrade and update `saffron` to create denom metadata for IBC markers [#1728](https://github.com/provenance-io/provenance/issues/1728).

### Improvements

* Wrote unit tests on the keeper methods [#1699](https://github.com/provenance-io/provenance/issues/1699).
* During `FillBids`, the seller settlement fee is now calculated on the total price instead of each order individually [#1699](https://github.com/provenance-io/provenance/issues/1699).
* In the `OrderFeeCalc` query, ensure the market exists [#1699](https://github.com/provenance-io/provenance/issues/1699).
* Add publishing of docker arm64 container builds [#1634](https://github.com/provenance-io/provenance/issues/1634)
* Add additional logging to trigger module [#1718](https://github.com/provenance-io/provenance/issues/1718).

### Bug Fixes

* During `InitGenesis`, ensure LastOrderId is at least the largest order id [#1699](https://github.com/provenance-io/provenance/issues/1699).
* Properly populate the permissions lists when reading access grants from state [#1699](https://github.com/provenance-io/provenance/issues/1699).
* Fixed the paginated order queries to properly look up orders [#1699](https://github.com/provenance-io/provenance/issues/1699).
* Fixed denom metadata source chain-id retrieval for new ibc markers [#1726](https://github.com/provenance-io/provenance/issues/1726).

### Dependencies
### Full Commit History

- Bump `bufbuild/buf-setup-action` from 1.27.1 to 1.27.2 ([#1724](https://github.com/provenance-io/provenance/pull/1724))
- Bump `github.com/google/uuid` from 1.3.1 to 1.4.0 ([#1723](https://github.com/provenance-io/provenance/pull/1723))
- Bump `github.com/gorilla/mux` from 1.8.0 to 1.8.1 ([#1734](https://github.com/provenance-io/provenance/pull/1734))
- Bump `golang.org/x/text` from 0.13.0 to 0.14.0 ([#1735](https://github.com/provenance-io/provenance/pull/1735))
- Bump `github.com/spf13/cobra` from 1.7.0 to 1.8.0 ([#1733](https://github.com/provenance-io/provenance/pull/1733))
* https://github.com/provenance-io/provenance/compare/v1.17.0-rc1...v1.17.0-rc2
* https://github.com/provenance-io/provenance/compare/v1.16.0...v1.17.0-rc2

---

Expand Down Expand Up @@ -1291,4 +1308,4 @@ into new 0.40.x base. Minimal unit test coverage and features in place to begin

The Provenance Blockchain was started by Figure Technologies in 2018 using a Hyperledger Fabric derived private network.
A subsequent migration was made to a new internal private network based on the 0.38-0.39 series of Cosmos SDK and
Tendermint. The Provence-IO/Provenance Cosmos SDK derived public network is the
Tendermint. The Provence-IO/Provenance Cosmos SDK derived public network is the
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func New(

app.ExchangeKeeper = exchangekeeper.NewKeeper(
appCodec, keys[exchange.StoreKey], authtypes.FeeCollectorName,
app.AccountKeeper, app.AttributeKeeper, app.BankKeeper, app.HoldKeeper,
app.AccountKeeper, app.AttributeKeeper, app.BankKeeper, app.HoldKeeper, app.MarkerKeeper,
)

pioMessageRouter := MessageRouterFunc(func(msg sdk.Msg) baseapp.MsgServiceHandler {
Expand Down
6 changes: 6 additions & 0 deletions x/exchange/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

attrtypes "github.com/provenance-io/provenance/x/attribute/types"
markertypes "github.com/provenance-io/provenance/x/marker/types"
)

type AccountKeeper interface {
Expand All @@ -30,3 +31,8 @@ type HoldKeeper interface {
ReleaseHold(ctx sdk.Context, addr sdk.AccAddress, funds sdk.Coins) error
GetHoldCoin(ctx sdk.Context, addr sdk.AccAddress, denom string) (sdk.Coin, error)
}

type MarkerKeeper interface {
GetMarker(ctx sdk.Context, address sdk.AccAddress) (markertypes.MarkerAccountI, error)
AddSetNetAssetValues(ctx sdk.Context, marker markertypes.MarkerAccountI, netAssetValues []markertypes.NetAssetValue, source string) error
}
55 changes: 55 additions & 0 deletions x/exchange/fulfillment.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,58 @@ func getPriceTransfer(f *orderFulfillment) (*Transfer, error) {
// This is here in case a new SubTypeI is made that isn't accounted for in here.
panic(fmt.Errorf("%s order %d: unknown order type", f.GetOrderType(), f.GetOrderID()))
}

// NetAssetValue is a total of assets and the price they sold for.
type NetAssetValue struct {
Taztingo marked this conversation as resolved.
Show resolved Hide resolved
// Assets is the funds being bought/sold
Assets sdk.Coin
// Price is the price paid for those assets.
Price sdk.Coin
}

// filterOrders returns all the filled orders (partial or full) that return true from the checker.
func filterOrders(settlement *Settlement, checker func(order OrderI) bool) []OrderI {
var rv []OrderI
for _, order := range settlement.FullyFilledOrders {
if checker(order) {
rv = append(rv, order)
}
}
if settlement.PartialOrderFilled != nil && checker(settlement.PartialOrderFilled) {
rv = append(rv, settlement.PartialOrderFilled)
}
return rv
}

// GetNAVs returns all the net-asset-value entries that represent this settlement.
func GetNAVs(settlement *Settlement) []*NetAssetValue {
// We need to count ONLY the bid orders or ONLY the ask orders.
// But some settlements are expected to only have one or the other, so look
// for bids first and fall back to asks if there aren't any bids.
// I chose bids first because they're filled at their listed price, but I don't
// think it really matters which one is chosen to check first.
orders := filterOrders(settlement, OrderI.IsBidOrder)
if len(orders) == 0 {
orders = filterOrders(settlement, OrderI.IsAskOrder)
}

var navs []*NetAssetValue
for _, order := range orders {
assets := order.GetAssets()
price := order.GetPrice()
found := false
for _, nav := range navs {
if nav.Assets.Denom == assets.Denom && nav.Price.Denom == price.Denom {
found = true
nav.Assets.Amount = nav.Assets.Amount.Add(assets.Amount)
nav.Price.Amount = nav.Price.Amount.Add(price.Amount)
break
}
}
if !found {
navs = append(navs, &NetAssetValue{Assets: assets, Price: price})
}
}

return navs
}
Loading
Loading