Skip to content
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

feat: add encode data task #223

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions solidity/tasks/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AddTxParam,
SUB_CHECK_PRIVATE_KEY,
SUB_CONFIRM_TRANSACTION,
SUB_CREATE_ASSET_DATA,
SUB_CREATE_TRANSACTION,
SUB_GET_NODE_URL,
SUB_SEND_ETH,
Expand Down Expand Up @@ -106,6 +107,40 @@ task("call", "call contract, Example: npx hardhat call 0x... balanceOf(address)(
}
)

task("encode", "encode function data, Example: npx hardhat encode transfer(address,uint256) 0x... 1000000000000000000")
.addVariadicPositionalParam("params", "encode function data params", undefined, string, true)
.setAction(async (taskArgs, hre) => {
const {params} = taskArgs;
const func = params[0];
params.splice(0, 1);

if (!func) {
throw new Error("Please provide func");
}

const abi = parseAbiItemFromSignature(func)
const abiInterface = new hre.ethers.Interface([abi])

if (abi.inputs && (abi.inputs.length !== params.length)) {
throw new Error(`Please provide ${abi.inputs.length} params`)
}
const data = abiInterface.encodeFunctionData(abi.name as string, params)
console.log(data)
})

task("encode-erc20-data", "encode asset data, Example: npx hardhat encode-erc20-data 0x... 1000000000000000000")
.addParam("tokens", "", undefined, string, true)
.addParam("amounts", "", undefined, string, true)
.setAction(async (taskArgs, hre) => {
const {tokens, amounts} = taskArgs;
const asset = await hre.run(SUB_CREATE_ASSET_DATA, {
bridgeTokens: tokens,
bridgeAmounts: amounts,
assetType: "ERC20"
});
console.log(asset)
})

interface AbiItem {
name?: string;
inputs?: { name: string; type: string; }[];
Expand Down
12 changes: 12 additions & 0 deletions tests/scripts/ethereum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ function call() {
hardhat_task call "$@"
}

function bridge_erc20_call() {
hardhat_task bridge-erc20-call "$@" --mnemonic "$MNEMONIC" --disable-confirm "true"
}

function encode() {
hardhat_task encode "$@"
}

function encode_erc20_data() {
hardhat_task encode-erc20-data "$@"
}

## ARGS: <bridge-contract> <bridge-token> <amount> <destination> <target-ibc> [opts...]
function send_to_fx() {
local bridge_contract=${1} bridge_token=${2} amount=${3} destination=${4} target_ibc=${5:-""}
Expand Down
Loading