Skip to content

Commit

Permalink
[contract] contract release, first version
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Nov 30, 2023
1 parent 053a1e7 commit 3590b10
Show file tree
Hide file tree
Showing 62 changed files with 9,934 additions and 379 deletions.
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[toolchain]
anchor_version = "0.29.0"
solana_version = "1.16.17"
solana_version = "1.16.18"

[workspace]
types = "packages/validator-bonds-sdk/generated/"
Expand Down
25 changes: 25 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ codegen-units = 1

[workspace.dependencies]
anchor-lang = "0.29.0"
anchor-spl = {version = "0.29.0", default-features = false, features = ["stake"]}
solana-security-txt = "1.1.1"
default-env = "0.1.1"
anyhow = "1.0.40"
bincode = "1.3.3"
clap = { version = "4.1.11", features = ["derive", "env"] }
Expand All @@ -35,5 +38,5 @@ solana-ledger = "=1.16.18"
solana-program = "=1.16.18"
solana-runtime = "=1.16.18"
solana-sdk = "=1.16.18"
solana-security-txt = "1.1.1"
tokio = { version = "1", features = ["full"] }

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"_test": "pnpm jest --config jest.config.test-validator.js -- \"$FILE\"",
"test:test-validator": "BROWSER= anchor test",
"test:bankrun": "pnpm jest --config jest.config.bankrun.js --runInBand true -- \"$FILE\"",
"test": "cargo test && pnpm test:bankrun && pnpm test:test-validator",
"test:cargo": "cargo test --features no-entrypoint",
"test": "pnpm test:cargo && pnpm test:bankrun && pnpm test:test-validator",
"cli": "ts-node ./packages/validator-bonds-cli/src/",
"lint:cargo": "cargo fmt -- --check && cargo clippy",
"lint:cargo-fix": "cargo fmt --all && cargo clippy --fix --allow-staged --allow-dirty",
Expand All @@ -28,7 +29,7 @@
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "4.9.5",
"@marinade.finance/jest-utils": "^2.0.17"
"@marinade.finance/jest-utils": "^2.0.18"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Init config account using CLI', () => {
operator.toBase58(),
'--rent-payer',
rentPayerPath,
'--claim-settlement-after-epochs',
'--epochs-to-claim-settlement',
42,
'--withdraw-lockup-epochs',
43,
Expand All @@ -102,7 +102,7 @@ describe('Init config account using CLI', () => {
const configData = await getConfig(program, configKeypair.publicKey)
expect(configData.adminAuthority).toEqual(admin)
expect(configData.operatorAuthority).toEqual(operator)
expect(configData.claimSettlementAfterEpochs).toEqual(42)
expect(configData.epochsToClaimSettlement).toEqual(42)
expect(configData.withdrawLockupEpochs).toEqual(43)
await expect(
provider.connection.getBalance(rentPayerKeypair.publicKey)
Expand Down
19 changes: 15 additions & 4 deletions packages/validator-bonds-cli/__tests__/test-validator/show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getProgram,
initConfigInstruction,
VALIDATOR_BONDS_PROGRAM_ID,
findBondsWithdrawerAuthority,
} from '@marinade.finance/validator-bonds-sdk'
import { executeTxSimple } from '@marinade.finance/web3js-common'
import { transaction } from '@marinade.finance/anchor-common'
Expand Down Expand Up @@ -33,13 +34,17 @@ describe('Show command using CLI', () => {
program,
adminAuthority,
operatorAuthority,
claimSettlementAfterEpochs: 101,
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
})
tx.add(initConfigIx)
await executeTxSimple(provider.connection, tx, [provider.wallet, keypair!])

const configAccountAddress = keypair!.publicKey
const [, bondsWithdrawerAuthorityBump] = findBondsWithdrawerAuthority(
configAccountAddress,
program.programId
)
await (
expect([
'pnpm',
Expand Down Expand Up @@ -67,8 +72,10 @@ describe('Show command using CLI', () => {
account: {
adminAuthority: adminAuthority.toBase58(),
operatorAuthority: operatorAuthority.toBase58(),
claimSettlementAfterEpochs: 101,
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
}),
})
Expand Down Expand Up @@ -102,8 +109,10 @@ describe('Show command using CLI', () => {
account: {
adminAuthority: adminAuthority.toBase58(),
operatorAuthority: operatorAuthority.toBase58(),
claimSettlementAfterEpochs: 101,
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
},
]),
Expand Down Expand Up @@ -164,8 +173,10 @@ describe('Show command using CLI', () => {
account: {
adminAuthority: adminAuthority.toBase58(),
operatorAuthority: operatorAuthority.toBase58(),
claimSettlementAfterEpochs: 101,
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
},
]),
Expand Down
12 changes: 6 additions & 6 deletions packages/validator-bonds-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"main": "src/index",
"dependencies": {
"@marinade.finance/validator-bonds-sdk": "workspace:*",
"@coral-xyz/anchor": "^0.28.0",
"@solana/web3.js": "^1.87.3",
"@marinade.finance/cli-common": "^2.0.17",
"@marinade.finance/anchor-common": "^2.0.17",
"@marinade.finance/web3js-common": "^2.0.17",
"@coral-xyz/anchor": "^0.29.0",
"@solana/web3.js": "^1.87.6",
"@marinade.finance/cli-common": "^2.0.18",
"@marinade.finance/anchor-common": "^2.0.18",
"@marinade.finance/web3js-common": "^2.0.18",
"bn.js": "^5.2.1",
"jsbi": "^4.3.0",
"commander": "^9.5.0",
Expand All @@ -32,6 +32,6 @@
"yaml": "^2.3.3"
},
"devDependencies": {
"@marinade.finance/jest-utils": "^2.0.17"
"@marinade.finance/jest-utils": "^2.0.18"
}
}
14 changes: 7 additions & 7 deletions packages/validator-bonds-cli/src/commands/manage/initConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function installInitConfig(program: Command) {
parsePubkeyOrKeypair
)
.option(
'--claim-settlement-after-epochs <number>',
'--epochs-to-claim-settlement <number>',
'number of epochs after which claim can be settled',
parseFloat,
3
Expand All @@ -52,22 +52,22 @@ export function installInitConfig(program: Command) {
admin,
operator,
rentPayer,
claimSettlementAfterEpochs,
epochsToClaimSettlement,
withdrawLockupEpochs,
}: {
address?: Promise<Keypair>
admin?: Promise<PublicKey>
operator?: Promise<PublicKey>
rentPayer?: Promise<PublicKey | Keypair>
claimSettlementAfterEpochs: number
epochsToClaimSettlement: number
withdrawLockupEpochs: number
}) => {
await manageInitConfig({
address: await address,
adminAuthority: await admin,
operatorAuthority: await operator,
rentPayer: await rentPayer,
claimSettlementAfterEpochs,
epochsToClaimSettlement,
withdrawLockupEpochs,
})
}
Expand All @@ -79,14 +79,14 @@ async function manageInitConfig({
adminAuthority,
operatorAuthority,
rentPayer,
claimSettlementAfterEpochs,
epochsToClaimSettlement,
withdrawLockupEpochs,
}: {
address?: Keypair
adminAuthority?: PublicKey
operatorAuthority?: PublicKey
rentPayer?: PublicKey | Keypair
claimSettlementAfterEpochs: number
epochsToClaimSettlement: number
withdrawLockupEpochs: number
}) {
const { program, provider, logger, simulate, printOnly, wallet } =
Expand All @@ -109,7 +109,7 @@ async function manageInitConfig({
program,
adminAuthority,
operatorAuthority,
claimSettlementAfterEpochs,
epochsToClaimSettlement,
withdrawLockupEpochs,
rentPayer,
})
Expand Down
3 changes: 2 additions & 1 deletion packages/validator-bonds-cli/src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
print_data,
FormatType,
reformat,
reformatReserved,
} from '@marinade.finance/cli-common'
import { PublicKey } from '@solana/web3.js'
import { Command } from 'commander'
Expand Down Expand Up @@ -136,7 +137,7 @@ async function showConfig({
}
}

const reformatted = reformat(data)
const reformatted = reformat(data, reformatReserved)
print_data(reformatted, format)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Validator Bonds config account tests', () => {
program,
adminAuthority,
operatorAuthority,
claimSettlementAfterEpochs: 1,
epochsToClaimSettlement: 1,
withdrawLockupEpochs: 2,
})
tx.add(instruction)
Expand All @@ -43,7 +43,7 @@ describe('Validator Bonds config account tests', () => {

expect(configData.adminAuthority).toEqual(adminAuthority)
expect(configData.operatorAuthority).toEqual(operatorAuthority)
expect(configData.claimSettlementAfterEpochs).toEqual(1)
expect(configData.epochsToClaimSettlement).toEqual(1)
expect(configData.withdrawLockupEpochs).toEqual(2)
})
})
31 changes: 31 additions & 0 deletions packages/validator-bonds-sdk/__tests__/bankrun/solanaStake.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// import { Keypair } from '@solana/web3.js'
// import {
// ValidatorBondsProgram,
// getConfig,
// initConfigInstruction,
// } from '../../src'
// import { BankrunProvider } from 'anchor-bankrun'
// import {
// bankrunExecute,
// bankrunTransaction,
// initBankrunTest,
// } from './utils/bankrun'

