Skip to content

Commit

Permalink
CLI: fix balance command to show reasonable error on MSOL acocunt doe…
Browse files Browse the repository at this point in the history
…s not exist
  • Loading branch information
ochaloup committed Aug 9, 2023
1 parent c239c43 commit 8e15aa2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"Lamports",
"ledgerhq",
"localnet",
"mnde",
"MR2LqxoSbw831bNy68utpu5n4YqBH3AzDmddkgk9LQv",
"Msol",
"MsolAmount",
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-utils/src/equalityTesters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import BN from 'bn.js'

// Use to global configuration of Jest
/*
* / * * @type {import('ts-jest').JestConfigWithTsJest} * /
* module.exports = {
* setupFilesAfterEnv: ['<rootDir>/setup/equalityTesters.ts'],
* }
*/
* / * * @type {import('ts-jest').JestConfigWithTsJest} * /
* module.exports = {
* setupFilesAfterEnv: ['<rootDir>/setup/equalityTesters.ts'],
* }
*/

/**
* Equality testers for jest to compare BN and PublicKey.
Expand Down
4 changes: 3 additions & 1 deletion packages/marinade-ts-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"solana",
"marinade.finance",
"blockchain",
"staking"
"staking",
"msol",
"mnde"
],
"dependencies": {
"@coral-xyz/anchor": "0.28",
Expand Down
46 changes: 30 additions & 16 deletions packages/marinade-ts-cli/src/commands/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function installShowBalance(program: Command) {
.command('balance')
.description('Show account balance')
.argument(
'<account-pubkey>',
'Account to show balance for (default: keypair wallet pubkey)',
'[account-pubkey]',
'Account to show balance for (default: wallet pubkey)',
parsePubkey
)
.action(async (accountPubkey: Promise<PublicKey>) => {
Expand Down Expand Up @@ -53,19 +53,33 @@ export async function showBalance({
mSolMintAddress,
accountPubkey
)
const {
value: { amount: amountMSOL },
} = await connection.getTokenAccountBalance(userMSolATA)
const mSolATABalance = new BN(amountMSOL)
console.log(`mSOL Balance: ${lamportsToSol(mSolATABalance)}`)
try {
const {
value: { amount: amountMSOL },
} = await connection.getTokenAccountBalance(userMSolATA)
const mSolATABalance = new BN(amountMSOL)
console.log(`mSOL Balance: ${lamportsToSol(mSolATABalance)}`)
} catch (e) {
logger.error(
`MSOL ATA of the account ${accountPubkey.toBase58()} does not exist`,
e
)
}

const userLpATA = await getAssociatedTokenAccountAddress(
lpMint.address,
accountPubkey
)
const {
value: { amount: amountLP },
} = await connection.getTokenAccountBalance(userLpATA)
const userLpATABalance = new BN(amountLP)
console.log(`mSOL-SOL-LP Balance: ${lamportsToSol(userLpATABalance)}`)
try {
const userLpATA = await getAssociatedTokenAccountAddress(
lpMint.address,
accountPubkey
)
const {
value: { amount: amountLP },
} = await connection.getTokenAccountBalance(userLpATA)
const userLpATABalance = new BN(amountLP)
console.log(`mSOL-SOL-LP Balance: ${lamportsToSol(userLpATABalance)}`)
} catch (e) {
logger.error(
`LP ATA of the account ${accountPubkey.toBase58()} does not exist`,
e
)
}
}

0 comments on commit 8e15aa2

Please sign in to comment.