Skip to content

Commit

Permalink
feat: link governance engine and execution engine with community tags
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Letang <me@jeremyletang.com>
  • Loading branch information
jeremyletang committed Aug 12, 2024
1 parent a001bec commit 4eaaaf7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 16 deletions.
14 changes: 14 additions & 0 deletions core/execution/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,3 +1564,17 @@ func (e *Engine) GetFillPriceForMarket(marketID string, volume uint64, side type
}
return nil, types.ErrInvalidMarketID
}

func (e *Engine) UpdateCommunityTags(
ctx context.Context,
market string,
addTags []string,
removeTags []string,
) {
// has the market been removed since the proposal was created?
if !e.MarketExists(market) {
return
}

e.communityTags.UpdateTags(ctx, market, addTags, removeTags)
}
2 changes: 2 additions & 0 deletions core/governance/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ func (e *Engine) preEnactProposal(ctx context.Context, p *proposal) (te *ToEnact
te.volumeDiscountProgram = updatedVolumeDiscountProgramFromProposal(p)
case types.ProposalTermsTypeUpdateVolumeRebateProgram:
te.volumeRebateProgram = updatedVolumeRebateProgramFromProposal(p)
case types.ProposalTermsTypeUpdateMarketCommunityTags:
te.updateMarketCommunityTags = p.UpdateMarketCommunityTags()
}
return //nolint:nakedret
}
Expand Down
41 changes: 25 additions & 16 deletions core/governance/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,23 @@ func (p *proposal) purgeBlankVotes(votes map[string]*types.Vote) {
// ToEnact wraps the proposal in a type that has a convenient interface
// to quickly work out what change we're dealing with, and get the data.
type ToEnact struct {
p *proposal
m *ToEnactNewMarket
s *ToEnactNewSpotMarket
newAsset *types.Asset
updatedAsset *types.Asset
n *types.NetworkParameter
as *types.AssetDetails
updatedMarket *types.Market
updatedSpotMarket *types.Market
f *ToEnactFreeform
t *ToEnactTransfer
c *ToEnactCancelTransfer
msu *ToEnactMarketStateUpdate
referralProgramChanges *types.ReferralProgram
volumeDiscountProgram *types.VolumeDiscountProgram
volumeRebateProgram *types.VolumeRebateProgram
p *proposal
m *ToEnactNewMarket
s *ToEnactNewSpotMarket
newAsset *types.Asset
updatedAsset *types.Asset
n *types.NetworkParameter
as *types.AssetDetails
updatedMarket *types.Market
updatedSpotMarket *types.Market
f *ToEnactFreeform
t *ToEnactTransfer
c *ToEnactCancelTransfer
msu *ToEnactMarketStateUpdate
referralProgramChanges *types.ReferralProgram
volumeDiscountProgram *types.VolumeDiscountProgram
volumeRebateProgram *types.VolumeRebateProgram
updateMarketCommunityTags *types.UpdateMarketCommunityTags
}

type ToEnactMarketStateUpdate struct{}
Expand All @@ -275,6 +276,10 @@ type ToEnactNewSpotMarket struct{}
// ToEnactFreeform there is nothing to enact with a freeform proposal.
type ToEnactFreeform struct{}

func (t ToEnact) IsUpdateMarketCommunityTags() bool {
return t.updateMarketCommunityTags != nil
}

func (t ToEnact) IsVolumeDiscountProgramUpdate() bool {
return t.volumeDiscountProgram != nil
}
Expand Down Expand Up @@ -372,6 +377,10 @@ func (t *ToEnact) VolumeRebateProgramUpdate() *types.VolumeRebateProgram {
return t.volumeRebateProgram
}

func (t *ToEnact) UpdateMarketCommunityTags() *types.UpdateMarketCommunityTags {
return t.updateMarketCommunityTags
}

func (t *ToEnact) UpdateMarket() *types.Market {
return t.updatedMarket
}
Expand Down
5 changes: 5 additions & 0 deletions core/processor/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2720,6 +2720,11 @@ func (app *App) onTick(ctx context.Context, t time.Time) {
case toEnact.IsVolumeRebateProgramUpdate():
prop.State = types.ProposalStateEnacted
app.volumeRebateProgram.UpdateProgram(toEnact.VolumeRebateProgramUpdate())
case toEnact.IsUpdateMarketCommunityTags():
prop.State = types.ProposalStateEnacted
tags := toEnact.UpdateMarketCommunityTags()
app.exec.UpdateCommunityTags(
ctx, tags.MarketID, tags.AddTags, tags.RemoveTags)
default:
app.log.Error("unknown proposal cannot be enacted", logging.ProposalID(prop.ID))
prop.FailUnexpectedly(fmt.Errorf("unknown proposal \"%s\" cannot be enacted", prop.ID))
Expand Down
12 changes: 12 additions & 0 deletions core/processor/mocks/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ type ExecutionEngine interface {

// add this method here for testing, this is the exec engine interface used by the gastimator.
GetMarketCounters() map[string]*types.MarketCounters

UpdateCommunityTags(ctx context.Context, market string, addTags []string, removeTags []string)
}

type GovernanceEngine interface {
Expand Down

0 comments on commit 4eaaaf7

Please sign in to comment.