-
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.
Token commands + Improvements (#157)
* added balance diff in inspection * transfer token and send uluna commands * added mainnet ids * refactor before execution * refactor and improvements * fix rebase * Gauntlet sec improvements (#166) * transfer ownership checks * inpect offchain config from event info * provider in execution context. minor improvements * updated test * hex to base64 * Update guantlet e2e test to use an rdd with all non zero false values so the inspect command can check all values have changed No longer use the digest in the test as it is not needed Co-authored-by: Tate <[email protected]> * added cw20 code id and more validations * small refactor Co-authored-by: Tate <[email protected]>
- Loading branch information
Showing
29 changed files
with
543 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"access_controller": 2690, | ||
"ocr2": 3024, | ||
"proxy_ocr2": 3202, | ||
"cw3_flex_multisig": 3192, | ||
"cw4_group": 3193, | ||
"cw20_base": 3 | ||
} |
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
86 changes: 49 additions & 37 deletions
86
packages-ts/gauntlet-terra-contracts/src/commands/contracts/link/transfer.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,46 +1,58 @@ | ||
import { TerraCommand, TransactionResponse } from '@chainlink/gauntlet-terra' | ||
import { Result } from '@chainlink/gauntlet-core' | ||
import { BN, logger, prompt } from '@chainlink/gauntlet-core/dist/utils' | ||
import { CATEGORIES } from '../../../lib/constants' | ||
import { CATEGORIES, TOKEN_DECIMALS } from '../../../lib/constants' | ||
import { AbstractInstruction, ExecutionContext, instructionToCommand } from '../../abstract/executionWrapper' | ||
import { AccAddress } from '@terra-money/terra.js' | ||
|
||
export default class TransferLink extends TerraCommand { | ||
static description = 'Transfer LINK' | ||
static examples = [ | ||
`yarn gauntlet token:transfer --network=bombay-testnet --to=[RECEIVER] --amount=[AMOUNT_IN_TOKEN_UNITS]`, | ||
`yarn gauntlet token:transfer --network=bombay-testnet --to=[RECEIVER] --amount=[AMOUNT_IN_TOKEN_UNITS] --link=[TOKEN_ADDRESS] --decimals=[TOKEN_DECIMALS]`, | ||
] | ||
type CommandInput = { | ||
to: string | ||
// Units in LINK | ||
amount: string | ||
} | ||
|
||
static id = 'token:transfer' | ||
static category = CATEGORIES.LINK | ||
type ContractInput = { | ||
recipient: string | ||
amount: string | ||
} | ||
|
||
constructor(flags, args: string[]) { | ||
super(flags, args) | ||
const makeCommandInput = async (flags: any): Promise<CommandInput> => { | ||
if (flags.input) return flags.input as CommandInput | ||
return { | ||
to: flags.to, | ||
amount: flags.amount, | ||
} | ||
} | ||
|
||
makeRawTransaction = async () => { | ||
throw new Error('Transfer LINK command: makeRawTransaction method not implemented') | ||
} | ||
const validateInput = (input: CommandInput): boolean => { | ||
if (!AccAddress.validate(input.to)) throw new Error(`Invalid destination address`) | ||
if (isNaN(Number(input.amount))) throw new Error(`Amount ${input.amount} is not a number`) | ||
return true | ||
} | ||
|
||
execute = async () => { | ||
const decimals = this.flags.decimals || 18 | ||
const link = this.flags.link || process.env.LINK | ||
const amount = new BN(this.flags.amount).mul(new BN(10).pow(new BN(decimals))) | ||
|
||
await prompt(`Sending ${this.flags.amount} LINK (${amount.toString()}) to ${this.flags.to}. Continue?`) | ||
const tx = await this.call(link, { | ||
transfer: { | ||
recipient: this.flags.to, | ||
amount: amount.toString(), | ||
}, | ||
}) | ||
logger.success(`LINK transferred successfully to ${this.flags.to} (txhash: ${tx.hash})`) | ||
return { | ||
responses: [ | ||
{ | ||
tx, | ||
contract: link, | ||
}, | ||
], | ||
} as Result<TransactionResponse> | ||
const makeContractInput = async (input: CommandInput): Promise<ContractInput> => { | ||
const amount = new BN(input.amount).mul(new BN(10).pow(new BN(TOKEN_DECIMALS))) | ||
return { | ||
recipient: input.to, | ||
amount: amount.toString(), | ||
} | ||
} | ||
|
||
const beforeExecute = (context: ExecutionContext<CommandInput, ContractInput>) => async (): Promise<void> => { | ||
logger.info( | ||
`Transferring ${context.contractInput.amount} (${context.input.amount}) Tokens to ${context.contractInput.recipient}`, | ||
) | ||
await prompt('Continue?') | ||
} | ||
|
||
const transferToken: AbstractInstruction<CommandInput, ContractInput> = { | ||
instruction: { | ||
category: CATEGORIES.LINK, | ||
contract: 'cw20_base', | ||
function: 'transfer', | ||
}, | ||
makeInput: makeCommandInput, | ||
validateInput: validateInput, | ||
makeContractInput: makeContractInput, | ||
beforeExecute, | ||
} | ||
|
||
export default instructionToCommand(transferToken) |
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.