Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dollar token smart contract #419

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/abi-encode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ABI Encode
on:
push:
branches:
- master # Replace with your branch name

jobs:
abi-encode:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14

- name: Install dependencies
run: npm install

- name: ABI Encode
uses: blocklytics/[email protected]
with:
contractPath: ./contracts/Dollar.sol # Replace with your contract path
arguments: '000000000000000000000000123456789abcdefABCDEF123456789ABCDEF123' # Replace with your constructor arguments
33 changes: 33 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
33 changes: 33 additions & 0 deletions Dollar.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.0/contracts/access/Ownable.sol";

contract DollarToken is ERC20, Ownable {
bool private _contractCreated;
address private _tokenFactory;

modifier onlyTokenFactory() {
require(msg.sender == _tokenFactory, "Only the token factory can create instances of this contract");
_;
}

constructor(address tokenFactory) ERC20("Dollar", "$") {
require(!_contractCreated, "Contract already created");
_contractCreated = true;
_tokenFactory = tokenFactory;

uint256 initialSupply = 32674174016000000000000 * (10**6); // 32,674,174,016 tokens with 6 decimals
_mint(msg.sender, initialSupply);
}

function additionalMint(uint256 amount) public onlyOwner {
_mint(msg.sender, amount);
}

function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
}

21 changes: 21 additions & 0 deletions TokenFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.0/contracts/access/Ownable.sol";

contract DollarTokenFactory is Ownable {
event TokenCreated(address indexed tokenAddress);

function createToken(string memory name, string memory symbol, uint256 initialSupply) external onlyOwner {
DollarToken token = new DollarToken(name, symbol, initialSupply);
emit TokenCreated(address(token));
}
}

contract DollarToken is ERC20 {
constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20(name, symbol) {
_mint(msg.sender, initialSupply);
}
}

33 changes: 33 additions & 0 deletions contracts/Dollar.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.4.0/contracts/access/Ownable.sol";

contract DollarToken is ERC20, Ownable {
bool private _contractCreated;
address private _tokenFactory;

modifier onlyTokenFactory() {
require(msg.sender == _tokenFactory, "Only the token factory can create instances of this contract");
_;
}

constructor(address tokenFactory) ERC20("Dollar", "$") {
require(!_contractCreated, "Contract already created");
_contractCreated = true;
_tokenFactory = tokenFactory;

uint256 initialSupply = 32674174016000000000000 * (10**6); // 32,674,174,016 tokens with 6 decimals
_mint(msg.sender, initialSupply);
}

function additionalMint(uint256 amount) public onlyOwner {
_mint(msg.sender, amount);
}

function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
}

Loading