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

[CL Incentives] Implement CreateIncentive logic and message #4519

Merged
merged 11 commits into from
Mar 10, 2023

Conversation

AlpinYukseloglu
Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu commented Mar 6, 2023

Closes: #4400, #4183

What is the purpose of the change

This PR implements incentive creation logic and its respective message.

Brief Changelog

  • Implement createIncentive
  • Implement MsgCreateIncentive & related wiring

Testing and Verifying

  • New functionality is tested in incentives_test.go

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (no)
  • How is the feature or change documented? (not documented)

Copy link
Contributor

@stackman27 stackman27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just have couple of questions

Comment on lines +141 to +142
string incentive_denom = 3;
string incentive_amount = 4 [
Copy link
Contributor

@stackman27 stackman27 Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought, why not set this as Coin instead of denom and amount? so that later down the line we can create incentives record for many Coins

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on making this a Coin, unless it was by design for a reason I am not seeing.


func (msg MsgCreateIncentive) Route() string { return RouterKey }
func (msg MsgCreateIncentive) Type() string { return TypeMsgCollectIncentives }
func (msg MsgCreateIncentive) ValidateBasic() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

Copy link
Contributor

@stackman27 stackman27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also do we ever need to update Incentive Records? or are these also non fungible once created?

Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done :) just a few non blocking comments

