Add get balance task

This commit is contained in:
Oskar Thoren 2021-02-09 12:33:13 +08:00
parent 1b615e9604
commit 13ddea07c3
2 changed files with 23 additions and 5 deletions

View File

@ -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

View File

@ -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;