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

[contract] changing bond authority from vote account withdrawer to validator identity #10

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion .github/workflows/typescript-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
lint-and-test:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 50
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand All @@ -28,6 +28,19 @@ jobs:
with:
components: rustfmt, clippy

- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- run: pnpm install
- run: pnpm lint
- run: pnpm test:cargo
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "4.9.5",
"@marinade.finance/jest-utils": "^2.0.20"
"@marinade.finance/jest-utils": "^2.0.21"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
5 changes: 3 additions & 2 deletions packages/validator-bonds-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ The bond account is bound to a validator vote account.
```sh
# bond account at mainnet
validator-bonds -um init-bond -k <fee-payer-keypair> \
--vote-account <vote-account-pubkey> --vote-account-withdrawer <vote-account-withdrawer-keypair> \
--bond-authority <authority-on-bond-account-pubkey> --rent-payer <rent-payer-account-keypair>
--vote-account <vote-account-pubkey> --validator-identity <validator-identity-keypair> \
--bond-authority <authority-on-bond-account-pubkey> \
--rent-payer <rent-payer-account-keypair>

# to configure bond account properties
validator-bonds -um configure-bond --help
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,30 @@ import {
} from '@marinade.finance/validator-bonds-sdk/__tests__/utils/testTransactions'
import {
AnchorExtendedProvider,
getValidatorInfo,
initTest,
} from '@marinade.finance/validator-bonds-sdk/__tests__/test-validator/testValidator'
import { createVoteAccount } from '@marinade.finance/validator-bonds-sdk/__tests__/utils/staking'

describe('Configure bond account using CLI', () => {
let provider: AnchorExtendedProvider
let program: ValidatorBondsProgram
let voteWithdrawerPath: string
let voteWithdrawerKeypair: Keypair
let voteWithdrawerCleanup: () => Promise<void>
let bondAuthorityPath: string
let bondAuthorityKeypair: Keypair
let bondAuthorityCleanup: () => Promise<void>
let configAccount: PublicKey
let bondAccount: PublicKey
let voteAccount: PublicKey
let validatorIdentity: Keypair
let validatorIdentityPath: string

beforeAll(async () => {
shellMatchers()
;({ provider, program } = await initTest())
})

beforeEach(async () => {
;({
path: voteWithdrawerPath,
keypair: voteWithdrawerKeypair,
cleanup: voteWithdrawerCleanup,
} = await createTempFileKeypair())
const voteWithdrawerKeypair = Keypair.generate()
janlegner marked this conversation as resolved.
Show resolved Hide resolved
;({
path: bondAuthorityPath,
keypair: bondAuthorityKeypair,
Expand All @@ -54,26 +50,29 @@ describe('Configure bond account using CLI', () => {
expect(
provider.connection.getAccountInfo(configAccount)
).resolves.not.toBeNull()
;({ validatorIdentity, validatorIdentityPath } = await getValidatorInfo(
provider.connection
))
;({ voteAccount } = await createVoteAccount(
provider,
undefined,
undefined,
voteWithdrawerKeypair
voteWithdrawerKeypair,
validatorIdentity
))
;({ bondAccount } = await executeInitBondInstruction(
program,
provider,
configAccount,
bondAuthorityKeypair,
voteAccount,
voteWithdrawerKeypair,
validatorIdentity,
33
))
})

afterEach(async () => {
await bondAuthorityCleanup()
await voteWithdrawerCleanup()
})

it('configure bond account', async () => {
Expand Down Expand Up @@ -125,7 +124,7 @@ describe('Configure bond account using CLI', () => {
'--vote-account',
voteAccount.toBase58(),
'--authority',
voteWithdrawerPath,
validatorIdentityPath,
'--bond-authority',
newBondAuthority.toBase58(),
'--revenue-share',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { executeInitConfigInstruction } from '@marinade.finance/validator-bonds-sdk/__tests__/utils/testTransactions'
import {
AnchorExtendedProvider,
getValidatorInfo,
initTest,
} from '@marinade.finance/validator-bonds-sdk/__tests__/test-validator/testValidator'
import { createVoteAccount } from '@marinade.finance/validator-bonds-sdk/__tests__/utils/staking'
Expand All @@ -26,11 +27,11 @@ describe('Init bond account using CLI', () => {
let rentPayerKeypair: Keypair
let rentPayerCleanup: () => Promise<void>
const rentPayerFunds = 10 * LAMPORTS_PER_SOL
let voteWithdrawerPath: string
let voteWithdrawerKeypair: Keypair
let voteWithdrawerCleanup: () => Promise<void>
let configAccount: PublicKey
let voteAccount: PublicKey
let validatorIdentity: Keypair
let validatorIdentityPath: string

beforeAll(async () => {
shellMatchers()
Expand All @@ -43,11 +44,7 @@ describe('Init bond account using CLI', () => {
keypair: rentPayerKeypair,
cleanup: rentPayerCleanup,
} = await createTempFileKeypair())
;({
path: voteWithdrawerPath,
keypair: voteWithdrawerKeypair,
cleanup: voteWithdrawerCleanup,
} = await createTempFileKeypair())
voteWithdrawerKeypair = Keypair.generate()
;({ configAccount } = await executeInitConfigInstruction({
program,
provider,
Expand All @@ -57,11 +54,15 @@ describe('Init bond account using CLI', () => {
expect(
provider.connection.getAccountInfo(configAccount)
).resolves.not.toBeNull()
;({ validatorIdentity, validatorIdentityPath } = await getValidatorInfo(
provider.connection
))
;({ voteAccount } = await createVoteAccount(
provider,
undefined,
undefined,
voteWithdrawerKeypair
voteWithdrawerKeypair,
validatorIdentity
))

const tx = new Transaction().add(
Expand All @@ -79,7 +80,6 @@ describe('Init bond account using CLI', () => {

afterEach(async () => {
await rentPayerCleanup()
await voteWithdrawerCleanup()
})

it('init bond account', async () => {
Expand All @@ -99,8 +99,8 @@ describe('Init bond account using CLI', () => {
configAccount.toBase58(),
'--vote-account',
voteAccount.toBase58(),
'--vote-account-withdrawer',
voteWithdrawerPath,
'--validator-identity',
validatorIdentityPath,
'--bond-authority',
bondAuthority.publicKey.toBase58(),
'--revenue-share',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,15 @@ describe('Show command using CLI', () => {
expect(
provider.connection.getAccountInfo(configAccount)
).resolves.not.toBeNull()
const { voteAccount, authorizedWithdrawer } = await createVoteAccount(
provider
)
const { voteAccount, validatorIdentity } = await createVoteAccount(provider)
const bondAuthority = Keypair.generate()
const { bondAccount } = await executeInitBondInstruction(
program,
provider,
configAccount,
bondAuthority,
voteAccount,
authorizedWithdrawer,
validatorIdentity,
222
)
const [, bump] = bondAddress(configAccount, voteAccount, program.programId)
Expand Down
8 changes: 4 additions & 4 deletions packages/validator-bonds-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"@marinade.finance/validator-bonds-sdk": "^1.0.1",
"@coral-xyz/anchor": "^0.29.0",
"@solana/web3.js": "^1.87.6",
"@marinade.finance/cli-common": "^2.0.20",
"@marinade.finance/anchor-common": "^2.0.20",
"@marinade.finance/web3js-common": "^2.0.20",
"@marinade.finance/cli-common": "^2.0.21",
"@marinade.finance/anchor-common": "^2.0.21",
"@marinade.finance/web3js-common": "^2.0.21",
"bn.js": "^5.2.1",
"jsbi": "^4.3.0",
"commander": "^9.5.0",
Expand All @@ -39,6 +39,6 @@
"yaml": "^2.3.3"
},
"devDependencies": {
"@marinade.finance/jest-utils": "^2.0.20"
"@marinade.finance/jest-utils": "^2.0.21"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function installConfigureBond(program: Command) {
'--authority <keypair_or_pubkey>',
'Authority that is permitted to do changes in bonds account. ' +
'It is either the authority defined in bonds account or ' +
'validator vote account withdrawer authority that the bond account is connected to. ' +
'vote account validator identity that the bond account is connected to. ' +
'(default: wallet keypair)',
parsePubkeyOrKeypair
)
Expand Down
26 changes: 13 additions & 13 deletions packages/validator-bonds-cli/src/commands/manage/initBond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export function installInitBond(program: Command) {
parsePubkey
)
.option(
'--vote-account-withdrawer <keypair_or_pubkey>',
'Validator vote account withdrawer authority. ' +
'To create the bond the signature of the account is needed (default: wallet keypair)',
'--validator-identity <keypair_or_pubkey>',
'Validator identity linked to the vote account. ' +
'To create the bond the signature of the validator identity is needed (default: wallet keypair)',
parsePubkeyOrKeypair
)
.option(
Expand All @@ -52,22 +52,22 @@ export function installInitBond(program: Command) {
async ({
config,
voteAccount,
voteAccountWithdrawer,
validatorIdentity,
bondAuthority,
revenueShare,
rentPayer,
}: {
config?: Promise<PublicKey>
voteAccount: Promise<PublicKey>
voteAccountWithdrawer?: Promise<PublicKey | Keypair>
validatorIdentity?: Promise<PublicKey | Keypair>
bondAuthority: Promise<PublicKey>
revenueShare: number
rentPayer?: Promise<PublicKey | Keypair>
}) => {
await manageInitBond({
config: await config,
voteAccount: await voteAccount,
voteAccountWithdrawer: await voteAccountWithdrawer,
validatorIdentity: await validatorIdentity,
bondAuthority: await bondAuthority,
revenueShare: revenueShare,
rentPayer: await rentPayer,
Expand All @@ -79,14 +79,14 @@ export function installInitBond(program: Command) {
async function manageInitBond({
config = CONFIG_ADDRESS,
voteAccount,
voteAccountWithdrawer,
validatorIdentity,
bondAuthority,
revenueShare,
rentPayer,
}: {
config?: PublicKey
voteAccount: PublicKey
voteAccountWithdrawer?: PublicKey | Keypair
validatorIdentity?: PublicKey | Keypair
bondAuthority: PublicKey
revenueShare: number
rentPayer?: PublicKey | Keypair
Expand All @@ -102,10 +102,10 @@ async function manageInitBond({
signers.push(rentPayer)
rentPayer = rentPayer.publicKey
}
voteAccountWithdrawer = voteAccountWithdrawer || wallet.publicKey
if (voteAccountWithdrawer instanceof Keypair) {
signers.push(voteAccountWithdrawer)
voteAccountWithdrawer = voteAccountWithdrawer.publicKey
validatorIdentity = validatorIdentity || wallet.publicKey
if (validatorIdentity instanceof Keypair) {
signers.push(validatorIdentity)
validatorIdentity = validatorIdentity.publicKey
}

bondAuthority = bondAuthority || wallet.publicKey
Expand All @@ -115,7 +115,7 @@ async function manageInitBond({
configAccount: config,
bondAuthority,
validatorVoteAccount: voteAccount,
validatorVoteWithdrawer: voteAccountWithdrawer,
validatorIdentity,
revenueShareHundredthBps: revenueShare,
rentPayer,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Validator Bonds configure bond account', () => {
let config: ProgramAccount<Config>
let bond: ProgramAccount<Bond>
let bondAuthority: Keypair
let withdrawerAuthority: Keypair
let validatorIdentity: Keypair
let voterAuthority: Keypair

beforeAll(async () => {
Expand All @@ -38,23 +38,26 @@ describe('Validator Bonds configure bond account', () => {
publicKey: configAccount,
account: await getConfig(program, configAccount),
}
const { voteAccount, authorizedWithdrawer, authorizedVoter } =
await createVoteAccount(provider)
const {
voteAccount,
validatorIdentity: nodePubkey,
authorizedVoter,
} = await createVoteAccount(provider)
bondAuthority = Keypair.generate()
const { bondAccount } = await executeInitBondInstruction(
program,
provider,
config.publicKey,
bondAuthority,
voteAccount,
authorizedWithdrawer,
nodePubkey,
123
)
bond = {
publicKey: bondAccount,
account: await getBond(program, bondAccount),
}
withdrawerAuthority = authorizedWithdrawer
validatorIdentity = nodePubkey
voterAuthority = authorizedVoter
})

Expand Down Expand Up @@ -91,10 +94,10 @@ describe('Validator Bonds configure bond account', () => {
const { instruction } = await configureBondInstruction({
program,
bondAccount: bond.publicKey,
authority: withdrawerAuthority,
authority: validatorIdentity,
newBondAuthority: newBondAuthority.publicKey,
})
await provider.sendIx([withdrawerAuthority], instruction)
await provider.sendIx([validatorIdentity], instruction)

const bondData = await getBond(program, bond.publicKey)
expect(bondData.config).toEqual(config.publicKey)
Expand Down
Loading
Loading