Skip to content

Commit

Permalink
Merge in createProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Nov 17, 2022
1 parent 5681f1f commit c58e0fb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 111 deletions.
Expand Up @@ -14,7 +14,6 @@ import { CONTRACT_LIST } from '../../../lib/contracts'
import { makeTransferOwnershipCommand } from '../ownership/transferOwnership'
import { makeUpgradeProgramCommand } from '../../abstract/upgrade'
import Fund from './fund'
import CreateProposal from './proposal/createProposal'
import ProposeConfig from './proposeConfig'
import Close from './close'
import WithdrawFunds from './withdrawFunds'
Expand All @@ -33,7 +32,6 @@ export default [
OCR2InitializeFlow,
SetBilling,
AcceptProposal,
CreateProposal,
ProposeConfig,
ReadState,
SetBillingAccessController,
Expand Down
Expand Up @@ -8,7 +8,6 @@ import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import OCR2Inspect from './inspection/inspect'
import CreateFeed from '../store/createFeed'
import SetWriter from '../store/setWriter'
import CreateProposal from './proposal/createProposal'
import ProposeConfig from './proposeConfig'
import AcceptProposal from './proposal/acceptProposal'

Expand Down Expand Up @@ -67,15 +66,8 @@ export default class OCR2InitializeFlow extends FlowCommand<TransactionResponse>
},
{
id: this.stepIds.PROPOSAL,
name: 'Create Proposal',
command: CreateProposal,
},
{
name: 'Propose Config',
command: ProposeConfig,
flags: {
proposalId: FlowCommand.ID.data(this.stepIds.PROPOSAL, 'proposal'),
},
args: [FlowCommand.ID.contract(this.stepIds.OCR_2)],
},
{
Expand Down

This file was deleted.

@@ -1,7 +1,7 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger, BN, time, prompt, longs } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { Keypair, PublicKey, SystemProgram } from '@solana/web3.js'
import { MAX_TRANSACTION_BYTES, ORACLES_MAX_LENGTH } from '../../../lib/constants'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'
import { divideIntoChunks } from '../../../lib/utils'
Expand Down Expand Up @@ -96,7 +96,6 @@ type Input = {
f: number | string
offchainConfig: OffchainConfig
userSecret?: string
proposalId: string
}

