-
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.
* accept and transfer ownership commands store * fixes
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
gauntlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/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,49 @@ | ||
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 AcceptOwnership extends SolanaCommand { | ||
static id = 'store:accept_ownership' | ||
static category = CONTRACT_LIST.STORE | ||
|
||
static examples = ['yarn gauntlet store:accept_ownership --network=devnet --state=[STORE_STATE]'] | ||
|
||
constructor(flags, args) { | ||
super(flags, args) | ||
|
||
this.require(!!this.flags.state, 'Please provide flags with "state"') | ||
} | ||
|
||
execute = async () => { | ||
const store = getContract(CONTRACT_LIST.STORE, '') | ||
const storeAddress = store.programId.toString() | ||
const storeProgram = this.loadProgram(store.idl, storeAddress) | ||
|
||
const owner = this.wallet.payer | ||
|
||
const storeState = new PublicKey(this.flags.state) | ||
|
||
await prompt(`Accepting ownership of store state (${storeState.toString()}). Continue?`) | ||
|
||
const tx = await storeProgram.rpc.acceptOwnership({ | ||
accounts: { | ||
store: storeState, | ||
authority: owner.publicKey, | ||
}, | ||
signers: [owner], | ||
}) | ||
|
||
logger.success(`Accepted ownership on tx ${tx}`) | ||
|
||
return { | ||
responses: [ | ||
{ | ||
tx: this.wrapResponse(tx, storeState.toString(), { state: storeState.toString() }), | ||
contract: storeState.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
53 changes: 53 additions & 0 deletions
53
...tlet/packages/gauntlet-solana-contracts/src/commands/contracts/store/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,53 @@ | ||
import { Result } from '@chainlink/gauntlet-core' | ||
import { 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 TransferWwnership extends SolanaCommand { | ||
static id = 'store:transfer_ownership' | ||
static category = CONTRACT_LIST.STORE | ||
|
||
static examples = [ | ||
'yarn gauntlet store:transfer_ownership --network=devnet --state=[STORE_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 store = getContract(CONTRACT_LIST.STORE, '') | ||
const storeAddress = store.programId.toString() | ||
const storeProgram = this.loadProgram(store.idl, storeAddress) | ||
|
||
const owner = this.wallet.payer | ||
|
||
const storeState = new PublicKey(this.flags.state) | ||
const proposedOwner = new PublicKey(this.flags.to) | ||
|
||
await prompt( | ||
`Transfering ownership of store state (${storeState.toString()}) to: (${proposedOwner.toString()}). Continue?`, | ||
) | ||
|
||
const tx = await storeProgram.rpc.transferOwnership(proposedOwner, { | ||
accounts: { | ||
store: storeState, | ||
authority: owner.publicKey, | ||
}, | ||
signers: [owner], | ||
}) | ||
|
||
return { | ||
responses: [ | ||
{ | ||
tx: this.wrapResponse(tx, storeState.toString(), { state: storeState.toString() }), | ||
contract: storeState.toString(), | ||
}, | ||
], | ||
} as Result<TransactionResponse> | ||
} | ||
} |