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

withdraw withdrawn rewards #18

Merged
merged 2 commits into from
Feb 28, 2024
Merged

withdraw withdrawn rewards #18

merged 2 commits into from
Feb 28, 2024

Conversation

codchen
Copy link
Collaborator

@codchen codchen commented Feb 27, 2024

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

@codchen codchen force-pushed the withdraw-withdrawn-rewards branch from 44c196a to ad6585a Compare February 27, 2024 06:44
@@ -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).
Copy link
Contributor

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?

Copy link
Collaborator Author

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 {
Copy link
Contributor

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?

Copy link
Collaborator Author

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

@codchen codchen merged commit 286611c into main Feb 28, 2024
1 check passed
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.

2 participants