Skip to content

Commit

Permalink
[sdk&cli] bump version 1.3.6, show bond to work with withdraw request…
Browse files Browse the repository at this point in the history
… address+show stake account on debug
  • Loading branch information
ochaloup committed May 13, 2024
1 parent 32e7d82 commit 4cebdfc
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 54 deletions.
8 changes: 4 additions & 4 deletions packages/validator-bonds-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ added 165 packages in 35s
# to verify installed version
validator-bonds --version
1.3.5
1.3.6
```

To get info on available commands
Expand Down Expand Up @@ -401,7 +401,7 @@ To check where NPM packages are and will be installed:
# Get npm global installation folder
npm list -g
> /usr/lib
> +-- @marinade.finance/validator-bonds-cli@1.3.5
> +-- @marinade.finance/validator-bonds-cli@1.3.6
> ...
# In this case, the `bin` folder is located at /usr/bin
```
Expand All @@ -427,7 +427,7 @@ With this configuration, NPM packages will be installed under the `prefix` direc
npm i -g @marinade.finance/validator-bonds-cli@latest
npm list -g
> ~/.local/share/npm/lib
> `-- @marinade.finance/validator-bonds-cli@1.3.5
> `-- @marinade.finance/validator-bonds-cli@1.3.6
```
To execute the installed packages from any location,
Expand Down Expand Up @@ -577,7 +577,7 @@ Commands:
# Get npm global installation folder
npm list -g
> ~/.local/share/npm/lib
> `-- @marinade.finance/validator-bonds-cli@1.3.5
> `-- @marinade.finance/validator-bonds-cli@1.3.6
# In this case, the 'bin' folder is located at ~/.local/share/npm/bin
# Get validator-bonds binary folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
executeInitBondInstruction,
executeInitConfigInstruction,
executeInitWithdrawRequestInstruction,
} from '@marinade.finance/validator-bonds-sdk/__tests__/utils/testTransactions'
import { initTest } from '@marinade.finance/validator-bonds-sdk/__tests__/test-validator/testValidator'
} from '../../../validator-bonds-sdk/__tests__/utils/testTransactions'
import { initTest } from '../../../validator-bonds-sdk/__tests__/test-validator/testValidator'
import {
createBondsFundedStakeAccount,
createVoteAccount,
} from '@marinade.finance/validator-bonds-sdk/__tests__/utils/staking'
} from '../../../validator-bonds-sdk/__tests__/utils/staking'
import { rand } from '@marinade.finance/ts-common'
import { AnchorExtendedProvider } from '@marinade.finance/anchor-common'
import BN from 'bn.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ describe('Show command using CLI', () => {
code: 1,
signal: '',
// stderr: '',
stdout: /Account of type bond or voteAccount was not found/,
stdout:
/Account of type bond or voteAccount or withdrawRequest was not found/,
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/validator-bonds-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marinade.finance/validator-bonds-cli",
"version": "1.3.5",
"version": "1.3.6",
"description": "CLI of the validator bonds contract",
"repository": {
"type": "git",
Expand All @@ -24,7 +24,7 @@
],
"main": "src/index",
"dependencies": {
"@marinade.finance/validator-bonds-sdk": "^1.3.5",
"@marinade.finance/validator-bonds-sdk": "^1.3.6",
"@coral-xyz/anchor": "^0.29.0",
"@solana/web3.js": "^1.91.1",
"@marinade.finance/ledger-utils": "^3.0.1",
Expand Down
17 changes: 16 additions & 1 deletion packages/validator-bonds-cli/src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function installShowBond(program: Command) {
.description('Showing data of bond account(s)')
.argument(
'[address]',
'Address of the bond account or vote account. ' +
'Address of the bond account or vote account or withdraw request. ' +
'It will show bond account data (when the argument is provided other filter options are ignored)',
parsePubkey
)
Expand Down Expand Up @@ -322,6 +322,12 @@ async function showBond({
numberSettlementStakeAccounts:
bondFunding[0].numberSettlementStakeAccounts,
withdrawRequest: bondFunding[0].withdrawRequest,
bondFundedStakeAccounts: cliContext.logger.isLevelEnabled('debug')
? bondFunding[0].bondFundedStakeAccounts
: undefined,
settlementFundedStakeAccounts: cliContext.logger.isLevelEnabled('debug')
? bondFunding[0].settlementFundedStakeAccounts
: undefined,
}
} else {
// CLI did not provide an address, we will search for accounts based on filter parameters
Expand Down Expand Up @@ -363,6 +369,12 @@ async function showBond({
(data[i].numberSettlementStakeAccounts =
bondFunding?.numberSettlementStakeAccounts),
(data[i].withdrawRequest = bondFunding?.withdrawRequest)
if (cliContext.logger.isLevelEnabled('debug')) {
data[i].bondFundedStakeAccounts =
bondFunding?.bondFundedStakeAccounts
data[i].settlementFundedStakeAccounts =
bondFunding?.settlementFundedStakeAccounts
}
}
}
} catch (err) {
Expand Down Expand Up @@ -466,6 +478,9 @@ function reformatBond(key: string, value: any): ReformatAction {
records: [{ key, value: '<NOT EXISTING>' }],
}
}
if (value === undefined) {
return { type: 'Remove' }
}
return { type: 'UsePassThrough' }
}

Expand Down
51 changes: 45 additions & 6 deletions packages/validator-bonds-cli/src/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getBondFromAddress({
accountInfo = await checkAccountExistence(
program.provider.connection,
address,
'Account of type bond or voteAccount was not found'
'Account of type bond or voteAccount or withdrawRequest was not found'
)
} else {
accountInfo = address.account
Expand All @@ -49,6 +49,31 @@ export async function getBondFromAddress({
logger,
})

if (voteAccountAddress === null) {
// it could be withdraw request address or bond, let's try to decode it as withdraw request
let withdrawRequestData: WithdrawRequest | undefined = undefined
const withdrawRequestAddress = address
try {
withdrawRequestData = decodeWithdrawRequest({ program, accountInfo })
address = withdrawRequestData.bond
} catch (e) {
logger.debug(`Failed to decode account ${address} as withdraw request`, e)
}
// we found the provided address as the withdraw request, let's check the bond account
if (withdrawRequestData !== undefined) {
const bondAccountInfo =
await program.provider.connection.getAccountInfo(address)
if (bondAccountInfo === null) {
throw new CliCommandError({
valueName: '[withdraw request address]:[bond account address]',
value: withdrawRequestAddress.toBase58() + ':' + address.toBase58(),
msg: 'Bond account address taken from provided withdraw request was not found',
})
}
accountInfo = bondAccountInfo
}
}

// If the address is a vote account, derive the bond account address from it
if (voteAccountAddress !== null) {
if (config === undefined) {
Expand Down Expand Up @@ -120,6 +145,23 @@ async function isVoteAccount({
return voteAccountAddress
}

/**
* Check if the address and data is a withdraw request.
* If not throwing exception, returns the withdraw request data.
*/
function decodeWithdrawRequest({
program,
accountInfo,
}: {
program: ValidatorBondsProgram
accountInfo: AccountInfo<Buffer>
}): WithdrawRequest {
return program.coder.accounts.decode<WithdrawRequest>(
program.account.withdrawRequest.idlAccount.name,
accountInfo.data
)
}

/**
* Expecting the provided address is a withdraw request or bond or vote account,
* returns the account info of the (derived) bond account.
Expand All @@ -135,17 +177,14 @@ export async function getWithdrawRequestFromAddress({
logger: Logger
config: PublicKey | undefined
}): Promise<ProgramAccountInfo<WithdrawRequest>> {
let accountInfo = await checkAccountExistence(
let accountInfo: AccountInfo<Buffer> = await checkAccountExistence(
program.provider.connection,
address,
'Account of type withdrawRequest or bond or voteAccount was not found'
)

try {
const withdrawRequestData = program.coder.accounts.decode<WithdrawRequest>(
program.account.withdrawRequest.idlAccount.name,
accountInfo.data
)
const withdrawRequestData = decodeWithdrawRequest({ program, accountInfo })
return programAccountInfo(address, accountInfo, withdrawRequestData)
} catch (e) {
logger.debug(`Failed to decode account ${address} as withdraw request`, e)
Expand Down
2 changes: 1 addition & 1 deletion packages/validator-bonds-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const logger: Logger = configureLogger()
const program = new Command()

program
.version('1.3.5')
.version('1.3.6')
.allowExcessArguments(false)
.configureHelp({ showGlobalOptions: true })
.option(
Expand Down
2 changes: 1 addition & 1 deletion packages/validator-bonds-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marinade.finance/validator-bonds-sdk",
"version": "1.3.5",
"version": "1.3.6",
"description": "SDK of the validator bonds contract",
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions packages/validator-bonds-sdk/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ export type BondDataWithFunding = {
numberActiveStakeAccounts: number
numberSettlementStakeAccounts: number
withdrawRequest: ProgramAccount<WithdrawRequest> | undefined
bondFundedStakeAccounts: ProgramAccountInfo<StakeAccountParsed>[]
settlementFundedStakeAccounts: ProgramAccountInfo<StakeAccountParsed>[]
}

function calculateFundedAmount(
Expand Down Expand Up @@ -723,6 +725,8 @@ export async function getBondsFunding({
numberActiveStakeAccounts: bondFunded.length,
numberSettlementStakeAccounts: settlementFunded.length,
withdrawRequest,
bondFundedStakeAccounts: bondFunded,
settlementFundedStakeAccounts: settlementFunded,
}
}
)
Expand Down
36 changes: 3 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions settlement-pipelines/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marinade.finance/settlement-pipelines",
"version": "1.3.5",
"version": "1.3.6",
"description": "Tests for settlement pipelines CLI",
"repository": {
"type": "git",
Expand All @@ -17,7 +17,7 @@
"author": "Marinade.Finance",
"license": "ISC",
"devDependencies": {
"@marinade.finance/validator-bonds-sdk": "workspace: ^1.3.5",
"@marinade.finance/validator-bonds-sdk": "workspace: ^1.3.6",
"@coral-xyz/anchor": "^0.29.0",
"@solana/web3.js": "^1.91.1",
"@marinade.finance/ledger-utils": "^3.0.1",
Expand Down

0 comments on commit 4cebdfc

Please sign in to comment.