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 adjustments n1 #8

Merged
merged 6 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ seeds = true
skip-lint = false

[programs.mainnet]
validator_bonds = "vbondsKbsC4QSLQQnn6ngZvkqfywn6KgEeQbkGSpk1V"
validator_bonds = "vBoNdEvzMrSai7is21XgVYik65mqtaKXuSdMBJ1xkW4"

[programs.devnet]
validator_bonds = "vbondsKbsC4QSLQQnn6ngZvkqfywn6KgEeQbkGSpk1V"
validator_bonds = "vBoNdEvzMrSai7is21XgVYik65mqtaKXuSdMBJ1xkW4"

[programs.localnet]
validator_bonds = "vbondsKbsC4QSLQQnn6ngZvkqfywn6KgEeQbkGSpk1V"
validator_bonds = "vBoNdEvzMrSai7is21XgVYik65mqtaKXuSdMBJ1xkW4"

[registry]
url = "https://api.apr.dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ import {
Transaction,
} from '@solana/web3.js'
import {
VALIDATOR_BONDS_PROGRAM_ID,
ValidatorBondsProgram,
getConfig,
getProgram,
} from '@marinade.finance/validator-bonds-sdk'
import { initTest } from './utils'

beforeAll(() => {
shellMatchers()
})

describe('Init config account using CLI', () => {
const provider = AnchorProvider.env()
provider.opts.skipPreflight = true
const program = getProgram({
connection: provider,
programId: VALIDATOR_BONDS_PROGRAM_ID,
})
let provider: AnchorProvider
let program: ValidatorBondsProgram

let configPath: string
let configKeypair: Keypair
let configCleanup: () => Promise<void>

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

beforeEach(async () => {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
;({
Expand Down
21 changes: 11 additions & 10 deletions packages/validator-bonds-cli/__tests__/test-validator/show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ import { AnchorProvider } from '@coral-xyz/anchor'
import { shellMatchers } from '@marinade.finance/jest-utils'
import YAML from 'yaml'
import {
getProgram,
initConfigInstruction,
VALIDATOR_BONDS_PROGRAM_ID,
findBondsWithdrawerAuthority,
ValidatorBondsProgram,
} from '@marinade.finance/validator-bonds-sdk'
import { executeTxSimple } from '@marinade.finance/web3js-common'
import { transaction } from '@marinade.finance/anchor-common'
import { Keypair } from '@solana/web3.js'
import { initTest } from './utils'

beforeAll(() => {
shellMatchers()
})

describe('Show command using CLI', () => {
const provider = AnchorProvider.env()
provider.opts.skipPreflight = true
provider.opts.commitment = 'confirmed'
const program = getProgram({
connection: provider.connection,
wallet: provider.wallet,
opts: provider.opts,
programId: VALIDATOR_BONDS_PROGRAM_ID,
let provider: AnchorProvider
let program: ValidatorBondsProgram

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

it('show config', async () => {
Expand Down Expand Up @@ -74,6 +72,7 @@ describe('Show command using CLI', () => {
operatorAuthority: operatorAuthority.toBase58(),
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
minimumStakeLamports: 1000000000,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
Expand Down Expand Up @@ -111,6 +110,7 @@ describe('Show command using CLI', () => {
operatorAuthority: operatorAuthority.toBase58(),
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
minimumStakeLamports: 1000000000,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
Expand Down Expand Up @@ -175,6 +175,7 @@ describe('Show command using CLI', () => {
operatorAuthority: operatorAuthority.toBase58(),
epochsToClaimSettlement: 101,
withdrawLockupEpochs: 102,
minimumStakeLamports: 1000000000,
bondsWithdrawerAuthorityBump,
reserved: [512],
},
Expand Down
19 changes: 19 additions & 0 deletions packages/validator-bonds-cli/__tests__/test-validator/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as anchor from '@coral-xyz/anchor'
import { AnchorProvider } from '@coral-xyz/anchor'
import {
ValidatorBondsProgram,
getProgram,
} from '@marinade.finance/validator-bonds-sdk'

export async function initTest(): Promise<{
program: ValidatorBondsProgram
provider: AnchorProvider
}> {
if (process.env.ANCHOR_PROVIDER_URL?.includes('localhost')) {
// workaround to: https://github.com/coral-xyz/anchor/pull/2725
process.env.ANCHOR_PROVIDER_URL = 'http://127.0.0.1:8899'
}
const provider = AnchorProvider.env() as anchor.AnchorProvider
provider.opts.skipPreflight = true
return { program: getProgram(provider), provider }
}
3 changes: 2 additions & 1 deletion packages/validator-bonds-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ program
.allowExcessArguments(false)
.option(
'-u, --cluster <cluster>',
'solana cluster URL, accepts shortcuts (d/devnet, m/mainnet) (default: http://localhost:8899)'
'solana cluster URL, accepts shortcuts (d/devnet, m/mainnet)',
'http://127.0.0.1:8899'
)
.option('-c <cluster>', 'alias for "-u, --cluster"')
.option('--commitment <commitment>', 'Commitment', 'confirmed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ export async function initTest(): Promise<{
program: ValidatorBondsProgram
provider: AnchorProvider
}> {
anchor.setProvider(anchor.AnchorProvider.env())
const provider = anchor.getProvider() as anchor.AnchorProvider
if (process.env.ANCHOR_PROVIDER_URL?.includes('localhost')) {
// workaround to: https://github.com/coral-xyz/anchor/pull/2725
process.env.ANCHOR_PROVIDER_URL = 'http://127.0.0.1:8899'
}
const provider = AnchorProvider.env() as anchor.AnchorProvider
provider.opts.skipPreflight = true
return { program: getProgram(provider), provider }
}
60 changes: 40 additions & 20 deletions packages/validator-bonds-sdk/generated/validator_bonds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export type ValidatorBonds = {
"isMut": false,
"isSigner": false,
"docs": [
"authority that the provided stake account will be assigned to, authority owner is the program"
"new authority owner, it's the bonds program"
],
"pda": {
"seeds": [
Expand All @@ -296,7 +296,7 @@ export type ValidatorBonds = {
},
{
"name": "stakeAccount",
"isMut": false,
"isMut": true,
"isSigner": false,
"docs": [
"stake account to be deposited"
Expand Down Expand Up @@ -2289,7 +2289,7 @@ export type ValidatorBonds = {
]
},
{
"name": "DepositBondEvent",
"name": "FundBondEvent",
"fields": [
{
"name": "bond",
Expand Down Expand Up @@ -2812,7 +2812,7 @@ export type ValidatorBonds = {
]
},
{
"name": "WithdrawEvent",
"name": "ClaimWithdrawRequestEvent",
"fields": [
{
"name": "withdrawRequest",
Expand Down Expand Up @@ -2926,18 +2926,18 @@ export type ValidatorBonds = {
},
{
"code": 6012,
"name": "HundrethBasisPointsOverflow",
"name": "HundredthBasisPointsOverflow",
"msg": "Value of hundredth basis points is too big"
},
{
"code": 6013,
"name": "HundrethBasisPointsCalculation",
"msg": "Hundreth basis points calculation failure"
"name": "HundredthBasisPointsCalculation",
"msg": "Hundredth basis points calculation failure"
},
{
"code": 6014,
"name": "HundrethBasisPointsParse",
"msg": "Hundreth basis points failure to parse the value"
"name": "HundredthBasisPointsParse",
"msg": "Hundredth basis points failure to parse the value"
},
{
"code": 6015,
Expand Down Expand Up @@ -3081,13 +3081,23 @@ export type ValidatorBonds = {
},
{
"code": 6043,
"name": "NonBondStakeAuthorities",
"msg": "One or both stake authorities does not belong to bonds program"
},
{
"code": 6044,
"name": "SettlementAuthorityMismatch",
"msg": "Settlement stake account authority does not match with the provided stake account authority"
},
{
"code": 6044,
"code": 6045,
"name": "StakeDelegationMismatch",
"msg": "Delegation of provided stake account mismatches"
},
{
"code": 6046,
"name": "NotYetImplemented",
"msg": "Not yet implemented"
}
]
};
Expand Down Expand Up @@ -3370,7 +3380,7 @@ export const IDL: ValidatorBonds = {
"isMut": false,
"isSigner": false,
"docs": [
"authority that the provided stake account will be assigned to, authority owner is the program"
"new authority owner, it's the bonds program"
],
"pda": {
"seeds": [
Expand All @@ -3390,7 +3400,7 @@ export const IDL: ValidatorBonds = {
},
{
"name": "stakeAccount",
"isMut": false,
"isMut": true,
"isSigner": false,
"docs": [
"stake account to be deposited"
Expand Down Expand Up @@ -5383,7 +5393,7 @@ export const IDL: ValidatorBonds = {
]
},
{
"name": "DepositBondEvent",
"name": "FundBondEvent",
"fields": [
{
"name": "bond",
Expand Down Expand Up @@ -5906,7 +5916,7 @@ export const IDL: ValidatorBonds = {
]
},
{
"name": "WithdrawEvent",
"name": "ClaimWithdrawRequestEvent",
"fields": [
{
"name": "withdrawRequest",
Expand Down Expand Up @@ -6020,18 +6030,18 @@ export const IDL: ValidatorBonds = {
},
{
"code": 6012,
"name": "HundrethBasisPointsOverflow",
"name": "HundredthBasisPointsOverflow",
"msg": "Value of hundredth basis points is too big"
},
{
"code": 6013,
"name": "HundrethBasisPointsCalculation",
"msg": "Hundreth basis points calculation failure"
"name": "HundredthBasisPointsCalculation",
"msg": "Hundredth basis points calculation failure"
},
{
"code": 6014,
"name": "HundrethBasisPointsParse",
"msg": "Hundreth basis points failure to parse the value"
"name": "HundredthBasisPointsParse",
"msg": "Hundredth basis points failure to parse the value"
},
{
"code": 6015,
Expand Down Expand Up @@ -6175,13 +6185,23 @@ export const IDL: ValidatorBonds = {
},
{
"code": 6043,
"name": "NonBondStakeAuthorities",
"msg": "One or both stake authorities does not belong to bonds program"
},
{
"code": 6044,
"name": "SettlementAuthorityMismatch",
"msg": "Settlement stake account authority does not match with the provided stake account authority"
},
{
"code": 6044,
"code": 6045,
"name": "StakeDelegationMismatch",
"msg": "Delegation of provided stake account mismatches"
},
{
"code": 6046,
"name": "NotYetImplemented",
"msg": "Not yet implemented"
}
]
};
3 changes: 3 additions & 0 deletions packages/validator-bonds-sdk/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { ProgramAccount } from '@coral-xyz/anchor'
import { PublicKey } from '@solana/web3.js'
import { ValidatorBondsProgram, Config } from './sdk'

// TODO:
// - users can create arbitrary stake accounts (even with lockups), sdk must be prepared for that when showing total usable deposits

export async function getConfig(
program: ValidatorBondsProgram,
address: PublicKey
Expand Down
Loading
Loading