Skip to content

Commit

Permalink
Merge pull request #269 from EpicsDAO/update
Browse files Browse the repository at this point in the history
Update solv.config.json to solv4.config.json
  • Loading branch information
POPPIN-FUMI authored Sep 4, 2024
2 parents 0f2735d + d3fb23f commit b6126d9
Show file tree
Hide file tree
Showing 86 changed files with 744 additions and 1,727 deletions.
11 changes: 11 additions & 0 deletions .changeset/angry-colts-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@epics-dao/solv': patch
---

Update solv.config.json to solv4.config.json

solv.config.json will be deprecated in the future, please update your config file to solv4.config.json with the following command:

```bash
solv update --config
```
6 changes: 2 additions & 4 deletions packages/solv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"start": "node dist/index.js"
},
"dependencies": {
"@jup-ag/api": "^6.0.27",
"@jup-ag/api": "6.0.27",
"@metaplex-foundation/mpl-token-metadata": "3.2.1",
"@metaplex-foundation/umi": "0.9.2",
"@metaplex-foundation/umi-bundle-defaults": "0.9.2",
Expand All @@ -48,21 +48,19 @@
"commander": "12.1.0",
"dotenv": "16.4.5",
"inquirer": "10.2.0",
"node-cron": "3.0.3",
"node-fetch": "3.3.2",
"prompt": "1.3.0"
},
"devDependencies": {
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.7",
"@skeet-framework/discord-utils": "0.4.2",
"@swc/core": "^1.7.21",
"@swc/core": "1.7.21",
"@types/bn.js": "5.1.5",
"@types/cli-progress": "3.11.6",
"@types/cli-spinner": "0.2.3",
"@types/inquirer": "9.0.7",
"@types/node": "22.5.1",
"@types/node-cron": "3.0.11",
"@types/node-fetch": "2.6.11",
"@types/prompt": "1.1.8",
"@typescript-eslint/eslint-plugin": "8.3.0",
Expand Down
81 changes: 75 additions & 6 deletions packages/solv/src/cli/balance/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { program } from '@/index'
import { ConfigParams } from '@/lib/readOrCreateDefaultConfig'
import { showKeypairsInfo } from '../server/getValidatorInfo/showKeypairsInfo'
import { splBalance } from '@/lib/solana/splBalance'
import { homedir } from 'os'
import { DefaultConfigType } from '@/config/types'
import { getAllKeyPaths } from '@/config/config'
import { getSolBalance } from '@/lib/getSolBalance'
import { getSolanaAddress } from '@/lib/getSolanaAddress'
import { Network, NodeType } from '@/config/enums'
import chalk from 'chalk'
import { spawnSync } from 'child_process'
import { IDENTITY_KEY_PATH } from '@/config/constants'

export type BalanceOptions = {
spl: boolean
}

export const balanceCommands = (solvConfig: ConfigParams) => {
const { config } = solvConfig
export const balanceCommands = (config: DefaultConfigType) => {
program
.command('balance')
.alias('bal')
Expand All @@ -21,8 +26,72 @@ export const balanceCommands = (solvConfig: ConfigParams) => {
const defaultKey = 'mainnet-authority-keypair.json'
const keyPath = `${homedir()}/${defaultKey}`
await splBalance(keyPath)
return
process.exit(0)
}
await showKeypairsInfo(config.SOLV_TYPE)
await showKeypairsInfo(config)
process.exit(0)
})
}

const showKeypairsInfo = async (config: DefaultConfigType) => {
const keyInfo = getKeypairsInfo(config)
const output = `Validator Key: ${keyInfo.validatorKey}
Address: ${keyInfo.validatorKeyAddress}
Balance: ${keyInfo.validatorKeyBalance}
Vote Key: ${keyInfo.voteKey}
Address: ${keyInfo.voteKeyAddress}
Balance: ${keyInfo.voteKeyBalance}
Authority Key: ${keyInfo.authorityKey}
Address: ${keyInfo.authorityKeyAddress}
Balance: ${keyInfo.authorityKeyBalance}
Active Identity:`
console.log(chalk.white(output))
spawnSync(`solana-keygen pubkey ${IDENTITY_KEY_PATH}`, {
stdio: 'inherit',
shell: true,
})
}

