Skip to content

Commit

Permalink
Gauntlet transfer ownership (#105)
Browse files Browse the repository at this point in the history
* accept and transfer ownership commands store

* fixes
  • Loading branch information
RodrigoAD authored Jan 13, 2022
1 parent 60cc230 commit 2cecb6b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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'

export default class AcceptOwnership extends SolanaCommand {
static id = 'store:accept_ownership'
static category = CONTRACT_LIST.STORE

static examples = ['yarn gauntlet store:accept_ownership --network=devnet --state=[STORE_STATE]']

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

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

execute = async () => {
const store = getContract(CONTRACT_LIST.STORE, '')
const storeAddress = store.programId.toString()
const storeProgram = this.loadProgram(store.idl, storeAddress)

const owner = this.wallet.payer

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

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

const tx = await storeProgram.rpc.acceptOwnership({
accounts: {
store: storeState,
authority: owner.publicKey,
},
signers: [owner],
})

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

return {
responses: [
{
tx: this.wrapResponse(tx, storeState.toString(), { state: storeState.toString() }),
contract: storeState.toString(),
},
],
} as Result<TransactionResponse>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import Initialize from './initialize'
import CreateFeed from './createFeed'
import SetValidatorConfig from './setValidatorConfig'
import SetWriter from './setWriter'
import TransferOwnership from './transferOwnership'
import AcceptOwnership from './acceptOwnership'

export default [Initialize, CreateFeed, SetValidatorConfig, SetWriter]
export default [Initialize, CreateFeed, SetValidatorConfig, SetWriter, TransferOwnership, AcceptOwnership]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Result } from '@chainlink/gauntlet-core'
import { 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'

export default class TransferWwnership extends SolanaCommand {
static id = 'store:transfer_ownership'
static category = CONTRACT_LIST.STORE

static examples = [
'yarn gauntlet store:transfer_ownership --network=devnet --state=[STORE_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 store = getContract(CONTRACT_LIST.STORE, '')
const storeAddress = store.programId.toString()
const storeProgram = this.loadProgram(store.idl, storeAddress)

const owner = this.wallet.payer

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

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

const tx = await storeProgram.rpc.transferOwnership(proposedOwner, {
accounts: {
store: storeState,
authority: owner.publicKey,
},
signers: [owner],
})

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

0 comments on commit 2cecb6b

Please sign in to comment.