-
Notifications
You must be signed in to change notification settings - Fork 21
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
withdraw withdrawn rewards #18
Conversation
44c196a
to
ad6585a
Compare
@@ -360,6 +365,33 @@ fn execute_initiate_withdraw_reward( | |||
Ok(response) | |||
} | |||
|
|||
// rewards may be automatically withdrawn to contract's bank balance during redelegation/undelegation/delegating | |||
// more to the same validator. The amount of such withdrawn rewards, assuming no external deposit to the contract | |||
// is present, can be calculated as: bank balance - (total - withdrawn principal - staked - unbonding). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should update this comment since it is no longer including "unbonding" right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep it there as a reminder of what the correct calculation should be. There is a note on the line below stating that we are omitting unbonding for now and why
let bank_balance = deps.querier.query_balance(env.contract.address.clone(), DENOM.load(deps.storage)?)?.amount.u128(); | ||
let total_locked: u128 = VESTING_AMOUNTS.load(deps.storage)?.iter().sum(); | ||
let withdrawn_principal = WITHDRAWN_LOCKED.load(deps.storage)? + WITHDRAWN_UNLOCKED.load(deps.storage)?; | ||
let staked: u128 = deps.querier.query_all_delegations(env.contract.address)?.iter().map(|del: &Delegation| -> u128 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this query intentionally exclude rewards? as in, it will only return the principal staked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delegations are always principals as we don't reinvest rewards into staking
Describe your changes and provide context
rewards may be automatically withdrawn to contract's bank balance during redelegation/undelegation/delegating more to the same validator. The amount of such withdrawn rewards, assuming no external deposit to the contract is present, can be calculated as: bank balance - (total - withdrawn principal - staked - unbonding).
Note that because CW currently doesn't support querying unbonding amount, we will ignore unbonding amount in the calculationg for now. This would make under-withdraw possible but still impossible to over-withdraw (which is bad).
To avoid under-withdraw, the operator can wait till there is no unbonding amount for the contract when executing
rewards withdrawal.
Testing performed to validate your change
unit test & local sei test