Skip to content

Commit

Permalink
split set access controller commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Jan 14, 2022
1 parent 8c79d34 commit 3193ff3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import SetOffchainConfigFlow from './offchainConfig/setOffchainConfig.flow'
import WriteOffchainConfig from './offchainConfig/write'
import PayRemaining from './payRemaining'
import ReadState from './read'
import SetAccessController from './setAccessController'
import SetBillingAccessController from './setBillingAccessController'
import SetRequesterAccessController from './setRequesterAccessController'
import SetBilling from './setBilling'
import SetConfig from './setConfig'
import SetPayees from './setPayees'
Expand All @@ -27,7 +28,8 @@ export default [
BeginOffchainConfig,
WriteOffchainConfig,
CommitOffchainConfig,
SetAccessController,
SetBillingAccessController,
SetRequesterAccessController,
// Inspection
...Inspection,
// ONLY DEV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'

export default class SetAccessController extends SolanaCommand {
static id = 'ocr2:set_access_controller'
export default class SetBillingAccessController extends SolanaCommand {
static id = 'ocr2:set_billing_access_controller'
static category = CONTRACT_LIST.OCR_2

static examples = [
'yarn gauntlet ocr2:set_access_controller --network=local --state=[STATE_ACC] --type=[AC_TYPE] --accessController=[AC_ACC]',
'yarn gauntlet ocr2:set_billing_access_controller --network=local --state=[STATE_ACC] --accessController=[AC_ACC]',
]

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

this.requireFlag('state', 'Provide a valid state address')
this.requireFlag('type', 'Provide type of access controller to set')
this.requireFlag('accessController', 'Provide a valid access controller address')
}

Expand All @@ -25,29 +24,22 @@ export default class SetAccessController extends SolanaCommand {
const address = ocr2.programId.toString()
const program = this.loadProgram(ocr2.idl, address)

this.require(this.flags.type === 'billing' || this.flags.type === 'requester', 'Invalid access controller type')

const acType = this.flags.type
const state = new PublicKey(this.flags.state)
const ac = new PublicKey(this.flags.accessController)

const info = await program.account.state.fetch(state)
const oldAC = acType === 'billing' ? info.config.billingAccessController : info.config.requesterAccessController
const oldAC = info.config.billingAccessController

logger.log(`Access controller information:
- OCR State: ${state.toString()}
- Old AC: ${oldAC}
- New AC: ${ac.toString()}
- Type: ${acType}
`)

this.require(oldAC.toString() !== ac.toString(), 'New access controller is the same as existing access controller')
await prompt(`Continue setting ${this.flags.type} access controller?`)

const setACCommand =
acType === 'billing' ? program.rpc.setBillingAccessController : program.rpc.setRequesterAccessController
await prompt(`Continue setting billing access controller?`)

const tx = await setACCommand({
const tx = await program.rpc.setBillingAccessController({
accounts: {
state: state,
authority: this.wallet.payer.publicKey,
Expand All @@ -56,7 +48,7 @@ export default class SetAccessController extends SolanaCommand {
signers: [this.wallet.payer],
})

logger.success(`Access controller set on tx ${tx}`)
logger.success(`Billing access controller set on tx ${tx}`)
return {
responses: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 SetRequesterAccessController extends SolanaCommand {
static id = 'ocr2:set_requester_access_controller'
static category = CONTRACT_LIST.OCR_2

static examples = [
'yarn gauntlet ocr2:set_requester_access_controller --network=local --state=[STATE_ACC] --accessController=[AC_ACC]',
]

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

this.requireFlag('state', 'Provide a valid state address')
this.requireFlag('accessController', 'Provide a valid access controller address')
}

execute = async () => {
const ocr2 = getContract(CONTRACT_LIST.OCR_2, '')
const address = ocr2.programId.toString()
const program = this.loadProgram(ocr2.idl, address)

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

const info = await program.account.state.fetch(state)
const oldAC = info.config.requesterAccessController

logger.log(`Access controller information:
- OCR State: ${state.toString()}
- Old AC: ${oldAC}
- New AC: ${ac.toString()}
`)

this.require(oldAC.toString() !== ac.toString(), 'New access controller is the same as existing access controller')
await prompt(`Continue setting requester access controller?`)

const tx = await program.rpc.setRequesterAccessController({
accounts: {
state: state,
authority: this.wallet.payer.publicKey,
accessController: ac,
},
signers: [this.wallet.payer],
})

logger.success(`Requester access controller set on tx ${tx}`)
return {
responses: [
{
tx: this.wrapResponse(tx, state.toString()),
contract: state.toString(),
},
],
} as Result<TransactionResponse>
}
}

0 comments on commit 3193ff3

Please sign in to comment.