export const prepareOffchainConfigForDiff = (config: OffchainConfig, extra?: Object): Object => {
Expand All @@ -112,12 +111,11 @@ const _toHex = (a: string) => Buffer.from(a, 'hex')
export default class ProposeConfig extends SolanaCommand {
static id = 'ocr2:propose_config'
static category = CONTRACT_LIST.OCR_2
static examples = [
'yarn gauntlet ocr2:propose_config --network=devnet --rdd=[PATH_TO_RDD] --proposalId=EPRYwrb1Dwi8VT5SutS4vYNdF8HqvE7QwvqeCCwHdVLC [AGGREGATOR_ADDRESS]',
]
static examples = ['yarn gauntlet ocr2:propose_config --network=devnet --rdd=[PATH_TO_RDD] [AGGREGATOR_ADDRESS]']

input: Input
randomSecret: string
proposal: Keypair

static makeInputFromRDD = (rdd: any, stateAddress: string): OffchainConfig => {
const aggregator = rdd.contracts[stateAddress]
Expand Down Expand Up @@ -193,16 +191,11 @@ export default class ProposeConfig extends SolanaCommand {
oracles,
f,
offchainConfig,
proposalId: this.flags.proposalId || this.flags.configProposal,
}
}

constructor(flags, args) {
super(flags, args)
this.require(
!!this.flags.proposalId || !!this.flags.configProposal,
'Please provide Config Proposal ID with flag "proposalId" or "configProposal"',
)
this.requireArgs('Please provide an aggregator address')
this.require(
// TODO: should be able to just rely on random secret?
Expand All @@ -220,15 +213,38 @@ export default class ProposeConfig extends SolanaCommand {
}

makeRawTransaction = async (signer: PublicKey) => {
const proposal = new PublicKey(this.input.proposalId)
const proposal = Keypair.generate()
this.proposal = proposal

// createProposal
const version = new BN(2)

logger.log('Generating data for creating config proposal')
logger.log('Config Proposal state will be at:', proposal.toString())

const createIx = await this.program.methods
.createProposal(version)
.accounts({
proposal: proposal.publicKey,
authority: signer,
})
.instruction()
const defaultAccountSize = new BN(this.program.account.proposal.size)
const createAccountIx = SystemProgram.createAccount({
fromPubkey: signer,
newAccountPubkey: proposal.publicKey,
space: defaultAccountSize.toNumber(),
lamports: await this.provider.connection.getMinimumBalanceForRentExemption(defaultAccountSize.toNumber()),
programId: this.program.programId,
})

// proposeConfig

const oracles = this.input.oracles.map(({ signer, transmitter }) => ({
signer: Buffer.from(signer, 'hex'),
transmitter: new PublicKey(transmitter),
}))

// proposeConfig

const f = new BN(this.input.f)

const minOracleLength = f.mul(new BN(3)).toNumber()
Expand All @@ -241,7 +257,7 @@ export default class ProposeConfig extends SolanaCommand {
const configIx = await this.program.methods
.proposeConfig(oracles, f)
.accounts({
proposal,
proposal: proposal.publicKey,
authority: signer,
})
.instruction()
Expand All @@ -259,7 +275,7 @@ export default class ProposeConfig extends SolanaCommand {
const payeesIx = await this.program.methods
.proposePayees(link)
.accounts({
proposal,
proposal: proposal.publicKey,
authority: signer,
})
.remainingAccounts(payees)
Expand Down Expand Up @@ -295,7 +311,7 @@ export default class ProposeConfig extends SolanaCommand {
this.program.methods
.writeOffchainConfig(buffer)
.accounts({
proposal: proposal,
proposal: proposal.publicKey,
authority: signer,
})
.instruction(),
Expand All @@ -305,12 +321,12 @@ export default class ProposeConfig extends SolanaCommand {
const finalizeIx = await this.program.methods
.finalizeProposal()
.accounts({
proposal: proposal,
proposal: proposal.publicKey,
authority: signer,
})
.instruction()

return [configIx, payeesIx, ...offchainConfigIxs, finalizeIx]
return [createAccountIx, createIx, configIx, payeesIx, ...offchainConfigIxs, finalizeIx]
}

beforeExecute = async () => {
Expand Down Expand Up @@ -382,10 +398,15 @@ export default class ProposeConfig extends SolanaCommand {
}
const txhash = txs[txs.length - 1]
logger.success(`Config proposal finalized on tx ${txhash}`)
logger.line()
logger.info('Use the Config Proposal ID in future proposal commands:')
logger.info(this.proposal.publicKey.toString())
logger.line()

return {
data: {
secret: this.randomSecret,
proposal: this.proposal.publicKey.toString(),
},
responses: [
// TODO: map over responses
Expand Down
Expand Up @@ -10,7 +10,6 @@ import DeployToken from '../token/deploy'
import SetBilling from './setBilling'
import CreateFeed from '../store/createFeed'
import SetWriter from '../store/setWriter'
import CreateProposal from './proposal/createProposal'
import ProposeConfig from './proposeConfig'
import AcceptProposal from './proposal/acceptProposal'

Expand Down Expand Up @@ -192,22 +191,16 @@ export default class SetupFlow extends FlowCommand<TransactionResponse> {
},
args: [FlowCommand.ID.contract(this.stepIds.OCR_2)],
},
{
id: this.stepIds.PROPOSAL,
name: 'Create Proposal',
command: CreateProposal,
},
{
name: 'Propose Config',
command: ProposeConfig,
id: this.stepIds.PROPOSAL,
flags: {
input: {
oracles: configInput.oracles,
f: configInput.f,
offchainConfig: offchainConfigInput,
proposalId: this.getReportStepDataById(FlowCommand.ID.data(this.stepIds.PROPOSAL, 'proposal')),
},
proposalId: FlowCommand.ID.data(this.stepIds.PROPOSAL, 'proposal'),
secret: randomSecret,
},
args: [FlowCommand.ID.contract(this.stepIds.OCR_2)],
Expand Down

0 comments on commit c58e0fb

Please sign in to comment.