-
Notifications
You must be signed in to change notification settings - Fork 43
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
Ownership commands for every program #106
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 10 additions & 1 deletion
11
gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/accessController/index.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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import Initialize from './initialize' | ||
import AddAccess from './addAccess' | ||
import ReadState from './read' | ||
import { makeAcceptOwnershipCommand } from '../ownership/acceptOwnership' | ||
import { makeTransferOwnershipCommand } from '../ownership/transferOwnership' | ||
import { CONTRACT_LIST } from '../../../lib/contracts' | ||
|
||
export default [Initialize, AddAccess, ReadState] | ||
export default [ | ||
Initialize, | ||
AddAccess, | ||
ReadState, | ||
makeAcceptOwnershipCommand(CONTRACT_LIST.ACCESS_CONTROLLER), | ||
makeTransferOwnershipCommand(CONTRACT_LIST.ACCESS_CONTROLLER), | ||
] |
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
54 changes: 54 additions & 0 deletions
54
...et/packages/gauntlet-solana-contracts/src/commands/contracts/ownership/acceptOwnership.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,54 @@ | ||
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 { SolanaConstructor } from '../../../lib/types' | ||
|
||
export const makeAcceptOwnershipCommand = (contractId: CONTRACT_LIST): SolanaConstructor => { | ||
return class AcceptOwnership extends SolanaCommand { | ||
static id = `${contractId}:accept_ownership` | ||
static category = contractId | ||
|
||
static examples = [`yarn gauntlet ${contractId}:accept_ownership --network=devnet --state=[PROGRAM_STATE]`] | ||
|
||
constructor(flags, args) { | ||
super(flags, args) | ||
|
||
this.require(!!this.flags.state, 'Please provide flags with "state"') | ||
} | ||
|
||
execute = async () => { | ||
const contract = getContract(contractId, '') | ||
const address = contract.programId.toString() | ||
const program = this.loadProgram(contract.idl, address) | ||
|
||
const owner = this.wallet.payer | ||
|
||
const state = new PublicKey(this.flags.state) | ||
|
||
await prompt(`Accepting ownership of ${contractId} state (${state.toString()}). Continue?`) | ||
|
||
const tx = await program.rpc.acceptOwnership({ | ||
accounts: { | ||
// Store contract expects an store account instead of a state acc | ||
...(contractId === CONTRACT_LIST.STORE && { store: state }), | ||
...(contractId !== CONTRACT_LIST.STORE && { state }), | ||
authority: owner.publicKey, | ||
}, | ||
signers: [owner], | ||
}) | ||
|
||
logger.success(`Accepted ownership on tx ${tx}`) | ||
|
||
return { | ||
responses: [ | ||
{ | ||
tx: this.wrapResponse(tx, state.toString(), { state: state.toString() }), | ||
contract: state.toString(), | ||
}, | ||
], | ||
} as Result<TransactionResponse> | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/ownership/index.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,7 @@ | ||
import { makeTransferOwnershipCommand } from './transferOwnership' | ||
import { makeAcceptOwnershipCommand } from './acceptOwnership' | ||
|
||
export default { | ||
makeTransferOwnershipCommand, | ||
makeAcceptOwnershipCommand, | ||
} |
60 changes: 60 additions & 0 deletions
60
.../packages/gauntlet-solana-contracts/src/commands/contracts/ownership/transferOwnership.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,60 @@ | ||
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 { SolanaConstructor } from '../../../lib/types' | ||
|
||
export const makeTransferOwnershipCommand = (contractId: CONTRACT_LIST): SolanaConstructor => { | ||
return class TransferOwnership extends SolanaCommand { | ||
static id = `${contractId}:transfer_ownership` | ||
static category = contractId | ||
|
||
static examples = [ | ||
`yarn gauntlet ${contractId}:transfer_ownership --network=devnet --state=[PROGRAM_STATE] --to=[PROPOSED_OWNER]`, | ||
] | ||
|
||
constructor(flags, args) { | ||
super(flags, args) | ||
|
||
this.require(!!this.flags.state, 'Please provide flags with "state"') | ||
this.require(!!this.flags.to, 'Please provide flags with "to"') | ||
} | ||
|
||
execute = async () => { | ||
const contract = getContract(contractId, '') | ||
const address = contract.programId.toString() | ||
const program = this.loadProgram(contract.idl, address) | ||
|
||
const owner = this.wallet.payer | ||
|
||
const state = new PublicKey(this.flags.state) | ||
const proposedOwner = new PublicKey(this.flags.to) | ||
|
||
await prompt( | ||
`Transfering ownership of ${contractId} state (${state.toString()}) to: (${proposedOwner.toString()}). Continue?`, | ||
) | ||
|
||
const tx = await program.rpc.transferOwnership(proposedOwner, { | ||
accounts: { | ||
// Store contract expects an store account instead of a state acc | ||
...(contractId === CONTRACT_LIST.STORE && { store: state }), | ||
...(contractId !== CONTRACT_LIST.STORE && { state }), | ||
authority: owner.publicKey, | ||
}, | ||
signers: [owner], | ||
}) | ||
|
||
logger.success(`Ownership transferred to ${proposedOwner.toString()} on tx ${tx}`) | ||
|
||
return { | ||
responses: [ | ||
{ | ||
tx: this.wrapResponse(tx, state.toString(), { state: state.toString() }), | ||
contract: state.toString(), | ||
}, | ||
], | ||
} as Result<TransactionResponse> | ||
} | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/acceptOwnership.ts
This file was deleted.
Oops, something went wrong.
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
53 changes: 0 additions & 53 deletions
53
...tlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/transferOwnership.ts
This file was deleted.
Oops, something went wrong.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@archseer Seems like the store contract expects a different account name than the rest. Should we have same interface on every program?
(https://github.com/smartcontractkit/chainlink-solana/blob/develop/contracts/programs/store/src/lib.rs#L133)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we could do that, I kept the name different initially since there were some calls where both
store
and ocr2state
had to be passed but in that case it's probably better to usestore_state
/ocr2_state
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#113