Skip to content

Commit

Permalink
Add WrapCommand, makeRawTransaction(), ProposalContext
Browse files Browse the repository at this point in the history
Also: fix compiler errors, workaround for gauntlet-core bug in
type declaration for findPolymorphic
  • Loading branch information
reductionista committed Feb 15, 2022
1 parent e9e2978 commit 3f8b33e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,28 @@ export default class AbstractCommand extends TerraCommand {
}

// create and sign transaction, without executing
abstractPrepare = async () => {
makeRawTransaction = async () => {
const operations = {
[TERRA_OPERATIONS.DEPLOY]: this.opts.prepareDeploy()
[TERRA_OPERATIONS.EXECUTE]: this.opts.prepareCall()
[TERRA_OPERATIONS.DEPLOY]: this.abstractPrepareDeploy,
[TERRA_OPERATIONS.EXECUTE]: this.abstractPrepareCall,
[TERRA_OPERATIONS.QUERY]: () => { throw Error("makeRawTransaction: cannot make a tx from a query commmand") },
// TODO: [TERRA_OPERATIONS.UPLOAD]: this.abstractPrepareUpload,
}
return await operations[this.opts.action](address, {
[this.opts.function]: this.params,
})

return await operations[this.opts.action](this.params, this.args[0])
}

const address = this.args[0]
return operations[this.opts.action](this.params, address)
}
abstractPrepareDeploy = async(params:any) => {
const codeId = this.codeIds[this.opts.contract.id]
this.require(!!codeId, `Code Id for contract ${this.opts.contract.id} not found`)
return await this.prepareDeploy(codeId, params)
}

abstractPrepareCall = async(params:any, address:string) => {
return await this.prepareCall(address, {
[this.opts.function]: params,
})
}

execute = async () => {
const operations = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
import { TerraCommand } from '@chainlink/gauntlet-terra'
import { TerraCommand, TransactionResponse } from '@chainlink/gauntlet-terra'
import { MultisigTerraCommand } from '../contracts/multisig'
import { Result, Command } from '@chainlink/gauntlet-core'

type COMMANDS = {
custom: any[]
class EmptyCommand extends Command {
constructor() {
super({help : false}, [])
}
}

export default (commands: COMMANDS, slug: string) => {
export default (commands: any[], slug: string) : Command => {
const slugs: string[] = slug.split(':')
if (slugs.length < 3) {
return null
throw Error(`Command ${slugs.join(':')} not found`)
}
const op: string = slugs.pop()!
const command: any = commands.custom[slugs.join()]
if (!!command) return undefined
const command: any = commands[slugs.join()]
if (!!command) throw Error(`Command ${slugs.join(':')} not found`)

switch (op) {
case 'multisig':
case 'propose':
case 'vote':
case 'execute':
case 'approve': // vote yes, then execute if threshold is reached
return class Command extends MultisigTerraCommand {
class WrappedCommand extends MultisigTerraCommand {
static id = slugs.join()

constructor(flags, args) {
super(flags, args)
}

multisigOp = () => {
return op
}
commandType = () => {
return command
}
}

let cmd = new EmptyCommand()
let wc = Object.setPrototypeOf(WrappedCommand, EmptyCommand.prototype)
wc = Object.assign(wc, cmd)
return wc
default:
return undefined
throw Error(`Command ${slugs.join(':')} not found`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@

import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { Result } from '@chainlink/gauntlet-core'
import { TerraCommand, TransactionResponse } from '@chainlink/gauntlet-terra'
import { TerraCommand, RawTransaction, TransactionResponse } from '@chainlink/gauntlet-terra'
import { CATEGORIES } from '../../../lib/constants'
import { CONTRACT_LIST, Contract, getContract, TERRA_OPERATIONS } from '../../../lib/contracts'
import AbstractCommand from '../../abstract'

type ProposalContext = {
rawTx: RawTransaction,
multisigSigner: string,
proposalState: any,
}

type StringGetter = () => string

Expand All @@ -37,26 +44,20 @@ abstract class MultisigTerraCommand extends TerraCommand {
}

execute = async (): Promise<Result<TransactionResponse>> => {
const tx =

switch ( this.command.opts.action) {
case(TERRA_OPERATIONS.deploy):
tx = this.command.prepare_deploy()
} else if () {
this.command.prepare_call()
}

const contract = getContract()
const tx = this.command.makeRawTransaction()
console.debug(tx)

return {
responses: [
{
tx: tx
contract: contract
}
]
} as Result<TransactionResponse>
responses: [],
} as Result<TransactionResponse>
}
}

export const wrapCommand = (command) => {
return class CustomCommand extends MultisigTerraCommand {
static id = `${command.id}:multisig`
static category = CATEGORIES.MULTISIG
}
}

export { MultisigTerraCommand }
2 changes: 1 addition & 1 deletion packages-ts/gauntlet-terra-contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const commands = {
custom: [...Terra],
loadDefaultFlags: () => defaultFlags,
abstract: {
findPolymorphic: () => findPolymorphic,
findPolymorphic: findPolymorphic,
makeCommand: makeAbstractCommand,
},
}
Expand Down
4 changes: 4 additions & 0 deletions packages-ts/gauntlet-terra/src/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Tx as RawTransaction } from '@terra-money/terra.js'

export type TransactionResponse = {
hash: string
address?: string
wait: () => { success: boolean }
tx?: any
}

export { RawTransaction }
4 changes: 2 additions & 2 deletions packages-ts/gauntlet-terra/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TerraCommand from './commands/internal/terra'
import { waitExecute } from './lib/execute'
import { TransactionResponse } from './commands/types'
import { RawTransaction, TransactionResponse } from './commands/types'
import * as constants from './lib/constants'

export { TerraCommand, waitExecute, TransactionResponse, constants }
export { RawTransaction, TerraCommand, waitExecute, TransactionResponse, constants }

0 comments on commit 3f8b33e

Please sign in to comment.