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

[cli] make withdraw claim to work with stake accounts #123

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -231,12 +231,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 @@ -256,7 +275,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 @@ -315,7 +334,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