mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 12:26:19 +00:00
Tasks in erc20-watcher to deploy and transfer tokens. (#233)
Co-authored-by: nabarun <nabarun@deepstacksoft.com>
This commit is contained in:
parent
8fa6229562
commit
cf0713eda7
6
packages/erc20-watcher/.gitignore
vendored
6
packages/erc20-watcher/.gitignore
vendored
@ -3,4 +3,8 @@
|
||||
node_modules/
|
||||
build/
|
||||
tmp/
|
||||
temp/
|
||||
temp/
|
||||
|
||||
#Hardhat files
|
||||
cache
|
||||
artifacts
|
||||
|
27
packages/erc20-watcher/hardhat.config.ts
Normal file
27
packages/erc20-watcher/hardhat.config.ts
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright 2021 Vulcanize, Inc.
|
||||
//
|
||||
|
||||
import '@nomiclabs/hardhat-waffle';
|
||||
|
||||
import './test/tasks/token-deploy';
|
||||
import './test/tasks/token-transfer';
|
||||
import './test/tasks/block-latest';
|
||||
|
||||
// You need to export an object to set up your config
|
||||
// Go to https://hardhat.org/config/ to learn more
|
||||
|
||||
/**
|
||||
* @type import('hardhat/config').HardhatUserConfig
|
||||
*/
|
||||
export default {
|
||||
solidity: '0.8.0',
|
||||
networks: {
|
||||
docker: {
|
||||
url: 'http://dapptools:8545'
|
||||
}
|
||||
},
|
||||
paths: {
|
||||
sources: './test/contracts'
|
||||
}
|
||||
};
|
@ -10,7 +10,13 @@
|
||||
"test": "mocha -r ts-node/register src/**/*.spec.ts",
|
||||
"lint": "eslint .",
|
||||
"build": "tsc",
|
||||
"watch:contract": "ts-node src/cli/watch-contract.ts --configFile environments/local.toml"
|
||||
"watch:contract": "ts-node src/cli/watch-contract.ts --configFile environments/local.toml",
|
||||
"token:deploy": "hardhat --network localhost token-deploy",
|
||||
"token:deploy:docker": "hardhat --network docker token-deploy",
|
||||
"token:transfer": "hardhat --network localhost token-transfer",
|
||||
"token:transfer:docker": "hardhat --network docker token-transfer",
|
||||
"block:latest": "hardhat --network localhost block-latest",
|
||||
"block:latest:docker": "hardhat --network docker block-latest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -50,6 +56,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ethersproject/abi": "^5.3.0",
|
||||
"@openzeppelin/contracts": "^4.3.1",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/fs-extra": "^9.0.11",
|
||||
"@types/json-bigint": "^1.0.0",
|
||||
|
10
packages/erc20-watcher/test/contracts/GLDToken.sol
Normal file
10
packages/erc20-watcher/test/contracts/GLDToken.sol
Normal file
@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract GLDToken is ERC20 {
|
||||
constructor(uint256 initialSupply) ERC20("Gold", "GLD") {
|
||||
_mint(msg.sender, initialSupply);
|
||||
}
|
||||
}
|
18
packages/erc20-watcher/test/tasks/block-latest.ts
Normal file
18
packages/erc20-watcher/test/tasks/block-latest.ts
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright 2021 Vulcanize, Inc.
|
||||
//
|
||||
|
||||
import { task } from 'hardhat/config';
|
||||
import '@nomiclabs/hardhat-ethers';
|
||||
|
||||
task(
|
||||
'block-latest',
|
||||
'Prints the current block info',
|
||||
async (_, { ethers }) => {
|
||||
const blockNumber = await ethers.provider.getBlockNumber();
|
||||
const block = await ethers.provider.getBlock(blockNumber);
|
||||
|
||||
console.log('Block Number:', blockNumber);
|
||||
console.log('Block Hash:', block.hash);
|
||||
}
|
||||
);
|
19
packages/erc20-watcher/test/tasks/token-deploy.ts
Normal file
19
packages/erc20-watcher/test/tasks/token-deploy.ts
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright 2021 Vulcanize, Inc.
|
||||
//
|
||||
|
||||
import { task, types } from 'hardhat/config';
|
||||
import '@nomiclabs/hardhat-ethers';
|
||||
|
||||
const DEFAULT_INITIAL_SUPPLY = '1000000000000000000000';
|
||||
|
||||
task('token-deploy', 'Deploys GLD token')
|
||||
.addOptionalParam('initialSupply', 'Set total supply', DEFAULT_INITIAL_SUPPLY, types.string)
|
||||
.setAction(async (args, hre) => {
|
||||
const { initialSupply } = args;
|
||||
await hre.run('compile');
|
||||
const Token = await hre.ethers.getContractFactory('GLDToken');
|
||||
const token = await Token.deploy(hre.ethers.BigNumber.from(initialSupply));
|
||||
|
||||
console.log('GLD Token deployed to:', token.address);
|
||||
});
|
33
packages/erc20-watcher/test/tasks/token-transfer.ts
Normal file
33
packages/erc20-watcher/test/tasks/token-transfer.ts
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// Copyright 2021 Vulcanize, Inc.
|
||||
//
|
||||
|
||||
import { task, types } from 'hardhat/config';
|
||||
import '@nomiclabs/hardhat-ethers';
|
||||
import { ContractTransaction } from 'ethers';
|
||||
|
||||
task('token-transfer', 'Move tokens to recipient')
|
||||
.addParam('token', 'Token contract address', undefined, types.string)
|
||||
.addParam('to', 'Transfer recipient address', undefined, types.string)
|
||||
.addParam('amount', 'Token amount to transfer', undefined, types.int)
|
||||
.setAction(async (args, hre) => {
|
||||
const { token: tokenAddress, to, amount } = args;
|
||||
await hre.run('compile');
|
||||
const Token = await hre.ethers.getContractFactory('GLDToken');
|
||||
const token = Token.attach(tokenAddress);
|
||||
|
||||
const transaction: ContractTransaction = await token.transfer(to, amount);
|
||||
|
||||
const receipt = await transaction.wait();
|
||||
|
||||
if (receipt.events) {
|
||||
const TransferEvent = receipt.events.find(el => el.event === 'Transfer');
|
||||
|
||||
if (TransferEvent && TransferEvent.args) {
|
||||
console.log('Transfer Event');
|
||||
console.log('from:', TransferEvent.args.from.toString());
|
||||
console.log('to:', TransferEvent.args.to.toString());
|
||||
console.log('value:', TransferEvent.args.value.toString());
|
||||
}
|
||||
}
|
||||
});
|
@ -73,5 +73,6 @@
|
||||
"resolveJsonModule": true /* Enabling the option allows importing JSON, and validating the types in that JSON file. */
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["dist"]
|
||||
"exclude": ["dist"],
|
||||
"files": ["./hardhat.config.ts"]
|
||||
}
|
||||
|
@ -1895,6 +1895,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-3.4.1-solc-0.7-2.tgz#371c67ebffe50f551c3146a9eec5fe6ffe862e92"
|
||||
integrity sha512-tAG9LWg8+M2CMu7hIsqHPaTyG4uDzjr6mhvH96LvOpLZZj6tgzTluBt+LsCf1/QaYrlis6pITvpIaIhE+iZB+Q==
|
||||
|
||||
"@openzeppelin/contracts@^4.3.1":
|
||||
version "4.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.1.tgz#c01f791ce6c9d3989ac1a643267501dbe336b9e3"
|
||||
integrity sha512-QjgbPPlmDK2clK1hzjw2ROfY8KA5q+PfhDUUxZFEBCZP9fi6d5FuNoh/Uq0oCTMEKPmue69vhX2jcl0N/tFKGw==
|
||||
|
||||
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf"
|
||||
|
Loading…
Reference in New Issue
Block a user