Skip to content
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

Multisig command export and execute options #155

Merged
merged 13 commits into from
Feb 3, 2022
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
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