-
Notifications
You must be signed in to change notification settings - Fork 221
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
Reward Interception at the Cosmos Layer for Lien Payoff #4466
Comments
@dckc for your input please. |
Tag @dckc |
We decided this is how it should be done, so let's do it for MN-1. |
JL: options look like "cron job" or trigger on user action DC: then what do you need from the JS side? JL: burn it or use v-purse? MF: escrow in v-bank? stability pool? RG: does runStake do stability pool stuff? |
Liens support has been removed and is not a near-term goal. Closing now, but can reopen if we want the feature in the future. |
What is the Problem Being Solved?
Issue #4244 gives the problem of needing to use RUN rewards from staking to first pay off any Lien debt. In fact, the whole Lien concept, where liened BLD is not liquidated, is predicated on being able to take control of a slice of the reward stream.
But implementing this reward interception at the JS level is difficult, as it cannot happen atomically with reward distribution. Automation at the JS level can quickly schedule an after-the-fact transfer of the reward out of the account, but there would be a race with the user attempting to do the same thing.
Instead, if we implemented the interception at the Cosmos level, the interception would be atomic with the reward, leaving no room for a race with the user. But there would be a price - the need to mirror the debt state at the Cosmos level.
Description of the Design
Distribution hooks
As part of the clawback vesting work (agoric-labs/cosmos-sdk PR#155), we added a feature for hooks into the distribution module:
There is an existing hook that's used for clawback vesting accounts. It disables the ability to use a separate withdrawal address, then calculates the vested/unvested ratio of the staked tokens (preferring to make as much as possible vested), then adjusts the vesting schedule to have the unvested portion of the reward vest in proportion to the existing remaining vesting amount.
We shouldn't make the existing hook lien-aware, since it's part of
cosmos-sdk
. Fortunately, you can register multiple hooks with the distribution module, and I believe a new lien-aware hook would compose with the vesting hook in either order.Account state model and reward calculations
Previous work on liens identified the 3 dimensions of activity of an account: staking, lockup, and liens. (See spec.
Since we need to prohibit liens on unvested funds (#4332), vesting fits into the lien dimension, where there will now be three states:
After slashing, we have different behavior depending on what happens next:
For reward distribution, we have a different calculation:
The new distribution hook for liens will make this calculation and then transfer out the liened share of the reward, up at a maximum of the remaining debt. Since the liened amount is invisible to the distribution hook for vesting, they should be able to run in either order.
Cosmos-side state and bridge protocol
The above calculation needs to know the remaining debt associated with any lien, and reduce it when it confiscates the rewards. It must track the funds it has placed into its own module account and on behalf of which liened account. Then it must make these confiscated rewards available to
So we need the following synchronous bridge messages from JS to golang:
and the following async messages from golang to JS:
Additionally, we must allow JS to transfer funds out of the Cosmos-level module account, which is best done by extending or duplicating the logic in
x/vbank
to make it behave like a purse, or add analogous bridge messages.Relation to standalone lien module
Fortunately, the above mechanisms are already largely implemented in the paused standalone line of credit module (#3991).
I'd estimate about 13 story points to complete the work for the purposes here, depending on the details of the JS-Golang API.
Security Considerations
Test Plan
The text was updated successfully, but these errors were encountered: