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 support #37

Merged
merged 37 commits into from
Jan 14, 2022
Merged

Multisig support #37

merged 37 commits into from
Jan 14, 2022

Conversation

ebarakos
Copy link
Contributor

@ebarakos ebarakos commented Dec 15, 2021

@ebarakos ebarakos changed the title Create multisig command Multisig support Dec 15, 2021
@ebarakos ebarakos mentioned this pull request Dec 16, 2021
@@ -37,36 +39,90 @@ export default class SetBilling extends SolanaCommand {
this.requireFlag('state', 'Provide a valid state address')
}

execute = async () => {
makeRawTransaction = async (): Promise<SolanaRawTransaction> => {
Copy link
Member

@RodrigoAD RodrigoAD Dec 20, 2021

Choose a reason for hiding this comment

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

This probably should return a set of txs. There could be cases where many tx are needed to perform the operation (see writeOffchainConfig)

Base automatically changed from feature/relay to master December 21, 2021 18:37
@RodrigoAD RodrigoAD force-pushed the multisig branch 2 times, most recently from 7f8c0fa to 607762e Compare December 21, 2021 19:35
@RodrigoAD RodrigoAD changed the base branch from master to develop December 21, 2021 19:38
@ebarakos ebarakos marked this pull request as ready for review January 10, 2022 09:51

this.program = this.loadProgram(this.multisig.idl, this.address)
const txResults = []
if (!this.flags.tx) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should stick to the 3 steps: create, approve and execute, and perform just one action per execution.

  • Create: Should create the tx proposal, and outputs the the tx public key for future actions.
  • Approve: Approves (we can use the --approve flag) the proposal created before. We should provide the tx public key with the proposal flag (--proposal)
  • Executes: Executes the proposal, if the approval is ready

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the single --proposal flag flow as discussed.

@ebarakos ebarakos marked this pull request as ready for review January 12, 2022 13:45
@ebarakos
Copy link
Contributor Author

Current flow:

Run the command using gauntlet-serum-multisig instead of gauntlet. e.g yarn gauntlet-serum-multisig ocr2:set_billing --network=local --state=2RvzKkWPmaBNUHC8k9ffjo2vmbqUd6uPw77TnjuuswpN

Creation, approval, execution happens automatically if the proposal is eligible. If not, user is prompted to add a --proposal flag for the rest of the owners, to approve/execute it.

Copy link
Member

@RodrigoAD RodrigoAD left a comment

Choose a reason for hiding this comment

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

It looks so much better! Just needs some final changes

Comment on lines 13 to 17
proposal: PublicKey
multisigAddress: PublicKey
multisigSigner: PublicKey
owners: [PublicKey]
threshold: number
Copy link
Member

Choose a reason for hiding this comment

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

Let's try to reduce the amount of context variables. I'd only leave command, program and multisigAddress

Comment on lines 30 to 31
this.require(process.env.MULTISIG_ADDRESS != null, 'Please set MULTISIG_ADDRESS env var')
this.multisigAddress = new PublicKey(process.env.MULTISIG_ADDRESS || '')
Copy link
Member

Choose a reason for hiding this comment

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

Move this into the constructor.

Suggested change
this.require(process.env.MULTISIG_ADDRESS != null, 'Please set MULTISIG_ADDRESS env var')
this.multisigAddress = new PublicKey(process.env.MULTISIG_ADDRESS || '')
this.require(!!process.env.MULTISIG_ADDRESS, 'Please set MULTISIG_ADDRESS env var')
this.multisigAddress = new PublicKey(process.env.MULTISIG_ADDRESS)

this.multisigAddress = new PublicKey(process.env.MULTISIG_ADDRESS || '')
const multisig = getContract(CONTRACT_LIST.MULTISIG, '')
this.program = this.loadProgram(multisig.idl, multisig.programId.toString())
logger.info(`Multisig Address: ${process.env.MULTISIG_ADDRESS}`)
Copy link
Member

Choose a reason for hiding this comment

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

We should already have defined this.multisigAddress here, no need to use process.env.MULTISIG_ADDRESS

Comment on lines 72 to 74
wrapAction = async (action) => {
try {
const tx = await action
Copy link
Member

Choose a reason for hiding this comment

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

action seems like it's being executed already. Try to wrap the function first, then add the args you want for this new fn

Suggested change
wrapAction = async (action) => {
try {
const tx = await action
type ProposalAction = (rawTx: RawTransaction) => Promise<string>
...
wrapAction = (proposalAction: ProposalAction) => (rawTx: RawTransaction) {
try {
const tx = await proposalAction(rawTx)

You would consume it like:

this.wrapAction(this.createProposal)(rawTxs[0])

wrapAction = async (action) => {
try {
const tx = await action
this.inspectProposalState(this.flags.proposal)
Copy link
Member

@RodrigoAD RodrigoAD Jan 14, 2022

Choose a reason for hiding this comment

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

You should not use this.flags.proposal here anymore. There should be already a validated proposal, that we receive as an argument

const tx = await this.program.rpc.createTransaction(rawTx.programId, rawTx.accounts, rawTx.data, {
accounts: {
multisig: this.multisigAddress,
transaction: this.flags.proposal,
Copy link
Member

Choose a reason for hiding this comment

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

Same here, no flags here anymore

const tx = await this.program.rpc.approve({
accounts: {
multisig: this.multisigAddress,
transaction: this.flags.proposal,
Copy link
Member

Choose a reason for hiding this comment

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

Same here

return tx
}

remainingApprovalsNeeded = (proposalState, threshold: number): number => {
Copy link
Member

Choose a reason for hiding this comment

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

This fn should return already a boolean indicating if it is ready for execution

Comment on lines 40 to 43
this.require(!!process.env.MULTISIG_ADDRESS, 'Please set MULTISIG_ADDRESS env var')
this.multisigAddress = new PublicKey(process.env.MULTISIG_ADDRESS)
const multisig = getContract(CONTRACT_LIST.MULTISIG, '')
this.program = this.loadProgram(multisig.idl, multisig.programId.toString())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RodrigoAD I had to move these in execute() again because I was getting errors.

const input = this.makeInput(this.flags.input)

const input = this.makeInput(
({
Copy link
Member

Choose a reason for hiding this comment

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

Forgot to remove this. It should be: const input = this.makeInput(this.flags.input)

@ebarakos ebarakos merged commit 6ca7765 into develop Jan 14, 2022
@ebarakos ebarakos deleted the multisig branch January 14, 2022 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants