Skip to content

Commit

Permalink
unstake lst from validator with highest amount
Browse files Browse the repository at this point in the history
  • Loading branch information
groninge01 committed Jan 21, 2025
1 parent 813a9e2 commit 39d01b2
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ export function useGetAmountDelegatedPerValidator(chain: GqlChain) {
function chooseValidatorsForUnstakeAmount(unstakeAmountShares: bigint) {
const unstakeAmountAssets = (unstakeAmountShares * rate) / 10n ** 18n

const validator = amountDelegatedPerValidator.find(
validator => validator.amountDelegated > unstakeAmountAssets
// choose the validator with the most amount delegated
const validator = amountDelegatedPerValidator.reduce(
(max, current) =>
unstakeAmountAssets < current.amountDelegated &&
current.amountDelegated > max.amountDelegated
? current
: max,
amountDelegatedPerValidator[0]
)

// TODO: we should split the unstake amount across several validators down the line
Expand Down

0 comments on commit 39d01b2

Please sign in to comment.