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

Add LP staking into Picasso runtime #3504

Merged
merged 34 commits into from
May 4, 2023

Conversation

RustNinja
Copy link
Collaborator

@RustNinja RustNinja commented Apr 26, 2023

This PR added reward and farming pallets to cover use cases related to LP Reward staking

Introduced configuration of this pallets to picasso-runtime

Reward and farming pallet contains Mock Runtime and covered by unit tests.

  • reward pallet stores stakes and claimable reward for LP stakers.
  • farming pallet provides extrinsics:
    for Root origin:
    update_reward_schedule - create or overwrite the reward schedule
    remove_reward_schedule - Explicitly remove a reward schedule and transfer any remaining back to holding account
    for any origin:
    deposit - Stake the LP tokens in the reward pool and lock user balances until withdraw action(Store value in reward pallet)
    withdraw - Unstake the LP tokens from the reward pool
    claim - Withdraw any accrued rewards from the reward pool

on_initialize hook - distribute reward each N block according to scheduled(created by update_reward_schedule extrinsic). User steel need to call extrinsic claim to move reward from FarmingAccount to user account.

picasson-runtime implements two runtime function for rpc endpoints:

  • compute_farming_reward
  • estimate_farming_reward

conppsable-node exposes this RPC endpoints for picasso runtime.

@RustNinja RustNinja marked this pull request as draft April 26, 2023 20:52
@RustNinja RustNinja marked this pull request as ready for review April 27, 2023 21:15
code/parachain/frame/farming/src/lib.rs Outdated Show resolved Hide resolved
@RustNinja RustNinja requested a review from kkast April 28, 2023 13:17
@josietyleung
Copy link
Contributor

@kollegian can we test this out please? thanks

@kollegian
Copy link
Contributor

kollegian commented May 1, 2023

@josietyleung this is wip. Writing test plan now.

Add logs for update reward schedule and remove comments
@RustNinja
Copy link
Collaborator Author

Can you try running it locally, using

nix run .#devnet-picasso-complete

and check that it works nicely?

yes. i checked.
it works fine.

i use locally:
nix run --extra-experimental-features nix-command --extra-experimental-features flakes .#devnet-picasso

there are associated pallets.
extrinsic for creating the pool and deposit/stake/claim tokens:

3AB11938-E21D-4444-9EF5-02EBA1C69C40

and
chain state
AFF2EC39-22F9-485F-BAE5-280F99EAAD07

working close with @kollegian to test it together

@RustNinja RustNinja requested review from blasrodri and removed request for dzmitry-lahoda May 2, 2023 18:21
blasrodri
blasrodri previously approved these changes May 2, 2023
@kollegian
Copy link
Contributor

@josietyleung @blasrodri @RustNinja tested lp staking sirs. Other than one bug it seems good. #3555
The test plan can be seen here
https://docs.google.com/spreadsheets/d/19-kLAIwggsZW1WaPzDBEPi-DPeIIJCzxfXKluqsEQaE/edit#gid=585780262

blasrodri
blasrodri previously approved these changes May 4, 2023
@RustNinja RustNinja enabled auto-merge May 4, 2023 11:17
@blasrodri
Copy link
Contributor

@RustNinja
Copy link
Collaborator Author

RustNinja commented May 4, 2023

@josietyleung @blasrodri @RustNinja tested lp staking sirs. Other than one bug it seems good. #3555 The test plan can be seen here https://docs.google.com/spreadsheets/d/19-kLAIwggsZW1WaPzDBEPi-DPeIIJCzxfXKluqsEQaE/edit#gid=585780262

We already discussed with @kollegian and I want to leave explanation here:
@kollegian found the issue/bug that related only to amount in event DistributeReward
here is the screen:

image

but actually it is not a bug. this is by design.

DistributeReward event with a high accuracy means how manny assets we distribute each block or each period.

Imagine that we want to distribute BTC(it will help us easily understand the logic if we take BTC for example). or some very expensive assets.
each block we will distribute very tiny amount of BTC that is much less then 1 satoshi. for example 0.1 Satoshi
But after 10 blocks distributed 1 satoshi.
DistributeReward event emit each block(on N period) and will show with more accuracy how many satoshi we are distributing
so in this case DistributeReward amount is 10 but actually it means 0.1 satoshi.
We are not able to reduce the accuracy for this event because then user will not see any distribution/changes in event frequently at all but there is distribution.
So we need high accuracy only in this DistributeReward to show changes for frontend in case when distribution is much smaller than 1 unit of Asset.

code/parachain/frame/farming/src/mock.rs Outdated Show resolved Hide resolved
code/parachain/frame/reward/src/mock.rs Outdated Show resolved Hide resolved
code/parachain/runtime/picasso/src/lib.rs Outdated Show resolved Hide resolved
@RustNinja RustNinja added this pull request to the merge queue May 4, 2023
@RustNinja RustNinja requested a review from blasrodri May 4, 2023 12:43
@RustNinja
Copy link
Collaborator Author

This is failing here https://github.com/ComposableFi/composable/actions/runs/4881822141/jobs/8711166782#step:6:9790

@blasrodri
thanks.
it is not related to this pr.
but I created another PR to fix warning/failing of CI benchmarking step for all pallets in composable repo.

#3557

Please re-approve this PR because i push changes and remove commented code.

@RustNinja RustNinja removed this pull request from the merge queue due to a manual request May 4, 2023
@RustNinja RustNinja added this pull request to the merge queue May 4, 2023
Merged via the queue into ComposableFi:main with commit 3303bd1 May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants