Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Oct 18, 2023
2 parents d70a3ab + abf94a0 commit 41bb6c6
Show file tree
Hide file tree
Showing 73 changed files with 60,395 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* Create the `x/exchange` module which facilitates the buying and selling of assets [#1658](https://github.com/provenance-io/provenance/issues/1658).
Assets and funds remain in their owner's account (with a hold on them) until the order is settled (or cancelled).
Market's are created to manage order matching and define fees.
The chain will receive a portion of the fees a market collects.
* Allow marker's transfer authority to prevent transfer of restricted coin with deny list on send [#1518](https://github.com/provenance-io/provenance/issues/1518).
* Add net asset value to markers [#1328](https://github.com/provenance-io/provenance/issues/1328).
* Add ICQHost and Oracle module to allow cross chain oracle queries [#1497](https://github.com/provenance-io/provenance/issues/1497).
Expand Down
19 changes: 18 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ import (
attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper"
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
attributewasm "github.com/provenance-io/provenance/x/attribute/wasm"
"github.com/provenance-io/provenance/x/exchange"
exchangekeeper "github.com/provenance-io/provenance/x/exchange/keeper"
exchangemodule "github.com/provenance-io/provenance/x/exchange/module"
"github.com/provenance-io/provenance/x/hold"
holdkeeper "github.com/provenance-io/provenance/x/hold/keeper"
holdmodule "github.com/provenance-io/provenance/x/hold/module"
ibchooks "github.com/provenance-io/provenance/x/ibchooks"
"github.com/provenance-io/provenance/x/ibchooks"
ibchookskeeper "github.com/provenance-io/provenance/x/ibchooks/keeper"
ibchookstypes "github.com/provenance-io/provenance/x/ibchooks/types"
"github.com/provenance-io/provenance/x/marker"
Expand Down Expand Up @@ -226,6 +229,7 @@ var (
triggermodule.AppModuleBasic{},
oraclemodule.AppModuleBasic{},
holdmodule.AppModuleBasic{},
exchangemodule.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -317,6 +321,7 @@ type App struct {
AttributeKeeper attributekeeper.Keeper
NameKeeper namekeeper.Keeper
HoldKeeper holdkeeper.Keeper
ExchangeKeeper exchangekeeper.Keeper
WasmKeeper *wasm.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper

Expand Down Expand Up @@ -400,6 +405,7 @@ func New(
triggertypes.StoreKey,
oracletypes.StoreKey,
hold.StoreKey,
exchange.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -569,6 +575,11 @@ func New(
appCodec, keys[hold.StoreKey], app.BankKeeper,
)

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

pioMessageRouter := MessageRouterFunc(func(msg sdk.Msg) baseapp.MsgServiceHandler {
return pioMsgFeesRouter.Handler(msg)
})
Expand Down Expand Up @@ -751,6 +762,7 @@ func New(
triggermodule.NewAppModule(appCodec, app.TriggerKeeper, app.AccountKeeper, app.BankKeeper),
oracleModule,
holdmodule.NewAppModule(appCodec, app.HoldKeeper),
exchangemodule.NewAppModule(appCodec, app.ExchangeKeeper),

// IBC
ibc.NewAppModule(app.IBCKeeper),
Expand Down Expand Up @@ -801,6 +813,7 @@ func New(
quarantine.ModuleName,
sanction.ModuleName,
hold.ModuleName,
exchange.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -840,6 +853,7 @@ func New(
quarantine.ModuleName,
sanction.ModuleName,
hold.ModuleName,
exchange.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -871,6 +885,7 @@ func New(
metadatatypes.ModuleName,
msgfeestypes.ModuleName,
hold.ModuleName,
exchange.ModuleName, // must be after the hold module.

ibchost.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -911,6 +926,7 @@ func New(
quarantine.ModuleName,
sanction.ModuleName,
hold.ModuleName,
exchange.ModuleName,

ibchookstypes.ModuleName,
icatypes.ModuleName,
Expand Down Expand Up @@ -961,6 +977,7 @@ func New(
triggermodule.NewAppModule(appCodec, app.TriggerKeeper, app.AccountKeeper, app.BankKeeper),
oraclemodule.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper, app.IBCKeeper.ChannelKeeper),
holdmodule.NewAppModule(appCodec, app.HoldKeeper),
exchangemodule.NewAppModule(appCodec, app.ExchangeKeeper),
provwasm.NewWrapper(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.NameKeeper),

// IBC
Expand Down
28 changes: 24 additions & 4 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper"
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
"github.com/provenance-io/provenance/x/exchange"
"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"
Expand Down Expand Up @@ -115,10 +116,11 @@ var upgrades = map[string]appUpgrade{
setupICQ(ctx, app)
updateMaxSupply(ctx, app)
addMarkerNavs(ctx, app)
setExchangeParams(ctx, app)

return vm, nil
},
Added: []string{icqtypes.ModuleName, oracletypes.ModuleName, ibchookstypes.ModuleName, hold.ModuleName},
Added: []string{icqtypes.ModuleName, oracletypes.ModuleName, ibchookstypes.ModuleName, hold.ModuleName, exchange.ModuleName},
},
"saffron": { // upgrade for v1.17.0,
Handler: func(ctx sdk.Context, app *App, vm module.VersionMap) (module.VersionMap, error) {
Expand All @@ -135,10 +137,11 @@ var upgrades = map[string]appUpgrade{
setupICQ(ctx, app)
updateMaxSupply(ctx, app)
addMarkerNavs(ctx, app)
setExchangeParams(ctx, app)

return vm, nil
},
Added: []string{icqtypes.ModuleName, oracletypes.ModuleName, ibchookstypes.ModuleName, hold.ModuleName},
Added: []string{icqtypes.ModuleName, oracletypes.ModuleName, ibchookstypes.ModuleName, hold.ModuleName, exchange.ModuleName},
},
// TODO - Add new upgrade definitions here.
}
Expand Down Expand Up @@ -327,14 +330,16 @@ func setAccountDataNameRecord(ctx sdk.Context, accountK attributetypes.AccountKe
return attributekeeper.EnsureModuleAccountAndAccountDataNameRecord(ctx, accountK, nameK)
}

// setupICQ sets the correct default values for ICQKeeper
// setupICQ sets the correct default values for ICQKeeper.
// TODO: Remove with the saffron handlers.
func setupICQ(ctx sdk.Context, app *App) {
ctx.Logger().Info("Updating ICQ params")
app.ICQKeeper.SetParams(ctx, icqtypes.NewParams(true, []string{"/provenance.oracle.v1.Query/Oracle"}))
ctx.Logger().Info("Done updating ICQ params")
}

// updateMaxSupply sets the value of max supply to the current value of MaxTotalSupply
// updateMaxSupply sets the value of max supply to the current value of MaxTotalSupply.
// TODO: Remove with the saffron handlers.
func updateMaxSupply(ctx sdk.Context, app *App) {
ctx.Logger().Info("Updating MaxSupply marker param")
params := app.MarkerKeeper.GetParams(ctx)
Expand Down Expand Up @@ -370,3 +375,18 @@ func addMarkerNavs(ctx sdk.Context, app *App) {
})
ctx.Logger().Info("Done adding marker net asset values")
}

// setExchangeParams sets exchange module's params to the defaults.
// TODO: Remove with the saffron handlers.
func setExchangeParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Ensuring exchange module params are set.")
params := app.ExchangeKeeper.GetParams(ctx)
if params != nil {
ctx.Logger().Info("Exchange module params are already defined.")
} else {
params = exchange.DefaultParams()
ctx.Logger().Info("Setting exchange module params to defaults.")
app.ExchangeKeeper.SetParams(ctx, params)
}
ctx.Logger().Info("Done ensuring exchange module params are set.")
}
78 changes: 77 additions & 1 deletion app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/provenance-io/provenance/x/exchange"
markertypes "github.com/provenance-io/provenance/x/marker/types"
msgfeetypes "github.com/provenance-io/provenance/x/msgfees/types"
)
Expand Down Expand Up @@ -429,6 +430,7 @@ func (s *UpgradeTestSuite) TestSaffronRC1() {
"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.",
}

s.AssertUpgradeHandlerLogs("saffron-rc1", expInLog, nil)
Expand All @@ -447,6 +449,7 @@ func (s *UpgradeTestSuite) TestSaffron() {
"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.",
}

s.AssertUpgradeHandlerLogs("saffron", expInLog, nil)
Expand Down Expand Up @@ -891,7 +894,6 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() {
expNav: nil,
},
}

for _, tc := range tests {
s.Run(tc.name, func() {
netAssetValues := []markertypes.NetAssetValue{}
Expand All @@ -910,3 +912,77 @@ func (s *UpgradeTestSuite) TestAddMarkerNavs() {
})
}
}

func (s *UpgradeTestSuite) TestSetExchangeParams() {
startMsg := "INF Ensuring exchange module params are set."
noopMsg := "INF Exchange module params are already defined."
updateMsg := "INF Setting exchange module params to defaults."
doneMsg := "INF Done ensuring exchange module params are set."

tests := []struct {
name string
existingParams *exchange.Params
expectedParams *exchange.Params
expInLog []string
}{
{
name: "no params set yet",
existingParams: nil,
expectedParams: exchange.DefaultParams(),
expInLog: []string{startMsg, updateMsg, doneMsg},
},
{
name: "params set with no splits and default zero",
existingParams: &exchange.Params{DefaultSplit: 0},
expectedParams: &exchange.Params{DefaultSplit: 0},
expInLog: []string{startMsg, noopMsg, doneMsg},
},
{
name: "params set with no splits and different default",
existingParams: &exchange.Params{DefaultSplit: exchange.DefaultDefaultSplit + 100},
expectedParams: &exchange.Params{DefaultSplit: exchange.DefaultDefaultSplit + 100},
expInLog: []string{startMsg, noopMsg, doneMsg},
},
{
name: "params set with some splits",
existingParams: &exchange.Params{
DefaultSplit: exchange.DefaultDefaultSplit + 100,
DenomSplits: []exchange.DenomSplit{
{Denom: "peach", Split: 3000},
{Denom: "plum", Split: 100},
},
},
expectedParams: &exchange.Params{
DefaultSplit: exchange.DefaultDefaultSplit + 100,
DenomSplits: []exchange.DenomSplit{
{Denom: "peach", Split: 3000},
{Denom: "plum", Split: 100},
},
},
expInLog: []string{startMsg, noopMsg, doneMsg},
},
}
for _, tc := range tests {
s.Run(tc.name, func() {
s.app.ExchangeKeeper.SetParams(s.ctx, tc.existingParams)

// Reset the log buffer and call the fun. Relog the output if it panics.
s.logBuffer.Reset()
testFunc := func() {
setExchangeParams(s.ctx, s.app)
}
didNotPanic := s.Assert().NotPanics(testFunc, "setExchangeParams")
logOutput := s.GetLogOutput("setExchangeParams")
if !didNotPanic {
return
}

// Make sure the log has the expected lines.
s.AssertLogContents(logOutput, tc.expInLog, nil, true, "setExchangeParams")

// Make sure the params are as expected now.
params := s.app.ExchangeKeeper.GetParams(s.ctx)
s.Assert().Equal(tc.expectedParams, params, "params after setExchangeParams")
})
}
}
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36409,8 +36409,8 @@ paths:
type: string
format: uint64
title: >-
maximum amount of supply to allow a marker to be created
with
Deprecated: Prefer to use `max_supply` instead. Maximum
amount of supply to allow a marker to be created with
enable_governance:
type: boolean
format: boolean
Expand All @@ -36425,6 +36425,11 @@ paths:

requests are only subject to platform coin validation
denom expression)
max_supply:
type: string
title: >-
maximum amount of supply to allow a marker to be created
with
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -83319,7 +83324,9 @@ definitions:
max_total_supply:
type: string
format: uint64
title: maximum amount of supply to allow a marker to be created with
title: >-
Deprecated: Prefer to use `max_supply` instead. Maximum amount of
supply to allow a marker to be created with
enable_governance:
type: boolean
format: boolean
Expand All @@ -83332,6 +83339,9 @@ definitions:

requests are only subject to platform coin validation denom
expression)
max_supply:
type: string
title: maximum amount of supply to allow a marker to be created with
description: Params defines the set of params for the account module.
provenance.marker.v1.QueryAccessResponse:
type: object
Expand Down Expand Up @@ -83950,7 +83960,9 @@ definitions:
max_total_supply:
type: string
format: uint64
title: maximum amount of supply to allow a marker to be created with
title: >-
Deprecated: Prefer to use `max_supply` instead. Maximum amount of
supply to allow a marker to be created with
enable_governance:
type: boolean
format: boolean
Expand All @@ -83963,6 +83975,9 @@ definitions:

requests are only subject to platform coin validation denom
expression)
max_supply:
type: string
title: maximum amount of supply to allow a marker to be created with
description: QueryParamsResponse is the response type for the Query/Params RPC method.
provenance.marker.v1.QuerySupplyResponse:
type: object
Expand Down
Loading

0 comments on commit 41bb6c6

Please sign in to comment.