describe('Solana stake account behavior verification', () => {
// let provider: BankrunProvider
// let program: ValidatorBondsProgram

beforeAll(async () => {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
// ;({ provider, program } = await initBankrunTest())
})

// TODO: #1 when stake account is created with lockup what happens when authority is changed?
// will the lockup custodian stays the same as before?
// can be lockup removed completely?
// what the 'custodian' field on 'authorize' method has the significance for?
//
// TODO: #2 check what happens when lockup account is merged with non-lockup account?
// TODO: #3 what happen after split of stake account with authorities, are they maintained as in the original one?
it('', async () => {})
})
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Validator Bonds config account tests', () => {
program,
adminAuthority,
operatorAuthority,
claimSettlementAfterEpochs: 1,
epochsToClaimSettlement: 1,
withdrawLockupEpochs: 2,
})
tx.add(instruction)
Expand All @@ -72,14 +72,14 @@ describe('Validator Bonds config account tests', () => {

expect(configData.adminAuthority).toEqual(adminAuthority)
expect(configData.operatorAuthority).toEqual(operatorAuthority)
expect(configData.claimSettlementAfterEpochs).toEqual(1)
expect(configData.epochsToClaimSettlement).toEqual(1)
expect(configData.withdrawLockupEpochs).toEqual(2)

// Ensure the event listener was called
await event.then(e => {
expect(e.adminAuthority).toEqual(adminAuthority)
expect(e.operatorAuthority).toEqual(operatorAuthority)
expect(e.claimSettlementAfterEpochs).toEqual(1)
expect(e.epochsToClaimSettlement).toEqual(1)
expect(e.withdrawLockupEpochs).toEqual(2)
})
})
Expand All @@ -97,7 +97,7 @@ describe('Validator Bonds config account tests', () => {
program,
adminAuthority,
operatorAuthority,
claimSettlementAfterEpochs: i,
epochsToClaimSettlement: i,
withdrawLockupEpochs: i + 1,
})
tx.add(instruction)
Expand Down
Loading

0 comments on commit 3590b10

Please sign in to comment.