-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0440233
commit 1819512
Showing
6 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages-ts/gauntlet-terra-contracts/src/commands/abstract/polymorphic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TerraCommand } from '@chainlink/gauntlet-terra' | ||
import { MultisigTerraCommand } from '../contracts/multisig' | ||
|
||
type COMMANDS = { | ||
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 | ||
|
||
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 | ||
} | ||
} | ||
|
2 changes: 2 additions & 0 deletions
2
packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { CreateGroup } from './group' | ||
import { CreateWallet } from './wallet' | ||
import {MultisigTerraCommand} from './multisig' | ||
|
||
export default [CreateGroup, CreateWallet] | ||
export { MultisigTerraCommand } |
54 changes: 54 additions & 0 deletions
54
packages-ts/gauntlet-terra-contracts/src/commands/contracts/multisig/multisig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// multisig.ts | ||
// | ||
// For now, propose, vote, and execute functionality are all combined into one CONTRACT:COMMAND::multisig meta-command | ||
// This is parallel to how things are implemented in Solana. The execute happens automatically as soon as the last | ||
// vote required to exceeed the threshold is cast. And the difference between propose and vote is distinguished by | ||
// whether the --proposal=PROPOSAL_HASH flag is passed. Later, we may want to split this into CONTRACT::COMMAND::propose, | ||
// CONTRACT::COMMAND::vote, and CONTRACT::COMMAND::execute. We may also want to add CONTRACT::COMMAND::close, to | ||
// abort a proposal early (before it expires), disallowing any further voting on it. | ||
|
||
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' | ||
|
||
type StringGetter = () => string | ||
|
||
abstract class MultisigTerraCommand extends TerraCommand { | ||
static category = CATEGORIES.MULTISIG | ||
|
||
commandType:any | ||
multisigOp:StringGetter | ||
|
||
command:TerraCommand | ||
multisigAddress:string | ||
multisigContract: Promise<Contract> | ||
|
||
constructor(flags, args) { | ||
super(flags, args) | ||
|
||
logger.info(`Running ${this.commandType()} in multisig mode`) | ||
this.command = new this.commandType()(flags, args) | ||
this.command.invokeMiddlewares(this.command, this.command.middlewares) | ||
this.require(!!process.env.MULTISIG_ADDRESS, 'Please set MULTISIG_ADDRESS env var') | ||
this.multisigContract = getContract(CONTRACT_LIST.MULTISIG, flags.version) | ||
this.multisigAddress = process.env.MULTISIG_ADDRESS! | ||
} | ||
|
||
execute = async (): Promise<Result<TransactionResponse>> => { | ||
if ( MultisigTerraCommand.id[1] == 'deploy' ) | ||
this.command.run() | ||
|
||
return { | ||
responses: [ | ||
{ | ||
tx: new TransactionResponse, | ||
contract: '' | ||
} | ||
] | ||
} as Result<TransactionResponse> | ||
} | ||
} | ||
|
||
export { MultisigTerraCommand } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters