Skip to content

Commit

Permalink
stableCoin
Browse files Browse the repository at this point in the history
  • Loading branch information
chandn0 committed Jan 25, 2024
1 parent 4c7e346 commit 3e7c2c8
Show file tree
Hide file tree
Showing 5 changed files with 597 additions and 16 deletions.
12 changes: 6 additions & 6 deletions packages/buildbear/sandbox.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sandboxId": "mass-lando-calrissian-056e4f18",
"chainId": 12911,
"rpcUrl": "https://rpc.buildbear.io/mass-lando-calrissian-056e4f18",
"faucetUrl": "https://faucet.buildbear.io/mass-lando-calrissian-056e4f18",
"explorerUrl": "https://explorer.buildbear.io/mass-lando-calrissian-056e4f18",
"verificationUrl": "https://api.buildbear.io/v1/api/verify/etherscan/mass-lando-calrissian-056e4f18",
"sandboxId": "joyous-gorgon-c47fe457",
"chainId": 14115,
"rpcUrl": "https://rpc.buildbear.io/joyous-gorgon-c47fe457",
"faucetUrl": "https://faucet.buildbear.io/joyous-gorgon-c47fe457",
"explorerUrl": "https://explorer.buildbear.io/joyous-gorgon-c47fe457",
"verificationUrl": "https://api.buildbear.io/v1/api/verify/etherscan/joyous-gorgon-c47fe457",
"forkingChainId": 1
}
119 changes: 119 additions & 0 deletions packages/hardhat/contracts/stablecoin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

contract Stablecoin {
string public name;
string public symbol;
uint8 public decimals;
uint public totalSupply;
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) public allowance;

event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
event Issued(uint value);

address public owner;
bool public paused;
mapping(address => bool) public minters;
mapping(address => bool) public blacklist;

modifier notBlacklisted() {
require(!blacklist[msg.sender], "Blacklisted address");
_;
}

modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}

modifier onlyMinter() {
require(minters[msg.sender], "Not a minter");
_;
}

modifier notPaused() {
require(!paused, "Function Paused");
_;
}

constructor(
string memory _name,
string memory _symbol,
uint8 _decimals,
uint _initialSupply,
address _owner
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _initialSupply;
balances[_owner] = _initialSupply;
owner = _owner;
}

function changeOwner(address _newOwner) public onlyOwner {
owner = _newOwner;
}

function transfer(
address _to,
uint _value
) public notPaused notBlacklisted returns (bool success) {
require(balances[msg.sender] >= _value, "Insufficient balance");
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}

function approve(
address _spender,
uint _value
) public notPaused notBlacklisted returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}

function transferFrom(
address _from,
address _to,
uint _value
) public notPaused notBlacklisted returns (bool success) {
require(
balances[_from] >= _value && allowance[_from][msg.sender] >= _value,
"Insufficient balance or allowance"
);
balances[_from] -= _value;
allowance[_from][msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(_from, _to, _value);
return true;
}

function mint(
address _recipient,
uint256 _value
) public onlyMinter notBlacklisted {
totalSupply += _value;
balances[_recipient] += _value;
emit Issued(_value);
}

function setPaused(bool _paused) public onlyOwner {
paused = _paused;
}

function setMinter(address _minter, bool _paused) public onlyOwner {
minters[_minter] = _paused;
}

function setBlacklist(
address _address,
bool _isBlacklisted
) public onlyOwner {
blacklist[_address] = _isBlacklisted;
}
}
46 changes: 46 additions & 0 deletions packages/hardhat/deploy/00_deploy_your_stableCoin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
// import {} from "../deployments/buildbear/"

/**
* Deploys a contract named "YourContract" using the deployer account and
* constructor arguments set to the deployer address
*
* @param hre HardhatRuntimeEnvironment object.
*/
const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/*
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
When deploying to live networks (e.g `yarn deploy --network goerli`), the deployer account
should have sufficient balance to pay for the gas fees for contract creation.
You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY
with a random private key in the .env file (then used on hardhat.config.ts)
You can run the `yarn account` command to check your balance in every network.
*/
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

const your_contract = await deploy("Stablecoin", {
from: deployer,
args: ["BuildBear", "BB", 10, 10000, "0x840597Df1f4B183B1923c54e0043eDb9affa6cbd"],
// Contract constructor arguments
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
});

await hre.run("verify:verify", {
address: your_contract.address,
constructorArguments: ["BuildBear", "BB", 10, 10000, "0x840597Df1f4B183B1923c54e0043eDb9affa6cbd"],
});

};

export default deployYourContract;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags YourContract
deployYourContract.tags = ["Stablecoin"];
Loading

0 comments on commit 3e7c2c8

Please sign in to comment.