/
acceptOwnership.ts
85 lines (69 loc) · 2.81 KB
/
acceptOwnership.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 { GetOwnership } from './inspectOwnership'
import { SolanaConstructor } from '../../../lib/types'
import RDD from '../../../lib/rdd'
export const makeAcceptOwnershipCommand = (
contractId: CONTRACT_LIST,
getOwnership: GetOwnership,
): SolanaConstructor => {
return class AcceptOwnership extends SolanaCommand {
static id = `${contractId}:accept_ownership`
static category = contractId
static examples = [`yarn gauntlet ${contractId}:accept_ownership --network=devnet [PROGRAM_STATE]`]
constructor(flags, args) {
super(flags, args)
this.requireArgs('Please provide the state as an arg!')
}
buildCommand = async (flags, args) => {
const contract = getContract(contractId, '')
const address = contract.programId.toString()
this.program = this.loadProgram(contract.idl, address)
return this
}
makeRawTransaction = async (signer: PublicKey) => {
const contract = getContract(contractId, '')
const address = contract.programId.toString()
const program = this.loadProgram(contract.idl, address)
const state = new PublicKey(this.args[0])
const tx = await program.methods
.acceptOwnership()
.accounts({
state: state,
authority: signer,
})
.instruction()
return [tx]
}
beforeExecute = async () => {
const ownership = await getOwnership(this.program, new PublicKey(this.args[0]))
const contract = RDD.getContractFromRDD(RDD.load(this.flags.network, this.flags.rdd), this.args[0])
logger.info(`Accepting Ownership of contract of type "${contract.type}":
- Contract: ${contract.address} ${contract.description ? '- ' + contract.description : ''}
- Current Owner: ${ownership.owner.toString()}
- Next Owner (proposed): ${ownership.proposedOwner.toString()}`)
await prompt('Continue?')
}
execute = async () => {
await this.buildCommand(this.flags, this.args)
await this.beforeExecute()
const signer = this.wallet.publicKey
const rawTx = await this.makeRawTransaction(signer)
await this.simulateTx(signer, rawTx)
const txhash = await this.sendTxWithIDL(this.signAndSendRawTx, this.program.idl)(rawTx)
logger.success(`Accepted ownership on tx hash: ${txhash}`)
const state = this.args[0]
return {
responses: [
{
tx: this.wrapResponse(txhash, state),
contract: state,
},
],
} as Result<TransactionResponse>
}
}
}