-
Notifications
You must be signed in to change notification settings - Fork 44
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
PROGRAM_ID_OCR2=CF13pnKGJ1WJZeEgVAtFdUi4MMndXm9hneiHs8azUaZt | ||
PROGRAM_ID_ACCESS_CONTROLLER=2F5NEkMnCRkmahEAcQfTQcZv1xtGgrWFfjENtTwHLuKg | ||
PROGRAM_ID_STORE=A7Jh2nb1hZHwqEofm4N8SXbKTj82rx7KUfjParQXUyMQ | ||
|
||
|
||
MULTISIG_ADDRESS=DgCpBtJgwpDNqKCcSxrYriVuR4CGMT1Fb8TAUn4M7tHE | ||
MULTISIG_SIGNER=CKq1fZpQpna3vxcNtKRXCjWdpwwAD3yyfeswg8fXvqtJ |
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' | ||
|
||
|
@@ -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 { | ||
|
@@ -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 | ||
} | ||
|
||
|
@@ -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)) { | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why removing this logging for known erros? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these local vars?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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