export const getKeypairsInfo = (config: DefaultConfigType) => {
const keypairs = getAllKeyPaths()
const isTestnet = config.NETWORK === Network.TESTNET
const isRPC = config.NODE_TYPE === NodeType.RPC

if (isRPC) {
return {
validatorKey: keypairs.testnetValidatorKey,
validatorKeyAddress: getSolanaAddress(keypairs.testnetValidatorKey),
validatorKeyBalance: getSolBalance(keypairs.testnetValidatorKey),
}
}

if (isTestnet) {
return {
validatorKey: keypairs.testnetValidatorKey,
validatorKeyAddress: getSolanaAddress(keypairs.testnetValidatorKey),
validatorKeyBalance: getSolBalance(keypairs.testnetValidatorKey),
voteKey: keypairs.testnetValidatorVoteKey,
voteKeyAddress: getSolanaAddress(keypairs.testnetValidatorVoteKey),
voteKeyBalance: getSolBalance(keypairs.testnetValidatorVoteKey),
authorityKey: keypairs.testnetValidatorAuthorityKey,
authorityKeyAddress: getSolanaAddress(
keypairs.testnetValidatorAuthorityKey,
),
authorityKeyBalance: getSolBalance(keypairs.testnetValidatorAuthorityKey),
}
}

return {
validatorKey: keypairs.mainnetValidatorKey,
validatorKeyAddress: getSolanaAddress(keypairs.mainnetValidatorKey),
validatorKeyBalance: getSolBalance(keypairs.mainnetValidatorKey),
voteKey: keypairs.mainnetValidatorVoteKey,
voteKeyAddress: getSolanaAddress(keypairs.mainnetValidatorVoteKey),
voteKeyBalance: getSolBalance(keypairs.mainnetValidatorVoteKey),
authorityKey: keypairs.mainnetValidatorAuthorityKey,
authorityKeyAddress: getSolanaAddress(
keypairs.mainnetValidatorAuthorityKey,
),
authorityKeyBalance: getSolBalance(keypairs.mainnetValidatorAuthorityKey),
}
}
6 changes: 2 additions & 4 deletions packages/solv/src/cli/check/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { program } from '@/index'
import { ConfigParams } from '@/lib/readOrCreateDefaultConfig'
import { df } from './df/df'
import { displayTable } from '@/lib/logger/table'
import getPreferredDisks, { GetPreferredDisksResult } from './mt/getLargestDisk'

