From 13ddea07c39415fd39eb508cb5a01557096d42a6 Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Tue, 9 Feb 2021 12:33:13 +0800 Subject: [PATCH] Add get balance task --- hardhat.config.js | 7 +++++++ src/swap-helpers.js | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hardhat.config.js b/hardhat.config.js index bffff0d..ccbd396 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -44,6 +44,13 @@ task("redeemCheque", "Redeem cheque") console.log(JSON.stringify(resp)); }); +task("getBalances", "Get ERC20 Balances for Alice and Bob") + .addParam("erc20address", "ERC20 Address") + .setAction(async taskArgs => { + var resp = await swap.getBalances(taskArgs.erc20address); + console.log(JSON.stringify(resp)); + }); + // You need to export an object to set up your config // Go to https://hardhat.org/config/ to learn more diff --git a/src/swap-helpers.js b/src/swap-helpers.js index d3a9830..4581527 100644 --- a/src/swap-helpers.js +++ b/src/swap-helpers.js @@ -151,14 +151,25 @@ async function redeemCheque(aliceSwapAddress, issuerSig) { var foo = await swapContract.cashChequeBeneficiary(recipient, cumulativePayout, issuerSig); console.log("Resp", foo); - // Reproduced error here: - // ProviderError: VM Exception while processing transaction: revert SimpleSwap: invalid issuer signature - // TODO Fix it - - return {resp: foo} + return {resp: foo}; }; +async function getBalances(erc20address) { + var erc20artifact = await artifacts.readArtifact("ERC20PresetMinterPauser"); + var signers = await ethers.getSigners(); + var aliceSigner = signers[0]; + var erc20contract = new ethers.Contract(erc20address, erc20artifact.abi, aliceSigner); + + var aliceBalance = await erc20contract.balanceOf(aliceAddress); + var bobBalance = await erc20contract.balanceOf(bobAddress); + + return {aliceBalance: aliceBalance.toNumber(), + bobBalance: bobBalance.toNumber()}; +} + + module.exports.setupSwap = setupSwap; module.exports.signCheque = signCheque; module.exports.redeemCheque = redeemCheque; +module.exports.getBalances = getBalances;