diff --git a/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/acceptOwnership.ts b/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/acceptOwnership.ts new file mode 100644 index 000000000..cd6316243 --- /dev/null +++ b/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/acceptOwnership.ts @@ -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 + } +} diff --git a/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/index.ts b/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/index.ts index a5e7edcaa..44043282a 100644 --- a/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/index.ts +++ b/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/index.ts @@ -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] diff --git a/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/transferOwnership.ts b/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/transferOwnership.ts new file mode 100644 index 000000000..331aa9690 --- /dev/null +++ b/gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/transferOwnership.ts @@ -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 + } +}