Skip to content

Commit

Permalink
ownership commands for every program
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoAD committed Jan 14, 2022
1 parent 2cecb6b commit 74dd5b2
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import Initialize from './initialize'
import AddAccess from './addAccess'
import ReadState from './read'
import { makeAcceptOwnershipCommand } from '../ownership/acceptOwnership'
import { makeTransferOwnershipCommand } from '../ownership/transferOwnership'
import { CONTRACT_LIST } from '../../../lib/contracts'

export default [Initialize, AddAccess, ReadState]
export default [
Initialize,
AddAccess,
ReadState,
makeAcceptOwnershipCommand(CONTRACT_LIST.ACCESS_CONTROLLER),
makeTransferOwnershipCommand(CONTRACT_LIST.ACCESS_CONTROLLER),
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import SetupFlow from './setup.dev.flow'
import SetupRDDFlow from './setup.dev.rdd.flow'
import Transmit from './transmit.dev'
import Inspection from './inspection'
import { makeAcceptOwnershipCommand } from '../ownership/acceptOwnership'
import { CONTRACT_LIST } from '../../../lib/contracts'
import { makeTransferOwnershipCommand } from '../ownership/transferOwnership'

export default [
Initialize,
Expand All @@ -32,4 +35,6 @@ export default [
Transmit,
SetupFlow,
SetupRDDFlow,
makeAcceptOwnershipCommand(CONTRACT_LIST.OCR_2),
makeTransferOwnershipCommand(CONTRACT_LIST.OCR_2),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import { SolanaConstructor } from '../../../lib/types'

export const makeAcceptOwnershipCommand = (contractId: CONTRACT_LIST): SolanaConstructor => {
return class AcceptOwnership extends SolanaCommand {
static id = `${contractId}:accept_ownership`
static category = contractId

static examples = [`yarn gauntlet ${contractId}:accept_ownership --network=devnet --state=[PROGRAM_STATE]`]

constructor(flags, args) {
super(flags, args)

this.require(!!this.flags.state, 'Please provide flags with "state"')
}

execute = async () => {
const contract = getContract(contractId, '')
const address = contract.programId.toString()
const program = this.loadProgram(contract.idl, address)

const owner = this.wallet.payer

const state = new PublicKey(this.flags.state)

await prompt(`Accepting ownership of ${contractId} state (${state.toString()}). Continue?`)

const tx = await program.rpc.acceptOwnership({
accounts: {
// Store contract expects an store account instead of a state acc
...(contractId === CONTRACT_LIST.STORE && { store: state }),
...(contractId !== CONTRACT_LIST.STORE && { state }),
authority: owner.publicKey,
},
signers: [owner],
})

logger.success(`Accepted ownership on tx ${tx}`)

return {
responses: [
{
tx: this.wrapResponse(tx, state.toString(), { state: state.toString() }),
contract: state.toString(),
},
],
} as Result<TransactionResponse>
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { makeTransferOwnershipCommand } from './transferOwnership'
import { makeAcceptOwnershipCommand } from './acceptOwnership'

export default {
makeTransferOwnershipCommand,
makeAcceptOwnershipCommand,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import { SolanaConstructor } from '../../../lib/types'

export const makeTransferOwnershipCommand = (contractId: CONTRACT_LIST): SolanaConstructor => {
return class TransferOwnership extends SolanaCommand {
static id = `${contractId}:transfer_ownership`
static category = contractId

static examples = [
`yarn gauntlet ${contractId}:transfer_ownership --network=devnet --state=[PROGRAM_STATE] --to=[PROPOSED_OWNER]`,
]

constructor(flags, args) {
super(flags, args)

this.require(!!this.flags.state, 'Please provide flags with "state"')
this.require(!!this.flags.to, 'Please provide flags with "to"')
}

execute = async () => {
const contract = getContract(contractId, '')
const address = contract.programId.toString()
const program = this.loadProgram(contract.idl, address)

const owner = this.wallet.payer

const state = new PublicKey(this.flags.state)
const proposedOwner = new PublicKey(this.flags.to)

await prompt(
`Transfering ownership of ${contractId} state (${state.toString()}) to: (${proposedOwner.toString()}). Continue?`,
)

const tx = await program.rpc.transferOwnership(proposedOwner, {
accounts: {
// Store contract expects an store account instead of a state acc
...(contractId === CONTRACT_LIST.STORE && { store: state }),
...(contractId !== CONTRACT_LIST.STORE && { state }),
authority: owner.publicKey,
},
signers: [owner],
})

logger.success(`Ownership transferred to ${proposedOwner.toString()} on tx ${tx}`)

return {
responses: [
{
tx: this.wrapResponse(tx, state.toString(), { state: state.toString() }),
contract: state.toString(),
},
],
} as Result<TransactionResponse>
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import Initialize from './initialize'
import CreateFeed from './createFeed'
import SetValidatorConfig from './setValidatorConfig'
import SetWriter from './setWriter'
import TransferOwnership from './transferOwnership'
import AcceptOwnership from './acceptOwnership'
import { makeAcceptOwnershipCommand } from '../ownership/acceptOwnership'
import { makeTransferOwnershipCommand } from '../ownership/transferOwnership'
import { CONTRACT_LIST } from '../../../lib/contracts'

export default [Initialize, CreateFeed, SetValidatorConfig, SetWriter, TransferOwnership, AcceptOwnership]
export default [
Initialize,
CreateFeed,
SetValidatorConfig,
SetWriter,
makeAcceptOwnershipCommand(CONTRACT_LIST.STORE),
makeTransferOwnershipCommand(CONTRACT_LIST.STORE),
]

This file was deleted.

4 changes: 4 additions & 0 deletions gauntlet/packages/gauntlet-solana-contracts/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SolanaCommand } from '@chainlink/gauntlet-solana'

interface Oracle {
signer: Buffer
transmitter: Buffer
Expand All @@ -10,3 +12,5 @@ export interface OCR2Config {
offchainConfig: Buffer
offchainConfigVersion: number
}

export type SolanaConstructor = new (flags, args) => SolanaCommand

0 comments on commit 74dd5b2

Please sign in to comment.