Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/set access controllers #104

Merged
merged 4 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import SetOffchainConfigFlow from './offchainConfig/setOffchainConfig.flow'
import WriteOffchainConfig from './offchainConfig/write'
import PayRemaining from './payRemaining'
import ReadState from './read'
import SetBillingAccessController from './setBillingAccessController'
import SetRequesterAccessController from './setRequesterAccessController'
import SetBilling from './setBilling'
import SetConfig from './setConfig'
import SetPayees from './setPayees'
Expand All @@ -26,6 +28,8 @@ export default [
BeginOffchainConfig,
WriteOffchainConfig,
CommitOffchainConfig,
SetBillingAccessController,
SetRequesterAccessController,
// Inspection
...Inspection,
// ONLY DEV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class Initialize extends SolanaCommand {
super(flags, args)

this.requireFlag('requesterAccessController', 'Provide a --requesterAccessController flag with a valid address')
this.requireFlag('billingAccessController', 'Provide a --requesterAccessController flag with a valid address')
this.requireFlag('billingAccessController', 'Provide a --billingAccessController flag with a valid address')
}

execute = async () => {
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 SetBillingAccessController extends SolanaCommand {
static id = 'ocr2:set_billing_access_controller'
static category = CONTRACT_LIST.OCR_2

static examples = [
'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('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.billingAccessController

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 billing access controller?`)

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

logger.success(`Billing access controller set on tx ${tx}`)
return {
responses: [
{
tx: this.wrapResponse(tx, state.toString()),
contract: state.toString(),
},
],
} as Result<TransactionResponse>
}
}
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>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@ import SetValidatorConfig from './setValidatorConfig'
import SetWriter from './setWriter'
import TransferOwnership from './transferOwnership'
import AcceptOwnership from './acceptOwnership'
import SetLoweringAccessController from './setLoweringAccessController'

export default [Initialize, CreateFeed, SetValidatorConfig, SetWriter, TransferOwnership, AcceptOwnership]
export default [
Initialize,
CreateFeed,
SetValidatorConfig,
SetWriter,
TransferOwnership,
AcceptOwnership,
SetLoweringAccessController,
]
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 SetLoweringAccessController extends SolanaCommand {
static id = 'store:set_lowering_access_controller'
static category = CONTRACT_LIST.STORE

static examples = [
'yarn gauntlet store:set_lowering_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 store = getContract(CONTRACT_LIST.STORE, '')
const address = store.programId.toString()
const program = this.loadProgram(store.idl, address)

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

const info = await program.account.store.fetch(state)
const oldAC = info.loweringAccessController

logger.log(`Access controller information:
- Store 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 lowering access controller?`)

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

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