export const checkCommands = (solvConfig: ConfigParams) => {
const { locale } = solvConfig
const check = program.command('check').description(locale.cmds.check)
export const checkCommands = () => {
const check = program.command('check').description('Check System Status')

check
.command('df')
Expand Down
3 changes: 1 addition & 2 deletions packages/solv/src/cli/check/mt/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { program } from '@/index'
import { spawnSync } from 'child_process'
import getPreferredDisk from './getLargestDisk'
import { ConfigParams } from '@/lib/readOrCreateDefaultConfig'

export const mountCommands = (solvConfig: ConfigParams) => {
export const mountCommands = () => {
program
.command('mtr')
.description('Mount Reload Command')
Expand Down
117 changes: 3 additions & 114 deletions packages/solv/src/cli/cron/index.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,15 @@
import { program } from '@/index'
import cron from 'node-cron'
import { getEpoch } from './getEpoch'
import { Logger } from '@/lib/logger'
import { spawnSync } from 'child_process'
import { stopSolana } from '../stop/stopSolana'
import { sendDiscord } from '@skeet-framework/utils'
import { spawnSync } from 'node:child_process'
import chalk from 'chalk'
import dotenv from 'dotenv'
import { ConfigParams } from '@/lib/readOrCreateDefaultConfig'
import hasEpochTimer from './hasEpochTimer'

dotenv.config()

type CronOptions = {
cron: string
epoch: string
}

export const cronCommands = (solvConfig: ConfigParams) => {
const { locale } = solvConfig
const crond = program
.command('cron')
.description(locale.cmds.cron)
.argument('<cmd>', locale.cmds.cron)

crond
.command('watchHalt')
.description(
'Solv Discord Notification Command. Please set `.env` file with `DISCORD_WEBHOOK_URL=<wehbookurl>`',
)
.option('-c, --cron <value>', 'Cron Job', '*/10 * * * *')
.option('-e, --epoch <epoch>', 'Epoch', '579')
.action(async (options: CronOptions) => {
const DISCORD_WEBHOOK_URL = solvConfig.config.DISCORD_WEBHOOK_URL
const triggerEpoch = Number(options.epoch)
Logger.normal(`🕰️ Running Cron Job: ${options.cron}`)
cron.schedule(options.cron, async () => {
const epoch = getEpoch()
if (Number(epoch) === triggerEpoch) {
await sendDiscord(
`Current Epoch: ${epoch} - Stopping Solana Validator!`,
{
webhookUrl: DISCORD_WEBHOOK_URL,
},
)
stopSolana()
await sendDiscord(
`Current Epoch: ${epoch} - Stopped Solana Validator!`,
{
webhookUrl: DISCORD_WEBHOOK_URL,
},
)
process.exit(0)
}
console.log({ epoch })
})
})

crond
.command('halt')
.description('Solv Node Halt Discord Notification Command')
.action(async (options: any) => {
const cmd = `npx pm2 start solv --name solvHalt -- cron watchHalt`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
})
export const cronCommands = () => {
const crond = program.command('cron').description(`Cron Job Commands`)

crond
.command('epoch')
Expand All @@ -79,61 +25,4 @@ export const cronCommands = (solvConfig: ConfigParams) => {
spawnSync(cronJob, { shell: true, stdio: 'inherit' })
console.log(chalk.green('✅ Epoch Timer Cron Job Set'))
})

crond
.command('monitor')
.alias('m')
.description('Monitor Solana Validator by pm2')
.action(() => {
const cmd = `npx pm2 monit`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
})

crond
.command('status')
.alias('s')
.description('Show pm2 status')
.action(() => {
const cmd = `npx pm2 status`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
})

crond
.command('log')
.alias('l')
.option('-i, --id <id>', 'pm2 id', '')
.description('Show pm2 log')
.action((options: { id: string }) => {
let cmd = `npx pm2 log`
if (options.id !== '') {
cmd = `npx pm2 log ${options.id}`
}
spawnSync(cmd, { shell: true, stdio: 'inherit' })
})

crond
.command('delete')
.alias('d')
.option('-i, --id <id>', 'pm2 id', '')
.description('Delete pm2 task')
.action((options: { id: string }) => {
if (options.id === '') {
console.log(chalk.yellow('⚠️ Please set pm2 id'))
}
const cmd = `npx pm2 delete ${options.id}`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
})

crond
.command('restart')
.alias('r')
.option('-i, --id <id>', 'pm2 id', '')
.description('Restart pm2 task')
.action((options: { id: string }) => {
if (options.id === '') {
console.log(chalk.yellow('⚠️ Please set pm2 id'))
}
const cmd = `npx pm2 restart ${options.id}`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
})
}
11 changes: 6 additions & 5 deletions packages/solv/src/cli/epochTimer/alertMessage.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { getAllKeyPaths, NETWORK_TYPES } from '@/config/config'
import { getAllKeyPaths } from '@/config/config'
import { Network } from '@/config/enums'
import { DefaultConfigType } from '@/config/types'
import { EpochInfoCLIType } from '@/lib/getEpochInfoByRust'
import { getSolanaAddress } from '@/lib/getSolanaAddress'
import { ConfigParams } from '@/lib/readOrCreateDefaultConfig'
import { sendDiscord } from '@/lib/sendDiscord'

const alertMessage = async (
currentEpoch: EpochInfoCLIType,
lessThan: string,
solvConfig: ConfigParams,
config: DefaultConfigType,
) => {
const isTestnet = solvConfig.config.SOLANA_NETWORK === NETWORK_TYPES.TESTNET
const isTestnet = config.NETWORK === Network.TESTNET
const { mainnetValidatorKey, testnetValidatorKey } = getAllKeyPaths()
const address = isTestnet
? getSolanaAddress(testnetValidatorKey)
: getSolanaAddress(mainnetValidatorKey)
const content = `===⏳ ${currentEpoch.epoch} ⏳===
Validator: ${address}
Network: ${solvConfig.config.SOLANA_NETWORK}
Network: ${config.NETWORK}
CurrentEpoch: ${currentEpoch.epoch}
Next epoch is coming in less than ${lessThan}!
Epoch Completed: ${currentEpoch.epochCompletedPercent}%
Expand Down
15 changes: 6 additions & 9 deletions packages/solv/src/cli/epochTimer/checkBalance.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import getBalance, { KeyType } from '@/lib/solana/getBalance'
import {
MINIMUM_VALIDATOR_BALANCE,
NETWORK_TYPES,
getAllKeyPaths,
} from '@/config/config'
import { MINIMUM_VALIDATOR_BALANCE, getAllKeyPaths } from '@/config/config'
import { getSolanaAddress } from '@/lib/getSolanaAddress'
import { sendDiscord } from '@/lib/sendDiscord'
import { ConfigParams } from '@/lib/readOrCreateDefaultConfig'
import chalk from 'chalk'
import { SOLANA_TESTNET_RPC_URL } from '@/config/constants'
import { DefaultConfigType } from '@/config/types'
import { Network } from '@/config/enums'

const checkBalance = async (solvConfig: ConfigParams) => {
let rpcUrl = solvConfig.config.RPC_URL
const isTestnet = solvConfig.config.SOLANA_NETWORK === NETWORK_TYPES.TESTNET
const checkBalance = async (config: DefaultConfigType) => {
let rpcUrl = config.RPC_URL
const isTestnet = config.NETWORK === Network.TESTNET
if (isTestnet) {
rpcUrl = SOLANA_TESTNET_RPC_URL
}
Expand Down
Loading

0 comments on commit b6126d9

Please sign in to comment.