Skip to content

Commit

Permalink
Merge pull request #190 from OriginTrail/test-token-deployment
Browse files Browse the repository at this point in the history
Added test Token deployment script, modified Token contract not to be dependant on the Hub
  • Loading branch information
u-hubar authored Nov 24, 2023
2 parents 0a37123 + 72b8fba commit 00ab110
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 33 deletions.
76 changes: 60 additions & 16 deletions abi/Token.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
{
"inputs": [
{
"internalType": "address",
"name": "hubAddress",
"type": "address"
"internalType": "string",
"name": "tokenName",
"type": "string"
},
{
"internalType": "string",
"name": "tokenSymbol",
"type": "string"
}
],
"stateMutability": "nonpayable",
Expand Down Expand Up @@ -35,6 +40,25 @@
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -326,19 +350,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "hub",
"outputs": [
{
"internalType": "contract Hub",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -394,6 +405,26 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -540,5 +571,18 @@
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
8 changes: 4 additions & 4 deletions contracts/v1/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

pragma solidity ^0.8.16;

import {HubDependent} from "./abstract/HubDependent.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract Token is HubDependent, ERC20, AccessControl {
contract Token is Ownable, ERC20, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

// solhint-disable-next-line no-empty-blocks
constructor(address hubAddress) HubDependent(hubAddress) ERC20("TEST TOKEN", "TEST") {}
constructor(string memory tokenName, string memory tokenSymbol) ERC20(tokenName, tokenSymbol) {}

function setupRole(address minter) public onlyHubOwner {
function setupRole(address minter) public onlyOwner {
_setupRole(MINTER_ROLE, minter);
}

Expand Down
17 changes: 5 additions & 12 deletions deploy/003_deploy_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,26 @@ import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer, minter } = await hre.getNamedAccounts();
const { deployer } = await hre.getNamedAccounts();

const isDeployed = hre.helpers.isDeployed('Token');

const Token = await hre.helpers.deploy({
newContractName: 'Token',
passHubInConstructor: false,
additionalArgs: ['TEST TOKEN', 'TEST'],
});

if (!isDeployed) {
const hubControllerAddress = hre.helpers.contractDeployments.contracts['HubController'].evmAddress;
const HubController = await hre.ethers.getContractAt('HubController', hubControllerAddress, deployer);

const TokenAbi = hre.helpers.getAbi('Token');
const TokenInterface = new hre.ethers.utils.Interface(TokenAbi);

const setupRoleTx = await HubController.forwardCall(
Token.address,
TokenInterface.encodeFunctionData('setupRole', [minter]),
);
const setupRoleTx = await Token.setupRole(deployer, { from: deployer });
await setupRoleTx.wait();
}
if (hre.network.name === 'hardhat') {
const amountToMint = hre.ethers.utils.parseEther(`${5_000_000}`);
const accounts = await hre.ethers.getSigners();

for (const acc of accounts) {
const mintTx = await Token.mint(acc.address, amountToMint, { from: minter, gasLimit: 80_000 });
const mintTx = await Token.mint(acc.address, amountToMint, { from: deployer, gasLimit: 80_000 });
await mintTx.wait();
}
}
Expand Down
26 changes: 26 additions & 0 deletions scripts/deploy_test_token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import hre from 'hardhat';

async function main() {
const [tokenName, tokenSymbol] = process.argv.slice(2);

if (!tokenName || !tokenSymbol) {
console.error('Usage: npx hardhat run scripts/deployToken.js --network <network_name> <tokenName> <tokenSymbol>');
process.exit(1);
}

const TokenFactory = await hre.ethers.getContractFactory('Token');
const Token = await TokenFactory.deploy(tokenName, tokenSymbol);

await Token.deployed();

console.log(
`${tokenName} ($${tokenSymbol}) token has been deployed to: ${Token.address} on the ${hre.network.name} blockchain!`,
);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
2 changes: 1 addition & 1 deletion utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Helpers {

public async deploy({
newContractName,
newContractNameInHub,
newContractNameInHub = undefined,
passHubInConstructor = true,
setContractInHub = true,
setAssetStorageInHub = false,
Expand Down

0 comments on commit 00ab110

Please sign in to comment.