Sifchain / sifnode

SifNode - The future of Defi
Other
108 stars 119 forks source link

Enhance Non-Rowan Yield Reward Functionality with Optional Duration Feature #3438

Closed snobbee closed 5 months ago

snobbee commented 5 months ago

Currently, the Sifchain codebase includes a feature for non-Rowan yield rewards, where users can add non-Rowan liquidity to a reward bucket. The system then automatically distributes the entire liquidity in the bucket to the corresponding liquidity pool. This is a valuable functionality, but it could be further enhanced for better flexibility and utility.

Feature Request: I propose adding an optional duration parameter to this existing functionality. When this duration is set, any new liquidity added to the reward bucket should not be distributed immediately in its entirety. Instead, it would be more beneficial if the distribution of this new liquidity is spread out over the specified duration. This means the liquidity would be distributed in smaller, incremental portions throughout the duration period, rather than all at once.

Benefits:

I believe this enhancement will add significant value to the Sifchain platform, offering greater control and flexibility to users in the management of non-Rowan liquidity rewards.

snobbee commented 5 months ago

1. πŸ“ Indexing

I'm indexing the files within your repository.

2. πŸ”Ž Searching

I'm searching for relevant snippets in your repository.

I found the following snippets in your repository.

View Snippets https://github.com/Sifchain/sifnode/blob/main/x/dispensation/claims.md#L0-L15 https://github.com/Sifchain/sifnode/blob/main/x/dispensation/claims.md#L15-L30 https://github.com/Sifchain/sifnode/blob/main/x/dispensation/claims.md#L30-L45 https://github.com/Sifchain/sifnode/blob/main/x/clp/keeper/calculations.go#L0-L25 https://github.com/Sifchain/sifnode/blob/main/x/clp/keeper/calculations.go#L0-L26

3. 🌐 Planning

I'm creating a plan for the discussion and coding steps.

I have created the following workflow as a basis for how the discussion and coding will be derived.

πŸ’‘ Steps

Add Duration Parameter to AddLiquidityToRewardBucket Message **Action:** `modify` **File:** `x/clp/types/message_add_liquidity_to_rewards_bucket.go` **Lines:** `[1, 50]` **Dependencies:** `[]` **Instructions:** `Add a new field 'Duration' of type 'time.Duration' to the 'MsgAddLiquidityToRewardBucket' struct. This field will represent the duration over which the added liquidity will be distributed. Update the 'NewMsgAddLiquidityToRewardBucket' function to accept this new parameter and assign it to the created message. Update the 'ValidateBasic' function to check that the duration is not negative.`
Update AddLiquidityToRewardBucket Handler **Action:** `modify` **File:** `x/clp/keeper/msg_server_add_liquidity_to_rewards_bucket.go` **Lines:** `[1, 50]` **Dependencies:** `['Step 1']` **Instructions:** `Update the 'AddLiquidityToRewardBucket' function to handle the new duration parameter. Instead of immediately distributing the added liquidity, schedule it to be distributed over the specified duration. This will likely involve creating a new 'DistributionSchedule' struct that keeps track of the remaining liquidity and the end time, and adding a new 'DistributionSchedules' field to the 'RewardBucket' struct. Update the 'EndBlocker' function to distribute the scheduled liquidity.`
Update CLI Command **Action:** `modify` **File:** `x/clp/client/cli/tx_add_liquidity_to_rewards_bucket.go` **Lines:** `[1, 50]` **Dependencies:** `['Step 1']` **Instructions:** `Update the 'CmdAddLiquidityToRewardBucket' function to accept the new duration parameter from the command line and pass it to the 'NewMsgAddLiquidityToRewardBucket' function.`
Update REST API **Action:** `modify` **File:** `x/clp/client/rest/tx.go` **Lines:** `[1, 50]` **Dependencies:** `['Step 1']` **Instructions:** `Update the 'registerTxRoutes' function to accept the new duration parameter from the HTTP request and pass it to the 'NewMsgAddLiquidityToRewardBucket' function.`
Update Unit Tests **Action:** `modify` **File:** `x/clp/keeper/msg_server_add_liquidity_to_rewards_bucket_test.go` **Lines:** `[1, 50]` **Dependencies:** `['Step 1', 'Step 2']` **Instructions:** `Update the unit tests to cover the new functionality. This should include tests for the case where the duration is zero (which should behave the same as before), the case where the duration is positive, and the case where the duration is negative (which should return an error).`
snobbee commented 5 months ago

The key functionalities around Reward buckets are located within those files:

snobbee commented 5 months ago

Given the complexity of updating the 'AddLiquidityToRewardBucket' function and the potential for errors, I suggest breaking down Step 2 into smaller, more manageable subtasks. This could include creating the 'DistributionSchedule' struct, adding the 'DistributionSchedules' field to the 'RewardBucket' struct, and updating the 'EndBlocker' function separately. Additionally, to address the concern about negative duration, we should ensure that the check for negative duration is robust and fails gracefully. This could be done by returning a specific error message when the duration is negative, and handling this error appropriately in the calling code. Finally, to ensure thorough testing, we should consider using test-driven development. This would involve writing the tests for the new functionality before implementing it, which can help ensure that all edge cases are covered.