diff --git a/packages/buildbear/sandbox.json b/packages/buildbear/sandbox.json index 993258f..b8cf3bf 100644 --- a/packages/buildbear/sandbox.json +++ b/packages/buildbear/sandbox.json @@ -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 } \ No newline at end of file diff --git a/packages/hardhat/contracts/stablecoin.sol b/packages/hardhat/contracts/stablecoin.sol new file mode 100644 index 0000000..65e25d5 --- /dev/null +++ b/packages/hardhat/contracts/stablecoin.sol @@ -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; + } +} diff --git a/packages/hardhat/deploy/00_deploy_your_stableCoin.ts b/packages/hardhat/deploy/00_deploy_your_stableCoin.ts new file mode 100644 index 0000000..60f31c3 --- /dev/null +++ b/packages/hardhat/deploy/00_deploy_your_stableCoin.ts @@ -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"]; diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index f1ff6ed..d09f7b6 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -5,9 +5,9 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; const deployedContracts = { - 12911: { + 14115: { Aave: { - address: "0x7c4aFDb4F2aA2Ba2735392026C775f98613C54bd", + address: "0x35CC13aa4C894372Fb2449cA8A5bD4d6D7470E7F", abi: [ { inputs: [ @@ -134,8 +134,424 @@ const deployedContracts = { ], inheritedFunctions: {}, }, + Stablecoin: { + address: "0x8205A8795d7B84f3e09c00CD420A9E738AD27222", + abi: [ + { + inputs: [ + { + internalType: "string", + name: "_name", + type: "string", + }, + { + internalType: "string", + name: "_symbol", + type: "string", + }, + { + internalType: "uint8", + name: "_decimals", + type: "uint8", + }, + { + internalType: "uint256", + name: "_initialSupply", + type: "uint256", + }, + { + internalType: "address", + name: "_owner", + type: "address", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "owner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "spender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Approval", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Issued", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Transfer", + type: "event", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "allowance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_spender", + type: "address", + }, + { + internalType: "uint256", + name: "_value", + type: "uint256", + }, + ], + name: "approve", + outputs: [ + { + internalType: "bool", + name: "success", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "balances", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "blacklist", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_newOwner", + type: "address", + }, + ], + name: "changeOwner", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "decimals", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_recipient", + type: "address", + }, + { + internalType: "uint256", + name: "_value", + type: "uint256", + }, + ], + name: "mint", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "minters", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "name", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "paused", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_address", + type: "address", + }, + { + internalType: "bool", + name: "_isBlacklisted", + type: "bool", + }, + ], + name: "setBlacklist", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_minter", + type: "address", + }, + { + internalType: "bool", + name: "_paused", + type: "bool", + }, + ], + name: "setMinter", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bool", + name: "_paused", + type: "bool", + }, + ], + name: "setPaused", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "symbol", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "totalSupply", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_to", + type: "address", + }, + { + internalType: "uint256", + name: "_value", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + internalType: "bool", + name: "success", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_from", + type: "address", + }, + { + internalType: "address", + name: "_to", + type: "address", + }, + { + internalType: "uint256", + name: "_value", + type: "uint256", + }, + ], + name: "transferFrom", + outputs: [ + { + internalType: "bool", + name: "success", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + ], + inheritedFunctions: {}, + }, Swap: { - address: "0x49cDc67F5f2A85b0C600919604FE3360c65a42CE", + address: "0x5793aF6d47ffFAE96ED4f4E26a8917CE64291f33", abi: [ { inputs: [ @@ -238,7 +654,7 @@ const deployedContracts = { inheritedFunctions: {}, }, YourContract: { - address: "0x6AFc76B5B068e289eA96B0f82f56F2E35Fd909f7", + address: "0xb45025327D711e0849710760437150Da778811c4", abi: [ { inputs: [ diff --git a/packages/nextjs/sandbox.json b/packages/nextjs/sandbox.json index 993258f..b8cf3bf 100644 --- a/packages/nextjs/sandbox.json +++ b/packages/nextjs/sandbox.json @@ -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 } \ No newline at end of file