From c27ce1c8421a3e54a4a1b0f29f5a0dad690dfb50 Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Thu, 10 Feb 2022 14:57:46 -0800 Subject: [PATCH] WIP --- .../src/commands/abstract/index.ts | 15 ++++++ .../src/commands/abstract/polymorphic.ts | 51 ++++++++++--------- .../src/commands/contracts/multisig/index.ts | 2 +- .../commands/contracts/multisig/multisig.ts | 20 +++++--- .../src/commands/internal/terra.ts | 6 +-- 5 files changed, 60 insertions(+), 34 deletions(-) diff --git a/packages-ts/gauntlet-terra-contracts/src/commands/abstract/index.ts b/packages-ts/gauntlet-terra-contracts/src/commands/abstract/index.ts index 14f2939d..a6abf99b 100644 --- a/packages-ts/gauntlet-terra-contracts/src/commands/abstract/index.ts +++ b/packages-ts/gauntlet-terra-contracts/src/commands/abstract/index.ts @@ -184,6 +184,21 @@ export default class AbstractCommand extends TerraCommand { } } + // create and sign transaction, without executing + abstractPrepare = async () => { + const operations = { + [TERRA_OPERATIONS.DEPLOY]: this.opts.prepareDeploy() + [TERRA_OPERATIONS.EXECUTE]: this.opts.prepareCall() + } + return await operations[this.opts.action](address, { + [this.opts.function]: this.params, + }) +} + + const address = this.args[0] + return operations[this.opts.action](this.params, address) + } + execute = async () => { const operations = { [TERRA_OPERATIONS.DEPLOY]: this.abstractDeploy, diff --git a/packages-ts/gauntlet-terra-contracts/src/commands/abstract/polymorphic.ts b/packages-ts/gauntlet-terra-contracts/src/commands/abstract/polymorphic.ts index 8684e9a8..db7ced4e 100644 --- a/packages-ts/gauntlet-terra-contracts/src/commands/abstract/polymorphic.ts +++ b/packages-ts/gauntlet-terra-contracts/src/commands/abstract/polymorphic.ts @@ -2,31 +2,34 @@ import { TerraCommand } from '@chainlink/gauntlet-terra' import { MultisigTerraCommand } from '../contracts/multisig' type COMMANDS = { - custom:any[] + custom: any[] } -export default (commands:COMMANDS, slug:string) => { - const slugs:string[] = slug.split(':') - if (slugs.length < 3) { - return null - } - const op:string = slugs.pop()! - const command:any = commands.custom[slugs.join()] - if (!!command) return undefined +export default (commands: COMMANDS, slug: string) => { + const slugs: string[] = slug.split(':') + if (slugs.length < 3) { + return null + } + const op: string = slugs.pop()! + const command: any = commands.custom[slugs.join()] + if (!!command) return undefined - 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 { - static id = slugs.join() - multisigOp = () => { return op } - commandType = () => { return command } - } - default: - return undefined - } + 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 { + static id = slugs.join() + multisigOp = () => { + return op + } + commandType = () => { + return command + } + } + default: + return undefined + } } - diff --git a/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/index.ts b/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/index.ts index 4dd89d8b..ab5a0ca2 100644 --- a/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/index.ts +++ b/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/index.ts @@ -1,6 +1,6 @@ import { CreateGroup } from './group' import { CreateWallet } from './wallet' -import {MultisigTerraCommand} from './multisig' +import { MultisigTerraCommand } from './multisig' export default [CreateGroup, CreateWallet] export { MultisigTerraCommand } diff --git a/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/multisig.ts b/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/multisig.ts index 6641ce83..6dd10302 100644 --- a/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/multisig.ts +++ b/packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/multisig.ts @@ -11,7 +11,7 @@ import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils' import { Result } from '@chainlink/gauntlet-core' import { TerraCommand, TransactionResponse } from '@chainlink/gauntlet-terra' import { CATEGORIES } from '../../../lib/constants' -import { CONTRACT_LIST, Contract, getContract } from '../../../lib/contracts' +import { CONTRACT_LIST, Contract, getContract, TERRA_OPERATIONS } from '../../../lib/contracts' type StringGetter = () => string @@ -21,7 +21,7 @@ abstract class MultisigTerraCommand extends TerraCommand { commandType:any multisigOp:StringGetter - command:TerraCommand + command:AbstractCommand multisigAddress:string multisigContract: Promise @@ -37,14 +37,22 @@ abstract class MultisigTerraCommand extends TerraCommand { } execute = async (): Promise> => { - if ( MultisigTerraCommand.id[1] == 'deploy' ) - this.command.run() + 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() return { responses: [ { - tx: new TransactionResponse, - contract: '' + tx: tx + contract: contract } ] } as Result diff --git a/packages-ts/gauntlet-terra/src/commands/internal/terra.ts b/packages-ts/gauntlet-terra/src/commands/internal/terra.ts index 0152e2f1..0057c2eb 100644 --- a/packages-ts/gauntlet-terra/src/commands/internal/terra.ts +++ b/packages-ts/gauntlet-terra/src/commands/internal/terra.ts @@ -99,7 +99,7 @@ export default abstract class TerraCommand extends WriteCommand