Comment on lines +141 to +142
string incentive_denom = 3;
string incentive_amount = 4 [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on making this a Coin, unless it was by design for a reason I am not seeing.

Comment on lines +166 to +171
string incentive_denom = 1;
string incentive_amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"incentive_amount\"",
(gogoproto.nullable) = false
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this

Comment on lines +82 to +83
Flags: osmocli.FlagDesc{RequiredFlags: []*flag.FlagSet{FlagSetJustPoolId()}},
}, &types.MsgCreateIncentive{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking, but we have been trying to move away from mandatory flags, would be nice if we could just make poolId be part of the create incentive message

Comment on lines +2819 to +2829
"existing incentive records": {
poolId: defaultPoolId,
sender: s.TestAccs[0],
senderBalance: sdk.NewCoins(
sdk.NewCoin(
incentiveRecordOne.IncentiveDenom,
incentiveRecordOne.RemainingAmount.Ceil().RoundInt(),
),
),
recordToSet: incentiveRecordOne,
existingRecords: []types.IncentiveRecord{incentiveRecordTwo, incentiveRecordThree},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test case that tests what happens if someone creates the same incentive record twice? Does it add to the existing incentive record? I don't believe this tests that test case since I think incentiveRecordTwo and Three have different params.


func (msg MsgCreateIncentive) Route() string { return RouterKey }
func (msg MsgCreateIncentive) Type() string { return TypeMsgCollectIncentives }
func (msg MsgCreateIncentive) ValidateBasic() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

validUptime := false
for _, supportedUptime := range types.SupportedUptimes {
if minUptime == supportedUptime {
validUptime = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validUptime = true
validUptime = true
break

}

// Ensure sender has balance for incentive denom
incentiveCoin := sdk.NewCoin(incentiveDenom, incentiveAmount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to earlier comments - I think having it as Coin from the start makes more sense to me as well

Comment on lines +211 to +228
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
),
sdk.NewEvent(
types.TypeEvtCreateIncentive,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
sdk.NewAttribute(types.AttributeKeyPoolId, strconv.FormatUint(msg.PoolId, 10)),
sdk.NewAttribute(types.AttributeIncentiveDenom, msg.IncentiveDenom),
sdk.NewAttribute(types.AttributeIncentiveAmount, msg.IncentiveAmount.String()),
sdk.NewAttribute(types.AttributeIncentiveEmissionRate, msg.EmissionRate.String()),
sdk.NewAttribute(types.AttributeIncentiveStartTime, msg.StartTime.String()),
sdk.NewAttribute(types.AttributeIncentiveMinUptime, msg.MinUptime.String()),
),
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test these events being emitted?

@mergify
Copy link
Contributor

mergify bot commented Mar 10, 2023

⚠️ The sha of the head commit of this PR conflicts with #4569. Mergify cannot evaluate rules on this PR. ⚠️

AlpinYukseloglu added a commit that referenced this pull request Mar 15, 2023
* initial push

* push

* untracked files

* add untracked files

* merge branches

* add changes required for fees

* lint

* fix test errors

* clean up

* remove print lines

* feat: single fee accum (#4116)

* single fee accum

* lint

* no longer need to get all positions for fee

* incentive accum initialization

* lint

* Update x/concentrated-liquidity/store_test.go

Co-authored-by: Sishir Giri <[email protected]>

* add lower level tests and make uptime accum access private

* lint

* add gotests for helper fn

* Update test to use existing variable

Co-authored-by: Roman <[email protected]>

* create or update records upon position creation/update

* add tests and clean up

* sync position-related changes

* add support for negative liquidity delta

* add and test helper & set up tick initialization logic

* implement accumulator updates on tick crossing and clean up proto

* clean up comments

* minor test cleanup

* ensure accum initalization follows conventions and clean up tests

* update pool proto and CL pool extension for tracking liq changes

* update new field at pool initialization and add tests

* comment todos

* clean up naming and move empty options to global var

* add clarifying comments and lint

* implement IncentiveRecord proto

* add comments

* lint

* set up wiring for proto

* implement updateUptimeAccumulatorsToNow

* implement and test calcAccruedIncentivesForAccum

* add tests for new helpers

* minor comment updates

Co-authored-by: Roman <[email protected]>

* accum test updates

* lint

* clean up diff

* lint

* update go.mod for e2e

* clean up proto and add error message

* lint

* sketch out testing approach

* set up keys

* clean up diff

* clean up comments

* lint

* implement set and get for incentive records

* comment cleanup

* minor comment and test cleanup

* clean up tests and comments

* [CL Incentives] Implement `setIncentiveRecords` and `getIncentiveRecords` (#4283)

* set up keys

* implement set and get for incentive records

* comment cleanup

* minor comment and test cleanup

* Revert "[CL Incentives] Implement `setIncentiveRecords` and `getIncentiveRecords` (#4283)" (#4294)

This reverts commit de7c146.

* set incentive records in new position tests

* fix merge conflicts

* add check for init position record values

* fix and finalize uptime accum position tests

* fix go mod for e2e

* clean up diff

* add err check to accum update

* fix rounding error

* implement tick init uptime tracker logic

* fix test compatibility

* implement fix for global accums falling out of sync before tick init

* add tests to ensure uptime trackers are initialized properly

* add comment for new helper

* add core logic

* go mod tidy

* fix conflicts

* fix e2e

* update go mod

* fix and further test tick init logic

* remove redundant values from incentive record state

* cleanup from review

* comment cleanup

* set up cross tick tests

* add further tests

* test and comment cleanup

* implement core logic

* update osmoutils go mod and remove curTick as fn param

* thorough tests for new functionality

* clean up new functions for readability

* clean up test comments

* fix test names

* lint

* add godoc and further comments

* update go mod for e2e

* update liq change logic

* update uptime accums before gettings them for tick crossing

* abstract uptime init and update logic to helper

* add thorough tests for initOrUpdatePositionUptime

* update liquidity update logic and tests to use new helper

* add todo for frozenuntil issue

* lint

* lint

* clean up logic and add tests for helper

* go mod for osmoutils e2e

* move position key computation outside loop

* clean up imports and go sum

* fix imports

* [CL Incentives][bugfix]: Replace all uses of frozenUntil with joinTime and freezeDuration

* e2e passing

* implement message, proto, and core logic

* convert freezeduration to uint64

* implement tests for collectIncentives

* add msg level tests and clean up logic/tests

* add codec, cli, and simulation

* claim incentives upon position deletion to clear records

* comment cleanup

* lint

* minor test comment updates

Co-authored-by: Roman <[email protected]>

* godoc update

Co-authored-by: Roman <[email protected]>

* expand withdraw tests to better include incentives logic

* minor optimizations and cleanup from code review

* [CL Incentives] Implement `CreateIncentive` logic and message (#4519)

* draft implementation

* begin testing

* add more test cases

* add error catching test cases

* implement createIncentive message

* cli and codec

* add check and related tests

* add further tests and lint

* add test case for existing incentive records

* Revert "[CL Incentives] Implement `CreateIncentive` logic and message (#4519)" (#4568)

This reverts commit b07e763.

* fix conflicts

---------

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Sishir Giri <[email protected]>
Co-authored-by: Roman <[email protected]>
AlpinYukseloglu added a commit that referenced this pull request Mar 15, 2023
* initial push

* push

* untracked files

* add untracked files

* merge branches

* add changes required for fees

* lint

* fix test errors

* clean up

* remove print lines

* feat: single fee accum (#4116)

* single fee accum

* lint

* no longer need to get all positions for fee

* incentive accum initialization

* lint

* Update x/concentrated-liquidity/store_test.go

Co-authored-by: Sishir Giri <[email protected]>

* add lower level tests and make uptime accum access private

* lint

* add gotests for helper fn

* Update test to use existing variable

Co-authored-by: Roman <[email protected]>

* create or update records upon position creation/update

* add tests and clean up

* sync position-related changes

* add support for negative liquidity delta

* add and test helper & set up tick initialization logic

* implement accumulator updates on tick crossing and clean up proto

* clean up comments

* minor test cleanup

* ensure accum initalization follows conventions and clean up tests

* update pool proto and CL pool extension for tracking liq changes

* update new field at pool initialization and add tests

* comment todos

* clean up naming and move empty options to global var

* add clarifying comments and lint

* implement IncentiveRecord proto

* add comments

* lint

* set up wiring for proto

* implement updateUptimeAccumulatorsToNow

* implement and test calcAccruedIncentivesForAccum

* add tests for new helpers

* minor comment updates

Co-authored-by: Roman <[email protected]>

* accum test updates

* lint

* clean up diff

* lint

* update go.mod for e2e

* clean up proto and add error message

* lint

* sketch out testing approach

* set up keys

* clean up diff

* clean up comments

* lint

* implement set and get for incentive records

* comment cleanup

* minor comment and test cleanup

* clean up tests and comments

* [CL Incentives] Implement `setIncentiveRecords` and `getIncentiveRecords` (#4283)

* set up keys

* implement set and get for incentive records

* comment cleanup

* minor comment and test cleanup

* Revert "[CL Incentives] Implement `setIncentiveRecords` and `getIncentiveRecords` (#4283)" (#4294)

This reverts commit de7c146.

* set incentive records in new position tests

* fix merge conflicts

* add check for init position record values

* fix and finalize uptime accum position tests

* fix go mod for e2e

* clean up diff

* add err check to accum update

* fix rounding error

* implement tick init uptime tracker logic

* fix test compatibility

* implement fix for global accums falling out of sync before tick init

* add tests to ensure uptime trackers are initialized properly

* add comment for new helper

* add core logic

* go mod tidy

* fix conflicts

* fix e2e

* update go mod

* fix and further test tick init logic

* remove redundant values from incentive record state

* cleanup from review

* comment cleanup

* set up cross tick tests

* add further tests

* test and comment cleanup

* implement core logic

* update osmoutils go mod and remove curTick as fn param

* thorough tests for new functionality

* clean up new functions for readability

* clean up test comments

* fix test names

* lint

* add godoc and further comments

* update go mod for e2e

* update liq change logic

* update uptime accums before gettings them for tick crossing

* abstract uptime init and update logic to helper

* add thorough tests for initOrUpdatePositionUptime

* update liquidity update logic and tests to use new helper

* add todo for frozenuntil issue

* lint

* lint

* clean up logic and add tests for helper

* go mod for osmoutils e2e

* move position key computation outside loop

* clean up imports and go sum

* fix imports

* [CL Incentives][bugfix]: Replace all uses of frozenUntil with joinTime and freezeDuration

* e2e passing

* implement message, proto, and core logic

* convert freezeduration to uint64

* implement tests for collectIncentives

* add msg level tests and clean up logic/tests

* draft implementation

* begin testing

* add codec, cli, and simulation

* claim incentives upon position deletion to clear records

* comment cleanup

* add more test cases

* lint

* add error catching test cases

* implement createIncentive message

* cli and codec

* add check and related tests

* add further tests and lint

* add test case for existing incentive records

* minor test comment updates

Co-authored-by: Roman <[email protected]>

* godoc update

Co-authored-by: Roman <[email protected]>

* expand withdraw tests to better include incentives logic

* minor optimizations and cleanup from code review

* [CL Incentives] Implement `CreateIncentive` logic and message (#4519)

* draft implementation

* begin testing

* add more test cases

* add error catching test cases

* implement createIncentive message

* cli and codec

* add check and related tests

* add further tests and lint

* add test case for existing incentive records

* Revert "[CL Incentives] Implement `CreateIncentive` logic and message (#4519)" (#4568)

This reverts commit b07e763.

* fix conflicts

---------

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Sishir Giri <[email protected]>
Co-authored-by: Roman <[email protected]>
AlpinYukseloglu added a commit that referenced this pull request Mar 15, 2023
* initial push

* push

* untracked files

* add untracked files

* merge branches

* add changes required for fees

* lint

* fix test errors

* clean up

* remove print lines

* feat: single fee accum (#4116)

* single fee accum

* lint

* no longer need to get all positions for fee

* incentive accum initialization

* lint

* Update x/concentrated-liquidity/store_test.go

Co-authored-by: Sishir Giri <[email protected]>

* add lower level tests and make uptime accum access private

* lint

* add gotests for helper fn

* Update test to use existing variable

Co-authored-by: Roman <[email protected]>

* create or update records upon position creation/update

* add tests and clean up

* sync position-related changes

* add support for negative liquidity delta

* add and test helper & set up tick initialization logic

* implement accumulator updates on tick crossing and clean up proto

* clean up comments

* minor test cleanup

* ensure accum initalization follows conventions and clean up tests

* update pool proto and CL pool extension for tracking liq changes

* update new field at pool initialization and add tests

* comment todos

* clean up naming and move empty options to global var

* add clarifying comments and lint

* implement IncentiveRecord proto

* add comments

* lint

* set up wiring for proto

* implement updateUptimeAccumulatorsToNow

* implement and test calcAccruedIncentivesForAccum

* add tests for new helpers

* minor comment updates

Co-authored-by: Roman <[email protected]>

* accum test updates

* lint

* clean up diff

* lint

* update go.mod for e2e

* clean up proto and add error message

* lint

* sketch out testing approach

* set up keys

* clean up diff

* clean up comments

* lint

* implement set and get for incentive records

* comment cleanup

* minor comment and test cleanup

* clean up tests and comments

* [CL Incentives] Implement `setIncentiveRecords` and `getIncentiveRecords` (#4283)

* set up keys

* implement set and get for incentive records

* comment cleanup

* minor comment and test cleanup

* Revert "[CL Incentives] Implement `setIncentiveRecords` and `getIncentiveRecords` (#4283)" (#4294)

This reverts commit de7c146.

* set incentive records in new position tests

* fix merge conflicts

* add check for init position record values

* fix and finalize uptime accum position tests

* fix go mod for e2e

* clean up diff

* add err check to accum update

* fix rounding error

* implement tick init uptime tracker logic

* fix test compatibility

* implement fix for global accums falling out of sync before tick init

* add tests to ensure uptime trackers are initialized properly

* add comment for new helper

* add core logic

* go mod tidy

* fix conflicts

* fix e2e

* update go mod

* fix and further test tick init logic

* remove redundant values from incentive record state

* cleanup from review

* comment cleanup

* set up cross tick tests

* add further tests

* test and comment cleanup

* implement core logic

* update osmoutils go mod and remove curTick as fn param

* thorough tests for new functionality

* clean up new functions for readability

* clean up test comments

* fix test names

* lint

* add godoc and further comments

* update go mod for e2e

* update liq change logic

* update uptime accums before gettings them for tick crossing

* abstract uptime init and update logic to helper

* add thorough tests for initOrUpdatePositionUptime

* update liquidity update logic and tests to use new helper

* add todo for frozenuntil issue

* lint

* lint

* clean up logic and add tests for helper

* go mod for osmoutils e2e

* move position key computation outside loop

* clean up imports and go sum

* fix imports

* [CL Incentives][bugfix]: Replace all uses of frozenUntil with joinTime and freezeDuration

* e2e passing

* implement message, proto, and core logic

* convert freezeduration to uint64

* implement tests for collectIncentives

* add msg level tests and clean up logic/tests

* draft implementation

* begin testing

* add codec, cli, and simulation

* claim incentives upon position deletion to clear records

* comment cleanup

* add more test cases

* lint

* add error catching test cases

* implement createIncentive message

* cli and codec

* add check and related tests

* add further tests and lint

* add test case for existing incentive records

* pull relevant changes into new branch

* lint

* minor test comment updates

Co-authored-by: Roman <[email protected]>

* godoc update

Co-authored-by: Roman <[email protected]>

* expand withdraw tests to better include incentives logic

* minor optimizations and cleanup from code review

* [CL Incentives] Implement `CreateIncentive` logic and message (#4519)

* draft implementation

* begin testing

* add more test cases

* add error catching test cases

* implement createIncentive message

* cli and codec

* add check and related tests

* add further tests and lint

* add test case for existing incentive records

* Revert "[CL Incentives] Implement `CreateIncentive` logic and message (#4519)" (#4568)

This reverts commit b07e763.

* make unit tests more robust

* minor comment cleanup

* fix conflicts

---------

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Sishir Giri <[email protected]>
Co-authored-by: Roman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants