Skip to content

Commit

Permalink
Multisig wrapper command (#111)
Browse files Browse the repository at this point in the history
* commands export data

raw tx on inspection command

* basic package and schema

* multisig command

* multisig command improvements

list some todos

* more detailed state

* execute option on multisig

* refactor
  • Loading branch information
RodrigoAD authored Feb 18, 2022
1 parent 9955298 commit ddd0db8
Show file tree
Hide file tree
Showing 17 changed files with 398 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ DEFAULT_GAS_PRICE=0.5
LINK=terra1fcksmfjncl6m7apvpalvhwv5jxd9djv5lwyu82
BILLING_ACCESS_CONTROLLER=terra1trcufj64y53hxk7g8cra33xw3jkyvlr9lu99eu
REQUESTER_ACCESS_CONTROLLER=terra1s38kfu4qp0ttwxkka9zupaysefl5qruhv5rc0z
MULTISIG_GROUP=terra168lv95kfm49y9zu0409jmplj756ukxdrew7uta
MULTISIG_WALLET=terra1u89pduw4enewduy9qydj925738cyn9juszgj54

CW4_GROUP=terra1edk45cc6rckjszfmr87qfx50pfn2mnhg5mn3vd
CW3_FLEX_MULTISIG=terra1cql0r4csmce0ntf68dmkvu3negs7m662uyg90g
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AbstractCommand, { makeAbstractCommand } from '.'
import { Result } from '@chainlink/gauntlet-core'
import { TerraCommand, TransactionResponse } from '@chainlink/gauntlet-terra'
import { AccAddress, MsgExecuteContract } from '@terra-money/terra.js'

export interface AbstractInstruction<Input, ContractInput> {
instruction: {
Expand All @@ -26,15 +27,25 @@ export const instructionToCommand = (instruction: AbstractInstruction<any, any>)
super(flags, args)
}

execute = async (): Promise<Result<TransactionResponse>> => {
buildCommand = async (): Promise<TerraCommand> => {
const commandInput = await instruction.makeInput(this.flags, this.args)
if (!instruction.validateInput(commandInput)) {
throw new Error(`Invalid input params: ${JSON.stringify(commandInput)}`)
}
const input = await instruction.makeContractInput(commandInput)
const abstractCommand = await makeAbstractCommand(id, this.flags, this.args, input)
await abstractCommand.invokeMiddlewares(abstractCommand, abstractCommand.middlewares)
let response = await abstractCommand.execute()
return abstractCommand
}

makeRawTransaction = async (signer: AccAddress): Promise<MsgExecuteContract> => {
const command = await this.buildCommand()
return command.makeRawTransaction(signer)
}

execute = async (): Promise<Result<TransactionResponse>> => {
const command = await this.buildCommand()
let response = await command.execute()
if (instruction.afterExecute) {
const data = instruction.afterExecute(response)
response = { ...response, data: { ...data } }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Result } from '@chainlink/gauntlet-core'
import { AccAddress, MsgExecuteContract } from '@terra-money/terra.js'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { TransactionResponse, TerraCommand } from '@chainlink/gauntlet-terra'
import { Contract, CONTRACT_LIST, getContract, TerraABI, TERRA_OPERATIONS } from '../../lib/contracts'
Expand Down Expand Up @@ -130,6 +131,11 @@ export default class AbstractCommand extends TerraCommand {
this.contracts = [this.opts.contract.id]
}

makeRawTransaction = async (signer: AccAddress): Promise<MsgExecuteContract> => {
const address = this.args[0]
return new MsgExecuteContract(signer, address, this.params)
}

abstractDeploy: AbstractExecute = async (params: any) => {
logger.loading(`Deploying contract ${this.opts.contract.id}`)
const codeId = this.codeIds[this.opts.contract.id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export const instructionToInspectCommand = <CommandInput, Expected>(
super(flags, args)
}

makeRawTransaction = () => {
throw new Error('Inspection command does not involve any transaction')
}

execute = async (): Promise<Result<TransactionResponse>> => {
const input = await inspectInstruction.makeInput(this.flags, this.args)
const commands = await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default class DeployLink extends TerraCommand {
super(flags, args)
}

makeRawTransaction = async () => {
throw new Error('Deploy LINK command: makeRawTransaction method not implemented')
}

execute = async () => {
await prompt(`Begin deploying LINK Token?`)
const deploy = await this.deploy(CW20_BASE_CODE_IDs[this.flags.network], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class TransferLink extends TerraCommand {
super(flags, args)
}

makeRawTransaction = async () => {
throw new Error('Transfer LINK command: makeRawTransaction method not implemented')
}

execute = async () => {
const decimals = this.flags.decimals || 18
const link = this.flags.link || process.env.LINK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default class UploadContractCode extends TerraCommand {
super(flags, args)
}

makeRawTransaction = async () => {
throw new Error('Upload command: makeRawTransaction method not implemented')
}

getCodeId(response): number | undefined {
return Number(this.parseResponseValue(response, 'store_code', 'code_id'))
}
Expand Down
3 changes: 2 additions & 1 deletion packages-ts/gauntlet-terra-contracts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { executeCLI } from '@chainlink/gauntlet-core'
import { multisigWrapCommand } from '@chainlink/gauntlet-terra-cw-plus'
import { existsSync } from 'fs'
import path from 'path'
import { io } from '@chainlink/gauntlet-core/dist/utils'
Expand All @@ -7,7 +8,7 @@ import { makeAbstractCommand } from './commands/abstract'
import { defaultFlags } from './lib/args'

const commands = {
custom: [...Terra],
custom: [...Terra, ...Terra.map(multisigWrapCommand)],
loadDefaultFlags: () => defaultFlags,
abstract: {
findPolymorphic: () => undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages-ts/gauntlet-terra-contracts/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const enum CATEGORIES {
DEVIATION_FLAGGING_VALIDATOR = 'Devaiation Flagging Validator',
}

export const DEFAULT_RELEASE_VERSION = 'v0.0.4'
export const DEFAULT_RELEASE_VERSION = 'local'
export const DEFAULT_CWPLUS_VERSION = 'v0.9.1'

export const ORACLES_MAX_LENGTH = 31
Expand Down
1 change: 1 addition & 0 deletions packages-ts/gauntlet-terra-cw-plus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Gauntlet Terra CW Plus
32 changes: 32 additions & 0 deletions packages-ts/gauntlet-terra-cw-plus/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@chainlink/gauntlet-terra-cw-plus",
"version": "0.0.1",
"description": "Gauntlet Terra CW Plus contracts",
"keywords": [
"typescript",
"cli"
],
"main": "./dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"!dist/**/*.test.js"
],
"scripts": {
"preinstall": "node ../../scripts/require-yarn.js",
"gauntlet": "ts-node ./src/index.ts",
"lint": "tsc",
"test": "SKIP_PROMPTS=true jest --runInBand",
"test:coverage": "yarn test --collectCoverage",
"test:ci": "yarn test --ci",
"lint:format": "yarn prettier --check ./src",
"format": "yarn prettier --write ./src",
"clean": "rm -rf ./dist/ ./bin/",
"build": "yarn clean && tsc",
"bundle": "yarn build && pkg ."
},
"dependencies": {
"@chainlink/gauntlet-core": "0.0.7",
"@chainlink/gauntlet-terra": "*"
}
}
Loading

0 comments on commit ddd0db8

Please sign in to comment.