Skip to content

Commit

Permalink
fix tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Sep 12, 2023
1 parent 7326c39 commit 62562dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions omnichain/staking/lib/convertToHexAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ethers } from "ethers";

export const convertToHexAddress = (address: string): string => {
let addr: string;
try {
// Check if it's a valid hex address
addr = ethers.utils.getAddress(address);
} catch (e) {
// If not, try to convert it to an address from bech32
addr = ("0x" + Buffer.from(address).toString("hex")).slice(0, 42);
}
return addr;
};
6 changes: 5 additions & 1 deletion omnichain/staking/tasks/claim.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { convertToHexAddress } from "../lib/convertToHexAddress";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
console.log(`🔑 Using account: ${signer.address}\n`);

const staker = convertToHexAddress(args.staker);
console.log(staker);

const factory = await hre.ethers.getContractFactory("Staking");
const contract = factory.attach(args.contract);

const tx = await contract.claimRewards(args.staker);
const tx = await contract.claimRewards(staker);

const receipt = await tx.wait();

Expand Down
5 changes: 4 additions & 1 deletion omnichain/staking/tasks/rewards.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { task } from "hardhat/config";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { convertToHexAddress } from "../lib/convertToHexAddress";

const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
const [signer] = await hre.ethers.getSigners();
console.log(`🔑 Using account: ${signer.address}\n`);

const staker = convertToHexAddress(args.staker);

const factory = await hre.ethers.getContractFactory("Staking");
const contract = factory.attach(args.contract);

console.log(await contract.queryRewards(args.staker));
console.log(await contract.queryRewards(staker));
};

task("rewards", "Query staking rewards", main)
Expand Down

0 comments on commit 62562dc

Please sign in to comment.