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

Gauntlet Multisig - Reduce create proposal TX size #134

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion gauntlet/packages/gauntlet-serum-multisig/networks/.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
NODE_URL=http://127.0.0.1:8899
NODE_URL=http://127.0.0.1:8899

PROGRAM_ID_MULTISIG=3X4UvrX9gTxSmNmXww53W5dM5fT1Nby246hKV8Mx9LuD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these local vars?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are constant always on local environment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROGRAM_IDs yes, but MULTISIG_ADDRESS is created anew each time, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. Removing those

PROGRAM_ID_OCR2=CF13pnKGJ1WJZeEgVAtFdUi4MMndXm9hneiHs8azUaZt
PROGRAM_ID_ACCESS_CONTROLLER=2F5NEkMnCRkmahEAcQfTQcZv1xtGgrWFfjENtTwHLuKg
PROGRAM_ID_STORE=A7Jh2nb1hZHwqEofm4N8SXbKTj82rx7KUfjParQXUyMQ


MULTISIG_ADDRESS=
MULTISIG_SIGNER=
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Result } from '@chainlink/gauntlet-core'
import { TransactionResponse, SolanaCommand, RawTransaction } from '@chainlink/gauntlet-solana'
import { logger, BN } from '@chainlink/gauntlet-core/dist/utils'
import { PublicKey, SYSVAR_RENT_PUBKEY, Keypair } from '@solana/web3.js'
import { logger } from '@chainlink/gauntlet-core/dist/utils'
import { PublicKey, SYSVAR_RENT_PUBKEY, Keypair, Transaction } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '@chainlink/gauntlet-solana-contracts'
import { ProgramError, parseIdlErrors, Idl, Program } from '@project-serum/anchor'

Expand All @@ -11,7 +11,7 @@ type ProposalContext = {
proposalState: any
}

type ProposalAction = (proposal: Keypair | PublicKey, context: ProposalContext) => Promise<string>
type ProposalAction = (proposal: PublicKey, context: ProposalContext) => Promise<string>

export const wrapCommand = (command) => {
return class Multisig extends SolanaCommand {
Expand Down Expand Up @@ -60,13 +60,13 @@ export const wrapCommand = (command) => {
const rawTx = (await this.command.makeRawTransaction(multisigSigner))[0]
const isCreation = !this.flags.proposal
if (isCreation) {
const proposal = Keypair.generate()
const proposal = await this.createProposalAcount()
const result = await this.wrapAction(this.createProposal)(proposal, {
rawTx,
multisigSigner,
proposalState: {},
})
this.inspectProposalState(proposal.publicKey, threshold, owners)
this.inspectProposalState(proposal, threshold, owners)
return result
}

Expand All @@ -83,7 +83,14 @@ export const wrapCommand = (command) => {
const isAlreadyExecuted = proposalState.didExecute
if (isAlreadyExecuted) {
logger.info(`Proposal is already executed`)
return {} as Result<TransactionResponse>
return {
responses: [
{
tx: this.wrapResponse('', proposal.toString()),
contract: proposal.toString(),
},
],
}
}

if (!this.isReadyForExecution(proposalState, threshold)) {
Expand All @@ -95,44 +102,46 @@ export const wrapCommand = (command) => {
return result
}

wrapAction = (action: ProposalAction) => async (proposal: Keypair | PublicKey, context: ProposalContext) => {
try {
const tx = await action(proposal, context)
return {
responses: [
{
tx: this.wrapResponse(tx, proposal.toString()),
contract: proposal.toString(),
},
],
} as Result<TransactionResponse>
} catch (e) {
// known errors, defined in multisig contract. see serum_multisig.json
if (e.code >= 300 && e.code < 400) {
logger.error(e.msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this logging for known erros?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't doing anything. The program already logs this errors automatically

} else {
logger.error(e)
}
throw e
wrapAction = (action: ProposalAction) => async (
proposal: PublicKey,
context: ProposalContext,
): Promise<Result<TransactionResponse>> => {
const tx = await action(proposal, context)
return {
responses: [
{
tx: this.wrapResponse(tx, proposal.toString()),
contract: proposal.toString(),
},
],
}
}

createProposal: ProposalAction = async (proposal: Keypair, context): Promise<string> => {
createProposalAcount = async (): Promise<PublicKey> => {
logger.log('Creating proposal account')
const proposal = Keypair.generate()
const txSize = 1300 // Space enough
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

const proposalAccount = await this.program.account.transaction.createInstruction(proposal, txSize)
const accountTx = new Transaction().add(proposalAccount)
await this.provider.send(accountTx, [proposal, this.wallet.payer])
logger.success(`Proposal account created at: ${proposal.publicKey.toString()}`)
return proposal.publicKey
}

createProposal: ProposalAction = async (proposal: PublicKey, context): Promise<string> => {
logger.loading(`Creating proposal`)
const txSize = 1000
const tx = await this.program.rpc.createTransaction(
context.rawTx.programId,
context.rawTx.accounts,
context.rawTx.data,
{
accounts: {
multisig: this.multisigAddress,
transaction: proposal.publicKey,
transaction: proposal,
proposer: this.wallet.payer.publicKey,
rent: SYSVAR_RENT_PUBKEY,
},
instructions: [await this.program.account.transaction.createInstruction(proposal, txSize)],
signers: [proposal, this.wallet.payer],
signers: [this.wallet.payer],
},
)
return tx
Expand Down
Loading