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

fix: fix some logics and sync spec to latest source code #18

Merged
merged 28 commits into from
Jul 31, 2023

Conversation

zsystm
Copy link

@zsystm zsystm commented Jul 24, 2023

Description

Fixed

I found some logical errors during syncing spec to latest source codes.

DoCancelProvideInsurance

  • when cancel provide insurance, we should return all of its spendable coins from both derived address and fee pool address.

DoWithdrawInsurance

  • we should accept withdrawal request for only paired or unpaired insurances, not unpairing insurance. It because unpairing insurance is already in state transition situation at epoch, so it's weird to queue the request for that insurance.

GetAllRePairableChunksAndOutInsurances

  • if paired insurance of paired chunk have invalid insurance, then unpairing it and add it to out insurances to hande just like other unpairing chunks.
  • there was a logical error because chunk's status is changed to unpairing but, current paired chunk's status is still Paired and chunk have paired insurance id even if it is unpairing chunk.

add missing invariant checks

  • newly added RedelegationInfosInvariant was not included

Updated

calculation of NetAmount

  • consider insurance balance if there are any slashing penalty.

calculation of TotalRemainingRewards

  • dynamic fee and discounted reward mechanism were introduced before. we need to consider this when calc remaining rewards.
    before: del_reward - insurance_commission
    after:
rest = del_reward - insurance_commission
remaining = rest x (1 - dynamic_fee_rate)

Chore

  • refactor variables name in invariants.go
  • use lsm's own event key types, not other module's.
  • add module name to each event

Docs

  • Updated docs related with NetAmount.

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • included the necessary unit and integration tests
  • reviewed "Files changed" and left comments if necessary

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

DoCancelProvideInsurance
when cancel provide insurance, we should return all of its spendable coins from both derived address and fee pool address.

DoWithdrawInsurance
we can accept request only paired or unpaired insurances, not unpairing insurance.
it because unpairing insurance is already in state transition situation at epoch, so its weird to queue the request for that insurance.
fix core logics
before:
* there can be bug because chunk's status is changed to unpairing but, current paired chunk's status is still Paired and chunk have paired insurance id even if it is unpairing chunk.
after:
if paired insurance of paired chunk have invalid insurance, then unpairing it and add it to out insurances to hande just like other unpairing chunks.

add missing invariant checks
* newly added RedelegationInfosInvariant was not included

chore
* refactor variables name in invariants.go
* use lsm's own event key types, not other module's.
* add module name to each event
@zsystm zsystm self-assigned this Jul 24, 2023
@zsystm zsystm requested review from dongsam and poorphd July 24, 2023 06:02
Copy link
Member

@dongsam dongsam left a comment

Choose a reason for hiding this comment

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

The 5.75% (double_sign_friction + down_time_friction) notation on the spec is guaranteed only when param change is limited through the antihandler, so the antihandler content on spec needs to be updated

chore: since pb.go has been modified, re-generation of swagger and statik is needed

x/liquidstaking/spec/02_state.md Outdated Show resolved Hide resolved
* if there were slashing (token value of chunk's del < chunk size), then we consider insurance balance now.

* remove NativeTokenToLiquidStakeToken, just use MintRate. it is more easy to understand.
@zsystm zsystm requested a review from dongsam July 25, 2023 06:00
x/liquidstaking/keeper/net_amount.go Outdated Show resolved Hide resolved
x/liquidstaking/spec/02_state.md Show resolved Hide resolved
* add description about utilization ratio

* definition of NetAmount is changed. we consider insurance coverage now.
  * add missing item to a formula of NetAmount: sum of all unbonding balance of chunks (insurance coverage included)

* MaximumDiscountRate is defined as governance parameter
@zsystm
Copy link
Author

zsystm commented Jul 27, 2023

@dongsam @poorphd
Hey guys. Based on yesterday discussions, I updated the spec in 82516ac.
Could you review this commit?

After updated spec is confirmed, I'll apply it in source codes.

x/liquidstaking/spec/02_state.md Show resolved Hide resolved
@@ -76,4 +77,4 @@ The rewards accumulated on the **reward module account** can be withdrawn by any

The discount rate is calculated as follows: `discount rate = reward module account's balance / (num paired chunks * chunk size)`
Copy link
Member

Choose a reason for hiding this comment

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

we discussed the discount rate need to fix to use NetAmount instead of num-paired chunks, like the utilization ratio

Copy link
Author

Choose a reason for hiding this comment

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

Oh, I'll update it soon. sorry for miss

Copy link
Author

@zsystm zsystm Jul 27, 2023

Choose a reason for hiding this comment

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

Updated! thanks. 2fd453d

Copy link
Author

Choose a reason for hiding this comment

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

@dongsam
Any additional comments for this?

Copy link
Member

Choose a reason for hiding this comment

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

LGTM, now we can proceed with the code update based on the updated spec

Copy link
Member

@dongsam dongsam Jul 27, 2023

Choose a reason for hiding this comment

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

chore: Transition Diagram png files seem to be missing
forum post also should be updated

Copy link
Author

@zsystm zsystm Jul 27, 2023

Choose a reason for hiding this comment

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

@dongsam @poorphd
I think I should add description of security cap for both HardCap and MaximumDiscountRate.
Let me add these contents also.

Copy link
Author

Choose a reason for hiding this comment

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

Added missing diagrams and contents for security cap in d1733cc

Now I'll proceed the code updates.

Copy link

Choose a reason for hiding this comment

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

the update LGTM as well

@zsystm
Copy link
Author

zsystm commented Jul 28, 2023

@dongsam @poorphd

I updated source codes based on updated spec.
b-harvest:990c31c^^^^^...b-harvest:990c31c

Please review file changes from several commits 🙏

@zsystm zsystm requested a review from dongsam July 31, 2023 01:04
x/liquidstaking/keeper/liquidstaking.go Outdated Show resolved Hide resolved
x/liquidstaking/types/params_test.go Outdated Show resolved Hide resolved
@zsystm zsystm requested a review from dongsam July 31, 2023 04:58
x/liquidstaking/keeper/liquidstaking.go Outdated Show resolved Hide resolved
x/liquidstaking/keeper/liquidstaking.go Outdated Show resolved Hide resolved
@dongsam dongsam self-requested a review July 31, 2023 06:07
Copy link
Member

@dongsam dongsam left a comment

Choose a reason for hiding this comment

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

LGTM!

@zsystm zsystm merged commit 60a80bf into liquidstaking-module Jul 31, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

update: events type feat: financial sync docs: full sync spec with latest code
3 participants