-
Notifications
You must be signed in to change notification settings - Fork 8
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
Gauntlet sec improvements #166
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1404c25
transfer ownership checks
RodrigoAD c82a472
inpect offchain config from event info
RodrigoAD 9929c89
provider in execution context. minor improvements
RodrigoAD 92d09d1
updated test
RodrigoAD e61d880
hex to base64
RodrigoAD c6b4d3e
Update guantlet e2e test to use an rdd with all non zero false values…
tateexon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
import AbstractCommand, { makeAbstractCommand } from '.' | ||
import { Result } from '@chainlink/gauntlet-core' | ||
import { TerraCommand, TransactionResponse } from '@chainlink/gauntlet-terra' | ||
import { AccAddress } from '@terra-money/terra.js' | ||
import { AccAddress, LCDClient } from '@terra-money/terra.js' | ||
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils' | ||
|
||
export type BeforeExecutionContext<Input, ContractInput> = { | ||
export type ExecutionContext<Input, ContractInput> = { | ||
input: Input | ||
contractInput: ContractInput | ||
id: string | ||
contract: string | ||
provider: LCDClient | ||
flags: any | ||
} | ||
|
||
export type BeforeExecute<Input, ContractInput> = ( | ||
context: ExecutionContext<Input, ContractInput>, | ||
) => (signer: AccAddress) => Promise<void> | ||
|
||
export interface AbstractInstruction<Input, ContractInput> { | ||
examples?: string[] | ||
instruction: { | ||
|
@@ -21,10 +27,16 @@ export interface AbstractInstruction<Input, ContractInput> { | |
makeInput: (flags: any, args: string[]) => Promise<Input> | ||
validateInput: (input: Input) => boolean | ||
makeContractInput: (input: Input) => Promise<ContractInput> | ||
beforeExecute?: (context: BeforeExecutionContext<Input, ContractInput>) => () => Promise<void> | ||
beforeExecute?: BeforeExecute<Input, ContractInput> | ||
afterExecute?: (response: Result<TransactionResponse>) => any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to also type this function, something like:
Additionally, not too fond of these |
||
} | ||
|
||
const defaultBeforeExecute = <Input, ContractInput>(context: ExecutionContext<Input, ContractInput>) => async () => { | ||
logger.loading(`Executing ${context.id} from contract ${context.contract}`) | ||
logger.log('Input Params:', context.contractInput) | ||
await prompt(`Continue?`) | ||
} | ||
|
||
export const instructionToCommand = <Input, ContractInput>(instruction: AbstractInstruction<Input, ContractInput>) => { | ||
const id = `${instruction.instruction.contract}:${instruction.instruction.function}` | ||
const category = `${instruction.instruction.category}` | ||
|
@@ -40,12 +52,6 @@ export const instructionToCommand = <Input, ContractInput>(instruction: Abstract | |
super(flags, args) | ||
} | ||
|
||
defaultBeforeExecute = (context: BeforeExecutionContext<Input, ContractInput>) => async () => { | ||
logger.loading(`Executing ${context.id} from contract ${context.contract}`) | ||
logger.log('Input Params:', context.contractInput) | ||
await prompt(`Continue?`) | ||
} | ||
|
||
afterExecute = instruction.afterExecute || this.afterExecute | ||
|
||
buildCommand = async (flags, args): Promise<TerraCommand> => { | ||
|
@@ -54,15 +60,17 @@ export const instructionToCommand = <Input, ContractInput>(instruction: Abstract | |
throw new Error(`Invalid input params: ${JSON.stringify(input)}`) | ||
} | ||
const contractInput = await instruction.makeContractInput(input) | ||
const beforeExecutionContext: BeforeExecutionContext<Input, ContractInput> = { | ||
const executionContext: ExecutionContext<Input, ContractInput> = { | ||
input, | ||
contractInput, | ||
id, | ||
contract: this.args[0], | ||
provider: this.provider, | ||
flags, | ||
} | ||
this.beforeExecute = instruction.beforeExecute | ||
? instruction.beforeExecute(beforeExecutionContext) | ||
: this.defaultBeforeExecute(beforeExecutionContext) | ||
? instruction.beforeExecute(executionContext) | ||
: defaultBeforeExecute(executionContext) | ||
|
||
const abstractCommand = await makeAbstractCommand(id, this.flags, this.args, contractInput) | ||
await abstractCommand.invokeMiddlewares(abstractCommand, abstractCommand.middlewares) | ||
|
@@ -79,7 +87,7 @@ export const instructionToCommand = <Input, ContractInput>(instruction: Abstract | |
// TODO: Command should be built from gauntet-core | ||
await this.buildCommand(this.flags, this.args) | ||
// | ||
await this.beforeExecute() | ||
await this.beforeExecute(this.wallet.key.accAddress) | ||
let response = await this.command.execute() | ||
const data = this.afterExecute(response) | ||
if (data) { | ||
|
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a function, returning a function, returning a promise?
Makes more sense for the
BeforeExecute
type to be a simple function returning a promise?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instruction command will provide the context in what the execution will happen. Then is responsibility of the command executor to actually use the hook.
IE, multisig command don't have the context of what's happening in the underlying commands, just wants to trigger the hook