-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ownership commands for every program
- Loading branch information
Showing
9 changed files
with
151 additions
and
106 deletions.
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