-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/set access controllers (#104)
* add set access controller command to ocr2 * add set access controller command to store * quick fixes for comments, var names, etc * split set access controller commands
- Loading branch information
Showing
6 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...kages/gauntlet-solana-contracts/src/commands/contracts/ocr2/setBillingAccessController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ges/gauntlet-solana-contracts/src/commands/contracts/ocr2/setRequesterAccessController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ges/gauntlet-solana-contracts/src/commands/contracts/store/setLoweringAccessController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
} |