Skip to content

Commit

Permalink
[cli] make withdraw claim to work with stake accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Oct 8, 2024
1 parent 00862e3 commit f2725dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
27 changes: 24 additions & 3 deletions packages/validator-bonds-cli/src/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,31 @@ export async function getWithdrawRequestFromAddress({
}

let bondAccountAddress = address
const voteAccountAddress = await isVoteAccount({
let voteAccountAddress = await isVoteAccount({
address,
accountInfo,
logger,
})

if (
voteAccountAddress === null &&
accountInfo.owner.equals(StakeProgram.programId)
) {
try {
const stakeAccountData = deserializeStakeState(accountInfo.data)
voteAccountAddress =
stakeAccountData.Stake?.stake.delegation.voterPubkey ?? null
if (voteAccountAddress !== null) {
logger.info(
`Address ${address.toBase58()} is a STAKE ACCOUNT delegated to vote account ` +
`${voteAccountAddress.toBase58()}. Using the vote account to get the withdraw request data.`
)
}
} catch (e) {
logger.debug(`Failed to decode account ${address} as stake account`, e)
}
}

if (voteAccountAddress !== null) {
if (config === undefined) {
config = MARINADE_CONFIG_ADDRESS
Expand All @@ -257,7 +276,7 @@ export async function getWithdrawRequestFromAddress({
accountInfo = await checkAccountExistence(
program.provider.connection,
address,
'type of withdrawRequest'
`WithdrawRequest generated from bond address ${bondAccountAddress.toBase58()} does not exist`
)

// final decoding of withdraw request account from account info
Expand Down Expand Up @@ -324,7 +343,9 @@ async function checkAccountExistence(
throw new CliCommandError({
valueName: '[address]',
value: address.toBase58(),
msg: `Address does not exist at ${connection.rpcEndpoint}: ` + errorMsg,
msg:
`Address does not exist on-chain (RPC endpoint: ${connection.rpcEndpoint}): ` +
errorMsg,
})
}
return accountInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ export async function orchestrateWithdrawDeposit({

if (stakeAccountsFunded.length === 0 && amountToWithdraw > new BN(0)) {
throw new Error(
'orchestrateWithdrawDeposit: cannot find any stake accounts to withdraw from'
'Claim withdraw request failed: No stake accounts found for bond account ' +
`(${bondAccount.toBase58()}) to process the withdrawal.`
)
}

Expand Down

0 comments on commit f2725dd

Please sign in to comment.