Skip to content

Commit

Permalink
Multisig command export and execute options (#155)
Browse files Browse the repository at this point in the history
* multisig command export and execute options

* option to provide different signer than default

* comments and improvements

* proposal check and inspection command

* fixes and improvements

* Fixed execution signer. Improvements

* Local and Ledger wallet support (#167)

* added local and ledger wallet support

* Commands inherits multiig wallet

* refactor and improvements

* More IDL wrappings and improvements

* Improved logging information

* Small improvements on msig commands

* updated serum version

* Fix object equal comparison

* improved size on msig creation

* recent blockhash from confirmed block

* naming on multisig commands

Co-authored-by: Kristijan Rebernisak <kristijan.rebernisak@gmail.com>
  • Loading branch information
RodrigoAD and krebernisak authored Feb 3, 2022
1 parent d4f1ffa commit 827c07e
Show file tree
Hide file tree
Showing 35 changed files with 951 additions and 302 deletions.
25 changes: 20 additions & 5 deletions gauntlet/packages/gauntlet-serum-multisig/src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger, BN } from '@chainlink/gauntlet-core/dist/utils'
import { logger, BN, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey, SYSVAR_RENT_PUBKEY, Keypair } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '@chainlink/gauntlet-solana-contracts'
Expand All @@ -9,8 +9,6 @@ type Input = {
threshold: number | string
}

const DEFAULT_MAXIMUM_SIZE = 200

export default class MultisigCreate extends SolanaCommand {
static id = 'create'
static category = CONTRACT_LIST.MULTISIG
Expand Down Expand Up @@ -48,17 +46,34 @@ export default class MultisigCreate extends SolanaCommand {
[multisig.publicKey.toBuffer()],
program.programId,
)
const maximumSize = this.flags.maximumSize || DEFAULT_MAXIMUM_SIZE
const maxOwners = this.flags.maxOwners || 30
const owners = input.owners.map((key) => new PublicKey(key))

// SIZE IN BYTES
const OWNER_LENGTH = 32
const EXTRA = 2
const NONCE_LENGTH = 1
const THRESHOLD_LENGTH = 8
const SEQ_LENGTH = 4

const TOTAL_TO_ALLOCATE = (OWNER_LENGTH + EXTRA) * maxOwners + THRESHOLD_LENGTH + NONCE_LENGTH + SEQ_LENGTH

const threshold = new BN(input.threshold)
await prompt(
`A new multisig will be created with threshold ${threshold.toNumber()} and owners ${owners.map((o) =>
o.toString(),
)}. Continue?`,
)

const tx = await program.rpc.createMultisig(owners, new BN(input.threshold), nonce, {
accounts: {
multisig: multisig.publicKey,
rent: SYSVAR_RENT_PUBKEY,
},
signers: [multisig],
instructions: [await program.account.multisig.createInstruction(multisig, maximumSize)],
instructions: [await program.account.multisig.createInstruction(multisig, TOTAL_TO_ALLOCATE)],
})
logger.success('New multisig created')
logger.info(`Multisig address: ${multisig.publicKey}`)
logger.info(`Multisig Signer: ${multisigSigner.toString()}`)

Expand Down
44 changes: 44 additions & 0 deletions gauntlet/packages/gauntlet-serum-multisig/src/commands/inspect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '@chainlink/gauntlet-solana-contracts'

export default class MultisigInspect extends SolanaCommand {
static id = 'multisig:inspect'
static category = CONTRACT_LIST.MULTISIG

static examples = ['yarn gauntlet-serum-multisig multisig:inspect --network=local --state=MULTISIG_ACCOUNT']

constructor(flags, args) {
super(flags, args)
this.requireFlag('state', 'Please provide multisig state address')
}

execute = async () => {
const multisig = getContract(CONTRACT_LIST.MULTISIG, '')
const program = this.loadProgram(multisig.idl, multisig.programId.toString())

const state = new PublicKey(this.flags.state)
const multisigState = await program.account.multisig.fetch(state)
const [multisigSigner] = await PublicKey.findProgramAddress([state.toBuffer()], program.programId)
const threshold = multisigState.threshold
const owners = multisigState.owners

logger.info(`Multisig Info:
- ProgramID: ${program.programId.toString()}
- Address: ${state.toString()}
- Signer: ${multisigSigner.toString()}
- Threshold: ${threshold.toString()}
- Owners: ${owners}`)

return {
responses: [
{
tx: this.wrapResponse('', state.toString()),
contract: state.toString(),
},
],
} as Result<TransactionResponse>
}
}
Loading

0 comments on commit 827c07e

Please sign in to comment.