Sifchain / sifnode

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

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

Open snobbee opened 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/oracle/types/prophecy.go#L0-L32 https://github.com/Sifchain/sifnode/blob/main/x/oracle/types/prophecy.go#L0-L72

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 distributing the liquidity immediately, schedule it to be distributed gradually over the specified duration. This will likely involve creating a new function to handle the distribution, which will be called at regular intervals until the duration has passed.`
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. Pass this parameter when creating the 'MsgAddLiquidityToRewardBucket' message.`
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. Pass this parameter when creating the 'MsgAddLiquidityToRewardBucket' message.`
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 for the 'AddLiquidityToRewardBucket' message and handler to account for the new duration parameter. Ensure that the tests cover cases where the duration is zero (for immediate distribution), positive (for gradual distribution), and negative (which should be rejected).`

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

πŸ’‘ Steps

Update ValidateBasic Function **Action:** `modify` **File:** `x/clp/types/message_add_liquidity_to_rewards_bucket.go` **Lines:** `[1, 50]` **Dependencies:** `[]` **Instructions:** `In the 'ValidateBasic' function of the 'MsgAddLiquidityToRewardBucket' message, add a check to return an error if the 'Duration' field is negative. Import the 'errors' package from 'x/clp/types/errors.go' to use predefined error types.`
Implement Time-based Job Scheduler **Action:** `create` **File:** `x/clp/keeper/scheduler.go` **Lines:** `[1, 100]` **Dependencies:** `['Step 1']` **Instructions:** `Create a new file 'scheduler.go' in the 'x/clp/keeper' directory. Implement a time-based job scheduler that will handle the incremental distribution of liquidity over the specified duration. This scheduler should be able to queue jobs and execute them at the correct intervals based on the block time.`
Update CLI for Duration Parameter **Action:** `modify` **File:** `x/clp/client/cli/tx.go` **Lines:** `[1, 200]` **Dependencies:** `['Step 2']` **Instructions:** `Modify the CLI command for adding liquidity to a reward bucket to accept an optional 'duration' flag. Ensure that the flag is parsed correctly and passed to the message constructor. Use the 'flag' package to define the new flag.`
Update REST API for Duration Parameter **Action:** `modify` **File:** `x/clp/client/rest/tx.go` **Lines:** `[1, 150]` **Dependencies:** `['Step 3']` **Instructions:** `Update the REST API endpoint for adding liquidity to a reward bucket to parse the optional 'duration' parameter from the request body. Validate the input and ensure it is correctly included in the message that is created and signed.`
Create Unit Tests for Duration Parameter **Action:** `create` **File:** `x/clp/keeper/add_liquidity_to_rewards_bucket_test.go` **Lines:** `[1, 200]` **Dependencies:** `['Step 4']` **Instructions:** `Create comprehensive unit tests in 'add_liquidity_to_rewards_bucket_test.go' to cover the new duration parameter functionality. Test cases should include zero, negative, non-numeric, and out-of-range duration values. Use the 'testify' package for assertions.`
snobbee commented 5 months ago

The workflow is well-structured but could use more detail in certain areas. For negative duration, the 'ValidateBasic' function should return an error. For the gradual distribution functionality, consider using a time-based job scheduler or a similar mechanism to distribute the liquidity over time. For the CLI command and REST API updates, include error handling for invalid inputs. For the unit tests, ensure coverage for edge cases such as zero, negative, and extremely large duration values, as well as non-numeric and out-of-range inputs for the CLI command and REST API.